use of org.dbflute.dbmeta.info.ColumnInfo in project dbflute-core by dbflute.
the class AbstractSqlClause method buildSelectClauseSpecifiedScalar.
protected String buildSelectClauseSpecifiedScalar(String aliasName, String function) {
final String columnAlias = getScalarSelectColumnAlias();
final ColumnSqlName columnSqlName = getSpecifiedColumnSqlNameAsOne();
if (columnSqlName != null) {
// normal column
final String valueExp = aliasName + "." + columnSqlName;
if (hasUnionQuery() && hasSpecifyCalculation(getSpecifiedColumnAsOne())) {
throwScalarSelectUnionQuerySpecifyCalculationUnsupportedException();
}
// not null here
final ColumnInfo columnInfo = getSpecifiedColumnInfoAsOne();
// calculation resolved
final String functionExp = doBuildFunctionExp(function, columnInfo, valueExp);
return "select " + functionExp + " as " + columnAlias;
}
final String subQuery = getSpecifiedDerivingSubQueryAsOne();
if (subQuery != null) {
// SpecifyCalculation is already resolved in DerivedReferrer process
if (hasUnionQuery()) {
final String valueExp = aliasName + "." + columnAlias;
// not null here
final ColumnInfo columnInfo = getSpecifiedDerivingColumnInfoAsOne();
return "select " + doBuildFunctionExp(function, decryptSelectColumnIfNeeds(columnInfo, valueExp));
} else {
// adjusts alias definition target (move to function's scope)
final String aliasDef = " as " + columnAlias;
final StringBuilder sb = new StringBuilder();
final String pureSubQuery = Srl.substringLastFront(subQuery, aliasDef);
// just in case
final String aliasDefRear = Srl.substringLastRear(subQuery, aliasDef);
final String functionExp = doBuildFunctionExp(function, pureSubQuery);
sb.append("select ").append(functionExp).append(aliasDef).append(aliasDefRear);
return sb.toString();
}
}
String msg = "Not found specifed column for scalar: function=" + function;
// basically no way (checked before)
throw new IllegalStateException(msg);
}
use of org.dbflute.dbmeta.info.ColumnInfo in project dbflute-core by dbflute.
the class AbstractSqlClause method buildQueryUpdateSetClause.
protected void buildQueryUpdateSetClause(Map<String, Object> columnParameterMap, DBMeta dbmeta, StringBuilder sb, String aliasName) {
if (columnParameterMap == null) {
String msg = "The argument 'columnParameterMap' should not be null.";
throw new IllegalArgumentException(msg);
}
sb.append(ln());
int index = 0;
final int mapSize = columnParameterMap.size();
for (Entry<String, Object> entry : columnParameterMap.entrySet()) {
final String columnName = entry.getKey();
final Object parameter = entry.getValue();
final ColumnInfo columnInfo = dbmeta.findColumnInfo(columnName);
final ColumnSqlName columnSqlName = columnInfo.getColumnSqlName();
if (index == 0) {
sb.append(" set ");
} else {
sb.append(" , ");
}
if (aliasName != null) {
sb.append(aliasName);
}
sb.append(columnSqlName).append(" = ");
final String valueExp;
if (parameter instanceof QueryUpdateSetCalculationHandler) {
final QueryUpdateSetCalculationHandler handler = (QueryUpdateSetCalculationHandler) parameter;
valueExp = handler.buildStatement(aliasName);
} else {
valueExp = parameter.toString();
}
sb.append(encryptIfNeeds(columnInfo, valueExp));
if (mapSize - 1 > index) {
// before last loop
sb.append(ln());
}
++index;
}
}
use of org.dbflute.dbmeta.info.ColumnInfo in project dbflute-core by dbflute.
the class ScalarCondition method buildScalarCondition.
// ===================================================================================
// Build Clause
// ============
public String buildScalarCondition(String function, ScalarConditionOption option) {
setupOptionAttribute(option);
// get the specified column before it disappears at sub-query making.
final ColumnRealName columnRealName;
{
final String columnDbName = _subQuerySqlClause.getSpecifiedColumnDbNameAsOne();
if (columnDbName == null || columnDbName.trim().length() == 0) {
throwScalarConditionInvalidColumnSpecificationException(function);
}
columnRealName = _localRealNameProvider.provide(columnDbName);
}
final String subQueryClause = buildSubQueryClause(function, option);
final String beginMark = resolveSubQueryBeginMark(_subQueryIdentity) + ln();
final String endMark = resolveSubQueryEndMark(_subQueryIdentity);
final String endIndent = " ";
final ColumnInfo columnInfo = _subQuerySqlClause.getSpecifiedColumnInfoAsOne();
final String specifiedExp = decrypt(columnInfo, columnRealName.toString());
return // left and operand
specifiedExp + " " + _operand + " (" + beginMark + subQueryClause + ln() + endIndent + ") " + // right
endMark;
}
use of org.dbflute.dbmeta.info.ColumnInfo in project dbflute-core by dbflute.
the class ScalarCondition method buildUnionMainPartClause.
// almost same as derived-referrer's logic
protected String buildUnionMainPartClause(ColumnSqlName relatedColumnSqlName, String tableAliasName, ColumnRealName derivedColumnRealName, ColumnSqlName derivedColumnSqlName) {
// derivedColumnSqlName : e.g. PURCHASE_PRICE
// derivedRealSqlName : might be sub-query
final ColumnSqlName derivedRealSqlName = derivedColumnRealName.getColumnSqlName();
final StringBuilder keySb = new StringBuilder();
final List<ColumnInfo> pkList = _subQueryDBMeta.getPrimaryInfo().getPrimaryColumnList();
for (ColumnInfo pk : pkList) {
final ColumnSqlName pkSqlName = pk.getColumnSqlName();
if (pkSqlName.equals(derivedRealSqlName) || pkSqlName.equals(relatedColumnSqlName)) {
// to suppress same columns selected
continue;
}
keySb.append(keySb.length() > 0 ? ", " : "");
keySb.append(ColumnRealName.create(tableAliasName, pk.getColumnSqlName()));
}
if (relatedColumnSqlName != null && !relatedColumnSqlName.equals(derivedRealSqlName)) {
// to suppress same columns selected
keySb.append(keySb.length() > 0 ? ", " : "");
keySb.append(ColumnRealName.create(tableAliasName, relatedColumnSqlName));
}
setupUnionMainForDerivedColumn(keySb, derivedColumnRealName, derivedColumnSqlName, derivedRealSqlName);
return completeUnionMainWholeClause(tableAliasName, keySb);
}
use of org.dbflute.dbmeta.info.ColumnInfo in project dbflute-core by dbflute.
the class ScalarCondition method setupOptionAttribute.
protected void setupOptionAttribute(ScalarConditionOption option) {
ColumnInfo columnInfo = _subQuerySqlClause.getSpecifiedColumnInfoAsOne();
if (columnInfo == null) {
columnInfo = _subQuerySqlClause.getSpecifiedDerivingColumnInfoAsOne();
}
// basically not null (checked before)
option.xsetTargetColumnInfo(columnInfo);
option.xjudgeDatabase(_subQuerySqlClause);
}
Aggregations