use of com.ctrip.platform.dal.dao.sqlbuilder.AbstractFreeSqlBuilder in project dal by ctripcorp.
the class AbstractFreeSqlBuilderTest method testBracket.
@Test
public void testBracket() {
// Empty
AbstractFreeSqlBuilder test = create();
test.bracket(template);
test.setLogicDbName(logicDbName);
test.setHints(new DalHints());
assertEquals("(template)", test.build());
test = create();
test.bracket(template, template, template);
test.setLogicDbName(logicDbName);
test.setHints(new DalHints());
assertEquals("(template template template)", test.build());
// One
test = create();
test.bracket(text(template));
test.setLogicDbName(logicDbName);
test.setHints(new DalHints());
assertEquals("(template)", test.build());
// two
test = create();
test.bracket(text(template), expression(expression));
test.setLogicDbName(logicDbName);
test.setHints(new DalHints());
assertEquals("(template " + expression + ")", test.build());
}
use of com.ctrip.platform.dal.dao.sqlbuilder.AbstractFreeSqlBuilder in project dal by ctripcorp.
the class AbstractFreeSqlBuilderTest method testWhereClause.
@Test
public void testWhereClause() {
AbstractFreeSqlBuilder test = create();
test.where(expression("count()"), text(template));
test.setLogicDbName(logicDbName);
test.setHints(new DalHints());
assertEquals("WHERE count() template", test.build());
}
use of com.ctrip.platform.dal.dao.sqlbuilder.AbstractFreeSqlBuilder in project dal by ctripcorp.
the class AbstractFreeSqlBuilderTest method testLeftBracket.
@Test
public void testLeftBracket() {
AbstractFreeSqlBuilder test = create();
test.leftBracket();
test.setLogicDbName(logicDbName);
test.setHints(new DalHints());
assertEquals("(", test.build());
}
use of com.ctrip.platform.dal.dao.sqlbuilder.AbstractFreeSqlBuilder in project dal by ctripcorp.
the class AbstractFreeSqlBuilderTest method testAppendColumn.
@Test
public void testAppendColumn() {
AbstractFreeSqlBuilder test = create();
test.appendColumn(template);
test.setLogicDbName(logicDbName);
assertEquals("[" + template + "]", test.build());
test = create();
test.appendColumn(template, template);
test.setLogicDbName(logicDbName);
assertEquals("[" + template + "] AS " + template, test.build());
test = create();
test.append(column(template).as(template));
test.setLogicDbName(logicDbName);
assertEquals("[" + template + "] AS " + template, test.build());
}
use of com.ctrip.platform.dal.dao.sqlbuilder.AbstractFreeSqlBuilder in project dal by ctripcorp.
the class AbstractFreeSqlBuilderTest method testAutoMeltdownWhen.
@Test
public void testAutoMeltdownWhen() throws SQLException {
AbstractFreeSqlBuilder test = new AbstractFreeSqlBuilder();
test.append(AND).bracket(AND, OR, AND);
assertEquals("", test.build());
test = new AbstractFreeSqlBuilder();
test.append(expression(template), AND).bracket(AND, OR, AND);
assertEquals(template, test.build());
test = new AbstractFreeSqlBuilder();
test.setLogicDbName(logicDbName);
test.append(expression(template), AND).bracket(AND, OR, AND).appendColumn(template);
assertEquals(template + " " + wrappedTemplate, test.build());
test = new AbstractFreeSqlBuilder();
test.setLogicDbName(logicDbName);
test.append(expression(template), AND).bracket(AND, OR, AND).appendTable(template);
assertEquals(template + " " + wrappedTemplate, test.build());
test = new AbstractFreeSqlBuilder();
test.setLogicDbName(logicDbName);
test.append(expression(template)).when(false).append(AND).bracket(AND, OR, AND).appendTable(template);
assertEquals(wrappedTemplate, test.build());
test = new AbstractFreeSqlBuilder();
test.setLogicDbName(logicDbName);
test.append(expression(template), AND).bracket(AND, OR, AND).appendTable(template).append(AND).append(expression(template)).when(Boolean.FALSE == null);
assertEquals(template + " " + wrappedTemplate, test.build());
test = new AbstractFreeSqlBuilder();
test.setLogicDbName(logicDbName);
test.append(expression(template), AND).bracket(AND, OR, AND, expression(template)).appendTable(template).append(AND).append(expression(template)).when(Boolean.FALSE == null);
assertEquals("template AND (template) [template]", test.build());
}
Aggregations