コード例 #1
0
  protected void initPersisters(
      final List associations,
      final LockOptions lockOptions,
      final AssociationInitCallback callback)
      throws MappingException {
    final int joins = countEntityPersisters(associations);
    final int collections = countCollectionPersisters(associations);

    collectionOwners = collections == 0 ? null : new int[collections];
    collectionPersisters = collections == 0 ? null : new CollectionPersister[collections];
    collectionSuffixes = BasicLoader.generateSuffixes(joins + 1, collections);

    this.lockOptions = lockOptions;

    persisters = new Loadable[joins];
    aliases = new String[joins];
    owners = new int[joins];
    ownerAssociationTypes = new EntityType[joins];
    lockModeArray = ArrayHelper.fillArray(lockOptions.getLockMode(), joins);

    int i = 0;
    int j = 0;
    Iterator iter = associations.iterator();
    while (iter.hasNext()) {
      final OuterJoinableAssociation oj = (OuterJoinableAssociation) iter.next();
      if (!oj.isCollection()) {

        persisters[i] = (Loadable) oj.getJoinable();
        aliases[i] = oj.getRHSAlias();
        owners[i] = oj.getOwner(associations);
        ownerAssociationTypes[i] = (EntityType) oj.getJoinableType();
        callback.associationProcessed(oj, i);
        i++;

      } else {

        QueryableCollection collPersister = (QueryableCollection) oj.getJoinable();
        if (oj.getJoinType() == JoinType.LEFT_OUTER_JOIN && !oj.hasRestriction()) {
          // it must be a collection fetch
          collectionPersisters[j] = collPersister;
          collectionOwners[j] = oj.getOwner(associations);
          j++;
        }

        if (collPersister.isOneToMany()) {
          persisters[i] = (Loadable) collPersister.getElementPersister();
          aliases[i] = oj.getRHSAlias();
          callback.associationProcessed(oj, i);
          i++;
        }
      }
    }

    if (ArrayHelper.isAllNegative(owners)) owners = null;
    if (collectionOwners != null && ArrayHelper.isAllNegative(collectionOwners)) {
      collectionOwners = null;
    }
  }
コード例 #2
0
 /**
  * Count the number of instances of Joinable which are actually also instances of
  * PersistentCollection which are being fetched by outer join
  */
 protected static final int countCollectionPersisters(List associations) throws MappingException {
   int result = 0;
   Iterator iter = associations.iterator();
   while (iter.hasNext()) {
     OuterJoinableAssociation oj = (OuterJoinableAssociation) iter.next();
     if (oj.getJoinType() == JoinType.LEFT_OUTER_JOIN
         && oj.getJoinable().isCollection()
         && !oj.hasRestriction()) {
       result++;
     }
   }
   return result;
 }