|
|||||||||||||||||||
| 30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover | |||||||||||||||||||
| Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
| JdbcServiceImpl.java | - | 0% | 0% | 0% |
|
||||||||||||||
| 1 |
/**
|
|
| 2 |
* @(#)JdbcServiceImpl.java
|
|
| 3 |
*
|
|
| 4 |
* JFoxSOAF, Service-Oriented Application Framework
|
|
| 5 |
*
|
|
| 6 |
* Copyright(c) JFoxSOAF Team
|
|
| 7 |
*
|
|
| 8 |
* Licensed under the GNU LGPL, Version 2.1 (the "License");
|
|
| 9 |
* you may not use this file except in compliance with the License.
|
|
| 10 |
* You may obtain a copy of the License at
|
|
| 11 |
*
|
|
| 12 |
* http://www.gnu.org/copyleft/lesser.html
|
|
| 13 |
*
|
|
| 14 |
* Unless required by applicable law or agreed to in writing, software
|
|
| 15 |
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
| 16 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
| 17 |
* See the License for the specific language governing permissions and
|
|
| 18 |
* limitations under the License.
|
|
| 19 |
*
|
|
| 20 |
* For more information, please visit:
|
|
| 21 |
* http://www.jfox.cn/confluence/display/JFoxSOAF/Home
|
|
| 22 |
* http://www.huihoo.org/jfox/jfoxsoaf
|
|
| 23 |
*/
|
|
| 24 |
|
|
| 25 |
package org.huihoo.jfox.soaf.services.persistence;
|
|
| 26 |
|
|
| 27 |
import java.sql.Connection;
|
|
| 28 |
import java.sql.SQLException;
|
|
| 29 |
|
|
| 30 |
import javax.sql.DataSource;
|
|
| 31 |
|
|
| 32 |
import org.apache.commons.dbutils.QueryRunner;
|
|
| 33 |
import org.apache.commons.dbutils.ResultSetHandler;
|
|
| 34 |
import org.huihoo.jfox.soaf.exception.DAOException;
|
|
| 35 |
|
|
| 36 |
/**
|
|
| 37 |
* <p>
|
|
| 38 |
* JDBC persistence service implementation.
|
|
| 39 |
* </p>
|
|
| 40 |
*
|
|
| 41 |
* @author <a href="mailto:founder_chen@yahoo.com.cn">Peter Cheng </a>
|
|
| 42 |
* @version $Revision: 1.10 $ $Date: 2005/08/19 11:29:21 $
|
|
| 43 |
* @version Revision: 1.0
|
|
| 44 |
*/
|
|
| 45 |
|
|
| 46 |
public class JdbcServiceImpl implements JdbcService { |
|
| 47 |
|
|
| 48 |
private QueryRunner queryRunner;
|
|
| 49 |
|
|
| 50 |
/**
|
|
| 51 |
* @param dataSource
|
|
| 52 |
*/
|
|
| 53 | 0 |
public JdbcServiceImpl() {
|
| 54 | 0 |
queryRunner = new QueryRunner();
|
| 55 |
} |
|
| 56 |
|
|
| 57 |
/**
|
|
| 58 |
* @see org.huihoo.jfox.soaf.services.persistence.JdbcService#setDataSource(javax.sql.DataSource)
|
|
| 59 |
*/
|
|
| 60 | 0 |
public void setDataSource(DataSource dataSource) { |
| 61 | 0 |
queryRunner.setDataSource(dataSource); |
| 62 |
} |
|
| 63 |
|
|
| 64 |
/**
|
|
| 65 |
* @see org.huihoo.jfox.soaf.services.persistence.JdbcService#query(java.sql.Connection,
|
|
| 66 |
* java.lang.String, java.lang.Object,
|
|
| 67 |
* org.apache.commons.dbutils.ResultSetHandler)
|
|
| 68 |
*/
|
|
| 69 | 0 |
public Object query(Connection conn, String sql, Object param,
|
| 70 |
ResultSetHandler rsh) throws DAOException {
|
|
| 71 | 0 |
try {
|
| 72 | 0 |
return queryRunner.query(conn, sql, param, rsh);
|
| 73 |
} catch (SQLException e) {
|
|
| 74 | 0 |
throw new DAOException("Failed to query - sql [" + sql |
| 75 |
+ "], parameterObject [" + param + "]. Cause: " + e, e); |
|
| 76 |
} |
|
| 77 |
} |
|
| 78 |
|
|
| 79 |
/**
|
|
| 80 |
* @see org.huihoo.jfox.soaf.services.persistence.JdbcService#query(java.sql.Connection,
|
|
| 81 |
* java.lang.String, java.lang.Object[],
|
|
| 82 |
* org.apache.commons.dbutils.ResultSetHandler)
|
|
| 83 |
*/
|
|
| 84 | 0 |
public Object query(Connection conn, String sql, Object[] params,
|
| 85 |
ResultSetHandler rsh) throws DAOException {
|
|
| 86 | 0 |
try {
|
| 87 | 0 |
return queryRunner.query(conn, sql, params, rsh);
|
| 88 |
} catch (SQLException e) {
|
|
| 89 | 0 |
throw new DAOException("Failed to query - sql [" + sql |
| 90 |
+ "]. Cause: " + e, e);
|
|
| 91 |
} |
|
| 92 |
} |
|
| 93 |
|
|
| 94 |
/**
|
|
| 95 |
* @see org.huihoo.jfox.soaf.services.persistence.JdbcService#query(java.sql.Connection,
|
|
| 96 |
* java.lang.String, org.apache.commons.dbutils.ResultSetHandler)
|
|
| 97 |
*/
|
|
| 98 | 0 |
public Object query(Connection conn, String sql, ResultSetHandler rsh)
|
| 99 |
throws DAOException {
|
|
| 100 | 0 |
try {
|
| 101 | 0 |
return queryRunner.query(conn, sql, rsh);
|
| 102 |
} catch (SQLException e) {
|
|
| 103 | 0 |
throw new DAOException("Failed to query - sql [" + sql |
| 104 |
+ "]. Cause: " + e, e);
|
|
| 105 |
} |
|
| 106 |
} |
|
| 107 |
|
|
| 108 |
/**
|
|
| 109 |
* @see org.huihoo.jfox.soaf.services.persistence.JdbcService#query(java.lang.String,
|
|
| 110 |
* java.lang.Object, org.apache.commons.dbutils.ResultSetHandler)
|
|
| 111 |
*/
|
|
| 112 | 0 |
public Object query(String sql, Object param, ResultSetHandler rsh)
|
| 113 |
throws DAOException {
|
|
| 114 | 0 |
try {
|
| 115 | 0 |
return queryRunner.query(sql, param, rsh);
|
| 116 |
} catch (SQLException e) {
|
|
| 117 | 0 |
throw new DAOException("Failed to query - sql [" + sql |
| 118 |
+ "]. Cause: " + e, e);
|
|
| 119 |
} |
|
| 120 |
} |
|
| 121 |
|
|
| 122 |
/**
|
|
| 123 |
* @see org.huihoo.jfox.soaf.services.persistence.JdbcService#query(java.lang.String,
|
|
| 124 |
* java.lang.Object[], org.apache.commons.dbutils.ResultSetHandler)
|
|
| 125 |
*/
|
|
| 126 | 0 |
public Object query(String sql, Object[] params, ResultSetHandler rsh)
|
| 127 |
throws DAOException {
|
|
| 128 | 0 |
try {
|
| 129 | 0 |
return queryRunner.query(sql, params, rsh);
|
| 130 |
} catch (SQLException e) {
|
|
| 131 | 0 |
throw new DAOException("Failed to query - sql [" + sql |
| 132 |
+ "]. Cause: " + e, e);
|
|
| 133 |
} |
|
| 134 |
} |
|
| 135 |
|
|
| 136 |
/**
|
|
| 137 |
* @see org.huihoo.jfox.soaf.services.persistence.JdbcService#query(java.lang.String,
|
|
| 138 |
* org.apache.commons.dbutils.ResultSetHandler)
|
|
| 139 |
*/
|
|
| 140 | 0 |
public Object query(String sql, ResultSetHandler rsh) throws DAOException { |
| 141 | 0 |
try {
|
| 142 | 0 |
return queryRunner.query(sql, rsh);
|
| 143 |
} catch (SQLException e) {
|
|
| 144 | 0 |
throw new DAOException("Failed to query - sql [" + sql |
| 145 |
+ "]. Cause: " + e, e);
|
|
| 146 |
} |
|
| 147 |
} |
|
| 148 |
|
|
| 149 |
/**
|
|
| 150 |
* @see org.huihoo.jfox.soaf.services.persistence.JdbcService#update(java.sql.Connection,
|
|
| 151 |
* java.lang.String, java.lang.Object)
|
|
| 152 |
*/
|
|
| 153 | 0 |
public int update(Connection conn, String sql, Object param) |
| 154 |
throws DAOException {
|
|
| 155 | 0 |
try {
|
| 156 | 0 |
return queryRunner.update(conn, sql);
|
| 157 |
} catch (SQLException e) {
|
|
| 158 | 0 |
throw new DAOException("Failed to query - sql [" + sql |
| 159 |
+ "]. Cause: " + e, e);
|
|
| 160 |
} |
|
| 161 |
} |
|
| 162 |
|
|
| 163 |
/**
|
|
| 164 |
* @see org.huihoo.jfox.soaf.services.persistence.JdbcService#update(java.sql.Connection,
|
|
| 165 |
* java.lang.String, java.lang.Object[])
|
|
| 166 |
*/
|
|
| 167 | 0 |
public int update(Connection conn, String sql, Object[] params) |
| 168 |
throws DAOException {
|
|
| 169 | 0 |
try {
|
| 170 | 0 |
return queryRunner.update(conn, sql, conn);
|
| 171 |
} catch (SQLException e) {
|
|
| 172 | 0 |
throw new DAOException("Failed to query - sql [" + sql |
| 173 |
+ "]. Cause: " + e, e);
|
|
| 174 |
} |
|
| 175 |
} |
|
| 176 |
|
|
| 177 |
/**
|
|
| 178 |
* @see org.huihoo.jfox.soaf.services.persistence.JdbcService#update(java.sql.Connection,
|
|
| 179 |
* java.lang.String)
|
|
| 180 |
*/
|
|
| 181 | 0 |
public int update(Connection conn, String sql) throws DAOException { |
| 182 | 0 |
try {
|
| 183 | 0 |
return queryRunner.update(sql);
|
| 184 |
} catch (SQLException e) {
|
|
| 185 | 0 |
throw new DAOException("Failed to query - sql [" + sql |
| 186 |
+ "]. Cause: " + e, e);
|
|
| 187 |
} |
|
| 188 |
} |
|
| 189 |
|
|
| 190 |
/**
|
|
| 191 |
* @see org.huihoo.jfox.soaf.services.persistence.JdbcService#update(java.lang.String,
|
|
| 192 |
* java.lang.Object)
|
|
| 193 |
*/
|
|
| 194 | 0 |
public int update(String sql, Object param) throws DAOException { |
| 195 | 0 |
try {
|
| 196 | 0 |
return queryRunner.update(sql, param);
|
| 197 |
} catch (SQLException e) {
|
|
| 198 | 0 |
throw new DAOException("Failed to query - sql [" + sql |
| 199 |
+ "]. Cause: " + e, e);
|
|
| 200 |
} |
|
| 201 |
} |
|
| 202 |
|
|
| 203 |
/**
|
|
| 204 |
* @see org.huihoo.jfox.soaf.services.persistence.JdbcService#update(java.lang.String,
|
|
| 205 |
* java.lang.Object[])
|
|
| 206 |
*/
|
|
| 207 | 0 |
public int update(String sql, Object[] params) throws DAOException { |
| 208 | 0 |
try {
|
| 209 | 0 |
return queryRunner.update(sql, params);
|
| 210 |
} catch (SQLException e) {
|
|
| 211 | 0 |
throw new DAOException("Failed to query - sql [" + sql |
| 212 |
+ "]. Cause: " + e, e);
|
|
| 213 |
} |
|
| 214 |
} |
|
| 215 |
|
|
| 216 |
/**
|
|
| 217 |
* @see org.huihoo.jfox.soaf.services.persistence.JdbcService#update(java.lang.String)
|
|
| 218 |
*/
|
|
| 219 | 0 |
public int update(String sql) throws DAOException { |
| 220 | 0 |
try {
|
| 221 | 0 |
return queryRunner.update(sql);
|
| 222 |
} catch (SQLException e) {
|
|
| 223 | 0 |
throw new DAOException("Failed to query - sql [" + sql |
| 224 |
+ "]. Cause: " + e, e);
|
|
| 225 |
} |
|
| 226 |
} |
|
| 227 |
} |
|
||||||||||