KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > versant > core > jdo > SynchronizedQueryResult


1
2 /*
3  * Copyright (c) 1998 - 2005 Versant Corporation
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  * Versant Corporation - initial API and implementation
11  */

12 package com.versant.core.jdo;
13
14 import java.util.Iterator JavaDoc;
15 import java.util.Collection JavaDoc;
16 import java.util.List JavaDoc;
17 import java.util.ListIterator JavaDoc;
18
19 /**
20  * QueryResult implementation that synchronizes all methods except the
21  * next and prev accessors on a lock object. Synchronization for the next and
22  * prev accessors is provided inside {@link VersantQueryImp}.
23  */

24 public final class SynchronizedQueryResult implements QueryResult {
25
26     private final Object JavaDoc lock;
27     private final QueryResult q;
28
29     public SynchronizedQueryResult(Object JavaDoc lock, QueryResult q) {
30         this.lock = lock;
31         this.q = q;
32     }
33
34     public QueryResult getNext() {
35         return q.getNext();
36     }
37
38     public void setNext(QueryResult next) {
39         q.setNext(next);
40     }
41
42     public QueryResult getPrev() {
43         return q.getPrev();
44     }
45
46     public void setPrev(QueryResult prev) {
47         q.setPrev(prev);
48     }
49
50     public void close() {
51         synchronized (lock) {
52             q.close();
53         }
54     }
55
56     public void setParams(Object JavaDoc[] params) {
57         synchronized (lock) {
58             q.setParams(params);
59         }
60     }
61
62     public Iterator JavaDoc createInternalIterNoFlush() {
63         synchronized (lock) {
64             return q.createInternalIterNoFlush();
65         }
66     }
67
68     public int size() {
69         synchronized (lock) {
70             return q.size();
71         }
72     }
73
74     public void clear() {
75         synchronized (lock) {
76             q.clear();
77         }
78     }
79
80     public boolean isEmpty() {
81         synchronized (lock) {
82             return q.isEmpty();
83         }
84     }
85
86     public Object JavaDoc[] toArray() {
87         synchronized (lock) {
88             return q.toArray();
89         }
90     }
91
92     public Object JavaDoc get(int index) {
93         synchronized (lock) {
94             return q.get(index);
95         }
96     }
97
98     public Object JavaDoc remove(int index) {
99         synchronized (lock) {
100             return q.remove(index);
101         }
102     }
103
104     public void add(int index, Object JavaDoc element) {
105         synchronized (lock) {
106             q.add(index, element);
107         }
108     }
109
110     public int indexOf(Object JavaDoc o) {
111         synchronized (lock) {
112             return q.indexOf(o);
113         }
114     }
115
116     public int lastIndexOf(Object JavaDoc o) {
117         synchronized (lock) {
118             return q.lastIndexOf(o);
119         }
120     }
121
122     public boolean add(Object JavaDoc o) {
123         synchronized (lock) {
124             return q.add(o);
125         }
126     }
127
128     public boolean contains(Object JavaDoc o) {
129         synchronized (lock) {
130             return q.contains(o);
131         }
132     }
133
134     public boolean remove(Object JavaDoc o) {
135         synchronized (lock) {
136             return q.remove(o);
137         }
138     }
139
140     public boolean addAll(int index, Collection JavaDoc c) {
141         synchronized (lock) {
142             return q.addAll(index, c);
143         }
144     }
145
146     public boolean addAll(Collection JavaDoc c) {
147         synchronized (lock) {
148             return q.addAll(c);
149         }
150     }
151
152     public boolean containsAll(Collection JavaDoc c) {
153         synchronized (lock) {
154             return q.containsAll(c);
155         }
156     }
157
158     public boolean removeAll(Collection JavaDoc c) {
159         synchronized (lock) {
160             return q.removeAll(c);
161         }
162     }
163
164     public boolean retainAll(Collection JavaDoc c) {
165         synchronized (lock) {
166             return q.retainAll(c);
167         }
168     }
169
170     public Iterator JavaDoc iterator() {
171         synchronized (lock) {
172             return q.iterator();
173         }
174     }
175
176     public List JavaDoc subList(int fromIndex, int toIndex) {
177         synchronized (lock) {
178             return q.subList(fromIndex, toIndex);
179         }
180     }
181
182     public ListIterator JavaDoc listIterator() {
183         synchronized (lock) {
184             return q.listIterator();
185         }
186     }
187
188     public ListIterator JavaDoc listIterator(int index) {
189         synchronized (lock) {
190             return q.listIterator(index);
191         }
192     }
193
194     public Object JavaDoc set(int index, Object JavaDoc element) {
195         synchronized (lock) {
196             return q.set(index, element);
197         }
198     }
199
200     public Object JavaDoc[] toArray(Object JavaDoc a[]) {
201         synchronized (lock) {
202             return q.toArray(a);
203         }
204     }
205
206 }
207
208
Popular Tags