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 sql The SQL string. (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(String sql, Map<String, ValueType> columnValueTypeMap, DfJFadStringConverter converter, int limit) {
// [ATTENTION]: no use bind variables
final List<Map<String, String>> resultList = new ArrayList<Map<String, String>>();
Connection conn = null;
Statement st = null;
ResultSet rs = null;
try {
conn = getConnection();
beginTransactionIfNeeds(conn);
st = conn.createStatement();
rs = st.executeQuery(sql);
final DfJFadResultSetWrapper wrapper = new DfJFadResultSetWrapper(rs, columnValueTypeMap, converter);
int count = 0;
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(sql, 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 DfLReverseDataExtractor method createColumnValueTypeMap.
// ===================================================================================
// JDBC Handling
// =============
protected Map<String, ValueType> createColumnValueTypeMap(List<Column> columnList) {
final Map<String, ValueType> valueTypeMap = new LinkedHashMap<String, ValueType>();
for (Column column : columnList) {
final String columnName = column.getName();
// create value type for the column
final ValueType valueType;
if (column.isJavaNativeStringObject()) {
if (column.isDbTypeStringClob()) {
valueType = new StringClobType();
} else {
valueType = new StringType();
}
} else if (column.isJavaNativeDateObject()) {
// date types should be treated correctly
if (column.isJdbcTypeTime()) {
valueType = new TimeType();
} else if (column.isJdbcTypeTimestamp()) {
valueType = new TimestampType();
} else if (column.isJdbcTypeDate()) {
if (column.isDbTypeOracleDate()) {
valueType = new UtilDateAsTimestampType();
} else {
valueType = new UtilDateAsSqlDateType();
}
} else {
// no way
valueType = new TimestampType();
}
} else if (column.isJavaNativeBinaryObject()) {
// unsupported BLOG as loda data
valueType = new NullBytesType();
} else {
// other types are treated as string
// because ReplaceSchema can accept them
valueType = new StringType();
}
valueTypeMap.put(columnName, valueType);
}
return valueTypeMap;
}
use of org.dbflute.jdbc.ValueType in project dbflute-core by dbflute.
the class DfLReverseDataExtractor method processNormalData.
// ===================================================================================
// Normal Data
// ===========
protected DfLReverseDataResult processNormalData(Table table, String sql) {
final DfJdbcFacade facade = new DfJdbcFacade(_dataSource);
final Map<String, ValueType> valueTypeMap = createColumnValueTypeMap(table.getColumnList());
final DfJFadStringConverter converter = createStringConverter();
final Integer limit = _extractingLimit;
final List<Map<String, String>> resultList = facade.selectStringList(sql, valueTypeMap, converter, limit);
return new DfLReverseDataResult(resultList);
}
use of org.dbflute.jdbc.ValueType in project dbflute-core by dbflute.
the class DfLReverseDataExtractor method processLargeData.
// ===================================================================================
// Large Data
// ==========
protected DfLReverseDataResult processLargeData(Table table, final String sql) {
final DfJdbcFacade facade = new DfJdbcFacade(_dataSource);
final Map<String, ValueType> valueTypeMap = createColumnValueTypeMap(table.getColumnList());
final DfJFadStringConverter converter = createStringConverter();
final DfJFadCursorCallback callback = facade.selectCursor(sql, valueTypeMap, converter);
return new DfLReverseDataResult(callback);
}
use of org.dbflute.jdbc.ValueType in project dbflute-core by dbflute.
the class TnRowCreatorExtension method processDerivedMap.
protected void processDerivedMap(ResultSet rs, Map<String, Map<String, Integer>> selectIndexMap, Map<String, TnPropertyMapping> propertyCache, Object row) throws SQLException {
final ConditionBean cb = ConditionBeanContext.getConditionBeanOnThread();
final SqlClause sqlClause = cb.getSqlClause();
if (!sqlClause.hasSpecifiedDerivingSubQuery()) {
return;
}
final DerivedMappable mappable = (DerivedMappable) row;
final List<String> derivingAliasList = sqlClause.getSpecifiedDerivingAliasList();
DerivedTypeHandler typeHandler = null;
for (String derivingAlias : derivingAliasList) {
// propertyCache has alias name when derived-referrer as case-insensitive
if (propertyCache.containsKey(derivingAlias)) {
// already handled
continue;
}
if (!derivingAlias.startsWith(DERIVED_MAPPABLE_ALIAS_PREFIX)) {
// might be exception but no need to be strict here
continue;
}
if (typeHandler == null) {
// basically fixed instance returned
typeHandler = cb.xgetDerivedTypeHandler();
if (typeHandler == null) {
// no way, just in case
String msg = "Not found the type handler from condition-bean: " + cb.asTableDbName();
throw new IllegalStateException(msg);
}
}
final HpDerivingSubQueryInfo derivingInfo = sqlClause.getSpecifiedDerivingInfo(derivingAlias);
final ValueType valueType = TnValueTypes.getValueType(typeHandler.findMappingType(derivingInfo));
final String onQueryAlias = Srl.substringFirstRear(derivingAlias, DERIVED_MAPPABLE_ALIAS_PREFIX);
Object selectedValue = getValue(rs, onQueryAlias, valueType, selectIndexMap);
selectedValue = typeHandler.convertToMapValue(derivingInfo, selectedValue);
mappable.registerDerivedValue(derivingAlias, selectedValue);
}
}
Aggregations