001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */
019: package org.apache.openjpa.persistence;
020:
021: import java.util.Iterator;
022: import java.util.List;
023:
024: import org.apache.openjpa.kernel.DelegatingExtent;
025:
026: /**
027: * An extent is a logical view of all instances of a class.
028: *
029: * @author Abe White
030: * @since 0.4.1
031: * @nojavadoc
032: */
033: public class ExtentImpl<T> implements Extent<T> {
034:
035: private final EntityManagerImpl _em;
036: private final DelegatingExtent _extent;
037: private FetchPlan _fetch = null;
038:
039: /**
040: * Constructor; supply delegate.
041: */
042: public ExtentImpl(EntityManagerImpl em,
043: org.apache.openjpa.kernel.Extent extent) {
044: _em = em;
045: _extent = new DelegatingExtent(extent, PersistenceExceptions
046: .getRollbackTranslator(em));
047: }
048:
049: /**
050: * Delegate.
051: */
052: public org.apache.openjpa.kernel.Extent getDelegate() {
053: return _extent.getDelegate();
054: }
055:
056: public Class<T> getElementClass() {
057: return _extent.getElementType();
058: }
059:
060: public boolean hasSubclasses() {
061: return _extent.hasSubclasses();
062: }
063:
064: public OpenJPAEntityManager getEntityManager() {
065: return _em;
066: }
067:
068: public FetchPlan getFetchPlan() {
069: _em.assertNotCloseInvoked();
070: _extent.lock();
071: try {
072: if (_fetch == null)
073: _fetch = ((EntityManagerFactoryImpl) _em
074: .getEntityManagerFactory()).toFetchPlan(_extent
075: .getBroker(), _extent.getFetchConfiguration());
076: return _fetch;
077: } finally {
078: _extent.unlock();
079: }
080: }
081:
082: public boolean getIgnoreChanges() {
083: return _extent.getIgnoreChanges();
084: }
085:
086: public void setIgnoreChanges(boolean ignoreChanges) {
087: _em.assertNotCloseInvoked();
088: _extent.setIgnoreChanges(ignoreChanges);
089: }
090:
091: public List<T> list() {
092: _em.assertNotCloseInvoked();
093: return _extent.list();
094: }
095:
096: public Iterator<T> iterator() {
097: _em.assertNotCloseInvoked();
098: return _extent.iterator();
099: }
100:
101: public void closeAll() {
102: _extent.closeAll();
103: }
104:
105: public int hashCode() {
106: return _extent.hashCode();
107: }
108:
109: public boolean equals(Object other) {
110: if (other == this )
111: return true;
112: if (!(other instanceof ExtentImpl))
113: return false;
114: return _extent.equals(((ExtentImpl) other)._extent);
115: }
116: }
|