Search in sources :

Example 21 with DfColumnMeta

use of org.dbflute.logic.jdbc.metadata.info.DfColumnMeta in project dbflute-core by dbflute.

the class DfSql2EntityTask method setupColumnComment.

protected void setupColumnComment(Map<String, DfColumnMeta> metaMap, String columnName, Column column) {
    final DfColumnMeta columnMeta = metaMap.get(columnName);
    final String sql2EntityRelatedTableName = columnMeta.getSql2EntityRelatedTableName();
    final Table relatedTable = getRelatedTable(sql2EntityRelatedTableName);
    String relatedComment = null;
    if (relatedTable != null) {
        final String relatedColumnName = columnMeta.getSql2EntityRelatedColumnName();
        final Column relatedColumn = relatedTable.getColumn(relatedColumnName);
        if (relatedColumn != null) {
            relatedComment = relatedColumn.getPlainComment();
        }
    }
    // the meta has its select column comment
    final String selectColumnComment = columnMeta.getColumnComment();
    final String commentMark = "// ";
    final String delimiter = getAliasDelimiterInDbComment();
    final StringBuilder sb = new StringBuilder();
    if (Srl.is_NotNull_and_NotTrimmedEmpty(relatedComment)) {
        sb.append(relatedComment);
        if (Srl.is_NotNull_and_NotTrimmedEmpty(selectColumnComment)) {
            // both exist
            if (Srl.is_NotNull_and_NotTrimmedEmpty(delimiter)) {
                // use alias option
                if (relatedComment.contains(delimiter)) {
                    // resolved in related comment
                    sb.append(ln()).append(commentMark).append(selectColumnComment);
                } else {
                    // unresolved yet
                    if (isDbCommentOnAliasBasis()) {
                        // related comment is alias
                        sb.append(delimiter);
                    } else {
                        // related comment is description
                        sb.append(ln());
                    }
                    sb.append(commentMark).append(selectColumnComment);
                }
            } else {
                // no alias option
                sb.append(ln()).append(commentMark).append(selectColumnComment);
            }
        }
    } else {
        // not found related comment
        if (Srl.is_NotNull_and_NotTrimmedEmpty(selectColumnComment)) {
            if (Srl.is_NotNull_and_NotTrimmedEmpty(delimiter)) {
                // use alias option
                if (isDbCommentOnAliasBasis()) {
                    // select column comment is treated as description
                    sb.append(delimiter);
                }
            }
            sb.append(commentMark).append(selectColumnComment);
        }
    }
    column.setPlainComment(sb.toString());
}
Also used : DfColumnMeta(org.dbflute.logic.jdbc.metadata.info.DfColumnMeta) Table(org.apache.torque.engine.database.model.Table) Column(org.apache.torque.engine.database.model.Column)

Example 22 with DfColumnMeta

use of org.dbflute.logic.jdbc.metadata.info.DfColumnMeta in project dbflute-core by dbflute.

the class DfSql2EntityTask method setupTorqueType.

protected void setupTorqueType(Map<String, DfColumnMeta> metaMap, String columnName, Column column, boolean allCommonColumn) {
    // - - - - - - - - - -/
    if (allCommonColumn) {
        final String commonColumnTorqueType = getCommonColumnTorqueType(columnName);
        if (commonColumnTorqueType != null) {
            column.setJdbcType(commonColumnTorqueType);
            return;
        }
    }
    final DfColumnMeta columnMeta = metaMap.get(columnName);
    final String columnTorqueType = getColumnTorqueType(columnMeta);
    column.setJdbcType(columnTorqueType);
}
Also used : DfColumnMeta(org.dbflute.logic.jdbc.metadata.info.DfColumnMeta)

Example 23 with DfColumnMeta

use of org.dbflute.logic.jdbc.metadata.info.DfColumnMeta in project dbflute-core by dbflute.

the class DfSql2EntityTask method setupColumnSizeContainsDigit.

protected void setupColumnSizeContainsDigit(Map<String, DfColumnMeta> metaMap, String columnName, Column column) {
    final DfColumnMeta columnMeta = metaMap.get(columnName);
    final int columnSize = columnMeta.getColumnSize();
    final int decimalDigits = columnMeta.getDecimalDigits();
    column.setupColumnSize(columnSize, decimalDigits);
}
Also used : DfColumnMeta(org.dbflute.logic.jdbc.metadata.info.DfColumnMeta)

Example 24 with DfColumnMeta

use of org.dbflute.logic.jdbc.metadata.info.DfColumnMeta in project dbflute-core by dbflute.

the class DfSql2EntityTask method setupDbType.

protected void setupDbType(Map<String, DfColumnMeta> metaMap, String columnName, Column column) {
    final DfColumnMeta columnMeta = metaMap.get(columnName);
    final String dbTypeName;
    final String plainName = columnMeta.getDbTypeName();
    if (Srl.contains(plainName, ".")) {
        // basically for ARRAY and STRUCT type
        final String catalogSchema = Srl.substringLastFront(plainName, ".");
        final UnifiedSchema unifiedSchema = UnifiedSchema.createAsDynamicSchema(catalogSchema);
        if (unifiedSchema.isMainSchema()) {
            dbTypeName = Srl.substringLastRear(plainName, ".");
        } else {
            dbTypeName = plainName;
        }
    } else {
        dbTypeName = plainName;
    }
    column.setDbType(dbTypeName);
}
Also used : DfColumnMeta(org.dbflute.logic.jdbc.metadata.info.DfColumnMeta) UnifiedSchema(org.apache.torque.engine.database.model.UnifiedSchema)

Example 25 with DfColumnMeta

use of org.dbflute.logic.jdbc.metadata.info.DfColumnMeta in project dbflute-core by dbflute.

the class DfColumnValueConverter method processString.

protected String processString(String tableName, String columnName, Map<String, DfColumnMeta> columnMetaMap, String filteredValue, String before, String after) {
    if (!"$$String$$".equalsIgnoreCase(before)) {
        // no converted
        return null;
    }
    final DfColumnMeta columnMeta = columnMetaMap.get(columnName);
    final Class<?> boundType = _bindTypeProvider.provide(tableName, columnMeta);
    if (!String.class.isAssignableFrom(boundType)) {
        // no converted
        return null;
    }
    if (after.equalsIgnoreCase("$$NullToEmpty$$")) {
        if (filteredValue == null) {
            return "";
        }
    }
    // no converted
    return null;
}
Also used : DfColumnMeta(org.dbflute.logic.jdbc.metadata.info.DfColumnMeta)

Aggregations

DfColumnMeta (org.dbflute.logic.jdbc.metadata.info.DfColumnMeta)71 SQLException (java.sql.SQLException)16 Connection (java.sql.Connection)10 LinkedHashMap (java.util.LinkedHashMap)9 Map (java.util.Map)8 File (java.io.File)7 StringKeyMap (org.dbflute.helper.StringKeyMap)7 ResultSet (java.sql.ResultSet)5 Statement (java.sql.Statement)5 ArrayList (java.util.ArrayList)5 DfJDBCException (org.dbflute.exception.DfJDBCException)5 FileInputStream (java.io.FileInputStream)4 BigDecimal (java.math.BigDecimal)4 DatabaseMetaData (java.sql.DatabaseMetaData)4 PreparedStatement (java.sql.PreparedStatement)4 Timestamp (java.sql.Timestamp)4 HashMap (java.util.HashMap)4 StringSet (org.dbflute.helper.StringSet)4 DfDataRow (org.dbflute.helper.dataset.DfDataRow)4 DfDataTable (org.dbflute.helper.dataset.DfDataTable)4