use of org.dbflute.cbean.sqlclause.query.QueryClause in project dbflute-core by dbflute.
the class AbstractSqlClause method getInlineViewClause.
protected String getInlineViewClause(TableSqlName inlineTableSqlName, List<QueryClause> inlineWhereClauseList, int tablePos) {
final String inlineBaseAlias = getInlineViewBasePointAlias();
final StringBuilder sb = new StringBuilder();
sb.append("(select * from ").append(inlineTableSqlName).append(" ").append(inlineBaseAlias);
final String baseIndent = buildSpaceBar(tablePos + 1);
sb.append(ln()).append(baseIndent);
sb.append(" where ");
int count = 0;
for (QueryClause whereClause : inlineWhereClauseList) {
final String clauseElement = filterWhereClauseSimply(whereClause.toString());
if (count > 0) {
sb.append(ln()).append(baseIndent);
sb.append(" and ");
}
sb.append(clauseElement);
++count;
}
sb.append(")");
return sb.toString();
}
use of org.dbflute.cbean.sqlclause.query.QueryClause in project dbflute-core by dbflute.
the class AbstractSqlClause method buildFromClause.
protected void buildFromClause(StringBuilder sb) {
sb.append(ln()).append(" ");
sb.append("from ");
// basically for in-line view indent
int tablePos = 7;
if (isJoinInParentheses()) {
for (int i = 0; i < getOuterJoinMap().size(); i++) {
sb.append("(");
++tablePos;
}
}
final TableSqlName tableSqlName = getDBMeta().getTableSqlName();
final String basePointAliasName = getBasePointAliasName();
if (hasBaseTableInlineWhereClause()) {
final List<QueryClause> baseTableInlineWhereList = getBaseTableInlineWhereList();
sb.append(getInlineViewClause(tableSqlName, baseTableInlineWhereList, tablePos));
sb.append(" ").append(basePointAliasName);
} else {
sb.append(tableSqlName).append(" ").append(basePointAliasName);
}
sb.append(getFromBaseTableHint());
if (_dynamicHintFromBaseTable != null) {
sb.append(" ").append(_dynamicHintFromBaseTable);
}
sb.append(getLeftOuterJoinClause());
}
use of org.dbflute.cbean.sqlclause.query.QueryClause in project dbflute-core by dbflute.
the class AbstractConditionBean method xcreateColQyClause.
// -----------------------------------------------------
// Create ColQyClause
// ------------------
protected <CB extends ConditionBean> QueryClause xcreateColQyClause(final String leftColumn, final String operand, final String rightColumn, final HpCalcSpecification<CB> rightCalcSp) {
return new QueryClause() {
@Override
public String toString() {
final String leftExp = resolveColumnExp(rightCalcSp.getLeftCalcSp(), leftColumn);
final String rightExp = resolveColumnExp(rightCalcSp, rightColumn);
return xbuildColQyClause(leftExp, operand, rightExp);
}
protected String resolveColumnExp(HpCalcSpecification<CB> calcSp, String columnExp) {
final String resolvedExp;
if (calcSp != null) {
final String statement = calcSp.buildStatementToSpecifidName(columnExp);
if (statement != null) {
// exists calculation
assertCalculationColumnType(calcSp);
// cipher already resolved
resolvedExp = statement;
} else {
final ColumnInfo columnInfo = calcSp.getSpecifiedColumnInfo();
if (columnInfo != null) {
// means plain column
resolvedExp = decryptIfNeeds(columnInfo, columnExp);
} else {
// deriving sub-query
resolvedExp = columnExp;
}
}
} else {
resolvedExp = columnExp;
}
return resolvedExp;
}
protected void assertCalculationColumnType(HpCalcSpecification<CB> calcSp) {
if (calcSp.hasConvert()) {
// because it may be Date type
return;
}
final ColumnInfo columnInfo = calcSp.getResolvedSpecifiedColumnInfo();
if (columnInfo != null) {
// basically true but checked just in case
if (!columnInfo.isObjectNativeTypeNumber()) {
// *simple message because other types may be supported at the future
String msg = "Not number column specified: " + columnInfo;
throw new ColumnQueryCalculationUnsupportedColumnTypeException(msg);
}
}
}
};
}
use of org.dbflute.cbean.sqlclause.query.QueryClause in project dbflute-core by dbflute.
the class AbstractConditionBean method xcolqy.
// [DBFlute-0.9.5.3]
// ===================================================================================
// Column Query
// ============
protected <CB extends ConditionBean> ColumnCalculator xcolqy(CB leftCB, CB rightCB, SpecifyQuery<CB> leftSp, SpecifyQuery<CB> rightSp, final String operand) {
assertQueryPurpose();
final HpCalcSpecification<CB> leftCalcSp = xcreateCalcSpecification(leftSp);
leftCalcSp.specify(leftCB);
final String leftColumn = xbuildColQyLeftColumn(leftCB, leftCalcSp);
final HpCalcSpecification<CB> rightCalcSp = xcreateCalcSpecification(rightSp);
rightCalcSp.specify(rightCB);
final String rightColumn = xbuildColQyRightColumn(rightCB, rightCalcSp);
rightCalcSp.setLeftCalcSp(leftCalcSp);
final QueryClause queryClause = xcreateColQyClause(leftColumn, operand, rightColumn, rightCalcSp);
xregisterColQyClause(queryClause, leftCalcSp, rightCalcSp);
return rightCalcSp;
}
Aggregations