use of org.dbflute.dbmeta.name.ColumnSqlName in project dbflute-core by dbflute.
the class DerivedReferrer method buildUnionMainPartClause.
protected String buildUnionMainPartClause(ColumnSqlName relatedColumnSqlName, String tableAliasName, ColumnRealName derivedColumnRealName, ColumnSqlName derivedColumnSqlName, String correlatedFixedCondition) {
// derivedColumnSqlName : e.g. PURCHASE_PRICE
// derivedRealSqlName : might be sub-query
final ColumnSqlName derivedRealSqlName = derivedColumnRealName.getColumnSqlName();
final StringBuilder keySb = new StringBuilder();
if (isFixedCondition(correlatedFixedCondition)) {
setupUnionMainForFixedCondition(keySb, tableAliasName, derivedColumnSqlName);
} else {
// no fixed condition, mainly here
final List<ColumnInfo> pkList = _subQueryDBMeta.getPrimaryInfo().getPrimaryColumnList();
for (ColumnInfo pk : pkList) {
final ColumnSqlName pkSqlName = pk.getColumnSqlName();
if (pkSqlName.equals(derivedRealSqlName) || pkSqlName.equals(relatedColumnSqlName)) {
// to suppress same columns selected
continue;
}
keySb.append(keySb.length() > 0 ? ", " : "");
keySb.append(ColumnRealName.create(tableAliasName, pk.getColumnSqlName()));
}
if (!relatedColumnSqlName.equals(derivedRealSqlName)) {
// to suppress same columns selected
keySb.append(keySb.length() > 0 ? ", " : "");
keySb.append(ColumnRealName.create(tableAliasName, relatedColumnSqlName));
}
}
setupUnionMainForDerivedColumn(keySb, derivedColumnRealName, derivedColumnSqlName, derivedRealSqlName);
return completeUnionMainWholeClause(tableAliasName, keySb);
}
use of org.dbflute.dbmeta.name.ColumnSqlName in project dbflute-core by dbflute.
the class DerivedReferrer method buildSubQueryClause.
// ===================================================================================
// (Single PrimaryKey) SubQuery Clause
// ===================================
/**
* Build the clause of sub-query by single primary key.
* @param function The expression for deriving function. (NotNull)
* @param correlatedColumnRealName The real names of correlated column that is main-query table's column. (NotNull)
* @param relatedColumnSqlName The real names of related column that is sub-query table's column. (NotNull)
* @param correlatedFixedCondition The fixed condition as correlated condition. (NullAllowed)
* @param option The option of DerivedReferrer. (NotNull)
* @return The clause of sub-query. (NotNull)
*/
protected String buildSubQueryClause(String function, ColumnRealName correlatedColumnRealName, ColumnSqlName relatedColumnSqlName, String correlatedFixedCondition, DerivedReferrerOption option) {
final String tableAliasName = getSubQueryLocalAliasName();
final ColumnSqlName derivedColumnSqlName = getDerivedColumnSqlName();
if (derivedColumnSqlName == null) {
throwDerivedReferrerInvalidColumnSpecificationException(function);
}
final ColumnRealName derivedColumnRealName = getDerivedColumnRealName();
final String subQueryClause;
if (_subQuerySqlClause.hasUnionQuery()) {
subQueryClause = buildUnionSubQueryClause(function, correlatedColumnRealName, relatedColumnSqlName, option, tableAliasName, derivedColumnRealName, derivedColumnSqlName, correlatedFixedCondition);
} else {
final String selectClause = "select " + buildFunctionPart(function, derivedColumnRealName, option, false);
final String fromWhereClause;
if (option.isSuppressCorrelation()) {
// e.g. myselfDerived
fromWhereClause = buildPlainFromWhereClause(selectClause, tableAliasName, correlatedFixedCondition);
} else {
// basically here
fromWhereClause = buildCorrelationFromWhereClause(selectClause, tableAliasName, correlatedColumnRealName, relatedColumnSqlName, correlatedFixedCondition);
}
subQueryClause = selectClause + " " + fromWhereClause;
}
return resolveSubQueryLevelVariable(subQueryClause);
}
use of org.dbflute.dbmeta.name.ColumnSqlName in project dbflute-core by dbflute.
the class DerivedReferrer method buildUnionMainPartClause.
protected String buildUnionMainPartClause(ColumnRealName[] correlatedColumnRealNames, ColumnSqlName[] relatedColumnSqlNames, String tableAliasName, ColumnRealName derivedColumnRealName, ColumnSqlName derivedColumnSqlName, String correlatedFixedCondition) {
// similar to simple primary key so refer it
final StringBuilder keySb = new StringBuilder();
final ColumnSqlName derivedRealSqlName = derivedColumnRealName.getColumnSqlName();
if (isFixedCondition(correlatedFixedCondition)) {
setupUnionMainForFixedCondition(keySb, tableAliasName, derivedColumnSqlName);
} else {
// no fixed condition, mainly here
final Set<ColumnSqlName> relatedColumnSqlSet = new HashSet<ColumnSqlName>();
for (ColumnSqlName columnSqlName : relatedColumnSqlNames) {
relatedColumnSqlSet.add(columnSqlName);
}
final ColumnSqlName derivedSqlName = derivedRealSqlName;
final List<ColumnInfo> pkList = _subQueryDBMeta.getPrimaryInfo().getPrimaryColumnList();
for (ColumnInfo pk : pkList) {
final ColumnSqlName pkSqlName = pk.getColumnSqlName();
if (pkSqlName.equals(derivedSqlName) || relatedColumnSqlSet.contains(pkSqlName)) {
// to suppress same columns selected
continue;
}
keySb.append(keySb.length() > 0 ? ", " : "");
keySb.append(ColumnRealName.create(tableAliasName, pk.getColumnSqlName()));
}
for (ColumnSqlName relatedSqlName : relatedColumnSqlNames) {
if (relatedSqlName.equals(derivedSqlName)) {
// to suppress same columns selected
continue;
}
keySb.append(keySb.length() > 0 ? ", " : "");
keySb.append(ColumnRealName.create(tableAliasName, relatedSqlName));
}
}
setupUnionMainForDerivedColumn(keySb, derivedColumnRealName, derivedColumnSqlName, derivedRealSqlName);
return completeUnionMainWholeClause(tableAliasName, keySb);
}
use of org.dbflute.dbmeta.name.ColumnSqlName in project dbflute-core by dbflute.
the class SqlClauseOracle method lockForUpdate.
// ===================================================================================
// Lock Override
// =============
/**
* {@inheritDoc}
*/
public void lockForUpdate() {
final DBMeta dbmeta = findDBMeta(_tableDbName);
final String basePointAliasName = getBasePointAliasName();
if (dbmeta.hasPrimaryKey()) {
final ColumnSqlName primaryKeyName = dbmeta.getPrimaryInfo().getFirstColumn().getColumnSqlName();
_lockSqlSuffix = " for update of " + basePointAliasName + "." + primaryKeyName;
} else {
final ColumnSqlName randomColumnName = ((ColumnInfo) dbmeta.getColumnInfoList().get(0)).getColumnSqlName();
_lockSqlSuffix = " for update of " + basePointAliasName + "." + randomColumnName;
}
}
use of org.dbflute.dbmeta.name.ColumnSqlName in project dbflute-core by dbflute.
the class TnQueryUpdateDynamicCommand method buildQueryUpdateTwoWaySql.
// ===================================================================================
// Build SQL
// =========
/**
* @param entity The entity for update. (NotNull)
* @param cb The condition-beanĀ for query. (NotNull)
* @param option The option of update. (NullAllowed)
* @param boundPropTypeList The type list of bound property. (NotNull, AlwaysEmpty)
* @return The two-way SQL of query update. (NullAllowed: if non-modification, return null)
*/
protected String buildQueryUpdateTwoWaySql(Entity entity, ConditionBean cb, final UpdateOption<ConditionBean> option, List<TnPropertyType> boundPropTypeList) {
final Map<String, Object> columnParameterMap = new LinkedHashMap<String, Object>();
final DBMeta dbmeta = entity.asDBMeta();
final Set<String> modifiedSet = entity.mymodifiedProperties();
final List<ColumnInfo> columnInfoList = dbmeta.getColumnInfoList();
for (final ColumnInfo columnInfo : columnInfoList) {
if (columnInfo.isOptimisticLock()) {
// exclusive control columns are processed after here
continue;
}
final String columnDbName = columnInfo.getColumnDbName();
if (option != null && option.hasStatement(columnDbName)) {
// prior to specified
columnParameterMap.put(columnDbName, new SqlClause.QueryUpdateSetCalculationHandler() {
public String buildStatement(String aliasName) {
return option.buildStatement(columnDbName, aliasName);
}
});
continue;
}
if (isSpecifiedProperty(option, modifiedSet, columnInfo)) {
final String propertyName = columnInfo.getPropertyName();
final Object value = columnInfo.read(entity);
if (value != null) {
columnParameterMap.put(columnDbName, "/*entity." + propertyName + "*/null");
// add bound property type
final TnPropertyType propertyType = _beanMetaData.getPropertyType(propertyName);
boundPropTypeList.add(propertyType);
} else {
// it uses null literal on query
// because the SQL analyzer blocks null parameters
// (the analyzer should do it for condition-bean)
columnParameterMap.put(columnDbName, "null");
}
continue;
}
}
if (columnParameterMap.isEmpty()) {
return null;
}
if (dbmeta.hasVersionNo()) {
final ColumnInfo columnInfo = dbmeta.getVersionNoColumnInfo();
final String columnDbName = columnInfo.getColumnDbName();
columnParameterMap.put(columnDbName, new SqlClause.QueryUpdateSetCalculationHandler() {
public String buildStatement(String aliasName) {
// cipher for versionNo is unsupported
final ColumnSqlName columnSqlName = columnInfo.getColumnSqlName();
return (aliasName != null ? aliasName : "") + columnSqlName + " + 1";
}
});
}
if (dbmeta.hasUpdateDate()) {
ColumnInfo columnInfo = dbmeta.getUpdateDateColumnInfo();
columnInfo.write(entity, ResourceContext.getAccessTimestamp());
final String columnDbName = columnInfo.getColumnDbName();
final String propertyName = columnInfo.getPropertyName();
columnParameterMap.put(columnDbName, "/*entity." + propertyName + "*/null");
// add bound property type
boundPropTypeList.add(_beanMetaData.getPropertyType(propertyName));
}
if (option != null && option.isQueryUpdateForcedDirectAllowed()) {
cb.getSqlClause().enableQueryUpdateForcedDirect();
}
return cb.getSqlClause().getClauseQueryUpdate(columnParameterMap);
}
Aggregations