use of org.dbflute.jdbc.ValueType in project dbflute-core by dbflute.
the class TnPlainValueTypes method getValueType.
// -----------------------------------------------------
// byType
// ------
/**
* Get the value type by class type. <br>
* The basic objects are prior to the basic interfaces basically,
* but only when the ENUM is assignable from the class type, interfaces are prior.
* Because frequently the ENUM has application own interfaces.
* Actually Classification of DBFlute matches the pattern.
* @param type The type of class. (NullAllowed: if null, returns object type)
* @return The value type. (NotNull: if not found, returns object type)
*/
public ValueType getValueType(Class<?> type) {
if (type == null) {
return DEFAULT_OBJECT;
}
final boolean interfaceFirst = Enum.class.isAssignableFrom(type);
ValueType valueType = null;
if (interfaceFirst) {
valueType = getBasicInterfaceValueType(type);
if (valueType == null) {
valueType = getBasicObjectValueType(type);
}
} else {
valueType = getBasicObjectValueType(type);
if (valueType == null) {
valueType = getBasicInterfaceValueType(type);
}
}
return valueType != null ? valueType : DEFAULT_OBJECT;
}
use of org.dbflute.jdbc.ValueType in project dbflute-core by dbflute.
the class TnAbstractBasicSqlHandler method bindArgs.
// ===================================================================================
// Common Logic
// ============
// -----------------------------------------------------
// Arguments Handling
// ------------------
/**
* @param conn The connection for the database. (NotNull)
* @param ps The prepared statement for the SQL. (NotNull)
* @param args The arguments for binding. (NullAllowed)
* @param valueTypes The types of binding value. (NotNull)
*/
protected void bindArgs(Connection conn, PreparedStatement ps, Object[] args, ValueType[] valueTypes) {
if (args == null) {
return;
}
Object current = null;
try {
for (int i = 0; i < args.length; ++i) {
final ValueType valueType = valueTypes[i];
current = args[i];
valueType.bindValue(conn, ps, i + 1, current);
}
} catch (SQLException e) {
final SQLExceptionResource resource = createSQLExceptionResource();
resource.setNotice("Failed to bind the value.");
if (current != null) {
resource.addResource("Bound Value", current);
}
handleSQLException(e, resource);
}
}
use of org.dbflute.jdbc.ValueType in project dbflute-core by dbflute.
the class TnAbstractBasicSqlHandler method bindArgs.
/**
* @param conn The connection for the database. (NotNull)
* @param ps The prepared statement for the SQL. (NotNull)
* @param args The arguments for binding. (NullAllowed)
* @param argTypes The types of arguments. (NullAllowed: if args is null, this is also null)
* @param beginIndex The index for beginning of binding.
*/
protected void bindArgs(Connection conn, PreparedStatement ps, Object[] args, Class<?>[] argTypes, int beginIndex) {
if (args == null) {
return;
}
Object current = null;
try {
for (int i = beginIndex; i < args.length; ++i) {
current = args[i];
final ValueType valueType = findValueType(argTypes[i], current);
valueType.bindValue(conn, ps, i + 1, current);
}
} catch (SQLException e) {
final SQLExceptionResource resource = createSQLExceptionResource();
resource.setNotice("Failed to bind the value.");
if (current != null) {
resource.addResource("Bound Value", current);
}
handleSQLException(e, resource);
}
}
use of org.dbflute.jdbc.ValueType in project dbflute-core by dbflute.
the class TnAbstractMapResultSetHandler method createRow.
protected Map<String, Object> createRow(ResultSet rs, Map<String, ValueType> propertyTypeMap) throws SQLException {
final Map<String, Object> row = newRowMap();
final Set<Entry<String, ValueType>> entrySet = propertyTypeMap.entrySet();
int index = 0;
for (Entry<String, ValueType> entry : entrySet) {
final String propertyName = entry.getKey();
final ValueType valueType = entry.getValue();
final Object value = valueType.getValue(rs, index + 1);
row.put(propertyName, value);
++index;
}
return row;
}
use of org.dbflute.jdbc.ValueType in project dbflute-core by dbflute.
the class TnAbstractMapResultSetHandler method createPropertyTypeMap.
protected Map<String, ValueType> createPropertyTypeMap(ResultSetMetaData rsmd) throws SQLException {
final int count = rsmd.getColumnCount();
final Map<String, ValueType> propertyTypeMap = newPropertyTypeMap();
for (int i = 0; i < count; ++i) {
final String propertyName = rsmd.getColumnLabel(i + 1);
// because it can only use by-JDBC-type value type here
final int columnType = rsmd.getColumnType(i + 1);
final ValueType valueType = getValueType(columnType);
propertyTypeMap.put(propertyName, valueType);
}
return propertyTypeMap;
}
Aggregations