Search in sources :

Example 11 with DalConnection

use of com.ctrip.platform.dal.dao.client.DalConnection in project dal by ctripcorp.

the class AutoMarkdownTest method mockDalConnection.

public DalConnection mockDalConnection() {
    DalConnection conn = EasyMock.createMock(DalConnection.class);
    DbMeta meta = EasyMock.createMock(DbMeta.class);
    EasyMock.expect(meta.getDataBaseKeyName()).andReturn(dbName).times(1);
    EasyMock.expect(meta.getDatabaseCategory()).andReturn(DatabaseCategory.MySql).times(1);
    EasyMock.expect(conn.getMeta()).andReturn(meta).times(3);
    EasyMock.replay(meta, conn);
    return conn;
}
Also used : DbMeta(com.ctrip.platform.dal.dao.client.DbMeta) DalConnection(com.ctrip.platform.dal.dao.client.DalConnection)

Example 12 with DalConnection

use of com.ctrip.platform.dal.dao.client.DalConnection in project dal by ctripcorp.

the class DalConnectionTest method testSetAutoCommit.

@Test
public void testSetAutoCommit() throws SQLException {
    Connection conn = null;
    try {
        DalConnection test = getConnection();
        test.setAutoCommit(false);
        conn = test.getConn();
        assertFalse(conn.getAutoCommit());
        test.setAutoCommit(true);
        assertTrue(conn.getAutoCommit());
    } catch (Throwable e) {
        fail();
        e.printStackTrace();
    } finally {
        if (conn != null)
            conn.close();
    }
}
Also used : DalConnection(com.ctrip.platform.dal.dao.client.DalConnection) Connection(java.sql.Connection) DalConnection(com.ctrip.platform.dal.dao.client.DalConnection) Test(org.junit.Test)

Example 13 with DalConnection

use of com.ctrip.platform.dal.dao.client.DalConnection in project dal by ctripcorp.

the class DalConnectionManagerTest method testGetNewConnection.

@Test
public void testGetNewConnection() {
    boolean useMaster = true;
    DalHints hints = new DalHints();
    try {
        DalConnectionManager test = getDalConnectionManager(noShardDb);
        DalConnection conn = test.getNewConnection(hints, useMaster, DalEventEnum.BATCH_CALL);
        assertNotNull(conn);
        assertNotNull(conn.getConn());
        conn.getConn().close();
    } catch (Exception e) {
        e.printStackTrace();
        fail();
    }
}
Also used : DalHints(com.ctrip.platform.dal.dao.DalHints) DalConnection(com.ctrip.platform.dal.dao.client.DalConnection) DalConnectionManager(com.ctrip.platform.dal.dao.client.DalConnectionManager) Test(org.junit.Test)

Example 14 with DalConnection

use of com.ctrip.platform.dal.dao.client.DalConnection in project dal by ctripcorp.

the class DalTransactionTest method getDalConnection.

private DalConnection getDalConnection(int shard) throws Exception {
    Connection conn = null;
    conn = DalClientFactory.getDalConfigure().getLocator().getConnection("SqlSvrShard_" + shard);
    return new DalConnection(conn, true, String.valueOf(shard), DbMeta.createIfAbsent(logicDbName, DalClientFactory.getDalConfigure().getDatabaseSet(logicDbName).getDatabaseCategory(), conn));
}
Also used : DalConnection(com.ctrip.platform.dal.dao.client.DalConnection) Connection(java.sql.Connection) DalConnection(com.ctrip.platform.dal.dao.client.DalConnection)

Aggregations

DalConnection (com.ctrip.platform.dal.dao.client.DalConnection)14 Connection (java.sql.Connection)10 Test (org.junit.Test)10 PooledConnection (org.apache.tomcat.jdbc.pool.PooledConnection)3 DalHints (com.ctrip.platform.dal.dao.DalHints)2 DalException (com.ctrip.platform.dal.exceptions.DalException)2 SQLException (java.sql.SQLException)2 DalConnectionManager (com.ctrip.platform.dal.dao.client.DalConnectionManager)1 DbMeta (com.ctrip.platform.dal.dao.client.DbMeta)1 LogEntry (com.ctrip.platform.dal.dao.client.LogEntry)1 ResultSet (java.sql.ResultSet)1 Statement (java.sql.Statement)1