use of com.ctrip.platform.dal.dao.sqlbuilder.AbstractFreeSqlBuilder in project dal by ctripcorp.
the class AbstractFreeSqlBuilderTest method testColumn.
@Test
public void testColumn() {
AbstractFreeSqlBuilder test = create();
test.append(column(template));
assertEquals(wrappedTemplate, test.build());
}
use of com.ctrip.platform.dal.dao.sqlbuilder.AbstractFreeSqlBuilder in project dal by ctripcorp.
the class AbstractFreeSqlBuilderTest method testGroupBy.
@Test
public void testGroupBy() {
AbstractFreeSqlBuilder test = create();
test.groupBy(template);
test.setLogicDbName(logicDbName);
test.setHints(new DalHints());
assertEquals("GROUP BY " + wrappedTemplate, test.build());
test = create();
test.groupBy(expression(template));
test.setLogicDbName(logicDbName);
test.setHints(new DalHints());
assertEquals("GROUP BY " + template, test.build());
}
use of com.ctrip.platform.dal.dao.sqlbuilder.AbstractFreeSqlBuilder in project dal by ctripcorp.
the class AbstractFreeSqlBuilderTest method testAutoMeltdown.
@Test
public void testAutoMeltdown() 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)).ignoreNull(null).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)).ignoreNull(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)).ignoreNull(null);
assertEquals("template AND (template) [template]", test.build());
}
use of com.ctrip.platform.dal.dao.sqlbuilder.AbstractFreeSqlBuilder in project dal by ctripcorp.
the class AbstractFreeSqlBuilderTest method testFrom.
@Test
public void testFrom() {
String noShardTable = "noShard";
AbstractFreeSqlBuilder test = create();
test.from(noShardTable);
test.setLogicDbName(logicDbName);
test.setHints(new DalHints());
assertEquals("FROM [noShard] WITH (NOLOCK)", test.build());
test = create();
test.from(table(noShardTable));
test.setLogicDbName(logicDbName);
test.setHints(new DalHints());
assertEquals("FROM [noShard] WITH (NOLOCK)", test.build());
test = create();
test.from(table(noShardTable));
test.setLogicDbName("dao_test");
test.setHints(new DalHints());
assertEquals("FROM `noShard`", test.build());
}
use of com.ctrip.platform.dal.dao.sqlbuilder.AbstractFreeSqlBuilder in project dal by ctripcorp.
the class AbstractFreeSqlBuilderTest method testLikePattern.
@Test
public void testLikePattern() {
testExpression(wrappedTemplate + " LIKE ?", new ExpressionProvider() {
public AbstractFreeSqlBuilder createExp() {
return create().like(template);
}
public AbstractFreeSqlBuilder createExpWithParameter() {
return create().like(template, "abc", MatchPattern.END_WITH, Types.VARCHAR);
}
public AbstractFreeSqlBuilder createExpWithNullParameter() {
return create().like(template, null, MatchPattern.END_WITH, Types.VARCHAR);
}
});
AbstractFreeSqlBuilder builder = create().like(template, "abc", MatchPattern.END_WITH, Types.VARCHAR);
assertEquals("%abc", builder.buildParameters().get(0).getValue());
builder = create().like(template, "abc", MatchPattern.BEGIN_WITH, Types.VARCHAR);
assertEquals("abc%", builder.buildParameters().get(0).getValue());
builder = create().like(template, "abc", MatchPattern.CONTAINS, Types.VARCHAR);
assertEquals("%abc%", builder.buildParameters().get(0).getValue());
builder = create().like(template, "a%b%c", MatchPattern.USER_DEFINED, Types.VARCHAR);
assertEquals("a%b%c", builder.buildParameters().get(0).getValue());
}
Aggregations