Search in sources :

Example 16 with ForeignInfo

use of org.dbflute.dbmeta.info.ForeignInfo in project dbflute-core by dbflute.

the class AbstractDBMeta method findForeignInfo.

/**
 * {@inheritDoc}
 */
public ForeignInfo findForeignInfo(String foreignPropertyName) {
    assertStringNotNullAndNotTrimmedEmpty("foreignPropertyName", foreignPropertyName);
    final Map<String, ForeignInfo> flexibleMap = getForeignInfoFlexibleMap();
    final ForeignInfo foreignInfo = flexibleMap.get(foreignPropertyName);
    if (foreignInfo == null) {
        final String notice = "The foreign info was not found.";
        final String keyName = "Foreign Property";
        throwDBMetaNotFoundException(notice, keyName, foreignPropertyName, flexibleMap.keySet());
    }
    return foreignInfo;
}
Also used : ForeignInfo(org.dbflute.dbmeta.info.ForeignInfo)

Example 17 with ForeignInfo

use of org.dbflute.dbmeta.info.ForeignInfo in project dbflute-core by dbflute.

the class AbstractConditionQuery method xregOutJo.

protected void xregOutJo(String prop) {
    // should be called after registration
    if (_queryRelationKeepingMap == null) {
        // no way, just in case
        _queryRelationKeepingMap = newLinkedHashMapSized(4);
    }
    final ConditionQuery cq = _queryRelationKeepingMap.get(prop);
    if (cq == null) {
        // no way, just in case
        String msg = "Not found the condition-query for (Query)Relation: " + prop;
        throw new IllegalStateException(msg);
    }
    final ForeignInfo foreignInfo = xgetLocalDBMeta().findForeignInfo(prop);
    final Map<ColumnInfo, ColumnInfo> localForeignColMap = foreignInfo.getLocalForeignColumnInfoMap();
    final Map<String, String> joinOnMap = newLinkedHashMapSized(localForeignColMap.size());
    for (Entry<ColumnInfo, ColumnInfo> entry : localForeignColMap.entrySet()) {
        final ColumnInfo localCol = entry.getKey();
        final ColumnInfo foreignCol = entry.getValue();
        joinOnMap.put(localCol.getColumnDbName(), foreignCol.getColumnDbName());
    }
    registerOuterJoin(cq, joinOnMap, prop);
}
Also used : ForeignInfo(org.dbflute.dbmeta.info.ForeignInfo) ColumnInfo(org.dbflute.dbmeta.info.ColumnInfo)

Example 18 with ForeignInfo

use of org.dbflute.dbmeta.info.ForeignInfo in project dbflute-core by dbflute.

the class AbstractConditionQuery method xdoBuildReferrerCorrelatedFixedCondition.

protected String xdoBuildReferrerCorrelatedFixedCondition(ConditionQuery subQuery, 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 FixedConditionResolver resolver = createReferrerFixedConditionResolver(subQuery);
    return resolver.resolveVariable(fixedCondition, false);
}
Also used : ForeignInfo(org.dbflute.dbmeta.info.ForeignInfo) FixedConditionResolver(org.dbflute.cbean.sqlclause.join.FixedConditionResolver) RelationInfo(org.dbflute.dbmeta.info.RelationInfo)

Example 19 with ForeignInfo

use of org.dbflute.dbmeta.info.ForeignInfo in project dbflute-core by dbflute.

the class AbstractConditionQuery method registerOuterJoin.

// ===================================================================================
// Outer Join
// ==========
/**
 * Register outer-join. <br>
 * Optional info, fixed condition and fixed in-line, are resolved in this method.
 * @param foreignCQ The condition-query for foreign table. (NotNull)
 * @param joinOnResourceMap The resource map of join condition on on-clause. (NotNull)
 * @param foreignPropertyName The property name of foreign relation corresponding to this join. (NotNull)
 */
protected void registerOuterJoin(ConditionQuery foreignCQ, Map<String, String> joinOnResourceMap, String foreignPropertyName) {
    final DBMeta dbmeta = xgetLocalDBMeta();
    final ForeignInfo foreignInfo = dbmeta.findForeignInfo(foreignPropertyName);
    doRegisterOuterJoin(foreignCQ, joinOnResourceMap, foreignPropertyName, foreignInfo);
}
Also used : ForeignInfo(org.dbflute.dbmeta.info.ForeignInfo) DBMeta(org.dbflute.dbmeta.DBMeta)

Example 20 with ForeignInfo

use of org.dbflute.dbmeta.info.ForeignInfo in project dbflute-core by dbflute.

the class TnDBMetaBeanAnnotationReader method getRelationKey.

public String getRelationKey(DfPropertyDesc pd) {
    if (_simpleType) {
        return null;
    }
    if (_fieldBeanAnnotationReader != null) {
        return _fieldBeanAnnotationReader.getRelationKey(pd);
    }
    if (!_dbmeta.hasForeign(pd.getPropertyName())) {
        return null;
    }
    final ForeignInfo foreignInfo = _dbmeta.findForeignInfo(pd.getPropertyName());
    final Map<ColumnInfo, ColumnInfo> localForeignColumnInfoMap = foreignInfo.getLocalForeignColumnInfoMap();
    final Set<ColumnInfo> keySet = localForeignColumnInfoMap.keySet();
    final StringBuilder sb = new StringBuilder();
    for (ColumnInfo localColumnInfo : keySet) {
        final ColumnInfo foreignColumnInfo = localForeignColumnInfoMap.get(localColumnInfo);
        if (sb.length() > 0) {
            sb.append(", ");
        }
        sb.append(localColumnInfo.getColumnDbName());
        sb.append(":").append(foreignColumnInfo.getColumnDbName());
    }
    return sb.toString();
}
Also used : ForeignInfo(org.dbflute.dbmeta.info.ForeignInfo) ColumnInfo(org.dbflute.dbmeta.info.ColumnInfo)

Aggregations

ForeignInfo (org.dbflute.dbmeta.info.ForeignInfo)20 DBMeta (org.dbflute.dbmeta.DBMeta)8 LinkedHashMap (java.util.LinkedHashMap)4 ColumnInfo (org.dbflute.dbmeta.info.ColumnInfo)4 ArrayList (java.util.ArrayList)3 RelationInfo (org.dbflute.dbmeta.info.RelationInfo)3 List (java.util.List)2 Method (java.lang.reflect.Method)1 HashMap (java.util.HashMap)1 Entity (org.dbflute.Entity)1 ConditionQuery (org.dbflute.cbean.ConditionQuery)1 FixedConditionResolver (org.dbflute.cbean.sqlclause.join.FixedConditionResolver)1 SelectedRelationColumn (org.dbflute.cbean.sqlclause.select.SelectedRelationColumn)1 TableSqlName (org.dbflute.dbmeta.name.TableSqlName)1 PropertyMethodFinder (org.dbflute.dbmeta.property.PropertyMethodFinder)1 DBMetaNotFoundException (org.dbflute.exception.DBMetaNotFoundException)1 DfPropertyAccessor (org.dbflute.helper.beans.DfPropertyAccessor)1 RelationOptionalFactory (org.dbflute.optional.RelationOptionalFactory)1 IndexOfInfo (org.dbflute.util.Srl.IndexOfInfo)1