Search in sources :

Example 1 with Column

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

the class DfLReverseDataExtractor method createColumnValueTypeMap.

// ===================================================================================
// JDBC Handling
// =============
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 loda 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)

Example 2 with Column

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

the class DfLReverseDataExtractor method buildOrderByClause.

protected String buildOrderByClause(Table table) {
    final ForeignKey selfReferenceFK = table.getSelfReferenceForeignKey();
    final String orderBy;
    if (selfReferenceFK != null && selfReferenceFK.isSimpleKeyFK()) {
        final Column firstColumn = table.getColumn(selfReferenceFK.getFirstLocalColumnName());
        final String firstName = firstColumn.getColumnSqlNameDirectUse();
        orderBy = buildOrderByNullsFirst(firstName);
    } else {
        orderBy = "";
    }
    return orderBy;
}
Also used : Column(org.apache.torque.engine.database.model.Column) ForeignKey(org.apache.torque.engine.database.model.ForeignKey)

Example 3 with Column

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

the class DfLReverseOutputHandler method setupXlsDataTable.

// ===================================================================================
// Xls Data
// ========
protected void setupXlsDataTable(DfDataSet dataSet, Table table, List<Map<String, String>> extractedList, int sheetNumber, List<String> sectionInfoList) {
    final List<Map<String, String>> recordList;
    {
        final String tableInfo = "  " + table.getTableDispName() + " (" + extractedList.size() + ")";
        _log.info(tableInfo);
        sectionInfoList.add(tableInfo);
        if (extractedList.size() > _xlsLimit) {
            // just in case
            recordList = extractedList.subList(0, _xlsLimit);
        } else {
            recordList = extractedList;
        }
    }
    final DfDataTable dataTable = new DfDataTable(resolveSheetName(table, sheetNumber));
    final List<Column> columnList = table.getColumnList();
    for (Column column : columnList) {
        if (isExceptCommonColumn(column)) {
            continue;
        }
        dataTable.addColumn(column.getName(), DfDtsColumnTypes.STRING);
    }
    for (Map<String, String> recordMap : recordList) {
        final Set<String> columnNameSet = recordMap.keySet();
        final DfDataRow dataRow = dataTable.addRow();
        for (String columnName : columnNameSet) {
            if (!dataTable.hasColumn(columnName)) {
                // basically excepted common columns
                continue;
            }
            final String value = recordMap.get(columnName);
            dataRow.addValue(columnName, value);
        }
    }
    dataSet.addTable(dataTable);
}
Also used : Column(org.apache.torque.engine.database.model.Column) DfDataTable(org.dbflute.helper.dataset.DfDataTable) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) DfDataRow(org.dbflute.helper.dataset.DfDataRow)

Example 4 with Column

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

the class DfSPolicyTableStatementChecker method isIfTrue.

protected boolean isIfTrue(DfSPolicyStatement statement, DfSPolicyIfPart ifPart, Table table) {
    final String ifItem = ifPart.getIfItem();
    final String ifValue = ifPart.getIfValue();
    final boolean notIfValue = ifPart.isNotIfValue();
    if (ifItem.equalsIgnoreCase("tableName")) {
        return isHitExp(toComparingTableName(table), ifValue) == !notIfValue;
    } else if (ifItem.equalsIgnoreCase("alias")) {
        return isHitExp(table.getAlias(), ifValue) == !notIfValue;
    } else if (ifItem.equalsIgnoreCase("pk_dbType") || ifItem.equalsIgnoreCase("pkDbType")) {
        // for compatible
        if (table.hasPrimaryKey()) {
            final List<Column> pkList = table.getPrimaryKey();
            for (Column pk : pkList) {
                // required here (for PK's something)
                return isHitExp(pk.getDbType(), ifValue) == !notIfValue;
            }
        }
    } else if (ifItem.equalsIgnoreCase("pk_size")) {
        if (table.hasPrimaryKey()) {
            final List<Column> pkList = table.getPrimaryKey();
            for (Column pk : pkList) {
                // required here (for PK's something)
                return isHitExp(pk.getColumnSize(), ifValue) == !notIfValue;
            }
        }
    } else if (ifItem.equalsIgnoreCase("pk_dbType_with_size")) {
        if (table.hasPrimaryKey()) {
            final List<Column> pkList = table.getPrimaryKey();
            for (Column pk : pkList) {
                // required here (for PK's something)
                return isHitExp(toComparingDbTypeWithSize(pk), ifValue) == !notIfValue;
            }
        }
    } else {
        throwSchemaPolicyCheckIllegalIfThenStatementException(statement, "Unknown if-item: " + ifItem);
    }
    return false;
}
Also used : Column(org.apache.torque.engine.database.model.Column) List(java.util.List)

Example 5 with Column

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

the class DfSPolicyWholeThemeChecker method determineSameWhatIfSameColumnName.

protected String determineSameWhatIfSameColumnName(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;
            }
            for (Table yourTable : myTableList) {
                if (myTable.equals(yourTable)) {
                    continue;
                }
                final String myColumnName = myColumn.getName();
                final Column yourColumn = yourTable.getColumn(myColumnName);
                if (yourColumn != null) {
                    if (!isTargetColumn(yourColumn)) {
                        continue;
                    }
                    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 name
                        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)

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