use of com.ctrip.platform.dal.dao.sqlbuilder.Expressions.Expression in project dal by ctripcorp.
the class AbstractFreeSqlBuilderTest method testWhen.
@Test
public void testWhen() {
AbstractFreeSqlBuilder test = create();
Expression exp;
try {
test.when(false);
fail();
} catch (Exception e) {
}
test = create();
try {
test.append(template).when(false);
fail();
} catch (Exception e) {
}
test = create();
try {
test.append(template).when(true);
fail();
} catch (Exception e) {
}
test = create();
exp = new Expression(expression);
test.append(template).append(exp).when(false);
assertTrue(exp.isInvalid());
assertEquals(template, test.build());
test = create();
exp = new Expression(expression);
test.append(template).append(exp).when(true);
assertTrue(exp.isValid());
assertEquals(template + " " + expression, test.build());
}
use of com.ctrip.platform.dal.dao.sqlbuilder.Expressions.Expression in project dal by ctripcorp.
the class AbstractFreeSqlBuilder method ignoreNull.
/**
* Ignore last expression if iy's value is null.
*
* @param value
* @return
*/
public AbstractFreeSqlBuilder ignoreNull() {
Expression last = getLastExpression();
if (!(last instanceof ColumnExpression))
throw new IllegalStateException("The last sql segement is not an ColumnExpression.");
((ColumnExpression) last).ignoreNull();
return this;
}
use of com.ctrip.platform.dal.dao.sqlbuilder.Expressions.Expression 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