⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sessionfactoryimpl.java

📁 hibernate 开源框架的代码 jar包希望大家能喜欢
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
				StringBuffer failingQueries = new StringBuffer( "Errors in named queries: " );				for ( Iterator iterator = keys.iterator() ; iterator.hasNext() ; ) {					String queryName = ( String ) iterator.next();					HibernateException e = ( HibernateException ) errors.get( queryName );					failingQueries.append( queryName );					if ( iterator.hasNext() ) {						failingQueries.append( ", " );					}					log.error( "Error in named query: " + queryName, e );				}				throw new HibernateException( failingQueries.toString() );			}		}		//stats		getStatistics().setStatisticsEnabled( settings.isStatisticsEnabled() );		// EntityNotFoundDelegate		EntityNotFoundDelegate entityNotFoundDelegate = cfg.getEntityNotFoundDelegate();		if ( entityNotFoundDelegate == null ) {			entityNotFoundDelegate = new EntityNotFoundDelegate() {				public void handleEntityNotFound(String entityName, Serializable id) {					throw new ObjectNotFoundException( id, entityName );				}			};		}		this.entityNotFoundDelegate = entityNotFoundDelegate;		this.observer.sessionFactoryCreated( this );	}	public QueryPlanCache getQueryPlanCache() {		return queryPlanCache;	}	private Map checkNamedQueries() throws HibernateException {		Map errors = new HashMap();		// Check named HQL queries		log.debug("Checking " + namedQueries.size() + " named HQL queries");		Iterator itr = namedQueries.entrySet().iterator();		while ( itr.hasNext() ) {			final Map.Entry entry = ( Map.Entry ) itr.next();			final String queryName = ( String ) entry.getKey();			final NamedQueryDefinition qd = ( NamedQueryDefinition ) entry.getValue();			// this will throw an error if there's something wrong.			try {				log.debug("Checking named query: " + queryName);				//TODO: BUG! this currently fails for named queries for non-POJO entities				queryPlanCache.getHQLQueryPlan( qd.getQueryString(), false, CollectionHelper.EMPTY_MAP );			}			catch ( QueryException e ) {				errors.put( queryName, e );			}			catch ( MappingException e ) {				errors.put( queryName, e );			}		}		log.debug("Checking " + namedSqlQueries.size() + " named SQL queries");		itr = namedSqlQueries.entrySet().iterator();		while ( itr.hasNext() ) {			final Map.Entry entry = ( Map.Entry ) itr.next();			final String queryName = ( String ) entry.getKey();			final NamedSQLQueryDefinition qd = ( NamedSQLQueryDefinition ) entry.getValue();			// this will throw an error if there's something wrong.			try {				log.debug("Checking named SQL query: " + queryName);				// TODO : would be really nice to cache the spec on the query-def so as to not have to re-calc the hash;				// currently not doable though because of the resultset-ref stuff...				NativeSQLQuerySpecification spec;				if ( qd.getResultSetRef() != null ) {					ResultSetMappingDefinition definition = ( ResultSetMappingDefinition ) sqlResultSetMappings.get( qd.getResultSetRef() );					if ( definition == null ) {						throw new MappingException( "Unable to find resultset-ref definition: " + qd.getResultSetRef() );					}					spec = new NativeSQLQuerySpecification(							qd.getQueryString(),					        definition.getQueryReturns(),					        qd.getQuerySpaces()					);				}				else {					spec =  new NativeSQLQuerySpecification(							qd.getQueryString(),					        qd.getQueryReturns(),					        qd.getQuerySpaces()					);				}				queryPlanCache.getNativeSQLQueryPlan( spec );			}			catch ( QueryException e ) {				errors.put( queryName, e );			}			catch ( MappingException e ) {				errors.put( queryName, e );			}		}		return errors;	}	public StatelessSession openStatelessSession() {		return new StatelessSessionImpl( null, this );	}	public StatelessSession openStatelessSession(Connection connection) {		return new StatelessSessionImpl( connection, this );	}	private SessionImpl openSession(		Connection connection,	    boolean autoClose,	    long timestamp,	    Interceptor sessionLocalInterceptor	) {		return new SessionImpl(		        connection,		        this,		        autoClose,		        timestamp,		        sessionLocalInterceptor == null ? interceptor : sessionLocalInterceptor,		        settings.getDefaultEntityMode(),		        settings.isFlushBeforeCompletionEnabled(),		        settings.isAutoCloseSessionEnabled(),		        settings.getConnectionReleaseMode()			);	}	public org.hibernate.classic.Session openSession(Connection connection, Interceptor sessionLocalInterceptor) {		return openSession(connection, false, Long.MIN_VALUE, sessionLocalInterceptor);	}	public org.hibernate.classic.Session openSession(Interceptor sessionLocalInterceptor)	throws HibernateException {		// note that this timestamp is not correct if the connection provider		// returns an older JDBC connection that was associated with a		// transaction that was already begun before openSession() was called		// (don't know any possible solution to this!)		long timestamp = settings.getRegionFactory().nextTimestamp();		return openSession( null, true, timestamp, sessionLocalInterceptor );	}	public org.hibernate.classic.Session openSession(Connection connection) {		return openSession(connection, interceptor); //prevents this session from adding things to cache	}	public org.hibernate.classic.Session openSession() throws HibernateException {		return openSession(interceptor);	}	public org.hibernate.classic.Session openTemporarySession() throws HibernateException {		return new SessionImpl(				null,		        this,		        true,		        settings.getRegionFactory().nextTimestamp(),		        interceptor,		        settings.getDefaultEntityMode(),		        false,		        false,		        ConnectionReleaseMode.AFTER_STATEMENT			);	}	public org.hibernate.classic.Session openSession(			final Connection connection,	        final boolean flushBeforeCompletionEnabled,	        final boolean autoCloseSessionEnabled,	        final ConnectionReleaseMode connectionReleaseMode) throws HibernateException {		return new SessionImpl(				connection,		        this,		        true,		        settings.getRegionFactory().nextTimestamp(),		        interceptor,		        settings.getDefaultEntityMode(),		        flushBeforeCompletionEnabled,		        autoCloseSessionEnabled,		        connectionReleaseMode			);	}	public org.hibernate.classic.Session getCurrentSession() throws HibernateException {		if ( currentSessionContext == null ) {			throw new HibernateException( "No CurrentSessionContext configured!" );		}		return currentSessionContext.currentSession();	}	public EntityPersister getEntityPersister(String entityName) throws MappingException {		EntityPersister result = (EntityPersister) entityPersisters.get(entityName);		if (result==null) {			throw new MappingException( "Unknown entity: " + entityName );		}		return result;	}	public CollectionPersister getCollectionPersister(String role) throws MappingException {		CollectionPersister result = (CollectionPersister) collectionPersisters.get(role);		if (result==null) {			throw new MappingException( "Unknown collection role: " + role );		}		return result;	}	public Settings getSettings() {		return settings;	}	public Dialect getDialect() {		return settings.getDialect();	}	public Interceptor getInterceptor()	{		return interceptor;	}	public TransactionFactory getTransactionFactory() {		return settings.getTransactionFactory();	}	public TransactionManager getTransactionManager() {		return transactionManager;	}	public SQLExceptionConverter getSQLExceptionConverter() {		return settings.getSQLExceptionConverter();	}	public Set getCollectionRolesByEntityParticipant(String entityName) {		return ( Set ) collectionRolesByEntityParticipant.get( entityName );	}	// from javax.naming.Referenceable	public Reference getReference() throws NamingException {		log.debug("Returning a Reference to the SessionFactory");		return new Reference(			SessionFactoryImpl.class.getName(),		    new StringRefAddr("uuid", uuid),		    SessionFactoryObjectFactory.class.getName(),		    null		);	}	private Object readResolve() throws ObjectStreamException {		log.trace("Resolving serialized SessionFactory");		// look for the instance by uuid		Object result = SessionFactoryObjectFactory.getInstance(uuid);		if (result==null) {			// in case we were deserialized in a different JVM, look for an instance with the same name			// (alternatively we could do an actual JNDI lookup here....)			result = SessionFactoryObjectFactory.getNamedInstance(name);			if (result==null) {				throw new InvalidObjectException("Could not find a SessionFactory named: " + name);			}			else {				log.debug("resolved SessionFactory by name");			}		}		else {			log.debug("resolved SessionFactory by uid");		}		return result;	}	public NamedQueryDefinition getNamedQuery(String queryName) {		return (NamedQueryDefinition) namedQueries.get(queryName);	}	public NamedSQLQueryDefinition getNamedSQLQuery(String queryName) {		return (NamedSQLQueryDefinition) namedSqlQueries.get(queryName);	}	public ResultSetMappingDefinition getResultSetMapping(String resultSetName) {		return (ResultSetMappingDefinition) sqlResultSetMappings.get(resultSetName);	}	public Type getIdentifierType(String className) throws MappingException {		return getEntityPersister(className).getIdentifierType();	}	public String getIdentifierPropertyName(String className) throws MappingException {		return getEntityPersister(className).getIdentifierPropertyName();	}	private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {		log.trace("deserializing");		in.defaultReadObject();		log.debug("deserialized: " + uuid);	}	private void writeObject(ObjectOutputStream out) throws IOException {		log.debug("serializing: " + uuid);		out.defaultWriteObject();		log.trace("serialized");	}	public Type[] getReturnTypes(String queryString) throws HibernateException {		return queryPlanCache.getHQLQueryPlan( queryString, false, CollectionHelper.EMPTY_MAP ).getReturnMetadata().getReturnTypes();	}	public String[] getReturnAliases(String queryString) throws HibernateException {		return queryPlanCache.getHQLQueryPlan( queryString, false, CollectionHelper.EMPTY_MAP ).getReturnMetadata().getReturnAliases();	}	public ClassMetadata getClassMetadata(Class persistentClass) throws HibernateException {		return getClassMetadata( persistentClass.getName() );	}	public CollectionMetadata getCollectionMetadata(String roleName) throws HibernateException {		return (CollectionMetadata) collectionMetadata.get(roleName);	}	public ClassMetadata getClassMetadata(String entityName) throws HibernateException {		return (ClassMetadata) classMetadata.get(entityName);	}	/**	 * Return the names of all persistent (mapped) classes that extend or implement the	 * given class or interface, accounting for implicit/explicit polymorphism settings	 * and excluding mapped subclasses/joined-subclasses of other classes in the result.	 */	public String[] getImplementors(String className) throws MappingException {		final Class clazz;		try {			clazz = ReflectHelper.classForName(className);		}		catch (ClassNotFoundException cnfe) {			return new String[] { className }; //for a dynamic-class		}		ArrayList results = new ArrayList();		Iterator iter = entityPersisters.values().iterator();		while ( iter.hasNext() ) {			//test this entity to see if we must query it			EntityPersister testPersister = (EntityPersister) iter.next();			if ( testPersister instanceof Queryable ) {				Queryable testQueryable = (Queryable) testPersister;				String testClassName = testQueryable.getEntityName();				boolean isMappedClass = className.equals(testClassName);				if ( testQueryable.isExplicitPolymorphism() ) {					if ( isMappedClass ) {						return new String[] {className}; //NOTE EARLY EXIT					}				}				else {					if (isMappedClass) {						results.add(testClassName);					}					else {						final Class mappedClass = testQueryable.getMappedClass( EntityMode.POJO );						if ( mappedClass!=null && clazz.isAssignableFrom( mappedClass ) ) {							final boolean assignableSuperclass;							if ( testQueryable.isInherited() ) {								Class mappedSuperclass = getEntityPersister( testQueryable.getMappedSuperclass() ).getMappedClass( EntityMode.POJO);								assignableSuperclass = clazz.isAssignableFrom(mappedSuperclass);							}							else {								assignableSuperclass = false;							}							if ( !assignableSuperclass ) {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -