Search in sources :

Example 6 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 7 with DfColumnMeta

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

the class DfDelimiterDataWriterImpl method createSqlBuilder.

protected DfDelimiterDataWriteSqlBuilder createSqlBuilder(DfDelimiterDataResultInfo resultInfo, String tableDbName, final Map<String, DfColumnMeta> columnMetaMap, List<String> columnNameList, List<String> valueList) {
    final DfDelimiterDataWriteSqlBuilder sqlBuilder = new DfDelimiterDataWriteSqlBuilder();
    sqlBuilder.setTableDbName(tableDbName);
    sqlBuilder.setColumnMetaMap(columnMetaMap);
    sqlBuilder.setColumnNameList(columnNameList);
    sqlBuilder.setValueList(valueList);
    sqlBuilder.setNotFoundColumnMap(resultInfo.getNotFoundColumnMap());
    sqlBuilder.setConvertValueMap(_convertValueMap);
    sqlBuilder.setDefaultValueMap(_defaultValueMap);
    sqlBuilder.setBindTypeProvider(new DfColumnBindTypeProvider() {

        public Class<?> provide(String tableName, DfColumnMeta columnMeta) {
            return getBindType(tableName, columnMeta);
        }
    });
    sqlBuilder.setDefaultValueProp(_defaultValueProp);
    return sqlBuilder;
}
Also used : DfColumnMeta(org.dbflute.logic.jdbc.metadata.info.DfColumnMeta) DfColumnBindTypeProvider(org.dbflute.logic.replaceschema.loaddata.DfColumnBindTypeProvider)

Example 8 with DfColumnMeta

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

the class DfXlsDataHandlerImpl method convertColumnValueIfNeeds.

// ===================================================================================
// Column Value Filter
// ===================
protected void convertColumnValueIfNeeds(String dataDirectory, String tableName, Map<String, Object> columnValueMap, Map<String, DfColumnMeta> columnMetaMap) {
    // handling both convertValueMap and defaultValueMap
    final Map<String, Map<String, String>> convertValueMap = getConvertValueMap(dataDirectory);
    final Map<String, String> defaultValueMap = getDefaultValueMap(dataDirectory);
    // so it does not need to convert here
    if (// no convert
    (convertValueMap == null || convertValueMap.isEmpty()) && (defaultValueMap == null || defaultValueMap.isEmpty())) {
        // and no default
        return;
    }
    final DfColumnValueConverter converter = new DfColumnValueConverter(convertValueMap, defaultValueMap, new DfColumnBindTypeProvider() {

        public Class<?> provide(String tableName, DfColumnMeta columnMeta) {
            return getBindType(tableName, columnMeta);
        }
    });
    converter.convert(tableName, columnValueMap, columnMetaMap);
}
Also used : DfColumnMeta(org.dbflute.logic.jdbc.metadata.info.DfColumnMeta) DfColumnBindTypeProvider(org.dbflute.logic.replaceschema.loaddata.DfColumnBindTypeProvider) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) StringKeyMap(org.dbflute.helper.StringKeyMap)

Example 9 with DfColumnMeta

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

the class DfXlsDataHandlerImpl method filterValidColumn.

protected void filterValidColumn(final DfDataSet dataSet) {
    for (int i = 0; i < dataSet.getTableSize(); i++) {
        final DfDataTable table = dataSet.getTable(i);
        final String tableName = table.getTableDbName();
        final Map<String, DfColumnMeta> metaMetaMap = getColumnMetaMap(tableName);
        for (int j = 0; j < table.getColumnSize(); j++) {
            final DfDataColumn dataColumn = table.getColumn(j);
            if (!metaMetaMap.containsKey(dataColumn.getColumnDbName())) {
                dataColumn.setWritable(false);
            }
        }
    }
}
Also used : DfColumnMeta(org.dbflute.logic.jdbc.metadata.info.DfColumnMeta) DfDataColumn(org.dbflute.helper.dataset.DfDataColumn) DfDataTable(org.dbflute.helper.dataset.DfDataTable)

Example 10 with DfColumnMeta

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

the class DfXlsDataHandlerImplTest method test_processBoolean.

// -----------------------------------------------------
// Boolean
// -------
public void test_processBoolean() throws Exception {
    // ## Arrange ##
    final DfXlsDataHandlerImpl impl = new DfXlsDataHandlerImpl(null, null) {

        @Override
        protected Class<?> getBindType(String tableName, DfColumnMeta columnMetaInfo) {
            return BigDecimal.class;
        }
    };
    Map<String, DfColumnMeta> columnMetaInfoMap = StringKeyMap.createAsCaseInsensitive();
    DfColumnMeta info = new DfColumnMeta();
    info.setColumnName("foo");
    info.setColumnSize(3);
    info.setJdbcDefValue(Types.NUMERIC);
    columnMetaInfoMap.put("foo", info);
    // ## Act ##
    boolean actual = impl.processBoolean("tbl", "foo", "0", null, null, 0, columnMetaInfoMap, 3);
    // ## Assert ##
    log("actual=" + actual);
    assertFalse(actual);
}
Also used : DfColumnMeta(org.dbflute.logic.jdbc.metadata.info.DfColumnMeta) DfXlsDataHandlerImpl(org.dbflute.logic.replaceschema.loaddata.impl.DfXlsDataHandlerImpl) BigDecimal(java.math.BigDecimal)

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