1 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 ; 28 import java.util.List ; 29 30 public abstract class BaseStatement implements MappedStatement { 31 32 private String id; 33 private Integer resultSetType; 34 private Integer fetchSize; 35 private ResultMap resultMap; 36 private ParameterMap parameterMap; 37 private Class parameterClass; 38 private Sql sql; 39 private int baseCacheKey; 40 private ExtendedSqlMapClient sqlMapClient; 41 42 private List executeListeners = new ArrayList (); 43 44 private String resource; 45 46 public String getId() { 47 return id; 48 } 49 50 public Integer getResultSetType() { 51 return resultSetType; 52 } 53 54 public void setResultSetType(Integer resultSetType) { 55 this.resultSetType = resultSetType; 56 } 57 58 public Integer getFetchSize() { 59 return fetchSize; 60 } 61 62 public void setFetchSize(Integer fetchSize) { 63 this.fetchSize = fetchSize; 64 } 65 66 public void setId(String 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 getParameterClass() { 95 return parameterClass; 96 } 97 98 public void setParameterClass(Class parameterClass) { 99 this.parameterClass = parameterClass; 100 } 101 102 public String getResource() { 103 return resource; 104 } 105 106 public void setResource(String resource) { 107 this.resource = resource; 108 } 109 110 public CacheKey getCacheKey(RequestScope request, Object 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)); 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 |