1. 数据库事务

    事务基本上不需要开发人员关注,在框架里都做了封装。
    事务级别为服务级,服务进来时启动事务,服务退出时提交或回滚并关闭,支持服务调服务的事务控制,若当前服务只有查询,则不执行 Commit 或 Rallback。
    示例代码:

    try {
    	//启动模拟二阶段事务
    	SessionManager.getInstance().start(visit);
    	//事务提交
    	SessionManager.getInstance().commit();
    } catch (Exception e) {
    	//事务回滚
    	SessionManager.getInstance().rollback();
    } finally {
    	//注销
    	SessionManager.getInstance().destroy();
    }
    
  2. 数据库连接

    数据库连接配置在database.xml里,开发时可以指定配置,生产时将用统一配置覆盖。
    开发时配置示例如下:

    <database>
    	<framework
    		type="dbcp"
    		driver="oracle.jdbc.driver.OracleDriver"
    		url="jdbc:oracle:thin:@127.0.0.1:1521:ORACLE"
    		user="UOP_CEN1"
    		passwd="UOP_CEN1"
    		initialSize="5"
    		maxActive="10"
    		maxIdle="5"
    		maxWait="1000"
    		/>
    	<cen1
    		type="jdbc"
    		driver="oracle.jdbc.driver.OracleDriver"
    		url="jdbc:oracle:thin:@127.0.0.1:1521:ORACLE"
    		user="UOP_CEN1"
    		passwd="UOP_CEN1"
    		/>
    	<crm1
    		type="jndi"
    		jndi="framework"
    		/>
    </database>
    
  3. DAO 基类

    com.ailk.biz.bean.BizDAO 结构图及 API

    /**
     * 根据subsys.default创建默认的DAO
     * @param clazz
     * @return
     * @throws Exception
     */
    public static <Type extends IBaseDAO> Type createDAO(Class<Type> clazz) throws Exception
    
    /**
     * 根据subsys.group+routeId创建DAO
     * @param clazz
     * @param routeId
     * @return
     * @throws Exception
     */
    public static <Type extends IBaseDAO> Type createDAO(Class<Type> clazz,String routeId) throws Exception
    
    /**
     * get visit();
     * 
     * @return
     * @throws Exception
     */
    public static BizVisit getVisit() throws Exception 
    
    /**
     * reate data input
     * 
     * @param params
     * @return
     */
    public static IDataInput createDataInput() throws Exception 
    
    /**
     * create data input
     * 
     * @param params
     * @param pagin
     * @return
     */
    public static IDataInput createDataInput(IData params) throws Exception 
    
    /**
     * create data input
     * 
     * @param params
     * @param pagin
     * @return
     */
    public static IDataInput createDataInput(IData params, Pagination pagination) throws Exception 
    
    
    /**
     * get sql by code code
     * 
     * @param sqlref
     * @return IDataset
     * @throws Exception
     */
    public String getSqlByCodeCode(String sqlref) throws Exception 
    
    /**
     * get sql by code code
     * 
     * @param tabname
     * @param sqlref
     * @param codecode_Datasource
     * @return IDataset
     * @throws Exception
     */
    public String getSqlByCodeCode(String tabname, String sqlref) throws Exception 
    
    /**
     * query list by code code
     * 
     * @param sqlref
     * @param param
     * @return IDataset
     * @throws Exception
     */
    public IDataset queryListByCodeCode(String sqlref, IData param) throws Exception 
    
    /**
     * query list by code code
     * 
     * @param daoname
     * @param sqlref
     * @param param
     * @param codecode_Datasource
     * @return IDataset
     * @throws Exception
     */
    public IDataset queryListByCodeCode(String tabname, String sqlref, IData param) throws Exception 
    
    /**
     * query list by code code
     * 
     * @param tabname
     * @param sqlref
     * @param param
     * @param pagination
     * @param codecode_Datasource
     * @return IDataset
     * @throws Exception
     */
    public IDataset queryListByCodeCode(String tabname, String sqlref, IData param, Pagination pagination) throws Exception 
    
    /**
     * execute update by CodeCode
     * 
     * @param tabname
     * @param sqlref
     * @param param
     * @param codecode_Datasource
     * @return
     * @throws Exception
     */
    public int executeUpdateByCodeCode(String tabname, String sqlref, IData param) throws Exception 
    
    /**
     * execute batch by CodeCode
     * 
     * @param tabname
     * @param sqlref
     * @param params
     * @param codecode_Datasource
     * @return
     * @throws Exception
     */
    public int[] executeBatchByCodeCode(String tabname, String sqlref, IDataset params) throws Exception 
    
    /**
     * query list by code code parser
     * 
     * @param tabname
     * @param sqlref
     * @param param
     * @return IDataset
     * @throws Exception
     */
    public IDataset queryListByCodeCodeParser(String tabname, String sqlref, IData param) throws Exception 
    
    /**
     * query list by code code parser
     * 
     * @param tabname
     * @param sqlref
     * @param param
     * @param pagination
     * @param codecode_Datasource
     * @return IDataset
     * @throws Exception
     */
    public IDataset queryListByCodeCodeParser(String tabname, String sqlref, IData param, Pagination pagination) throws Exception 
    
    /**
     * get sql by sqlstore
     * 
     * @param sqlref
     * @param sqlstore_Datasource
     * @return IDataset
     * @throws Exception
     */
    public String getSqlBySqlstore(String sqlref) throws Exception 
    
    /**
     * query list by sqlstore
     * 
     * @param sqlref
     * @param param
     * @return IDataset
     * @throws Exception
     */
    public IDataset queryListBySqlstore(String sqlref, IData param) throws Exception 
    
    /**
     * query list by sqlstore
     * 
     * @param sqlref
     * @param param
     * @param pagination
     * @return IDataset
     * @throws Exception
     */
    public IDataset queryListBySqlstore(String sqlref, IData param, Pagination pagination) throws Exception 
    
    /**
     * query list by sqlstore parser
     * 
     * @param sqlref
     * @param param
     * @return IDataset
     * @throws Exception
     */
    public IDataset queryListBySqlstoreParser(String sqlref, IData param) throws Exception 
    
    /**
     * query list by sqlstore parser
     * 
     * @param sqlref
     * @param param
     * @param pagination
     * @return IDataset
     * @throws Exception
     */
    public IDataset queryListBySqlstoreParser(String sqlref, IData param, Pagination pagination) throws Exception 
    
    /**
     * execute update by sqlstore
     * 
     * @param sqlref
     * @param param
     * @param sqlstore_Datasource
     * @return int
     * @throws Exception
     */
    public int executeUpdateBySqlstore(String sqlref, IData param) throws Exception 
    
    /**
     * execute update by sqlstore
     * 
     * @param sqlref
     * @param params
     * @param sqlstore_Datasource
     * @return int[]
     * @throws Exception
     */
    public int[] executeBatchBySqlstore(String sqlref, IDataset params) throws Exception 
    

    示例代码:

    public class CustDAO extends BizDAO {
    	/**
    	 * query custs
    	 * @param param
    	 * @return
    	 * @throws Exception
    	 */
    	public IDataset queryCusts(IData param) throws Exception {
    		SQLParser parser = new SQLParser(param);
    		
    		parser.addSQL("select t.* from tf_f_cust_vip t");
    		parser.addSQL(" where 1 = 1");
    		parser.addSQL(" and cust_id = :CUST_ID");
    		parser.addSQL(" and cust_name like '%' || :CUST_NAME || '%'");
    		parser.addSQL(" order by t.cust_id ");
    
    		return queryList(parser);
    	}
    }