Search in sources :

Example 6 with ColumnRealName

use of org.dbflute.dbmeta.name.ColumnRealName in project dbflute-core by dbflute.

the class DerivedReferrer method buildDerivedReferrer.

// ===================================================================================
// Build Clause
// ============
public String buildDerivedReferrer(String function, String correlatedColumnDbName, String relatedColumnDbName, String correlatedFixedCondition, DerivedReferrerOption option) {
    setupOptionAttribute(option);
    if (isSinglePrimaryKey(correlatedColumnDbName, relatedColumnDbName)) {
        final ColumnRealName correlatedColumnRealName = _localRealNameProvider.provide(correlatedColumnDbName);
        final ColumnSqlName relatedColumnSqlName = _subQuerySqlNameProvider.provide(relatedColumnDbName);
        final String subQueryClause = buildSubQueryClause(function, correlatedColumnRealName, relatedColumnSqlName, correlatedFixedCondition, option);
        final String beginMark = resolveSubQueryBeginMark(_subQueryIdentity) + ln();
        final String endMark = resolveSubQueryEndMark(_subQueryIdentity);
        final String endIndent = "       ";
        return doBuildDerivedReferrer(function, correlatedColumnRealName, relatedColumnSqlName, subQueryClause, beginMark, endMark, endIndent);
    } else {
        final List<String> columnDbNameSplit = Srl.splitListTrimmed(correlatedColumnDbName, ",");
        final ColumnRealName[] correlatedColumnRealNames = new ColumnRealName[columnDbNameSplit.size()];
        for (int i = 0; i < columnDbNameSplit.size(); i++) {
            correlatedColumnRealNames[i] = _localRealNameProvider.provide(columnDbNameSplit.get(i));
        }
        final List<String> relatedColumnSplit = Srl.splitListTrimmed(relatedColumnDbName, ",");
        final ColumnSqlName[] relatedColumnSqlNames = new ColumnSqlName[relatedColumnSplit.size()];
        for (int i = 0; i < relatedColumnSplit.size(); i++) {
            relatedColumnSqlNames[i] = _subQuerySqlNameProvider.provide(relatedColumnSplit.get(i));
        }
        final String subQueryClause = buildSubQueryClause(function, correlatedColumnRealNames, relatedColumnSqlNames, correlatedFixedCondition, option);
        final String beginMark = resolveSubQueryBeginMark(_subQueryIdentity) + ln();
        final String endMark = resolveSubQueryEndMark(_subQueryIdentity);
        final String endIndent = "       ";
        return doBuildDerivedReferrer(function, correlatedColumnRealNames, relatedColumnSqlNames, subQueryClause, beginMark, endMark, endIndent);
    }
}
Also used : ColumnSqlName(org.dbflute.dbmeta.name.ColumnSqlName) ColumnRealName(org.dbflute.dbmeta.name.ColumnRealName)

Example 7 with ColumnRealName

use of org.dbflute.dbmeta.name.ColumnRealName in project dbflute-core by dbflute.

the class ExistsReferrer method buildExistsReferrer.

// ===================================================================================
// Build Clause
// ============
/**
 * Build the clause of sub-query by single primary key.
 * @param correlatedColumnDbName The DB name of correlated column that is main-query table's column. (NotNull)
 * @param relatedColumnDbName The DB name of related column that is sub-query table's column. (NotNull)
 * @param correlatedFixedCondition The fixed condition as correlated condition. (NullAllowed)
 * @param existsOption The option of ExistsReferrer. (basically for NotExistsReferrer) (NullAllowed: if null, means ExistsReferrer)
 * @return The clause of sub-query. (NotNull)
 */
public String buildExistsReferrer(String correlatedColumnDbName, String relatedColumnDbName, String correlatedFixedCondition, String existsOption) {
    existsOption = existsOption != null ? existsOption + " " : "";
    final String subQueryClause;
    if (isSinglePrimaryKey(correlatedColumnDbName, relatedColumnDbName)) {
        final ColumnSqlName relatedColumnSqlName = _subQuerySqlNameProvider.provide(relatedColumnDbName);
        final ColumnRealName correlatedColumnRealName = _localRealNameProvider.provide(correlatedColumnDbName);
        subQueryClause = buildSubQueryClause(correlatedColumnRealName, relatedColumnSqlName, correlatedFixedCondition);
    } else {
        // compound primary keys
        final List<String> columnDbNameSplit = Srl.splitListTrimmed(correlatedColumnDbName, ",");
        final ColumnRealName[] correlatedColumnRealNames = new ColumnRealName[columnDbNameSplit.size()];
        for (int i = 0; i < columnDbNameSplit.size(); i++) {
            correlatedColumnRealNames[i] = _localRealNameProvider.provide(columnDbNameSplit.get(i));
        }
        final List<String> relatedColumnSplit = Srl.splitListTrimmed(relatedColumnDbName, ",");
        final ColumnSqlName[] relatedColumnSqlNames = new ColumnSqlName[relatedColumnSplit.size()];
        for (int i = 0; i < relatedColumnSplit.size(); i++) {
            relatedColumnSqlNames[i] = _subQuerySqlNameProvider.provide(relatedColumnSplit.get(i));
        }
        subQueryClause = buildSubQueryClause(correlatedColumnRealNames, relatedColumnSqlNames, correlatedFixedCondition);
    }
    final String beginMark = resolveSubQueryBeginMark(_subQueryIdentity) + ln();
    final String endMark = resolveSubQueryEndMark(_subQueryIdentity);
    final String endIndent = "       ";
    return existsOption + "exists (" + beginMark + subQueryClause + ln() + endIndent + ")" + endMark;
}
Also used : ColumnSqlName(org.dbflute.dbmeta.name.ColumnSqlName) ColumnRealName(org.dbflute.dbmeta.name.ColumnRealName)

Example 8 with ColumnRealName

use of org.dbflute.dbmeta.name.ColumnRealName in project dbflute-core by dbflute.

the class ConditionKey method resolveBindClause.

// -----------------------------------------------------
// Clause Resolver
// ---------------
protected BindClauseResult resolveBindClause(ColumnRealName columnRealName, String location, ColumnFunctionCipher cipher, ConditionOption option) {
    final String basicBindExp = buildBindVariableExp(location, option);
    final String bindExp;
    final ColumnRealName resolvedColumn;
    {
        final ColumnRealName columnExp;
        if (cipher != null) {
            final String plainColumnExp = columnRealName.toString();
            final String decryptExp = cipher.decrypt(plainColumnExp);
            final boolean nonInvertible = plainColumnExp.equals(decryptExp);
            if (isBindEncryptAllowed(columnRealName, option, nonInvertible)) {
                bindExp = cipher.encrypt(basicBindExp);
                columnExp = columnRealName;
            } else {
                // needs to decrypt (invertible)
                bindExp = basicBindExp;
                columnExp = toColumnRealName(decryptExp);
            }
        } else {
            // mainly here
            bindExp = basicBindExp;
            columnExp = columnRealName;
        }
        resolvedColumn = resolveOptionalColumn(columnExp, option);
    }
    return createBindClauseResult(resolvedColumn, bindExp, option);
}
Also used : ColumnRealName(org.dbflute.dbmeta.name.ColumnRealName)

Example 9 with ColumnRealName

use of org.dbflute.dbmeta.name.ColumnRealName in project dbflute-core by dbflute.

the class ConditionKey method resolveCompoundColumn.

protected ColumnRealName resolveCompoundColumn(ColumnRealName baseRealName, ConditionOption option) {
    if (option == null || !option.hasCompoundColumn()) {
        return baseRealName;
    }
    if (!option.hasStringConnector()) {
        // basically no way
        String msg = "The option should have string connector when compound column is specified: " + option;
        throw new IllegalConditionBeanOperationException(msg);
    }
    final List<SpecifiedColumn> compoundColumnList = option.getCompoundColumnList();
    final List<ColumnRealName> realNameList = new ArrayList<ColumnRealName>();
    // already cipher
    realNameList.add(doResolveCompoundColumnOption(option, baseRealName));
    for (SpecifiedColumn specifiedColumn : compoundColumnList) {
        realNameList.add(doResolveCompoundColumnOption(option, doResolveCompoundColumnCipher(option, specifiedColumn)));
    }
    final OnQueryStringConnector stringConnector = option.getStringConnector();
    final String connected = stringConnector.connect(realNameList.toArray());
    return ColumnRealName.create(null, new ColumnSqlName(connected));
}
Also used : ColumnSqlName(org.dbflute.dbmeta.name.ColumnSqlName) IllegalConditionBeanOperationException(org.dbflute.exception.IllegalConditionBeanOperationException) ArrayList(java.util.ArrayList) SpecifiedColumn(org.dbflute.cbean.dream.SpecifiedColumn) ColumnRealName(org.dbflute.dbmeta.name.ColumnRealName) OnQueryStringConnector(org.dbflute.dbway.OnQueryStringConnector)

Example 10 with ColumnRealName

use of org.dbflute.dbmeta.name.ColumnRealName in project dbflute-core by dbflute.

the class ConditionKey method doResolveCompoundColumnCipher.

protected ColumnRealName doResolveCompoundColumnCipher(ConditionOption option, SpecifiedColumn specifiedColumn) {
    final GearedCipherManager cipherManager = option.getGearedCipherManager();
    final ColumnRealName specifiedName = specifiedColumn.toColumnRealName();
    if (cipherManager != null && !specifiedColumn.isDerived()) {
        final ColumnInfo columnInfo = specifiedColumn.getColumnInfo();
        final ColumnFunctionCipher cipher = cipherManager.findColumnFunctionCipher(columnInfo);
        if (cipher != null) {
            return toColumnRealName(cipher.decrypt(specifiedName.toString()));
        } else {
            return specifiedName;
        }
    } else {
        return specifiedName;
    }
}
Also used : ColumnInfo(org.dbflute.dbmeta.info.ColumnInfo) ColumnFunctionCipher(org.dbflute.cbean.cipher.ColumnFunctionCipher) GearedCipherManager(org.dbflute.cbean.cipher.GearedCipherManager) ColumnRealName(org.dbflute.dbmeta.name.ColumnRealName)

Aggregations

ColumnRealName (org.dbflute.dbmeta.name.ColumnRealName)21 ColumnSqlName (org.dbflute.dbmeta.name.ColumnSqlName)8 ColumnInfo (org.dbflute.dbmeta.info.ColumnInfo)5 ColumnFunctionCipher (org.dbflute.cbean.cipher.ColumnFunctionCipher)2 SpecifiedColumn (org.dbflute.cbean.dream.SpecifiedColumn)2 OrScopeQueryAndPartQueryClause (org.dbflute.cbean.sqlclause.query.OrScopeQueryAndPartQueryClause)2 QueryClause (org.dbflute.cbean.sqlclause.query.QueryClause)2 StringQueryClause (org.dbflute.cbean.sqlclause.query.StringQueryClause)2 DBMeta (org.dbflute.dbmeta.DBMeta)2 ArrayList (java.util.ArrayList)1 GearedCipherManager (org.dbflute.cbean.cipher.GearedCipherManager)1 QueryModeProvider (org.dbflute.cbean.cvalue.ConditionValue.QueryModeProvider)1 SqlClause (org.dbflute.cbean.sqlclause.SqlClause)1 FixedConditionResolver (org.dbflute.cbean.sqlclause.join.FixedConditionResolver)1 OnQueryStringConnector (org.dbflute.dbway.OnQueryStringConnector)1 IllegalConditionBeanOperationException (org.dbflute.exception.IllegalConditionBeanOperationException)1