use of com.ctrip.platform.dal.dao.sqlbuilder.AbstractFreeSqlBuilder in project dal by ctripcorp.
the class AbstractFreeSqlBuilderTest method testIgnorNull.
@Test
public void testIgnorNull() throws SQLException {
AbstractFreeSqlBuilder test = new AbstractFreeSqlBuilder();
test.setLogicDbName(logicDbName);
test.append(template);
test.setNullable("", null, Types.VARCHAR);
test.equal(template, null, Types.VARCHAR).ignoreNull().and();
test.notEqual(template, null, Types.VARCHAR).ignoreNull().and();
test.greaterThan(template, null, Types.VARCHAR).ignoreNull().and();
test.greaterThanEquals(template, null, Types.VARCHAR).ignoreNull().and();
test.lessThan(template, null, Types.VARCHAR).ignoreNull().and();
test.lessThanEquals(template, null, Types.VARCHAR).ignoreNull().and();
test.between(template, null, null, Types.VARCHAR).ignoreNull().and();
test.like(template, null, Types.VARCHAR).ignoreNull().and();
test.like(template, null, MatchPattern.BEGIN_WITH, Types.VARCHAR).ignoreNull().and();
test.notLike(template, null, Types.VARCHAR).ignoreNull().and();
test.notLike(template, null, MatchPattern.BEGIN_WITH, Types.VARCHAR).ignoreNull().and();
test.in(template, null, Types.VARCHAR).ignoreNull().and();
test.in(template, new ArrayList<>(), Types.VARCHAR).ignoreNull().and();
test.notIn(template, null, Types.VARCHAR).ignoreNull().and();
test.notIn(template, new ArrayList<>(), Types.VARCHAR).ignoreNull().and();
assertEquals(template, test.build());
assertEquals(0, test.buildParameters().size());
}
use of com.ctrip.platform.dal.dao.sqlbuilder.AbstractFreeSqlBuilder in project dal by ctripcorp.
the class AbstractFreeSqlBuilderTest method testExcludeAll.
@Test
public void testExcludeAll() {
AbstractFreeSqlBuilder test = new AbstractFreeSqlBuilder();
test.setLogicDbName(logicDbName);
test.select(template).from(template).where(AbstractFreeSqlBuilder.excludeAll()).equal(template);
assertEquals("SELECT [template] FROM [template] WITH (NOLOCK) WHERE 1<>1 OR [template] = ?", test.build());
test = new AbstractFreeSqlBuilder();
test.setLogicDbName(logicDbName);
test.select(template).from(template).where(AbstractFreeSqlBuilder.excludeAll()).equal(template).ignoreNull(null);
assertEquals("SELECT [template] FROM [template] WITH (NOLOCK) WHERE 1<>1", test.build());
}
use of com.ctrip.platform.dal.dao.sqlbuilder.AbstractFreeSqlBuilder in project dal by ctripcorp.
the class AbstractFreeSqlBuilderTest method testSetInNullable.
@Test
public void testSetInNullable() throws SQLException {
AbstractFreeSqlBuilder test = new AbstractFreeSqlBuilder();
test.setLogicDbName(logicDbName);
StatementParameters p = new StatementParameters();
test.with(p);
List<String> paras = new ArrayList<>();
paras.add("abc1");
paras.add("abc2");
paras.add("abc3");
test.select(template).setInNullable(template, paras, Types.VARCHAR);
assertEquals("SELECT [template]", test.build());
StatementParameters parameters = test.buildParameters();
assertEquals(1, parameters.size());
assertTrue(parameters.get(0).isInParam());
// Null case
test = new AbstractFreeSqlBuilder();
test.setLogicDbName(logicDbName);
p = new StatementParameters();
test.with(p);
paras = new ArrayList<>();
paras.add("abc1");
paras.add("abc2");
paras.add("abc3");
test.select(template).setInNullable(template, null, Types.VARCHAR);
assertEquals("SELECT [template]", test.build());
parameters = test.buildParameters();
assertEquals(0, parameters.size());
// Empty case
test = new AbstractFreeSqlBuilder();
test.setLogicDbName(logicDbName);
p = new StatementParameters();
test.with(p);
paras = new ArrayList<>();
test.select(template).setInNullable(template, null, Types.VARCHAR);
assertEquals("SELECT [template]", test.build());
parameters = test.buildParameters();
assertEquals(0, parameters.size());
}
use of com.ctrip.platform.dal.dao.sqlbuilder.AbstractFreeSqlBuilder in project dal by ctripcorp.
the class AbstractFreeSqlBuilderTest method testAppendConditionWithElse.
@Test
public void testAppendConditionWithElse() {
AbstractFreeSqlBuilder test = create();
test.appendWhen(true, template, elseTemplate);
assertEquals(template, test.build());
test = create();
test.appendWhen(false, template, elseTemplate);
assertEquals(elseTemplate, test.build());
}
use of com.ctrip.platform.dal.dao.sqlbuilder.AbstractFreeSqlBuilder in project dal by ctripcorp.
the class AbstractFreeSqlBuilderTest method testIsNull.
@Test
public void testIsNull() {
AbstractFreeSqlBuilder test = create();
test.isNull(template);
test.setLogicDbName(logicDbName);
test.setHints(new DalHints());
assertEquals(wrappedTemplate + " IS NULL", test.build());
assertEquals(0, test.buildParameters().size());
}
Aggregations