Search in sources :

Example 46 with AbstractFreeSqlBuilder

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;
}
Also used : DalHints(com.ctrip.platform.dal.dao.DalHints) StatementParameters(com.ctrip.platform.dal.dao.StatementParameters) AbstractFreeSqlBuilder(com.ctrip.platform.dal.dao.sqlbuilder.AbstractFreeSqlBuilder)

Example 47 with AbstractFreeSqlBuilder

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

Example 48 with AbstractFreeSqlBuilder

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

Example 49 with AbstractFreeSqlBuilder

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

Example 50 with AbstractFreeSqlBuilder

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());
}
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

AbstractFreeSqlBuilder (com.ctrip.platform.dal.dao.sqlbuilder.AbstractFreeSqlBuilder)55 Test (org.junit.Test)51 DalHints (com.ctrip.platform.dal.dao.DalHints)17 StatementParameters (com.ctrip.platform.dal.dao.StatementParameters)8 SQLException (java.sql.SQLException)5 Text (com.ctrip.platform.dal.dao.sqlbuilder.AbstractFreeSqlBuilder.Text)4 ArrayList (java.util.ArrayList)3 Expression (com.ctrip.platform.dal.dao.sqlbuilder.Expressions.Expression)2 Clause (com.ctrip.platform.dal.dao.sqlbuilder.Clause)1