Search in sources :

Example 36 with AbstractFreeSqlBuilder

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

the class AbstractFreeSqlBuilderTest method testBracket.

@Test
public void testBracket() {
    // Empty
    AbstractFreeSqlBuilder test = create();
    test.bracket(template);
    test.setLogicDbName(logicDbName);
    test.setHints(new DalHints());
    assertEquals("(template)", test.build());
    test = create();
    test.bracket(template, template, template);
    test.setLogicDbName(logicDbName);
    test.setHints(new DalHints());
    assertEquals("(template template template)", test.build());
    // One
    test = create();
    test.bracket(text(template));
    test.setLogicDbName(logicDbName);
    test.setHints(new DalHints());
    assertEquals("(template)", test.build());
    // two
    test = create();
    test.bracket(text(template), expression(expression));
    test.setLogicDbName(logicDbName);
    test.setHints(new DalHints());
    assertEquals("(template " + expression + ")", test.build());
}
Also used : DalHints(com.ctrip.platform.dal.dao.DalHints) AbstractFreeSqlBuilder(com.ctrip.platform.dal.dao.sqlbuilder.AbstractFreeSqlBuilder) Test(org.junit.Test)

Example 37 with AbstractFreeSqlBuilder

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

the class AbstractFreeSqlBuilderTest method testWhereClause.

@Test
public void testWhereClause() {
    AbstractFreeSqlBuilder test = create();
    test.where(expression("count()"), text(template));
    test.setLogicDbName(logicDbName);
    test.setHints(new DalHints());
    assertEquals("WHERE count() 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 38 with AbstractFreeSqlBuilder

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

the class AbstractFreeSqlBuilderTest method testLeftBracket.

@Test
public void testLeftBracket() {
    AbstractFreeSqlBuilder test = create();
    test.leftBracket();
    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 39 with AbstractFreeSqlBuilder

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

the class AbstractFreeSqlBuilderTest method testAppendColumn.

@Test
public void testAppendColumn() {
    AbstractFreeSqlBuilder test = create();
    test.appendColumn(template);
    test.setLogicDbName(logicDbName);
    assertEquals("[" + template + "]", test.build());
    test = create();
    test.appendColumn(template, template);
    test.setLogicDbName(logicDbName);
    assertEquals("[" + template + "] AS " + template, test.build());
    test = create();
    test.append(column(template).as(template));
    test.setLogicDbName(logicDbName);
    assertEquals("[" + template + "] AS " + template, test.build());
}
Also used : AbstractFreeSqlBuilder(com.ctrip.platform.dal.dao.sqlbuilder.AbstractFreeSqlBuilder) Test(org.junit.Test)

Example 40 with AbstractFreeSqlBuilder

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

the class AbstractFreeSqlBuilderTest method testAutoMeltdownWhen.

@Test
public void testAutoMeltdownWhen() 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)).when(false).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)).when(Boolean.FALSE == 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)).when(Boolean.FALSE == null);
    assertEquals("template AND (template) [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