KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > jdbc > core > simple > SimpleJdbcOperations


1 /*
2  * Copyright 2002-2005 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.core.simple;
18
19 import java.util.List JavaDoc;
20 import java.util.Map JavaDoc;
21
22 import org.springframework.dao.DataAccessException;
23 import org.springframework.jdbc.core.JdbcOperations;
24
25 /**
26  * JDBC operations nterface usable on Java 5 and above, exposing a
27  * set of common JDBC operations, whose interface is simplified
28  * through the use of varargs and autoboxing.
29  *
30  * @author Rod Johnson
31  * @author Rob Harrop
32  * @since 2.0
33  * @see SimpleJdbcTemplate
34  * @see org.springframework.jdbc.core.JdbcOperations
35  */

36 public interface SimpleJdbcOperations {
37
38     /**
39      * Expose the classic Spring JdbcTemplate to allow invocation of less
40      * commonly used methods.
41      */

42     JdbcOperations getJdbcOperations();
43
44
45     /**
46      * Query for an <code>int</code> passing in a SQL query and a variable
47      * number of arguments.
48      */

49     int queryForInt(String JavaDoc sql, Object JavaDoc... args) throws DataAccessException;
50
51     /**
52      * Query for an <code>long</code> passing in a SQL query and a variable
53      * number of arguments.
54      */

55     long queryForLong(String JavaDoc sql, Object JavaDoc... args) throws DataAccessException;
56
57     /**
58      * Query for an object of type <code>T</code> identified by the supplied @{@link Class}.
59      * @param sql the SQL query to run.
60      * @param requiredType the required type of the return value.
61      * @param args the args for the query.
62      * @see JdbcOperations#queryForObject(String, Class)
63      * @see JdbcOperations#queryForObject(String, Object[], Class)
64      */

65     <T> T queryForObject(String JavaDoc sql, Class JavaDoc<T> requiredType, Object JavaDoc... args)
66             throws DataAccessException;
67
68     /**
69      * Query for an object of type <code>T</code> using the supplied
70      * {@link ParameterizedRowMapper} to the query results to the object.
71      * @param sql the SQL query to run.
72      * @param rm the @{@link ParameterizedRowMapper} to use for result mapping
73      * @param args the args for the query.
74      * @see JdbcOperations#queryForObject(String, org.springframework.jdbc.core.RowMapper)
75      * @see JdbcOperations#queryForObject(String, Object[], org.springframework.jdbc.core.RowMapper)
76      */

77     <T> T queryForObject(String JavaDoc sql, ParameterizedRowMapper<T> rm, Object JavaDoc... args)
78             throws DataAccessException;
79
80     /**
81      * Query for a {@link List} of <code>Objects</code> of type <code>T</code> using
82      * the supplied {@link ParameterizedRowMapper} to the query results to the object.
83      * @param sql the SQL query to run.
84      * @param rm the @{@link ParameterizedRowMapper} to use for result mapping
85      * @param args the args for the query.
86      * @see JdbcOperations#queryForObject(String, org.springframework.jdbc.core.RowMapper)
87      * @see JdbcOperations#queryForObject(String, Object[], org.springframework.jdbc.core.RowMapper)
88      */

89     <T> List JavaDoc<T> query(String JavaDoc sql, ParameterizedRowMapper<T> rm, Object JavaDoc... args)
90             throws DataAccessException;
91
92     /**
93      * Execute the supplied query with the (optional) supplied arguments.
94      * <p>The query is expected to be a single row query; the result row will be
95      * mapped to a Map (one entry for each column, using the column name as the key).
96      * @see JdbcOperations#queryForMap(String)
97      * @see JdbcOperations#queryForMap(String, Object[])
98      */

99     Map JavaDoc<String JavaDoc, Object JavaDoc> queryForMap(String JavaDoc sql, Object JavaDoc... args)
100             throws DataAccessException;
101
102     /**
103      * Execute the supplied query with the (optional) supplied arguments.
104      * <p>Each element in the returned {@link List} is constructed as a {@link Map}
105      * as described in {@link #queryForMap}
106      * @see JdbcOperations#queryForList(String)
107      * @see JdbcOperations#queryForList(String, Object[])
108      */

109     List JavaDoc<Map JavaDoc<String JavaDoc, Object JavaDoc>> queryForList(String JavaDoc sql, Object JavaDoc... args)
110             throws DataAccessException;
111
112     /**
113      * Executes the supplied SQL statement with (optional) supplied arguments.
114      * @return the numbers of rows affected by the update.
115      * @see JdbcOperations#update(String)
116      * @see JdbcOperations#update(String, Object[])
117      */

118     int update(String JavaDoc sql, Object JavaDoc... args) throws DataAccessException;
119
120 }
121
Popular Tags