Search in sources :

Example 46 with FreeSelectSqlBuilder

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

the class DalQueryDaoTest method queryListForInParamBuilderNew1.

// Test in parameters
private List<Short> queryListForInParamBuilderNew1(DalHints hints) throws SQLException {
    StatementParameters parameters = new StatementParameters();
    FreeSelectSqlBuilder<List<Short>> builder = new FreeSelectSqlBuilder<>();
    builder.with(parameters);
    List<Integer> inParam = new ArrayList<>();
    inParam.add(0);
    inParam.add(1);
    inParam.add(2);
    inParam.add(3);
    inParam.add(4);
    builder.selectAll().from(TABLE_NAME).where(in("type", inParam, Types.INTEGER));
    builder.mapWith(new ShortRowMapper());
    return dao.query(builder, parameters, hints.shardBy("type"));
}
Also used : FreeSelectSqlBuilder(com.ctrip.platform.dal.dao.sqlbuilder.FreeSelectSqlBuilder) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ShortRowMapper(com.ctrip.platform.dal.dao.helper.ShortRowMapper) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 47 with FreeSelectSqlBuilder

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

the class DalGroupDBDao method getGroupDBByDbName.

public DalGroupDB getGroupDBByDbName(String dbname) throws SQLException {
    FreeSelectSqlBuilder<DalGroupDB> builder = new FreeSelectSqlBuilder<>(dbCategory);
    builder.setTemplate("SELECT id, dbname, comment,dal_group_id, db_address, db_port, db_user, db_password, db_catalog, db_providerName, mode_type FROM alldbs WHERE dbname=?");
    StatementParameters parameters = new StatementParameters();
    int i = 1;
    parameters.set(i++, "dbname", Types.VARCHAR, dbname);
    builder.mapWith(dalGroupDBRowMapper).requireFirst().nullable();
    DalHints hints = DalHints.createIfAbsent(null).allowPartial();
    return queryDao.query(builder, parameters, hints);
}
Also used : FreeSelectSqlBuilder(com.ctrip.platform.dal.dao.sqlbuilder.FreeSelectSqlBuilder) DalHints(com.ctrip.platform.dal.dao.DalHints) StatementParameters(com.ctrip.platform.dal.dao.StatementParameters) DalGroupDB(com.ctrip.platform.dal.daogen.entity.DalGroupDB)

Example 48 with FreeSelectSqlBuilder

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

the class DalGroupDBDao method getDalClusterGroupDbsByGroupId.

public List<DalGroupDB> getDalClusterGroupDbsByGroupId(int groupId, String dbModeType) throws SQLException {
    FreeSelectSqlBuilder<List<DalGroupDB>> builder = new FreeSelectSqlBuilder<>(dbCategory);
    builder.setTemplate("SELECT id, dbname, comment,dal_group_id, db_address, db_port, db_user, db_password, db_catalog, db_providerName, mode_type FROM alldbs WHERE dal_group_id=? and mode_type=?");
    StatementParameters parameters = new StatementParameters();
    int i = 1;
    parameters.set(i++, "dal_group_id", Types.INTEGER, groupId);
    parameters.set(i++, "mode_type", Types.VARCHAR, dbModeType);
    builder.mapWith(dalGroupDBRowMapper);
    DalHints hints = DalHints.createIfAbsent(null).allowPartial();
    return queryDao.query(builder, parameters, hints);
}
Also used : FreeSelectSqlBuilder(com.ctrip.platform.dal.dao.sqlbuilder.FreeSelectSqlBuilder) DalHints(com.ctrip.platform.dal.dao.DalHints) StatementParameters(com.ctrip.platform.dal.dao.StatementParameters) ArrayList(java.util.ArrayList) List(java.util.List)

Example 49 with FreeSelectSqlBuilder

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

the class DaoByFreeSql method updateAndGetTasks.

public List<GenTaskByFreeSql> updateAndGetTasks(int projectId) throws SQLException {
    FreeSelectSqlBuilder<List<GenTaskByFreeSql>> builder = new FreeSelectSqlBuilder<>(dbCategory);
    StringBuilder sb = new StringBuilder();
    sb.append("SELECT id, project_id, db_name, class_name,pojo_name,method_name,crud_type,sql_content,parameters,`generated`,version,update_user_no,update_time,comment,scalarType,pojoType,pagination,sql_style,approved,approveMsg,hints ");
    sb.append("FROM task_sql WHERE project_id=? AND `generated`=FALSE");
    builder.setTemplate(sb.toString());
    StatementParameters parameters = new StatementParameters();
    int i = 1;
    parameters.set(i++, "project_id", Types.INTEGER, projectId);
    builder.mapWith(genTaskByFreeSqlRowMapper);
    DalHints hints = DalHints.createIfAbsent(null).allowPartial();
    List<GenTaskByFreeSql> list = queryDao.query(builder, parameters, hints);
    List<GenTaskByFreeSql> result = new ArrayList<>();
    if (list == null || list.size() == 0)
        return result;
    processList(list);
    for (GenTaskByFreeSql entity : list) {
        entity.setGenerated(true);
        if (updateTask(entity) > 0) {
            result.add(entity);
        }
    }
    return result;
}
Also used : FreeSelectSqlBuilder(com.ctrip.platform.dal.dao.sqlbuilder.FreeSelectSqlBuilder) DalHints(com.ctrip.platform.dal.dao.DalHints) StatementParameters(com.ctrip.platform.dal.dao.StatementParameters) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) GenTaskByFreeSql(com.ctrip.platform.dal.daogen.entity.GenTaskByFreeSql)

Example 50 with FreeSelectSqlBuilder

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

the class DaoByFreeSql method getTasksByProjectId.

public List<GenTaskByFreeSql> getTasksByProjectId(int projectId) throws SQLException {
    FreeSelectSqlBuilder<List<GenTaskByFreeSql>> builder = new FreeSelectSqlBuilder<>(dbCategory);
    StringBuilder sb = new StringBuilder();
    sb.append("SELECT id, project_id, mode_type, db_name, class_name,pojo_name,method_name,crud_type,sql_content,parameters,`generated`,version,update_user_no,update_time,comment,scalarType,pojoType,pagination,sql_style,approved,approveMsg,hints ");
    sb.append("FROM task_sql WHERE project_id=? order by id");
    builder.setTemplate(sb.toString());
    StatementParameters parameters = new StatementParameters();
    int i = 1;
    parameters.set(i++, "project_id", Types.INTEGER, projectId);
    builder.mapWith(genTaskByFreeSqlRowMapper);
    DalHints hints = DalHints.createIfAbsent(null).allowPartial();
    List<GenTaskByFreeSql> list = queryDao.query(builder, parameters, hints);
    processList(list);
    return list;
}
Also used : FreeSelectSqlBuilder(com.ctrip.platform.dal.dao.sqlbuilder.FreeSelectSqlBuilder) DalHints(com.ctrip.platform.dal.dao.DalHints) StatementParameters(com.ctrip.platform.dal.dao.StatementParameters) ArrayList(java.util.ArrayList) List(java.util.List) GenTaskByFreeSql(com.ctrip.platform.dal.daogen.entity.GenTaskByFreeSql)

Aggregations

FreeSelectSqlBuilder (com.ctrip.platform.dal.dao.sqlbuilder.FreeSelectSqlBuilder)61 StatementParameters (com.ctrip.platform.dal.dao.StatementParameters)44 DalHints (com.ctrip.platform.dal.dao.DalHints)38 List (java.util.List)38 ArrayList (java.util.ArrayList)22 Test (org.junit.Test)17 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)10 DalQueryDao (com.ctrip.platform.dal.dao.DalQueryDao)6 ShortRowMapper (com.ctrip.platform.dal.dao.helper.ShortRowMapper)6 DalDefaultJpaMapper (com.ctrip.platform.dal.dao.helper.DalDefaultJpaMapper)4 DatabaseSet (com.ctrip.platform.dal.daogen.entity.DatabaseSet)3 GenTaskByFreeSql (com.ctrip.platform.dal.daogen.entity.GenTaskByFreeSql)3 GenTaskBySqlBuilder (com.ctrip.platform.dal.daogen.entity.GenTaskBySqlBuilder)3 DalCustomRowMapper (com.ctrip.platform.dal.dao.helper.DalCustomRowMapper)2 FreeUpdateSqlBuilder (com.ctrip.platform.dal.dao.sqlbuilder.FreeUpdateSqlBuilder)2 DatabaseSetEntry (com.ctrip.platform.dal.daogen.entity.DatabaseSetEntry)2 GenTaskByTableViewSp (com.ctrip.platform.dal.daogen.entity.GenTaskByTableViewSp)2 Project (com.ctrip.platform.dal.daogen.entity.Project)2 Map (java.util.Map)2 ClientTestModel (com.ctrip.platform.dal.dao.unitbase.ClientTestModel)1