View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    * 
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   * 
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.jetspeed.components.persistence.store;
18  
19  import java.util.Collection;
20  import java.util.Iterator;
21  
22  import org.apache.jetspeed.components.persistence.store.LockFailedException;
23  
24  /***
25   * <p>
26   * PersistenceStore
27   * </p>
28   * 
29   * <p>
30   * The persistence store allows access to the persistent
31   * storage mechanism within the application.
32   * <br/>
33   * PersistenceStore instances <strong>ARE NOT</strong> 
34   * thread safe.  The best practices approach for using
35   * the persistence store is to use 
36   * <code>PersistenceStoreContainer.getStoreForThread()</code>
37   * any time the store is to be accessed.
38   *  
39   * </p>
40   * 
41   * @
42   * @author <a href="mailto:weaver@apache.org">Scott T. Weaver</a>
43   * @version $ $
44   *
45   */
46  public interface PersistenceStore
47  {
48      /*** 
49       * No lock at all aka the object is read only changes WILL NOT be persisted
50       * at checkPoints or commits.
51       */
52      int LOCK_NO_LOCK = 0;
53  
54      /*** 
55       * changes to the object will be written to the database, in this case the lock 
56       * will be automatically upgraded to the write lock on transaction
57       */
58      int LOCK_READ = 1;
59  
60      /***
61       * changes to the object will be written to the database. 
62       */
63      int LOCK_PESSIMISTIC = 2;
64      
65  	void addEventListener(PersistenceStoreEventListener listener);
66      
67      void close();
68  
69      void deletePersistent(Object obj) throws LockFailedException;
70      
71  	void deleteAll(Object query) throws LockFailedException;
72  
73      Collection getCollectionByQuery(Object query);
74  
75      Collection getCollectionByQuery(Object query, int lockLevel);
76      
77  	Object getObjectByQuery(Object query);
78  
79  	Object getObjectByQuery(Object query, int lockLevel);
80  	
81  	Object getObjectByIdentity(Object object) throws LockFailedException;
82  
83  	Object getObjectByIdentity(Object object, int lockLevel) throws LockFailedException;
84  
85      int getCount(Object query);
86  
87      Iterator getIteratorByQuery(Object query) ;
88  
89      Iterator getIteratorByQuery(Object query, int lockLevel);
90      
91      /***
92       * 
93       * <p>
94       * isClosed
95       * </p>
96       * <p>
97       * indicates whether or not this <code>PersistenceStore</code>
98       * instance has been closed.  A closed store will generally
99       * throw exceptions when any operation is performed upon it.
100      * </p>
101      * 
102      * @return
103      *
104      */
105     boolean isClosed();
106     
107     /***
108      * 
109      * <p>
110      * getTransaction
111      * </p>
112      * <p>
113      * Returns the current <code>Transaction</code> for thsis
114      * <code>PersistenceStore</code> instance.  The transaction
115      * will always be the same for the lifetime of the
116      * <code>PersistenceStore</code> instance. 
117      * </p>
118      * 
119      * @return <code>Transaction</code> for this 
120      * <code>PersistenceStore</code>
121      *
122      */
123     Transaction getTransaction();
124     
125     void invalidate(Object obj) throws LockFailedException;
126     
127     void invalidateAll() throws LockFailedException;
128     
129     void invalidateExtent(Class clazz) throws LockFailedException;
130     
131 	void invalidateByQuery(Object query) throws LockFailedException;
132     
133     void lockForWrite(Object obj) throws LockFailedException;
134     
135     void makePersistent(Object obj) throws LockFailedException;
136     
137     Filter newFilter();
138     
139     Object newQuery(Class clazz, Filter filter);
140     
141     Collection getExtent(Class clazz);
142     
143 	Collection getExtent(Class clazz, int lockLevel);
144 
145 }