Search in sources :

Example 6 with BaseDataSource

use of org.axe.interface_.persistence.BaseDataSource in project Axe by DongyuCai.

the class DataBaseHelper method beginTransaction.

/**
     * 开启事务
     * @throws SQLException 
     */
public static void beginTransaction() throws SQLException {
    //    	long t = System.currentTimeMillis();
    //		System.out.println("e1:"+t);
    Map<String, BaseDataSource> dsMap = DataSourceHelper.getDataSourceAll();
    HashMap<String, Connection> connMap = new HashMap<>();
    try {
        for (String dataSourceName : dsMap.keySet()) {
            BaseDataSource dataSource = dsMap.get(dataSourceName);
            //        		System.out.println("e2-"+dataSourceName+":"+t);
            if (dataSource.tns()) {
                Connection conn = dataSource.getConnection();
                //设置成手动提交
                conn.setAutoCommit(false);
                connMap.put(dataSourceName, conn);
            }
        //        		t = System.currentTimeMillis();
        //        		System.out.println("e2-"+dataSourceName+":"+t);
        }
        CONNECTION_HOLDER.set(connMap);
    } catch (SQLException e) {
        LOGGER.error("begin transaction failure", e);
        throw new SQLException(e);
    }
//        t = System.currentTimeMillis();
//		System.out.println("e3:"+t);
}
Also used : BaseDataSource(org.axe.interface_.persistence.BaseDataSource) HashMap(java.util.HashMap) SQLException(java.sql.SQLException) Connection(java.sql.Connection)

Aggregations

BaseDataSource (org.axe.interface_.persistence.BaseDataSource)6 Connection (java.sql.Connection)4 SQLException (java.sql.SQLException)4 HashMap (java.util.HashMap)3 Map (java.util.Map)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 Request (org.axe.annotation.mvc.Request)1 DataSource (org.axe.annotation.persistence.DataSource)1