Search in sources :

Example 21 with AbstractFreeSqlBuilder

use of com.ctrip.platform.dal.dao.sqlbuilder.AbstractFreeSqlBuilder in project dal by ctripcorp.

the class AbstractFreeSqlBuilderTest method testSetWhen.

@Test
public void testSetWhen() {
    AbstractFreeSqlBuilder test = new AbstractFreeSqlBuilder();
    test.setLogicDbName(logicDbName);
    StatementParameters p = new StatementParameters();
    test.with(p);
    test.select(template).from(template).where(equal(template)).set(false, template, "abc", Types.VARCHAR).when(false);
    assertEquals("SELECT [template] FROM [template] WITH (NOLOCK) WHERE", test.build());
    StatementParameters 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 22 with AbstractFreeSqlBuilder

use of com.ctrip.platform.dal.dao.sqlbuilder.AbstractFreeSqlBuilder in project dal by ctripcorp.

the class AbstractFreeSqlBuilderTest method testSelect.

@Test
public void testSelect() {
    String noShardTable = "noShard";
    AbstractFreeSqlBuilder test = create();
    test.select();
    test.setLogicDbName(logicDbName);
    test.setHints(new DalHints());
    assertEquals("SELECT", test.build());
    test = create();
    test.select(template, template, template);
    test.setLogicDbName(logicDbName);
    test.setHints(new DalHints());
    assertEquals("SELECT [template], [template], [template]", test.build());
    test = create();
    test.select(text(template), expression(template), column(template).as(template));
    test.setLogicDbName(logicDbName);
    test.setHints(new DalHints());
    assertEquals("SELECT template, template, [template] AS template", test.build());
}
Also used : DalHints(com.ctrip.platform.dal.dao.DalHints) AbstractFreeSqlBuilder(com.ctrip.platform.dal.dao.sqlbuilder.AbstractFreeSqlBuilder) Test(org.junit.Test)

Example 23 with AbstractFreeSqlBuilder

use of com.ctrip.platform.dal.dao.sqlbuilder.AbstractFreeSqlBuilder in project dal by ctripcorp.

the class ExpressionsTest method setEnv.

private void setEnv(Clause test) {
    AbstractFreeSqlBuilder builder = new AbstractFreeSqlBuilder();
    builder.append(test);
    builder.setLogicDbName(logicDbName);
}
Also used : AbstractFreeSqlBuilder(com.ctrip.platform.dal.dao.sqlbuilder.AbstractFreeSqlBuilder)

Example 24 with AbstractFreeSqlBuilder

use of com.ctrip.platform.dal.dao.sqlbuilder.AbstractFreeSqlBuilder in project dal by ctripcorp.

the class AbstractFreeSqlBuilderTest method testSetHints.

@Test
public void testSetHints() {
    AbstractFreeSqlBuilder test = create();
    try {
        test.setHints(null);
        fail();
    } catch (Exception e) {
    }
    test.setHints(new DalHints());
}
Also used : DalHints(com.ctrip.platform.dal.dao.DalHints) AbstractFreeSqlBuilder(com.ctrip.platform.dal.dao.sqlbuilder.AbstractFreeSqlBuilder) SQLException(java.sql.SQLException) Test(org.junit.Test)

Example 25 with AbstractFreeSqlBuilder

use of com.ctrip.platform.dal.dao.sqlbuilder.AbstractFreeSqlBuilder in project dal by ctripcorp.

the class AbstractFreeSqlBuilderTest method testOr.

@Test
public void testOr() {
    AbstractFreeSqlBuilder test = create();
    test.or();
    assertEquals("", test.build());
    test = create();
    test.or(template);
    assertEquals(template, test.build());
    test = create();
    test.or(template, template);
    assertEquals("template OR template", test.build());
    test = create();
    test.or(expressions(template));
    assertEquals(template, test.build());
    test = create();
    test.or(expressions(template, expression));
    assertEquals(template + " OR " + expression, test.build());
    test = create();
    test.or(expressions(template, template, template));
    assertEquals("template OR template OR template", test.build());
}
Also used : AbstractFreeSqlBuilder(com.ctrip.platform.dal.dao.sqlbuilder.AbstractFreeSqlBuilder) 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