1 /*
2 * Copyright 2004-2022 the original author or authors.
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 * https://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.scope;
17
18 import com.ibatis.sqlmap.engine.mapping.parameter.ParameterMap;
19 import com.ibatis.sqlmap.engine.mapping.result.ResultMap;
20 import com.ibatis.sqlmap.engine.mapping.sql.Sql;
21 import com.ibatis.sqlmap.engine.mapping.statement.MappedStatement;
22
23 import java.sql.ResultSet;
24 import java.util.HashMap;
25 import java.util.Map;
26
27 /**
28 * Request based implementation of Scope interface.
29 */
30 public class StatementScope {
31
32 /** The session scope. */
33 // Used by Any
34 private SessionScope sessionScope;
35
36 /** The error context. */
37 private ErrorContext errorContext;
38
39 /** The statement. */
40 private MappedStatement statement;
41
42 /** The parameter map. */
43 private ParameterMap parameterMap;
44
45 /** The result map. */
46 private ResultMap resultMap;
47
48 /** The sql. */
49 private Sql sql;
50
51 /** The dynamic parameter map. */
52 // Used by DynamicSql
53 private ParameterMap dynamicParameterMap;
54
55 /** The dynamic sql. */
56 private String dynamicSql;
57
58 /** The result set. */
59 // Used by N+1 Select solution
60 private ResultSet resultSet;
61
62 /** The unique keys. */
63 private Map uniqueKeys;
64
65 /** The row data found. */
66 private boolean rowDataFound;
67
68 /** The current nested key. */
69 private String currentNestedKey;
70
71 /**
72 * Instantiates a new statement scope.
73 *
74 * @param sessionScope
75 * the session scope
76 */
77 public StatementScope(SessionScope sessionScope) {
78 this.errorContext = new ErrorContext();
79 this.rowDataFound = true;
80 this.sessionScope = sessionScope;
81 }
82
83 /**
84 * Gets the current nested key.
85 *
86 * @return Returns the currentNestedKey.
87 */
88 public String getCurrentNestedKey() {
89 return currentNestedKey;
90 }
91
92 /**
93 * Sets the current nested key.
94 *
95 * @param currentNestedKey
96 * The currentNestedKey to set.
97 */
98 public void setCurrentNestedKey(String currentNestedKey) {
99 this.currentNestedKey = currentNestedKey;
100 }
101
102 /**
103 * Get the request's error context.
104 *
105 * @return - the request's error context
106 */
107 public ErrorContext getErrorContext() {
108 return errorContext;
109 }
110
111 /**
112 * Get the session of the request.
113 *
114 * @return - the session
115 */
116 public SessionScope getSession() {
117 return sessionScope;
118 }
119
120 /**
121 * Get the statement for the request.
122 *
123 * @return - the statement
124 */
125 public MappedStatement getStatement() {
126 return statement;
127 }
128
129 /**
130 * Set the statement for the request.
131 *
132 * @param statement
133 * - the statement
134 */
135 public void setStatement(MappedStatement statement) {
136 this.statement = statement;
137 }
138
139 /**
140 * Get the parameter map for the request.
141 *
142 * @return - the parameter map
143 */
144 public ParameterMap getParameterMap() {
145 return parameterMap;
146 }
147
148 /**
149 * Set the parameter map for the request.
150 *
151 * @param parameterMap
152 * - the new parameter map
153 */
154 public void setParameterMap(ParameterMap parameterMap) {
155 this.parameterMap = parameterMap;
156 }
157
158 /**
159 * Get the result map for the request.
160 *
161 * @return - the result map
162 */
163 public ResultMap getResultMap() {
164 return resultMap;
165 }
166
167 /**
168 * Set the result map for the request.
169 *
170 * @param resultMap
171 * - the result map
172 */
173 public void setResultMap(ResultMap resultMap) {
174 this.resultMap = resultMap;
175 }
176
177 /**
178 * Get the SQL for the request.
179 *
180 * @return - the sql
181 */
182 public Sql getSql() {
183 return sql;
184 }
185
186 /**
187 * Set the SQL for the request.
188 *
189 * @param sql
190 * - the sql
191 */
192 public void setSql(Sql sql) {
193 this.sql = sql;
194 }
195
196 /**
197 * Get the dynamic parameter for the request.
198 *
199 * @return - the dynamic parameter
200 */
201 public ParameterMap getDynamicParameterMap() {
202 return dynamicParameterMap;
203 }
204
205 /**
206 * Set the dynamic parameter for the request.
207 *
208 * @param dynamicParameterMap
209 * - the dynamic parameter
210 */
211 public void setDynamicParameterMap(ParameterMap dynamicParameterMap) {
212 this.dynamicParameterMap = dynamicParameterMap;
213 }
214
215 /**
216 * Get the dynamic SQL for the request.
217 *
218 * @return - the dynamic SQL
219 */
220 public String getDynamicSql() {
221 return dynamicSql;
222 }
223
224 /**
225 * Set the dynamic SQL for the request.
226 *
227 * @param dynamicSql
228 * - the dynamic SQL
229 */
230 public void setDynamicSql(String dynamicSql) {
231 this.dynamicSql = dynamicSql;
232 }
233
234 /**
235 * Gets the result set.
236 *
237 * @return the result set
238 */
239 public ResultSet getResultSet() {
240 return resultSet;
241 }
242
243 /**
244 * Sets the result set.
245 *
246 * @param resultSet
247 * the new result set
248 */
249 public void setResultSet(ResultSet resultSet) {
250 this.resultSet = resultSet;
251 }
252
253 /**
254 * Gets the unique keys.
255 *
256 * @param map
257 * the map
258 *
259 * @return the unique keys
260 */
261 public Map getUniqueKeys(ResultMap map) {
262 if (uniqueKeys == null) {
263 return null;
264 }
265 return (Map) uniqueKeys.get(map);
266 }
267
268 /**
269 * Sets the unique keys.
270 *
271 * @param map
272 * the map
273 * @param keys
274 * the keys
275 */
276 public void setUniqueKeys(ResultMap map, Map keys) {
277 if (uniqueKeys == null) {
278 uniqueKeys = new HashMap();
279 }
280 this.uniqueKeys.put(map, keys);
281 }
282
283 /**
284 * Checks if is row data found.
285 *
286 * @return true, if is row data found
287 */
288 public boolean isRowDataFound() {
289 return rowDataFound;
290 }
291
292 /**
293 * Sets the row data found.
294 *
295 * @param rowDataFound
296 * the new row data found
297 */
298 public void setRowDataFound(boolean rowDataFound) {
299 this.rowDataFound = rowDataFound;
300 }
301
302 }