Search in sources :

Example 21 with ValueType

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

the class TnPlainValueTypes method getValueType.

// -----------------------------------------------------
// byJdbcDefType
// -------------
/**
 * @param jdbcDefType The definition type of JDBC.
 * @return The value type. (NotNull)
 */
public ValueType getValueType(int jdbcDefType) {
    // for no entity and so on
    final Class<?> type = getType(jdbcDefType);
    if (type.equals(Object.class)) {
        // uses dynamic object
        ValueType valueType = _dynamicObjectValueTypeMap.get(jdbcDefType);
        if (valueType != null) {
            return valueType;
        }
        synchronized (this) {
            // lock this instance because also used in remove(), ...
            valueType = _dynamicObjectValueTypeMap.get(jdbcDefType);
            if (valueType != null) {
                // or reading might failed by same-time writing
                return valueType;
            }
            final ObjectType objectType = new ObjectType(jdbcDefType);
            _dynamicObjectValueTypeMap.put(jdbcDefType, objectType);
            return objectType;
        }
    } else {
        return getValueType(type);
    }
}
Also used : ObjectType(org.dbflute.s2dao.valuetype.basic.ObjectType) ValueType(org.dbflute.jdbc.ValueType)

Example 22 with ValueType

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

the class TnValueTypesTest method test_getValueType_byClassType_enum_priority_plain.

public void test_getValueType_byClassType_enum_priority_plain() throws Exception {
    // ## Arrange ##
    Class<?> keyType = TestPlainStatus.class;
    MockValueType mockValueType = new MockValueType();
    // ## Act ##
    TnValueTypes.registerBasicValueType(_currentDBDef, keyType, mockValueType);
    ValueType valueType = TnValueTypes.getValueType(keyType);
    // ## Assert ##
    assertNotSame(TnValueTypes.CLASSIFICATION, valueType);
    assertEquals(mockValueType, valueType);
}
Also used : MockValueType(org.dbflute.mock.MockValueType) ValueType(org.dbflute.jdbc.ValueType) MockValueType(org.dbflute.mock.MockValueType)

Example 23 with ValueType

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

the class DfJFadResultSetWrapper method getString.

public String getString(String columnName) throws SQLException {
    final Object value;
    final ValueType valueType = _columnValueTypeMap.get(columnName);
    if (valueType != null) {
        value = valueType.getValue(_rs, columnName);
    } else {
        value = _rs.getString(columnName);
    }
    if (value == null) {
        return null;
    }
    if (_stringConverter != null) {
        return _stringConverter.convert(value);
    } else {
        return value.toString();
    }
}
Also used : ValueType(org.dbflute.jdbc.ValueType)

Example 24 with ValueType

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

the class DfJdbcFacade method selectStringList.

/**
 * Select the list for records as string value using value types.
 * @param trySqlList The try SQL strings. (NotNull)
 * @param columnValueTypeMap The map of selected columns to value types. (NotNull, ValueTypeNullAllowed)
 * @param converter The converter to convert to string value. (NullAllowed: means no conversion)
 * @param limit The limit size for fetching. (MinusAllowed: means no limit)
 * @return The list for result. (NotNull)
 */
public List<Map<String, String>> selectStringList(List<String> trySqlList, Map<String, ValueType> columnValueTypeMap, DfJFadStringConverter converter, int limit) {
    if (trySqlList == null || trySqlList.isEmpty()) {
        throw new IllegalArgumentException("The argument 'trySqlList' should not be null and empty: " + trySqlList);
    }
    // [ATTENTION]: no use bind variables because of framework internal use
    final List<Map<String, String>> resultList = new ArrayList<Map<String, String>>();
    Connection conn = null;
    Statement st = null;
    ResultSet rs = null;
    String currentSql = null;
    try {
        conn = getConnection();
        beginTransactionIfNeeds(conn);
        st = conn.createStatement();
        final DfCurrentSqlResult result = retryableExecuteQuery(trySqlList, st);
        // not null, keep for later SQLException
        currentSql = result.getCurrentSql();
        // not null
        rs = result.getResultSet();
        int count = 0;
        final DfJFadResultSetWrapper wrapper = new DfJFadResultSetWrapper(rs, columnValueTypeMap, converter);
        while (wrapper.next()) {
            if (isOverLimit(limit, count)) {
                break;
            }
            final Map<String, String> recordMap = StringKeyMap.createAsFlexibleOrdered();
            final Set<Entry<String, ValueType>> entrySet = columnValueTypeMap.entrySet();
            for (Entry<String, ValueType> entry : entrySet) {
                final String columnName = entry.getKey();
                final String value = wrapper.getString(columnName);
                recordMap.put(columnName, value);
            }
            resultList.add(recordMap);
            ++count;
        }
        commitTrasactionIfNeeds(conn);
    } catch (SQLException e) {
        handleSQLException(currentSql, e);
        // unreachable
        return null;
    } finally {
        rollbackTransactionIfNeeds(conn);
        closeResultSet(rs);
        closeStatement(st);
        closeConnection(conn);
    }
    return resultList;
}
Also used : ValueType(org.dbflute.jdbc.ValueType) SQLException(java.sql.SQLException) Statement(java.sql.Statement) ArrayList(java.util.ArrayList) Connection(java.sql.Connection) Entry(java.util.Map.Entry) ResultSet(java.sql.ResultSet) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) StringKeyMap(org.dbflute.helper.StringKeyMap)

Example 25 with ValueType

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

the class TnAbstractPropertyTypeFactory method createPropertyType.

protected TnPropertyType createPropertyType(DfPropertyDesc propertyDesc) {
    final ValueType valueType = getValueType(propertyDesc);
    final String columnDbName = getColumnDbName(propertyDesc);
    final ColumnSqlName columnSqlName = getColumnSqlName(columnDbName);
    final ColumnInfo entityColumnInfo = getEntityColumnInfo(columnDbName);
    return new TnPropertyTypeImpl(propertyDesc, valueType, columnDbName, columnSqlName, entityColumnInfo);
}
Also used : ColumnSqlName(org.dbflute.dbmeta.name.ColumnSqlName) ValueType(org.dbflute.jdbc.ValueType) ColumnInfo(org.dbflute.dbmeta.info.ColumnInfo) TnPropertyTypeImpl(org.dbflute.s2dao.metadata.impl.TnPropertyTypeImpl)

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