use of org.dbflute.cbean.sqlclause.subquery.QueryDerivedReferrer in project dbflute-core by dbflute.
the class AbstractConditionQuery method doRegisterQueryDerivedReferrer.
protected void doRegisterQueryDerivedReferrer(String function, final ConditionQuery subQuery, String columnDbName, String relatedColumnDbName, String propertyName, String referrerPropertyName, String operand, Object value, String parameterPropertyName, DerivedReferrerOption option) {
assertFunctionNotNull("QueryDerivedReferrer", columnDbName, function);
assertSubQueryNotNull("QueryDerivedReferrer", columnDbName, subQuery);
option.xacceptBaseCB(xgetBaseCB());
if (isDerivedReferrerSelectAllPossible(subQuery, option)) {
createCBExThrower().throwQueryDerivedReferrerSelectAllPossibleException(function, subQuery);
}
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 String parameterPath = xgetLocation(parameterPropertyName);
final QueryDerivedReferrer derivedReferrer = option.createQueryDerivedReferrer(subQueryPath, localRealNameProvider, subQuerySqlNameProvider, subQueryLevel, subQueryClause, subQueryIdentity, subQueryDBMeta, cipherManager, mainSubQueryIdentity, operand, value, parameterPath);
xregisterParameterOption(option);
final String correlatedFixedCondition = xbuildReferrerCorrelatedFixedCondition(subQuery, referrerPropertyName);
final String clause = derivedReferrer.buildDerivedReferrer(function, columnDbName, relatedColumnDbName, correlatedFixedCondition, option);
// /= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
// is null or null-revived conversion (coalesce) -> no way to be inner
//
// for example, the following SQL is no way to be inner
// (suppose if PURCHASE refers WITHDRAWAL)
//
// select mb.MEMBER_ID, mb.MEMBER_NAME
// , mb.MEMBER_STATUS_CODE, wd.MEMBER_ID as WD_MEMBER_ID
// from MEMBER mb
// left outer join MEMBER_WITHDRAWAL wd on mb.MEMBER_ID = wd.MEMBER_ID
// where (select max(pc.PURCHASE_PRICE)
// from PURCHASE pc
// where pc.MEMBER_ID = wd.MEMBER_ID -- may null
// ) is null
// order by mb.MEMBER_ID
//
// and using coalesce means it may select records that have null value
// so using coalesce is no way in spite of operand
// = = = = = = = = = =/
final boolean noWayInner = HpQDRParameter.isOperandIsNull(operand) || option.mayNullRevived();
registerWhereClause(clause, noWayInner);
}
Aggregations