use of org.dbflute.cbean.sqlclause.SqlClause 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);
}
use of org.dbflute.cbean.sqlclause.SqlClause in project dbflute-core by dbflute.
the class AbstractConditionQuery method registerInScopeRelation.
// *unsupported ExistsReferrer as in-line because it's (or was) so dangerous
// ===================================================================================
// InScopeRelation
// ===============
// {Modified at DBFlute-0.7.5}
protected void registerInScopeRelation(final ConditionQuery subQuery, String columnDbName, String relatedColumnDbName, String propertyName, String relationPropertyName, boolean notInScope) {
assertSubQueryNotNull("InScopeRelation", columnDbName, 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 boolean suppressLocalAliasName = isInScopeRelationSuppressLocalAliasName();
final InScopeRelation inScopeRelation = new InScopeRelation(subQueryPath, localRealNameProvider, subQuerySqlNameProvider, subQueryLevel, subQueryClause, subQueryIdentity, subQueryDBMeta, cipherManager, suppressLocalAliasName);
final String correlatedFixedCondition = xbuildForeignCorrelatedFixedCondition(subQuery, relationPropertyName);
final String inScopeOption = notInScope ? "not" : null;
final String clause = inScopeRelation.buildInScopeRelation(columnDbName, relatedColumnDbName, correlatedFixedCondition, inScopeOption);
registerWhereClause(clause);
}
use of org.dbflute.cbean.sqlclause.SqlClause in project dbflute-core by dbflute.
the class HpAbstractSpecification method doColumn.
protected SpecifiedColumn doColumn(String columnName) {
// for extended class
checkSpecifiedThemeColumnStatus(columnName);
if (isSpecifiedColumn(columnName)) {
// returns the same instance as the specified before
return getSpecifiedColumn(columnName);
}
assertColumn(columnName);
callQuery();
if (isRequiredColumnSpecificationEnabled()) {
_alreadySpecifiedRequiredColumn = true;
doSpecifyRequiredColumn();
}
final SqlClause sqlClause = _baseCB.getSqlClause();
final String tableAliasName;
if (_query.isBaseQuery()) {
tableAliasName = sqlClause.getBasePointAliasName();
} else {
final String relationPath = _query.xgetRelationPath();
final int nestLevel = _query.xgetNestLevel();
tableAliasName = sqlClause.resolveJoinAliasName(relationPath, nestLevel);
keepDreamCruiseJourneyLogBookIfNeeds(relationPath, tableAliasName);
reflectDreamCruiseWhereUsedToJoin(relationPath, tableAliasName);
}
final SpecifiedColumn specifiedColumn = createSpecifiedColumn(columnName, tableAliasName);
sqlClause.specifySelectColumn(specifiedColumn);
saveSpecifiedColumn(columnName, specifiedColumn);
return specifiedColumn;
}
use of org.dbflute.cbean.sqlclause.SqlClause in project dbflute-core by dbflute.
the class HpSLSFunction method setupTargetColumnInfo.
protected void setupTargetColumnInfo(ScalarSelectOption option) {
if (option == null) {
return;
}
final SqlClause sqlClause = _conditionBean.getSqlClause();
ColumnInfo columnInfo = sqlClause.getSpecifiedColumnInfoAsOne();
if (columnInfo != null) {
columnInfo = sqlClause.getSpecifiedDerivingColumnInfoAsOne();
}
option.xsetTargetColumnInfo(columnInfo);
}
use of org.dbflute.cbean.sqlclause.SqlClause in project dbflute-core by dbflute.
the class HpSLSFunction method assertScalarSelectRequiredSpecifyColumn.
protected void assertScalarSelectRequiredSpecifyColumn() {
final SqlClause sqlClause = _conditionBean.getSqlClause();
final String columnName = sqlClause.getSpecifiedColumnDbNameAsOne();
final String subQuery = sqlClause.getSpecifiedDerivingSubQueryAsOne();
// should be specified is an only one object (column or sub-query)
if ((columnName != null && subQuery != null) || (columnName == null && subQuery == null)) {
throwScalarSelectInvalidColumnSpecificationException();
}
}
Aggregations