Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/ibatis/db/sqlmap/MappedStatement.java


1   /*
2    *  Copyright 2004 Clinton Begin
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  package com.ibatis.db.sqlmap;
17  
18  import com.ibatis.common.util.PaginatedList;
19  import com.ibatis.sqlmap.client.SqlMapClient;
20  
21  import java.sql.Connection;
22  import java.sql.SQLException;
23  import java.util.List;
24  import java.util.Map;
25  
26  public class MappedStatement {
27  
28    private SqlMapClient sqlMapClient;
29    private String statementName;
30  
31    public MappedStatement(SqlMapClient sqlMapClient, String statementName) {
32      this.sqlMapClient = sqlMapClient;
33      this.statementName = statementName;
34    }
35  
36    public int executeUpdate(Connection conn, Object parameterObject)
37        throws SQLException {
38      int n;
39      try {
40        sqlMapClient.setUserConnection(conn);
41        n = sqlMapClient.update(statementName, parameterObject);
42      } finally {
43        sqlMapClient.setUserConnection(null);
44      }
45      return n;
46    }
47  
48    public void executeQueryWithRowHandler(Connection conn, Object parameterObject, RowHandler rowHandler)
49        throws SQLException {
50      try {
51        sqlMapClient.setUserConnection(conn);
52        sqlMapClient.queryWithRowHandler(statementName, parameterObject, new RowHandlerAdapter(rowHandler));
53      } finally {
54        sqlMapClient.setUserConnection(null);
55      }
56    }
57  
58    public Map executeQueryForMap(Connection conn, Object parameterObject, String keyProperty)
59        throws SQLException {
60      Map map;
61      try {
62        sqlMapClient.setUserConnection(conn);
63        map = sqlMapClient.queryForMap(statementName, parameterObject, keyProperty);
64      } finally {
65        sqlMapClient.setUserConnection(null);
66      }
67      return map;
68    }
69  
70    public Map executeQueryForMap(Connection conn, Object parameterObject, String keyProperty, String valueProperty)
71        throws SQLException {
72      Map map;
73      try {
74        sqlMapClient.setUserConnection(conn);
75        map = sqlMapClient.queryForMap(statementName, parameterObject, keyProperty, valueProperty);
76      } finally {
77        sqlMapClient.setUserConnection(null);
78      }
79      return map;
80    }
81  
82    public PaginatedList executeQueryForPaginatedList(Object parameterObject, int pageSize)
83        throws SQLException {
84      PaginatedList list = sqlMapClient.queryForPaginatedList(statementName, parameterObject, pageSize);
85      return list;
86    }
87  
88    public List executeQueryForList(Connection conn, Object parameterObject)
89        throws SQLException {
90      List list;
91      try {
92        sqlMapClient.setUserConnection(conn);
93        list = sqlMapClient.queryForList(statementName, parameterObject);
94      } finally {
95        sqlMapClient.setUserConnection(null);
96      }
97      return list;
98    }
99  
100   public List executeQueryForList(Connection conn, Object parameterObject, int skipResults, int maxResults)
101       throws SQLException {
102     List list;
103     try {
104       sqlMapClient.setUserConnection(conn);
105       list = sqlMapClient.queryForList(statementName, parameterObject, skipResults, maxResults);
106     } finally {
107       sqlMapClient.setUserConnection(null);
108     }
109     return list;
110   }
111 
112   public Object executeQueryForObject(Connection conn, Object parameterObject)
113       throws SQLException {
114     Object o;
115     try {
116       sqlMapClient.setUserConnection(conn);
117       o = sqlMapClient.queryForObject(statementName, parameterObject);
118     } finally {
119       sqlMapClient.setUserConnection(null);
120     }
121     return o;
122   }
123 
124   public Object executeQueryForObject(Connection conn, Object parameterObject, Object resultObject)
125       throws SQLException {
126     Object o;
127     try {
128       sqlMapClient.setUserConnection(conn);
129       o = sqlMapClient.queryForObject(statementName, parameterObject, resultObject);
130     } finally {
131       sqlMapClient.setUserConnection(null);
132     }
133     return o;
134   }
135 
136 
137 }