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;
}
};
}
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);
}
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);
}
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);
}
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();
}
Aggregations