Search in sources :

Example 41 with AbstractFreeSqlBuilder

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

the class AbstractFreeSqlBuilderTest method testAppendClause.

@Test
public void testAppendClause() {
    AbstractFreeSqlBuilder test = create();
    test.append(new Text(template));
    assertEquals(template, 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 42 with AbstractFreeSqlBuilder

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

the class AbstractFreeSqlBuilderTest method testHaving.

@Test
public void testHaving() {
    AbstractFreeSqlBuilder test = create();
    test.having(template);
    test.setLogicDbName(logicDbName);
    test.setHints(new DalHints());
    assertEquals("HAVING " + 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 43 with AbstractFreeSqlBuilder

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

the class AbstractFreeSqlBuilderTest method testSetIn.

@Test
public void testSetIn() throws SQLException {
    AbstractFreeSqlBuilder test = new AbstractFreeSqlBuilder();
    test.setLogicDbName(logicDbName);
    StatementParameters p = new StatementParameters();
    test.with(p);
    List<String> paras = new ArrayList<>();
    paras.add("abc1");
    paras.add("abc2");
    paras.add("abc3");
    test.select(template).setIn(template, paras, Types.VARCHAR);
    assertEquals("SELECT [template]", test.build());
    StatementParameters parameters = test.buildParameters();
    assertEquals(1, parameters.size());
    assertTrue(parameters.get(0).isInParam());
}
Also used : StatementParameters(com.ctrip.platform.dal.dao.StatementParameters) ArrayList(java.util.ArrayList) AbstractFreeSqlBuilder(com.ctrip.platform.dal.dao.sqlbuilder.AbstractFreeSqlBuilder) Test(org.junit.Test)

Example 44 with AbstractFreeSqlBuilder

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

the class AbstractFreeSqlBuilderTest method testNotLikePattern.

@Test
public void testNotLikePattern() {
    testExpression(wrappedTemplate + " NOT LIKE ?", new ExpressionProvider() {

        public AbstractFreeSqlBuilder createExp() {
            return create().notLike(template);
        }

        public AbstractFreeSqlBuilder createExpWithParameter() {
            return create().notLike(template, "abc", MatchPattern.BEGIN_WITH, Types.VARCHAR);
        }

        public AbstractFreeSqlBuilder createExpWithNullParameter() {
            return create().notLike(template, null, MatchPattern.BEGIN_WITH, Types.VARCHAR);
        }
    });
    AbstractFreeSqlBuilder builder = create().notLike(template, "abc", MatchPattern.END_WITH, Types.VARCHAR);
    assertEquals("%abc", builder.buildParameters().get(0).getValue());
    builder = create().notLike(template, "abc", MatchPattern.BEGIN_WITH, Types.VARCHAR);
    assertEquals("abc%", builder.buildParameters().get(0).getValue());
    builder = create().notLike(template, "abc", MatchPattern.CONTAINS, Types.VARCHAR);
    assertEquals("%abc%", builder.buildParameters().get(0).getValue());
    builder = create().notLike(template, "a%b%c", MatchPattern.USER_DEFINED, Types.VARCHAR);
    assertEquals("a%b%c", builder.buildParameters().get(0).getValue());
}
Also used : AbstractFreeSqlBuilder(com.ctrip.platform.dal.dao.sqlbuilder.AbstractFreeSqlBuilder) Test(org.junit.Test)

Example 45 with AbstractFreeSqlBuilder

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

the class AbstractFreeSqlBuilderTest method testAnd.

@Test
public void testAnd() {
    AbstractFreeSqlBuilder test = create();
    test.and();
    assertEquals("", test.build());
    test = create();
    test.and(template);
    assertEquals(template, test.build());
    test = create();
    test.and(template, template);
    assertEquals("template AND template", test.build());
    test = create();
    test.and(expressions(template));
    assertEquals("template", test.build());
    test = create();
    test.and(expressions(template, template));
    assertEquals("template AND template", test.build());
    test = create();
    test.and(expressions(template, template, template));
    assertEquals("template AND template AND 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