Search in sources :

Example 6 with DfJdbcFacade

use of org.dbflute.helper.jdbc.facade.DfJdbcFacade in project dbflute-core by dbflute.

the class DfSchemaInitializerJdbc method executeFirstSqlProcess.

protected void executeFirstSqlProcess(Connection conn, List<DfTableMeta> tableMetaList) {
    if (_initializeFirstSqlList == null || _initializeFirstSqlList.isEmpty()) {
        return;
    }
    final DfJdbcFacade jdbcFacade = new DfJdbcFacade(conn);
    for (String firstSql : _initializeFirstSqlList) {
        logReplaceSql(firstSql);
        jdbcFacade.execute(firstSql);
    }
}
Also used : DfJdbcFacade(org.dbflute.helper.jdbc.facade.DfJdbcFacade)

Example 7 with DfJdbcFacade

use of org.dbflute.helper.jdbc.facade.DfJdbcFacade in project dbflute-core by dbflute.

the class DfSchemaInitializerPostgreSQL method dropSequence.

// ===================================================================================
// Drop Sequence
// =============
@Override
protected void dropSequence(Connection conn, List<DfTableMeta> tableMetaList) {
    final String catalog = _unifiedSchema.existsPureCatalog() ? _unifiedSchema.getPureCatalog() : null;
    final String schema = _unifiedSchema.getPureSchema();
    final List<String> sequenceNameList = new ArrayList<String>();
    final DfJdbcFacade jdbcFacade = new DfJdbcFacade(conn);
    final String sequenceColumnName = "sequence_name";
    final StringBuilder sb = new StringBuilder();
    sb.append("select ").append(sequenceColumnName).append(" from information_schema.sequences");
    sb.append(" where ");
    if (Srl.is_NotNull_and_NotTrimmedEmpty(catalog)) {
        sb.append("sequence_catalog = '").append(catalog).append("'").append(" and ");
    }
    sb.append("sequence_schema = '").append(schema).append("'");
    final String sql = sb.toString();
    final List<String> sequenceColumnList = Arrays.asList(sequenceColumnName);
    final List<Map<String, String>> resultList = jdbcFacade.selectStringList(sql, sequenceColumnList);
    for (Map<String, String> recordMap : resultList) {
        sequenceNameList.add(recordMap.get(sequenceColumnName));
    }
    for (String sequenceName : sequenceNameList) {
        if (isSequenceExcept(sequenceName)) {
            continue;
        }
        final String sequenceSqlName = _unifiedSchema.buildSqlName(sequenceName);
        final String dropSequenceSql = "drop sequence " + sequenceSqlName;
        logReplaceSql(dropSequenceSql);
        jdbcFacade.execute(dropSequenceSql);
    }
}
Also used : ArrayList(java.util.ArrayList) Map(java.util.Map) DfJdbcFacade(org.dbflute.helper.jdbc.facade.DfJdbcFacade)

Example 8 with DfJdbcFacade

use of org.dbflute.helper.jdbc.facade.DfJdbcFacade in project dbflute-core by dbflute.

the class DfArrayExtractorOracle method selectSimpleArray.

protected List<Map<String, String>> selectSimpleArray(UnifiedSchema unifiedSchema) {
    final DfJdbcFacade facade = new DfJdbcFacade(_dataSource);
    final List<String> columnList = new ArrayList<String>();
    columnList.add("TYPE_NAME");
    final String sql = buildSimpleArraySql(unifiedSchema);
    final List<Map<String, String>> resultList;
    try {
        log(sql);
        resultList = facade.selectStringList(sql, columnList);
    } catch (Exception continued) {
        // because it's basically assist info
        log("Failed to select simple array info: " + continued.getMessage());
        return DfCollectionUtil.emptyList();
    }
    return resultList;
}
Also used : ArrayList(java.util.ArrayList) Map(java.util.Map) StringKeyMap(org.dbflute.helper.StringKeyMap) DfJdbcFacade(org.dbflute.helper.jdbc.facade.DfJdbcFacade)

Example 9 with DfJdbcFacade

use of org.dbflute.helper.jdbc.facade.DfJdbcFacade in project dbflute-core by dbflute.

the class DfDatetimePrecisionExtractorMySQL method extractDatetimePrecisionMap.

public Map<String, Map<String, Integer>> extractDatetimePrecisionMap(Set<String> tableSet) {
    try {
        final Map<String, Map<String, Integer>> precisionMap = StringKeyMap.createAsFlexibleOrdered();
        final DfJdbcFacade facade = new DfJdbcFacade(_dataSource);
        final List<String> columnList = DfCollectionUtil.newArrayList("TABLE_NAME", "COLUMN_NAME", "DATETIME_PRECISION");
        final StringBuilder sb = new StringBuilder();
        sb.append("select ").append(Srl.connectByDelimiter(columnList, ", "));
        sb.append(" from INFORMATION_SCHEMA.COLUMNS");
        sb.append(" where TABLE_SCHEMA = '").append(_unifiedSchema.getPureCatalog()).append("'");
        // unneeded (use if performance problem at future)
        // if (!tableSet.isEmpty()) { // just in case
        // sb.append(" and TABLE_NAME in ('").append(Srl.connectByDelimiter(tableSet, "', '")).append("')");
        // }
        sb.append(" and DATA_TYPE = 'datetime'");
        final String sql = sb.toString();
        _log.info(sql);
        final List<Map<String, String>> resultList = facade.selectStringList(sql, columnList);
        for (Map<String, String> recordMap : resultList) {
            final String tableName = recordMap.get("TABLE_NAME");
            final String columnName = recordMap.get("COLUMN_NAME");
            final String datetimePrecision = recordMap.get("DATETIME_PRECISION");
            Map<String, Integer> columnMap = precisionMap.get(tableName);
            if (columnMap == null) {
                columnMap = StringKeyMap.createAsFlexibleOrdered();
                precisionMap.put(tableName, columnMap);
            }
            columnMap.put(columnName, Integer.valueOf(datetimePrecision));
        }
        return precisionMap;
    } catch (RuntimeException continued) {
        _log.info("Failed to select date-time precision, so you cannot use date precision option.", continued);
        return Collections.emptyMap();
    }
}
Also used : Map(java.util.Map) StringKeyMap(org.dbflute.helper.StringKeyMap) DfJdbcFacade(org.dbflute.helper.jdbc.facade.DfJdbcFacade)

Example 10 with DfJdbcFacade

use of org.dbflute.helper.jdbc.facade.DfJdbcFacade in project dbflute-core by dbflute.

the class DfProcedureSynonymExtractorOracle method judgeSynonymSelectable.

protected void judgeSynonymSelectable(DfSynonymMeta info) {
    final DfJdbcFacade facade = new DfJdbcFacade(_dataSource);
    final String synonymSqlName = info.buildSynonymSqlName();
    final String sql = "select * from " + synonymSqlName + " where 0=1";
    try {
        final List<String> columnList = new ArrayList<String>();
        columnList.add("dummy");
        facade.selectStringList(sql, columnList);
        info.setSelectable(true);
    } catch (RuntimeException ignored) {
        info.setSelectable(false);
    }
}
Also used : ArrayList(java.util.ArrayList) DfJdbcFacade(org.dbflute.helper.jdbc.facade.DfJdbcFacade)

Aggregations

DfJdbcFacade (org.dbflute.helper.jdbc.facade.DfJdbcFacade)23 Map (java.util.Map)13 ArrayList (java.util.ArrayList)12 StringKeyMap (org.dbflute.helper.StringKeyMap)5 DfJFadStringConverter (org.dbflute.helper.jdbc.facade.DfJFadStringConverter)4 ValueType (org.dbflute.jdbc.ValueType)4 LinkedHashMap (java.util.LinkedHashMap)2 DfJFadCursorCallback (org.dbflute.helper.jdbc.facade.DfJFadCursorCallback)2 SQLException (java.sql.SQLException)1 SQLFailureException (org.dbflute.exception.SQLFailureException)1 DfProcedureArgumentInfo (org.dbflute.logic.jdbc.metadata.info.DfProcedureArgumentInfo)1