Search in sources :

Example 11 with SelectSqlBuilder

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

the class DalTableDaoTestStub method testQueryObjectAllColumns.

@Test
public void testQueryObjectAllColumns() throws SQLException {
    SelectSqlBuilder builder = new SelectSqlBuilder().selectAllColumns();
    builder.equal("type", 1, Types.SMALLINT);
    builder.requireFirst();
    ClientTestModel models = dao.queryObject(builder, new DalHints());
    Assert.assertNotNull(models);
    builder = new SelectSqlBuilder().selectAllColumns();
    builder.equal("type", 1, Types.SMALLINT);
    builder.requireFirst();
    models = dao.queryObject(builder.atPage(1, 1), new DalHints());
    Assert.assertNotNull(models);
    builder = new SelectSqlBuilder().selectAllColumns();
    builder.equal("type", 10, Types.SMALLINT);
    builder.requireFirst();
    models = dao.queryObject(builder.atPage(1, 10), new DalHints());
    Assert.assertNull(models);
}
Also used : DalHints(com.ctrip.platform.dal.dao.DalHints) ClientTestModel(test.com.ctrip.platform.dal.dao.unitbase.ClientTestModel) SelectSqlBuilder(com.ctrip.platform.dal.dao.sqlbuilder.SelectSqlBuilder) Test(org.junit.Test)

Example 12 with SelectSqlBuilder

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

the class DalTableDaoTestStub method testQueryList.

@Test
public void testQueryList() throws SQLException {
    SelectSqlBuilder builder = new SelectSqlBuilder();
    builder.equal("type", 1, Types.SMALLINT);
    List<ClientTestModel> models = dao.query(builder, new DalHints());
    Assert.assertTrue(null != models);
    Assert.assertEquals(3, models.size());
    builder = new SelectSqlBuilder();
    builder.equal("type", 1, Types.SMALLINT);
    models = dao.query(builder.atPage(1, 1), new DalHints());
    Assert.assertTrue(null != models);
    Assert.assertEquals(1, models.size());
    builder = new SelectSqlBuilder();
    builder.equal("type", 10, Types.SMALLINT);
    models = dao.query(builder.atPage(1, 10), new DalHints());
    Assert.assertTrue(null != models);
    Assert.assertEquals(0, models.size());
}
Also used : DalHints(com.ctrip.platform.dal.dao.DalHints) ClientTestModel(test.com.ctrip.platform.dal.dao.unitbase.ClientTestModel) SelectSqlBuilder(com.ctrip.platform.dal.dao.sqlbuilder.SelectSqlBuilder) Test(org.junit.Test)

Example 13 with SelectSqlBuilder

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

the class BaseQueryBuilderTest method testOrderBy.

@Test
public void testOrderBy() throws SQLException {
    SelectSqlBuilder qb;
    qb = createTest("Test", DatabaseCategory.MySql);
    qb.select("columns").where("conditions").orderBy("ob", true).orderBy("ob2", false).orderBy("ob3", true);
    assertEquals("SELECT `columns` FROM `Test` WHERE conditions ORDER BY `ob` ASC, `ob2` DESC, `ob3` ASC", qb.build());
    assertEquals("SELECT `columns` FROM `Test_0` WHERE conditions ORDER BY `ob` ASC, `ob2` DESC, `ob3` ASC", qb.build("_0"));
    qb = createTest("Test", DatabaseCategory.SqlServer);
    qb.select("columns").where("conditions").orderBy("ob", true).orderBy("ob2", false).orderBy("ob3", true);
    assertEquals("SELECT [columns] FROM [Test] WITH (NOLOCK) WHERE conditions ORDER BY [ob] ASC, [ob2] DESC, [ob3] ASC", qb.build());
    assertEquals("SELECT [columns] FROM [Test_0] WITH (NOLOCK) WHERE conditions ORDER BY [ob] ASC, [ob2] DESC, [ob3] ASC", qb.build("_0"));
}
Also used : SelectSqlBuilder(com.ctrip.platform.dal.dao.sqlbuilder.SelectSqlBuilder) Test(org.junit.Test)

Example 14 with SelectSqlBuilder

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

the class BaseQueryBuilderTest method testBuildTop.

@Test
public void testBuildTop() throws SQLException {
    SelectSqlBuilder qb;
    qb = createTest("Test", DatabaseCategory.MySql);
    qb.select("columns").where("conditions").orderBy("ob", true).top(5);
    assertEquals("SELECT `columns` FROM `Test` WHERE conditions ORDER BY `ob` ASC LIMIT 5", qb.build());
    assertEquals("SELECT `columns` FROM `Test_0` WHERE conditions ORDER BY `ob` ASC LIMIT 5", qb.build("_0"));
    qb = createTest("Test", DatabaseCategory.SqlServer);
    qb.select("columns").where("conditions").orderBy("ob", true).top(5);
    assertEquals("SELECT TOP 5 [columns] FROM [Test] WITH (NOLOCK) WHERE conditions ORDER BY [ob] ASC", qb.build());
    assertEquals("SELECT TOP 5 [columns] FROM [Test_0] WITH (NOLOCK) WHERE conditions ORDER BY [ob] ASC", qb.build("_0"));
}
Also used : SelectSqlBuilder(com.ctrip.platform.dal.dao.sqlbuilder.SelectSqlBuilder) Test(org.junit.Test)

Example 15 with SelectSqlBuilder

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

the class BaseQueryBuilderTest method testBuildRange.

@Test
public void testBuildRange() throws SQLException {
    SelectSqlBuilder qb;
    qb = createTest("Test", DatabaseCategory.MySql);
    qb.select("columns").where("conditions").orderBy("ob", true).range(100, 200);
    assertEquals("SELECT `columns` FROM `Test` WHERE conditions ORDER BY `ob` ASC LIMIT 100, 200", qb.build());
    assertEquals("SELECT `columns` FROM `Test_0` WHERE conditions ORDER BY `ob` ASC LIMIT 100, 200", qb.build("_0"));
    qb = createTest("Test", DatabaseCategory.SqlServer);
    qb.select("columns").where("conditions").orderBy("ob", true).range(100, 200);
    assertEquals("SELECT [columns] FROM [Test] WITH (NOLOCK) WHERE conditions ORDER BY [ob] ASC OFFSET 100 ROWS FETCH NEXT 200 ROWS ONLY", qb.build());
    assertEquals("SELECT [columns] FROM [Test_0] WITH (NOLOCK) WHERE conditions ORDER BY [ob] ASC OFFSET 100 ROWS FETCH NEXT 200 ROWS ONLY", qb.build("_0"));
}
Also used : SelectSqlBuilder(com.ctrip.platform.dal.dao.sqlbuilder.SelectSqlBuilder) Test(org.junit.Test)

Aggregations

SelectSqlBuilder (com.ctrip.platform.dal.dao.sqlbuilder.SelectSqlBuilder)48 Test (org.junit.Test)39 ArrayList (java.util.ArrayList)27 DalHints (com.ctrip.platform.dal.dao.DalHints)15 FreeSelectSqlBuilder (com.ctrip.platform.dal.dao.sqlbuilder.FreeSelectSqlBuilder)5 DalTableDao (com.ctrip.platform.dal.dao.DalTableDao)4 StatementParameters (com.ctrip.platform.dal.dao.StatementParameters)3 DalException (com.ctrip.platform.dal.exceptions.DalException)3 ClientTestModel (test.com.ctrip.platform.dal.dao.unitbase.ClientTestModel)3 SQLException (java.sql.SQLException)2 GenTaskByFreeSql (com.ctrip.platform.dal.daogen.entity.GenTaskByFreeSql)1 GenTaskBySqlBuilder (com.ctrip.platform.dal.daogen.entity.GenTaskBySqlBuilder)1