use of com.ctrip.platform.dal.dao.sqlbuilder.AbstractFreeSqlBuilder in project dal by ctripcorp.
the class AbstractFreeSqlBuilderTest method create.
/**
* Create test with auto meltdown disabled
* @return
*/
private AbstractFreeSqlBuilder create() {
AbstractFreeSqlBuilder test = new AbstractFreeSqlBuilder();
test.setLogicDbName(logicDbName);
test.setHints(new DalHints());
StatementParameters p = new StatementParameters();
test.with(p);
return test;
}
use of com.ctrip.platform.dal.dao.sqlbuilder.AbstractFreeSqlBuilder in project dal by ctripcorp.
the class AbstractFreeSqlBuilderTest method testIncludeAll.
@Test
public void testIncludeAll() {
AbstractFreeSqlBuilder test = new AbstractFreeSqlBuilder();
test.setLogicDbName(logicDbName);
test.select(template).from(template).where(AbstractFreeSqlBuilder.includeAll()).equal(template);
assertEquals("SELECT [template] FROM [template] WITH (NOLOCK) WHERE 1=1 AND [template] = ?", test.build());
test = new AbstractFreeSqlBuilder();
test.setLogicDbName(logicDbName);
test.select(template).from(template).where(AbstractFreeSqlBuilder.includeAll()).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 testRightBracket.
@Test
public void testRightBracket() {
AbstractFreeSqlBuilder test = create();
test.rightBracket();
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 testSetNullable.
@Test
public void testSetNullable() {
AbstractFreeSqlBuilder test = new AbstractFreeSqlBuilder();
test.setLogicDbName(logicDbName);
StatementParameters p = new StatementParameters();
test.with(p);
test.select(template).from(template).where(equal(template)).setNullable("abc", null, Types.VARCHAR).ignoreNull(null);
assertEquals("SELECT [template] FROM [template] WITH (NOLOCK) WHERE", test.build());
StatementParameters parameters = test.buildParameters();
assertEquals(0, parameters.size());
test = new AbstractFreeSqlBuilder();
test.setLogicDbName(logicDbName);
p = new StatementParameters();
test.with(p);
test.select(template).from(template).where(equal(template)).setNullable("abc", null, Types.VARCHAR);
assertEquals("SELECT [template] FROM [template] WITH (NOLOCK) WHERE [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 testNullable.
@Test
public void testNullable() {
AbstractFreeSqlBuilder test = create();
Expression exp;
try {
test.ignoreNull(null);
fail();
} catch (Exception e) {
}
test = create();
try {
test.append(template).ignoreNull(null);
fail();
} catch (Exception e) {
}
test = create();
try {
test.append(template).ignoreNull(new Object());
fail();
} catch (Exception e) {
}
test = create();
exp = new Expression(expression);
test.append(template).append(exp).ignoreNull(null);
assertTrue(exp.isInvalid());
assertEquals(template, test.build());
test = create();
exp = new Expression(expression);
test.append(template).append(exp).ignoreNull(new Object());
assertTrue(exp.isValid());
assertEquals(template + " " + expression, test.build());
}
Aggregations