Search in sources :

Example 51 with AbstractFreeSqlBuilder

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

the class AbstractFreeSqlBuilderTest method testColumn.

@Test
public void testColumn() {
    AbstractFreeSqlBuilder test = create();
    test.append(column(template));
    assertEquals(wrappedTemplate, test.build());
}
Also used : AbstractFreeSqlBuilder(com.ctrip.platform.dal.dao.sqlbuilder.AbstractFreeSqlBuilder) Test(org.junit.Test)

Example 52 with AbstractFreeSqlBuilder

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

the class AbstractFreeSqlBuilderTest method testGroupBy.

@Test
public void testGroupBy() {
    AbstractFreeSqlBuilder test = create();
    test.groupBy(template);
    test.setLogicDbName(logicDbName);
    test.setHints(new DalHints());
    assertEquals("GROUP BY " + wrappedTemplate, test.build());
    test = create();
    test.groupBy(expression(template));
    test.setLogicDbName(logicDbName);
    test.setHints(new DalHints());
    assertEquals("GROUP BY " + 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 53 with AbstractFreeSqlBuilder

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

the class AbstractFreeSqlBuilderTest method testAutoMeltdown.

@Test
public void testAutoMeltdown() throws SQLException {
    AbstractFreeSqlBuilder test = new AbstractFreeSqlBuilder();
    test.append(AND).bracket(AND, OR, AND);
    assertEquals("", test.build());
    test = new AbstractFreeSqlBuilder();
    test.append(expression(template), AND).bracket(AND, OR, AND);
    assertEquals(template, test.build());
    test = new AbstractFreeSqlBuilder();
    test.setLogicDbName(logicDbName);
    test.append(expression(template), AND).bracket(AND, OR, AND).appendColumn(template);
    assertEquals(template + " " + wrappedTemplate, test.build());
    test = new AbstractFreeSqlBuilder();
    test.setLogicDbName(logicDbName);
    test.append(expression(template), AND).bracket(AND, OR, AND).appendTable(template);
    assertEquals(template + " " + wrappedTemplate, test.build());
    test = new AbstractFreeSqlBuilder();
    test.setLogicDbName(logicDbName);
    test.append(expression(template)).ignoreNull(null).append(AND).bracket(AND, OR, AND).appendTable(template);
    assertEquals(wrappedTemplate, test.build());
    test = new AbstractFreeSqlBuilder();
    test.setLogicDbName(logicDbName);
    test.append(expression(template), AND).bracket(AND, OR, AND).appendTable(template).append(AND).append(expression(template)).ignoreNull(null);
    assertEquals(template + " " + wrappedTemplate, test.build());
    test = new AbstractFreeSqlBuilder();
    test.setLogicDbName(logicDbName);
    test.append(expression(template), AND).bracket(AND, OR, AND, expression(template)).appendTable(template).append(AND).append(expression(template)).ignoreNull(null);
    assertEquals("template AND (template) [template]", test.build());
}
Also used : AbstractFreeSqlBuilder(com.ctrip.platform.dal.dao.sqlbuilder.AbstractFreeSqlBuilder) Test(org.junit.Test)

Example 54 with AbstractFreeSqlBuilder

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

the class AbstractFreeSqlBuilderTest method testFrom.

@Test
public void testFrom() {
    String noShardTable = "noShard";
    AbstractFreeSqlBuilder test = create();
    test.from(noShardTable);
    test.setLogicDbName(logicDbName);
    test.setHints(new DalHints());
    assertEquals("FROM [noShard] WITH (NOLOCK)", test.build());
    test = create();
    test.from(table(noShardTable));
    test.setLogicDbName(logicDbName);
    test.setHints(new DalHints());
    assertEquals("FROM [noShard] WITH (NOLOCK)", test.build());
    test = create();
    test.from(table(noShardTable));
    test.setLogicDbName("dao_test");
    test.setHints(new DalHints());
    assertEquals("FROM `noShard`", test.build());
}
Also used : DalHints(com.ctrip.platform.dal.dao.DalHints) AbstractFreeSqlBuilder(com.ctrip.platform.dal.dao.sqlbuilder.AbstractFreeSqlBuilder) Test(org.junit.Test)

Example 55 with AbstractFreeSqlBuilder

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

the class AbstractFreeSqlBuilderTest method testLikePattern.

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

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

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

        public AbstractFreeSqlBuilder createExpWithNullParameter() {
            return create().like(template, null, MatchPattern.END_WITH, Types.VARCHAR);
        }
    });
    AbstractFreeSqlBuilder builder = create().like(template, "abc", MatchPattern.END_WITH, Types.VARCHAR);
    assertEquals("%abc", builder.buildParameters().get(0).getValue());
    builder = create().like(template, "abc", MatchPattern.BEGIN_WITH, Types.VARCHAR);
    assertEquals("abc%", builder.buildParameters().get(0).getValue());
    builder = create().like(template, "abc", MatchPattern.CONTAINS, Types.VARCHAR);
    assertEquals("%abc%", builder.buildParameters().get(0).getValue());
    builder = create().like(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)

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