|
From: <hib...@li...> - 2006-07-26 11:32:32
|
Author: max...@jb...
Date: 2006-07-26 07:32:19 -0400 (Wed, 26 Jul 2006)
New Revision: 10154
Added:
branches/Branch_3_2/Hibernate3/src/org/hibernate/InvalidMappingException.java
branches/Branch_3_2/Hibernate3/src/org/hibernate/MappingNotFoundException.java
Modified:
branches/Branch_3_2/Hibernate3/src/org/hibernate/DuplicateMappingException.java
branches/Branch_3_2/Hibernate3/src/org/hibernate/cfg/Configuration.java
Log:
merge from 3.2 HHH-1941
Modified: branches/Branch_3_2/Hibernate3/src/org/hibernate/DuplicateMappingException.java
===================================================================
--- branches/Branch_3_2/Hibernate3/src/org/hibernate/DuplicateMappingException.java 2006-07-26 09:11:56 UTC (rev 10153)
+++ branches/Branch_3_2/Hibernate3/src/org/hibernate/DuplicateMappingException.java 2006-07-26 11:32:19 UTC (rev 10154)
@@ -1,5 +1,12 @@
package org.hibernate;
+/**
+ * Raised whenever a duplicate for a certain type occurs.
+ * Duplicate class, table, property name etc.
+ *
+ * @author Max Rydahl Andersen
+ *
+ */
public class DuplicateMappingException extends MappingException {
private final String name;
Copied: branches/Branch_3_2/Hibernate3/src/org/hibernate/InvalidMappingException.java (from rev 10148, trunk/Hibernate3/src/org/hibernate/InvalidMappingException.java)
Copied: branches/Branch_3_2/Hibernate3/src/org/hibernate/MappingNotFoundException.java (from rev 10148, trunk/Hibernate3/src/org/hibernate/MappingNotFoundException.java)
Modified: branches/Branch_3_2/Hibernate3/src/org/hibernate/cfg/Configuration.java
===================================================================
--- branches/Branch_3_2/Hibernate3/src/org/hibernate/cfg/Configuration.java 2006-07-26 09:11:56 UTC (rev 10153)
+++ branches/Branch_3_2/Hibernate3/src/org/hibernate/cfg/Configuration.java 2006-07-26 11:32:19 UTC (rev 10154)
@@ -34,7 +34,9 @@
import org.hibernate.EmptyInterceptor;
import org.hibernate.HibernateException;
import org.hibernate.Interceptor;
+import org.hibernate.InvalidMappingException;
import org.hibernate.MappingException;
+import org.hibernate.MappingNotFoundException;
import org.hibernate.SessionFactory;
import org.hibernate.proxy.EntityNotFoundDelegate;
import org.hibernate.dialect.Dialect;
@@ -271,20 +273,22 @@
public Configuration addFile(String xmlFile) throws MappingException {
log.info( "Reading mappings from file: " + xmlFile );
try {
- List errors = new ArrayList();
- org.dom4j.Document doc = xmlHelper.createSAXReader( xmlFile, errors, entityResolver )
- .read( new File( xmlFile ) );
- if ( errors.size() != 0 ) {
- throw new MappingException( "invalid mapping", (Throwable) errors.get( 0 ) );
+ File file = new File( xmlFile );
+ if(file.exists()) {
+ List errors = new ArrayList();
+ org.dom4j.Document doc = xmlHelper.createSAXReader( xmlFile, errors, entityResolver )
+ .read( file );
+ if ( errors.size() != 0 ) {
+ throw new MappingException( "invalid mapping", (Throwable) errors.get( 0 ) );
+ }
+ add( doc );
+ return this;
+ } else {
+ throw new MappingNotFoundException("file", file.toString());
}
- add( doc );
- return this;
}
catch (Exception e) {
- throw new MappingException(
- "Could not read mapping document from file: " + xmlFile,
- e
- );
+ throw new InvalidMappingException("file", xmlFile, e);
}
}
@@ -299,10 +303,7 @@
addInputStream( new FileInputStream( xmlFile ) );
}
catch (Exception e) {
- throw new MappingException(
- "Could not read mapping document from file: " + xmlFile.getPath(),
- e
- );
+ throw new InvalidMappingException( "file", xmlFile.getPath(),e );
}
return this;
}
@@ -332,8 +333,8 @@
}
}
- // If deserialization failed
- if ( doc == null ) {
+ // If deserialization failed or cached file does not exist
+ if ( doc == null && xmlFile.exists()) {
log.info( "Reading mappings from file: " + xmlFile );
doc = xmlHelper.createSAXReader( xmlFile.getAbsolutePath(), errors, entityResolver )
.read( xmlFile );
@@ -344,6 +345,8 @@
catch (SerializationException e) {
log.warn( "Could not write cached file: " + lazyfile, e );
}
+ } else {
+ throw new MappingNotFoundException("file", xmlFile.toString());
}
if ( errors.size() != 0 ) {
@@ -353,10 +356,7 @@
return this;
}
catch (Exception e) {
- throw new MappingException(
- "Could not read mapping document from file: " + xmlFile,
- e
- );
+ throw new InvalidMappingException("file", xmlFile.toString(), e);
}
}
@@ -402,7 +402,7 @@
addInputStream( url.openStream() );
}
catch (Exception e) {
- throw new MappingException( "Could not read mapping document from URL: " + url, e );
+ throw new InvalidMappingException( "URL", ""+url, e );
}
return this;
}
@@ -466,7 +466,7 @@
return this;
}
catch (DocumentException e) {
- throw new MappingException( "Could not parse mapping document in input stream", e );
+ throw new InvalidMappingException( "input stream", null, e );
}
finally {
try {
@@ -488,13 +488,13 @@
log.info( "Reading mappings from resource: " + path );
InputStream rsrc = classLoader.getResourceAsStream( path );
if ( rsrc == null ) {
- throw new MappingException( "Resource: " + path + " not found" );
+ throw new MappingNotFoundException( "resource", path );
}
try {
return addInputStream( rsrc );
}
catch (MappingException me) {
- throw new MappingException( "Could not read mappings from resource: " + path, me );
+ throw new InvalidMappingException( "resource", path, me );
}
}
@@ -514,13 +514,13 @@
rsrc = Environment.class.getClassLoader().getResourceAsStream( path );
}
if ( rsrc == null ) {
- throw new MappingException( "Resource: " + path + " not found" );
+ throw new MappingNotFoundException( "resource", path );
}
try {
return addInputStream( rsrc );
}
catch (MappingException me) {
- throw new MappingException( "Could not read mappings from resource: " + path, me );
+ throw new InvalidMappingException( "resource", path, me );
}
}
@@ -535,16 +535,14 @@
log.info( "Reading mappings from resource: " + fileName );
InputStream rsrc = persistentClass.getClassLoader().getResourceAsStream( fileName );
if ( rsrc == null ) {
- throw new MappingException( "Resource: " + fileName + " not found" );
+ throw new MappingNotFoundException( "resource", fileName );
}
try {
return addInputStream( rsrc );
}
catch (MappingException me) {
- throw new MappingException(
- "Could not read mappings from resource: " + fileName,
- me
- );
+ throw new InvalidMappingException(
+ "resource", fileName, me );
}
}
@@ -564,8 +562,8 @@
jarFile = new JarFile( jar );
}
catch (IOException ioe) {
- throw new MappingException(
- "Could not read mapping documents from jar: " + jar.getName(),
+ throw new InvalidMappingException(
+ "Could not read mapping documents from jar: " + jar.getName(), "jar", jar.getName(),
ioe
);
}
@@ -581,8 +579,10 @@
addInputStream( jarFile.getInputStream( ze ) );
}
catch (Exception e) {
- throw new MappingException(
- "Could not read mapping documents from jar: " + jar.getName(),
+ throw new InvalidMappingException(
+ "Could not read mapping documents from jar: " + jar.getName(),
+ "jar",
+ jar.getName(),
e
);
}
|