Search in sources :

Example 6 with ConditionBean

use of org.dbflute.cbean.ConditionBean in project dbflute-core by dbflute.

the class AbstractBehaviorReadable method xcreateLoadReferrerCallback.

protected <// generic
LOCAL_ENTITY extends Entity, // generic
KEY, // generic
REFERRER_CB extends ConditionBean, // generic
REFERRER_ENTITY extends Entity> // return
InternalLoadReferrerCallback<LOCAL_ENTITY, KEY, REFERRER_CB, REFERRER_ENTITY> xcreateLoadReferrerCallback(final String referrerProperty, final DBMeta dbmeta, final ReferrerInfo referrerInfo, final BehaviorReadable referrerBhv, final Set<ColumnInfo> pkColSet, final Set<ColumnInfo> fkColSet, final Map<ColumnInfo, ColumnInfo> mappingColMap) {
    return new // for compound key
    InternalLoadReferrerCallback<LOCAL_ENTITY, KEY, REFERRER_CB, REFERRER_ENTITY>() {

        @SuppressWarnings("unchecked")
        public KEY getPKVal(LOCAL_ENTITY entity) {
            final Map<String, Object> keyMap = xnewLoadReferrerCompoundKeyMap();
            for (ColumnInfo pkCol : pkColSet) {
                // key is DB name
                keyMap.put(pkCol.getColumnDbName(), pkCol.read(entity));
            }
            return (KEY) keyMap;
        // cannot use because it might be unique key
        // return (KEY) dbmeta.extractPrimaryKeyMap(entity);
        }

        public void setRfLs(LOCAL_ENTITY entity, List<REFERRER_ENTITY> referrerList) {
            referrerInfo.write(entity, referrerList);
        }

        @SuppressWarnings("unchecked")
        public REFERRER_CB newMyCB() {
            return (REFERRER_CB) referrerBhv.newConditionBean();
        }

        public void qyFKIn(REFERRER_CB cb, final Collection<KEY> pkList) {
            // compound key doesn't use InScope so OrScopeQuery
            cb.invokeOrScopeQuery(new OrQuery<ConditionBean>() {

                public void query(ConditionBean orCB) {
                    for (final KEY pkKey : pkList) {
                        @SuppressWarnings("unchecked") final Map<String, Object> pkMap = (Map<String, Object>) pkKey;
                        orCB.invokeOrScopeQueryAndPart(new AndQuery<ConditionBean>() {

                            public void query(ConditionBean andCB) {
                                for (ColumnInfo fkCol : fkColSet) {
                                    final ColumnInfo pkCol = mappingColMap.get(fkCol);
                                    // key is DB name
                                    final Object pkValue = pkMap.get(pkCol.getColumnDbName());
                                    andCB.localCQ().invokeQueryEqual(fkCol.getColumnDbName(), pkValue);
                                }
                            }
                        });
                    }
                }
            });
        }

        public void qyOdFKAsc(REFERRER_CB cb) {
            for (ColumnInfo fkCol : fkColSet) {
                cb.localCQ().invokeOrderBy(fkCol.getColumnDbName(), true);
            }
        }

        public void spFKCol(REFERRER_CB cb) {
            for (ColumnInfo fkCol : fkColSet) {
                cb.localSp().xspecifyColumn(fkCol.getColumnDbName());
            }
        }

        public List<REFERRER_ENTITY> selRfLs(REFERRER_CB cb) {
            return referrerBhv.readList(cb);
        }

        @SuppressWarnings("unchecked")
        public KEY getFKVal(REFERRER_ENTITY entity) {
            final Map<String, Object> fkMap = xnewLoadReferrerCompoundKeyMap();
            for (ColumnInfo fkCol : fkColSet) {
                final Object fkValue = fkCol.read(entity);
                final ColumnInfo pkCol = mappingColMap.get(fkCol);
                // key is DB name
                final String mapKey = pkCol.getColumnDbName();
                final Class<?> fkType = fkCol.getObjectNativeType();
                final Class<?> pkType = pkCol.getObjectNativeType();
                final Object realValue;
                if (fkType.equals(pkType)) {
                    // basically true
                    realValue = fkValue;
                } else {
                    // different type (needs implicit conversion)
                    realValue = xconvertFK2PKImplicitly(referrerProperty, fkType, pkType, fkValue);
                }
                fkMap.put(mapKey, realValue);
            }
            return (KEY) fkMap;
        }

        public void setlcEt(REFERRER_ENTITY referrerEntity, LOCAL_ENTITY localEntity) {
            // always exists
            final RelationInfo reverseInfo = referrerInfo.getReverseRelation();
            final Object written = xconvertToRelationOptionalEntityIfNeeds(localEntity, reverseInfo);
            reverseInfo.write(referrerEntity, written);
        }

        public String getRfPrNm() {
            return referrerProperty;
        }
    };
}
Also used : ColumnInfo(org.dbflute.dbmeta.info.ColumnInfo) ConditionBean(org.dbflute.cbean.ConditionBean) RelationInfo(org.dbflute.dbmeta.info.RelationInfo) Collection(java.util.Collection) List(java.util.List) ArrayList(java.util.ArrayList) AndQuery(org.dbflute.cbean.scoping.AndQuery) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap)

Example 7 with ConditionBean

use of org.dbflute.cbean.ConditionBean in project dbflute-core by dbflute.

the class SelectCBExecution method execute.

// ===================================================================================
// Resource
// ========
@Override
public Object execute(Object[] args) {
    final ConditionBean cb = extractConditionBean(args);
    final Object splitResult = processPagingSelectAndQuerySplit(args, cb);
    if (splitResult != null) {
        // rarely
        return splitResult;
    }
    // basically here
    return superExecute(args);
}
Also used : ConditionBean(org.dbflute.cbean.ConditionBean)

Example 8 with ConditionBean

use of org.dbflute.cbean.ConditionBean in project dbflute-core by dbflute.

the class AbstractQueryUpdateCommand method beforeGettingSqlExecution.

// ===================================================================================
// Process Callback
// ================
@Override
public void beforeGettingSqlExecution() {
    assertStatus("beforeGettingSqlExecution");
    final ConditionBean cb = _conditionBean;
    ConditionBeanContext.setConditionBeanOnThread(cb);
}
Also used : ConditionBean(org.dbflute.cbean.ConditionBean)

Example 9 with ConditionBean

use of org.dbflute.cbean.ConditionBean in project dbflute-core by dbflute.

the class SelectCountCBCommand method beforeGettingSqlExecution.

// ===================================================================================
// Process Callback
// ================
public void beforeGettingSqlExecution() {
    assertStatus("beforeGettingSqlExecution");
    final ConditionBean cb = _conditionBean;
    // *Point!
    cb.xsetupSelectCountIgnoreFetchScope(_uniqueCount);
    ConditionBeanContext.setConditionBeanOnThread(cb);
}
Also used : ConditionBean(org.dbflute.cbean.ConditionBean)

Example 10 with ConditionBean

use of org.dbflute.cbean.ConditionBean in project dbflute-core by dbflute.

the class SelectScalarCBCommand method afterExecuting.

public void afterExecuting() {
    assertStatus("afterExecuting");
    final ConditionBean cb = _conditionBean;
    cb.getSqlClause().rollbackSelectClauseType();
}
Also used : ConditionBean(org.dbflute.cbean.ConditionBean)

Aggregations

ConditionBean (org.dbflute.cbean.ConditionBean)45 DeleteOption (org.dbflute.bhv.writable.DeleteOption)7 UpdateOption (org.dbflute.bhv.writable.UpdateOption)7 ArrayList (java.util.ArrayList)5 InsertOption (org.dbflute.bhv.writable.InsertOption)5 Entity (org.dbflute.Entity)4 ExceptionMessageBuilder (org.dbflute.helper.message.ExceptionMessageBuilder)4 List (java.util.List)3 AbstractBatchUpdateCommand (org.dbflute.bhv.core.command.AbstractBatchUpdateCommand)3 BatchDeleteCommand (org.dbflute.bhv.core.command.BatchDeleteCommand)3 BatchDeleteNonstrictCommand (org.dbflute.bhv.core.command.BatchDeleteNonstrictCommand)3 BatchInsertCommand (org.dbflute.bhv.core.command.BatchInsertCommand)3 BatchUpdateCommand (org.dbflute.bhv.core.command.BatchUpdateCommand)3 BatchUpdateNonstrictCommand (org.dbflute.bhv.core.command.BatchUpdateNonstrictCommand)3 DeleteEntityCommand (org.dbflute.bhv.core.command.DeleteEntityCommand)3 DeleteNonstrictEntityCommand (org.dbflute.bhv.core.command.DeleteNonstrictEntityCommand)3 InsertEntityCommand (org.dbflute.bhv.core.command.InsertEntityCommand)3 QueryDeleteCBCommand (org.dbflute.bhv.core.command.QueryDeleteCBCommand)3 QueryInsertCBCommand (org.dbflute.bhv.core.command.QueryInsertCBCommand)3 QueryUpdateCBCommand (org.dbflute.bhv.core.command.QueryUpdateCBCommand)3