Search in sources :

Example 16 with ValueType

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

the class TnValueTypesTest method test_getValueType_byInstance_enum_priority_plain.

public void test_getValueType_byInstance_enum_priority_plain() throws Exception {
    // ## Arrange ##
    Class<?> keyType = TestPlainStatus.class;
    MockValueType mockValueType = new MockValueType();
    // ## Act ##
    TnValueTypes.registerBasicValueType(_currentDBDef, keyType, mockValueType);
    ValueType valueType = TnValueTypes.getValueType(TestPlainStatus.FML);
    // ## 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 17 with ValueType

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

the class TnRelationRowCache method setupKeyElement.

protected Object setupKeyElement(ResultSet rs, TnRelationPropertyType rpt, Map<String, String> selectColumnMap, Map<String, Map<String, Integer>> selectIndexMap, String columnKeyName, TnPropertyType pt, String relationNoSuffix) throws SQLException {
    if (isOutOfRelationSelectIndex(relationNoSuffix, columnKeyName, selectIndexMap)) {
        // basically unreachable, same reason with next if statement, check just in case
        return null;
    }
    if (!selectColumnMap.containsKey(columnKeyName)) {
        // if the relation's select clause is specified
        return null;
    }
    final ValueType valueType = pt.getValueType();
    final Object value;
    if (selectIndexMap != null) {
        value = ResourceContext.getRelationValue(rs, relationNoSuffix, columnKeyName, valueType, selectIndexMap);
    } else {
        value = valueType.getValue(rs, columnKeyName);
    }
    // (treated as no relation data)
    return value;
}
Also used : ValueType(org.dbflute.jdbc.ValueType)

Example 18 with ValueType

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

the class TnAbstractEntityHandler method setupUpdateBindVariables.

protected void setupUpdateBindVariables(Object bean) {
    final List<Object> varList = new ArrayList<Object>();
    final List<ValueType> varValueTypeList = new ArrayList<ValueType>();
    // might be null
    final Set<String> uniqueDrivenPropSet = extractUniqueDrivenPropSet(bean);
    final TnBeanMetaData bmd = getBeanMetaData();
    final String timestampPropertyName = bmd.getTimestampPropertyName();
    final String versionNoPropertyName = bmd.getVersionNoPropertyName();
    for (int i = 0; i < _boundPropTypes.length; ++i) {
        final TnPropertyType pt = _boundPropTypes[i];
        final String propertyName = pt.getPropertyName();
        if (uniqueDrivenPropSet != null && uniqueDrivenPropSet.contains(propertyName)) {
            continue;
        }
        if (propertyName.equalsIgnoreCase(timestampPropertyName)) {
            final Timestamp timestamp = ResourceContext.getAccessTimestamp();
            addNewTimestamp(timestamp);
            varList.add(timestamp);
        } else if (propertyName.equalsIgnoreCase(versionNoPropertyName)) {
            if (!_versionNoAutoIncrementOnMemory) {
                // because of 'VERSION_NO = VERSION_NO + 1'
                continue;
            }
            // already null-checked
            final Object value = pt.getPropertyDesc().getValue(bean);
            final long longValue = DfTypeUtil.toPrimitiveLong(value) + 1L;
            final Long versionNo = Long.valueOf(longValue);
            addNewVersionNo(versionNo);
            varList.add(versionNo);
        } else if (_updateOption != null && _updateOption.hasStatement(pt.getColumnDbName())) {
            // because of 'FOO_COUNT = FOO_COUNT + 1'
            continue;
        } else {
            varList.add(pt.getPropertyDesc().getValue(bean));
        }
        varValueTypeList.add(pt.getValueType());
    }
    doSetupUpdateWhereBindVariables(varList, varValueTypeList, bean, uniqueDrivenPropSet);
    _bindVariables = varList.toArray();
    _bindVariableValueTypes = (ValueType[]) varValueTypeList.toArray(new ValueType[varValueTypeList.size()]);
}
Also used : ValueType(org.dbflute.jdbc.ValueType) TnBeanMetaData(org.dbflute.s2dao.metadata.TnBeanMetaData) ArrayList(java.util.ArrayList) Timestamp(java.sql.Timestamp) TnPropertyType(org.dbflute.s2dao.metadata.TnPropertyType)

Example 19 with ValueType

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

the class TnAbstractEntityHandler method setupInsertBindVariables.

protected void setupInsertBindVariables(Object bean) {
    final List<Object> varList = new ArrayList<Object>();
    final List<ValueType> varValueTypeList = new ArrayList<ValueType>();
    final TnBeanMetaData bmd = getBeanMetaData();
    final String timestampPropertyName = bmd.getTimestampPropertyName();
    final String versionNoPropertyName = bmd.getVersionNoPropertyName();
    for (int i = 0; i < _boundPropTypes.length; ++i) {
        final TnPropertyType pt = _boundPropTypes[i];
        if (pt.getPropertyName().equalsIgnoreCase(timestampPropertyName)) {
            final Timestamp timestamp = ResourceContext.getAccessTimestamp();
            addNewTimestamp(timestamp);
            varList.add(timestamp);
        } else if (pt.getPropertyName().equalsIgnoreCase(versionNoPropertyName)) {
            final Long firstNo = InsertOption.VERSION_NO_FIRST_VALUE;
            addNewVersionNo(firstNo);
            varList.add(firstNo);
        } else {
            varList.add(pt.getPropertyDesc().getValue(bean));
        }
        varValueTypeList.add(pt.getValueType());
    }
    _bindVariables = varList.toArray();
    _bindVariableValueTypes = (ValueType[]) varValueTypeList.toArray(new ValueType[varValueTypeList.size()]);
}
Also used : ValueType(org.dbflute.jdbc.ValueType) TnBeanMetaData(org.dbflute.s2dao.metadata.TnBeanMetaData) ArrayList(java.util.ArrayList) Timestamp(java.sql.Timestamp) TnPropertyType(org.dbflute.s2dao.metadata.TnPropertyType)

Example 20 with ValueType

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

the class TnProcedureHandler method bindArgs.

protected void bindArgs(Connection conn, CallableStatement cs, Object dto) throws SQLException {
    if (dto == null) {
        return;
    }
    int i = 0;
    for (TnProcedureParameterType ppt : _procedureMetaData.getBindParameterTypeList()) {
        final ValueType valueType = ppt.getValueType();
        final int bindIndex = (i + 1);
        // if INOUT parameter, both are true
        if (ppt.isOutType()) {
            valueType.registerOutParameter(conn, cs, bindIndex);
        }
        if (ppt.isInType()) {
            // bind as PreparedStatement
            // because CallableStatement's setter might be unsupported
            // (for example, PostgreSQL JDBC Driver for JDBC 3.0)
            final Object value = ppt.getValue(dto);
            valueType.bindValue(conn, cs, bindIndex, value);
        }
        // either must be true
        ++i;
    }
}
Also used : ValueType(org.dbflute.jdbc.ValueType) TnProcedureParameterType(org.dbflute.s2dao.metadata.TnProcedureParameterType)

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