use of com.ctrip.platform.dal.dao.sqlbuilder.AbstractFreeSqlBuilder in project dal by ctripcorp.
the class AbstractFreeSqlBuilderMeltdownTest method validate.
public void validate(String exp, String expected) throws SQLException {
AbstractFreeSqlBuilder builder = new AbstractFreeSqlBuilder().setLogicDbName(logicDbName);
// equal equalNull between betweenNull in inNull like likeNull isNull isNotNull AND OR NOT ( )
String[] tokens = exp.split(" ");
for (String token : tokens) {
switch(token) {
case "equal":
builder.equal("a");
break;
case "equalNull":
builder.equal("a").when(false);
break;
case "like":
builder.like("a");
break;
case "likeNull":
builder.like("a").when(false);
break;
case "isNull":
builder.isNull("a");
break;
case "isNotNull":
builder.isNotNull("a");
break;
case "in":
builder.in("a");
break;
case "notIn":
builder.notIn("a");
break;
case "inNull":
builder.in("a").when(false);
break;
case "notInNull":
builder.notIn("a").when(false);
break;
case "between":
builder.between("a");
break;
case "betweenNull":
builder.between("a").when(false);
break;
case "AND":
builder.and();
break;
case "OR":
builder.or();
break;
case "NOT":
builder.not();
break;
case "(":
builder.leftBracket();
break;
case ")":
builder.rightBracket();
break;
default:
Assert.fail("Unknown token: " + token);
}
}
Assert.assertEquals(expected, builder.build());
}
use of com.ctrip.platform.dal.dao.sqlbuilder.AbstractFreeSqlBuilder in project dal by ctripcorp.
the class AbstractFreeSqlBuilderMeltdownWithSpaceSkipDisabledTest method validate.
public void validate(String exp, String expected) throws SQLException {
AbstractFreeSqlBuilder builder = new AbstractFreeSqlBuilder().setLogicDbName(logicDbName);
builder.disableSpaceSkipping();
// equal equalNull between betweenNull in inNull like likeNull isNull isNotNull AND OR NOT ( )
String[] tokens = exp.split(" ");
for (String token : tokens) {
switch(token) {
case "equal":
builder.equal("a");
break;
case "equalNull":
builder.equal("a").ignoreNull(null);
break;
case "like":
builder.like("a");
break;
case "likeNull":
builder.like("a").ignoreNull(null);
break;
case "isNull":
builder.isNull("a");
break;
case "isNotNull":
builder.isNotNull("a");
break;
case "in":
builder.in("a");
break;
case "notIn":
builder.notIn("a");
break;
case "inNull":
builder.in("a").ignoreNull(null);
break;
case "notInNull":
builder.notIn("a").ignoreNull(null);
break;
case "between":
builder.between("a");
break;
case "betweenNull":
builder.between("a").ignoreNull(null);
break;
case "AND":
builder.and();
break;
case "OR":
builder.or();
break;
case "NOT":
builder.not();
break;
case "(":
builder.leftBracket();
break;
case ")":
builder.rightBracket();
break;
default:
Assert.fail("Unknown token: " + token);
}
}
Assert.assertEquals(expected, builder.build());
}
use of com.ctrip.platform.dal.dao.sqlbuilder.AbstractFreeSqlBuilder in project dal by ctripcorp.
the class AbstractFreeSqlBuilderTest method testAppendCondition.
@Test
public void testAppendCondition() {
AbstractFreeSqlBuilder test = create();
test.appendWhen(true, template);
assertEquals(template, test.build());
test = create();
test.appendWhen(false, template);
assertEquals(EMPTY, test.build());
}
use of com.ctrip.platform.dal.dao.sqlbuilder.AbstractFreeSqlBuilder in project dal by ctripcorp.
the class AbstractFreeSqlBuilderTest method testAppendTable.
@Test
public void testAppendTable() {
String noShardTable = "noShard";
AbstractFreeSqlBuilder test = create();
test.appendTable(noShardTable);
test.setLogicDbName(logicDbName);
test.setHints(new DalHints());
assertEquals("[" + noShardTable + "]", test.build());
test = create();
test.appendTable(tableName);
test.setLogicDbName(logicDbName);
test.setHints(new DalHints().inTableShard(1));
assertEquals("[" + tableName + "_1]", test.build());
test = create();
test.appendTable(tableName, template);
test.setLogicDbName(logicDbName);
test.setHints(new DalHints().inTableShard(1));
assertEquals("[" + tableName + "_1] AS " + template, test.build());
test = create();
test.append(table(tableName).as(template));
test.setLogicDbName(logicDbName);
test.setHints(new DalHints().inTableShard(1));
assertEquals("[" + tableName + "_1] AS " + template, test.build());
}
use of com.ctrip.platform.dal.dao.sqlbuilder.AbstractFreeSqlBuilder in project dal by ctripcorp.
the class AbstractFreeSqlBuilderTest method testIsNotNull.
@Test
public void testIsNotNull() {
AbstractFreeSqlBuilder test = create();
test.isNotNull(template);
test.setLogicDbName(logicDbName);
test.setHints(new DalHints());
assertEquals(wrappedTemplate + " IS NOT NULL", test.build());
assertEquals(0, test.buildParameters().size());
}
Aggregations