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);
}
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;
}
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()]);
}
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()]);
}
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;
}
}
Aggregations