KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > ibatis > db > sqlmap > MappedStatement


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 JavaDoc;
22 import java.sql.SQLException JavaDoc;
23 import java.util.List JavaDoc;
24 import java.util.Map JavaDoc;
25
26 public class MappedStatement {
27
28   private SqlMapClient sqlMapClient;
29   private String JavaDoc statementName;
30
31   public MappedStatement(SqlMapClient sqlMapClient, String JavaDoc statementName) {
32     this.sqlMapClient = sqlMapClient;
33     this.statementName = statementName;
34   }
35
36   public int executeUpdate(Connection JavaDoc conn, Object JavaDoc parameterObject)
37       throws SQLException JavaDoc {
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 JavaDoc conn, Object JavaDoc parameterObject, RowHandler rowHandler)
49       throws SQLException JavaDoc {
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 JavaDoc executeQueryForMap(Connection JavaDoc conn, Object JavaDoc parameterObject, String JavaDoc keyProperty)
59       throws SQLException JavaDoc {
60     Map JavaDoc 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 JavaDoc executeQueryForMap(Connection JavaDoc conn, Object JavaDoc parameterObject, String JavaDoc keyProperty, String JavaDoc valueProperty)
71       throws SQLException JavaDoc {
72     Map JavaDoc 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 JavaDoc parameterObject, int pageSize)
83       throws SQLException JavaDoc {
84     PaginatedList list = sqlMapClient.queryForPaginatedList(statementName, parameterObject, pageSize);
85     return list;
86   }
87
88   public List executeQueryForList(Connection JavaDoc conn, Object JavaDoc parameterObject)
89       throws SQLException JavaDoc {
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 JavaDoc conn, Object JavaDoc parameterObject, int skipResults, int maxResults)
101       throws SQLException JavaDoc {
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 JavaDoc executeQueryForObject(Connection JavaDoc conn, Object JavaDoc parameterObject)
113       throws SQLException JavaDoc {
114     Object JavaDoc 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 JavaDoc executeQueryForObject(Connection JavaDoc conn, Object JavaDoc parameterObject, Object JavaDoc resultObject)
125       throws SQLException JavaDoc {
126     Object JavaDoc 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 }
138
Popular Tags