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.kernel;
020:
021: import java.util.Collection;
022: import java.util.Set;
023:
024: import org.apache.openjpa.lib.rop.ResultList;
025: import org.apache.openjpa.lib.rop.ResultObjectProvider;
026: import org.apache.openjpa.meta.FieldMetaData;
027: import org.apache.openjpa.util.RuntimeExceptionTranslator;
028:
029: ///////////////////////////////////////////////////////////////
030: // NOTE: when adding a public API method, be sure to add it to
031: // JDO and JPA facades!
032: ///////////////////////////////////////////////////////////////
033:
034: /**
035: * Delegating fetch configuration that can also perform exception
036: * translation for use in facades.
037: *
038: * @author Abe White
039: * @nojavadoc
040: */
041: public class DelegatingFetchConfiguration implements FetchConfiguration {
042:
043: private final FetchConfiguration _fetch;
044: private final DelegatingFetchConfiguration _del;
045: private final RuntimeExceptionTranslator _trans;
046:
047: /**
048: * Constructor; supply delegate.
049: */
050: public DelegatingFetchConfiguration(FetchConfiguration fetch) {
051: this (fetch, null);
052: }
053:
054: /**
055: * Constructor; supply delegate and exception translator.
056: */
057: public DelegatingFetchConfiguration(FetchConfiguration fetch,
058: RuntimeExceptionTranslator trans) {
059: _fetch = fetch;
060: if (fetch instanceof DelegatingFetchConfiguration)
061: _del = (DelegatingFetchConfiguration) fetch;
062: else
063: _del = null;
064: _trans = trans;
065: }
066:
067: /**
068: * Return the direct delegate.
069: */
070: public FetchConfiguration getDelegate() {
071: return _fetch;
072: }
073:
074: /**
075: * Return the native delegate.
076: */
077: public FetchConfiguration getInnermostDelegate() {
078: return (_del == null) ? _fetch : _del.getInnermostDelegate();
079: }
080:
081: public int hashCode() {
082: return getInnermostDelegate().hashCode();
083: }
084:
085: public boolean equals(Object other) {
086: if (other == this )
087: return true;
088: if (other instanceof DelegatingFetchConfiguration)
089: other = ((DelegatingFetchConfiguration) other)
090: .getInnermostDelegate();
091: return getInnermostDelegate().equals(other);
092: }
093:
094: /**
095: * Translate the OpenJPA exception.
096: */
097: protected RuntimeException translate(RuntimeException re) {
098: return (_trans == null) ? re : _trans.translate(re);
099: }
100:
101: public StoreContext getContext() {
102: try {
103: return _fetch.getContext();
104: } catch (RuntimeException re) {
105: throw translate(re);
106: }
107: }
108:
109: public void setContext(StoreContext ctx) {
110: try {
111: _fetch.setContext(ctx);
112: } catch (RuntimeException re) {
113: throw translate(re);
114: }
115: }
116:
117: public int getFetchBatchSize() {
118: try {
119: return _fetch.getFetchBatchSize();
120: } catch (RuntimeException re) {
121: throw translate(re);
122: }
123: }
124:
125: public FetchConfiguration setFetchBatchSize(int fetchBatchSize) {
126: try {
127: _fetch.setFetchBatchSize(fetchBatchSize);
128: return this ;
129: } catch (RuntimeException re) {
130: throw translate(re);
131: }
132: }
133:
134: public int getMaxFetchDepth() {
135: try {
136: return _fetch.getMaxFetchDepth();
137: } catch (RuntimeException re) {
138: throw translate(re);
139: }
140: }
141:
142: public FetchConfiguration setMaxFetchDepth(int depth) {
143: try {
144: _fetch.setMaxFetchDepth(depth);
145: return this ;
146: } catch (RuntimeException re) {
147: throw translate(re);
148: }
149: }
150:
151: public Set getRootInstances() {
152: try {
153: return _fetch.getRootInstances();
154: } catch (RuntimeException re) {
155: throw translate(re);
156: }
157: }
158:
159: public FetchConfiguration setRootInstances(Collection roots) {
160: try {
161: _fetch.setRootInstances(roots);
162: return this ;
163: } catch (RuntimeException re) {
164: throw translate(re);
165: }
166: }
167:
168: public Set getRootClasses() {
169: try {
170: return _fetch.getRootClasses();
171: } catch (RuntimeException re) {
172: throw translate(re);
173: }
174: }
175:
176: public FetchConfiguration setRootClasses(Collection roots) {
177: try {
178: _fetch.setRootClasses(roots);
179: return this ;
180: } catch (RuntimeException re) {
181: throw translate(re);
182: }
183: }
184:
185: public boolean getQueryCacheEnabled() {
186: try {
187: return _fetch.getQueryCacheEnabled();
188: } catch (RuntimeException re) {
189: throw translate(re);
190: }
191: }
192:
193: public FetchConfiguration setQueryCacheEnabled(boolean cache) {
194: try {
195: _fetch.setQueryCacheEnabled(cache);
196: return this ;
197: } catch (RuntimeException re) {
198: throw translate(re);
199: }
200: }
201:
202: public int getFlushBeforeQueries() {
203: try {
204: return _fetch.getFlushBeforeQueries();
205: } catch (RuntimeException re) {
206: throw translate(re);
207: }
208: }
209:
210: public FetchConfiguration setFlushBeforeQueries(int flush) {
211: try {
212: _fetch.setFlushBeforeQueries(flush);
213: return this ;
214: } catch (RuntimeException re) {
215: throw translate(re);
216: }
217: }
218:
219: public Set getFetchGroups() {
220: try {
221: return _fetch.getFetchGroups();
222: } catch (RuntimeException re) {
223: throw translate(re);
224: }
225: }
226:
227: public boolean hasFetchGroup(String group) {
228: try {
229: return _fetch.hasFetchGroup(group);
230: } catch (RuntimeException re) {
231: throw translate(re);
232: }
233: }
234:
235: public FetchConfiguration addFetchGroup(String group) {
236: try {
237: _fetch.addFetchGroup(group);
238: return this ;
239: } catch (RuntimeException re) {
240: throw translate(re);
241: }
242: }
243:
244: public FetchConfiguration addFetchGroups(Collection groups) {
245: try {
246: _fetch.addFetchGroups(groups);
247: return this ;
248: } catch (RuntimeException re) {
249: throw translate(re);
250: }
251: }
252:
253: public FetchConfiguration removeFetchGroup(String group) {
254: try {
255: _fetch.removeFetchGroup(group);
256: return this ;
257: } catch (RuntimeException re) {
258: throw translate(re);
259: }
260: }
261:
262: public FetchConfiguration removeFetchGroups(Collection groups) {
263: try {
264: _fetch.removeFetchGroups(groups);
265: return this ;
266: } catch (RuntimeException re) {
267: throw translate(re);
268: }
269: }
270:
271: public FetchConfiguration clearFetchGroups() {
272: try {
273: _fetch.clearFetchGroups();
274: return this ;
275: } catch (RuntimeException re) {
276: throw translate(re);
277: }
278: }
279:
280: public FetchConfiguration resetFetchGroups() {
281: try {
282: _fetch.resetFetchGroups();
283: return this ;
284: } catch (RuntimeException re) {
285: throw translate(re);
286: }
287: }
288:
289: public Set getFields() {
290: try {
291: return _fetch.getFields();
292: } catch (RuntimeException re) {
293: throw translate(re);
294: }
295: }
296:
297: public boolean hasField(String field) {
298: try {
299: return _fetch.hasField(field);
300: } catch (RuntimeException re) {
301: throw translate(re);
302: }
303: }
304:
305: public FetchConfiguration addField(String field) {
306: try {
307: _fetch.addField(field);
308: return this ;
309: } catch (RuntimeException re) {
310: throw translate(re);
311: }
312: }
313:
314: public FetchConfiguration addFields(Collection fields) {
315: try {
316: _fetch.addFields(fields);
317: return this ;
318: } catch (RuntimeException re) {
319: throw translate(re);
320: }
321: }
322:
323: public FetchConfiguration removeField(String field) {
324: try {
325: _fetch.removeField(field);
326: return this ;
327: } catch (RuntimeException re) {
328: throw translate(re);
329: }
330: }
331:
332: public FetchConfiguration removeFields(Collection fields) {
333: try {
334: _fetch.removeFields(fields);
335: return this ;
336: } catch (RuntimeException re) {
337: throw translate(re);
338: }
339: }
340:
341: public FetchConfiguration clearFields() {
342: try {
343: _fetch.clearFields();
344: return this ;
345: } catch (RuntimeException re) {
346: throw translate(re);
347: }
348: }
349:
350: public int getLockTimeout() {
351: try {
352: return _fetch.getLockTimeout();
353: } catch (RuntimeException re) {
354: throw translate(re);
355: }
356: }
357:
358: public FetchConfiguration setLockTimeout(int timeout) {
359: try {
360: _fetch.setLockTimeout(timeout);
361: return this ;
362: } catch (RuntimeException re) {
363: throw translate(re);
364: }
365: }
366:
367: public int getReadLockLevel() {
368: try {
369: return _fetch.getReadLockLevel();
370: } catch (RuntimeException re) {
371: throw translate(re);
372: }
373: }
374:
375: public FetchConfiguration setReadLockLevel(int level) {
376: try {
377: _fetch.setReadLockLevel(level);
378: return this ;
379: } catch (RuntimeException re) {
380: throw translate(re);
381: }
382: }
383:
384: public int getWriteLockLevel() {
385: try {
386: return _fetch.getWriteLockLevel();
387: } catch (RuntimeException re) {
388: throw translate(re);
389: }
390: }
391:
392: public FetchConfiguration setWriteLockLevel(int level) {
393: try {
394: _fetch.setWriteLockLevel(level);
395: return this ;
396: } catch (RuntimeException re) {
397: throw translate(re);
398: }
399: }
400:
401: public ResultList newResultList(ResultObjectProvider rop) {
402: try {
403: return _fetch.newResultList(rop);
404: } catch (RuntimeException re) {
405: throw translate(re);
406: }
407: }
408:
409: public void copy(FetchConfiguration fetch) {
410: try {
411: _fetch.copy(fetch);
412: } catch (RuntimeException re) {
413: throw translate(re);
414: }
415: }
416:
417: public Object clone() {
418: try {
419: return _fetch.clone();
420: } catch (RuntimeException re) {
421: throw translate(re);
422: }
423: }
424:
425: public void setHint(String name, Object value) {
426: try {
427: _fetch.setHint(name, value);
428: } catch (RuntimeException re) {
429: throw translate(re);
430: }
431: }
432:
433: public Object getHint(String name) {
434: try {
435: return _fetch.getHint(name);
436: } catch (RuntimeException re) {
437: throw translate(re);
438: }
439: }
440:
441: public int requiresFetch(FieldMetaData fmd) {
442: try {
443: return _fetch.requiresFetch(fmd);
444: } catch (RuntimeException re) {
445: throw translate(re);
446: }
447: }
448:
449: public boolean requiresLoad() {
450: try {
451: return _fetch.requiresLoad();
452: } catch (RuntimeException re) {
453: throw translate(re);
454: }
455: }
456:
457: public FetchConfiguration traverse(FieldMetaData fmd) {
458: try {
459: return _fetch.traverse(fmd);
460: } catch (RuntimeException re) {
461: throw translate(re);
462: }
463: }
464:
465: public void lock() {
466: try {
467: _fetch.lock();
468: } catch (RuntimeException re) {
469: throw translate(re);
470: }
471: }
472:
473: public void unlock() {
474: try {
475: _fetch.unlock();
476: } catch (RuntimeException re) {
477: throw translate(re);
478: }
479: }
480: }
|