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());
}
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());
}
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();
}
}
Aggregations