Search in sources :

Example 36 with DBMeta

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);
}
Also used : DBMeta(org.dbflute.dbmeta.DBMeta) OutsideSqlContext(org.dbflute.outsidesql.OutsideSqlContext) BehaviorInvokeNameExtractor(org.dbflute.bhv.logging.invoke.BehaviorInvokeNameExtractor)

Example 37 with DBMeta

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);
}
Also used : RelationOptionalFactory(org.dbflute.optional.RelationOptionalFactory) LinkedHashMap(java.util.LinkedHashMap) ForeignInfo(org.dbflute.dbmeta.info.ForeignInfo) DBMeta(org.dbflute.dbmeta.DBMeta) RelationInfo(org.dbflute.dbmeta.info.RelationInfo) List(java.util.List) ArrayList(java.util.ArrayList)

Example 38 with DBMeta

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);
}
Also used : DBMeta(org.dbflute.dbmeta.DBMeta) ReferrerInfo(org.dbflute.dbmeta.info.ReferrerInfo)

Example 39 with DBMeta

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);
}
Also used : DBMeta(org.dbflute.dbmeta.DBMeta)

Example 40 with DBMeta

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);
}
Also used : DBMeta(org.dbflute.dbmeta.DBMeta) SequenceCache(org.dbflute.bhv.core.supplement.SequenceCache)

Aggregations

DBMeta (org.dbflute.dbmeta.DBMeta)64 ColumnInfo (org.dbflute.dbmeta.info.ColumnInfo)32 ArrayList (java.util.ArrayList)13 ForeignInfo (org.dbflute.dbmeta.info.ForeignInfo)13 List (java.util.List)12 LinkedHashMap (java.util.LinkedHashMap)11 ColumnSqlName (org.dbflute.dbmeta.name.ColumnSqlName)10 Entity (org.dbflute.Entity)9 PrimaryInfo (org.dbflute.dbmeta.info.PrimaryInfo)9 ReferrerInfo (org.dbflute.dbmeta.info.ReferrerInfo)9 Method (java.lang.reflect.Method)8 ReflectionFailureException (org.dbflute.util.DfReflectionUtil.ReflectionFailureException)8 Map (java.util.Map)7 ColumnFunctionCipher (org.dbflute.cbean.cipher.ColumnFunctionCipher)7 RelationInfo (org.dbflute.dbmeta.info.RelationInfo)7 LocalDate (java.time.LocalDate)6 LocalDateTime (java.time.LocalDateTime)6 Collection (java.util.Collection)6 Date (java.util.Date)6 HashMap (java.util.HashMap)6