use of org.dbflute.cbean.ConditionBean in project dbflute-core by dbflute.
the class HpAbstractSpecification method reflectDreamCruiseWhereUsedToJoin.
protected void reflectDreamCruiseWhereUsedToJoin(String relationPath, String tableAliasName) {
if (!_baseCB.xisDreamCruiseShip()) {
return;
}
// to suppress CountLeastJoin of the relation
// the DreamCruise might be used in where clause (not correctly but safety logic)
final ConditionBean portCB = _baseCB.xgetDreamCruiseDeparturePort();
final QueryUsedAliasInfo usedAliasInfo = new QueryUsedAliasInfo(tableAliasName, new InnerJoinNoWaySpeaker() {
public boolean isNoWayInner() {
// non fact of inner-join, because judge is so difficult when DreamCruise
return true;
}
});
portCB.getSqlClause().reflectWhereUsedToJoin(usedAliasInfo);
}
use of org.dbflute.cbean.ConditionBean in project dbflute-core by dbflute.
the class AbstractSqlClause method filterSpecifyColumnCalculation.
protected ColumnRealName filterSpecifyColumnCalculation(ColumnRealName specifiedRealName, SpecifiedColumn hpCol) {
if (hasSpecifyCalculation(hpCol)) {
hpCol.xinitSpecifyCalculation();
final HpCalcSpecification<ConditionBean> calcSpecification = hpCol.getSpecifyCalculation();
final String statement = calcSpecification.buildStatementToSpecifidName(specifiedRealName.toString());
return ColumnRealName.create(null, new ColumnSqlName(statement));
}
return specifiedRealName;
}
use of org.dbflute.cbean.ConditionBean in project dbflute-core by dbflute.
the class OrderByElement method setupManualOrderClause.
protected void setupManualOrderClause(StringBuilder sb, String columnAlias, Map<String, String> selectClauseRealColumnAliasMap) {
final String realAlias;
if (_manualOrderOption.hasOrderByCalculation()) {
final HpCalcSpecification<ConditionBean> calculationOrder = _manualOrderOption.getOrderByCalculation();
realAlias = calculationOrder.buildStatementToSpecifidName(columnAlias, selectClauseRealColumnAliasMap);
} else {
if (selectClauseRealColumnAliasMap != null) {
// means union
realAlias = columnAlias;
} else {
realAlias = decryptIfNeeds(_columnInfo, columnAlias);
}
}
final List<HpMobCaseWhenElement> caseWhenList = _manualOrderOption.getCaseWhenBoundList();
if (!caseWhenList.isEmpty()) {
sb.append(ln()).append(" case").append(ln());
int index = 0;
for (HpMobCaseWhenElement element : caseWhenList) {
sb.append(" when ");
doSetupManualOrderClause(sb, realAlias, element);
final List<HpMobCaseWhenElement> connectedElementList = element.getConnectedElementList();
for (HpMobCaseWhenElement connectedElement : connectedElementList) {
doSetupManualOrderClause(sb, realAlias, connectedElement);
}
final Object thenValue = element.getThenValue();
final String thenExp;
if (thenValue != null) {
thenExp = thenValue.toString();
} else {
thenExp = String.valueOf(index);
}
sb.append(" then ").append(thenExp).append(ln());
++index;
}
final Object elseValue = _manualOrderOption.getElseValue();
final String elseExp;
if (elseValue != null) {
elseExp = elseValue.toString();
} else {
elseExp = String.valueOf(index);
}
sb.append(" else ").append(elseExp).append(ln());
sb.append(" end");
} else {
sb.append(realAlias);
}
sb.append(" ").append(_ascDesc);
}
use of org.dbflute.cbean.ConditionBean in project dbflute-core by dbflute.
the class TnQueryInsertDynamicCommand method execute.
// ===================================================================================
// Execute
// =======
public Object execute(Object[] args) {
// analyze arguments
final Entity entity = extractEntityWithCheck(args);
final ConditionBean intoCB = extractIntoConditionBeanWithCheck(args);
final ConditionBean resourceCB = extractResourceConditionBeanWithCheck(args);
final InsertOption<ConditionBean> option = extractInsertOptionWithCheck(args);
prepareStatementConfigOnThreadIfExists(option);
// arguments for execution (not contains an option)
final String[] argNames = new String[] { "entity", "pmb" };
final Class<?>[] argTypes = new Class<?>[] { entity.getClass(), resourceCB.getClass() };
final Object[] realArgs = new Object[] { entity, resourceCB };
// prepare context
final List<TnPropertyType> boundPropTypeList = new ArrayList<TnPropertyType>();
final CommandContext context;
{
final String twoWaySql = buildQueryInsertTwoWaySql(entity, intoCB, resourceCB, option, boundPropTypeList);
context = createCommandContext(twoWaySql, argNames, argTypes, realArgs);
}
// execute
final TnCommandContextHandler handler = createCommandContextHandler(context);
handler.setExceptionMessageSqlArgs(context.getBindVariables());
final boolean identityDisabled = option != null && option.isPrimaryKeyIdentityDisabled();
if (identityDisabled) {
disableIdentityGeneration(entity);
}
final int rows;
RuntimeException sqlEx = null;
try {
rows = handler.execute(realArgs);
} catch (RuntimeException e) {
sqlEx = e;
throw e;
} finally {
if (identityDisabled) {
try {
enableIdentityGeneration(entity);
} catch (RuntimeException e) {
if (sqlEx == null) {
throw e;
}
// ignore the exception when main SQL fails
// not to close the main exception
}
}
}
return Integer.valueOf(rows);
}
use of org.dbflute.cbean.ConditionBean in project dbflute-core by dbflute.
the class TnBeanListResultSetHandler method mappingBean.
protected void mappingBean(ResultSet rs, BeanRowHandler handler) throws SQLException {
// lazy initialization because if the result is zero, the resources are unused
Map<String, String> selectColumnMap = null;
Map<String, TnPropertyMapping> propertyCache = null;
// key is relationNoSuffix, columnName
Map<String, Map<String, TnPropertyMapping>> relPropCache = null;
TnRelationRowCache relRowCache = null;
TnRelationSelector relSelector = null;
final TnBeanMetaData basePointBmd = getBeanMetaData();
// condition-bean info (variable for minimum thread local access)
final boolean hasCB = hasConditionBean();
final ConditionBean cb = hasCB ? getConditionBean() : null;
// outsideSql info (also variable for minimum thread local access)
final boolean hasOql = hasOutsideSqlContext();
final OutsideSqlContext oqlCtx = OutsideSqlContext.getOutsideSqlContextOnThread();
final boolean checkNonSp = checkNonSpecifiedColumnAccess(hasCB, cb, hasOql, oqlCtx);
final boolean colNullObj = isUseColumnNullObjectHandling(hasCB, cb);
final boolean skipRelationLoop;
{
final boolean emptyRelationCB = hasCB && isSelectedRelationEmpty(cb);
final boolean specifiedOutsideSql = hasOql && isSpecifiedOutsideSql(oqlCtx);
// if it has condition-bean that has no relation to get
// or it has outside SQL context that is specified outside-SQL,
// they are unnecessary to do relation loop
skipRelationLoop = emptyRelationCB || specifiedOutsideSql;
}
// null allowed
final Map<String, Map<String, Integer>> selectIndexMap = ResourceContext.getSelectIndexMap();
while (rs.next()) {
if (selectColumnMap == null) {
selectColumnMap = createSelectColumnMap(rs);
}
if (propertyCache == null) {
propertyCache = createPropertyCache(selectColumnMap, selectIndexMap);
}
// create row instance of base table by row property cache
final Object row = createRow(rs, selectIndexMap, propertyCache, cb);
if (skipRelationLoop) {
adjustCreatedRow(row, checkNonSp, colNullObj, basePointBmd, cb);
final boolean continueToNext = handler.handle(row);
if (!continueToNext) {
// skip rear records (basically for cursor select)
break;
}
continue;
}
if (relSelector == null) {
relSelector = createRelationSelector(hasCB, cb);
}
if (relPropCache == null) {
relPropCache = createRelationPropertyCache(selectColumnMap, selectIndexMap, relSelector);
}
if (relRowCache == null) {
relRowCache = createRelationRowCache(hasCB, cb);
}
final List<TnRelationPropertyType> rptList = basePointBmd.getRelationPropertyTypeList();
for (TnRelationPropertyType rpt : rptList) {
if (relSelector.isNonSelectedRelation(rpt.getRelationNoSuffixPart())) {
continue;
}
mappingFirstRelation(rs, row, rpt, selectColumnMap, selectIndexMap, relPropCache, relRowCache, relSelector);
}
adjustCreatedRow(row, checkNonSp, colNullObj, basePointBmd, cb);
final boolean continueToNext = handler.handle(row);
if (!continueToNext) {
// skip rear records (basically for cursor select)
break;
}
}
}
Aggregations