View Javadoc

1   /*
2    * $Id: ObjectStorePartition.java 22506 2011-07-21 16:30:40Z stephen.fenech $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
9    */
10  
11  package org.mule.util.store;
12  
13  import org.mule.api.store.ListableObjectStore;
14  import org.mule.api.store.ObjectStoreException;
15  import org.mule.api.store.PartitionableObjectStore;
16  
17  import java.io.Serializable;
18  import java.util.List;
19  
20  public class ObjectStorePartition<T extends Serializable> implements ListableObjectStore<T>
21  {
22  
23      final String partitionName;
24      final PartitionableObjectStore<T> partitionedObjectStore;
25  
26      public ObjectStorePartition(String partitionName, PartitionableObjectStore<T> partitionedObjectStore)
27      {
28          this.partitionName = partitionName;
29          this.partitionedObjectStore = partitionedObjectStore;
30      }
31  
32      @Override
33      public boolean contains(Serializable key) throws ObjectStoreException
34      {
35          return partitionedObjectStore.contains(key, partitionName);
36      }
37  
38      @Override
39      public void store(Serializable key, T value) throws ObjectStoreException
40      {
41          partitionedObjectStore.store(key, value, partitionName);
42      }
43  
44      @Override
45      public T retrieve(Serializable key) throws ObjectStoreException
46      {
47          return partitionedObjectStore.retrieve(key, partitionName);
48      }
49  
50      @Override
51      public T remove(Serializable key) throws ObjectStoreException
52      {
53          return partitionedObjectStore.remove(key, partitionName);
54      }
55  
56      @Override
57      public boolean isPersistent()
58      {
59          return partitionedObjectStore.isPersistent();
60      }
61  
62      @Override
63      public void open() throws ObjectStoreException
64      {
65          partitionedObjectStore.open(partitionName);
66      }
67  
68      @Override
69      public void close() throws ObjectStoreException
70      {
71          partitionedObjectStore.close(partitionName);
72      }
73  
74      @Override
75      public List<Serializable> allKeys() throws ObjectStoreException
76      {
77          return partitionedObjectStore.allKeys(partitionName);
78      }
79  
80      public PartitionableObjectStore<T> getBaseStore()
81      {
82          return partitionedObjectStore;
83      }
84      
85      public String getPartitionName()
86      {
87          return partitionName;
88      }
89      
90  }