001: /*
002: * Copyright 2004 Clinton Begin
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package com.ibatis.sqlmap.engine.scope;
017:
018: import com.ibatis.sqlmap.engine.mapping.parameter.ParameterMap;
019: import com.ibatis.sqlmap.engine.mapping.result.ResultMap;
020: import com.ibatis.sqlmap.engine.mapping.sql.Sql;
021: import com.ibatis.sqlmap.engine.mapping.statement.MappedStatement;
022:
023: import java.sql.ResultSet;
024: import java.util.Map;
025: import java.util.HashMap;
026:
027: /**
028: * Request based implementation of Scope interface
029: */
030: public class RequestScope extends BaseScope {
031: // Used by Any
032: private SessionScope session;
033: private ErrorContext errorContext;
034: private MappedStatement statement;
035: private ParameterMap parameterMap;
036: private ResultMap resultMap;
037: private Sql sql;
038: // Used by DynamicSql
039: private ParameterMap dynamicParameterMap;
040: private String dynamicSql;
041: // Used by N+1 Select solution
042: private ResultSet resultSet;
043: private Map uniqueKeys;
044: private boolean rowDataFound;
045: private String currentNestedKey;
046:
047: /**
048: * Default constructor
049: */
050: public RequestScope() {
051: errorContext = new ErrorContext();
052: reset();
053: }
054:
055: /**
056: * @return Returns the currentNestedKey.
057: */
058: public String getCurrentNestedKey() {
059: return currentNestedKey;
060: }
061:
062: /**
063: * @param currentNestedKey The currentNestedKey to set.
064: */
065: public void setCurrentNestedKey(String currentNestedKey) {
066: this .currentNestedKey = currentNestedKey;
067: }
068:
069: /**
070: * Get the request's error context
071: *
072: * @return - the request's error context
073: */
074: public ErrorContext getErrorContext() {
075: return errorContext;
076: }
077:
078: /**
079: * Get the session of the request
080: *
081: * @return - the session
082: */
083: public SessionScope getSession() {
084: return session;
085: }
086:
087: /**
088: * Set the session for the request
089: *
090: * @param session - the new session
091: */
092: public void setSession(SessionScope session) {
093: this .session = session;
094: }
095:
096: /**
097: * Get the statement for the request
098: *
099: * @return - the statement
100: */
101: public MappedStatement getStatement() {
102: return statement;
103: }
104:
105: /**
106: * Set the statement for the request
107: *
108: * @param statement - the statement
109: */
110: public void setStatement(MappedStatement statement) {
111: this .statement = statement;
112: }
113:
114: /**
115: * Get the parameter map for the request
116: *
117: * @return - the parameter map
118: */
119: public ParameterMap getParameterMap() {
120: return parameterMap;
121: }
122:
123: /**
124: * Set the parameter map for the request
125: *
126: * @param parameterMap - the new parameter map
127: */
128: public void setParameterMap(ParameterMap parameterMap) {
129: this .parameterMap = parameterMap;
130: }
131:
132: /**
133: * Get the result map for the request
134: *
135: * @return - the result map
136: */
137: public ResultMap getResultMap() {
138: return resultMap;
139: }
140:
141: /**
142: * Set the result map for the request
143: *
144: * @param resultMap - the result map
145: */
146: public void setResultMap(ResultMap resultMap) {
147: this .resultMap = resultMap;
148: }
149:
150: /**
151: * Get the SQL for the request
152: *
153: * @return - the sql
154: */
155: public Sql getSql() {
156: return sql;
157: }
158:
159: /**
160: * Set the SQL for the request
161: *
162: * @param sql - the sql
163: */
164: public void setSql(Sql sql) {
165: this .sql = sql;
166: }
167:
168: /**
169: * Get the dynamic parameter for the request
170: *
171: * @return - the dynamic parameter
172: */
173: public ParameterMap getDynamicParameterMap() {
174: return dynamicParameterMap;
175: }
176:
177: /**
178: * Set the dynamic parameter for the request
179: *
180: * @param dynamicParameterMap - the dynamic parameter
181: */
182: public void setDynamicParameterMap(ParameterMap dynamicParameterMap) {
183: this .dynamicParameterMap = dynamicParameterMap;
184: }
185:
186: /**
187: * Get the dynamic SQL for the request
188: *
189: * @return - the dynamic SQL
190: */
191: public String getDynamicSql() {
192: return dynamicSql;
193: }
194:
195: /**
196: * Set the dynamic SQL for the request
197: *
198: * @param dynamicSql - the dynamic SQL
199: */
200: public void setDynamicSql(String dynamicSql) {
201: this .dynamicSql = dynamicSql;
202: }
203:
204: public ResultSet getResultSet() {
205: return resultSet;
206: }
207:
208: public void setResultSet(ResultSet resultSet) {
209: this .resultSet = resultSet;
210: }
211:
212: public Map getUniqueKeys(ResultMap map) {
213: if (uniqueKeys == null) {
214: return null;
215: }
216: return (Map) uniqueKeys.get(map);
217: }
218:
219: public void setUniqueKeys(ResultMap map, Map keys) {
220: if (uniqueKeys == null) {
221: uniqueKeys = new HashMap();
222: }
223: this .uniqueKeys.put(map, keys);
224: }
225:
226: public boolean isRowDataFound() {
227: return rowDataFound;
228: }
229:
230: public void setRowDataFound(boolean rowDataFound) {
231: this .rowDataFound = rowDataFound;
232: }
233:
234: public void reset() {
235: super .reset();
236: errorContext.reset();
237: session = null;
238: statement = null;
239: parameterMap = null;
240: resultMap = null;
241: sql = null;
242: dynamicParameterMap = null;
243: dynamicSql = null;
244: resultSet = null;
245: uniqueKeys = null;
246: rowDataFound = true;
247: }
248:
249: }
|