KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hibernate > SessionFactory


1 //$Id: SessionFactory.java,v 1.15 2005/07/06 22:01:37 oneovthafew Exp $
2
package org.hibernate;
3
4 import java.io.Serializable JavaDoc;
5 import java.sql.Connection JavaDoc;
6 import java.util.Map JavaDoc;
7
8 import javax.naming.Referenceable JavaDoc;
9
10 import org.hibernate.metadata.ClassMetadata;
11 import org.hibernate.metadata.CollectionMetadata;
12 import org.hibernate.stat.Statistics;
13
14 /**
15  * Creates <tt>Session</tt>s. Usually an application has a single <tt>SessionFactory</tt>.
16  * Threads servicing client requests obtain <tt>Session</tt>s from the factory.<br>
17  * <br>
18  * Implementors must be threadsafe.<br>
19  * <br>
20  * <tt>SessionFactory</tt>s are immutable. The behaviour of a <tt>SessionFactory</tt> is
21  * controlled by properties supplied at configuration time. These properties are defined
22  * on <tt>Environment</tt>.
23  *
24  * @see Session
25  * @see org.hibernate.cfg.Environment
26  * @see org.hibernate.cfg.Configuration
27  * @see org.hibernate.connection.ConnectionProvider
28  * @see org.hibernate.transaction.TransactionFactory
29  * @author Gavin King
30  */

31 public interface SessionFactory extends Referenceable JavaDoc, Serializable JavaDoc {
32
33     /**
34      * Open a <tt>Session</tt> on the given connection.
35      * <p>
36      * Note that the second-level cache will be disabled if you
37      * supply a JDBC connection. Hibernate will not be able to track
38      * any statements you might have executed in the same transaction.
39      * Consider implementing your own <tt>ConnectionProvider</tt>.
40      *
41      * @param connection a connection provided by the application.
42      * @return Session
43      */

44     public org.hibernate.classic.Session openSession(Connection JavaDoc connection);
45
46     /**
47      * Create database connection and open a <tt>Session</tt> on it, specifying an
48      * interceptor.
49      *
50      * @param interceptor a session-scoped interceptor
51      * @return Session
52      * @throws HibernateException
53      */

54     public org.hibernate.classic.Session openSession(Interceptor interceptor) throws HibernateException;
55
56     /**
57      * Open a <tt>Session</tt> on the given connection, specifying an interceptor.
58      * <p>
59      * Note that the second-level cache will be disabled if you
60      * supply a JDBC connection. Hibernate will not be able to track
61      * any statements you might have executed in the same transaction.
62      * Consider implementing your own <tt>ConnectionProvider</tt>.
63      *
64      * @param connection a connection provided by the application.
65      * @param interceptor a session-scoped interceptor
66      * @return Session
67      */

68     public org.hibernate.classic.Session openSession(Connection JavaDoc connection, Interceptor interceptor);
69
70     /**
71      * Create database connection and open a <tt>Session</tt> on it.
72      *
73      * @return Session
74      * @throws HibernateException
75      */

76     public org.hibernate.classic.Session openSession() throws HibernateException;
77
78     /**
79      * Obtains the current session, where &quot;current&quot; is maintained in
80      * relation to the current JTA transaction; if a Session is not already
81      * associated with the current JTA transaction, a new Session will be opened
82      * and it will be associated with that JTA transaction.
83      * <p/>
84      * This is only useful in managed environments where Hibernate has access to
85      * the {@link javax.transaction.TransactionManager} for the given environment.
86      * A {@link javax.transaction.Transaction} must also already be in effect
87      * prior to calls to this method. If either condition fails, an exception
88      * is thrown.
89      * <p/>
90      * The Sessions returned from this method are automatically configured with
91      * both the {@link org.hibernate.cfg.Environment#FLUSH_BEFORE_COMPLETION auto-flush} and
92      * {@link org.hibernate.cfg.Environment#AUTO_CLOSE_SESSION auto-close} attributes set to
93      * true, meaning that the Session will be automatically flushed and closed
94      * as part of the lifecycle for the JTA transaction to which it is associated.
95      *
96      * @return The current session.
97      * @throws HibernateException Indicates that either<ul>
98      * <li>could not locate transaction manager
99      * <li>no transaction in effect
100      * <li>problems opening a session to associate with the transaction
101      * </ul>
102      */

103     public org.hibernate.classic.Session getCurrentSession() throws HibernateException;
104     
105     /**
106      * Get the <tt>ClassMetadata</tt> associated with the given entity class
107      *
108      * @see org.hibernate.metadata.ClassMetadata
109      */

110     public ClassMetadata getClassMetadata(Class JavaDoc persistentClass) throws HibernateException;
111
112     /**
113      * Get the <tt>ClassMetadata</tt> associated with the given entity name
114      *
115      * @see org.hibernate.metadata.ClassMetadata
116      * @since 3.0
117      */

118     public ClassMetadata getClassMetadata(String JavaDoc entityName) throws HibernateException;
119
120     /**
121      * Get the <tt>CollectionMetadata</tt> associated with the named collection role
122      *
123      * @see org.hibernate.metadata.CollectionMetadata
124      */

125     public CollectionMetadata getCollectionMetadata(String JavaDoc roleName) throws HibernateException;
126
127
128     /**
129      * Get all <tt>ClassMetadata</tt> as a <tt>Map</tt> from entityname <tt>String</tt>
130      * to metadata object
131      *
132      * @see org.hibernate.metadata.ClassMetadata
133      * @return a map from <tt>String</tt> an entity name to <tt>ClassMetaData</tt>
134      * @since 3.0 changed key from <tt>Class</tt> to <tt>String</tt>
135      */

136     public Map JavaDoc getAllClassMetadata() throws HibernateException;
137
138     /**
139      * Get all <tt>CollectionMetadata</tt> as a <tt>Map</tt> from role name
140      * to metadata object
141      *
142      * @see org.hibernate.metadata.CollectionMetadata
143      * @return a map from <tt>String</tt> to <tt>CollectionMetadata</tt>
144      */

145     public Map JavaDoc getAllCollectionMetadata() throws HibernateException;
146     
147     /**
148      * Get the statistics for this session factory
149      */

150     public Statistics getStatistics();
151
152     /**
153      * Destroy this <tt>SessionFactory</tt> and release all resources (caches,
154      * connection pools, etc). It is the responsibility of the application
155      * to ensure that there are no open <tt>Session</tt>s before calling
156      * <tt>close()</tt>.
157      */

158     public void close() throws HibernateException;
159     
160     /**
161      * Was this <tt>SessionFactory</tt> already closed?
162      */

163     public boolean isClosed();
164
165     /**
166      * Evict all entries from the second-level cache. This method occurs outside
167      * of any transaction; it performs an immediate "hard" remove, so does not respect
168      * any transaction isolation semantics of the usage strategy. Use with care.
169      */

170     public void evict(Class JavaDoc persistentClass) throws HibernateException;
171     /**
172      * Evict an entry from the second-level cache. This method occurs outside
173      * of any transaction; it performs an immediate "hard" remove, so does not respect
174      * any transaction isolation semantics of the usage strategy. Use with care.
175      */

176     public void evict(Class JavaDoc persistentClass, Serializable JavaDoc id) throws HibernateException;
177     /**
178      * Evict all entries from the second-level cache. This method occurs outside
179      * of any transaction; it performs an immediate "hard" remove, so does not respect
180      * any transaction isolation semantics of the usage strategy. Use with care.
181      */

182     public void evictEntity(String JavaDoc entityName) throws HibernateException;
183     /**
184      * Evict an entry from the second-level cache. This method occurs outside
185      * of any transaction; it performs an immediate "hard" remove, so does not respect
186      * any transaction isolation semantics of the usage strategy. Use with care.
187      */

188     public void evictEntity(String JavaDoc entityName, Serializable JavaDoc id) throws HibernateException;
189     /**
190      * Evict all entries from the second-level cache. This method occurs outside
191      * of any transaction; it performs an immediate "hard" remove, so does not respect
192      * any transaction isolation semantics of the usage strategy. Use with care.
193      */

194     public void evictCollection(String JavaDoc roleName) throws HibernateException;
195     /**
196      * Evict an entry from the second-level cache. This method occurs outside
197      * of any transaction; it performs an immediate "hard" remove, so does not respect
198      * any transaction isolation semantics of the usage strategy. Use with care.
199      */

200     public void evictCollection(String JavaDoc roleName, Serializable JavaDoc id) throws HibernateException;
201
202     /**
203      * Evict any query result sets cached in the default query cache region.
204      */

205     public void evictQueries() throws HibernateException;
206     /**
207      * Evict any query result sets cached in the named query cache region.
208      */

209     public void evictQueries(String JavaDoc cacheRegion) throws HibernateException;
210     /**
211      * Get a new stateless session.
212      */

213     public StatelessSession openStatelessSession();
214     /**
215      * Get a new stateless session for the given JDBC connection.
216      */

217     public StatelessSession openStatelessSession(Connection JavaDoc connection);
218 }
219
220
221
222
223
224
225
226
Popular Tags