1.HYPubBO_Client类
该类是对实例对象VO进行相关操作,里面的方法都是公共静态方法,所以调用的话就用类引用相关的方法即可。
public class HYPubBO_Client {
private static IUifService service = (IUifService) NCLocator.getInstance().lookup(IUifService.class.getName());
/**
* @return Returns the service.
*/
public static IUifService getService() throws UifException {
return service;
}
/**
* @param billVo
* @throws UifException
*/
public static void checkConsistence(AggregatedValueObject billVo) throws UifException {
getService().checkConsistence(billVo);
}
/**
* @param billVo
* @return
* @throws UifException
*/
public static ArrayList commitBill(AggregatedValueObject billVo) throws UifException {
return getService().commitBill(billVo);
}
/**
* @param vo
* @throws UifException
*/
public static void delete(SuperVO vo) throws UifException {
getService().delete(vo);
}
/**
* @param billVo
* @param userObj
* @return
* @throws UifException
*/
public static AggregatedValueObject deleteBD(AggregatedValueObject billVo,
Object userObj) throws UifException {
return getService().deleteBD(billVo, userObj);
}
/**
* @param billVo
* @return
* @throws UifException
*/
public static AggregatedValueObject deleteBill(AggregatedValueObject billVo)
throws UifException {
return getService().deleteBill(billVo);
}
/**
* @param c
* @param where
* @throws UifException
*/
public static void deleteByWhereClause(Class c, String where)
throws UifException {
getService().deleteByWhereClause(c, where);
}
/**
* @param tablename
* @param fieldname
* @param strwhere
* @return
* @throws java.rmi.UifException
*/
public static Object findColValue(String tablename, String fieldname,
String strwhere) throws UifException {
return getService().findColValue(tablename, fieldname, strwhere);
}
/**
* @param billtype
* @param pk_corp
* @param vo
* @param intNum
* @return
* @throws java.rmi.UifException
*/
public static String[] getBatchBillNo(String billtype, String pk_corp,
BillCodeObjValueVO vo, int intNum) throws UifException {
return getService().getBatchBillNo(billtype, pk_corp, vo, intNum);
}
/**
* @param billtype
* @param pk_corp
* @param custBillCode
* @param vo
* @return
* @throws java.rmi.UifException
*/
public static String getBillNo(String billtype, String pk_corp,
String custBillCode, BillCodeObjValueVO vo) throws UifException {
return getService().getBillNo(billtype, pk_corp, custBillCode, vo);
}
/**
* @param vo
* @return
* @throws UifException
*/
public static String insert(SuperVO vo) throws UifException {
return getService().insert(vo);
}
/**
* @param vo
* @return
* @throws UifException
*/
public static String[] insertAry(SuperVO[] vo) throws UifException {
return getService().insertAry(vo);
}
/**
* @param voClass
* @return
* @throws UifException
*/
public static SuperVO[] queryAll(Class voClass) throws UifException {
return getService().queryAll(voClass);
}
/**
* @param strBillType
* @param c
* @param key
* @param strWhere
* @return
* @throws UifException
*/
public static CircularlyAccessibleValueObject[] queryAllBodyData(
String strBillType, Class c, String key, String strWhere)
throws UifException {
return getService().queryAllBodyData(strBillType, c, key, strWhere);
}
/**
* @param billFinderClassName
* @param id
* @param type
* @return
* @throws UifException
*/
public static LightBillVO queryBillGraph(String billFinderClassName, String id,
String type) throws UifException {
return getService().queryBillGraph(billFinderClassName, id, type);
}
/**
* @param billFinderClassName
* @param id
* @param type
* @return
* @throws UifException
*/
public static LightBillVO queryBillGraph(String billFinderClassName,
String id, String type, LinkQueryType queryType) throws UifException {
return getService().queryBillGraph(billFinderClassName, id, type, queryType);
}
/**
* @param userObj
* @param strWhere
* @return
* @throws UifException
*/
public static AggregatedValueObject[] queryBillVOByCondition(Object userObj,
String strWhere) throws UifException {
return getService().queryBillVOByCondition(userObj, strWhere);
}
/**
* @param userObj
* @param parentPK
* @return
* @throws UifException
*/
public static AggregatedValueObject queryBillVOByPrimaryKey(Object userObj,
String parentPK) throws UifException {
return getService().queryBillVOByPrimaryKey(userObj, parentPK);
}
/**
* @param voClass
* @param strWhere
* @return
* @throws UifException
*/
public static SuperVO[] queryByCondition(Class voClass, String strWhere)
throws UifException {
return getService().queryByCondition(voClass, strWhere);
}
/**
* @param voClass
* @param pk
* @return
* @throws UifException
*/
public static SuperVO queryByPrimaryKey(Class voClass, String pk)
throws UifException {
return getService().queryByPrimaryKey(voClass, pk);
}
/**
* @param billVo
* @param userObj
* @return
* @throws UifException
*/
public static AggregatedValueObject saveBD(AggregatedValueObject billVo,
Object userObj) throws UifException {
return getService().saveBD(billVo, userObj);
}
/**
* @param billVos
* @param userObj
* @return
* @throws UifException
*/
public static AggregatedValueObject[] saveBDs(AggregatedValueObject[] billVos,
Object userObj) throws UifException {
return getService().saveBDs(billVos, userObj);
}
/**
* @param billVo
* @return
* @throws UifException
*/
public static AggregatedValueObject saveBill(AggregatedValueObject billVo)
throws UifException {
return getService().saveBill(billVo);
}
/**
* @param billVo
* @return
* @throws UifException
*/
public static AggregatedValueObject setBillTs(AggregatedValueObject billVo)
throws UifException {
return getService().setBillTs(billVo);
}
/**
* @param vo
* @throws UifException
*/
public static void update(SuperVO vo) throws UifException {
getService().update(vo);
}
/**
* @param vo
* @throws UifException
*/
public static void updateAry(SuperVO[] vo) throws UifException {
getService().updateAry(vo);
}
}
2.IUAPQueryBS接口 API :只能做数据查询
使用方式,如:
IUAPQueryBS queryBS = (IUAPQueryBS) NCLocator.getInstance().lookup(IUAPQueryBS.class.getName());
String sql = "select * from bd_psndoc where nvl(dr, 0) = 0"
queryBS.executeQuery(sql, BeanProcessor.class);//ArrayListProcessor,ArrayProcessor,BeanProcessor,BeanListProcessor, ColumnProcessor,ColumnListProcessor,MapProcessor,MapListProcessor
IUAPQueryBS接口的具体方法
public interface IUAPQueryBS {
abstract public Collection retrieveByCorp(Class c, String pkCorp,
String[] selectedFields) throws BusinessException;
abstract public Collection retrieveByCorp(Class c, String pkCorp)
throws BusinessException;
abstract public Object retrieveByPK(Class className, String pk)
throws BusinessException;
abstract public Object retrieveByPK(Class className, String pk,
String[] selectedFields) throws BusinessException;
public Collection retrieveByClause(Class className, String condition,
String[] fields) throws BusinessException;
/**
* @since 5.5
* @param className
* @param condition
* @param fields
* @param param
* @return
* @throws BusinessException
*/
public Collection retrieveByClause(Class className, String condition,
String[] fields, SQLParameter param) throws BusinessException;
public Collection retrieve(SuperVO vo, boolean isAnd, String[] fields)
throws BusinessException;
public Collection retrieve(SuperVO vo, boolean isAnd)
throws BusinessException;
/**
* 查询VO对应表所有数据
*
* @param className
* @return
* @throws DbException
*/
public Collection retrieveAll(Class className) throws BusinessException;
/**
* 根据条件查询VO对应表数据
*
* @param className
* @param condition
* @return
* @throws DbException
*/
public Collection retrieveByClause(Class className, String condition)
throws BusinessException;
/**
* 执行一个有参数SQL查询
*
* @param sql
* 查询的SQL语句
* @param parameter
* 查询参数
* @param processor
* 结果集处理器
* @return
* @throws BusinessException
* 查询出错则抛出异常
*/
public Object executeQuery(String sql, SQLParameter parameter,
ResultSetProcessor processor) throws BusinessException;
/**
* 执行一个无参数的SQL查询
*
* @param sql
* 查询的SQL语句
* @param processor
* 结果集处理器
* @return
* @throws BusinessException
* 查询出错则抛出异常
*/
public Object executeQuery(String sql, ResultSetProcessor processor)
throws BusinessException;
/**
* 根据值对象的属性值为条件查询对应数据
*
* @param vo
* 值对象
* @param meta
* 数据映射信息
* @return
* @throws DbException
* 如果查询出错则抛出DbException
*/
public abstract Collection retrieve(Object vo, IMappingMeta meta)
throws BusinessException;
/**
* 根据数据映射信息查询对应的所有数据
*
* @param className
* 对象名
* @param meta
* 数据映射信息
* @return
* @throws DbException
* 如果查询出错则抛出DbException
*/
public abstract Collection retrieveAll(Class className, IMappingMeta meta)
throws BusinessException;
public abstract Collection retrieveByClause(Class className,
IMappingMeta meta, String condition, String[] fields)
throws BusinessException;
public abstract Collection retrieveByClause(Class className,
IMappingMeta meta, String condition, String[] fields,
SQLParameter param) throws BusinessException;
public abstract Collection retrieveByClause(Class className,
IMappingMeta meta, String condition) throws BusinessException;
}
3.IVOPersistence接口API :只能做增 删 改操作
IVOPersistence voPer = (IVOPersistence) NCLocator.getInstance().lookup(IVOPersistence.class.getName())
1.BaseDAO
后台是使用BaseDAO类来进行数据库的相关操作的,而BaseDAO类是实现了IVOPersistence,和IUAPQueryBS两个接口,所以操作方法也基本和IVOPersistence, IUAPQueryBS一样。
final public class BaseDAO implements IVOPersistence, IUAPQueryBS {
private String dataSource = null;
int maxRows = -1;
boolean addTimestamp = true;
/**
* 默认构造函数,将使用当前数据源
*/
public BaseDAO() {
}
/**
* 有参构造函数,将使用指定数据源
*
* @param dataSource
* 数据源名称
*/
public BaseDAO(String dataSource) {
super();
this.dataSource = dataSource;
}
/**
* 根据SQL 执行数据库查询,并返回ResultSetProcessor处理后的对象 (非 Javadoc)
*
* @param sql
* 查询的SQL
* @param processor
* 结果集处理器
*/
public Object executeQuery(String sql, ResultSetProcessor processor)
throws DAOException {
PersistenceManager manager = null;
Object value = null;
try {
manager = createPersistenceManager(dataSource);
JdbcSession session = manager.getJdbcSession();
value = session.executeQuery(sql, processor);
} catch (DbException e) {
Logger.error(e.getMessage(), e);
throw new DAOException(e.getMessage());
} finally {
if (manager != null)
manager.release();
}
return value;
}
/**
* 根据指定SQL 执行有参数的数据库查询,并返回ResultSetProcessor处理后的对象
*
* @param sql
* 查询的SQL
* @param parameter
* 查询参数
* @param processor
* 结果集处理器
*/
public Object executeQuery(String sql, SQLParameter parameter,
ResultSetProcessor processor) throws DAOException {
PersistenceManager manager = null;
Object value = null;
try {
manager = createPersistenceManager(dataSource);
;
JdbcSession session = manager.getJdbcSession();
value = session.executeQuery(sql, parameter, processor);
} catch (DbException e) {
Logger.error(e.getMessage(), e);
throw new DAOException(e.getMessage());
} finally {
if (manager != null)
manager.release();
}
return value;
}
/**
* 根据指定SQL 执行有参数的数据库更新操作
*
* @param sql
* 更新的sql
* @param parameter
* 更新参数
* @return
* @throws DAOException
* 更新发生错误抛出DAOException
*/
public int executeUpdate(String sql, SQLParameter parameter)
throws DAOException {
PersistenceManager manager = null;
int value;
try {
manager = createPersistenceManager(dataSource);
JdbcSession session = manager.getJdbcSession();
value = session.executeUpdate(sql, parameter);
} catch (DbException e) {
Logger.error(e.getMessage(), e);
throw new DAOException(e.getMessage());
} finally {
if (manager != null)
manager.release();
}
return value;
}
/**
* 根据指定SQL 执行无参数的数据库更新操作
*
* @param sql
* 更新的sql
* @return
* @throws DAOException
* 更新发生错误抛出DAOException
*/
public int executeUpdate(String sql) throws DAOException {
PersistenceManager manager = null;
int value;
try {
manager = createPersistenceManager(dataSource);
JdbcSession session = manager.getJdbcSession();
value = session.executeUpdate(sql);
} catch (DbException e) {
Logger.error(e.getMessage(), e);
throw new DAOException(e.getMessage());
} finally {
if (manager != null)
manager.release();
}
return value;
}
/**
* 根据VO类名查询该VO对应表的所有数据
*
* @param className
* SuperVo类名
*
* @return
* @throws DAOException
* 发生错误抛出DAOException
*/
public Collection retrieveAll(Class className) throws DAOException {
PersistenceManager manager = null;
Collection values = null;
try {
manager = createPersistenceManager(dataSource);
values = manager.retrieveAll(className);
} catch (DbException e) {
Logger.error(e.getMessage(), e);
throw new DAOException(e.getMessage());
} finally {
if (manager != null)
manager.release();
}
return values;
}
/**
* 根据VO类名和where条件返回vo集合
*
* @param className
* Vo类名称
* @param condition
* 查询条件
* @return 返回Vo集合
* @throws DAOException
* 发生错误抛出DAOException
*/
public Collection retrieveByClause(Class className, String condition)
throws DAOException {
PersistenceManager manager = null;
Collection values = null;
try {
manager = createPersistenceManager(dataSource);
values = manager.retrieveByClause(className, condition);
} catch (DbException e) {
Logger.error(e.getMessage(), e);
throw new DAOException(e.getMessage());
} finally {
if (manager != null)
manager.release();
}
return values;
}
public Collection retrieveByClause(Class className, String condition,
SQLParameter params) throws DAOException {
return retrieveByClause(className, condition, (String[]) null, params);
}
/**
* 根据条件和排序返回Vo集合
*
* @param className
* VO类名
* @param condition
* 查询条件
* @param orderBy
* 排序条件
* @return 返回Vo集合
* @throws DAOException
* 发生错误抛出DAOException
*/
public Collection retrieveByClause(Class className, String condition,
String orderBy) throws DAOException {
return retrieveByClause(className, appendOrderBy(condition, orderBy),
(String[]) null, null);
}
public Collection retrieveByClause(Class className, String condition,
String orderBy, SQLParameter params) throws DAOException {
return retrieveByClause(className, appendOrderBy(condition, orderBy),
(String[]) null, params);
}
/**
* 根据VO类名和where条件返回指定列的vo集合
*
* @param className
* 类名称
* @param condition
* 查询条件
* @param fields
* 指定的字段名
*
*/
public Collection retrieveByClause(Class className, String condition,
String[] fields) throws DAOException {
return retrieveByClause(className, condition, fields, null);
}
public Collection retrieveByClause(Class className, String condition,
String[] fields, SQLParameter params) throws DAOException {
PersistenceManager manager = null;
Collection values = null;
try {
manager = createPersistenceManager(dataSource);
values = manager.retrieveByClause(className, condition, fields,
params);
} catch (DbException e) {
Logger.error(e.getMessage(), e);
throw new DAOException(e.getMessage());
} finally {
if (manager != null)
manager.release();
}
return values;
}
/**
* 根据VO类名和where条件及排序条件返回指定列的vo集合
*
* @param className
* 类名
* @param condition
* 查询条件
* @param orderBy
* 排序条件
* @param fields
* 指定列
* @return
* @throws DAOException
*/
public Collection retrieveByClause(Class className, String condition,
String orderBy, String[] fields) throws DAOException {
return retrieveByClause(className, appendOrderBy(condition, orderBy),
fields);
}
public Collection retrieveByClause(Class className, String condition,
String orderBy, String[] fields, SQLParameter params)
throws DAOException {
return retrieveByClause(className, appendOrderBy(condition, orderBy),
fields, params);
}
private String appendOrderBy(String condition, String orderBy) {
StringBuffer clause = new StringBuffer();
if (condition != null)
clause.append(condition);
if (orderBy != null && condition == null)
clause.append("ORDER BY ").append(orderBy);
if (orderBy != null && condition != null) {
clause.append(" ORDER BY ").append(orderBy);
}
return clause.toString();
}
/**
* 通过where条件查询所有满足条件的vo数组。 支持多表 创建日期:(2002-6-12)
*
* @param c
* Class
* @param strWhere
* String
* @return SuperVO[]
* @throws Exception
* 异常说明。
*/
@SuppressWarnings("unchecked")
public Object[] retrieveByClause(Class c, SqlSupportVO[] sqlvos,
String fromStr, String strWhere, String strOrderBy)
throws DAOException {
if (sqlvos == null || sqlvos.length == 0)
throw new NullPointerException("Sqlvos is null;");
if (fromStr == null)
throw new NullPointerException("fromStr is null;");
String[][] fields = new String[2][sqlvos.length];
MappingMeta meta = new MappingMeta("", "");
for (int i = 0; i < sqlvos.length; i++) {
fields[0][i] = sqlvos[i].getSqlSelectField();
fields[1][i] = sqlvos[i].getVoAttributeName();
meta.addMapping(sqlvos[i].getVoAttributeName(),
sqlvos[i].getSqlSelectField());
}
PersistenceManager manager = null;
try {
manager = createPersistenceManager(this.dataSource);
JdbcSession session = manager.getJdbcSession();
StringBuffer sql = new StringBuffer("SELECT ");
for (int i = 0; i < fields[0].length; i++) {
sql.append(fields[0][i]);
if (i != fields[0].length - 1)
sql.append(",");
}
sql.append(" FROM ").append(fromStr);
// create where sentence
if (strWhere != null && strWhere.trim().length() != 0) {
sql.append(" WHERE ").append(strWhere);
}
// create order by sentence
if (strOrderBy != null && strOrderBy.trim().length() != 0) {
sql.append(" ORDER BY ").append(strOrderBy);
}
BaseProcessor processor = new BeanMappingListProcessor(c, meta);
List result = (List) session
.executeQuery(sql.toString(), processor);
return result.toArray((Object[]) Array.newInstance(c, 0));
} catch (DbException e) {
Logger.error(e.getMessage(), e);
throw new DAOException(e.getMessage());
} finally {
if (manager != null)
manager.release();
}
}
/**
* 根据VO中的属性值作为匹配条件从数据库中查询该VO对应的表的数据
*
* @param vo
* 要查询的VO对象
* @param isAnd
* 指定匹配条件的逻辑(true代表&&,flase代表||)
* @return
* @throws DAOException
* 如果查询出错抛出DAOException
*/
public Collection retrieve(SuperVO vo, boolean isAnd) throws DAOException {
PersistenceManager manager = null;
Collection values = null;
try {
manager = createPersistenceManager(dataSource);
values = manager.retrieve(vo, isAnd);
} catch (DbException e) {
Logger.error(e.getMessage(), e);
throw new DAOException(e.getMessage());
} finally {
if (manager != null)
manager.release();
}
return values;
}
public Collection retrieveOrderBy(SuperVO vo, boolean isAnd,
String[] orderbyFields) throws DAOException {
return retrieve(vo, isAnd, null, orderbyFields);
}
public Collection retrieve(SuperVO vo, boolean isAnd, String[] fields,
String[] orderbyFields) throws DAOException {
PersistenceManager manager = null;
Collection values = null;
try {
manager = createPersistenceManager(dataSource);
values = manager.retrieve(vo, isAnd, fields, orderbyFields);
} catch (DbException e) {
Logger.error(e.getMessage(), e);
throw new DAOException(e.getMessage());
} finally {
if (manager != null)
manager.release();
}
return values;
}
/**
* 根据指定VO的值以及逻辑条件返回指定字段的VO集合
*
* @param vo
* 条件VO
* @param isAnd
* 逻辑条件,true代表与运算false代表或运算
*
*
*/
public Collection retrieve(SuperVO vo, boolean isAnd, String[] fields)
throws DAOException {
PersistenceManager manager = null;
Collection values = null;
try {
manager = createPersistenceManager(dataSource);
values = manager.retrieve(vo, isAnd, fields);
} catch (DbException e) {
Logger.error(e.getMessage(), e);
throw new DAOException(e.getMessage());
} finally {
if (manager != null)
manager.release();
}
return values;
}
/**
* 根据公司名和指定字段返回VO集合
*
* @param className
* VO类名
* @param pkCorp
* 公司主键
* @param selectedFields
* 查询字段
*
*/
public Collection retrieveByCorp(Class className, String pkCorp,
String[] selectedFields) throws DAOException {
PersistenceManager manager = null;
Collection values = null;
try {
manager = createPersistenceManager(dataSource);
values = manager.retrieveByCorp(className, pkCorp, selectedFields);
} catch (DbException e) {
Logger.error(e.getMessage(), e);
throw new DAOException(e.getMessage());
} finally {
if (manager != null)
manager.release();
}
return values;
}
/**
* 根据公司PK返回指定VO集合
*
* @param className
* VO名称
* @param 公司PK
*
*/
public Collection retrieveByCorp(Class className, String pkCorp)
throws DAOException {
PersistenceManager manager = null;
Collection values = null;
try {
manager = createPersistenceManager(dataSource);
values = manager.retrieveByCorp(className, pkCorp);
} catch (DbException e) {
Logger.error(e.getMessage(), e);
throw new DAOException(e.getMessage());
} finally {
if (manager != null)
manager.release();
}
return values;
}
/**
* 根据PK查询指定VO
*
* @param VO类名
* @param pk
* 主键
*
*/
public Object retrieveByPK(Class className, String pk) throws DAOException {
PersistenceManager manager = null;
Object values = null;
try {
manager = createPersistenceManager(dataSource);
values = manager.retrieveByPK(className, pk);
} catch (DbException e) {
Logger.error(e.getMessage(), e);
throw new DAOException(e.getMessage());
} finally {
if (manager != null)
manager.release();
}
return values;
}
/**
* 根据主键返回指定列的VO对象
*/
public Object retrieveByPK(Class className, String pk,
String[] selectedFields) throws DAOException {
PersistenceManager manager = null;
Object values = null;
try {
manager = createPersistenceManager(dataSource);
values = manager.retrieveByPK(className, pk, selectedFields);
} catch (DbException e) {
Logger.error(e.getMessage(), e);
throw new DAOException(e.getMessage());
} finally {
if (manager != null)
manager.release();
}
return values;
}
/**
* 插入一个VO对象,如果该VO的主键值非空则插入VO的原有主键
*
* @param vo
* @return
* @throws DAOException
*/
public String insertVOWithPK(SuperVO vo) throws DAOException {
PersistenceManager manager = null;
String pk = null;
try {
manager = createPersistenceManager(dataSource);
;
pk = manager.insertWithPK(vo);
} catch (DbException e) {
Logger.error(e.getMessage(), e);
throw new DAOException(e.getMessage());
} finally {
if (manager != null)
manager.release();
}
return pk;
}
/**
* 插入一个VO对象
*
* @param vo
* SuperVO对象
*
*/
public String insertVO(SuperVO vo) throws DAOException {
PersistenceManager manager = null;
String pk = null;
try {
manager = createPersistenceManager(dataSource);
;
pk = manager.insert(vo);
} catch (DbException e) {
Logger.error(e.getMessage(), e);
throw new DAOException(e.getMessage());
} finally {
if (manager != null)
manager.release();
}
return pk;
}
/**
* 插入一个VO数组如果该VO的主键值非空则插入VO的原有主键
*
* @param vo
* @return
* @throws DAOException
*/
public String[] insertVOArrayWithPK(SuperVO[] vo) throws DAOException {
PersistenceManager manager = null;
String pk[] = null;
try {
manager = createPersistenceManager(dataSource);
;
pk = manager.insertWithPK(vo);
} catch (DbException e) {
Logger.error(e.getMessage(), e);
throw new DAOException(e.getMessage());
} finally {
if (manager != null)
manager.release();
}
return pk;
}
/**
* 插入VO数组
*
* @param vo
* VO数组
*/
public String[] insertVOArray(SuperVO[] vo) throws DAOException {
PersistenceManager manager = null;
String pk[] = null;
try {
manager = createPersistenceManager(dataSource);
;
pk = manager.insert(vo);
} catch (DbException e) {
Logger.error(e.getMessage(), e);
throw new DAOException(e.getMessage());
} finally {
if (manager != null)
manager.release();
}
return pk;
}
/**
* 插入VO集合
*
* @param vos
* VO集合
*/
public String[] insertVOList(List vos) throws DAOException {
PersistenceManager manager = null;
String pk[] = null;
try {
manager = createPersistenceManager(dataSource);
;
pk = manager.insert(vos);
} catch (DbException e) {
Logger.error(e.getMessage(), e);
throw new DAOException(e.getMessage());
} finally {
if (manager != null)
manager.release();
}
return pk;
}
/**
* 根据IMappingMeta插入一个VO对象,该VO的主键值非空则插入VO的原有主键
*
* @param vo
* VO对象
* @param meta
* IMappingMeta
* @return
* @throws DAOException
*/
public String insertObjectWithPK(Object vo, IMappingMeta meta)
throws DAOException {
PersistenceManager manager = null;
try {
manager = createPersistenceManager(dataSource);
;
return manager.insertObjectWithPK(vo, meta);
} catch (DbException e) {
Logger.error(e.getMessage(), e);
throw new DAOException(e.getMessage());
} finally {
if (manager != null)
manager.release();
}
}
/**
* 根据IMappingMeta插入一个VO对象
*
* @param vo
* VO对象
* @param meta
* IMappingMeta
*/
public String insertObject(Object vo, IMappingMeta meta)
throws DAOException {
PersistenceManager manager = null;
try {
manager = createPersistenceManager(dataSource);
;
return manager.insertObject(vo, meta);
} catch (DbException e) {
Logger.error(e.getMessage(), e);
throw new DAOException(e.getMessage());
} finally {
if (manager != null)
manager.release();
}
}
/**
* 根据IMappingMeta插入VO对象集合,该VO的主键值非空则插入VO的原有主键
*
* @param vo
* VO对象集合
* @param meta
* IMappingMeta
* @return
* @throws DAOException
*/
public String[] insertObjectWithPK(Object[] vo, IMappingMeta meta)
throws DAOException {
PersistenceManager manager = null;
try {
manager = createPersistenceManager(dataSource);
;
return manager.insertObjectWithPK(vo, meta);
} catch (DbException e) {
Logger.error(e.getMessage(), e);
throw new DAOException(e.getMessage());
} finally {
if (manager != null)
manager.release();
}
}
/**
* 根据IMappingMeta插入VO对象集合
*
* @param vo
* VO对象集合
* @param meta
* IMappingMeta
* @return
* @throws DAOException
*/
public String[] insertObject(Object[] vo, IMappingMeta meta)
throws DAOException {
PersistenceManager manager = null;
try {
manager = createPersistenceManager(dataSource);
return manager.insertObject(vo, meta);
} catch (DbException e) {
Logger.error(e.getMessage(), e);
throw new DAOException(e.getMessage());
} finally {
if (manager != null)
manager.release();
}
}
/**
* 根据VO对象更新数据库
*
* @param vo
* VO对象
*/
public int updateVO(SuperVO vo) throws DAOException {
return updateVOArray(new SuperVO[] { vo });
}
/**
* 根据VO对象中指定列更新数据库
*
* @param vos
* VO对象
* @param fieldNames
* 指定列
* @throws DAOException
*/
public void updateVO(SuperVO vo, String[] fieldNames) throws DAOException {
updateVOArray(new SuperVO[] { vo }, fieldNames);
}
/**
* 根据VO对象数组更新数据库
*
* @param vo
* VO对象
*/
public int updateVOArray(SuperVO[] vos) throws DAOException {
return updateVOArray(vos, null);
}
/**
* 根据VO对象数组中指定列更新数据库
*
* @param vos
* VO对象
* @param fieldNames
* 指定列
*/
public int updateVOArray(SuperVO[] vos, String[] fieldNames)
throws DAOException {
return updateVOArray(vos, fieldNames, null, null);
}
/**
* 根据VO对象集合更新数据库
*
* @paramvos VO对象集合
*/
public void updateVOList(List vos) throws DAOException {
PersistenceManager manager = null;
try {
manager = createPersistenceManager(dataSource);
manager.update(vos);
} catch (DbException e) {
Logger.error(e.getMessage(), e);
throw new DAOException(e.getMessage());
} finally {
if (manager != null)
manager.release();
}
}
/**
* 根据VO对象和MappingMeta信息更新数据库
*
* @param vo
* VO对象
* @param meta
* MappingMeta信息
*/
public int updateObject(Object vo, IMappingMeta meta) throws DAOException {
return updateObject(vo, meta, null);
}
public int updateObject(Object[] vos, IMappingMeta meta)
throws DAOException {
return updateObject(vos, meta, null);
}
/**
* 在数据库中删除一组VO对象。
*
* @param SuperVO
* [] vos
* @throws Exception
* 异常说明。
*/
public UpdateResultVO execUpdateByVoState(SuperVO[] vos,
String[] selectedFields) throws DAOException {
ArrayList<SuperVO> listInsert = new ArrayList<SuperVO>();
ArrayList<SuperVO> listUpdate = new ArrayList<SuperVO>();
ArrayList<SuperVO> listDelete = new ArrayList<SuperVO>();
for (int i = 0; i < vos.length; i++) {
int status = vos[i].getStatus();
if (status == nc.vo.pub.VOStatus.NEW)
listInsert.add(vos[i]);
else if (status == nc.vo.pub.VOStatus.UPDATED)
listUpdate.add(vos[i]);
else if (status == nc.vo.pub.VOStatus.DELETED)
listDelete.add(vos[i]);
}
UpdateResultVO rsVO = new UpdateResultVO();
if (listInsert.size() > 0) {
rsVO.setPks(insertVOArray((SuperVO[]) listInsert
.toArray(new SuperVO[listInsert.size()])));
}
if (listUpdate.size() > 0) {
updateVOArray((SuperVO[]) listUpdate.toArray(new SuperVO[listUpdate
.size()]), selectedFields);
}
if (listDelete.size() > 0) {
deleteVOArray((SuperVO[]) listDelete.toArray(new SuperVO[listDelete
.size()]));
}
return rsVO;
}
/**
* 在数据库中删除一组VO对象。
*
* @param SuperVO
* [] vos
* @throws Exception
* 异常说明。
*/
public UpdateResultVO execUpdateByVoState(SuperVO[] vos)
throws DAOException {
return execUpdateByVoState(vos, null);
}
/**
* 在数据库中删除一个VO对象。
*
* @param vo
* VO对象
* @throws DAOException
* 如果删除出错抛出DAOException
*/
public void deleteVO(SuperVO vo) throws DAOException {
PersistenceManager manager = null;
try {
manager = createPersistenceManager(dataSource);
manager.delete(vo);
} catch (DbException e) {
Logger.error(e.getMessage(), e);
throw new DAOException(e.getMessage());
} finally {
if (manager != null)
manager.release();
}
}
/**
* 在数据库中删除一组VO对象。
*
* @param vos
* VO数组对象
* @throws DAOException
* 如果删除出错抛出DAOException
*/
public void deleteVOArray(SuperVO[] vos) throws DAOException {
PersistenceManager manager = null;
try {
manager = createPersistenceManager(dataSource);
manager.delete(vos);
} catch (DbException e) {
Logger.error(e.getMessage(), e);
throw new DAOException(e.getMessage());
} finally {
if (manager != null)
manager.release();
}
}
/**
* 在数据库中根据类名和PK数组删除一组VO对象集合
*
* @param className
* 要删除的VO类名
* @param pks
* PK数组
* @throws DAOException
* 如果删除出错抛出DAOException
*/
public void deleteByPKs(Class className, String[] pks) throws DAOException {
PersistenceManager manager = null;
try {
manager = createPersistenceManager(dataSource);
manager.deleteByPKs(className, pks);
} catch (DbException e) {
Logger.error(e.getMessage(), e);
throw new DAOException(e.getMessage());
} finally {
if (manager != null)
manager.release();
}
}
/**
* 在数据库中根据类名和条件删除数据
*
* @param className
* VO类名
* @param wherestr
* 条件
* @throws DAOException
* 如果删除出错抛出DAOException
*/
public void deleteByClause(Class className, String wherestr)
throws DAOException {
PersistenceManager manager = null;
try {
manager = createPersistenceManager(dataSource);
manager.deleteByClause(className, wherestr);
} catch (DbException e) {
Logger.error(e.getMessage(), e);
throw new DAOException(e.getMessage());
} finally {
if (manager != null)
manager.release();
}
}
public void deleteByClause(Class className, String wherestr,
SQLParameter params) throws DAOException {
PersistenceManager manager = null;
try {
manager = createPersistenceManager(dataSource);
manager.deleteByClause(className, wherestr, params);
} catch (DbException e) {
Logger.error(e.getMessage(), e);
throw new DAOException(e.getMessage());
} finally {
if (manager != null)
manager.release();
}
}
/**
* 在数据库中根据类名和PK删除一个VO对象集合
*
* @param className
* VO类名
* @param pk
* PK值
* @throws DAOException
* 如果删除出错抛出DAOException
*/
public void deleteByPK(Class className, String pk) throws DAOException {
PersistenceManager manager = null;
try {
manager = createPersistenceManager(dataSource);
manager.deleteByPK(className, pk);
} catch (DbException e) {
Logger.error(e.getMessage(), e);
throw new DAOException(e.getMessage());
} finally {
if (manager != null)
manager.release();
}
}
/**
* 在数据库中删除一组VO对象集合
*
* @param vos
* VO对象集合
* @throws DAOException
* 如果删除出错抛出DAOException
*/
public void deleteVOList(List vos) throws DAOException {
PersistenceManager manager = null;
try {
manager = createPersistenceManager(dataSource);
manager.delete(vos);
} catch (DbException e) {
Logger.error(e.getMessage(), e);
throw new DAOException(e.getMessage());
} finally {
if (manager != null)
manager.release();
}
}
/**
* 根据VO中的属性值和IMappingMeta删除指定数据
*
* @param vo
* vo对象
* @param meta
* IMappingMeta
*
*/
public void deleteObject(Object vo, IMappingMeta meta) throws DAOException {
PersistenceManager manager = null;
try {
manager = createPersistenceManager(dataSource);
manager.deleteObject(vo, meta);
} catch (DbException e) {
Logger.error(e.getMessage(), e);
throw new DAOException(e.getMessage());
} finally {
if (manager != null)
manager.release();
}
}
/**
* 根据VO数组中的属性值和IMappingMeta删除指定数据
*
* @param vo
* vo数组
* @param meta
* IMappingMeta
*/
public void deleteObject(Object[] vos, IMappingMeta meta)
throws DAOException {
PersistenceManager manager = null;
try {
manager = createPersistenceManager(dataSource);
manager.deleteObject(vos, meta);
} catch (DbException e) {
Logger.error(e.getMessage(), e);
throw new DAOException(e.getMessage());
} finally {
if (manager != null)
manager.release();
}
}
/**
* 根据VO数组中的属性值和IMappingMeta删除指定数据
*
* @param vo
* vo数组
* @param meta
* IMappingMeta
* @param dealNull
* 是否处理空字段
* @throws DAOException
*/
public void deleteObject(Object[] vos, IMappingMeta meta, boolean dealNull)
throws DAOException {
PersistenceManager manager = null;
try {
manager = createPersistenceManager(dataSource);
manager.deleteObject(vos, meta, dealNull);
} catch (DbException e) {
Logger.error(e.getMessage(), e);
throw new DAOException(e.getMessage());
} finally {
if (manager != null)
manager.release();
}
}
/**
* 根据IMappingMeta返回VO数组集合
*
* @param vo
* vo对象
* @param meta
* IMappingMeta
*/
public Collection retrieve(Object vo, IMappingMeta meta)
throws DAOException {
PersistenceManager manager = null;
try {
manager = createPersistenceManager(dataSource);
return manager.retrieve(vo, meta);
} catch (DbException e) {
Logger.error(e.getMessage(), e);
throw new DAOException(e.getMessage());
} finally {
if (manager != null)
manager.release();
}
}
/**
* 根据IMappingMeta返回指定Class的VO对象集合
*
* @param className
* 类名称
* @param meta
* IMappingMeta
*/
public Collection retrieveAll(Class className, IMappingMeta meta)
throws DAOException {
PersistenceManager manager = null;
try {
manager = createPersistenceManager(dataSource);
return manager.retrieveAll(className, meta);
} catch (DbException e) {
Logger.error(e.getMessage(), e);
throw new DAOException(e.getMessage());
} finally {
if (manager != null)
manager.release();
}
}
/**
* 根据IMappingMeta和查询条件返回指定Class的VO对象集合
*
* @param className
* 类名称
* @param condition
* 查询条件
* @param meta
* IMappingMeta
*/
public Collection retrieveByClause(Class className, IMappingMeta meta,
String condition) throws DAOException {
PersistenceManager manager = null;
try {
manager = createPersistenceManager(dataSource);
return manager.retrieveByClause(className, meta, condition);
} catch (DbException e) {
Logger.error(e.getMessage(), e);
throw new DAOException(e.getMessage());
} finally {
if (manager != null)
manager.release();
}
}
public Collection retrieveByClause(Class className, IMappingMeta meta,
String condition, SQLParameter params) throws DAOException {
return retrieveByClause(className, meta, condition, (String[]) null,
params);
}
public Collection retrieveByClause(Class className, IMappingMeta meta,
String condition, String[] fields, SQLParameter params)
throws DAOException {
PersistenceManager manager = null;
try {
manager = createPersistenceManager(dataSource);
return manager.retrieveByClause(className, meta, condition, fields,
params);
} catch (DbException e) {
Logger.error(e.getMessage(), e);
throw new DAOException(e.getMessage());
} finally {
if (manager != null)
manager.release();
}
}
/**
* 根据条件和 IMappingMeta查询返回指定列的VO集合
*
* @param className
* 类名
* @param meta
* IMappingMeta
* @param condition
* 指定条件
* @param fields
* 查询列
*/
public Collection retrieveByClause(Class className, IMappingMeta meta,
String condition, String[] fields) throws DAOException {
PersistenceManager manager = null;
try {
manager = createPersistenceManager(dataSource);
return manager.retrieveByClause(className, meta, condition, fields);
} catch (DbException e) {
Logger.error(e.getMessage(), e);
throw new DAOException(e.getMessage());
} finally {
if (manager != null)
manager.release();
}
}
/**
* 根据IMappingMeta和传入条件删除数据
*
* @param meta
* @param wherestr
* @return
* @throws DAOException
*/
public int deleteByClause(IMappingMeta meta, String wherestr)
throws DAOException {
return deleteByClause(meta, wherestr, null);
}
public int deleteByClause(IMappingMeta meta, String wherestr,
SQLParameter params) throws DAOException {
PersistenceManager manager = null;
try {
manager = createPersistenceManager(dataSource);
return manager.deleteByClause(meta, wherestr, params);
} catch (DbException e) {
Logger.error(e.getMessage(), e);
throw new DAOException(e.getMessage());
} finally {
if (manager != null)
manager.release();
}
}
/**
* 根据PK和IMappingMeta删除指定数据
*
* @param meta
* IMappingMeta
* @param pk
* 主键
* @return
* @throws DAOException
*/
public int deleteByPK(IMappingMeta meta, String pk) throws DAOException {
PersistenceManager manager = null;
try {
manager = createPersistenceManager(dataSource);
return manager.deleteByPK(meta, pk);
} catch (DbException e) {
Logger.error(e.getMessage(), e);
throw new DAOException(e.getMessage());
} finally {
if (manager != null)
manager.release();
}
}
/**
* 根据IMappingMeta和公司pk返回指定列的VO集合
*
* @param c
* VO类名称
* @param meta
* IMappingMeta
* @param pkCorp
* 公司PK
* @param selectedFields
* 指定字段数组
* @return
* @throws DAOException
*/
public Collection retrieveByCorp(Class c, IMappingMeta meta, String pkCorp,
String[] selectedFields) throws DAOException {
PersistenceManager manager = null;
try {
manager = createPersistenceManager(dataSource);
return manager.retrieveByCorp(c, meta, pkCorp, selectedFields);
} catch (DbException e) {
Logger.error(e.getMessage(), e);
throw new DAOException(e.getMessage());
} finally {
if (manager != null)
manager.release();
}
}
/**
* 根据公司PK和IMappingMeta返回对应VO集合
*
* @param c
* VO类
* @param meta
* IMappingMeta
* @param pkCorp
* 公司PK
* @return
* @throws DAOException
*/
public Collection retrieveByCorp(Class c, IMappingMeta meta, String pkCorp)
throws DAOException {
PersistenceManager manager = null;
try {
manager = createPersistenceManager(dataSource);
return manager.retrieveByCorp(c, meta, pkCorp);
} catch (DbException e) {
Logger.error(e.getMessage(), e);
throw new DAOException(e.getMessage());
} finally {
if (manager != null)
manager.release();
}
}
/**
* 根据IMappingMeta和pk返回指定字段对应的VO对象
*
* @param className
* VO类名
* @param meta
* IMappingMeta
* @param pk
* 主键
* @return
* @throws DAOException
*/
public Object retrieveByPK(Class className, IMappingMeta meta, String pk,
String[] selectedFields) throws DAOException {
PersistenceManager manager = null;
try {
manager = createPersistenceManager(dataSource);
return manager.retrieveByPK(className, meta, pk, selectedFields);
} catch (DbException e) {
Logger.error(e.getMessage(), e);
throw new DAOException(e.getMessage());
} finally {
if (manager != null)
manager.release();
}
}
/**
* 根据IMappingMeta和pk返回对应的VO对象
*
* @param className
* VO类名
* @param meta
* IMappingMeta
* @param pk
* 主键
* @return
* @throws DAOException
*/
public Object retrieveByPK(Class className, IMappingMeta meta, String pk)
throws DAOException {
PersistenceManager manager = null;
try {
manager = createPersistenceManager(dataSource);
return manager.retrieveByPK(className, meta, pk);
} catch (DbException e) {
Logger.error(e.getMessage(), e);
throw new DAOException(e.getMessage());
} finally {
if (manager != null)
manager.release();
}
}
/**
* 根据 IMappingMeta和条件更新VO对象对应的数据库
*
* @param vos
* VO对象
* @param meta
* IMappingMeta
* @param whereClause
* 条件语句
* @return
* @throws DAOException
*/
public int updateObject(Object vo, IMappingMeta meta, String whereClause)
throws DAOException {
PersistenceManager manager = null;
try {
manager = createPersistenceManager(dataSource);
return manager.updateObject(vo, meta, whereClause);
} catch (DbException e) {
Logger.error(e.getMessage(), e);
throw new DAOException(e.getMessage());
} finally {
if (manager != null)
manager.release();
}
}
/**
* 根据 IMappingMeta和条件更新VO对象数组对应的数据库
*
* @param vos
* VO对象
* @param meta
* IMappingMeta
* @param whereClause
* 条件语句
* @return
* @throws DAOException
*/
public int updateObject(Object[] vos, IMappingMeta meta, String whereClause)
throws DAOException {
return updateObject(vos, meta, whereClause, null);
}
/**
* 根据 IMappingMeta和条件更新VO对象数组对应的数据库
*
* @param vos
* VO对象
* @param meta
* IMappingMeta
* @param whereClause
* 条件语句
* @return
* @throws DAOException
*/
public int updateObject(Object[] vos, IMappingMeta meta,
String whereClause, SQLParameter param) throws DAOException {
PersistenceManager manager = null;
try {
manager = createPersistenceManager(dataSource);
return manager.updateObject(vos, meta, whereClause, param);
} catch (DbException e) {
Logger.error(e.getMessage(), e);
throw new DAOException(e.getMessage());
} finally {
if (manager != null)
manager.release();
}
}
/**
* 获得数据源类型
*
* @param key
* nc.vo.pub.oid.OID
* @throws java.sql.SQLException
* 异常说明。
*/
public int getDBType() {
return DataSourceCenter.getInstance().getDatabaseType(dataSource);
}
/**
* 返回数据库相关的表名
*
* @param dbType
* int
* @param tableName
* java.lang.String
* @return java.lang.String
* @since :V1.00
*/
protected String getTableName(int dbType, String tableName) {
String strTn = tableName;
switch (dbType) {
case DBConsts.POSTGRESQL:
case DBConsts.ALCEDO:
strTn = tableName.toLowerCase();
break;
case DBConsts.ORACLE:
case DBConsts.OSCAR:
case DBConsts.DB2:
// ORACLE需将表名大写
strTn = tableName.toUpperCase();
break;
}
return strTn;
}
/**
* 判断数据表是否存在
*
* @param tableName
* 数据表名称
* @return
* @throws DAOException
* 出错抛出DAOException
*/
public boolean isTableExisted(String tableName) throws DAOException {
if (tableName == null)
throw new NullPointerException("TableName is null!");
PersistenceManager manager = null;
ResultSet rs = null;
try {
manager = createPersistenceManager(dataSource);
int dbType = manager.getDBType();
DatabaseMetaData dbmd = manager.getMetaData();
if (dbType == DBConsts.ORACLE || dbType == DBConsts.OSCAR
|| dbType == DBConsts.DB2 || dbType == DBConsts.POSTGRESQL
|| dbType == DBConsts.ALCEDO || dbType == DBConsts.GBASE) {
rs = dbmd.getTables(manager.getCatalog(), manager.getSchema(),
getTableName(dbType, tableName),
new String[] { "TABLE" });
} else {
rs = dbmd.getTables(null, null,
getTableName(dbType, tableName),
new String[] { "TABLE" });
}
while (rs.next()) {
return true;
}
return false;
} catch (Exception e) {
Logger.error(e.getMessage(), e);
throw new DAOException(e.getMessage());
} finally {
DBUtil.closeRs(rs);
if (manager != null)
manager.release();
}
}
public int getMaxRows() {
return maxRows;
}
public void setMaxRows(int maxRows) {
this.maxRows = maxRows;
}
/**
* Modified by cch , add this method 根据PK和IMappingMeta删除指定数据
*
* @param meta
* IMappingMeta
* @param pk
* 主键
* @return
* @throws DAOException
*/
public int deleteByPKs(IMappingMeta meta, String[] pks) throws DAOException {
PersistenceManager manager = null;
try {
manager = createPersistenceManager(dataSource);
return manager.deleteByPKs(meta, pks);
} catch (DbException e) {
Logger.error(e.getMessage(), e);
throw new DAOException(e.getMessage());
} finally {
if (manager != null)
manager.release();
}
}
public void setAddTimeStamp(boolean addTimeStamp) {
this.addTimestamp = addTimeStamp;
}
public boolean getAddTimeStamp() {
return addTimestamp;
}
private PersistenceManager createPersistenceManager(String ds)
throws DbException {
PersistenceManager manager = PersistenceManager.getInstance(ds);
manager.setMaxRows(maxRows);
manager.setAddTimeStamp(addTimestamp);
return manager;
}
public int updateVOArray(final SuperVO[] vos, String[] fieldNames,
String whereClause, SQLParameter param) throws DAOException {
PersistenceManager manager = null;
try {
manager = createPersistenceManager(dataSource);
return manager.update(vos, fieldNames, whereClause, param);
} catch (DbException e) {
Logger.error(e.getMessage(), e);
throw new DAOException(e.getMessage());
} finally {
if (manager != null)
manager.release();
}
}
}
其他数据库操作类,如
1.nc.impl.am.db.DBAccessUtil(资产管理数据库持久化操作。(非元数据))
2.nc.jdbc.framework.PersistenceManager (对象持久化管理器抽象类)
他人封装的接口和实现类:
1)、BaseDaoUtil后台实现接口:IPrivateUtilMaintain
package nc.itf.feikai;
import java.util.List;
import java.util.Map;
import nc.vo.pub.AggregatedValueObject;
import nc.vo.pub.BusinessException;
import nc.vo.uap.pf.PfProcessBatchRetObject;
/**
* @Description BaseDaoUtil后台实现接口
* @author 王晓旭
* @date 2019年5月9日
*/
public interface IPrivateUtilMaintain {
/**
* @Description 执行单据动作(独立事务),private端使用
*/
Object executeAction__RequiresNew(String actionName, String billtype, AggregatedValueObject aggVO) throws BusinessException;
/**
* @Description 批量执行单据动作(独立事务),private端使用
*/
PfProcessBatchRetObject executeBatch__RequiresNew(String actionName, String billtype, AggregatedValueObject[] aggVOs) throws BusinessException;
/**
* @Description 获取 NC 默认数据源名称
*/
String getDefaultDataSource();
/**
* @Description 根据SQL语句查询并返回多条结果。
* @param arguments 可变参数。 查询 NC 系统数据只需传递SQL语句。查询其他系统数据,第一个参数为数据源名称,第二个参数为SQL语句。
*/
List<Map<String, Object>> listResult(String... arguments);
/**
* @Description 根据SQL语句查询并返回单条结果。
* @param arguments 可变参数。 查询 NC 系统数据只需传递SQL语句。查询其他系统数据,第一个参数为数据源名称,第二个参数为SQL语句。
*/
Map<String, Object> mapResult(String... arguments);
/**
* @Description 根据SQL语句查询并返回单个字段多个结果。
* @param arguments 可变参数。 查询 NC 系统数据只需传递SQL语句。查询其他系统数据,第一个参数为数据源名称,第二个参数为SQL语句。
*/
List<String> columnList(String... arguments);
/**
* @Description 根据SQL语句查询并返回单个字段单个结果。
* @param arguments 可变参数。 查询 NC 系统数据只需传递SQL语句。查询其他系统数据,第一个参数为数据源名称,第二个参数为SQL语句。
*/
String columnResult(String... arguments);
/**
* @Description 根据SQL语句查询并返回VO List集合。
* @param clazz 返回的VO类型
* @param arguments 可变参数。 查询 NC 系统数据只需传递SQL语句。查询其他系统数据,第一个参数为数据源名称,第二个参数为SQL语句。
*/
<T> List<T> beanList(Class<T> clazz, String... arguments);
/**
* @Description 根据SQL语句查询并返回单个VO。
* @param clazz 返回的VO类型
* @param arguments 可变参数。 查询 NC 系统数据只需传递SQL语句。查询其他系统数据,第一个参数为数据源名称,第二个参数为SQL语句。
*/
<T> T beanResult(Class<T> clazz, String... arguments);
}
2)、BaseDaoUtil后台实现类:PrivateUtilMaintainImpl
package nc.impl.feikai;
import java.util.List;
import java.util.Map;
import nc.bs.framework.common.InvocationInfoProxy;
import nc.itf.feikai.IPrivateUtilMaintain;
import nc.pub.feikai.BaseDaoUtil;
import nc.vo.pub.AggregatedValueObject;
import nc.vo.pub.BusinessException;
import nc.vo.uap.pf.PfProcessBatchRetObject;
/**
* @Description BaseDaoUtil后台实现类
* @author 王晓旭
* @date 2019年5月9日
*/
public class PrivateUtilMaintainImpl implements IPrivateUtilMaintain {
/*
* 执行单据动作(独立事务)
*/
@Override
public Object executeAction__RequiresNew(String actionName, String billtype, AggregatedValueObject aggVO) throws BusinessException {
return BaseDaoUtil.executeAction(actionName, billtype, aggVO);
}
/*
* 执行单据动作(独立事务)
*/
@Override
public PfProcessBatchRetObject executeBatch__RequiresNew(String actionName, String billtype, AggregatedValueObject[] aggVOs) throws BusinessException {
return BaseDaoUtil.executeBatch(actionName, billtype, aggVOs);
}
/*
* 获取 NC 默认数据源名称
*/
@Override
public String getDefaultDataSource() {
return InvocationInfoProxy.getInstance().getUserDataSource();
}
@Override
public List<Map<String, Object>> listResult(String... arguments) {
return BaseDaoUtil.listResult(arguments);
}
@Override
public Map<String, Object> mapResult(String... arguments) {
return BaseDaoUtil.mapResult(arguments);
}
@Override
public List<String> columnList(String... arguments) {
return BaseDaoUtil.columnList(arguments);
}
@Override
public String columnResult(String... arguments) {
return BaseDaoUtil.columnResult(arguments);
}
@Override
public <T> List<T> beanList(Class<T> clazz, String... arguments) {
return BaseDaoUtil.beanList(clazz, arguments);
}
@Override
public <T> T beanResult(Class<T> clazz, String... arguments) {
return BaseDaoUtil.beanResult(clazz, arguments);
}
}
3)、BaseDaoUtil:数据库操作工具类
package nc.pub.feikai;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import nc.bs.dao.BaseDAO;
import nc.bs.framework.common.NCLocator;
import nc.bsutil.mmpub.dpub.SysParamUtil;
import nc.itf.feikai.IPrivateUtilMaintain;
import nc.itf.uap.IUAPQueryBS;
import nc.itf.uap.IVOPersistence;
import nc.itf.uap.pf.IplatFormEntry;
import nc.jdbc.framework.generator.SequenceGenerator;
import nc.jdbc.framework.processor.BeanListProcessor;
import nc.jdbc.framework.processor.BeanProcessor;
import nc.jdbc.framework.processor.ColumnListProcessor;
import nc.jdbc.framework.processor.ColumnProcessor;
import nc.jdbc.framework.processor.MapListProcessor;
import nc.jdbc.framework.processor.MapProcessor;
import nc.md.data.access.NCObject;
import nc.md.persist.framework.IMDPersistenceQueryService;
import nc.pub.iufo.basedoc.OrgUtil;
import nc.ui.gl.contrastpub.Currency;
import nc.ui.pub.bill.BillCardPanel;
import nc.ui.pubapp.util.CardPanelValueUtils;
import nc.vo.org.OrgVO;
import nc.vo.pub.AggregatedValueObject;
import nc.vo.pub.BusinessException;
import nc.vo.pubapp.AppContext;
import nc.vo.uap.pf.PfProcessBatchRetObject;
/**
* @Description 数据库操作工具类
* @author 王晓旭
* @date 2019年5月9日
*/
public class BaseDaoUtil {
/**
* 私有构造,禁止创建实例
*/
private BaseDaoUtil() {
throw new IllegalStateException("Utility class");
}
/**
* client中执行增删改的数据源
*/
public static final IVOPersistence clientDao = NCLocator.getInstance().lookup(IVOPersistence.class);
/**
* client查询数据源
*/
public static final IUAPQueryBS query = NCLocator.getInstance().lookup(IUAPQueryBS.class);
/**
* NC默认数据源
*/
public static final BaseDAO dao = new BaseDAO();
/**
* BaseDaoUtil private端实现类,用于client端调用
*/
public static final IPrivateUtilMaintain ipu = NCLocator.getInstance().lookup(IPrivateUtilMaintain.class);
/**
* 数据源参数名
*/
private static final String DATASOURCE = "dataSource";
/**
* sql语句参数名
*/
private static final String SQL = "sql";
/**
* @Description 根据SQL语句查询并返回多条结果。
* @param arguments 可变参数。 查询 NC 系统数据只需传递SQL语句。查询其他系统数据,第一个参数为数据源名称,第二个参数为SQL语句。
*/
@SuppressWarnings("unchecked")
public static List<Map<String, Object>> listResult(String... arguments) {
List<Map<String, Object>> result = new ArrayList<Map<String, Object>>();
// 参数集合
Map<String, String> argumentsMap = parseArguments(arguments);
try {
// 执行查询
result = (List<Map<String, Object>>) new BaseDAO(argumentsMap.get(DATASOURCE)).executeQuery(argumentsMap.get(SQL), new MapListProcessor());
} catch (Exception e) {
return result;
}
return result;
}
/**
* @Description 根据SQL语句查询并返回单条结果。
* @param arguments 可变参数。 查询 NC 系统数据只需传递SQL语句。查询其他系统数据,第一个参数为数据源名称,第二个参数为SQL语句。
*/
@SuppressWarnings("unchecked")
public static Map<String, Object> mapResult(String... arguments) {
Map<String, Object> result = new HashMap<String, Object>(16);
// 参数集合
Map<String, String> argumentsMap = parseArguments(arguments);
try {
// 执行查询
result = (Map<String, Object>) new BaseDAO(argumentsMap.get(DATASOURCE)).executeQuery(argumentsMap.get(SQL), new MapProcessor());
} catch (Exception e) {
return result;
}
return result;
}
/**
* @Description 根据SQL语句查询并返回单个字段多个结果。
* @param arguments 可变参数。 查询 NC 系统数据只需传递SQL语句。查询其他系统数据,第一个参数为数据源名称,第二个参数为SQL语句。
*/
@SuppressWarnings("unchecked")
public static List<String> columnList(String... arguments) {
List<String> result = new ArrayList<String>();
// 参数集合
Map<String, String> argumentsMap = parseArguments(arguments);
try {
// 执行查询
result = (List<String>) new BaseDAO(argumentsMap.get(DATASOURCE)).executeQuery(argumentsMap.get(SQL), new ColumnListProcessor());
} catch (Exception e) {
return result;
}
return result;
}
/**
* @Description 根据SQL语句查询并返回单个字段单个结果。
* @param arguments 可变参数。 查询 NC 系统数据只需传递SQL语句。查询其他系统数据,第一个参数为数据源名称,第二个参数为SQL语句。
*/
public static String columnResult(String... arguments) {
String result = null;
// 参数集合
Map<String, String> argumentsMap = parseArguments(arguments);
try {
// 执行查询
result = (String) new BaseDAO(argumentsMap.get(DATASOURCE)).executeQuery(argumentsMap.get(SQL), new ColumnProcessor());
} catch (Exception e) {
return result;
}
return result;
}
/**
* @Description 根据SQL语句查询并返回VO List集合。
* @param clazz 返回的VO类型
* @param arguments 可变参数。 查询 NC 系统数据只需传递SQL语句。查询其他系统数据,第一个参数为数据源名称,第二个参数为SQL语句。
*/
@SuppressWarnings("unchecked")
public static <T> List<T> beanList(Class<T> clazz, String... arguments) {
List<T> result = new ArrayList<T>();
// 参数集合
Map<String, String> argumentsMap = parseArguments(arguments);
try {
// 执行查询
result = (List<T>) new BaseDAO(argumentsMap.get(DATASOURCE)).executeQuery(argumentsMap.get(SQL), new BeanListProcessor(clazz));
} catch (Exception e) {
return result;
}
return result;
}
/**
* @Description 根据SQL语句查询并返回单个VO。
* @param clazz 返回的VO类型
* @param arguments 可变参数。 查询 NC 系统数据只需传递SQL语句。查询其他系统数据,第一个参数为数据源名称,第二个参数为SQL语句。
*/
@SuppressWarnings("unchecked")
public static <T> T beanResult(Class<T> clazz, String... arguments) {
T result = null;
// 参数集合
Map<String, String> argumentsMap = parseArguments(arguments);
try {
// 执行查询
result = (T) new BaseDAO(argumentsMap.get(DATASOURCE)).executeQuery(argumentsMap.get(SQL), new BeanProcessor(clazz));
} catch (Exception e) {
return result;
}
return result;
}
/**
* @Description 解析参数数组转化为Map集合
* @param arguments 参数数组
* @return 参数Map集合
*/
private static Map<String, String> parseArguments(String... arguments) {
// 参数Map集合
Map<String, String> argumentsMap = new HashMap<String, String>(16);
// 数据源名称
String dataSource = null;
// SQL语句
String sql = null;
// 解析参数数组
if (1 == arguments.length) {
sql = arguments[0];
} else if (2 == arguments.length) {
dataSource = arguments[0];
sql = arguments[1];
} else {
throw new IllegalArgumentException("The number of arguments is wrong");
}
// 添加参数至 Map集合
argumentsMap.put(DATASOURCE, dataSource);
argumentsMap.put(SQL, sql);
return argumentsMap;
}
/**
* @Description 执行单据动作
* @param actionName 单据动作名称
* @param billtype 单据类型编码
* @param aggVO 单据聚合VO
*/
public static Object executeAction(String actionName, String billtype, AggregatedValueObject aggvo) throws BusinessException {
IplatFormEntry iIplatFormEntry = (IplatFormEntry) NCLocator.getInstance().lookup(IplatFormEntry.class.getName());
return iIplatFormEntry.processAction(actionName, billtype, null, aggvo, null, null);
}
/**
* @Description 批量执行单据动作
* @param actionName 单据动作名称
* @param billtype 单据类型编码
* @param aggVO 单据聚合VO
*/
public static PfProcessBatchRetObject executeBatch(String actionName, String billtype, AggregatedValueObject[] aggvos) throws BusinessException {
IplatFormEntry iIplatFormEntry = (IplatFormEntry) NCLocator.getInstance().lookup(IplatFormEntry.class.getName());
return (PfProcessBatchRetObject) iIplatFormEntry.processBatch(actionName, billtype, null, aggvos, null, new HashMap<Object, Object>(16));
}
/**
* @Description 根据主键获VO(过滤dr=1的记录)
* @param pk 单据主键
* @param clazz VO类型
*/
@SuppressWarnings("unchecked")
public static <T> T getVOByPk (String pk, Class<T> clazz) {
T t = null;
try {
IMDPersistenceQueryService query = NCLocator.getInstance().lookup(IMDPersistenceQueryService.class);
NCObject ncObj = query.queryBillOfNCObjectByPKWithDR(clazz, pk, true);
if (null == ncObj) {
return null;
}
if (AggregatedValueObject.class.isAssignableFrom(clazz)) {
t = (T) ncObj.getContainmentObject();
} else {
t = (T) ncObj.getModelConsistObject();
}
} catch (Exception e) {
return t;
}
return t;
}
/**
* @Description 获取 NC 客户端当前登录用户主键
*/
public static String getPkUser() {
return AppContext.getInstance().getPkUser();
}
/**
* @Description 获取 NC 客户端业务日期
*/
public static String getBusiDate() {
return AppContext.getInstance().getBusiDate().toString();
}
/**
* @Description 获取 NC 集团主键
*/
public static String getPkGroup() {
return AppContext.getInstance().getPkGroup();
}
/**
* @Description 获取新的系统主键
*/
public static String getNCPK() {
return new SequenceGenerator().generate();
}
/**
* @Description 获取新的随机主键
*/
public static String getUUIDPK() {
return UUID.randomUUID().toString().substring(0, 20);
}
/**
* @Description 根据币种编码获取币种主键
*/
public static String getPkCurrtypeByCode(String currtypeCode) throws BusinessException {
return Currency.getCurrtypePkByCode(currtypeCode);
}
/**
* @Description 获取卡片界面取值工具类
*/
public static CardPanelValueUtils getKeyValue(BillCardPanel panel) {
return new CardPanelValueUtils(panel);
}
/**
* @Description 根据组织编码获取组织主键
*/
public static String getPkOrgByCode(String orgCode) {
OrgVO vo = OrgUtil.getOrgVOByCode(orgCode);
return null == vo ? null : vo.getPk_org();
}
/**
* @Description 获取业务单元级系统参数(布尔型)
* @param pk_org 组织主键
* @param param 系统参数编码
*/
public static boolean getSysParamAsBoolean(String pk_org, String param) {
return SysParamUtil.getParamValueAsBoolean(pk_org, param);
}
/**
* @Description 获取文件大小,单位MB
* @param file
* @return
*/
public static int getFileMbSize(File file) {
long bit = file.length();
if(bit < 1024) {
return 0;
}
bit = bit >> 10 >> 10 ;
return ( int ) bit;
}
}
//后台通过主表主键查询AggVO
BillQuery<AggUserVO> bq = new BillQuery<>(AggUserVO.class);
bq.query(pk);
//前台通过主表主键查询AggVO
HYPubBO_Client.queryBillVOByPrimaryKey(AggUserVO.class, pk)
//前后台都能用
IBillQueryService bq = NCLocator.getInstance().lookup(IBillQueryService.class);