Search in sources :

Example 21 with FreeSelectSqlBuilder

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

the class DalGroupDBDao method getAllGroupDbs.

public List<DalGroupDB> getAllGroupDbs() throws SQLException {
    FreeSelectSqlBuilder<List<DalGroupDB>> builder = new FreeSelectSqlBuilder<>(dbCategory);
    StringBuilder sb = new StringBuilder();
    sb.append("SELECT a.id,a.dbname,a.dal_group_id,a.db_address,a.db_port,a.db_user,a.db_password,a.db_catalog,a.db_providerName,a.mode_type,b.group_name as comment ");
    sb.append("FROM alldbs a LEFT JOIN dal_group b ON b.id = a.dal_group_id ");
    builder.setTemplate(sb.toString());
    StatementParameters parameters = new StatementParameters();
    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 22 with FreeSelectSqlBuilder

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

the class DalGroupDBDao method getAllDbAllinOneNames.

public List<String> getAllDbAllinOneNames() throws SQLException {
    FreeSelectSqlBuilder<List<String>> builder = new FreeSelectSqlBuilder<>(dbCategory);
    builder.setTemplate("SELECT dbname FROM alldbs");
    StatementParameters parameters = new StatementParameters();
    builder.mapWith(dalGroupDBRowMapper).simpleType();
    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 23 with FreeSelectSqlBuilder

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

the class DalGroupDBDao method getGroupDBsByGroup.

public List<DalGroupDB> getGroupDBsByGroup(int groupId) 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=?");
    StatementParameters parameters = new StatementParameters();
    int i = 1;
    parameters.set(i++, "dal_group_id", Types.INTEGER, groupId);
    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 24 with FreeSelectSqlBuilder

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

the class DalGroupDBDao method getGroupDBsByGroupAndModeType.

public List<DalGroupDB> getGroupDBsByGroupAndModeType(int groupId, String modeType) throws SQLException {
    if (modeType == null) {
        return getGroupDBsByGroup(groupId);
    }
    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, modeType);
    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 25 with FreeSelectSqlBuilder

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

the class DaoBySqlBuilder method updateTask.

public int updateTask(GenTaskBySqlBuilder task) throws SQLException {
    {
        FreeSelectSqlBuilder<GenTaskBySqlBuilder> builder = new FreeSelectSqlBuilder<>(dbCategory);
        builder.setTemplate("SELECT 1 FROM task_auto WHERE id != ? AND project_id=? AND db_name=? AND table_name=? AND method_name=? LIMIT 1");
        StatementParameters parameters = new StatementParameters();
        int i = 1;
        parameters.set(i++, "id", Types.INTEGER, task.getId());
        parameters.set(i++, "project_id", Types.INTEGER, task.getProject_id());
        parameters.set(i++, "db_name", Types.VARCHAR, task.getDatabaseSetName());
        parameters.set(i++, "table_name", Types.VARCHAR, task.getTable_name());
        parameters.set(i++, "method_name", Types.VARCHAR, task.getMethod_name());
        builder.mapWith(genTaskBySqlBuilderRowMapper).requireFirst().nullable();
        DalHints hints = DalHints.createIfAbsent(null).allowPartial();
        GenTaskBySqlBuilder entity = queryDao.query(builder, parameters, hints);
        if (entity != null)
            return 0;
    }
    FreeUpdateSqlBuilder builder = new FreeUpdateSqlBuilder(dbCategory);
    StringBuilder sb = new StringBuilder();
    sb.append("UPDATE task_auto SET project_id=?,db_name=?, table_name=?, class_name=?,method_name=?,");
    sb.append("sql_style=?,crud_type=?,fields=?,where_condition=?,sql_content=?,`generated`=?,");
    sb.append("version=version+1,update_user_no=?,update_time=?,comment=?,scalarType=?,");
    sb.append("pagination=?,orderby=?,approved=?,approveMsg=?,hints=? ");
    sb.append("WHERE id=? AND version = ?");
    builder.setTemplate(sb.toString());
    StatementParameters parameters = new StatementParameters();
    int i = 1;
    parameters.set(i++, "project_id", Types.INTEGER, task.getProject_id());
    parameters.set(i++, "db_name", Types.VARCHAR, task.getDatabaseSetName());
    parameters.set(i++, "table_name", Types.VARCHAR, task.getTable_name());
    parameters.set(i++, "class_name", Types.VARCHAR, task.getClass_name());
    parameters.set(i++, "method_name", Types.VARCHAR, task.getMethod_name());
    parameters.set(i++, "sql_style", Types.VARCHAR, task.getSql_style());
    parameters.set(i++, "crud_type", Types.VARCHAR, task.getCrud_type());
    parameters.set(i++, "fields", Types.LONGVARCHAR, task.getFields());
    parameters.set(i++, "where_condition", Types.LONGVARCHAR, task.getCondition());
    parameters.set(i++, "sql_content", Types.LONGVARCHAR, task.getSql_content());
    parameters.set(i++, "generated", Types.BIT, task.getGenerated());
    parameters.set(i++, "update_user_no", Types.VARCHAR, task.getUpdate_user_no());
    parameters.set(i++, "update_time", Types.TIMESTAMP, task.getUpdate_time());
    parameters.set(i++, "comment", Types.LONGVARCHAR, task.getComment());
    parameters.set(i++, "scalarType", Types.VARCHAR, task.getScalarType());
    parameters.set(i++, "pagination", Types.BIT, task.getPagination());
    parameters.set(i++, "orderby", Types.VARCHAR, task.getOrderby());
    parameters.set(i++, "approved", Types.INTEGER, task.getApproved());
    parameters.set(i++, "approveMsg", Types.LONGVARCHAR, task.getApproveMsg());
    parameters.set(i++, "hints", Types.VARCHAR, task.getHints());
    // parameters.set(i++, "length", Types.TINYINT, task.getLength());
    parameters.set(i++, "id", Types.INTEGER, task.getId());
    parameters.set(i++, "version", Types.INTEGER, task.getVersion());
    DalHints hints = DalHints.createIfAbsent(null);
    return queryDao.update(builder, parameters, hints);
}
Also used : FreeSelectSqlBuilder(com.ctrip.platform.dal.dao.sqlbuilder.FreeSelectSqlBuilder) DalHints(com.ctrip.platform.dal.dao.DalHints) FreeUpdateSqlBuilder(com.ctrip.platform.dal.dao.sqlbuilder.FreeUpdateSqlBuilder) StatementParameters(com.ctrip.platform.dal.dao.StatementParameters) GenTaskBySqlBuilder(com.ctrip.platform.dal.daogen.entity.GenTaskBySqlBuilder)

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