use of org.dbflute.cbean.coption.ColumnConversionOption in project dbflute-core by dbflute.
the class HpCalcSpecification method doBuildStatement.
protected String doBuildStatement(String columnExp, Map<String, String> columnAliasMap, boolean removeCalcAlias) {
if (_calculationList.isEmpty()) {
return null;
}
// columnAliasMap means, e.g. union, already handled cipher
String targetExp = columnAliasMap != null ? columnExp : decryptIfNeeds(columnExp);
int index = 0;
final boolean firstEnclosing = needsFirstEnclosing(targetExp);
for (HpCalcElement calculation : _calculationList) {
if (index > 0 || (index == 0 && firstEnclosing)) {
targetExp = "(" + targetExp + ")";
}
if (!calculation.isPreparedConvOption()) {
final ColumnConversionOption option = calculation.getColumnConversionOption();
if (option != null) {
prepareConvOption(option, removeCalcAlias);
calculation.setPreparedConvOption(true);
}
}
targetExp = buildCalculationExp(targetExp, columnAliasMap, calculation, removeCalcAlias);
++index;
}
return targetExp;
}
use of org.dbflute.cbean.coption.ColumnConversionOption in project dbflute-core by dbflute.
the class HpCalcSpecification method convert.
/**
* {@inheritDoc}
*/
public ColumnCalculator convert(FunctionFilterOptionCall<ColumnConversionOption> opLambda) {
assertObjectNotNull("opLambda", opLambda);
if (_leftMode) {
assertLeftCalcSp();
// dispatch to nested one
_leftCalcSp.convert(opLambda);
return this;
} else {
final ColumnConversionOption option = createColumnConversionOption();
opLambda.callback(option);
// main process
return registerConv(option);
}
}
use of org.dbflute.cbean.coption.ColumnConversionOption in project dbflute-core by dbflute.
the class HpCalcSpecification method buildCalculationExp.
/**
* @param targetExp The expression of target column already handled cipher. (NotNull)
* @param columnAliasMap The map of column alias. (NullAllowed)
* @param calculation The element of calculation. (NotNull)
* @param removeCalcAlias Does it remove alias of calculation column.
* @return The expression of calculation statement. (NotNull)
*/
protected String buildCalculationExp(String targetExp, Map<String, String> columnAliasMap, HpCalcElement calculation, boolean removeCalcAlias) {
final CalculationType calculationType = calculation.getCalculationType();
if (calculationType.equals(CalculationType.CONV)) {
// convert
final ColumnConversionOption columnConversionOption = calculation.getColumnConversionOption();
return columnConversionOption.filterFunction(targetExp);
}
// number value or number column here
final Object calcValueExp;
if (calculation.hasCalculationValue()) {
// number value
calcValueExp = calculation.getCalculationValue();
} else if (calculation.hasCalculationColumn()) {
// number column
final SpecifiedColumn calculationColumn = calculation.getCalculationColumn();
final String columnExp;
if (removeCalcAlias) {
// means e.g. plain update
final String basePointAliasName = _baseCB.getSqlClause().getBasePointAliasName();
if (!basePointAliasName.equals(calculationColumn.getTableAliasName())) {
// may be relation column
throwCalculationColumnRelationUnresolvedException(targetExp, calculationColumn);
}
columnExp = calculationColumn.toColumnSqlName().toString();
} else {
columnExp = calculationColumn.toColumnRealName().toString();
}
final Object baseExp;
if (columnAliasMap != null) {
// e.g. ManualOrder on union
final String mappedAlias = columnAliasMap.get(columnExp);
baseExp = mappedAlias != null ? mappedAlias : columnExp;
} else {
// e.g. ColumnQuery, UpdateOption, non-union ManualOrder, DerivedReferrer
final ColumnInfo columnInfo = calculationColumn.getColumnInfo();
baseExp = !calculationColumn.isDerived() ? decryptIfNeeds(columnInfo, columnExp) : columnExp;
}
calcValueExp = filterNestedCalculation(baseExp, calculationColumn);
} else {
throwCalculationElementIllegalStateException(targetExp);
// unreachable
return null;
}
return targetExp + " " + calculationType.operand() + " " + calcValueExp;
}
Aggregations