Search in sources :

Example 1 with DerivedMappable

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);
    }
}
Also used : DerivedMappable(org.dbflute.dbmeta.accessory.DerivedMappable) ValueType(org.dbflute.jdbc.ValueType) DerivedTypeHandler(org.dbflute.dbmeta.accessory.DerivedTypeHandler) SqlClause(org.dbflute.cbean.sqlclause.SqlClause) HpDerivingSubQueryInfo(org.dbflute.cbean.chelper.HpDerivingSubQueryInfo) ConditionBean(org.dbflute.cbean.ConditionBean)

Aggregations

ConditionBean (org.dbflute.cbean.ConditionBean)1 HpDerivingSubQueryInfo (org.dbflute.cbean.chelper.HpDerivingSubQueryInfo)1 SqlClause (org.dbflute.cbean.sqlclause.SqlClause)1 DerivedMappable (org.dbflute.dbmeta.accessory.DerivedMappable)1 DerivedTypeHandler (org.dbflute.dbmeta.accessory.DerivedTypeHandler)1 ValueType (org.dbflute.jdbc.ValueType)1