Search in sources :

Example 6 with Column

use of org.apache.torque.engine.database.model.Column in project dbflute-core by dbflute.

the class DfSPolicyWholeThemeChecker method determineSameWhatIfSameColumnAlias.

protected String determineSameWhatIfSameColumnAlias(Database database, Function<Column, Object> valueProvider, boolean ignoreEmpty) {
    final List<Table> myTableList = toTableList(database);
    for (Table myTable : myTableList) {
        final List<Column> myColumnList = myTable.getColumnList();
        for (Column myColumn : myColumnList) {
            if (!isTargetColumn(myColumn)) {
                continue;
            }
            if (!myColumn.hasAlias()) {
                continue;
            }
            for (Table yourTable : myTableList) {
                if (myTable.equals(yourTable)) {
                    continue;
                }
                final String myColumnAlias = myColumn.getAlias();
                final List<Column> yourColumnList = yourTable.getColumnList();
                for (Column yourColumn : yourColumnList) {
                    if (!isTargetColumn(yourColumn)) {
                        continue;
                    }
                    if (!yourColumn.hasAlias()) {
                        continue;
                    }
                    if (myColumnAlias.equals(yourColumn.getAlias())) {
                        // same column alias
                        final Object myValue = valueProvider.apply(myColumn);
                        final Object yourValue = valueProvider.apply(yourColumn);
                        if (ignoreEmpty && eitherEmpty(myValue, yourValue)) {
                            continue;
                        }
                        if (!isEqual(myValue, yourValue)) {
                            // different in spite of same column alias
                            return toColumnExp(myColumn) + "=" + myValue + ", " + toColumnExp(yourColumn) + "=" + yourValue;
                        }
                    }
                }
            }
        }
    }
    return null;
}
Also used : Table(org.apache.torque.engine.database.model.Table) Column(org.apache.torque.engine.database.model.Column)

Example 7 with Column

use of org.apache.torque.engine.database.model.Column in project dbflute-core by dbflute.

the class DfPmbMetaData method adjustPropertyMetaFinally.

// ===================================================================================
//          Adjustment
// ==========
public void adjustPropertyMetaFinally(AppData schemaData) {
    // basically this adjusts property types for auto-detected properties
    // it should be called after initialization
    // (not called by procedure)
    final DfLanguageDependency lang = getBasicProperties().getLanguageDependency();
    final DfLanguagePropertyPackageResolver packageResolver = lang.getLanguagePropertyPackageResolver();
    final Set<String> autoDetectedPropertyNameSet = getAutoDetectedPropertyNameSet();
    if (autoDetectedPropertyNameSet == null || autoDetectedPropertyNameSet.isEmpty()) {
        return;
    }
    final Map<String, String> propertyNameTypeMap = getPropertyNameTypeMap();
    for (String propertyName : autoDetectedPropertyNameSet) {
        // loop for auto-detected properties
        final String beforeType = propertyNameTypeMap.get(propertyName);
        String afterType = null;
        if (isPropertyTypeList(propertyName) && isPropertyOptionClassification(propertyName, schemaData)) {
            if (isPropertyOptionClassificationFixedElement(propertyName)) {
            // :cls(Maihama.Sea) or :cls(Maihama.Sea, Land)
            // e.g. /*pmb.maihamaList:cls(Maihama.Sea)*/ or /*pmb.maihamaList:cls(Maihama.Sea, Land)*/
            // no adjustment because fixed element list needs List<String> as framework-internal property
            } else {
                // list property by public setter, wants to be e.g. List<CDef.Maihama>
                final String classificationName = getPropertyOptionClassificationName(propertyName, schemaData);
                final String plainType = "$$CDef$$." + classificationName;
                // ParameterBean has the "import" clause of language-embedded utility
                afterType = packageResolver.resolvePackageNameExceptUtil(plainType);
            }
        } else if (!beforeType.contains("CDef")) {
            final Column refColumn = getPropertyOptionReferenceColumn(propertyName, schemaData);
            if (refColumn != null) {
                // not CDef and reference
                afterType = refColumn.getJavaNative();
                final String utilPrefix = "java.util.";
                if (Srl.startsWith(afterType, utilPrefix) && Srl.count(afterType, ".") == 2) {
                    // ParameterBean has the "import" clause of language-embedded utility
                    afterType = Srl.substringFirstRear(afterType, utilPrefix);
                }
            }
        }
        if (afterType != null) {
            final String finalType;
            if (isPropertyTypeList(propertyName)) {
                final DfLanguageGrammar grammar = getLanguageGrammar();
                final String beginMark = grammar.getGenericBeginMark();
                final String endMark = grammar.getGenericEndMark();
                final String prefix = Srl.substringFirstFront(beforeType, "List" + beginMark);
                final String suffix = Srl.substringLastRear(beforeType, endMark);
                finalType = prefix + "List" + beginMark + afterType + endMark + suffix;
            } else {
                finalType = afterType;
            }
            // override
            propertyNameTypeMap.put(propertyName, finalType);
        }
    }
}
Also used : Column(org.apache.torque.engine.database.model.Column) DfLanguageGrammar(org.dbflute.logic.generate.language.grammar.DfLanguageGrammar) DfLanguageDependency(org.dbflute.logic.generate.language.DfLanguageDependency) DfLanguagePropertyPackageResolver(org.dbflute.logic.generate.language.pkgstyle.DfLanguagePropertyPackageResolver)

Example 8 with Column

use of org.apache.torque.engine.database.model.Column in project dbflute-core by dbflute.

the class DfPmbMetaData method getPropertyOptionClassificationColumn.

protected Column getPropertyOptionClassificationColumn(String propertyName, AppData schemaData) {
    final Column column = getPropertyOptionReferenceColumn(propertyName, schemaData);
    if (column == null) {
        // no way
        String msg = "The reference column should exist at this timing:";
        msg = msg + " property=" + _className + "." + propertyName;
        throw new IllegalStateException(msg);
    }
    if (!column.hasClassification()) {
        // no way
        String msg = "The reference column should have a classification at this timing:";
        msg = msg + " property=" + _className + "." + propertyName + " column=" + column;
        throw new IllegalStateException(msg);
    }
    return column;
}
Also used : Column(org.apache.torque.engine.database.model.Column)

Example 9 with Column

use of org.apache.torque.engine.database.model.Column in project dbflute-core by dbflute.

the class DfPmbPropertyOptionReference method getPmbMetaDataPropertyOptionReferenceColumn.

// ===================================================================================
// Reference Column
// ================
public Column getPmbMetaDataPropertyOptionReferenceColumn(AppData appData) {
    if (appData == null) {
        return null;
    }
    final Database database = appData.getDatabase();
    if (database == null) {
        return null;
    }
    final String refPrefix = OPTION_PREFIX;
    final String refSuffix = OPTION_SUFFIX;
    final String option;
    {
        final String optionExp = getPmbMetaDataPropertyOption();
        if (optionExp == null) {
            return null;
        }
        final List<String> splitOption = splitOption(optionExp);
        String firstOption = null;
        for (String element : splitOption) {
            if (element.startsWith(refPrefix) && element.endsWith(refSuffix)) {
                firstOption = element;
                break;
            }
        }
        if (firstOption == null) {
            return null;
        }
        option = firstOption;
    }
    final ScopeInfo scope = Srl.extractScopeFirst(option, refPrefix, refSuffix);
    final String content = scope.getContent().trim();
    final String delimiter = ".";
    final String tableName;
    final String columnName;
    if (content.contains(".")) {
        tableName = Srl.substringFirstFront(content, delimiter);
        columnName = Srl.substringFirstRear(content, delimiter);
    } else {
        tableName = content;
        columnName = null;
    }
    final Table table = database.getTable(tableName);
    if (table == null) {
        throwParameterBeanReferenceTableNotFoundException(option, tableName);
    }
    final String columnKeyName;
    if (columnName != null) {
        columnKeyName = columnName;
    } else {
        if (_pmbMetaData.isPropertyTypeList(_propertyName) && Srl.endsWith(_propertyName, "List")) {
            // e.g. statusList to status
            columnKeyName = Srl.substringLastFront(_propertyName, "List");
        } else {
            columnKeyName = _propertyName;
        }
    }
    final Column column = table.getColumn(columnKeyName);
    if (column == null) {
        throwParameterBeanReferenceColumnNotFoundException(option, tableName, columnName);
    }
    return column;
}
Also used : Table(org.apache.torque.engine.database.model.Table) Column(org.apache.torque.engine.database.model.Column) Database(org.apache.torque.engine.database.model.Database) List(java.util.List) ScopeInfo(org.dbflute.util.Srl.ScopeInfo)

Example 10 with Column

use of org.apache.torque.engine.database.model.Column in project dbflute-core by dbflute.

the class DfLReverseDataExtractor method createColumnValueTypeMap.

protected Map<String, ValueType> createColumnValueTypeMap(List<Column> columnList) {
    final Map<String, ValueType> valueTypeMap = new LinkedHashMap<String, ValueType>();
    for (Column column : columnList) {
        final String columnName = column.getName();
        // create value type for the column
        final ValueType valueType;
        if (column.isJavaNativeStringObject()) {
            if (column.isDbTypeStringClob()) {
                valueType = new StringClobType();
            } else {
                valueType = new StringType();
            }
        } else if (column.isJavaNativeDateObject()) {
            // date types should be treated correctly
            if (column.isJdbcTypeTime()) {
                valueType = new TimeType();
            } else if (column.isJdbcTypeTimestamp()) {
                valueType = new TimestampType();
            } else if (column.isJdbcTypeDate()) {
                if (column.isDbTypeOracleDate()) {
                    valueType = new UtilDateAsTimestampType();
                } else {
                    valueType = new UtilDateAsSqlDateType();
                }
            } else {
                // no way
                valueType = new TimestampType();
            }
        } else if (column.isJavaNativeBinaryObject()) {
            // unsupported BLOG as load data
            valueType = new NullBytesType();
        } else {
            // other types are treated as string
            // because ReplaceSchema can accept them
            valueType = new StringType();
        }
        valueTypeMap.put(columnName, valueType);
    }
    return valueTypeMap;
}
Also used : UtilDateAsSqlDateType(org.dbflute.s2dao.valuetype.basic.UtilDateAsSqlDateType) ValueType(org.dbflute.jdbc.ValueType) Column(org.apache.torque.engine.database.model.Column) StringType(org.dbflute.s2dao.valuetype.basic.StringType) StringClobType(org.dbflute.s2dao.valuetype.plugin.StringClobType) TimestampType(org.dbflute.s2dao.valuetype.basic.TimestampType) UtilDateAsTimestampType(org.dbflute.s2dao.valuetype.basic.UtilDateAsTimestampType) UtilDateAsTimestampType(org.dbflute.s2dao.valuetype.basic.UtilDateAsTimestampType) LinkedHashMap(java.util.LinkedHashMap) TimeType(org.dbflute.s2dao.valuetype.basic.TimeType)

Aggregations

Column (org.apache.torque.engine.database.model.Column)50 Table (org.apache.torque.engine.database.model.Table)16 List (java.util.List)10 Map (java.util.Map)8 ForeignKey (org.apache.torque.engine.database.model.ForeignKey)8 ArrayList (java.util.ArrayList)6 LinkedHashMap (java.util.LinkedHashMap)6 Database (org.apache.torque.engine.database.model.Database)5 DfBuildProperties (org.dbflute.DfBuildProperties)4 DfDataRow (org.dbflute.helper.dataset.DfDataRow)4 DfDataTable (org.dbflute.helper.dataset.DfDataTable)4 ExceptionMessageBuilder (org.dbflute.helper.message.ExceptionMessageBuilder)4 DfLanguageDependency (org.dbflute.logic.generate.language.DfLanguageDependency)4 Function (java.util.function.Function)3 File (java.io.File)2 IOException (java.io.IOException)2 SQLException (java.sql.SQLException)2 Entry (java.util.Map.Entry)2 Set (java.util.Set)2 Predicate (java.util.function.Predicate)2