Search in sources :

Example 1 with DalScalarExtractor

use of com.ctrip.platform.dal.dao.helper.DalScalarExtractor in project dal by ctripcorp.

the class DalConcurrentSqlServerTestStub method testExecute.

@Test
public void testExecute() throws SQLException {
    List<DalCommand> commands = new ArrayList<DalCommand>();
    commands.add(new DalCommand() {

        @Override
        public boolean execute(DalClient client) throws SQLException {
            String sql = "INSERT INTO " + TABLE_NAME + "(quantity,type,address)" + " VALUES(10, 1, 'SH INFO')";
            int ret = client.update(sql, new StatementParameters(), new DalHints());
            if (ret > 0) {
                System.out.println("insert success.");
            } else {
                System.out.println("insert failed.");
            }
            return ret > 0;
        }
    });
    commands.add(new DalCommand() {

        @Override
        public boolean execute(DalClient client) throws SQLException {
            String sql = "DELETE FROM " + TABLE_NAME + " WHERE address = '" + "SH INFO'";
            int ret = client.update(sql, new StatementParameters(), new DalHints());
            if (ret > 0) {
                System.out.println("delete success");
            } else {
                System.out.println("delete failed");
            }
            return ret > 0;
        }
    });
    client.execute(commands, new DalHints());
    String sql = "SELECT count(1) from " + TABLE_NAME;
    Number count = (Number) client.query(sql, new StatementParameters(), new DalHints(), new DalScalarExtractor());
    Assert.assertEquals(INSERT_COUNT, count.intValue());
}
Also used : DalCommand(com.ctrip.platform.dal.dao.DalCommand) DalClient(com.ctrip.platform.dal.dao.DalClient) DalHints(com.ctrip.platform.dal.dao.DalHints) SQLException(java.sql.SQLException) StatementParameters(com.ctrip.platform.dal.dao.StatementParameters) ArrayList(java.util.ArrayList) DalScalarExtractor(com.ctrip.platform.dal.dao.helper.DalScalarExtractor) Test(org.junit.Test)

Example 2 with DalScalarExtractor

use of com.ctrip.platform.dal.dao.helper.DalScalarExtractor in project dal by ctripcorp.

the class DalConcurrentMysqlTest method testExecute.

@Test
public void testExecute() throws SQLException {
    List<DalCommand> commands = new ArrayList<DalCommand>();
    commands.add(new DalCommand() {

        @Override
        public boolean execute(DalClient client) throws SQLException {
            String sql = "INSERT INTO " + TABLE_NAME + "(quantity,type,address)" + " VALUES(10, 1, 'SH INFO')";
            int ret = client.update(sql, new StatementParameters(), new DalHints());
            if (ret > 0) {
                System.out.println("insert success.");
            } else {
                System.out.println("insert failed.");
            }
            return ret > 0;
        }
    });
    commands.add(new DalCommand() {

        @Override
        public boolean execute(DalClient client) throws SQLException {
            String sql = "DELETE FROM " + TABLE_NAME + " WHERE address = '" + "SH INFO'";
            int ret = client.update(sql, new StatementParameters(), new DalHints());
            if (ret > 0) {
                System.out.println("delete success");
            } else {
                System.out.println("delete failed");
            }
            return ret > 0;
        }
    });
    client.execute(commands, new DalHints());
    String sql = "SELECT count(1) from " + TABLE_NAME;
    Number count = (Number) client.query(sql, new StatementParameters(), new DalHints(), new DalScalarExtractor());
    Assert.assertEquals(INSERT_COUNT, count.intValue());
}
Also used : DalCommand(com.ctrip.platform.dal.dao.DalCommand) DalClient(com.ctrip.platform.dal.dao.DalClient) DalHints(com.ctrip.platform.dal.dao.DalHints) SQLException(java.sql.SQLException) StatementParameters(com.ctrip.platform.dal.dao.StatementParameters) ArrayList(java.util.ArrayList) DalScalarExtractor(com.ctrip.platform.dal.dao.helper.DalScalarExtractor) Test(org.junit.Test)

Example 3 with DalScalarExtractor

use of com.ctrip.platform.dal.dao.helper.DalScalarExtractor in project dal by ctripcorp.

the class ManualMarkDownTest method logicDbMarkdownTest.

@Test
public void logicDbMarkdownTest() {
    String logicDb = "dao_test_sqlsvr_tableShard_simple";
    DalStatusManager.getDatabaseSetStatus(logicDb).setMarkdown(true);
    DalClient client = DalClientFactory.getClient(logicDb);
    try {
        client.query("select 1", new StatementParameters(), new DalHints(), new DalScalarExtractor());
        Assert.fail();
    } catch (SQLException e) {
    }
    DalStatusManager.getDatabaseSetStatus(logicDb).setMarkdown(false);
    try {
        client.query("select 1", new StatementParameters(), new DalHints(), new DalScalarExtractor());
    } catch (SQLException e) {
        Assert.fail();
    }
}
Also used : DalClient(com.ctrip.platform.dal.dao.DalClient) DalHints(com.ctrip.platform.dal.dao.DalHints) SQLException(java.sql.SQLException) StatementParameters(com.ctrip.platform.dal.dao.StatementParameters) DalScalarExtractor(com.ctrip.platform.dal.dao.helper.DalScalarExtractor) Test(org.junit.Test)

Aggregations

DalClient (com.ctrip.platform.dal.dao.DalClient)3 DalHints (com.ctrip.platform.dal.dao.DalHints)3 StatementParameters (com.ctrip.platform.dal.dao.StatementParameters)3 DalScalarExtractor (com.ctrip.platform.dal.dao.helper.DalScalarExtractor)3 SQLException (java.sql.SQLException)3 Test (org.junit.Test)3 DalCommand (com.ctrip.platform.dal.dao.DalCommand)2 ArrayList (java.util.ArrayList)2