Search in sources :

Example 1 with Expression

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());
}
Also used : Expression(com.ctrip.platform.dal.dao.sqlbuilder.Expressions.Expression) AbstractFreeSqlBuilder(com.ctrip.platform.dal.dao.sqlbuilder.AbstractFreeSqlBuilder) SQLException(java.sql.SQLException) Test(org.junit.Test)

Example 2 with Expression

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;
}
Also used : Expression(com.ctrip.platform.dal.dao.sqlbuilder.Expressions.Expression) ColumnExpression(com.ctrip.platform.dal.dao.sqlbuilder.Expressions.ColumnExpression) ColumnExpression(com.ctrip.platform.dal.dao.sqlbuilder.Expressions.ColumnExpression)

Example 3 with Expression

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());
}
Also used : Expression(com.ctrip.platform.dal.dao.sqlbuilder.Expressions.Expression) AbstractFreeSqlBuilder(com.ctrip.platform.dal.dao.sqlbuilder.AbstractFreeSqlBuilder) SQLException(java.sql.SQLException) Test(org.junit.Test)

Aggregations

Expression (com.ctrip.platform.dal.dao.sqlbuilder.Expressions.Expression)3 AbstractFreeSqlBuilder (com.ctrip.platform.dal.dao.sqlbuilder.AbstractFreeSqlBuilder)2 SQLException (java.sql.SQLException)2 Test (org.junit.Test)2 ColumnExpression (com.ctrip.platform.dal.dao.sqlbuilder.Expressions.ColumnExpression)1