/**
|
* <p>Title:</p>
|
* <p>Description:</p>
|
* <p>Copyright: Copyright (C) 2011 </p>
|
* <p>Company: VCI </p>
|
* @author Bear
|
* @time 2011-8-22
|
* @version 1.0
|
*/
|
package com.vci.server.base.persistence.dao;
|
|
import java.sql.Connection;
|
import java.sql.ResultSet;
|
import java.sql.SQLException;
|
import java.util.LinkedHashMap;
|
|
public abstract class JDBCCallback {
|
private java.sql.Connection cn = null;
|
private String sql = "";
|
private Object[] params = null;
|
private JDBCRunType runType = JDBCRunType.Function;
|
private int returnSqlType = 1;
|
private boolean isHasRefCursorOut = false;
|
private boolean closeConnectionInFinally = false;
|
|
/**
|
* 输出参数类型Maps(key:索引,value:输出参数类型<see>java.sql.Types</see>)
|
*/
|
private LinkedHashMap<Integer, Integer> outParamTypeMaps = new LinkedHashMap<Integer, Integer>();
|
/**
|
* 输出参数数据Maps(key:索引,value:输出参数数据值(Object))
|
*/
|
private LinkedHashMap<Integer, Object> outParamValueMaps = new LinkedHashMap<Integer, Object>();
|
|
/**
|
* 构建 callback 对象
|
* @param cn 连接
|
* @param sql sql
|
* @param runType 执行对象的类型 fun or proc or sql @see<p>com.vci.base.server.persistence.dao.JDBCRunType</p>
|
* @param returnSqlType 返回值类型(仅适应于fun)
|
* @param hasRefCursorOut 是否包含引用标参数(仅适应于proc)
|
* @param closeConnectionInFinally
|
* <p>根据参数选项,决定要不要关闭连接对象</p>
|
* <p>1.如果此连接来自于与Session连接池中的Connection,不需要关闭此连接,此时值应该传 <b>false</b></p>
|
* <p>2.如果此连接来自与DB创建的新连接(无连接池或不是从连接池中取出的连接),则需要即时关闭,此时值应该传 <b>true</b></p>
|
* <p>3.对于在启用了Hibernate的应用中,不需要即时关闭连接,此时值应该传 <b>false</b></p>
|
* @param params 参数值
|
*/
|
public JDBCCallback(Connection cn, String sql,
|
JDBCRunType runType, int returnSqlType, boolean isHasRefCursorOut,
|
boolean closeConnectionInFinally, Object[] params) {
|
super();
|
this.cn = cn;
|
this.sql = sql;
|
this.params = params;
|
this.runType = runType;
|
this.returnSqlType = returnSqlType;
|
this.isHasRefCursorOut = isHasRefCursorOut;
|
this.closeConnectionInFinally = closeConnectionInFinally;
|
}
|
/**
|
* 构建 callback 对象
|
* @param cn 连接
|
* @param sql sql
|
* @param runType 执行对象的类型 fun or proc or sql @see<p>com.vci.base.server.persistence.dao.JDBCRunType</p>
|
* @param returnSqlType 返回值类型(仅适应于fun)
|
* @param hasRefCursorOut 是否包含引用标参数(仅适应于proc)
|
* @param closeConnectionInFinally
|
* <p>根据参数选项,决定要不要关闭连接对象</p>
|
* <p>1.如果此连接来自于与Session连接池中的Connection,不需要关闭此连接,此时值应该传 <b>false</b></p>
|
* <p>2.如果此连接来自与DB创建的新连接(无连接池或不是从连接池中取出的连接),则需要即时关闭,此时值应该传 <b>true</b></p>
|
* <p>3.对于在启用了Hibernate的应用中,不需要即时关闭连接,此时值应该传 <b>false</b></p>
|
* @param outParamTypeMaps 输出参数类型Maps(key:索引,value:输出参数类型<see>java.sql.Types</see>)
|
* @param outParamValueMaps 输出参数数据Maps(key:索引,value:输出参数数据值(Object))
|
* @param params 参数值
|
*/
|
public JDBCCallback(Connection cn, String sql,
|
JDBCRunType runType, int returnSqlType, boolean isHasRefCursorOut,
|
boolean closeConnectionInFinally, Object[] params,
|
LinkedHashMap<Integer, Integer> outParamTypeMaps) {
|
this(cn, sql, runType, returnSqlType, isHasRefCursorOut, closeConnectionInFinally, params);
|
this.outParamTypeMaps = outParamTypeMaps;
|
}
|
|
public java.sql.Connection getCn() {
|
return cn;
|
}
|
public void setCn(java.sql.Connection cn) {
|
this.cn = cn;
|
}
|
|
public String getSql() {
|
return sql;
|
}
|
|
public void setSql(String sql) {
|
this.sql = sql;
|
}
|
|
public Object[] getParams() {
|
return params;
|
}
|
|
public void setParams(Object[] params) {
|
this.params = params;
|
}
|
|
public int getReturnSqlType() {
|
return returnSqlType;
|
}
|
|
public void setReturnSqlType(int returnSqlType) {
|
this.returnSqlType = returnSqlType;
|
}
|
|
public boolean isHasRefCursorOut() {
|
return isHasRefCursorOut;
|
}
|
|
public void setHasRefCursorOut(boolean isHasRefCursorOut) {
|
this.isHasRefCursorOut = isHasRefCursorOut;
|
}
|
|
public JDBCRunType getRunType() {
|
return runType;
|
}
|
|
public void setRunType(JDBCRunType runType) {
|
this.runType = runType;
|
}
|
|
public boolean isCloseConnectionInFinally() {
|
return closeConnectionInFinally;
|
}
|
public void setCloseConnectionInFinally(boolean closeConnectionInFinally) {
|
this.closeConnectionInFinally = closeConnectionInFinally;
|
}
|
/**
|
* 返回输出参数类型Maps(key:索引,value:输出参数类型<see>java.sql.Types</see>)
|
* @return
|
*/
|
public LinkedHashMap<Integer, Integer> getOutParamTypeMaps() {
|
return outParamTypeMaps;
|
}
|
/**
|
* 设置输出参数类型Maps(key:索引,value:输出参数类型<see>java.sql.Types</see>)
|
* @param outParamTypeMaps
|
*/
|
public void setOutParamTypeMaps(LinkedHashMap<Integer, Integer> outParamTypeMaps) {
|
this.outParamTypeMaps = outParamTypeMaps;
|
}
|
/**
|
* 返回 输出参数数据Maps(key:索引,value:输出参数数据值(Object))
|
* @return
|
*/
|
public LinkedHashMap<Integer, Object> getOutParamValueMaps() {
|
return outParamValueMaps;
|
}
|
/**
|
* 设置 输出参数数据Maps(key:索引,value:输出参数数据值(Object))
|
* @param outParamValueMaps
|
*/
|
public void setOutParamValueMaps(LinkedHashMap<Integer, Object> outParamValueMaps) {
|
this.outParamValueMaps = outParamValueMaps;
|
}
|
/**
|
* 执行回调
|
* @param rst ResultSet 对象
|
* @return
|
* @throws SQLException
|
*/
|
abstract public Object execute(ResultSet rst) throws SQLException;
|
}
|