KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > jdbc > object > SqlOperation


1 /*
2  * Copyright 2002-2006 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  * 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
17 package org.springframework.jdbc.object;
18
19 import org.springframework.jdbc.core.PreparedStatementCreator;
20 import org.springframework.jdbc.core.PreparedStatementCreatorFactory;
21 import org.springframework.jdbc.core.PreparedStatementSetter;
22 import org.springframework.jdbc.core.namedparam.NamedParameterUtils;
23
24 /**
25  * RdbmsOperation using a JdbcTemplate and representing a SQL-based
26  * operation such as a query or update, as opposed to a stored procedure.
27  *
28  * <p>Configures a PreparedStatementCreatorFactory based on the
29  * declared parameters.
30  *
31  * @author Rod Johnson
32  * @author Juergen Hoeller
33  * @see PreparedStatementCreatorFactory
34  */

35 public abstract class SqlOperation extends RdbmsOperation {
36
37     /**
38      * Object enabling us to create PreparedStatementCreators
39      * efficiently, based on this class's declared parameters.
40      */

41     private PreparedStatementCreatorFactory preparedStatementFactory;
42
43
44     /**
45      * Overridden method to configure the PreparedStatementCreatorFactory
46      * based on our declared parameters.
47      */

48     protected final void compileInternal() {
49         this.preparedStatementFactory = new PreparedStatementCreatorFactory(getSql(), getDeclaredParameters());
50         this.preparedStatementFactory.setResultSetType(getResultSetType());
51         this.preparedStatementFactory.setUpdatableResults(isUpdatableResults());
52         this.preparedStatementFactory.setReturnGeneratedKeys(isReturnGeneratedKeys());
53         if (getGeneratedKeysColumnNames() != null) {
54             this.preparedStatementFactory.setGeneratedKeysColumnNames(getGeneratedKeysColumnNames());
55         }
56         this.preparedStatementFactory.setNativeJdbcExtractor(getJdbcTemplate().getNativeJdbcExtractor());
57         this.preparedStatementFactory.setSqlToUse(NamedParameterUtils.parseSqlStatementIntoString(getSql()));
58
59         onCompileInternal();
60     }
61
62     /**
63      * Hook method that subclasses may override to post-process compilation.
64      * This implementation does nothing.
65      * @see #compileInternal
66      */

67     protected void onCompileInternal() {
68     }
69
70
71     /**
72      * Return a PreparedStatementSetter to perform an operation
73      * with the given parameters.
74      * @param params parameter array. May be <code>null</code>.
75      */

76     protected final PreparedStatementSetter newPreparedStatementSetter(Object JavaDoc[] params) {
77         return this.preparedStatementFactory.newPreparedStatementSetter(params);
78     }
79
80     /**
81      * Return a PreparedStatementCreator to perform an operation
82      * with the given parameters.
83      * @param params parameter array. May be <code>null</code>.
84      */

85     protected final PreparedStatementCreator newPreparedStatementCreator(Object JavaDoc[] params) {
86         return this.preparedStatementFactory.newPreparedStatementCreator(params);
87     }
88
89     /**
90      * Return a PreparedStatementCreator to perform an operation
91      * with the given parameters.
92      * @param sqlToUse the actual SQL statement to use (if different from
93      * the factory's, for example because of named parameter expanding)
94      * @param params parameter array. May be <code>null</code>.
95      */

96     protected final PreparedStatementCreator newPreparedStatementCreator(String JavaDoc sqlToUse, Object JavaDoc[] params) {
97         return this.preparedStatementFactory.newPreparedStatementCreator(sqlToUse, params);
98     }
99
100 }
101
Popular Tags