Search in sources :

Example 16 with DBMeta

use of org.dbflute.dbmeta.DBMeta in project dbflute-core by dbflute.

the class AbstractConditionQuery method doInvokeQuery.

protected void doInvokeQuery(String colName, String ckey, Object value, ConditionOption option) {
    assertStringNotNullAndNotTrimmedEmpty("columnFlexibleName", colName);
    assertStringNotNullAndNotTrimmedEmpty("conditionKeyName", ckey);
    final boolean noArg = Srl.equalsIgnoreCase(ckey, "IsNull", "IsNotNull", "IsNullOrEmpty", "EmptyString");
    if (!noArg && (value == null || "".equals(value))) {
        if (xgetSqlClause().isNullOrEmptyQueryChecked()) {
            // as default
            String msg = "The conditionValue is required but null or empty: column=" + colName + " value=" + value;
            throw new IllegalConditionBeanOperationException(msg);
        } else {
            // e.g. when cb.ignoreNullOrEmptyQuery()
            return;
        }
    }
    final PropertyNameCQContainer container = xhelpExtractingPropertyNameCQContainer(colName);
    final String flexibleName = container.getFlexibleName();
    final ConditionQuery cq = container.getConditionQuery();
    final DBMeta dbmeta = findDBMeta(cq.asTableDbName());
    final ColumnInfo columnInfo;
    try {
        columnInfo = dbmeta.findColumnInfo(flexibleName);
    } catch (RuntimeException e) {
        throwConditionInvokingColumnFindFailureException(colName, ckey, value, option, e);
        // unreachable (to avoid compile error)
        return;
    }
    final String columnCapPropName = initCap(columnInfo.getPropertyName());
    final boolean rangeOf = Srl.equalsIgnoreCase(ckey, "RangeOf");
    final boolean fromTo = Srl.equalsIgnoreCase(ckey, "FromTo", "DateFromTo");
    final boolean inScope = Srl.equalsIgnoreCase(ckey, "InScope");
    if (!noArg) {
        try {
            // convert type
            value = columnInfo.convertToObjectNativeType(value);
        } catch (RuntimeException e) {
            throwConditionInvokingValueConvertFailureException(colName, ckey, value, option, e);
        }
    }
    final String methodName = xbuildQuerySetMethodName(ckey, columnCapPropName);
    final List<Class<?>> typeList = newArrayListSized(4);
    final Class<?> propertyType = columnInfo.getObjectNativeType();
    if (fromTo) {
        if (LocalDate.class.isAssignableFrom(propertyType)) {
            // #date_parade
            typeList.add(propertyType);
            typeList.add(propertyType);
        } else if (LocalDateTime.class.isAssignableFrom(propertyType)) {
            typeList.add(propertyType);
            typeList.add(propertyType);
        } else {
            // fixedly util.Date
            typeList.add(Date.class);
            typeList.add(Date.class);
        }
    } else if (rangeOf) {
        typeList.add(propertyType);
        typeList.add(propertyType);
    } else {
        if (!noArg) {
            final Class<?> instanceType = value.getClass();
            if (inScope && Collection.class.isAssignableFrom(instanceType)) {
                // double check just in case
                // inScope's argument is fixed type
                typeList.add(Collection.class);
            } else {
                typeList.add(instanceType);
            }
        }
    }
    if (option != null) {
        typeList.add(option.getClass());
    }
    final List<Class<?>> filteredTypeList = newArrayListSized(typeList.size());
    for (Class<?> parameterType : typeList) {
        filteredTypeList.add(xfilterInvokeQueryParameterType(colName, ckey, parameterType));
    }
    final Class<?>[] parameterTypes = filteredTypeList.toArray(new Class<?>[filteredTypeList.size()]);
    final Method method = xhelpGettingCQMethod(cq, methodName, parameterTypes);
    if (method == null) {
        throwConditionInvokingSetMethodNotFoundException(colName, ckey, value, option, methodName, parameterTypes);
    }
    try {
        final List<Object> argList = newArrayList();
        if (fromTo || rangeOf) {
            if (!(value instanceof List<?>)) {
                // check type
                throwConditionInvokingDateFromToValueInvalidException(colName, ckey, value, option, methodName, parameterTypes);
            }
            argList.addAll((List<?>) value);
        } else {
            if (!noArg) {
                argList.add(value);
            }
        }
        if (option != null) {
            argList.add(option);
        }
        final List<Object> filteredArgList = newArrayListSized(argList.size());
        for (Object arg : argList) {
            filteredArgList.add(xfilterInvokeQueryParameterValue(colName, ckey, arg));
        }
        xhelpInvokingCQMethod(cq, method, filteredArgList.toArray());
    } catch (ReflectionFailureException e) {
        throwConditionInvokingSetReflectionFailureException(colName, ckey, value, option, methodName, parameterTypes, e);
    }
}
Also used : LocalDateTime(java.time.LocalDateTime) ColumnInfo(org.dbflute.dbmeta.info.ColumnInfo) Method(java.lang.reflect.Method) ReflectionFailureException(org.dbflute.util.DfReflectionUtil.ReflectionFailureException) Date(java.util.Date) LocalDate(java.time.LocalDate) DBMeta(org.dbflute.dbmeta.DBMeta) IllegalConditionBeanOperationException(org.dbflute.exception.IllegalConditionBeanOperationException) Collection(java.util.Collection) List(java.util.List) ArrayList(java.util.ArrayList)

Example 17 with DBMeta

use of org.dbflute.dbmeta.DBMeta 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);
}
Also used : ColumnRealNameProvider(org.dbflute.dbmeta.name.ColumnRealNameProvider) DerivedReferrerOptionFactory(org.dbflute.cbean.coption.DerivedReferrerOptionFactory) UnionClauseProvider(org.dbflute.cbean.sqlclause.union.UnionClauseProvider) SpecifiedColumn(org.dbflute.cbean.dream.SpecifiedColumn) ConditionKeyInScope(org.dbflute.cbean.ckey.ConditionKeyInScope) Date(java.util.Date) ParameterOption(org.dbflute.cbean.coption.ParameterOption) LoggerFactory(org.slf4j.LoggerFactory) OrderByElement(org.dbflute.cbean.sqlclause.orderby.OrderByElement) QueryClause(org.dbflute.cbean.sqlclause.query.QueryClause) ExceptionMessageBuilder(org.dbflute.helper.message.ExceptionMessageBuilder) ColumnSqlNameProvider(org.dbflute.dbmeta.name.ColumnSqlNameProvider) SimpleMapPmb(org.dbflute.twowaysql.pmbean.SimpleMapPmb) ColumnRealName(org.dbflute.dbmeta.name.ColumnRealName) PrimaryInfo(org.dbflute.dbmeta.info.PrimaryInfo) OrScopeQueryAndPartUnsupportedOperationException(org.dbflute.exception.OrScopeQueryAndPartUnsupportedOperationException) Map(java.util.Map) HpInvalidQueryInfo(org.dbflute.cbean.chelper.HpInvalidQueryInfo) DfBeanDescFactory(org.dbflute.helper.beans.factory.DfBeanDescFactory) ManualOrderOption(org.dbflute.cbean.ordering.ManualOrderOption) ConditionOption(org.dbflute.cbean.coption.ConditionOption) FixedConditionLazyChecker(org.dbflute.cbean.sqlclause.join.FixedConditionLazyChecker) Method(java.lang.reflect.Method) RangeOfOption(org.dbflute.cbean.coption.RangeOfOption) DfCollectionUtil(org.dbflute.util.DfCollectionUtil) SubQuery(org.dbflute.cbean.scoping.SubQuery) TimeZone(java.util.TimeZone) IndependentProcessor(org.dbflute.helper.function.IndependentProcessor) Timestamp(java.sql.Timestamp) Collection(java.util.Collection) LikeSearchOption(org.dbflute.cbean.coption.LikeSearchOption) QueryModeProvider(org.dbflute.cbean.cvalue.ConditionValue.QueryModeProvider) FixedConditionResolver(org.dbflute.cbean.sqlclause.join.FixedConditionResolver) ScalarConditionOption(org.dbflute.cbean.coption.ScalarConditionOption) DBMeta(org.dbflute.dbmeta.DBMeta) FunCustodial(org.dbflute.FunCustodial) DfBeanDesc(org.dbflute.helper.beans.DfBeanDesc) Classification(org.dbflute.jdbc.Classification) List(java.util.List) ColumnInfo(org.dbflute.dbmeta.info.ColumnInfo) ExistsReferrer(org.dbflute.cbean.sqlclause.subquery.ExistsReferrer) LocalDate(java.time.LocalDate) Entry(java.util.Map.Entry) SqlClauseMySql(org.dbflute.cbean.sqlclause.SqlClauseMySql) DBMetaProvider(org.dbflute.dbmeta.DBMetaProvider) DBFluteSystem(org.dbflute.system.DBFluteSystem) ColumnFunctionCipher(org.dbflute.cbean.cipher.ColumnFunctionCipher) DateConditionAdjuster(org.dbflute.cbean.garnish.datefitting.DateConditionAdjuster) ConditionKeyPrepareResult(org.dbflute.cbean.ckey.ConditionKeyPrepareResult) ScalarCondition(org.dbflute.cbean.sqlclause.subquery.ScalarCondition) HpFixedConditionQueryResolver(org.dbflute.cbean.chelper.HpFixedConditionQueryResolver) LocalDateTime(java.time.LocalDateTime) IllegalConditionBeanOperationException(org.dbflute.exception.IllegalConditionBeanOperationException) HashMap(java.util.HashMap) ReflectionFailureException(org.dbflute.util.DfReflectionUtil.ReflectionFailureException) DerivedReferrerOption(org.dbflute.cbean.coption.DerivedReferrerOption) ManualOrderOptionCall(org.dbflute.cbean.ordering.ManualOrderOptionCall) GearedCipherManager(org.dbflute.cbean.cipher.GearedCipherManager) ConditionInvokingFailureException(org.dbflute.exception.ConditionInvokingFailureException) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) SqlClauseOracle(org.dbflute.cbean.sqlclause.SqlClauseOracle) HpQDRSetupper(org.dbflute.cbean.chelper.HpQDRSetupper) ExtensionOperand(org.dbflute.dbway.ExtensionOperand) HpQDRParameter(org.dbflute.cbean.chelper.HpQDRParameter) PartitionByProvider(org.dbflute.cbean.sqlclause.subquery.ScalarCondition.PartitionByProvider) DfReflectionUtil(org.dbflute.util.DfReflectionUtil) QueryUsedAliasInfo(org.dbflute.cbean.sqlclause.query.QueryUsedAliasInfo) ShortCharHandlingMode(org.dbflute.jdbc.ShortCharHandlingMode) Srl(org.dbflute.util.Srl) QueryClauseArranger(org.dbflute.cbean.sqlclause.query.QueryClauseArranger) ColumnSqlName(org.dbflute.dbmeta.name.ColumnSqlName) ConditionValue(org.dbflute.cbean.cvalue.ConditionValue) RelationInfo(org.dbflute.dbmeta.info.RelationInfo) ForeignInfo(org.dbflute.dbmeta.info.ForeignInfo) FromToOption(org.dbflute.cbean.coption.FromToOption) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) HpSLCFunction(org.dbflute.cbean.chelper.HpSLCFunction) SpecifyDerivedReferrer(org.dbflute.cbean.sqlclause.subquery.SpecifyDerivedReferrer) WayOfMySQL(org.dbflute.dbway.WayOfMySQL) QueryDerivedReferrer(org.dbflute.cbean.sqlclause.subquery.QueryDerivedReferrer) ConditionKey(org.dbflute.cbean.ckey.ConditionKey) ConditionOptionCall(org.dbflute.cbean.coption.ConditionOptionCall) HpSLCCustomized(org.dbflute.cbean.chelper.HpSLCCustomized) ConditionBeanExceptionThrower(org.dbflute.cbean.exception.ConditionBeanExceptionThrower) HpDerivingSubQueryInfo(org.dbflute.cbean.chelper.HpDerivingSubQueryInfo) SubQueryPath(org.dbflute.cbean.sqlclause.subquery.SubQueryPath) ReferrerInfo(org.dbflute.dbmeta.info.ReferrerInfo) DfTypeUtil(org.dbflute.util.DfTypeUtil) HpQDRFunction(org.dbflute.cbean.chelper.HpQDRFunction) SqlClause(org.dbflute.cbean.sqlclause.SqlClause) InScopeRelation(org.dbflute.cbean.sqlclause.subquery.InScopeRelation) DBMeta(org.dbflute.dbmeta.DBMeta) SubQueryPath(org.dbflute.cbean.sqlclause.subquery.SubQueryPath) SqlClause(org.dbflute.cbean.sqlclause.SqlClause) ColumnSqlNameProvider(org.dbflute.dbmeta.name.ColumnSqlNameProvider) QueryDerivedReferrer(org.dbflute.cbean.sqlclause.subquery.QueryDerivedReferrer) GearedCipherManager(org.dbflute.cbean.cipher.GearedCipherManager)

Example 18 with DBMeta

use of org.dbflute.dbmeta.DBMeta 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);
}
Also used : ColumnRealNameProvider(org.dbflute.dbmeta.name.ColumnRealNameProvider) DerivedReferrerOptionFactory(org.dbflute.cbean.coption.DerivedReferrerOptionFactory) UnionClauseProvider(org.dbflute.cbean.sqlclause.union.UnionClauseProvider) SpecifiedColumn(org.dbflute.cbean.dream.SpecifiedColumn) ConditionKeyInScope(org.dbflute.cbean.ckey.ConditionKeyInScope) Date(java.util.Date) ParameterOption(org.dbflute.cbean.coption.ParameterOption) LoggerFactory(org.slf4j.LoggerFactory) OrderByElement(org.dbflute.cbean.sqlclause.orderby.OrderByElement) QueryClause(org.dbflute.cbean.sqlclause.query.QueryClause) ExceptionMessageBuilder(org.dbflute.helper.message.ExceptionMessageBuilder) ColumnSqlNameProvider(org.dbflute.dbmeta.name.ColumnSqlNameProvider) SimpleMapPmb(org.dbflute.twowaysql.pmbean.SimpleMapPmb) ColumnRealName(org.dbflute.dbmeta.name.ColumnRealName) PrimaryInfo(org.dbflute.dbmeta.info.PrimaryInfo) OrScopeQueryAndPartUnsupportedOperationException(org.dbflute.exception.OrScopeQueryAndPartUnsupportedOperationException) Map(java.util.Map) HpInvalidQueryInfo(org.dbflute.cbean.chelper.HpInvalidQueryInfo) DfBeanDescFactory(org.dbflute.helper.beans.factory.DfBeanDescFactory) ManualOrderOption(org.dbflute.cbean.ordering.ManualOrderOption) ConditionOption(org.dbflute.cbean.coption.ConditionOption) FixedConditionLazyChecker(org.dbflute.cbean.sqlclause.join.FixedConditionLazyChecker) Method(java.lang.reflect.Method) RangeOfOption(org.dbflute.cbean.coption.RangeOfOption) DfCollectionUtil(org.dbflute.util.DfCollectionUtil) SubQuery(org.dbflute.cbean.scoping.SubQuery) TimeZone(java.util.TimeZone) IndependentProcessor(org.dbflute.helper.function.IndependentProcessor) Timestamp(java.sql.Timestamp) Collection(java.util.Collection) LikeSearchOption(org.dbflute.cbean.coption.LikeSearchOption) QueryModeProvider(org.dbflute.cbean.cvalue.ConditionValue.QueryModeProvider) FixedConditionResolver(org.dbflute.cbean.sqlclause.join.FixedConditionResolver) ScalarConditionOption(org.dbflute.cbean.coption.ScalarConditionOption) DBMeta(org.dbflute.dbmeta.DBMeta) FunCustodial(org.dbflute.FunCustodial) DfBeanDesc(org.dbflute.helper.beans.DfBeanDesc) Classification(org.dbflute.jdbc.Classification) List(java.util.List) ColumnInfo(org.dbflute.dbmeta.info.ColumnInfo) ExistsReferrer(org.dbflute.cbean.sqlclause.subquery.ExistsReferrer) LocalDate(java.time.LocalDate) Entry(java.util.Map.Entry) SqlClauseMySql(org.dbflute.cbean.sqlclause.SqlClauseMySql) DBMetaProvider(org.dbflute.dbmeta.DBMetaProvider) DBFluteSystem(org.dbflute.system.DBFluteSystem) ColumnFunctionCipher(org.dbflute.cbean.cipher.ColumnFunctionCipher) DateConditionAdjuster(org.dbflute.cbean.garnish.datefitting.DateConditionAdjuster) ConditionKeyPrepareResult(org.dbflute.cbean.ckey.ConditionKeyPrepareResult) ScalarCondition(org.dbflute.cbean.sqlclause.subquery.ScalarCondition) HpFixedConditionQueryResolver(org.dbflute.cbean.chelper.HpFixedConditionQueryResolver) LocalDateTime(java.time.LocalDateTime) IllegalConditionBeanOperationException(org.dbflute.exception.IllegalConditionBeanOperationException) HashMap(java.util.HashMap) ReflectionFailureException(org.dbflute.util.DfReflectionUtil.ReflectionFailureException) DerivedReferrerOption(org.dbflute.cbean.coption.DerivedReferrerOption) ManualOrderOptionCall(org.dbflute.cbean.ordering.ManualOrderOptionCall) GearedCipherManager(org.dbflute.cbean.cipher.GearedCipherManager) ConditionInvokingFailureException(org.dbflute.exception.ConditionInvokingFailureException) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) SqlClauseOracle(org.dbflute.cbean.sqlclause.SqlClauseOracle) HpQDRSetupper(org.dbflute.cbean.chelper.HpQDRSetupper) ExtensionOperand(org.dbflute.dbway.ExtensionOperand) HpQDRParameter(org.dbflute.cbean.chelper.HpQDRParameter) PartitionByProvider(org.dbflute.cbean.sqlclause.subquery.ScalarCondition.PartitionByProvider) DfReflectionUtil(org.dbflute.util.DfReflectionUtil) QueryUsedAliasInfo(org.dbflute.cbean.sqlclause.query.QueryUsedAliasInfo) ShortCharHandlingMode(org.dbflute.jdbc.ShortCharHandlingMode) Srl(org.dbflute.util.Srl) QueryClauseArranger(org.dbflute.cbean.sqlclause.query.QueryClauseArranger) ColumnSqlName(org.dbflute.dbmeta.name.ColumnSqlName) ConditionValue(org.dbflute.cbean.cvalue.ConditionValue) RelationInfo(org.dbflute.dbmeta.info.RelationInfo) ForeignInfo(org.dbflute.dbmeta.info.ForeignInfo) FromToOption(org.dbflute.cbean.coption.FromToOption) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) HpSLCFunction(org.dbflute.cbean.chelper.HpSLCFunction) SpecifyDerivedReferrer(org.dbflute.cbean.sqlclause.subquery.SpecifyDerivedReferrer) WayOfMySQL(org.dbflute.dbway.WayOfMySQL) QueryDerivedReferrer(org.dbflute.cbean.sqlclause.subquery.QueryDerivedReferrer) ConditionKey(org.dbflute.cbean.ckey.ConditionKey) ConditionOptionCall(org.dbflute.cbean.coption.ConditionOptionCall) HpSLCCustomized(org.dbflute.cbean.chelper.HpSLCCustomized) ConditionBeanExceptionThrower(org.dbflute.cbean.exception.ConditionBeanExceptionThrower) HpDerivingSubQueryInfo(org.dbflute.cbean.chelper.HpDerivingSubQueryInfo) SubQueryPath(org.dbflute.cbean.sqlclause.subquery.SubQueryPath) ReferrerInfo(org.dbflute.dbmeta.info.ReferrerInfo) DfTypeUtil(org.dbflute.util.DfTypeUtil) HpQDRFunction(org.dbflute.cbean.chelper.HpQDRFunction) SqlClause(org.dbflute.cbean.sqlclause.SqlClause) InScopeRelation(org.dbflute.cbean.sqlclause.subquery.InScopeRelation) DBMeta(org.dbflute.dbmeta.DBMeta) SubQueryPath(org.dbflute.cbean.sqlclause.subquery.SubQueryPath) SqlClause(org.dbflute.cbean.sqlclause.SqlClause) ColumnSqlNameProvider(org.dbflute.dbmeta.name.ColumnSqlNameProvider) GearedCipherManager(org.dbflute.cbean.cipher.GearedCipherManager) InScopeRelation(org.dbflute.cbean.sqlclause.subquery.InScopeRelation)

Example 19 with DBMeta

use of org.dbflute.dbmeta.DBMeta in project dbflute-core by dbflute.

the class AbstractConditionQuery method xbuildReferrerCorrelatedFixedCondition.

protected String xbuildReferrerCorrelatedFixedCondition(ConditionQuery subQuery, String referrerPropertyName) {
    if (referrerPropertyName == null) {
        return null;
    }
    final DBMeta localDBMeta = xgetLocalDBMeta();
    if (!localDBMeta.hasReferrer(referrerPropertyName)) {
        // one-to-one referrer
        return null;
    }
    final ReferrerInfo referrerInfo = localDBMeta.findReferrerInfo(referrerPropertyName);
    return xdoBuildReferrerCorrelatedFixedCondition(subQuery, referrerInfo);
}
Also used : DBMeta(org.dbflute.dbmeta.DBMeta) ReferrerInfo(org.dbflute.dbmeta.info.ReferrerInfo)

Example 20 with DBMeta

use of org.dbflute.dbmeta.DBMeta in project dbflute-core by dbflute.

the class AbstractConditionBean method enablePagingSelectAndQuerySplit.

/**
 * Enable that it splits the SQL execute select and query of paging. <br>
 * You should confirm that the executed SQL on log matches with your expectation. <br>
 * It is very difficult internal logic so it also has simplistic logic. Be careful!
 * <pre>
 * Cannot use this:
 *  o if no PK or compound PK table (exception is thrown)
 *  o if SpecifiedDerivedOrderBy or not Paging (but no exception)
 *
 * Automatically Changed:
 *  o disable PagingCountLater (to suppress rows calculation)
 * </pre>
 * @deprecated This is rare handling for performance tuning so don't use this easily.
 */
public void enablePagingSelectAndQuerySplit() {
    assertOptionThatBadTiming("enablePagingSelectAndQuerySplit()");
    final DBMeta dbmeta = asDBMeta();
    if (!dbmeta.hasPrimaryKey() || dbmeta.getPrimaryInfo().isCompoundKey()) {
        String msg = "The PagingSelectAndQuerySplit needs only-one column key table: " + asTableDbName();
        throw new IllegalConditionBeanOperationException(msg);
    }
    // MySQL's rows calculation is not fit with this function
    // e.g.
    // paging : select PK only by business condition with sql_calc_found_rows
    // paging : select business data by PK without no sql_calc_found_rows
    // count  : select found_rows() -> returns latest count, why?
    disablePagingCountLater();
    _pagingSelectAndQuerySplit = true;
}
Also used : DBMeta(org.dbflute.dbmeta.DBMeta) IllegalConditionBeanOperationException(org.dbflute.exception.IllegalConditionBeanOperationException)

Aggregations

DBMeta (org.dbflute.dbmeta.DBMeta)64 ColumnInfo (org.dbflute.dbmeta.info.ColumnInfo)32 ArrayList (java.util.ArrayList)13 ForeignInfo (org.dbflute.dbmeta.info.ForeignInfo)13 List (java.util.List)12 LinkedHashMap (java.util.LinkedHashMap)11 ColumnSqlName (org.dbflute.dbmeta.name.ColumnSqlName)10 Entity (org.dbflute.Entity)9 PrimaryInfo (org.dbflute.dbmeta.info.PrimaryInfo)9 ReferrerInfo (org.dbflute.dbmeta.info.ReferrerInfo)9 Method (java.lang.reflect.Method)8 ReflectionFailureException (org.dbflute.util.DfReflectionUtil.ReflectionFailureException)8 Map (java.util.Map)7 ColumnFunctionCipher (org.dbflute.cbean.cipher.ColumnFunctionCipher)7 RelationInfo (org.dbflute.dbmeta.info.RelationInfo)7 LocalDate (java.time.LocalDate)6 LocalDateTime (java.time.LocalDateTime)6 Collection (java.util.Collection)6 Date (java.util.Date)6 HashMap (java.util.HashMap)6