Search in sources :

Example 11 with AbstractFreeSqlBuilder

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

the class AbstractFreeSqlBuilderTest method testIgnorNull.

@Test
public void testIgnorNull() throws SQLException {
    AbstractFreeSqlBuilder test = new AbstractFreeSqlBuilder();
    test.setLogicDbName(logicDbName);
    test.append(template);
    test.setNullable("", null, Types.VARCHAR);
    test.equal(template, null, Types.VARCHAR).ignoreNull().and();
    test.notEqual(template, null, Types.VARCHAR).ignoreNull().and();
    test.greaterThan(template, null, Types.VARCHAR).ignoreNull().and();
    test.greaterThanEquals(template, null, Types.VARCHAR).ignoreNull().and();
    test.lessThan(template, null, Types.VARCHAR).ignoreNull().and();
    test.lessThanEquals(template, null, Types.VARCHAR).ignoreNull().and();
    test.between(template, null, null, Types.VARCHAR).ignoreNull().and();
    test.like(template, null, Types.VARCHAR).ignoreNull().and();
    test.like(template, null, MatchPattern.BEGIN_WITH, Types.VARCHAR).ignoreNull().and();
    test.notLike(template, null, Types.VARCHAR).ignoreNull().and();
    test.notLike(template, null, MatchPattern.BEGIN_WITH, Types.VARCHAR).ignoreNull().and();
    test.in(template, null, Types.VARCHAR).ignoreNull().and();
    test.in(template, new ArrayList<>(), Types.VARCHAR).ignoreNull().and();
    test.notIn(template, null, Types.VARCHAR).ignoreNull().and();
    test.notIn(template, new ArrayList<>(), Types.VARCHAR).ignoreNull().and();
    assertEquals(template, test.build());
    assertEquals(0, test.buildParameters().size());
}
Also used : AbstractFreeSqlBuilder(com.ctrip.platform.dal.dao.sqlbuilder.AbstractFreeSqlBuilder) Test(org.junit.Test)

Example 12 with AbstractFreeSqlBuilder

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

the class AbstractFreeSqlBuilderTest method testExcludeAll.

@Test
public void testExcludeAll() {
    AbstractFreeSqlBuilder test = new AbstractFreeSqlBuilder();
    test.setLogicDbName(logicDbName);
    test.select(template).from(template).where(AbstractFreeSqlBuilder.excludeAll()).equal(template);
    assertEquals("SELECT [template] FROM [template] WITH (NOLOCK) WHERE 1<>1 OR [template] = ?", test.build());
    test = new AbstractFreeSqlBuilder();
    test.setLogicDbName(logicDbName);
    test.select(template).from(template).where(AbstractFreeSqlBuilder.excludeAll()).equal(template).ignoreNull(null);
    assertEquals("SELECT [template] FROM [template] WITH (NOLOCK) WHERE 1<>1", test.build());
}
Also used : AbstractFreeSqlBuilder(com.ctrip.platform.dal.dao.sqlbuilder.AbstractFreeSqlBuilder) Test(org.junit.Test)

Example 13 with AbstractFreeSqlBuilder

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

the class AbstractFreeSqlBuilderTest method testSetInNullable.

@Test
public void testSetInNullable() 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).setInNullable(template, paras, Types.VARCHAR);
    assertEquals("SELECT [template]", test.build());
    StatementParameters parameters = test.buildParameters();
    assertEquals(1, parameters.size());
    assertTrue(parameters.get(0).isInParam());
    // Null case
    test = new AbstractFreeSqlBuilder();
    test.setLogicDbName(logicDbName);
    p = new StatementParameters();
    test.with(p);
    paras = new ArrayList<>();
    paras.add("abc1");
    paras.add("abc2");
    paras.add("abc3");
    test.select(template).setInNullable(template, null, Types.VARCHAR);
    assertEquals("SELECT [template]", test.build());
    parameters = test.buildParameters();
    assertEquals(0, parameters.size());
    // Empty case
    test = new AbstractFreeSqlBuilder();
    test.setLogicDbName(logicDbName);
    p = new StatementParameters();
    test.with(p);
    paras = new ArrayList<>();
    test.select(template).setInNullable(template, null, Types.VARCHAR);
    assertEquals("SELECT [template]", test.build());
    parameters = test.buildParameters();
    assertEquals(0, parameters.size());
}
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 14 with AbstractFreeSqlBuilder

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

the class AbstractFreeSqlBuilderTest method testAppendConditionWithElse.

@Test
public void testAppendConditionWithElse() {
    AbstractFreeSqlBuilder test = create();
    test.appendWhen(true, template, elseTemplate);
    assertEquals(template, test.build());
    test = create();
    test.appendWhen(false, template, elseTemplate);
    assertEquals(elseTemplate, test.build());
}
Also used : AbstractFreeSqlBuilder(com.ctrip.platform.dal.dao.sqlbuilder.AbstractFreeSqlBuilder) Test(org.junit.Test)

Example 15 with AbstractFreeSqlBuilder

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

the class AbstractFreeSqlBuilderTest method testIsNull.

@Test
public void testIsNull() {
    AbstractFreeSqlBuilder test = create();
    test.isNull(template);
    test.setLogicDbName(logicDbName);
    test.setHints(new DalHints());
    assertEquals(wrappedTemplate + " IS NULL", test.build());
    assertEquals(0, test.buildParameters().size());
}
Also used : DalHints(com.ctrip.platform.dal.dao.DalHints) 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