annotationconfiguration.java
来自「hibernate3.2.6源码和jar包」· Java 代码 · 共 1,029 行 · 第 1/3 页
JAVA
1,029 行
} } } } private static void findClassNames( String defaultPackage, final Element startNode, final java.util.Set names ) { // if we have some extends we need to check if those classes possibly could be inside the // same hbm.xml file... Iterator[] classes = new Iterator[4]; classes[0] = startNode.elementIterator( "class" ); classes[1] = startNode.elementIterator( "subclass" ); classes[2] = startNode.elementIterator( "joined-subclass" ); classes[3] = startNode.elementIterator( "union-subclass" ); Iterator classIterator = new JoinedIterator( classes ); 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]; for (int i = 0; i < length - 1; i++) { newListeners[i] = listeners[i]; } 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]; for (int i = 0; i < length - 1; i++) { newListeners[i] = listeners[i]; } newListeners[length - 1] = (PreUpdateEventListener) validateEventListener; getEventListeners().setPreUpdateEventListeners( newListeners ); } } else { getEventListeners().setPreUpdateEventListeners( new PreUpdateEventListener[] { (PreUpdateEventListener) validateEventListener } ); } } } SearchConfiguration.enableHibernateSearch( getEventListeners(), getProperties() ); return super.buildSessionFactory(); } @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 + =
减小字号Ctrl + -
显示快捷键?