use of org.dbflute.cbean.chelper.HpDerivingSubQueryInfo in project dbflute-core by dbflute.
the class AbstractSqlClause method registerSpecifiedDerivedOrderBy.
public void registerSpecifiedDerivedOrderBy(String orderByProperty, boolean ascOrDesc) {
final HpDerivingSubQueryInfo specifiedDerivingInfo = getSpecifiedDerivingInfo(orderByProperty);
if (specifiedDerivingInfo == null) {
// basically no way because of already checked
String msg = "The deriving column was not found by the property: " + orderByProperty;
throw new IllegalStateException(msg);
}
final ColumnInfo columnInfo = specifiedDerivingInfo.extractDerivingColumnInfo();
doRegisterOrderBy(orderByProperty, ascOrDesc, columnInfo, true);
}
use of org.dbflute.cbean.chelper.HpDerivingSubQueryInfo 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);
}
}
use of org.dbflute.cbean.chelper.HpDerivingSubQueryInfo in project dbflute-core by dbflute.
the class AbstractConditionQuery method doRegisterSpecifyDerivedReferrer.
protected void doRegisterSpecifyDerivedReferrer(String function, final ConditionQuery subQuery, String columnDbName, String relatedColumnDbName, String propertyName, String referrerPropertyName, String aliasName, DerivedReferrerOption option) {
assertFunctionNotNull("SpecifyDerivedReferrer", columnDbName, function);
assertSubQueryNotNull("SpecifyDerivedReferrer", columnDbName, subQuery);
option.xacceptBaseCB(xgetBaseCB());
if (isDerivedReferrerSelectAllPossible(subQuery, option)) {
createCBExThrower().throwSpecifyDerivedReferrerSelectAllPossibleException(function, subQuery, aliasName);
}
final SubQueryPath subQueryPath = new SubQueryPath(xgetLocation(propertyName));
final GeneralColumnRealNameProvider localRealNameProvider = new GeneralColumnRealNameProvider();
final int subQueryLevel = subQuery.xgetSqlClause().getSubQueryLevel();
final SqlClause subQueryClause = subQuery.xgetSqlClause();
final String subQueryIdentity = propertyName + "[" + subQueryLevel + "]";
final ColumnSqlNameProvider subQuerySqlNameProvider = dbName -> subQuery.toColumnSqlName(dbName);
final DBMeta subQueryDBMeta = findDBMeta(subQuery.asTableDbName());
final GearedCipherManager cipherManager = xgetSqlClause().getGearedCipherManager();
final String mainSubQueryIdentity = propertyName + "[" + subQueryLevel + ":subquerymain]";
final SpecifyDerivedReferrer derivedReferrer = option.createSpecifyDerivedReferrer(subQueryPath, localRealNameProvider, subQuerySqlNameProvider, subQueryLevel, subQueryClause, subQueryIdentity, subQueryDBMeta, cipherManager, mainSubQueryIdentity, aliasName);
xregisterParameterOption(option);
final String correlatedFixedCondition = xbuildReferrerCorrelatedFixedCondition(subQuery, referrerPropertyName);
final String clause = derivedReferrer.buildDerivedReferrer(function, columnDbName, relatedColumnDbName, correlatedFixedCondition, option);
final HpDerivingSubQueryInfo subQueryInfo = xcreateDerivingSubQueryInfo(function, aliasName, clause, derivedReferrer);
xgetSqlClause().specifyDerivingSubQuery(subQueryInfo);
}
Aggregations