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

📄 annotationconfiguration.java

📁 Hibernate Annotations Sample
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
		while ( classIterator.hasNext() ) {			Element element = (Element) classIterator.next();			String entityName = element.attributeValue( "entity-name" );			if ( entityName == null ) entityName = getClassName( element.attribute( "name" ), defaultPackage );			names.add( entityName );			findClassNames( defaultPackage, element, names );		}	}	private static String getClassName(Attribute name, String defaultPackage) {		if ( name == null ) return null;		String unqualifiedName = name.getValue();		if ( unqualifiedName == null ) return null;		if ( unqualifiedName.indexOf( '.' ) < 0 && defaultPackage != null ) {			return defaultPackage + '.' + unqualifiedName;		}		return unqualifiedName;	}	public void setPrecedence(String precedence) {		this.precedence = precedence;	}	private static class CacheHolder {		public CacheHolder(String role, String usage, String region, boolean isClass, boolean cacheLazy) {			this.role = role;			this.usage = usage;			this.region = region;			this.isClass = isClass;			this.cacheLazy = cacheLazy;		}		public String role;		public String usage;		public String region;		public boolean isClass;		public boolean cacheLazy;	}	@Override	public AnnotationConfiguration addInputStream(InputStream xmlInputStream) throws MappingException {		try {			List errors = new ArrayList();			SAXReader saxReader = xmlHelper.createSAXReader( "XML InputStream", errors, getEntityResolver() );			try {				saxReader.setFeature( "http://apache.org/xml/features/validation/schema", true );				//saxReader.setFeature( "http://apache.org/xml/features/validation/dynamic", true );				//set the default schema locators				saxReader.setProperty(						"http://apache.org/xml/properties/schema/external-schemaLocation",						"http://java.sun.com/xml/ns/persistence/orm orm_1_0.xsd"				);			}			catch (SAXException e) {				saxReader.setValidation( false );			}			org.dom4j.Document doc = saxReader					.read( new InputSource( xmlInputStream ) );			if ( errors.size() != 0 ) {				throw new MappingException( "invalid mapping", (Throwable) errors.get( 0 ) );			}			add( doc );			return this;		}		catch (DocumentException e) {			throw new MappingException( "Could not parse mapping document in input stream", e );		}		finally {			try {				xmlInputStream.close();			}			catch (IOException ioe) {				log.warn( "Could not close input stream", ioe );			}		}	}	public SessionFactory buildSessionFactory() throws HibernateException {		//add validator events if the jar is available		boolean enableValidatorListeners = !"false".equalsIgnoreCase( getProperty( "hibernate.validator.autoregister_listeners" ) );		Class validateEventListenerClass = null;		try {			validateEventListenerClass = ReflectHelper.classForName(					"org.hibernate.validator.event.ValidateEventListener",					AnnotationConfiguration.class );		}		catch (ClassNotFoundException e) {			//validator is not present			log.debug( "Validator not present in classpath, ignoring event listener registration" );		}		if ( enableValidatorListeners && validateEventListenerClass != null ) {			//TODO so much duplication			Object validateEventListener;			try {				validateEventListener = validateEventListenerClass.newInstance();			}			catch (Exception e) {				throw new AnnotationException( "Unable to load Validator event listener", e );			}			{				boolean present = false;				PreInsertEventListener[] listeners = getEventListeners().getPreInsertEventListeners();				if ( listeners != null ) {					for (Object eventListener : listeners) {						//not isAssignableFrom since the user could subclass						present = present || validateEventListenerClass == eventListener.getClass();					}					if ( !present ) {						int length = listeners.length + 1;						PreInsertEventListener[] newListeners = new PreInsertEventListener[length];						System.arraycopy( listeners, 0, newListeners, 0, length - 1 );						newListeners[length - 1] = (PreInsertEventListener) validateEventListener;						getEventListeners().setPreInsertEventListeners( newListeners );					}				}				else {					getEventListeners().setPreInsertEventListeners(							new PreInsertEventListener[] { (PreInsertEventListener) validateEventListener }					);				}			}			//update event listener			{				boolean present = false;				PreUpdateEventListener[] listeners = getEventListeners().getPreUpdateEventListeners();				if ( listeners != null ) {					for (Object eventListener : listeners) {						//not isAssignableFrom since the user could subclass						present = present || validateEventListenerClass == eventListener.getClass();					}					if ( !present ) {						int length = listeners.length + 1;						PreUpdateEventListener[] newListeners = new PreUpdateEventListener[length];						System.arraycopy( listeners, 0, newListeners, 0, length - 1 );						newListeners[length - 1] = (PreUpdateEventListener) validateEventListener;						getEventListeners().setPreUpdateEventListeners( newListeners );					}				}				else {					getEventListeners().setPreUpdateEventListeners(							new PreUpdateEventListener[] { (PreUpdateEventListener) validateEventListener }					);				}			}		}				enableHibernateSearch(); 				return super.buildSessionFactory();	}	/**	 * Tries to automatically register Hibernate Search event listeners by locating the 	 * appropriate bootstrap class and calling the <code>enableHibernateSearch</code> method.	 */	private void enableHibernateSearch() {		// load the bootstrap class		Class searchStartupClass;		try {			searchStartupClass = ReflectHelper.classForName(SEARCH_STARTUP_CLASS, AnnotationConfiguration.class);			} catch ( ClassNotFoundException e ) {			// TODO remove this together with SearchConfiguration after 3.1.0 release of Search			// try loading deprecated HibernateSearchEventListenerRegister			try {				searchStartupClass = ReflectHelper.classForName("org.hibernate.cfg.search.HibernateSearchEventListenerRegister", AnnotationConfiguration.class);			} catch ( ClassNotFoundException cnfe ) {				log.debug("Search not present in classpath, ignoring event listener registration.");				return;			}		}				// call the method for registering the listeners		try {			Object searchStartupInstance = searchStartupClass.newInstance();			Method enableSearchMethod = searchStartupClass.getDeclaredMethod(SEARCH_STARTUP_METHOD,					EventListeners.class, Properties.class);			enableSearchMethod.invoke(searchStartupInstance, getEventListeners(), getProperties());		} catch ( InstantiationException e ) {			log.debug("Unable to instantiate {}, ignoring event listener registration.", SEARCH_STARTUP_CLASS);		} catch ( IllegalAccessException e ) {			log.debug("Unable to instantiate {}, ignoring event listener registration.", SEARCH_STARTUP_CLASS);		} catch ( NoSuchMethodException e ) {			log.debug("Method enableHibernateSearch() not found in {}.", SEARCH_STARTUP_CLASS);		} catch ( InvocationTargetException e ) {			log.debug("Unable to execute {}, ignoring event listener registration.", SEARCH_STARTUP_METHOD);		}	}	@Override	public AnnotationConfiguration addFile(String xmlFile) throws MappingException {		super.addFile( xmlFile );		return this;	}	@Override	public AnnotationConfiguration addFile(File xmlFile) throws MappingException {		super.addFile( xmlFile );		return this;	}	@Override	public AnnotationConfiguration addCacheableFile(File xmlFile) throws MappingException {		super.addCacheableFile( xmlFile );		return this;	}	@Override	public AnnotationConfiguration addCacheableFile(String xmlFile) throws MappingException {		super.addCacheableFile( xmlFile );		return this;	}	@Override	public AnnotationConfiguration addXML(String xml) throws MappingException {		super.addXML( xml );		return this;	}	@Override	public AnnotationConfiguration addURL(URL url) throws MappingException {		super.addURL( url );		return this;	}	@Override	public AnnotationConfiguration addResource(String resourceName, ClassLoader classLoader) throws MappingException {		super.addResource( resourceName, classLoader );		return this;	}	@Override	public AnnotationConfiguration addDocument(org.w3c.dom.Document doc) throws MappingException {		super.addDocument( doc );		return this;	}	@Override	public AnnotationConfiguration addResource(String resourceName) throws MappingException {		super.addResource( resourceName );		return this;	}	@Override	public AnnotationConfiguration addClass(Class persistentClass) throws MappingException {		super.addClass( persistentClass );		return this;	}	@Override	public AnnotationConfiguration addJar(File jar) throws MappingException {		super.addJar( jar );		return this;	}	@Override	public AnnotationConfiguration addDirectory(File dir) throws MappingException {		super.addDirectory( dir );		return this;	}	@Override	public AnnotationConfiguration setInterceptor(Interceptor interceptor) {		super.setInterceptor( interceptor );		return this;	}	@Override	public AnnotationConfiguration setProperties(Properties properties) {		super.setProperties( properties );		return this;	}	@Override	public AnnotationConfiguration addProperties(Properties extraProperties) {		super.addProperties( extraProperties );		return this;	}	@Override	public AnnotationConfiguration mergeProperties(Properties properties) {		super.mergeProperties( properties );		return this;	}	@Override	public AnnotationConfiguration setProperty(String propertyName, String value) {		super.setProperty( propertyName, value );		return this;	}	@Override	public AnnotationConfiguration configure() throws HibernateException {		super.configure();		return this;	}	@Override	public AnnotationConfiguration configure(String resource) throws HibernateException {		super.configure( resource );		return this;	}	@Override	public AnnotationConfiguration configure(URL url) throws HibernateException {		super.configure( url );		return this;	}	@Override	public AnnotationConfiguration configure(File configFile) throws HibernateException {		super.configure( configFile );		return this;	}	@Override	protected AnnotationConfiguration doConfigure(InputStream stream, String resourceName) throws HibernateException {		super.doConfigure( stream, resourceName );		return this;	}	@Override	public AnnotationConfiguration configure(org.w3c.dom.Document document) throws HibernateException {		super.configure( document );		return this;	}	@Override	protected AnnotationConfiguration doConfigure(Document doc) throws HibernateException {		super.doConfigure( doc );		return this;	}	@Override	public AnnotationConfiguration setCacheConcurrencyStrategy(String clazz, String concurrencyStrategy) throws MappingException {		super.setCacheConcurrencyStrategy( clazz, concurrencyStrategy );		return this;	}	@Override	public AnnotationConfiguration setCollectionCacheConcurrencyStrategy(String collectionRole, String concurrencyStrategy) throws MappingException {		super.setCollectionCacheConcurrencyStrategy( collectionRole, concurrencyStrategy );		return this;	}	@Override	public AnnotationConfiguration setNamingStrategy(NamingStrategy namingStrategy) {		super.setNamingStrategy( namingStrategy );		return this;	}	//not a public API	public ReflectionManager getReflectionManager() {		return reflectionManager;	}}

⌨️ 快捷键说明

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