KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > ibatis > sqlmap > engine > mapping > statement > BaseStatement


1 /*
2  * Copyright 2004 Clinton Begin
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, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package com.ibatis.sqlmap.engine.mapping.statement;
17
18 import com.ibatis.sqlmap.client.SqlMapClient;
19 import com.ibatis.sqlmap.engine.cache.CacheKey;
20 import com.ibatis.sqlmap.engine.execution.SqlExecutor;
21 import com.ibatis.sqlmap.engine.impl.ExtendedSqlMapClient;
22 import com.ibatis.sqlmap.engine.mapping.parameter.ParameterMap;
23 import com.ibatis.sqlmap.engine.mapping.result.ResultMap;
24 import com.ibatis.sqlmap.engine.mapping.sql.Sql;
25 import com.ibatis.sqlmap.engine.scope.RequestScope;
26
27 import java.util.ArrayList JavaDoc;
28 import java.util.List JavaDoc;
29
30 public abstract class BaseStatement implements MappedStatement {
31
32   private String JavaDoc id;
33   private Integer JavaDoc resultSetType;
34   private Integer JavaDoc fetchSize;
35   private ResultMap resultMap;
36   private ParameterMap parameterMap;
37   private Class JavaDoc parameterClass;
38   private Sql sql;
39   private int baseCacheKey;
40   private ExtendedSqlMapClient sqlMapClient;
41
42   private List JavaDoc executeListeners = new ArrayList JavaDoc();
43
44   private String JavaDoc resource;
45
46   public String JavaDoc getId() {
47     return id;
48   }
49
50   public Integer JavaDoc getResultSetType() {
51     return resultSetType;
52   }
53
54   public void setResultSetType(Integer JavaDoc resultSetType) {
55     this.resultSetType = resultSetType;
56   }
57
58   public Integer JavaDoc getFetchSize() {
59     return fetchSize;
60   }
61
62   public void setFetchSize(Integer JavaDoc fetchSize) {
63     this.fetchSize = fetchSize;
64   }
65
66   public void setId(String JavaDoc id) {
67     this.id = id;
68   }
69
70   public Sql getSql() {
71     return sql;
72   }
73
74   public void setSql(Sql sql) {
75     this.sql = sql;
76   }
77
78   public ResultMap getResultMap() {
79     return resultMap;
80   }
81
82   public void setResultMap(ResultMap resultMap) {
83     this.resultMap = resultMap;
84   }
85
86   public ParameterMap getParameterMap() {
87     return parameterMap;
88   }
89
90   public void setParameterMap(ParameterMap parameterMap) {
91     this.parameterMap = parameterMap;
92   }
93
94   public Class JavaDoc getParameterClass() {
95     return parameterClass;
96   }
97
98   public void setParameterClass(Class JavaDoc parameterClass) {
99     this.parameterClass = parameterClass;
100   }
101
102   public String JavaDoc getResource() {
103     return resource;
104   }
105
106   public void setResource(String JavaDoc resource) {
107     this.resource = resource;
108   }
109
110   public CacheKey getCacheKey(RequestScope request, Object JavaDoc parameterObject) {
111     Sql sql = request.getSql();
112     ParameterMap pmap = sql.getParameterMap(request, parameterObject);
113     CacheKey cacheKey = pmap.getCacheKey(request, parameterObject);
114     cacheKey.update(id);
115     cacheKey.update(baseCacheKey);
116     cacheKey.update(sql.getSql(request, parameterObject)); //Fixes bug 953001
117
return cacheKey;
118   }
119
120   public void setBaseCacheKey(int base) {
121     this.baseCacheKey = base;
122   }
123
124   public void addExecuteListener(ExecuteListener listener) {
125     executeListeners.add(listener);
126   }
127
128   public void notifyListeners() {
129     for (int i = 0, n = executeListeners.size(); i < n; i++) {
130       ((ExecuteListener) executeListeners.get(i)).onExecuteStatement(this);
131     }
132   }
133
134   public SqlExecutor getSqlExecutor() {
135     return sqlMapClient.getSqlExecutor();
136   }
137
138   public SqlMapClient getSqlMapClient() {
139     return sqlMapClient;
140   }
141
142   public void setSqlMapClient(SqlMapClient sqlMapClient) {
143     this.sqlMapClient = (ExtendedSqlMapClient) sqlMapClient;
144   }
145
146   public void initRequest(RequestScope request) {
147     request.setStatement(this);
148     request.setParameterMap(parameterMap);
149     request.setResultMap(resultMap);
150     request.setSql(sql);
151   }
152
153 }
154
Popular Tags