use of org.dbflute.cbean.dream.SpecifiedColumn in project dbflute-core by dbflute.
the class HpCalcSpecification method getResolvedSpecifiedTableAliasName.
// -----------------------------------------------------
// Table Alias
// -----------
public String getResolvedSpecifiedTableAliasName() {
// resolved plain or deriving sub-query
checkSpecifiedCB();
if (_specifedCB.xhasDreamCruiseTicket()) {
final SpecifiedColumn ticket = _specifedCB.xshowDreamCruiseTicket();
return ticket.getTableAliasName();
}
final ColumnRealName columnRealName = _specifedCB.getSqlClause().getSpecifiedColumnRealNameAsOne();
if (columnRealName != null) {
return columnRealName.getTableAliasName();
}
return _specifedCB.getSqlClause().getSpecifiedDerivingAliasNameAsOne();
}
use of org.dbflute.cbean.dream.SpecifiedColumn 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;
}
use of org.dbflute.cbean.dream.SpecifiedColumn in project dbflute-core by dbflute.
the class UpdateOption method doBuildStatement.
protected String doBuildStatement(String columnDbName, String aliasName) {
final HpCalcSpecification<CB> calcSp = findStatementSpecification(columnDbName);
if (calcSp == null) {
return null;
}
final SpecifiedColumn specifiedColumn = calcSp.getResolvedSpecifiedColumn();
if (specifiedColumn != null && specifiedColumn.hasSpecifyCalculation()) {
throwVaryingUpdateSpecifyCalculatonUnsupportedException(columnDbName);
}
final String statement = calcSp.buildStatementAsSqlName(aliasName);
if (statement == null) {
// means non-calculation
throwVaryingUpdateNotFoundCalculationException(columnDbName);
}
return statement;
}
use of org.dbflute.cbean.dream.SpecifiedColumn in project dbflute-core by dbflute.
the class AbstractConditionBean method inviteDerivedToDreamCruise.
/**
* {@inheritDoc}
*/
public SpecifiedColumn inviteDerivedToDreamCruise(String derivedAlias) {
if (!xisDreamCruiseShip()) {
String msg = "This invitation is only allowed by Dream Cruise Ship: " + derivedAlias;
throw new IllegalConditionBeanOperationException(msg);
}
final SqlClause portClause = xgetDreamCruiseDeparturePort().getSqlClause();
if (!portClause.hasSpecifiedDerivingSubQuery(derivedAlias)) {
String msg = "Not found the derived info by the argument 'derivedAlias': " + derivedAlias;
throw new IllegalArgumentException(msg);
}
final ColumnInfo columnInfo = portClause.getSpecifiedDerivingColumnInfo(derivedAlias);
if (columnInfo == null) {
String msg = "Not found the derived column by the argument 'derivedAlias': " + derivedAlias;
throw new IllegalArgumentException(msg);
}
return new SpecifiedColumn(null, columnInfo, this, derivedAlias, true);
}
use of org.dbflute.cbean.dream.SpecifiedColumn in project dbflute-core by dbflute.
the class AbstractConditionBean method invokeSpecifyColumn.
/**
* {@inheritDoc}
*/
public SpecifiedColumn invokeSpecifyColumn(String columnPropertyPath) {
final String delimiter = ".";
Object currentObj = localSp();
String remainder = columnPropertyPath;
boolean last = false;
while (true) {
final int deimiterIndex = remainder.indexOf(delimiter);
final String propertyName;
if (deimiterIndex < 0) {
// hard to get relation DB meta so plain name
propertyName = remainder;
last = true;
} else {
propertyName = remainder.substring(0, deimiterIndex);
remainder = remainder.substring(deimiterIndex + delimiter.length(), remainder.length());
}
final Class<?> targetType = currentObj.getClass();
final String methodName = (last ? "column" : "specify") + initCap(propertyName);
final Method method = xhelpGettingCBChainMethod(targetType, methodName, (Class<?>[]) null);
if (method == null) {
String msg = "Not found the method for SpecifyColumn:";
msg = msg + " columnPropertyPath=" + columnPropertyPath + " targetType=" + targetType + " methodName=" + methodName;
throw new ConditionInvokingFailureException(msg);
}
try {
currentObj = DfReflectionUtil.invoke(method, currentObj, (Object[]) null);
} catch (ReflectionFailureException e) {
String msg = "Failed to invoke the method:";
msg = msg + " columnPropertyPath=" + columnPropertyPath + " targetType=" + targetType + " methodName=" + methodName;
throw new ConditionInvokingFailureException(msg, e);
}
if (last) {
break;
}
}
return (SpecifiedColumn) currentObj;
}
Aggregations