Пример #1
0
    public void close() throws Exception {
      if (_extent != null && _extent._openItrs != null) {
        _extent.lock();
        try {
          _extent._openItrs.remove(this);
        } finally {
          _extent.unlock();
        }
      }

      _closed = true;
      ((Closeable) getIterator()).close();
    }
Пример #2
0
    public void close() throws Exception {
      if (_extent != null && _extent._openItrs != null) {
        _extent.lock();
        try {
          _extent._openItrs.remove(this);
        } finally {
          _extent.unlock();
        }
      }

      _closed = true;
      for (Iterator itr = getIterators().iterator(); itr.hasNext(); )
        ((Closeable) itr.next()).close();
    }
Пример #3
0
  public Iterator<T> iterator() {
    _broker.assertNontransactionalRead();
    CloseableIterator citr = null;
    try {
      // create an iterator chain; add pnew objects if transactional
      CloseableIteratorChain chain = new CloseableIteratorChain();
      boolean trans = !_ignore && _broker.isActive();
      if (trans) chain.addIterator(new FilterNewIterator());

      // add database iterators for each implementing class
      MetaDataRepository repos = _broker.getConfiguration().getMetaDataRepositoryInstance();
      ClassMetaData meta = repos.getMetaData(_type, _broker.getClassLoader(), false);

      ClassMetaData[] metas;
      if (meta != null
          && (!_subs || !meta.isManagedInterface())
          && (meta.isMapped() || (_subs && meta.getMappedPCSubclassMetaDatas().length > 0)))
        metas = new ClassMetaData[] {meta};
      else if (_subs && (meta == null || meta.isManagedInterface()))
        metas = repos.getImplementorMetaDatas(_type, _broker.getClassLoader(), false);
      else metas = EMPTY_METAS;

      ResultObjectProvider rop;
      for (int i = 0; i < metas.length; i++) {
        rop = _broker.getStoreManager().executeExtent(metas[i], _subs, _fc);
        if (rop != null) chain.addIterator(new ResultObjectProviderIterator(rop));
      }

      // filter deleted objects if transactional
      if (trans) citr = new FilterDeletedIterator(chain);
      else citr = chain;
      citr.setRemoveOnClose(this);
    } catch (OpenJPAException ke) {
      throw ke;
    } catch (RuntimeException re) {
      throw new GeneralException(re);
    }

    lock();
    try {
      if (_openItrs == null) _openItrs = new ReferenceHashSet(ReferenceHashSet.WEAK);
      _openItrs.add(citr);
    } finally {
      unlock();
    }
    return citr;
  }
Пример #4
0
  public void closeAll() {
    if (_openItrs == null) return;

    lock();
    try {
      CloseableIterator citr;
      for (Iterator itr = _openItrs.iterator(); itr.hasNext(); ) {
        citr = (CloseableIterator) itr.next();
        citr.setRemoveOnClose(null);
        try {
          citr.close();
        } catch (Exception e) {
        }
      }
      _openItrs.clear();
    } catch (OpenJPAException ke) {
      throw ke;
    } catch (RuntimeException re) {
      throw new GeneralException(re);
    } finally {
      unlock();
    }
  }