|
From: <one...@us...> - 2003-01-22 13:09:22
|
Update of /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/impl
In directory sc8-pr-cvs1:/tmp/cvs-serv17676/sf/hibernate/impl
Modified Files:
DatastoreImpl.java SessionImpl.java
Log Message:
fixed a problem with unsaved-value attribute not being recognized for composite-id
added Interceptor.isUnsaved()
made save() aware of proxies
Index: DatastoreImpl.java
===================================================================
RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/impl/DatastoreImpl.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** DatastoreImpl.java 20 Jan 2003 12:48:11 -0000 1.6
--- DatastoreImpl.java 22 Jan 2003 13:09:19 -0000 1.7
***************
*** 410,413 ****
--- 410,420 ----
}
+ /**
+ * @see net.sf.hibernate.Interceptor#isUnsaved(java.lang.Object)
+ */
+ public Boolean isUnsaved(Object entity) {
+ return null;
+ }
+
}
Index: SessionImpl.java
===================================================================
RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/impl/SessionImpl.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -C2 -d -r1.10 -r1.11
*** SessionImpl.java 15 Jan 2003 12:49:01 -0000 1.10
--- SessionImpl.java 22 Jan 2003 13:09:19 -0000 1.11
***************
*** 488,494 ****
* object and returned.
*/
! public Serializable save(Object object) throws HibernateException {
! if (object==null) throw new NullPointerException("attempted to save null");
EntityEntry e = getEntry(object);
--- 488,496 ----
* object and returned.
*/
! public Serializable save(Object obj) throws HibernateException {
! if (obj==null) throw new NullPointerException("attempted to save null");
!
! Object object = HibernateProxyHelper.unproxy(obj, this);
EntityEntry e = getEntry(object);
***************
*** 510,514 ****
throw new JDBCException("Could not save object", sqle);
}
! return doSave(object, id);
}
--- 512,516 ----
throw new JDBCException("Could not save object", sqle);
}
! return doSave(object, obj, id);
}
***************
*** 517,525 ****
* Save a transient object with a manually assigned ID.
*/
! public void save(Object object, Serializable id) throws HibernateException {
! if (object==null) throw new NullPointerException("attempted to insert null");
if (id==null) throw new NullPointerException("null identifier passed to insert()");
EntityEntry e = getEntry(object);
if ( e!=null ) {
--- 519,529 ----
* Save a transient object with a manually assigned ID.
*/
! public void save(Object obj, Serializable id) throws HibernateException {
! if (obj==null) throw new NullPointerException("attempted to insert null");
if (id==null) throw new NullPointerException("null identifier passed to insert()");
+ Object object = HibernateProxyHelper.unproxy(obj, this);
+
EntityEntry e = getEntry(object);
if ( e!=null ) {
***************
*** 536,543 ****
}
! doSave(object, id);
}
! private Serializable doSave(Object object, Serializable id) throws HibernateException {
ClassPersister persister = getPersister(object);
--- 540,547 ----
}
! doSave(object, obj, id);
}
! private Serializable doSave(Object object, Object proxy, Serializable id) throws HibernateException {
ClassPersister persister = getPersister(object);
***************
*** 634,637 ****
--- 638,642 ----
addEntry(object, LOADED, values, id, Versioning.getVersion(values, persister), LockMode.WRITE, identityCol, persister);
//tableAccesses.add( persister.getQualifiedTableName() );
+ if (proxy!=object) proxiesByKey.put(key, proxy);
if (!identityCol) insertions.add( new ScheduledInsertion( id, values, object, persister, this ) );
***************
*** 989,1015 ****
if (e!=null && e.status!=DELETED) {
// do nothing for persistent instances
! log.trace("object already associated with session");
}
! else if (e!=null) { //e.status==DELETED
! save(object);
}
else {
// the object is transient
! ClassPersister persister = getPersister(object);
! if ( persister.hasIdentifierProperty() ) {
!
! Serializable id = persister.getIdentifier(object);
!
! if ( persister.isUnsaved(id) ) {
! save(object);
}
else {
! doUpdate(object, obj, id);
}
-
}
else {
! save(object);
}
--- 994,1040 ----
if (e!=null && e.status!=DELETED) {
// do nothing for persistent instances
! log.trace("saveOrUpdate() persistent instance");
}
! else if (e!=null) { //ie. e.status==DELETED
! log.trace("saveOrUpdate() deleted instance");
! save(obj);
}
else {
// the object is transient
! Boolean isUnsaved = interceptor.isUnsaved(object);
! if (isUnsaved==null) {
! // use unsaved-value
! ClassPersister persister = getPersister(object);
! if ( persister.hasIdentifierProperty() ) {
!
! Serializable id = persister.getIdentifier(object);
!
! if ( persister.isUnsaved(id) ) {
! if ( log.isTraceEnabled() ) log.trace("saveOrUpdate() unsaved instance with id: " + id);
! save(obj);
! }
! else {
! if ( log.isTraceEnabled() ) log.trace("saveOrUpdate() previously saved instance with id: " + id);
! doUpdate(object, obj, id);
!
! }
!
}
else {
! // no identifier property ... default to save()
! log.trace("saveOrUpdate() unsaved instance with no identifier property");
! save(obj);
}
}
else {
! if ( Boolean.TRUE.equals(isUnsaved) ) {
! log.trace("saveOrUpdate() unsaved instance");
! save(obj);
! }
! else {
! log.trace("saveOrUpdate() previously saved instance");
! update(obj);
! }
}
|