use of org.dbflute.dbmeta.accessory.DerivedMappable 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