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

📄 sessionfactoryimpl.java

📁 用Java实现的23个常用设计模式源代码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
		CollectionPersister result = (CollectionPersister) collectionPersisters.get(role);		if (result==null) throw new MappingException( "No persister for collection role: " + role );		return result;	}		public Databinder openDatabinder() throws HibernateException {		if (templates==null) throw new HibernateException(			"No output stylesheet configured. Use the property hibernate.output_stylesheet and ensure xalan.jar is in classpath"		);		try {			return new XMLDatabinder( this, templates.newTransformer() );		}		catch (Exception e) {			log.error("Could not open Databinder", e);			throw new HibernateException("Could not open Databinder", e);		}	}		public Dialect getDialect() {		return settings.getDialect();	}		public TransactionFactory getTransactionFactory() {		return settings.getTransactionFactory();	}		public TransactionManager getTransactionManager() {		return transactionManager;	}		// 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 boolean isJdbcBatchUpdateEnabled() {		return settings.getJdbcBatchSize()>0;	}		public int getJdbcBatchSize() {		return settings.getJdbcBatchSize();	}		public boolean isScrollableResultSetsEnabled() {		return settings.isScrollableResultSetsEnabled();	}		public boolean isOuterJoinedFetchEnabled() {		return settings.isOuterJoinFetchEnabled();	}		public String getNamedQuery(String queryName) {		String queryString = (String) namedQueries.get(queryName);				return queryString;	}		public InternalNamedSQLQuery getNamedSQLQuery(String queryName) {		return (InternalNamedSQLQuery) namedSqlQueries.get(queryName);	}			public Type getIdentifierType(Class ObjectClass) throws MappingException {		return getPersister(ObjectClass).getIdentifierType();	}	public String getIdentifierPropertyName(Class ObjectClass) throws MappingException {		return getPersister(ObjectClass).getIdentifierPropertyName();	}		private final void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {		log.trace("deserializing");		in.defaultReadObject();		log.debug("deserialized: " + uuid);	}	private final void writeObject(ObjectOutputStream out) throws IOException {		log.debug("serializing: " + uuid);		out.defaultWriteObject();		log.trace("serialized");	}		public Type[] getReturnTypes(String queryString) throws HibernateException {		String[] queries = QueryTranslator.concreteQueries(queryString, this);		if ( queries.length==0 ) throw new HibernateException("Query does not refer to any persistent classes: " + queryString);		return getQuery( queries[0], true )[0].getReturnTypes();	}			public String getDefaultSchema() {		return settings.getDefaultSchemaName();	}		public ClassMetadata getClassMetadata(Class persistentClass) throws HibernateException {		return (ClassMetadata) classMetadata.get(persistentClass);	}		public CollectionMetadata getCollectionMetadata(String roleName) throws HibernateException {		return (CollectionMetadata) collectionMetadata.get(roleName);	}		/**	 * 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(Class clazz) {		ArrayList results = new ArrayList();		Iterator iter = classPersisters.values().iterator();		while ( iter.hasNext() ) {			ClassPersister p = (ClassPersister) iter.next();			if ( p instanceof Queryable ) {				Queryable q = (Queryable) p;				String className = q.getClassName();				boolean isMappedClass = clazz.equals( q.getMappedClass() );				if ( q.isExplicitPolymorphism() ) {					if (isMappedClass) return new String[] { className };				}				else {					if (isMappedClass) {						results.add(className);					}					else if (						clazz.isAssignableFrom( q.getMappedClass() ) &&						( !q.isInherited() || !clazz.isAssignableFrom( q.getMappedSuperclass() ) )					) {						results.add(className);					}				}			}		}		return (String[]) results.toArray( new String[ results.size() ] );	}		public String getImportedClassName(String className) {		String result = (String) imports.get(className);		return (result==null) ? className : result;	}		public Map getAllClassMetadata() throws HibernateException {		return classMetadata;	}		public Map getAllCollectionMetadata() throws HibernateException {		return collectionMetadata;	}		/**	 * <ol>	 * <li>close the prepared statement cache (and all prepared statements)	 * <li>close the JDBC connection	 * <li>remove the JNDI binding	 * </ol>	 */	public void close() throws HibernateException {				log.info("closing");				Iterator iter = classPersisters.values().iterator();		while ( iter.hasNext() ) {			ClassPersister p = (ClassPersister) iter.next();			if ( p.hasCache() ) p.getCache().destroy();		}				iter = collectionPersisters.values().iterator();		while ( iter.hasNext() ) {			CollectionPersister p = (CollectionPersister) iter.next();			if ( p.hasCache() ) p.getCache().destroy();		}				try {			settings.getConnectionProvider().close();		}		finally {			SessionFactoryObjectFactory.removeInstance(uuid, name, properties);		}				if ( isQueryCacheEnabled() )  {			queryCache.destroy();			iter = queryCaches.values().iterator();			while ( iter.hasNext() ) {				QueryCache cache = (QueryCache) iter.next();				cache.destroy();			}			updateTimestampsCache.destroy();		}				if ( settings.isAutoDropSchema() ) schemaExport.drop(false, true);			}	public void evict(Class persistentClass, Serializable id) throws HibernateException {		ClassPersister p = getPersister(persistentClass);		if ( p.hasCache() ) p.getCache().remove(id);	}	public void evict(Class persistentClass) throws HibernateException {		ClassPersister p = getPersister(persistentClass);		if ( p.hasCache() ) p.getCache().clear();	}	public void evictCollection(String roleName, Serializable id)		throws HibernateException {		CollectionPersister p = getCollectionPersister(roleName);		if ( p.hasCache() ) p.getCache().remove(id);	}	public void evictCollection(String roleName) throws HibernateException {		CollectionPersister p = getCollectionPersister(roleName);		if ( p.hasCache() ) p.getCache().clear();	}	public Integer getMaximumFetchDepth() {		return settings.getMaximumFetchDepth();	}	public Type getPropertyType(Class persistentClass, String propertyName)		throws MappingException {		return getPersister(persistentClass).getPropertyType(propertyName);	}	public boolean isShowSqlEnabled() {		return settings.isShowSqlEnabled();	}	public Integer getJdbcFetchSize() {		return settings.getStatementFetchSize();	}		public ConnectionProvider getConnectionProvider() {		return settings.getConnectionProvider();	}	public UpdateTimestampsCache getUpdateTimestampsCache() {		return updateTimestampsCache;	}	public QueryCache getQueryCache() {		return queryCache;	}		public QueryCache getQueryCache(String cacheRegion) throws		HibernateException {		if (cacheRegion==null) return getQueryCache();		QueryCache currentQueryCache = (QueryCache) queryCaches.get(cacheRegion);		if (currentQueryCache==null) {			currentQueryCache = new QueryCache(				settings.getCacheProvider(), 				properties,				updateTimestampsCache, 				cacheRegion			);			queryCaches.put(cacheRegion, currentQueryCache);		}		return currentQueryCache;	}	public boolean isQueryCacheEnabled() {		return settings.isQueryCacheEnabled();	}	public void evictQueries() throws HibernateException {		queryCache.clear();		if ( queryCaches.size()==0 ) updateTimestampsCache.clear();	}	public void evictQueries(String cacheRegion) throws HibernateException {		if (cacheRegion==null) {			throw new NullPointerException("use the zero-argument form to evict the default query cache");		}		else {			QueryCache currentQueryCache = (QueryCache) queryCaches.get(cacheRegion);			if (queryCache!=null) currentQueryCache.clear();		}	}		//TODO: a better way to normalize the NamedSQLQuery aspect	static class InternalNamedSQLQuery {			private String query;		private String[] returnAliases;		private Class[] returnClasses;		public InternalNamedSQLQuery(String query, String[] aliases, Class[] clazz) {			this.returnClasses = clazz;			this.returnAliases = aliases;			this.query = query;			}		/**		 * @return Returns the aliases.		 */		public String[] getReturnAliases() {			return returnAliases;		}		/**		 * @return Returns the clazz.		 */		public Class[] getReturnClasses() {			return returnClasses;		}		/**		 * @return Returns the query.		 */		public String getQueryString() {			return query;		}	}	}

⌨️ 快捷键说明

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