use of org.dbflute.cbean.sqlclause.SqlClause in project dbflute-core by dbflute.
the class HpSpecifyColumnRequiredChecker method checkSpecifyColumnRequiredIfNeeds.
public void checkSpecifyColumnRequiredIfNeeds(ConditionBean cb, Consumer<Set<String>> thrower) {
// cannot embed this to SQL clause because of too complex
// so simple implementation like this:
final SqlClause sqlClause = cb.getSqlClause();
final String basePointAliasName = sqlClause.getBasePointAliasName();
final Set<String> nonSpecifiedAliasSet = new LinkedHashSet<>();
if (!sqlClause.hasSpecifiedSelectColumn(basePointAliasName)) {
// local table without SpecifyColumn
nonSpecifiedAliasSet.add(cb.asDBMeta().getTableDispName() + " (" + basePointAliasName + ")");
}
for (Entry<String, Map<String, SelectedRelationColumn>> entry : sqlClause.getSelectedRelationColumnMap().entrySet()) {
final String tableAliasName = entry.getKey();
if (!sqlClause.hasSpecifiedSelectColumn(tableAliasName)) {
// relation table without SpecifyColumn
final Collection<SelectedRelationColumn> values = entry.getValue().values();
final String dispName;
if (!values.isEmpty()) {
final SelectedRelationColumn firstColumn = values.iterator().next();
dispName = sqlClause.translateSelectedRelationPathToPropName(firstColumn.getRelationNoSuffix());
} else {
// no way, just in case
dispName = "*no name";
}
nonSpecifiedAliasSet.add(dispName + " (" + tableAliasName + ")");
}
}
if (!nonSpecifiedAliasSet.isEmpty()) {
thrower.accept(nonSpecifiedAliasSet);
}
}
use of org.dbflute.cbean.sqlclause.SqlClause in project dbflute-core by dbflute.
the class ScalarCondition method buildSubQueryClause.
protected String buildSubQueryClause(String function, ScalarConditionOption option) {
// release ScalarCondition for compound PK
// (compound PK restricted until 1.0.5G without special reason)
// if (!_subQueryDBMeta.hasPrimaryKey() || _subQueryDBMeta.hasCompoundPrimaryKey()) {
// String msg = "The scalar-condition is unsupported when no primary key or compound primary key:";
// msg = msg + " table=" + _subQueryDBMeta.getTableDbName();
// throw new IllegalConditionBeanOperationException(msg);
// }
final String tableAliasName = getSubQueryLocalAliasName();
final String derivedColumnDbName = _subQuerySqlClause.getSpecifiedColumnDbNameAsOne();
if (derivedColumnDbName == null) {
throwScalarConditionInvalidColumnSpecificationException(function);
}
final ColumnSqlName derivedColumnSqlName = getDerivedColumnSqlName();
final ColumnRealName derivedColumnRealName = getDerivedColumnRealName();
assertScalarConditionColumnType(function, derivedColumnDbName);
ColumnRealName partitionByCorrelatedColumnRealName = null;
ColumnSqlName partitionByRelatedColumnSqlName = null;
final SqlClause partitionBySqlClause = _partitionByProvider.provideSqlClause();
if (partitionBySqlClause != null) {
final String partitionByColumnDbName = partitionBySqlClause.getSpecifiedColumnDbNameAsOne();
if (partitionByColumnDbName == null) {
// means empty specify or duplicate specify
throwScalarConditionPartitionByInvalidColumnSpecificationException(function);
}
partitionByCorrelatedColumnRealName = _localRealNameProvider.provide(partitionByColumnDbName);
partitionByRelatedColumnSqlName = _subQuerySqlNameProvider.provide(partitionByColumnDbName);
}
final String subQueryClause;
if (_subQuerySqlClause.hasUnionQuery()) {
subQueryClause = buildUnionSubQuerySql(function, tableAliasName, derivedColumnSqlName, derivedColumnRealName, partitionByCorrelatedColumnRealName, partitionByRelatedColumnSqlName, option);
} else {
final String selectClause = "select " + buildFunctionPart(function, derivedColumnRealName, option, false);
final String fromWhereClause = buildFromWhereClause(selectClause, tableAliasName, partitionByCorrelatedColumnRealName, partitionByRelatedColumnSqlName);
subQueryClause = selectClause + " " + fromWhereClause;
}
return resolveSubQueryLevelVariable(subQueryClause);
}
use of org.dbflute.cbean.sqlclause.SqlClause in project dbflute-core by dbflute.
the class TnRowCreatorExtension method adjustCreatedRow.
// ===================================================================================
// Fix Row
// =======
/**
* Adjust created row. (clearing modified info, ...)
* @param row The row of result list. (NotNull)
* @param checkNonSp Does is use the check of access to non-specified column?
* @param colNullObj Does is use the handling of column null object?
* @param basePointBmd The bean meta data of the row for base-point table. (NotNull)
* @param cb The condition-bean for the select. (NullAllowed: when not condition-bean select)
*/
public static void adjustCreatedRow(final Object row, boolean checkNonSp, boolean colNullObj, TnBeanMetaData basePointBmd, ConditionBean cb) {
// _/_/_/_/_/_/_/_/_/_/
if (row instanceof Entity) {
final Entity entity = (Entity) row;
// _/_/_/_/_/_/_/_/_/_/
if (checkNonSp) {
// contains enabled by CB and using SpecifyColumn
entity.modifiedToSpecified();
// _/_/_/_/_/_/_/_/_/_/
if (colNullObj && cb != null) {
// check 'cb' just in case
final SqlClause sqlClause = cb.getSqlClause();
for (ColumnInfo columnInfo : sqlClause.getLocalSpecifiedNullObjectColumnSet()) {
entity.myspecifyProperty(columnInfo.getPropertyName());
}
}
}
// only table that has null object target column is object-able (generated as it)
if (colNullObj && entity instanceof ColumnNullObjectable) {
((ColumnNullObjectable) entity).enableColumnNullObject();
}
// clear modified properties for update process using selected entity
entity.clearModifiedInfo();
// mark as select to determine the entity is selected or user-created
// basically for e.g. determine columns of batch insert
entity.markAsSelect();
} else {
// not DBFlute entity
// actually any bean meta data can be accepted
// because only it gets modified properties
basePointBmd.getModifiedPropertyNames(row).clear();
}
}
use of org.dbflute.cbean.sqlclause.SqlClause in project dbflute-core by dbflute.
the class TnRowCreatorExtension method processDerivedMap.
protected void processDerivedMap(ResultSet rs, Map<String, Map<String, Integer>> selectIndexMap, Map<String, TnPropertyMapping> propertyCache, Object row) throws SQLException {
final ConditionBean cb = ConditionBeanContext.getConditionBeanOnThread();
final SqlClause sqlClause = cb.getSqlClause();
if (!sqlClause.hasSpecifiedDerivingSubQuery()) {
return;
}
final DerivedMappable mappable = (DerivedMappable) row;
final List<String> derivingAliasList = sqlClause.getSpecifiedDerivingAliasList();
DerivedTypeHandler typeHandler = null;
for (String derivingAlias : derivingAliasList) {
// propertyCache has alias name when derived-referrer as case-insensitive
if (propertyCache.containsKey(derivingAlias)) {
// already handled
continue;
}
if (!derivingAlias.startsWith(DERIVED_MAPPABLE_ALIAS_PREFIX)) {
// might be exception but no need to be strict here
continue;
}
if (typeHandler == null) {
// basically fixed instance returned
typeHandler = cb.xgetDerivedTypeHandler();
if (typeHandler == null) {
// no way, just in case
String msg = "Not found the type handler from condition-bean: " + cb.asTableDbName();
throw new IllegalStateException(msg);
}
}
final HpDerivingSubQueryInfo derivingInfo = sqlClause.getSpecifiedDerivingInfo(derivingAlias);
final ValueType valueType = TnValueTypes.getValueType(typeHandler.findMappingType(derivingInfo));
final String onQueryAlias = Srl.substringFirstRear(derivingAlias, DERIVED_MAPPABLE_ALIAS_PREFIX);
Object selectedValue = getValue(rs, onQueryAlias, valueType, selectIndexMap);
selectedValue = typeHandler.convertToMapValue(derivingInfo, selectedValue);
mappable.registerDerivedValue(derivingAlias, selectedValue);
}
}
use of org.dbflute.cbean.sqlclause.SqlClause in project dbflute-core by dbflute.
the class TnBeanListResultSetHandler method createRelationSelector.
/**
* Create the selector of relation.
* @param hasCB Does the select use condition-bean?
* @param cb The condition-bean for the select. (NullAllowed: not condition-bean select)
* @return The created selector instance. (NotNull)
*/
protected TnRelationSelector createRelationSelector(final boolean hasCB, ConditionBean cb) {
final boolean undefClsSel = isUndefinedClassificationSelectAllowed(hasCB, cb);
final boolean colNullObj = isUseColumnNullObjectHandling(hasCB, cb);
return new TnRelationSelector() {
public boolean isNonLimitMapping() {
return hasCB;
}
public boolean isNonSelectedRelation(String relationNoSuffix) {
return hasCB && !cb.getSqlClause().hasSelectedRelation(relationNoSuffix);
}
public boolean isNonSelectedNextConnectingRelation(String relationNoSuffix) {
return hasCB && !cb.getSqlClause().isSelectedNextConnectingRelation(relationNoSuffix);
}
public boolean canUseRelationCache(String relationNoSuffix) {
return hasCB && cb.getSqlClause().canUseRelationCache(relationNoSuffix);
}
public boolean isNonSpecifiedColumnAccessAllowed(String relationNoSuffix) {
return hasCB && cb.isNonSpecifiedColumnAccessAllowed();
}
public boolean isUsingSpecifyColumnInRelation(String relationNoSuffix) {
if (!hasCB) {
return false;
}
final SqlClause sqlClause = cb.getSqlClause();
final String tableAlias = sqlClause.translateSelectedRelationPathToTableAlias(relationNoSuffix);
if (tableAlias == null) {
// no way but just in case
return false;
}
return sqlClause.hasSpecifiedSelectColumn(tableAlias);
}
public Set<ColumnInfo> getRelationSpecifiedNullObjectColumnSet(String relationNoSuffix) {
if (!hasCB) {
return DfCollectionUtil.emptySet();
}
return cb.getSqlClause().getRelationSpecifiedNullObjectColumnSet(relationNoSuffix);
}
public boolean isUndefinedClassificationSelectAllowed(String relationNoSuffix) {
return undefClsSel;
}
public boolean isColumnNullObjectEnabled(String relationNoSuffix) {
return colNullObj;
}
};
}
Aggregations