use of org.dbflute.dbmeta.name.ColumnSqlName 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.name.ColumnSqlName in project dbflute-core by dbflute.
the class AbstractSqlClause method buildQueryUpdateInScopeClause.
protected void buildQueryUpdateInScopeClause(Map<String, Object> columnParameterMap, DBMeta dbmeta, StringBuilder sb) {
if (columnParameterMap != null) {
buildQueryUpdateSetClause(columnParameterMap, dbmeta, sb, null);
}
final ColumnSqlName primaryKeyName = dbmeta.getPrimaryInfo().getFirstColumn().getColumnSqlName();
final String selectClause = "select " + getBasePointAliasName() + "." + primaryKeyName;
String fromWhereClause = getClauseFromWhereWithUnionTemplate();
// Replace template marks. These are very important!
fromWhereClause = replace(fromWhereClause, getUnionSelectClauseMark(), selectClause);
fromWhereClause = replace(fromWhereClause, getUnionWhereClauseMark(), "");
fromWhereClause = replace(fromWhereClause, getUnionWhereFirstConditionMark(), "");
final String subQuery = processSubQueryIndent(selectClause + " " + fromWhereClause);
sb.append(ln());
sb.append(" where ").append(primaryKeyName);
sb.append(" in (").append(ln()).append(subQuery);
if (!subQuery.endsWith(ln())) {
sb.append(ln());
}
sb.append(")");
}
use of org.dbflute.dbmeta.name.ColumnSqlName 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.name.ColumnSqlName 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.name.ColumnSqlName in project dbflute-core by dbflute.
the class DerivedReferrer method setupUnionMainForFixedCondition.
protected void setupUnionMainForFixedCondition(StringBuilder keySb, String tableAliasName, ColumnSqlName derivedColumnSqlName) {
// all columns because fixed condition might contain them
final List<ColumnInfo> columnInfoList = _subQueryDBMeta.getColumnInfoList();
for (ColumnInfo columnInfo : columnInfoList) {
final ColumnSqlName sqlName = columnInfo.getColumnSqlName();
if (sqlName.equals(derivedColumnSqlName)) {
// to suppress same columns selected
continue;
}
final ColumnRealName realName = ColumnRealName.create(tableAliasName, columnInfo.getColumnSqlName());
keySb.append(keySb.length() > 0 ? ", " : "");
keySb.append(realName);
}
}
Aggregations