Search in sources :

Example 1 with HpCalcSpecification

use of org.dbflute.cbean.chelper.HpCalcSpecification 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)

Aggregations

HpCalcSpecification (org.dbflute.cbean.chelper.HpCalcSpecification)1 QueryClause (org.dbflute.cbean.sqlclause.query.QueryClause)1 ColumnInfo (org.dbflute.dbmeta.info.ColumnInfo)1 ColumnQueryCalculationUnsupportedColumnTypeException (org.dbflute.exception.ColumnQueryCalculationUnsupportedColumnTypeException)1