Search in sources :

Example 11 with QueryClause

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();
}
Also used : QueryClause(org.dbflute.cbean.sqlclause.query.QueryClause) OrScopeQueryAndPartQueryClause(org.dbflute.cbean.sqlclause.query.OrScopeQueryAndPartQueryClause) StringQueryClause(org.dbflute.cbean.sqlclause.query.StringQueryClause)

Example 12 with QueryClause

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());
}
Also used : QueryClause(org.dbflute.cbean.sqlclause.query.QueryClause) OrScopeQueryAndPartQueryClause(org.dbflute.cbean.sqlclause.query.OrScopeQueryAndPartQueryClause) StringQueryClause(org.dbflute.cbean.sqlclause.query.StringQueryClause) TableSqlName(org.dbflute.dbmeta.name.TableSqlName)

Example 13 with QueryClause

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);
                }
            }
        }
    };
}
Also used : HpCalcSpecification(org.dbflute.cbean.chelper.HpCalcSpecification) ColumnInfo(org.dbflute.dbmeta.info.ColumnInfo) ColumnQueryCalculationUnsupportedColumnTypeException(org.dbflute.exception.ColumnQueryCalculationUnsupportedColumnTypeException) QueryClause(org.dbflute.cbean.sqlclause.query.QueryClause)

Example 14 with QueryClause

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;
}
Also used : QueryClause(org.dbflute.cbean.sqlclause.query.QueryClause)

Aggregations

QueryClause (org.dbflute.cbean.sqlclause.query.QueryClause)14 OrScopeQueryAndPartQueryClause (org.dbflute.cbean.sqlclause.query.OrScopeQueryAndPartQueryClause)11 StringQueryClause (org.dbflute.cbean.sqlclause.query.StringQueryClause)11 ColumnRealName (org.dbflute.dbmeta.name.ColumnRealName)3 QueryUsedAliasInfo (org.dbflute.cbean.sqlclause.query.QueryUsedAliasInfo)2 DBMeta (org.dbflute.dbmeta.DBMeta)2 ColumnInfo (org.dbflute.dbmeta.info.ColumnInfo)2 TableSqlName (org.dbflute.dbmeta.name.TableSqlName)2 Method (java.lang.reflect.Method)1 Timestamp (java.sql.Timestamp)1 LocalDate (java.time.LocalDate)1 LocalDateTime (java.time.LocalDateTime)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Map (java.util.Map)1