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