use of org.dbflute.exception.ColumnQueryCalculationUnsupportedColumnTypeException 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);
}
}
}
};
}
Aggregations