|
From: <one...@us...> - 2002-12-06 12:22:24
|
Update of /cvsroot/hibernate/Hibernate/cirrus/hibernate/impl
In directory sc8-pr-cvs1:/tmp/cvs-serv1496
Modified Files:
SessionImpl.java
Log Message:
fixed a bug parsing upper case IS NOT NULL, NOT IN, etc
improved some exception messages (incl patch by Max Andersen)
added Resin support
Index: SessionImpl.java
===================================================================
RCS file: /cvsroot/hibernate/Hibernate/cirrus/hibernate/impl/SessionImpl.java,v
retrieving revision 1.154
retrieving revision 1.155
diff -C2 -d -r1.154 -r1.155
*** SessionImpl.java 28 Nov 2002 23:29:23 -0000 1.154
--- SessionImpl.java 6 Dec 2002 12:22:20 -0000 1.155
***************
*** 519,528 ****
}
! if ( log.isTraceEnabled() ) log.trace( "saving " + persister.getClassName() + '#' + ( (id==null) ? "native" : id ) );
if (!identityCol) { // if the id is generated by the database, we assign the key later
key = new Key(id, persister);
! if ( getEntity(key) != null ) throw new HibernateException("The generated ID is already in use");
persister.setIdentifier(object, id);
--- 519,528 ----
}
! if ( log.isTraceEnabled() ) log.trace( "saving " + infoString(persister,id));
if (!identityCol) { // if the id is generated by the database, we assign the key later
key = new Key(id, persister);
! if ( getEntity(key) != null ) throw new HibernateException("The generated ID is already in use" + infoString(persister, id));
persister.setIdentifier(object, id);
***************
*** 567,571 ****
key = new Key(id, persister);
! if ( getEntity(key) != null ) throw new HibernateException("The natively generated ID is already in use");
persister.setIdentifier(object, id);
--- 567,571 ----
key = new Key(id, persister);
! if ( getEntity(key) != null ) throw new HibernateException("The natively generated ID is already in use " + infoString(persister,id));
persister.setIdentifier(object, id);
***************
*** 717,726 ****
persister = entry.persister;
}
! if ( !persister.isMutable() ) throw new HibernateException( "attempted to delete an object of immutable class: " + persister.getClassName() );
if (entry.status!=LOADED) throw new ObjectDeletedException("Object was already deleted", entry.id);
! if ( log.isTraceEnabled() ) log.trace( "deleting " + persister.getClassName() + '#' + entry.id );
Type[] propTypes = persister.getPropertyTypes();
--- 717,726 ----
persister = entry.persister;
}
! if ( !persister.isMutable() ) throw new HibernateException( "attempted to delete an object of immutable class: " + infoString(persister));
if (entry.status!=LOADED) throw new ObjectDeletedException("Object was already deleted", entry.id);
! if ( log.isTraceEnabled() ) log.trace( "deleting " + infoString(persister, entry.id) );
Type[] propTypes = persister.getPropertyTypes();
***************
*** 890,894 ****
if (id==null) {
// assume this is a newly instantiated transient object
! throw new HibernateException("The given object has a null identifier property");
}
else {
--- 890,894 ----
if (id==null) {
// assume this is a newly instantiated transient object
! throw new HibernateException("The given object has a null identifier property " + infoString(persister));
}
else {
***************
*** 900,904 ****
}
else {
! throw new HibernateException("The given object has no identifier property - you must supply an id");
}
--- 900,904 ----
}
else {
! throw new HibernateException("The given object has no identifier property - you must supply an id " + infoString(persister));
}
***************
*** 955,971 ****
if ( !persister.isMutable() ) throw new HibernateException(
! "attempted to update an object of immutable class: " + persister.getClassName()
);
! if ( log.isTraceEnabled() ) log.trace( "updating " + persister.getClassName() + '#' + id );
Key key = new Key(id, persister);
Object old = getEntity(key);
if (old==object) {
! throw new AssertionFailure("Hibernate has a bug in update() ... or you are using an illegal id type");
}
else if ( old!=null ) {
throw new HibernateException(
! "Another object was associated with this id (the object with the given id was already loaded)"
);
}
--- 955,975 ----
if ( !persister.isMutable() ) throw new HibernateException(
! "attempted to update an object of immutable class: " + infoString(persister)
);
! if ( log.isTraceEnabled() ) log.trace( "updating " + infoString(persister, id) );
Key key = new Key(id, persister);
Object old = getEntity(key);
if (old==object) {
! throw new AssertionFailure(
! "Hibernate has a bug in update() ... or you are using an illegal id type" +
! infoString(persister, id)
! );
}
else if ( old!=null ) {
throw new HibernateException(
! "Another object was associated with this id (the object with the given id was already loaded) " +
! infoString(persister, id)
);
}
***************
*** 1179,1183 ****
if (e.status!=LOADED) throw new TransientObjectException("attempted to lock a deleted instance");
! if ( log.isTraceEnabled() ) log.trace( "locking " + persister.getClassName() + '#' + e.id + " in mode: " + lockMode );
if ( persister.hasCache() ) persister.getCache().lock(e.id);
--- 1183,1187 ----
if (e.status!=LOADED) throw new TransientObjectException("attempted to lock a deleted instance");
! if ( log.isTraceEnabled() ) log.trace( "locking " + infoString(persister, e.id) + " in mode: " + lockMode );
if ( persister.hasCache() ) persister.getCache().lock(e.id);
***************
*** 1403,1407 ****
private Object doLoadByClass(Class clazz, Serializable id, boolean checkDeleted, boolean allowProxyCreation) throws SQLException, HibernateException {
! if ( log.isTraceEnabled() ) log.trace( "loading " + clazz.getName() + '#' + id );
ClassPersister persister = getPersister(clazz);
--- 1407,1411 ----
private Object doLoadByClass(Class clazz, Serializable id, boolean checkDeleted, boolean allowProxyCreation) throws SQLException, HibernateException {
! if ( log.isTraceEnabled() ) log.trace( "loading " + infoString(clazz, id) );
ClassPersister persister = getPersister(clazz);
***************
*** 1457,1461 ****
if (lockMode==LockMode.WRITE) throw new HibernateException("Invalid lock mode for load()");
! if ( log.isTraceEnabled() ) log.trace( "loading " + clazz.getName() + '#' + id + " in lock mode: " + lockMode );
if (id==null) throw new NullPointerException("null is not a valid identifier");
--- 1461,1465 ----
if (lockMode==LockMode.WRITE) throw new HibernateException("Invalid lock mode for load()");
! if ( log.isTraceEnabled() ) log.trace( "loading " + infoString(clazz, id) + " in lock mode: " + lockMode );
if (id==null) throw new NullPointerException("null is not a valid identifier");
***************
*** 1494,1498 ****
//DONT need to flush before a load by id
! if ( log.isTraceEnabled() ) log.trace( "attempting to resolve " + theClass.getName() + '#' + id );
final Object finalResult;
--- 1498,1502 ----
//DONT need to flush before a load by id
! if ( log.isTraceEnabled() ) log.trace( "attempting to resolve " + infoString(theClass, id) );
final Object finalResult;
***************
*** 1756,1760 ****
) { // its dirty!
! if ( log.isTraceEnabled() ) log.trace("Updating entity: " + persister.getMappedClass().getName() + "#" + entry.id);
substitute = interceptor.onFlushDirty(
--- 1760,1764 ----
) { // its dirty!
! if ( log.isTraceEnabled() ) log.trace("Updating entity: " + infoString(persister, entry.id) );
substitute = interceptor.onFlushDirty(
***************
*** 2560,2563 ****
--- 2564,2633 ----
return many ? new JoinedIterator(results) : result;
+ }
+
+ // Exception message helpers
+ /**
+ * Generate small message that can be used in traces and exception
+ * messages.
+ * @param persister The persister for the class in question
+ * @param id The id
+ * @return String on the form [FooBar#id]
+ */
+ private String infoString(ClassPersister persister, Serializable id) {
+ StringBuffer s = new StringBuffer();
+ s.append("[");
+ if(persister==null) {
+ s.append("<ClassPersister is null>");
+ }
+ else {
+ s.append(persister.getClassName());
+ }
+ s.append("#");
+
+ if (id==null) {
+ s.append("native");
+ }
+ else {
+ s.append(id);
+ }
+ s.append("]");
+
+ return s.toString();
+
+ }
+
+ private String infoString(Class clazz, Serializable id) {
+ StringBuffer s = new StringBuffer();
+ s.append("[");
+ if(clazz==null) {
+ s.append("<Class is null>");
+ }
+ else {
+ s.append(clazz.getName());
+ }
+ s.append("#");
+
+ if (id==null) {
+ s.append("native");
+ }
+ else {
+ s.append(id);
+ }
+ s.append("]");
+
+ return s.toString();
+ }
+
+ private String infoString(ClassPersister persister) {
+ StringBuffer s = new StringBuffer();
+ s.append("[");
+ if (persister == null) {
+ s.append("<ClassPersister is null>");
+ }
+ else {
+ s.append(persister.getClassName());
+ }
+ s.append("]");
+ return s.toString();
}
|