01: /*
02: $Header: /cvsroot/xorm/xorm/src/org/xorm/ExtentImpl.java,v 1.7 2003/08/19 10:50:07 radzimir Exp $
03:
04: This file is part of XORM.
05:
06: XORM is free software; you can redistribute it and/or modify it
07: under the terms of the GNU General Public License as published by
08: the Free Software Foundation; either version 2 of the License, or
09: (at your option) any later version.
10:
11: XORM is distributed in the hope that it will be useful, but
12: WITHOUT ANY WARRANTY; without even the implied warranty of
13: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: General Public License for more details.
15:
16: You should have received a copy of the GNU General Public License
17: along with XORM; if not, write to the Free Software Foundation,
18: Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19: */
20: package org.xorm;
21:
22: import java.util.ArrayList;
23: import java.util.Collection;
24: import java.util.Iterator;
25: import javax.jdo.Extent;
26: import javax.jdo.PersistenceManager;
27:
28: public class ExtentImpl implements Extent {
29: private InterfaceManager mgr;
30: private Class clazz;
31: private boolean subclasses;
32: private ArrayList iterators;
33:
34: ExtentImpl(InterfaceManager mgr, Class clazz, boolean subclasses) {
35: //if (subclasses) throw new UnsupportedOperationException("Subclasses not supported");
36: this .mgr = mgr;
37: this .clazz = clazz;
38: this .subclasses = subclasses;
39: iterators = new ArrayList();
40: }
41:
42: /**
43: * Current implementation is functional but not performant.
44: */
45: public Iterator iterator() {
46: // This is a bit of a fake-out for now.
47: Collection c = (Collection) mgr.newQuery(clazz).execute();
48: Iterator it = c.iterator();
49: iterators.add(it);
50: return it;
51: }
52:
53: /** Subclasses are not currently supported. */
54: public boolean hasSubclasses() {
55: return subclasses;
56: }
57:
58: /** Returns the candidate class of this extent. */
59: public Class getCandidateClass() {
60: return clazz;
61: }
62:
63: /** Returns the persistence manager that created this extent. */
64: public PersistenceManager getPersistenceManager() {
65: return mgr;
66: }
67:
68: /** Closes all iterators associated with this extent. */
69: public void closeAll() {
70: Iterator it = iterators.iterator();
71: while (it.hasNext()) {
72: ((CollectionProxy.ProxyIterator) it.next()).close();
73: it.remove();
74: }
75: }
76:
77: /** Closes the given iterator. */
78: public void close(Iterator iterator) {
79: if (!iterators.contains(iterator))
80: throw new IllegalArgumentException();
81: CollectionProxy.ProxyIterator extentIt = (CollectionProxy.ProxyIterator) iterator;
82: extentIt.close();
83: iterators.remove(iterator);
84: }
85: }
|