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);
}
}
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;
}
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);
}
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));
}
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;
}
}
Aggregations