Search in sources :

Example 6 with ValueType

use of org.dbflute.jdbc.ValueType in project dbflute-core by dbflute.

the class TnRelationRowCreatorExtension method registerRelationValue.

protected void registerRelationValue(TnRelationRowCreationResource res, String columnName) throws SQLException {
    final TnPropertyMapping mapping = res.getCurrentPropertyMapping();
    Object value = null;
    if (res.containsRelationKeyColumn(columnName)) {
        // #RELKEY
        // if this column is relation key, it gets the value from relation key values
        // for performance and avoiding twice getting same column value
        value = res.extractRelationKeyValue(columnName);
    } else {
        final ValueType valueType = mapping.getValueType();
        final Map<String, Map<String, Integer>> selectIndexMap = res.getSelectIndexMap();
        final ResultSet rs = res.getResultSet();
        if (selectIndexMap != null) {
            final String relationNoSuffix = res.getRelationNoSuffix();
            value = ResourceContext.getRelationValue(rs, relationNoSuffix, columnName, valueType, selectIndexMap);
        } else {
            value = valueType.getValue(rs, columnName);
        }
    }
    handleRelationValueRegistration(res, mapping, value);
}
Also used : TnPropertyMapping(org.dbflute.s2dao.metadata.TnPropertyMapping) ValueType(org.dbflute.jdbc.ValueType) ResultSet(java.sql.ResultSet) Map(java.util.Map)

Example 7 with ValueType

use of org.dbflute.jdbc.ValueType in project dbflute-core by dbflute.

the class TnProcedureMetaDataFactory method findValueType.

// ===================================================================================
// Value Type
// ==========
protected ValueType findValueType(DfPropertyDesc parameterDesc) {
    final Class<?> pmbType = parameterDesc.getBeanDesc().getBeanClass();
    final String paramName = parameterDesc.getPropertyName();
    final Class<?> paramType = parameterDesc.getPropertyType();
    final Object valueTypeDef = _annotationReader.getValueType(parameterDesc);
    if (valueTypeDef instanceof ValueType) {
        return (ValueType) valueTypeDef;
    } else {
        final String keyName = (valueTypeDef != null ? valueTypeDef.toString() : null);
        final DBDef dbdef = ResourceContext.currentDBDef();
        return _valueTypeProvider.provide(pmbType, paramName, paramType, keyName, dbdef);
    }
}
Also used : ValueType(org.dbflute.jdbc.ValueType) DBDef(org.dbflute.dbway.DBDef)

Example 8 with ValueType

use of org.dbflute.jdbc.ValueType in project dbflute-core by dbflute.

the class DfLReverseDataExtractor method createColumnValueTypeMap.

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 load 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 9 with ValueType

use of org.dbflute.jdbc.ValueType in project dbflute-core by dbflute.

the class DfLReverseDataExtractor method processLargeData.

// ===================================================================================
// Large Data
// ==========
protected DfLReverseDataResult processLargeData(Table table, final List<String> sqlList) {
    final DfJdbcFacade facade = createJdbcFacade();
    final Map<String, ValueType> valueTypeMap = createColumnValueTypeMap(table.getColumnList());
    final DfJFadStringConverter converter = createStringConverter();
    final DfJFadCursorCallback callback = facade.selectCursor(sqlList, valueTypeMap, converter);
    return new DfLReverseDataResult(callback);
}
Also used : DfJFadStringConverter(org.dbflute.helper.jdbc.facade.DfJFadStringConverter) ValueType(org.dbflute.jdbc.ValueType) DfJFadCursorCallback(org.dbflute.helper.jdbc.facade.DfJFadCursorCallback) DfJdbcFacade(org.dbflute.helper.jdbc.facade.DfJdbcFacade)

Example 10 with ValueType

use of org.dbflute.jdbc.ValueType in project dbflute-core by dbflute.

the class TnValueTypesTest method test_getValueType_byJdbcType_dynamicObject_threadSafe_basic.

public void test_getValueType_byJdbcType_dynamicObject_threadSafe_basic() throws Exception {
    // ## Arrange ##
    ExecutionCreator<ValueType> creator = new ExecutionCreator<ValueType>() {

        public Execution<ValueType> create() {
            return new Execution<ValueType>() {

                int _index = 12345678;

                public ValueType execute() {
                    if (Thread.currentThread().getId() % 2 == 0) {
                        ++_index;
                    }
                    final int sqlType = _index;
                    log(sqlType);
                    final ValueType valueType = TnValueTypes.getValueType(sqlType);
                    assertEquals(sqlType, valueType.getSqlType());
                    assertTrue(TnValueTypes.isDynamicObject(valueType));
                    return valueType;
                }
            };
        }
    };
    // ## Act & Assert ##
    fireSameExecution(creator);
}
Also used : ValueType(org.dbflute.jdbc.ValueType) MockValueType(org.dbflute.mock.MockValueType)

Aggregations

ValueType (org.dbflute.jdbc.ValueType)35 MockValueType (org.dbflute.mock.MockValueType)8 LinkedHashMap (java.util.LinkedHashMap)6 ArrayList (java.util.ArrayList)5 Map (java.util.Map)5 ResultSet (java.sql.ResultSet)4 SQLException (java.sql.SQLException)4 DfJFadStringConverter (org.dbflute.helper.jdbc.facade.DfJFadStringConverter)4 DfJdbcFacade (org.dbflute.helper.jdbc.facade.DfJdbcFacade)4 Entry (java.util.Map.Entry)3 TnPropertyType (org.dbflute.s2dao.metadata.TnPropertyType)3 Connection (java.sql.Connection)2 Statement (java.sql.Statement)2 Timestamp (java.sql.Timestamp)2 Column (org.apache.torque.engine.database.model.Column)2 SQLExceptionResource (org.dbflute.bhv.exception.SQLExceptionResource)2 PluginValueTypeNotFoundException (org.dbflute.exception.PluginValueTypeNotFoundException)2 StringKeyMap (org.dbflute.helper.StringKeyMap)2 DfJFadCursorCallback (org.dbflute.helper.jdbc.facade.DfJFadCursorCallback)2 ExceptionMessageBuilder (org.dbflute.helper.message.ExceptionMessageBuilder)2