Search in sources :

Example 6 with SelectSqlBuilder

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

the class SelectSqlBuilderTest method testMySQLNew.

@Test
public void testMySQLNew() throws SQLException {
    List<String> in = new ArrayList<String>();
    in.add("12");
    in.add("12");
    SelectSqlBuilder builder = new SelectSqlBuilder();
    builder.select("PeopleID", "Name", "CityID");
    builder.equal("a", "paramValue", Types.INTEGER);
    builder.and().in("b", in, Types.INTEGER);
    builder.and().like("b", "in", Types.INTEGER);
    builder.and().betweenNullable("c", "paramValue1", "paramValue2", Types.INTEGER);
    builder.and().betweenNullable("d", null, "paramValue2", Types.INTEGER);
    builder.and().isNull("sss");
    builder.orderBy("PeopleID", false);
    builder.from("People").setDatabaseCategory(DatabaseCategory.MySql);
    String sql = builder.build();
    String expect_sql = "SELECT `PeopleID`, `Name`, `CityID` FROM `People` " + "WHERE `a` = ? AND `b` in ( ? ) AND `b` LIKE ? AND `c` BETWEEN ? AND ? " + "AND `sss` IS NULL ORDER BY `PeopleID` DESC";
    Assert.assertEquals(expect_sql, sql);
}
Also used : ArrayList(java.util.ArrayList) SelectSqlBuilder(com.ctrip.platform.dal.dao.sqlbuilder.SelectSqlBuilder) Test(org.junit.Test)

Example 7 with SelectSqlBuilder

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

the class DalGroupDBDao method getGroupDbsByDbNames.

public List<DalGroupDB> getGroupDbsByDbNames(Set<String> dbNames) throws SQLException {
    SelectSqlBuilder builder = new SelectSqlBuilder();
    builder.select("id", "db_catalog", "db_port", "db_providerName", "dbname", "db_password", "db_user", "db_address", "comment", "dal_group_id");
    builder.in("dbname", new ArrayList<>(dbNames), Types.VARCHAR, false);
    DalHints hints = DalHints.createIfAbsent(null);
    return client.query(builder, hints);
}
Also used : DalHints(com.ctrip.platform.dal.dao.DalHints) FreeSelectSqlBuilder(com.ctrip.platform.dal.dao.sqlbuilder.FreeSelectSqlBuilder) SelectSqlBuilder(com.ctrip.platform.dal.dao.sqlbuilder.SelectSqlBuilder)

Example 8 with SelectSqlBuilder

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

the class DalGroupDao method getAllGroups.

public List<DalGroup> getAllGroups() throws SQLException {
    SelectSqlBuilder builder = new SelectSqlBuilder().selectAll();
    DalHints hints = DalHints.createIfAbsent(null);
    return client.query(builder, hints);
}
Also used : DalHints(com.ctrip.platform.dal.dao.DalHints) SelectSqlBuilder(com.ctrip.platform.dal.dao.sqlbuilder.SelectSqlBuilder)

Example 9 with SelectSqlBuilder

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

the class DalTableDaoTestStub method testQueryListAllColumns.

@Test
public void testQueryListAllColumns() throws SQLException {
    SelectSqlBuilder builder = new SelectSqlBuilder().selectAllColumns();
    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().selectAllColumns();
    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().selectAllColumns();
    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 10 with SelectSqlBuilder

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

the class DalTableDaoTestStub method testQueryObjectList.

@Test
public void testQueryObjectList() throws SQLException {
    SelectSqlBuilder builder = new SelectSqlBuilder();
    builder.equal("type", 1, Types.SMALLINT);
    List<Short> models = dao.query(builder, new DalHints(), Short.class);
    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(), Short.class);
    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(), Short.class);
    Assert.assertTrue(null != models);
    Assert.assertEquals(0, models.size());
}
Also used : DalHints(com.ctrip.platform.dal.dao.DalHints) 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