📄 executeimpl.java
字号:
package org.speedframework.engine.impl;
import org.speedframework.cache.*;
import org.speedframework.util.*;
import java.util.Map;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.Statement;
import java.util.List;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.apache.log4j.Logger;
import org.speedframework.engine.Execute;
import org.speedframework.exception.SpeedException;
import org.speedframework.execute.ExecuteHelper;
import org.speedframework.execute.ExecuteHelpserFactory;
import java.sql.CallableStatement;
/**
* <p>
* Title: SpeedFrameworkWork持久层框架
* </p>
*
* <p>
* Description: 数据访问持久层
* </p>
*
* <p>
* Copyright: Copyright (c) 2005
* </p>
*
* <p>
* Company: SpeedFrameworkWork
* </p>
*
* @author 李志峰 电话:13824431576 程伟杰 电话:13926047208
* @version 1.1beta
*/
/**
* @author lizf
*
*/
public class ExecuteImpl implements Execute {
private static final Logger log = Logger.getLogger(ExecuteImpl.class);
private Connection con;
private ExecuteHelper psh;
public ExecuteImpl( Connection con,String dbtype){
this.psh=ExecuteHelpserFactory.getExecuteHelper(con,dbtype);
this.con=con;
}
public List insert(String SQL, Object[] parmvalue,
boolean useCache) throws SpeedException {
PreparedStatement ps = null;
List keys = null;
try {
log.debug(SQL);
keys = psh.executeInsert(ps, SQL,
parmvalue);
String table = SQLHelper.getInsertTable(SQL);
if (ConfigureHelper.getGlobalCacheStatus() && useCache) {
CacheManage.RemoveCache(table);
}
if (ps != null) {
ps.close();
}
} catch (Exception e) {
throw new SpeedException(e);
}
return keys;
}
/**
* update
*
* @param con
* Connection
* @param SQL
* String
* @param parm
* String[]
* @throws Exception
*/
public void update( String SQL, Object[] param,
boolean useCache) throws SpeedException {
PreparedStatement ps = null;
try {
log.debug(SQL);
if (SQL == null || param.length == 0) {
throw new Exception();
}
psh.setExecuteUpdate(ps, SQL, param);
String table = SQLHelper.getUpdateTable(SQL);
if (ConfigureHelper.getGlobalCacheStatus() && useCache) {
CacheManage.RemoveCache(table);
}
} catch (Exception e) {
throw new SpeedException(e);
} finally {
if (ps != null) {
try {
ps.close();
} catch (SQLException ex) {
throw new SpeedException(ex);
}
}
}
}
/**
* select
*
* @param con
* Connection
* @param SQL
* String
* @param entity
* Object
* @param voclass
* Class
* @return List
*/
public List select( String SQL, Object entity,
Class voclass, boolean useCache) throws SpeedException {
List list = SQLHelper.getSelectParam(SQL);
Object[] parmvalue = ParamHelper.getParamValue(list, entity);
List rlist = this.select(SQL, parmvalue, voclass, useCache);
return rlist;
}
/**
* select
*
* @param con
* Connection
* @param SQL
* String
* @param parm
* String[]
* @param voclass
* Class
* @throws Exception
* @return List
*/
public List select( String SQL, Object[] parmvalue,
Class voclass, boolean useCache) throws SpeedException {
PreparedStatement ps = null;
ResultSet rs = null;
// SQL = SQL.toLowerCase();
List relist = null;
try {
log.debug(SQL);
if (ConfigureHelper.getGlobalCacheStatus() && useCache) {
relist = CacheManage.FindCache(parmvalue, SQL);
}
if (relist == null) {
ps = con.prepareStatement(SQL);
rs = psh.setExecuteQuery(ps, parmvalue);
relist = RowsUtils.copyRows(rs, voclass);
if (ConfigureHelper.getGlobalCacheStatus() && useCache) {
CacheManage.put(parmvalue, SQL, relist);
}
}
} catch (Exception e) {
throw new SpeedException(e);
} finally {
try {
if (rs != null) {
rs.close();
}
if (ps != null) {
ps.close();
}
} catch (SQLException ex) {
throw new SpeedException(ex);
}
}
return relist;
}
/**
* insert
*
* @param con
* Connection
* @param SQL
* String
* @param entity
* Object
* @throws Exception
*/
public List insert( String SQL, Object entity,
boolean useCache) throws SpeedException {
List list = SQLHelper.getInsertParam(SQL);
Object[] param = ParamHelper.getParamValue(list, entity);
return this.insert( SQL, param, useCache);
}
/**
* update
*
* @param con
* Connection
* @param SQL
* String
* @param entity
* Object
* @throws Exception
*/
public void update( String SQL, Object entity,
boolean useCache) throws SpeedException {
List list = SQLHelper.getUpdateParam(SQL);
Object[] param = ParamHelper.getParamValue(list, entity);
this.update(SQL, param, useCache);
}
/**
* delete
*
* @param con
* Connection
* @param SQL
* String
* @param entity
* Object
*/
public void delete( String SQL, Object entity,
boolean useCache) throws SpeedException {
List list = SQLHelper.getDeleteParam(SQL);
Object[] param = ParamHelper.getParamValue(list, entity);
this.delete( SQL, param, useCache);
}
/**
* delete
*
* @param con
* Connection
* @param SQL
* String
* @param parm
* String[]
* @throws Exception
*/
public void delete( String SQL, Object[] param,
boolean useCache) throws SpeedException {
PreparedStatement ps = null;
try {
log.debug(SQL);
psh.setExecuteUpdate(ps, SQL, param);
String table = SQLHelper.getDeleteTabel(SQL);
if (ConfigureHelper.getGlobalCacheStatus() && useCache) {
CacheManage.RemoveCache(table);
}
} catch (Exception e) {
throw new SpeedException(e);
} finally {
if (ps != null) {
try {
ps.close();
} catch (SQLException ex) {
throw new SpeedException(ex);
}
}
}
}
public int getDataCount( String SQL, Object[] params,
boolean useCache) throws SpeedException {
// String type = SQLHelper.getDataBaseType(con);
// String sql = SQLHelper.getCountSQL(type, SQL);
List rlist = this.select( SQL, params, null, useCache);
Map map = (Map) rlist.get(0);
return Integer.parseInt(map.get("count_").toString());
}
/**
* executeBatch
*
* @param con
* Connection
* @param SQL
* String
* @param parm
* String[][]
*/
public void executeBatch( String SQL, Object[][] params,
boolean useCache) throws SpeedException {
try {
log.debug(SQL);
psh.executeBatch(SQL, params);
// String table = SQLHelper.getInsertTable(SQL);
String table = SQLHelper.getExecuteBatchTable(SQL);
if (ConfigureHelper.getGlobalCacheStatus() && useCache) {
CacheManage.RemoveCache(table);
}
} catch (Exception ex) {
throw new SpeedException(ex);
}
}
/**
* executeBatch
*
* @param con
* Connection
* @param SQL
* String
* @param list
* List
*/
public void executeBatch( String SQL, List list) {
}
/*
* (非 Javadoc)
*
* @see org.speedframework.engine.Execute#executeCall(java.sql.Connection,
* java.lang.String, java.lang.Object[], java.lang.Class, boolean)
*/
public List executeCall( String SQL, Object[] params,
Class voclass, boolean useCache) {
List relist = null;
CallableStatement proc = null;
ResultSet rs = null;
SQL = SQL.toLowerCase();
try {
log.debug(SQL);
psh.setExecuteCall(proc, SQL, params);
if (voclass != null) {
rs = (ResultSet) proc.getObject(1);
relist = RowsUtils.copyRows(rs, voclass);
}
} catch (Exception ex) {
throw new SpeedException(ex);
} finally {
try {
if (rs != null) {
rs.close();
}
if (proc != null) {
proc.close();
}
} catch (SQLException ex) {
throw new SpeedException(ex);
}
}
return relist;
}
/*
* (非 Javadoc)
*
* @see org.speedframework.engine.Execute#select(java.sql.Connection,
* java.lang.String, java.lang.Class, boolean)
*/
public List select( String SQL, Class voclass,
boolean useCache) throws SpeedException {
Object[] parmvalue = {};
Statement st = null;
ResultSet rs = null;
// SQL = SQL.toLowerCase();
List relist = null;
try {
log.debug(SQL);
if (ConfigureHelper.getGlobalCacheStatus() && useCache) {
relist = CacheManage.FindCache(parmvalue, SQL);
}
if (relist == null) {
st = con.createStatement();
rs = st.executeQuery(SQL);
relist = RowsUtils.copyRows(rs, voclass);
if (ConfigureHelper.getGlobalCacheStatus() && useCache) {
CacheManage.put(parmvalue, SQL, relist);
}
}
} catch (Exception e) {
throw new SpeedException(e);
} finally {
try {
if (rs != null) {
rs.close();
}
if (st != null) {
st.close();
}
} catch (SQLException ex) {
throw new SpeedException(ex);
}
}
return relist;
}
/*
* (非 Javadoc)
*
* @see org.speedframework.engine.Execute#executeFunction(java.sql.Connection,
* java.lang.String, java.lang.Object[], java.lang.Class, boolean)
*/
public Object executeFunction( String SQL, Object[] params,int returnType,
Class voclass, boolean useCache) throws SpeedException {
CallableStatement cstmt = null;
try {
log.debug(SQL);
return psh.setFunctionCall(cstmt, SQL, params,returnType);
} catch (Exception ex) {
throw new SpeedException(ex);
} finally {
try {
if (cstmt != null) {
cstmt.close();
}
} catch (SQLException e) {
throw new SpeedException(e);
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -