Search in sources :

Example 6 with StringSet

use of org.dbflute.helper.StringSet in project dbflute-core by dbflute.

the class DfDelimiterDataListedColumnHandler method setupColumnNameList.

public void setupColumnNameList(List<String> columnNameList, DfDelimiterDataFirstLineInfo firstLineInfo, Map<String, DfColumnMeta> columnMetaMap, Map<String, String> defaultValueMap, Predicate<String> needsCheckingColumnDef, Consumer<List<String>> columnDefChecker) {
    columnNameList.addAll(firstLineInfo.getColumnNameList());
    if (columnNameList.isEmpty()) {
        throwDelimiterDataColumnDefNotFoundException(_dataFile, _tableDbName);
    }
    if (needsCheckingColumnDef.test(_dataDirectory)) {
        columnDefChecker.accept(columnNameList);
    }
    final StringSet columnSet = StringSet.createAsFlexible();
    columnSet.addAll(columnNameList);
    final List<String> additionalColumnList = new ArrayList<String>();
    for (String defaultColumn : defaultValueMap.keySet()) {
        if (columnSet.contains(defaultColumn)) {
            continue;
        }
        if (columnMetaMap.containsKey(defaultColumn)) {
            // only existing column in DB
            additionalColumnList.add(defaultColumn);
        }
    }
    // defined columns + default columns (existing in DB)
    columnNameList.addAll(additionalColumnList);
}
Also used : StringSet(org.dbflute.helper.StringSet) ArrayList(java.util.ArrayList)

Example 7 with StringSet

use of org.dbflute.helper.StringSet in project dbflute-core by dbflute.

the class DfArrayExtractorOracle method doExtractFlatArrayInfoSecondMap.

// ===================================================================================
// Second Array Info
// =================
protected StringKeyMap<DfTypeArrayInfo> doExtractFlatArrayInfoSecondMap(UnifiedSchema unifiedSchema) {
    final StringKeyMap<DfTypeArrayInfo> flatArrayInfoMap = StringKeyMap.createAsFlexibleOrdered();
    final List<DfProcedureArgumentInfo> argInfoList = extractProcedureArgumentInfoList(unifiedSchema);
    for (int i = 0; i < argInfoList.size(); i++) {
        final DfProcedureArgumentInfo argInfo = argInfoList.get(i);
        final String argumentName = argInfo.getArgumentName();
        if (Srl.is_Null_or_TrimmedEmpty(argumentName)) {
            continue;
        }
        final String dataType = argInfo.getDataType();
        if (!isDataTypeArray(dataType)) {
            continue;
        }
        final String typeName = argInfo.getTypeName();
        if (Srl.is_Null_or_TrimmedEmpty(typeName)) {
            continue;
        }
        setupFlatArrayInfo(flatArrayInfoMap, argInfoList, argInfo, i);
    }
    final StringSet allArrayTypeSet = extractSimpleArrayNameSet(unifiedSchema);
    for (String allArrayTypeName : allArrayTypeSet) {
        if (!flatArrayInfoMap.containsKey(allArrayTypeName)) {
            final DfTypeArrayInfo arrayInfo = new DfTypeArrayInfo(unifiedSchema, allArrayTypeName);
            // the way to get the info is also unknown
            arrayInfo.setElementType("Unknown");
            flatArrayInfoMap.put(allArrayTypeName, arrayInfo);
        }
    }
    return flatArrayInfoMap;
}
Also used : StringSet(org.dbflute.helper.StringSet) DfTypeArrayInfo(org.dbflute.logic.jdbc.metadata.info.DfTypeArrayInfo) DfProcedureArgumentInfo(org.dbflute.logic.jdbc.metadata.info.DfProcedureArgumentInfo)

Example 8 with StringSet

use of org.dbflute.helper.StringSet in project dbflute-core by dbflute.

the class DfArrayExtractorOracle method extractSimpleArrayNameSet.

// ===================================================================================
// Simple Type Info
// ================
protected StringSet extractSimpleArrayNameSet(UnifiedSchema unifiedSchema) {
    final List<Map<String, String>> resultList = selectSimpleArray(unifiedSchema);
    final StringSet arrayTypeSet = StringSet.createAsFlexibleOrdered();
    for (Map<String, String> map : resultList) {
        arrayTypeSet.add(buildArrayTypeName(map.get("TYPE_NAME"), unifiedSchema));
    }
    return arrayTypeSet;
}
Also used : StringSet(org.dbflute.helper.StringSet) Map(java.util.Map) StringKeyMap(org.dbflute.helper.StringKeyMap)

Example 9 with StringSet

use of org.dbflute.helper.StringSet in project dbflute-core by dbflute.

the class DfSchemaXmlSerializer method helpColumnAdjustment.

protected List<DfColumnMeta> helpColumnAdjustment(DatabaseMetaData dbMeta, DfTableMeta tableMeta, List<DfColumnMeta> columnList) {
    if (!canHandleSynonym(tableMeta)) {
        return columnList;
    }
    final DfSynonymMeta synonym = getSynonymMetaInfo(tableMeta);
    if (synonym == null) {
        // means not synonym or no supplementary info
        return columnList;
    }
    final List<DfColumnMeta> metaInfoList = synonym.getColumnMetaInfoList();
    if (metaInfoList.isEmpty()) {
        return metaInfoList;
    }
    if (synonym.isDBLink() && columnList.isEmpty()) {
        columnList = metaInfoList;
    } else if (metaInfoList.size() != columnList.size()) {
        // for Oracle's bug(?), which is following:
        // /- - - - - - - - - - - - - - - - - - - - - - - - - - -
        // For example, Schema A, B are like this:
        // A: FOO table
        // B: FOO table, BAR synonym to A's FOO table
        // BAR synonym's columns are from both A and B's FOO table.
        // (means that BAR synonym has other table's columns)
        // Why? my friend, the Oracle JDBC Driver!
        // - - - - - - - - - -/
        final StringSet columnSet = StringSet.createAsCaseInsensitive();
        for (DfColumnMeta columnMeta : metaInfoList) {
            columnSet.add(columnMeta.getColumnName());
        }
        final List<DfColumnMeta> filteredList = new ArrayList<DfColumnMeta>();
        for (DfColumnMeta columnMeta : columnList) {
            if (columnSet.contains(columnMeta.getColumnName())) {
                filteredList.add(columnMeta);
            }
        }
        columnList = filteredList;
    }
    return columnList;
}
Also used : DfColumnMeta(org.dbflute.logic.jdbc.metadata.info.DfColumnMeta) DfSynonymMeta(org.dbflute.logic.jdbc.metadata.info.DfSynonymMeta) StringSet(org.dbflute.helper.StringSet) List(java.util.List) ArrayList(java.util.ArrayList)

Example 10 with StringSet

use of org.dbflute.helper.StringSet in project dbflute-core by dbflute.

the class DfAdditionalForeignKeyInitializer method processAllTableFK.

protected void processAllTableFK(String foreignKeyName, String foreignTableName, List<String> foreignColumnNameList, DfAdditionalForeignKeyOption option) {
    if (option.isFixedOnlyJoin()) {
        String msg = "Cannot use fixedOnlyJoin when all-table FK: " + foreignKeyName;
        throw new DfIllegalPropertySettingException(msg);
    }
    // for check about same-column self reference
    final Table foreignTable = getTable(foreignTableName);
    final StringSet foreignColumnSet = StringSet.createAsFlexible();
    foreignColumnSet.addAll(foreignColumnNameList);
    for (Table table : getTableList()) {
        final String localTableName = table.getTableDbName();
        final List<String> localColumnNameList = getLocalColumnNameList(table, foreignKeyName, foreignTableName, foreignColumnNameList, localTableName, option, true, false);
        if (!table.containsColumn(localColumnNameList)) {
            continue;
        }
        // check same-column self reference
        final StringSet localColumnSet = StringSet.createAsFlexible();
        localColumnSet.addAll(localColumnNameList);
        final boolean selfReference = table.getTableDbName().equals(foreignTable.getTableDbName());
        if (selfReference && localColumnSet.equalsUnderCharOption(foreignColumnSet)) {
            continue;
        }
        // check same foreign key existence
        final String fixedSuffix = option.getFixedSuffix();
        final ForeignKey existingFK = table.findExistingForeignKey(foreignTableName, localColumnNameList, foreignColumnNameList, fixedSuffix);
        if (existingFK != null) {
            _log.info("The foreign key has already set up: " + foreignKeyName + "(" + fixedSuffix + ")");
            reflectOptionToExistingFKIfNeeds(foreignKeyName, option, existingFK);
            continue;
        }
        final String currentForeignKeyName = foreignKeyName + "_" + toConstraintPart(localTableName);
        setupForeignKeyToTable(currentForeignKeyName, foreignTableName, foreignColumnNameList, table, localColumnNameList, option);
        showResult(foreignTableName, foreignColumnNameList, table, localColumnNameList, option);
    }
}
Also used : Table(org.apache.torque.engine.database.model.Table) StringSet(org.dbflute.helper.StringSet) ForeignKey(org.apache.torque.engine.database.model.ForeignKey) DfIllegalPropertySettingException(org.dbflute.exception.DfIllegalPropertySettingException)

Aggregations

StringSet (org.dbflute.helper.StringSet)10 DfColumnMeta (org.dbflute.logic.jdbc.metadata.info.DfColumnMeta)4 ArrayList (java.util.ArrayList)3 Connection (java.sql.Connection)2 DatabaseMetaData (java.sql.DatabaseMetaData)2 SQLException (java.sql.SQLException)2 Statement (java.sql.Statement)2 Entry (java.util.Map.Entry)2 DfAutoIncrementExtractor (org.dbflute.logic.jdbc.metadata.basic.DfAutoIncrementExtractor)2 DfColumnExtractor (org.dbflute.logic.jdbc.metadata.basic.DfColumnExtractor)2 DfPrimaryKeyMeta (org.dbflute.logic.jdbc.metadata.info.DfPrimaryKeyMeta)2 DfTableMeta (org.dbflute.logic.jdbc.metadata.info.DfTableMeta)2 ResultSet (java.sql.ResultSet)1 List (java.util.List)1 Map (java.util.Map)1 ForeignKey (org.apache.torque.engine.database.model.ForeignKey)1 Table (org.apache.torque.engine.database.model.Table)1 DfIllegalPropertySettingException (org.dbflute.exception.DfIllegalPropertySettingException)1 StringKeyMap (org.dbflute.helper.StringKeyMap)1 DfProcedureArgumentInfo (org.dbflute.logic.jdbc.metadata.info.DfProcedureArgumentInfo)1