KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > roller > business > PersistenceStrategy


1 /*
2  * Created on Aug 13, 2003
3  */

4 package org.roller.business;
5
6 import java.io.Serializable JavaDoc;
7
8 import org.roller.RollerException;
9 import org.roller.pojos.PersistentObject;
10 import org.roller.pojos.UserData;
11
12 /**
13  * Persistence strategy masks underlying persistence mechanism.
14  * State is held in thread local storage (TLS).
15  * When you call begin(), a PersistenceSession object is associated with your thread.
16  * When you call release(), TLS is cleared.
17  *
18  * @author Lance Lavandowska
19  * @author Dave Johnson
20  */

21 public interface PersistenceStrategy extends Serializable JavaDoc
22 {
23     /**
24      * Save a persistent object to storage. This method is only needed when
25      * a new object is to be added to storage.
26      */

27     public PersistentObject store(PersistentObject data)
28         throws RollerException;
29        
30     /**
31      * Load an persistent object from storage. Object returned is a
32      * persistent instance, meaning that changes to it will be automatically
33      * saved to storage the next time that commit() is called.
34      */

35     public PersistentObject load(
36         String JavaDoc id, Class JavaDoc cls) throws RollerException;
37         
38     /**
39      * Remove an object from storage.
40      */

41     public void remove(PersistentObject po)
42         throws RollerException;
43         
44     /**
45      * Remove an object from storage.
46      */

47     public void remove(String JavaDoc id, Class JavaDoc cls)
48         throws RollerException;
49         
50     /**
51      * Release existing resources and start new session and transaction.
52      */

53     public void begin(UserData user) throws RollerException;
54     
55     /**
56      * Associate user with thread.
57      */

58     public void setUser(UserData user) throws RollerException;
59     public UserData getUser() throws RollerException;
60
61     /**
62      * Commit all changes made to persistent objects since last call to begin.
63      */

64     public void commit() throws RollerException;
65
66     /**
67      * Rollback all changes since last call to begin.
68      */

69     public void rollback() throws RollerException;
70     
71     /**
72      * Release associated resources (database connection, session, etc.) and
73      * clear thread local storage.
74      */

75     public void release() throws RollerException;
76 }
77
Popular Tags