Search in sources :

Example 1 with DfColumnMeta

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

the class DfLoadingControlProp method resolveRelativeDate.

// ===================================================================================
// Date Adjustment
// ===============
public void resolveRelativeDate(String dataDirectory, String tableName, Map<String, Object> columnValueMap, Map<String, DfColumnMeta> columnMetaMap, Set<String> sysdateColumnSet, DfColumnBindTypeProvider bindTypeProvider, int rowNumber) {
    // was born at LUXA
    if (!hasDateAdjustment(dataDirectory, tableName)) {
        return;
    }
    final Map<String, Object> resolvedMap = new HashMap<String, Object>();
    for (Entry<String, Object> entry : columnValueMap.entrySet()) {
        final String columnName = entry.getKey();
        if (isSysdateColumn(sysdateColumnSet, columnName)) {
            // keep sysdate as default value
            continue;
        }
        final Object value = entry.getValue();
        if (value == null) {
            continue;
        }
        if (!isDateAdjustmentAllowedValueType(value)) {
            // out of target type
            continue;
        }
        if (!hasDateAdjustmentExp(dataDirectory, tableName, columnName)) {
            // no-adjustment column
            continue;
        }
        final DfColumnMeta columnMeta = columnMetaMap.get(columnName);
        final Class<?> bindType = bindTypeProvider.provide(tableName, columnMeta);
        if (bindType == null) {
            // unknown column type
            continue;
        }
        if (!isDateAdjustmentAllowedBindType(dataDirectory, tableName, columnName, bindType)) {
            // cannot be date
            continue;
        }
        final String dateExp = toAdjustedResourceDateExp(tableName, columnName, bindType, value);
        if (dateExp == null) {
            // e.g. wrong value
            continue;
        }
        final String adjusted = adjustDateIfNeeds(dataDirectory, tableName, columnName, dateExp, rowNumber);
        resolvedMap.put(columnName, convertAdjustedValueToDateType(tableName, columnName, bindType, adjusted));
    }
    for (Entry<String, Object> entry : resolvedMap.entrySet()) {
        // to keep original map instance
        columnValueMap.put(entry.getKey(), entry.getValue());
    }
}
Also used : DfColumnMeta(org.dbflute.logic.jdbc.metadata.info.DfColumnMeta) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap)

Example 2 with DfColumnMeta

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

the class DfAbsractDataWriter method processXml.

// -----------------------------------------------------
// XML
// ---
protected boolean processXml(String tableName, String columnName, String value, PreparedStatement ps, int bindCount, Map<String, DfColumnMeta> columnInfoMap, int rowNumber) throws SQLException {
    if (value == null || value.trim().length() == 0) {
        // cannot be XML
        return false;
    }
    final DfColumnMeta columnInfo = columnInfoMap.get(columnName);
    if (columnInfo != null) {
        if (getBasicProperties().isDatabasePostgreSQL()) {
            final String dbTypeName = columnInfo.getDbTypeName();
            if (!dbTypeName.startsWith("xml")) {
                return false;
            }
            value = filterXmlValue(value);
            ps.setObject(bindCount, value, Types.OTHER);
            return true;
        }
    }
    // unsupported when meta data is not found
    return false;
}
Also used : DfColumnMeta(org.dbflute.logic.jdbc.metadata.info.DfColumnMeta)

Example 3 with DfColumnMeta

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

the class DfAbsractDataWriter method processNotNullNotString.

// -----------------------------------------------------
// NotNull NotString
// -----------------
protected boolean processNotNullNotString(String dataDirectory, String tableName, String columnName, Object obj, Connection conn, PreparedStatement ps, int bindCount, Map<String, DfColumnMeta> columnInfoMap, int rowNumber) throws SQLException {
    if (!isNotNullNotString(obj)) {
        return false;
    }
    final DfColumnMeta columnInfo = columnInfoMap.get(columnName);
    if (columnInfo != null) {
        final Class<?> columnType = getBindType(tableName, columnInfo);
        if (columnType != null) {
            bindNotNullValueByColumnType(tableName, columnName, conn, ps, bindCount, obj, columnType, rowNumber);
            return true;
        }
    }
    bindNotNullValueByInstance(tableName, columnName, conn, ps, bindCount, obj, rowNumber);
    return true;
}
Also used : DfColumnMeta(org.dbflute.logic.jdbc.metadata.info.DfColumnMeta)

Example 4 with DfColumnMeta

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

the class DfAbsractDataWriter method processArray.

// -----------------------------------------------------
// ARRAY
// -----
protected boolean processArray(String tableName, String columnName, String value, PreparedStatement ps, int bindCount, Map<String, DfColumnMeta> columnInfoMap, int rowNumber) throws SQLException {
    if (value == null || value.trim().length() == 0) {
        // cannot be array
        return false;
    }
    final DfColumnMeta columnInfo = columnInfoMap.get(columnName);
    if (columnInfo != null) {
        if (getBasicProperties().isDatabasePostgreSQL()) {
            // rsMeta#getColumnTypeName() returns value starts with "_" if
            // rsMeta#getColumnType() returns Types.ARRAY in PostgreSQL.
            // e.g. UUID[] -> _uuid
            final int jdbcDefValue = columnInfo.getJdbcDefValue();
            final String dbTypeName = columnInfo.getDbTypeName();
            if (jdbcDefValue != Types.ARRAY || !dbTypeName.startsWith("_")) {
                return false;
            }
            value = filterArrayValue(value);
            ps.setObject(bindCount, value, Types.OTHER);
            return true;
        }
    }
    // unsupported when meta data is not found
    return false;
}
Also used : DfColumnMeta(org.dbflute.logic.jdbc.metadata.info.DfColumnMeta)

Example 5 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