001: /*
002: * Copyright (c) 1998 - 2005 Versant Corporation
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * Versant Corporation - initial API and implementation
010: */
011: package com.versant.core.jdo;
012:
013: import java.util.Iterator;
014: import java.util.Collection;
015: import java.util.List;
016: import java.util.ListIterator;
017:
018: /**
019: * QueryResult implementation that synchronizes all methods except the
020: * next and prev accessors on a lock object. Synchronization for the next and
021: * prev accessors is provided inside {@link VersantQueryImp}.
022: */
023: public final class SynchronizedQueryResult implements QueryResult {
024:
025: private final Object lock;
026: private final QueryResult q;
027:
028: public SynchronizedQueryResult(Object lock, QueryResult q) {
029: this .lock = lock;
030: this .q = q;
031: }
032:
033: public QueryResult getNext() {
034: return q.getNext();
035: }
036:
037: public void setNext(QueryResult next) {
038: q.setNext(next);
039: }
040:
041: public QueryResult getPrev() {
042: return q.getPrev();
043: }
044:
045: public void setPrev(QueryResult prev) {
046: q.setPrev(prev);
047: }
048:
049: public void close() {
050: synchronized (lock) {
051: q.close();
052: }
053: }
054:
055: public void setParams(Object[] params) {
056: synchronized (lock) {
057: q.setParams(params);
058: }
059: }
060:
061: public Iterator createInternalIterNoFlush() {
062: synchronized (lock) {
063: return q.createInternalIterNoFlush();
064: }
065: }
066:
067: public int size() {
068: synchronized (lock) {
069: return q.size();
070: }
071: }
072:
073: public void clear() {
074: synchronized (lock) {
075: q.clear();
076: }
077: }
078:
079: public boolean isEmpty() {
080: synchronized (lock) {
081: return q.isEmpty();
082: }
083: }
084:
085: public Object[] toArray() {
086: synchronized (lock) {
087: return q.toArray();
088: }
089: }
090:
091: public Object get(int index) {
092: synchronized (lock) {
093: return q.get(index);
094: }
095: }
096:
097: public Object remove(int index) {
098: synchronized (lock) {
099: return q.remove(index);
100: }
101: }
102:
103: public void add(int index, Object element) {
104: synchronized (lock) {
105: q.add(index, element);
106: }
107: }
108:
109: public int indexOf(Object o) {
110: synchronized (lock) {
111: return q.indexOf(o);
112: }
113: }
114:
115: public int lastIndexOf(Object o) {
116: synchronized (lock) {
117: return q.lastIndexOf(o);
118: }
119: }
120:
121: public boolean add(Object o) {
122: synchronized (lock) {
123: return q.add(o);
124: }
125: }
126:
127: public boolean contains(Object o) {
128: synchronized (lock) {
129: return q.contains(o);
130: }
131: }
132:
133: public boolean remove(Object o) {
134: synchronized (lock) {
135: return q.remove(o);
136: }
137: }
138:
139: public boolean addAll(int index, Collection c) {
140: synchronized (lock) {
141: return q.addAll(index, c);
142: }
143: }
144:
145: public boolean addAll(Collection c) {
146: synchronized (lock) {
147: return q.addAll(c);
148: }
149: }
150:
151: public boolean containsAll(Collection c) {
152: synchronized (lock) {
153: return q.containsAll(c);
154: }
155: }
156:
157: public boolean removeAll(Collection c) {
158: synchronized (lock) {
159: return q.removeAll(c);
160: }
161: }
162:
163: public boolean retainAll(Collection c) {
164: synchronized (lock) {
165: return q.retainAll(c);
166: }
167: }
168:
169: public Iterator iterator() {
170: synchronized (lock) {
171: return q.iterator();
172: }
173: }
174:
175: public List subList(int fromIndex, int toIndex) {
176: synchronized (lock) {
177: return q.subList(fromIndex, toIndex);
178: }
179: }
180:
181: public ListIterator listIterator() {
182: synchronized (lock) {
183: return q.listIterator();
184: }
185: }
186:
187: public ListIterator listIterator(int index) {
188: synchronized (lock) {
189: return q.listIterator(index);
190: }
191: }
192:
193: public Object set(int index, Object element) {
194: synchronized (lock) {
195: return q.set(index, element);
196: }
197: }
198:
199: public Object[] toArray(Object a[]) {
200: synchronized (lock) {
201: return q.toArray(a);
202: }
203: }
204:
205: }
|