1 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 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 queryName) throws MappingException { 23 NamedQueryDefinition nqd = factory.getNamedQuery(queryName); 24 final Query query; 25 if ( nqd != null ) { 26 String 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 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 |