1414
1515package com .cloudant .client .cache ;
1616
17- import com .cloudant .client .api .Changes ;
1817import com .cloudant .client .api .Database ;
19- import com .cloudant .client .api .DesignDocumentManager ;
20- import com .cloudant .client .api .Search ;
21- import com .cloudant .client .api .model .DbInfo ;
22- import com .cloudant .client .api .model .FindByIndexOptions ;
23- import com .cloudant .client .api .model .Index ;
24- import com .cloudant .client .api .model .IndexField ;
2518import com .cloudant .client .api .model .Params ;
26- import com .cloudant .client .api .model .Permissions ;
2719import com .cloudant .client .api .model .Response ;
28- import com .cloudant .client .api .model .Shard ;
29- import com .cloudant .client .api .views .AllDocsRequestBuilder ;
30- import com .cloudant .client .api .views .ViewRequestBuilder ;
3120
32- import java .io .InputStream ;
33- import java .net .URI ;
34- import java .util .EnumSet ;
3521import java .util .List ;
36- import java .util .Map ;
3722
3823/**
3924 * A {@link Database} implementation with a cache.
4025 *
4126 * @author Arun Iyengar
4227 */
43- public class DatabaseCache implements Database {
28+ public class DatabaseCache extends Database {
4429
45- protected final Database db ;
4630 protected final Cache <String , Object > cache ;
47-
48-
31+
4932 /**
5033 * Constructor which is designed to work with a variety of different caches.
5134 *
52- * @param database data structure with information about the database connection
53- * @param cacheInstance cache instance which has already been created and initialized
35+ * @param database non-null data structure with information about the database connection
36+ * @param cacheInstance non-null cache instance which has already been created and initialized
5437 */
5538 public DatabaseCache (Database database , Cache <String , Object > cacheInstance ) {
56- this . db = database ;
39+ super ( database ) ;
5740 this .cache = cacheInstance ;
5841 }
5942
@@ -113,7 +96,7 @@ public <T> T find(Class<T> classType, String id) {
11396 if (value != null ) {
11497 return value ;
11598 } else {
116- value = db .find (classType , id );
99+ value = super .find (classType , id );
117100 cachePut (id , value );
118101 return value ;
119102 }
@@ -131,7 +114,7 @@ public <T> T find(Class<T> classType, String id, Params params) {
131114 if (value != null ) {
132115 return value ;
133116 } else {
134- value = db .find (classType , id , params );
117+ value = super .find (classType , id , params );
135118 cachePut (id , value );
136119 return value ;
137120 }
@@ -157,7 +140,7 @@ public <T> T findAny(Class<T> classType, String uri) {
157140 if (value != null ) {
158141 return value ;
159142 } else {
160- value = db .findAny (classType , uri );
143+ value = super .findAny (classType , uri );
161144 cachePut (uri , value );
162145 return value ;
163146 }
@@ -174,7 +157,7 @@ public boolean contains(String id) {
174157 if (cache .get (id ) != null ) {
175158 return true ;
176159 } else {
177- return db .contains (id );
160+ return super .contains (id );
178161 }
179162 }
180163
@@ -185,7 +168,7 @@ public boolean contains(String id) {
185168 * </P>
186169 */
187170 public Response save (Object object ) {
188- Response response = db .save (object );
171+ Response response = super .save (object );
189172 cachePut (response .getId (), object );
190173 return response ;
191174 }
@@ -197,7 +180,7 @@ public Response save(Object object) {
197180 * </P>
198181 */
199182 public Response save (Object object , int writeQuorum ) {
200- Response response = db .save (object , writeQuorum );
183+ Response response = super .save (object , writeQuorum );
201184 cachePut (response .getId (), object );
202185 return response ;
203186 }
@@ -209,7 +192,7 @@ public Response save(Object object, int writeQuorum) {
209192 * </P>
210193 */
211194 public Response post (Object object ) {
212- Response response = db .post (object );
195+ Response response = super .post (object );
213196 cachePut (response .getId (), object );
214197 return response ;
215198 }
@@ -221,7 +204,7 @@ public Response post(Object object) {
221204 * </P>
222205 */
223206 public Response post (Object object , int writeQuorum ) {
224- Response response = db .post (object , writeQuorum );
207+ Response response = super .post (object , writeQuorum );
225208 cachePut (response .getId (), object );
226209 return response ;
227210 }
@@ -233,7 +216,7 @@ public Response post(Object object, int writeQuorum) {
233216 * </P>
234217 */
235218 public Response update (Object object ) {
236- Response response = db .update (object );
219+ Response response = super .update (object );
237220 cachePut (response .getId (), object );
238221 return response ;
239222 }
@@ -245,7 +228,7 @@ public Response update(Object object) {
245228 * </P>
246229 */
247230 public Response update (Object object , int writeQuorum ) {
248- Response response = db .update (object , writeQuorum );
231+ Response response = super .update (object , writeQuorum );
249232 cachePut (response .getId (), object );
250233 return response ;
251234 }
@@ -257,7 +240,7 @@ public Response update(Object object, int writeQuorum) {
257240 * </P>
258241 */
259242 public Response remove (Object object ) {
260- Response response = db .remove (object );
243+ Response response = super .remove (object );
261244 cache .delete (response .getId ());
262245 return response ;
263246 }
@@ -271,7 +254,7 @@ public Response remove(Object object) {
271254 */
272255 @ Override
273256 public List <Response > bulk (List <?> list ) {
274- List <Response > responses = db .bulk (list );
257+ List <Response > responses = super .bulk (list );
275258 int index = 0 ;
276259 for (Object o : list ) {
277260 Response response = responses .get (index );
@@ -283,225 +266,4 @@ public List<Response> bulk(List<?> list) {
283266 }
284267 return responses ;
285268 }
286-
287- /* Remainder of Database implementation follows, delegating calls to the Database instance
288- specified on construction */
289-
290- /**
291- * {@inheritDoc}
292- */
293- @ Override
294- public void setPermissions (String s , EnumSet <Permissions > enumSet ) {
295- db .setPermissions (s , enumSet );
296- }
297-
298- /**
299- * {@inheritDoc}
300- */
301- @ Override
302- public Map <String , EnumSet <Permissions >> getPermissions () {
303- return db .getPermissions ();
304- }
305-
306- /**
307- * {@inheritDoc}
308- */
309- @ Override
310- public List <Shard > getShards () {
311- return db .getShards ();
312- }
313-
314- /**
315- * {@inheritDoc}
316- */
317- @ Override
318- public Shard getShard (String s ) {
319- return db .getShard (s );
320- }
321-
322- /**
323- * {@inheritDoc}
324- */
325- @ Override
326- public void createIndex (String s , String s1 , String s2 , IndexField [] indexFields ) {
327- db .createIndex (s , s1 , s2 , indexFields );
328- }
329-
330- /**
331- * {@inheritDoc}
332- */
333- @ Override
334- public void createIndex (String s ) {
335- db .createIndex (s );
336- }
337-
338- /**
339- * {@inheritDoc}
340- */
341- @ Override
342- public <T > List <T > findByIndex (String s , Class <T > aClass ) {
343- return db .findByIndex (s , aClass );
344- }
345-
346- /**
347- * {@inheritDoc}
348- */
349- @ Override
350- public <T > List <T > findByIndex (String s , Class <T > aClass , FindByIndexOptions
351- findByIndexOptions ) {
352- return db .findByIndex (s , aClass , findByIndexOptions );
353- }
354-
355- /**
356- * {@inheritDoc}
357- */
358- @ Override
359- public List <Index > listIndices () {
360- return db .listIndices ();
361- }
362-
363- /**
364- * {@inheritDoc}
365- */
366- @ Override
367- public void deleteIndex (String s , String s1 ) {
368- db .deleteIndex (s , s1 );
369- }
370-
371- /**
372- * {@inheritDoc}
373- */
374- @ Override
375- public Search search (String s ) {
376- return db .search (s );
377- }
378-
379- /**
380- * {@inheritDoc}
381- */
382- @ Override
383- public DesignDocumentManager getDesignDocumentManager () {
384- return db .getDesignDocumentManager ();
385- }
386-
387- /**
388- * {@inheritDoc}
389- */
390- @ Override
391- public ViewRequestBuilder getViewRequestBuilder (String s , String s1 ) {
392- return db .getViewRequestBuilder (s , s1 );
393- }
394-
395- /**
396- * {@inheritDoc}
397- */
398- @ Override
399- public AllDocsRequestBuilder getAllDocsRequestBuilder () {
400- return db .getAllDocsRequestBuilder ();
401- }
402-
403- /**
404- * {@inheritDoc}
405- */
406- @ Override
407- public Changes changes () {
408- return db .changes ();
409- }
410-
411- /**
412- * <P>
413- * Note that cache implementations currently do not store multiple revisions, so this method
414- * only operates remotely.
415- * </P>
416- * {@inheritDoc}
417- */
418- @ Override
419- public <T > T find (Class <T > aClass , String s , String s1 ) {
420- return db .find (aClass , s , s1 );
421- }
422-
423- /**
424- * <P>
425- * Note that cache implementations only store objects, so InputStreams are returned from the
426- * remote database.
427- * </P>
428- * {@inheritDoc}
429- */
430- @ Override
431- public InputStream find (String s ) {
432- return db .find (s );
433- }
434-
435- /**
436- * <P>
437- * Note that cache implementations only store objects, so InputStreams are returned from the
438- * remote database.
439- * </P>
440- * {@inheritDoc}
441- */
442- @ Override
443- public InputStream find (String s , String s1 ) {
444- return db .find (s , s1 );
445- }
446-
447- /**
448- * <P>
449- * Note that cache implementations currently do not store multiple revisions, so this method
450- * only operates remotely.
451- * </P>
452- * {@inheritDoc}
453- */
454- @ Override
455- public Response remove (String s , String s1 ) {
456- return db .remove (s , s1 );
457- }
458-
459- /**
460- * {@inheritDoc}
461- */
462- @ Override
463- public Response saveAttachment (InputStream inputStream , String s , String s1 ) {
464- return db .saveAttachment (inputStream , s , s1 );
465- }
466-
467- /**
468- * {@inheritDoc}
469- */
470- @ Override
471- public Response saveAttachment (InputStream inputStream , String s , String s1 , String s2 ,
472- String s3 ) {
473- return db .saveAttachment (inputStream , s , s1 , s2 , s3 );
474- }
475-
476- /**
477- * {@inheritDoc}
478- */
479- @ Override
480- public String invokeUpdateHandler (String s , String s1 , Params params ) {
481- return db .invokeUpdateHandler (s , s1 , params );
482- }
483-
484- /**
485- * {@inheritDoc}
486- */
487- @ Override
488- public URI getDBUri () {
489- return db .getDBUri ();
490- }
491-
492- /**
493- * {@inheritDoc}
494- */
495- @ Override
496- public DbInfo info () {
497- return db .info ();
498- }
499-
500- /**
501- * {@inheritDoc}
502- */
503- @ Override
504- public void ensureFullCommit () {
505- db .ensureFullCommit ();
506- }
507269}
0 commit comments