use of org.dbflute.dbmeta.info.ColumnInfo in project dbflute-core by dbflute.
the class AbstractConditionQuery method xcreateManualOrderSpecifiedColumn.
protected SpecifiedColumn xcreateManualOrderSpecifiedColumn(ConditionBean dreamCruiseCB) {
final OrderByElement orderByLastElement = xgetSqlClause().getOrderByLastElement();
final String aliasName = orderByLastElement.getAliasName();
final String columnName = orderByLastElement.getColumnName();
final ColumnInfo columnInfo = orderByLastElement.getColumnInfo();
final boolean derived = orderByLastElement.isDerivedOrderBy();
return new SpecifiedColumn(aliasName, columnInfo, dreamCruiseCB, columnName, derived);
}
use of org.dbflute.dbmeta.info.ColumnInfo 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.dbmeta.info.ColumnInfo in project dbflute-core by dbflute.
the class HpCalcSpecification method prepareConvOption.
protected void prepareConvOption(ColumnConversionOption option, boolean removeCalcAlias) {
if (removeCalcAlias) {
option.xremoveCalcAlias();
}
option.xjudgeDatabase(_baseCB.getSqlClause());
if (option.xgetTargetColumnInfo() == null) {
// might be already set (e.g. HpSpecifiedColumn's convert(), see the comment)
// DreamCruise specifies several columns so cannot get here so checked
final ColumnInfo columnInfo = getResolvedSpecifiedColumnInfo();
// can be set if specified once
option.xsetTargetColumnInfo(columnInfo);
}
if (_mysticBindingSnapshot != null && option.xgetMysticBindingSnapshot() == null) {
// can be set if specified once
option.xsetMysticBindingSnapshot(_mysticBindingSnapshot);
}
_baseCB.localCQ().xregisterParameterOption(option);
}
use of org.dbflute.dbmeta.info.ColumnInfo in project dbflute-core by dbflute.
the class UpdateOption method xcheckSpecifiedUpdateColumnPrimaryKey.
// -----------------------------------------------------
// Update Process
// --------------
public void xcheckSpecifiedUpdateColumnPrimaryKey() {
// checked later by process if it needs
if (_updateColumnSpecification == null) {
return;
}
assertUpdateColumnSpecifiedCB();
final CB cb = _updateColumnSpecifiedCB;
final String basePointAliasName = cb.getSqlClause().getBasePointAliasName();
final DBMeta dbmeta = cb.asDBMeta();
if (dbmeta.hasPrimaryKey()) {
final PrimaryInfo pkInfo = dbmeta.getPrimaryInfo();
final List<ColumnInfo> pkList = pkInfo.getPrimaryColumnList();
for (ColumnInfo pk : pkList) {
final String columnDbName = pk.getColumnDbName();
if (cb.getSqlClause().hasSpecifiedSelectColumn(basePointAliasName, columnDbName)) {
String msg = "PK columns should not be allowed to specify as update columns: " + columnDbName;
throw new SpecifyUpdateColumnInvalidException(msg);
}
}
}
}
use of org.dbflute.dbmeta.info.ColumnInfo in project dbflute-core by dbflute.
the class UpdateOption method xacceptUpdateColumnModifiedPropertiesIfNeeds.
// -----------------------------------------------------
// Modified Properties
// -------------------
// for BatchUpdate
public void xacceptUpdateColumnModifiedPropertiesIfNeeds(List<? extends Entity> entityList) {
// internal
if (entityList == null) {
throw new IllegalArgumentException("The argument 'entityList' should not be null.");
}
if (_updateColumnSpecification != null) {
// already specified
return;
}
if (entityList.isEmpty()) {
// do nothing
return;
}
if (xisCompatibleBatchUpdateDefaultEveryColumn()) {
// every column for compatible
return;
}
final Entity firstEntity = entityList.get(0);
final Set<String> targetProps = xgatherUpdateColumnModifiedProperties(entityList, firstEntity);
final DBMeta dbmeta = firstEntity.asDBMeta();
specify(new SpecifyQuery<CB>() {
public void specify(CB cb) {
// you don't need to specify primary key because primary key has special handling
for (String prop : targetProps) {
final ColumnInfo info = dbmeta.findColumnInfo(prop);
if (!info.isPrimary()) {
// except PK
cb.localSp().xspecifyColumn(info.getColumnDbName());
}
}
}
});
}
Aggregations