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);
}
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());
}
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"));
}
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"));
}
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"));
}
Aggregations