View Javadoc

1   /*
2    * Copyright 2004-2006 the Seasar Foundation and the Others.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 
13   * either express or implied. See the License for the specific language
14   * governing permissions and limitations under the License.
15   */
16  package org.seasar.tuigwaa.logic.functor;
17  
18  import java.util.Map;
19  
20  import javax.servlet.http.HttpServletRequest;
21  
22  import org.seasar.framework.container.factory.SingletonS2ContainerFactory;
23  import org.seasar.tuigwaa.database.function.DaoMethod;
24  import org.seasar.tuigwaa.model.DAOService;
25  import org.seasar.tuigwaa.model.ModelService;
26  import org.seasar.tuigwaa.model.core.TgwEntity;
27  import org.seasar.tuigwaa.plugin.TgwPluginUtils;
28  import org.seasar.tuigwaa.util.TgwContext;
29  
30  import com.isenshi.util.functor.UnaryProcedure;
31  
32  public class RowUpdateProcedure implements UnaryProcedure {
33  
34  	private String updateDaoName;
35  
36  	private String entityName;
37  
38  	public RowUpdateProcedure() {
39  	}
40  
41  	public RowUpdateProcedure(String entityName, String daoName) {
42  		this.entityName = entityName;
43  		this.updateDaoName = daoName;
44  	}
45  
46  	public void setUpdateDaoName(String updateDaoName) {
47  		this.updateDaoName = updateDaoName;
48  	}
49  
50  	public String getUpdateDaoName() {
51  		return updateDaoName;
52  	}
53  
54  	public void setEntityName(String entityName) {
55  		this.entityName = entityName;
56  	}
57  
58  	public String getEntityName() {
59  		return entityName;
60  	}
61  
62  	public void run(Object obj) {
63  		DAOService daoService = (DAOService) SingletonS2ContainerFactory
64  				.getContainer().getComponent(DAOService.class);
65  		ModelService entityService = (ModelService) SingletonS2ContainerFactory
66  				.getContainer().getComponent(ModelService.class);
67  
68  		String siteName = TgwContext.getSiteName();
69  		TgwEntity entity = entityService.getEntity(siteName, entityName);
70  		DaoMethod daoMethod = daoService.getDAO(entity)
71  				.getMethod(updateDaoName);
72  
73  		
74  		//get id directly from httprequest
75  		HttpServletRequest request = SingletonS2ContainerFactory.getContainer()
76  				.getRequest();
77  		Map map = TgwPluginUtils.getEntityNameMapFromRequest(request);
78  		String idStr = (String)map.get(entityName);
79  		if(idStr==null){
80  			return;
81  		}
82  		Long id = Long.valueOf(idStr);
83  		
84  		//Long id = TgwPluginUtils.getEntityId(entity);
85  
86  		if (id != null && id.longValue() > 0) { // ignore logic
87  			daoMethod.evaluate(id);
88  		}
89  	}
90  }