KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hibernate > impl > AbstractSessionImpl


1 //$Id: AbstractSessionImpl.java,v 1.1 2005/07/18 04:14:02 oneovthafew Exp $
2
package org.hibernate.impl;
3
4 import org.hibernate.MappingException;
5 import org.hibernate.Query;
6 import org.hibernate.engine.NamedQueryDefinition;
7 import org.hibernate.engine.NamedSQLQueryDefinition;
8 import org.hibernate.engine.SessionImplementor;
9
10 /**
11  * Functionality common to stateless and stateful sessions
12  *
13  * @author Gavin King
14  */

15 public abstract class AbstractSessionImpl implements SessionImplementor {
16     protected transient SessionFactoryImpl factory;
17     
18     protected AbstractSessionImpl(SessionFactoryImpl factory) {
19         this.factory = factory;
20     }
21     
22     public Query getNamedQuery(String JavaDoc queryName) throws MappingException {
23         NamedQueryDefinition nqd = factory.getNamedQuery(queryName);
24         final Query query;
25         if ( nqd != null ) {
26             String JavaDoc queryString = nqd.getQueryString();
27             QueryImpl query1 = new QueryImpl(queryString, nqd.getFlushMode(), this);
28             query = query1;
29             query.setComment("named HQL query " + queryName);
30         }
31         else {
32             NamedSQLQueryDefinition nsqlqd = factory.getNamedSQLQuery( queryName );
33             if (nsqlqd==null) {
34                 throw new MappingException("Named query not known: " + queryName);
35             }
36             query = new SQLQueryImpl(nsqlqd, this);
37             query.setComment("named native SQL query " + queryName);
38             nqd = nsqlqd;
39         }
40         initQuery(query, nqd );
41         return query;
42     }
43
44     public Query getNamedSQLQuery(String JavaDoc queryName) throws MappingException {
45         NamedSQLQueryDefinition nsqlqd = factory.getNamedSQLQuery( queryName );
46         if (nsqlqd==null) {
47             throw new MappingException("Named SQL query not known: " + queryName);
48         }
49         Query query = new SQLQueryImpl(nsqlqd, this);
50         query.setComment("named native SQL query " + queryName);
51         initQuery( query, nsqlqd );
52         return query;
53     }
54
55     private void initQuery(Query query, NamedQueryDefinition nqd) {
56         query.setCacheable( nqd.isCacheable() );
57         query.setCacheRegion( nqd.getCacheRegion() );
58         if ( nqd.getTimeout()!=null ) query.setTimeout( nqd.getTimeout().intValue() );
59         if ( nqd.getFetchSize()!=null ) query.setFetchSize( nqd.getFetchSize().intValue() );
60     }
61     
62 }
63
Popular Tags