Search in sources :

Example 6 with AbstractFreeSqlBuilder

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

the class AbstractFreeSqlBuilderTest method testNot.

@Test
public void testNot() {
    AbstractFreeSqlBuilder test = create();
    test.not();
    assertEquals("NOT", test.build());
}
Also used : AbstractFreeSqlBuilder(com.ctrip.platform.dal.dao.sqlbuilder.AbstractFreeSqlBuilder) Test(org.junit.Test)

Example 7 with AbstractFreeSqlBuilder

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

the class AbstractFreeSqlBuilderTest method testSelectAll.

@Test
public void testSelectAll() {
    AbstractFreeSqlBuilder test = create();
    test.selectAll();
    test.setLogicDbName(logicDbName);
    test.setHints(new DalHints());
    assertEquals("SELECT *", test.build());
}
Also used : DalHints(com.ctrip.platform.dal.dao.DalHints) AbstractFreeSqlBuilder(com.ctrip.platform.dal.dao.sqlbuilder.AbstractFreeSqlBuilder) Test(org.junit.Test)

Example 8 with AbstractFreeSqlBuilder

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

the class AbstractFreeSqlBuilderTest method testAppendWith.

@Test
public void testAppendWith() {
    AbstractFreeSqlBuilder test = create();
    test.appendWith(COMMA, new Text(template), new Text(elseTemplate));
    assertEquals("template, elseTemplate", test.build());
}
Also used : AbstractFreeSqlBuilder(com.ctrip.platform.dal.dao.sqlbuilder.AbstractFreeSqlBuilder) Text(com.ctrip.platform.dal.dao.sqlbuilder.AbstractFreeSqlBuilder.Text) Test(org.junit.Test)

Example 9 with AbstractFreeSqlBuilder

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

the class AbstractFreeSqlBuilderTest method testSet.

@Test
public void testSet() {
    AbstractFreeSqlBuilder test = new AbstractFreeSqlBuilder();
    test.setLogicDbName(logicDbName);
    StatementParameters p = new StatementParameters();
    test.with(p);
    test.select(template).from(template).where(equal(template)).set(template, "abc", Types.VARCHAR);
    assertEquals("SELECT [template] FROM [template] WITH (NOLOCK) WHERE [template] = ?", test.build());
    StatementParameters parameters = test.buildParameters();
    assertEquals(1, parameters.size());
    assertEquals(template, parameters.get(0).getName());
}
Also used : StatementParameters(com.ctrip.platform.dal.dao.StatementParameters) AbstractFreeSqlBuilder(com.ctrip.platform.dal.dao.sqlbuilder.AbstractFreeSqlBuilder) Test(org.junit.Test)

Example 10 with AbstractFreeSqlBuilder

use of com.ctrip.platform.dal.dao.sqlbuilder.AbstractFreeSqlBuilder 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)

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