use of org.dbflute.dbmeta.info.ForeignInfo in project dbflute-core by dbflute.
the class HpFixedConditionQueryResolver method resolveOptimizedForeignAlias.
protected String resolveOptimizedForeignAlias(String optimizedCondition, InlineViewResource resource, Map<ForeignInfo, String> foreignAliasMap) {
if (optimizedCondition == null) {
return null;
}
final Map<String, ForeignInfo> optimizedVariableMap = resource.getOptimizedVariableMap();
if (optimizedVariableMap == null) {
return optimizedCondition;
}
for (Entry<String, ForeignInfo> entry : optimizedVariableMap.entrySet()) {
final String relationVariable = entry.getKey();
final ForeignInfo foreignInfo = entry.getValue();
final String inlineAlias = foreignAliasMap.get(foreignInfo);
optimizedCondition = replaceString(optimizedCondition, relationVariable, inlineAlias);
}
return optimizedCondition;
}
use of org.dbflute.dbmeta.info.ForeignInfo in project dbflute-core by dbflute.
the class AbstractBehaviorReadable method xdoBuildReferrerCorrelatedFixedCondition.
protected String xdoBuildReferrerCorrelatedFixedCondition(ConditionBean cb, ReferrerInfo referrerInfo) {
final RelationInfo reverseRelation = referrerInfo.getReverseRelation();
if (reverseRelation == null) {
return null;
}
if (!(reverseRelation instanceof ForeignInfo)) {
String msg = "The reverse relation (referrer's reverse) should be foreign info: " + referrerInfo;
throw new IllegalStateException(msg);
}
final ForeignInfo foreignInfo = (ForeignInfo) reverseRelation;
final String fixedCondition = foreignInfo.getFixedCondition();
if (fixedCondition == null || fixedCondition.trim().length() == 0) {
return null;
}
final String localAliasMark = HpFixedConditionQueryResolver.LOCAL_ALIAS_MARK;
final String basePointAliasName = cb.getSqlClause().getBasePointAliasName();
return Srl.replace(fixedCondition, localAliasMark, basePointAliasName);
}
use of org.dbflute.dbmeta.info.ForeignInfo 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.info.ForeignInfo in project dbflute-core by dbflute.
the class AbstractSqlClause method resolveRelationNo.
/**
* {@inheritDoc}
*/
public int resolveRelationNo(String localTableName, String foreignPropertyName) {
final DBMeta dbmeta = findDBMeta(localTableName);
final ForeignInfo foreignInfo = dbmeta.findForeignInfo(foreignPropertyName);
return foreignInfo.getRelationNo();
}
use of org.dbflute.dbmeta.info.ForeignInfo in project dbflute-core by dbflute.
the class AbstractDBMeta method findForeignInfo.
/**
* {@inheritDoc}
*/
public ForeignInfo findForeignInfo(int relationNo) {
final Map<Integer, ForeignInfo> relationNoKeyMap = getForeignInfoRelationNoKeyMap();
final ForeignInfo foreignInfo = relationNoKeyMap.get(relationNo);
if (foreignInfo == null) {
final String notice = "The foreign info was not found.";
final String keyName = "Relation No";
throwDBMetaNotFoundException(notice, keyName, relationNo, relationNoKeyMap.keySet());
}
return foreignInfo;
}
Aggregations