Search in sources :

Example 56 with DfColumnMeta

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

the class DfColumnValueConverter method processTimestamp.

protected String processTimestamp(String tableName, String columnName, Map<String, DfColumnMeta> columnMetaMap, String filteredValue, String before, String after) {
    if (!"$$Timestamp$$".equalsIgnoreCase(before)) {
        // no converted
        return null;
    }
    final DfColumnMeta columnMeta = columnMetaMap.get(columnName);
    final Class<?> boundType = _bindTypeProvider.provide(tableName, columnMeta);
    if (!Timestamp.class.isAssignableFrom(boundType)) {
        // no converted
        return null;
    }
    // process target here
    if (after.equalsIgnoreCase("$$ZeroPrefixMillis$$")) {
        // DBFlute default
        if (filteredValue != null && filteredValue.contains(".")) {
            final String front = Srl.substringLastFront(filteredValue, ".");
            final String millis = Srl.substringLastRear(filteredValue, ".");
            if (millis.length() == 1) {
                filteredValue = front + ".00" + millis;
            } else if (millis.length() == 2) {
                filteredValue = front + ".0" + millis;
            }
            // processed
            return filteredValue;
        }
    } else if (after.equalsIgnoreCase("$$ZeroSuffixMillis$$")) {
        if (filteredValue != null && filteredValue.contains(".")) {
            final String millis = Srl.substringLastRear(filteredValue, ".");
            if (millis.length() == 1) {
                filteredValue = filteredValue + "00";
            } else if (millis.length() == 2) {
                filteredValue = filteredValue + "0";
            }
            // processed
            return filteredValue;
        }
    }
    // no converted
    return null;
}
Also used : DfColumnMeta(org.dbflute.logic.jdbc.metadata.info.DfColumnMeta) Timestamp(java.sql.Timestamp)

Example 57 with DfColumnMeta

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

the class DfColumnValueConverter method findTypedColumnConvertMap.

protected Map<String, String> findTypedColumnConvertMap(String columnName, Map<String, DfColumnMeta> columnMetaMap) {
    final DfColumnMeta meta = columnMetaMap.get(columnName);
    if (meta == null) {
        // no way, just in case
        throw new IllegalStateException("Not found the column meta: " + columnName);
    }
    final String jdbcType = TypeMap.findJdbcTypeByJdbcDefValue(meta.getJdbcDefValue());
    if (jdbcType == null) {
        // as not found
        return Collections.emptyMap();
    }
    if (_typedColumnConvertMap != null) {
        final Map<String, String> existingMap = _typedColumnConvertMap.get(jdbcType);
        if (existingMap != null) {
            return existingMap;
        }
    } else {
        _typedColumnConvertMap = StringKeyMap.createAsCaseInsensitive();
    }
    // e.g. $$type(VARCHAR)$$
    final String typedKey = "$$type(" + jdbcType + ")$$";
    final Map<String, String> valueMap = _convertValueMap.getOrDefault(typedKey, Collections.emptyMap());
    _typedColumnConvertMap.put(jdbcType, valueMap);
    return _typedColumnConvertMap.get(jdbcType);
}
Also used : DfColumnMeta(org.dbflute.logic.jdbc.metadata.info.DfColumnMeta)

Example 58 with DfColumnMeta

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

the class DfAbsractDataWriter method getColumnMetaMap.

// ===================================================================================
// Column Meta
// ===========
protected Map<String, DfColumnMeta> getColumnMetaMap(String tableDbName) {
    if (_columnInfoCacheMap.containsKey(tableDbName)) {
        return _columnInfoCacheMap.get(tableDbName);
    }
    // because the name might be user favorite case name
    prepareTableCaseTranslationIfNeeds();
    final Map<String, DfColumnMeta> columnMetaMap = StringKeyMap.createAsFlexible();
    Connection conn = null;
    try {
        conn = _dataSource.getConnection();
        final DatabaseMetaData metaData = conn.getMetaData();
        final List<DfColumnMeta> columnList = _columnHandler.getColumnList(metaData, _unifiedSchema, tableDbName);
        for (DfColumnMeta columnInfo : columnList) {
            columnMetaMap.put(columnInfo.getColumnName(), columnInfo);
        }
        _columnInfoCacheMap.put(tableDbName, columnMetaMap);
        return columnMetaMap;
    } catch (SQLException e) {
        String msg = "Failed to get column meta informations: table=" + tableDbName;
        throw new IllegalStateException(msg, e);
    } finally {
        if (conn != null) {
            try {
                conn.close();
            } catch (SQLException ignored) {
            }
        }
    }
}
Also used : DfColumnMeta(org.dbflute.logic.jdbc.metadata.info.DfColumnMeta) SQLException(java.sql.SQLException) Connection(java.sql.Connection) DatabaseMetaData(java.sql.DatabaseMetaData)

Example 59 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 60 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)

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