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.ArrayList;
022: import java.util.Arrays;
023: import java.util.Collection;
024: import java.util.Iterator;
025: import javax.persistence.LockModeType;
026:
027: import org.apache.openjpa.kernel.DelegatingFetchConfiguration;
028: import org.apache.openjpa.kernel.FetchConfiguration;
029:
030: /**
031: * Implements FetchPlan via delegation to FetchConfiguration.
032: *
033: * @author Abe White
034: * @author Pinaki Poddar
035: * @since 0.4.1
036: * @nojavadoc
037: */
038: public class FetchPlanImpl implements FetchPlan {
039:
040: private final DelegatingFetchConfiguration _fetch;
041:
042: /**
043: * Constructor; supply delegate.
044: */
045: public FetchPlanImpl(FetchConfiguration fetch) {
046: _fetch = newDelegatingFetchConfiguration(fetch);
047: }
048:
049: /**
050: * Create a new exception-translating delegating fetch configuration.
051: */
052: protected DelegatingFetchConfiguration newDelegatingFetchConfiguration(
053: FetchConfiguration fetch) {
054: return new DelegatingFetchConfiguration(fetch,
055: PersistenceExceptions.TRANSLATOR);
056: }
057:
058: /**
059: * Delegate.
060: */
061: public FetchConfiguration getDelegate() {
062: return _fetch.getDelegate();
063: }
064:
065: public int getMaxFetchDepth() {
066: return _fetch.getMaxFetchDepth();
067: }
068:
069: public FetchPlan setMaxFetchDepth(int depth) {
070: _fetch.setMaxFetchDepth(depth);
071: return this ;
072: }
073:
074: public int getFetchBatchSize() {
075: return _fetch.getFetchBatchSize();
076: }
077:
078: public FetchPlan setFetchBatchSize(int fetchBatchSize) {
079: _fetch.setFetchBatchSize(fetchBatchSize);
080: return this ;
081: }
082:
083: public boolean getQueryResultCacheEnabled() {
084: return _fetch.getQueryCacheEnabled();
085: }
086:
087: public FetchPlan setQueryResultCacheEnabled(boolean cache) {
088: _fetch.setQueryCacheEnabled(cache);
089: return this ;
090: }
091:
092: public boolean getQueryResultCache() {
093: return getQueryResultCacheEnabled();
094: }
095:
096: public FetchPlan setQueryResultCache(boolean cache) {
097: return setQueryResultCacheEnabled(cache);
098: }
099:
100: public Collection<String> getFetchGroups() {
101: return _fetch.getFetchGroups();
102: }
103:
104: public FetchPlan addFetchGroup(String group) {
105: _fetch.addFetchGroup(group);
106: return this ;
107: }
108:
109: public FetchPlan addFetchGroups(String... groups) {
110: return addFetchGroups(Arrays.asList(groups));
111: }
112:
113: public FetchPlan addFetchGroups(Collection groups) {
114: _fetch.addFetchGroups(groups);
115: return this ;
116: }
117:
118: public FetchPlan removeFetchGroup(String group) {
119: _fetch.removeFetchGroup(group);
120: return this ;
121: }
122:
123: public FetchPlan removeFetchGroups(String... groups) {
124: return removeFetchGroups(Arrays.asList(groups));
125: }
126:
127: public FetchPlan removeFetchGroups(Collection groups) {
128: _fetch.removeFetchGroups(groups);
129: return this ;
130: }
131:
132: public FetchPlan clearFetchGroups() {
133: _fetch.clearFetchGroups();
134: return this ;
135: }
136:
137: public FetchPlan resetFetchGroups() {
138: _fetch.resetFetchGroups();
139: return this ;
140: }
141:
142: public Collection<String> getFields() {
143: return (Collection<String>) _fetch.getFields();
144: }
145:
146: public boolean hasField(String field) {
147: return _fetch.hasField(field);
148: }
149:
150: public boolean hasField(Class cls, String field) {
151: return hasField(toFieldName(cls, field));
152: }
153:
154: public FetchPlan addField(String field) {
155: _fetch.addField(field);
156: return this ;
157: }
158:
159: public FetchPlan addField(Class cls, String field) {
160: return addField(toFieldName(cls, field));
161: }
162:
163: public FetchPlan addFields(String... fields) {
164: return addFields(Arrays.asList(fields));
165: }
166:
167: public FetchPlan addFields(Class cls, String... fields) {
168: return addFields(cls, Arrays.asList(fields));
169: }
170:
171: public FetchPlan addFields(Collection fields) {
172: _fetch.addFields(fields);
173: return this ;
174: }
175:
176: public FetchPlan addFields(Class cls, Collection fields) {
177: return addFields(toFieldNames(cls, fields));
178: }
179:
180: public FetchPlan removeField(String field) {
181: _fetch.removeField(field);
182: return this ;
183: }
184:
185: public FetchPlan removeField(Class cls, String field) {
186: return removeField(toFieldName(cls, field));
187: }
188:
189: public FetchPlan removeFields(String... fields) {
190: return removeFields(Arrays.asList(fields));
191: }
192:
193: public FetchPlan removeFields(Class cls, String... fields) {
194: return removeFields(cls, Arrays.asList(fields));
195: }
196:
197: public FetchPlan removeFields(Collection fields) {
198: _fetch.removeFields(fields);
199: return this ;
200: }
201:
202: public FetchPlan removeFields(Class cls, Collection fields) {
203: return removeFields(toFieldNames(cls, fields));
204: }
205:
206: public FetchPlan clearFields() {
207: _fetch.clearFields();
208: return this ;
209: }
210:
211: private static String toFieldName(Class cls, String field) {
212: return cls.getName() + "." + field;
213: }
214:
215: private static Collection toFieldNames(Class cls, Collection fields) {
216: if (fields.isEmpty())
217: return fields;
218: Collection names = new ArrayList(fields);
219: for (Iterator itr = fields.iterator(); itr.hasNext();)
220: names.add(toFieldName(cls, (String) itr.next()));
221: return names;
222: }
223:
224: public int getLockTimeout() {
225: return _fetch.getLockTimeout();
226: }
227:
228: public FetchPlan setLockTimeout(int timeout) {
229: _fetch.setLockTimeout(timeout);
230: return this ;
231: }
232:
233: public LockModeType getReadLockMode() {
234: return EntityManagerImpl.fromLockLevel(_fetch
235: .getReadLockLevel());
236: }
237:
238: public FetchPlan setReadLockMode(LockModeType mode) {
239: _fetch.setReadLockLevel(EntityManagerImpl.toLockLevel(mode));
240: return this ;
241: }
242:
243: public LockModeType getWriteLockMode() {
244: return EntityManagerImpl.fromLockLevel(_fetch
245: .getWriteLockLevel());
246: }
247:
248: public FetchPlan setWriteLockMode(LockModeType mode) {
249: _fetch.setWriteLockLevel(EntityManagerImpl.toLockLevel(mode));
250: return this ;
251: }
252:
253: public int hashCode() {
254: return _fetch.hashCode();
255: }
256:
257: public boolean equals(Object other) {
258: if (other == this )
259: return true;
260: if (!(other instanceof FetchPlanImpl))
261: return false;
262: return _fetch.equals(((FetchPlanImpl) other)._fetch);
263: }
264: }
|