use of org.dbflute.dbmeta.DBMeta in project dbflute-core by dbflute.
the class BehaviorCommandInvoker method extractBehaviorInvoke.
// -----------------------------------------------------
// Extract BehaviorInvoke
// ----------------------
protected <RESULT> BehaviorInvokeNameResult extractBehaviorInvoke(BehaviorCommand<RESULT> behaviorCommand, StackTraceElement[] stackTrace) {
final DBMeta dbmeta = ResourceContext.provideDBMeta(behaviorCommand.getTableDbName());
if (dbmeta == null) {
// basically no way, only direct invoking
return createUnknownInvokeNameResult();
}
Class<?> outsideSqlResultType = null;
boolean outsideSqlAutoPaging = false;
if (behaviorCommand.isOutsideSql()) {
final OutsideSqlContext outsideSqlContext = getOutsideSqlContext();
outsideSqlResultType = outsideSqlContext.getResultType();
outsideSqlAutoPaging = outsideSqlContext.isAutoPagingLogging();
}
final BehaviorInvokeNameExtractor extractor = createBehaviorInvokeNameExtractor(dbmeta, outsideSqlResultType, outsideSqlAutoPaging);
return extractor.extractBehaviorInvoke(stackTrace);
}
use of org.dbflute.dbmeta.DBMeta in project dbflute-core by dbflute.
the class AbstractBehaviorReadable method helpPulloutInternally.
// ===================================================================================
// Pull out Relation
// =================
protected <LOCAL_ENTITY extends Entity, FOREIGN_ENTITY extends Entity> List<FOREIGN_ENTITY> helpPulloutInternally(List<LOCAL_ENTITY> localEntityList, String foreignPropertyName) {
assertObjectNotNull("localEntityList", localEntityList);
assertObjectNotNull("foreignPropertyName", foreignPropertyName);
final DBMeta dbmeta = asDBMeta();
final ForeignInfo foreignInfo = dbmeta.findForeignInfo(foreignPropertyName);
final RelationInfo reverseInfo = foreignInfo.getReverseRelation();
final boolean existsReferrer = reverseInfo != null;
final RelationOptionalFactory optionalFactory = xgetROpFactory();
final Map<Integer, FOREIGN_ENTITY> foreignBasicMap = new LinkedHashMap<Integer, FOREIGN_ENTITY>();
// lazy-loaded
Map<Integer, List<FOREIGN_ENTITY>> foreignCollisionMap = null;
final Map<FOREIGN_ENTITY, List<LOCAL_ENTITY>> foreignReferrerMap = new LinkedHashMap<FOREIGN_ENTITY, List<LOCAL_ENTITY>>();
for (LOCAL_ENTITY localEntity : localEntityList) {
final FOREIGN_ENTITY foreignEntity = xextractPulloutForeignEntity(foreignInfo, reverseInfo, optionalFactory, localEntity);
if (foreignEntity == null) {
continue;
}
// _/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
// basically mapped foreign entities are unique instances
// but according to circumstances, same PK different instance (rare case)
//
// e.g. normal pattern (no problem)
// A - M - X
// B - M - X
// C - N - X
// D - O - Y
//
// e.g. when OverRelation, might be following pattern
// A - M - X
// B - M - Y *same relation but different nested relation
// C - N - X
// D - O - Y
//
// when the latter pattern, the instance of A's M is different from the one of B's M
// so it need to handle the unique as instance (don't use overridden equals() of entity)
// _/_/_/_/_/_/_/_/_/_/
foreignCollisionMap = xsavePulloutForeignEntity(foreignBasicMap, foreignCollisionMap, foreignEntity);
if (existsReferrer) {
if (!foreignReferrerMap.containsKey(foreignEntity)) {
foreignReferrerMap.put(foreignEntity, new ArrayList<LOCAL_ENTITY>());
}
foreignReferrerMap.get(foreignEntity).add(localEntity);
}
}
if (existsReferrer) {
for (Entry<FOREIGN_ENTITY, List<LOCAL_ENTITY>> entry : foreignReferrerMap.entrySet()) {
final FOREIGN_ENTITY foreignEntity = entry.getKey();
final List<LOCAL_ENTITY> mappedLocalList = entry.getValue();
final Object writtenObj = xextractPulloutReverseWrittenObject(foreignInfo, reverseInfo, optionalFactory, mappedLocalList);
reverseInfo.write(foreignEntity, writtenObj);
}
}
return xpreparePulloutResultList(foreignBasicMap, foreignCollisionMap);
}
use of org.dbflute.dbmeta.DBMeta in project dbflute-core by dbflute.
the class AbstractBehaviorReadable method xbuildReferrerCorrelatedFixedCondition.
protected String xbuildReferrerCorrelatedFixedCondition(ConditionBean cb, String referrerPropertyName) {
if (referrerPropertyName == null) {
return null;
}
final DBMeta localDBMeta = asDBMeta();
if (!localDBMeta.hasReferrer(referrerPropertyName)) {
// one-to-one referrer
return null;
}
final ReferrerInfo referrerInfo = localDBMeta.findReferrerInfo(referrerPropertyName);
return xdoBuildReferrerCorrelatedFixedCondition(cb, referrerInfo);
}
use of org.dbflute.dbmeta.DBMeta in project dbflute-core by dbflute.
the class SelectNextValCommand method prepareSequenceCache.
protected String prepareSequenceCache(String sql, SequenceCache sequenceCache) {
final DBMeta dbmeta = _dbmeta;
final Integer incrementSize = dbmeta.getSequenceIncrementSize();
final Integer cacheSize = dbmeta.getSequenceCacheSize();
return doPrepareSequenceCache(sql, sequenceCache, incrementSize, cacheSize);
}
use of org.dbflute.dbmeta.DBMeta in project dbflute-core by dbflute.
the class SelectNextValCommand method createSelectNextValExecution.
protected SqlExecution createSelectNextValExecution(TnResultSetHandler handler) {
assertStatus("createSelectNextValExecution");
final DBMeta dbmeta = _dbmeta;
assertTableHasSequence();
// filtered later
String sql = getSequenceNextValSql();
assertSequenceReturnsNotNull(sql, dbmeta);
// handling for sequence cache
final SequenceCache sequenceCache = findSequenceCache(dbmeta);
sql = prepareSequenceCache(sql, sequenceCache);
return createSequenceExecution(handler, sql, sequenceCache);
}
Aggregations