|
From: <one...@us...> - 2003-01-03 13:36:04
|
Update of /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/impl
In directory sc8-pr-cvs1:/tmp/cvs-serv2643/src/net/sf/hibernate/impl
Modified Files:
FilterImpl.java QueryImpl.java ScheduledCollectionAction.java
ScheduledCollectionRecreate.java
ScheduledCollectionRemove.java ScheduledCollectionUpdate.java
SessionFactoryImpl.java SessionImpl.java
Removed Files:
CollectionPersister.java
Log Message:
removed exceptions that occur if an object is saved or deleted multiple times in a session
added <parent> subelement to <composite-element> and <nested-composite-element>
Index: FilterImpl.java
===================================================================
RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/impl/FilterImpl.java,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -C2 -d -r1.1.1.1 -r1.2
*** FilterImpl.java 1 Jan 2003 13:55:45 -0000 1.1.1.1
--- FilterImpl.java 3 Jan 2003 13:36:01 -0000 1.2
***************
*** 27,33 ****
*/
public Iterator iterate() throws SQLException, HibernateException {
! values.add(0, null);
! types.add(0, null);
! return session.iterateFilter(collection, queryString, values.toArray(), (Type[]) types.toArray(NO_TYPES), selection, namedParams);
}
--- 27,33 ----
*/
public Iterator iterate() throws SQLException, HibernateException {
! getValues().add(0, null);
! getTypes().add(0, null);
! return getSession().iterateFilter(collection, getQueryString(), getValues().toArray(), (Type[]) getTypes().toArray(NO_TYPES), getSelection(), getNamedParams() );
}
***************
*** 36,42 ****
*/
public List list() throws SQLException, HibernateException {
! values.add(0, null);
! types.add(0, null);
! return session.filter(collection, queryString, values.toArray(), (Type[]) types.toArray(NO_TYPES), selection, namedParams);
}
--- 36,42 ----
*/
public List list() throws SQLException, HibernateException {
! getValues().add(0, null);
! getTypes().add(0, null);
! return getSession().filter(collection, getQueryString(), getValues().toArray(), (Type[]) getTypes().toArray(NO_TYPES), getSelection(), getNamedParams() );
}
Index: QueryImpl.java
===================================================================
RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/impl/QueryImpl.java,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -C2 -d -r1.1.1.1 -r1.2
*** QueryImpl.java 1 Jan 2003 13:55:48 -0000 1.1.1.1
--- QueryImpl.java 3 Jan 2003 13:36:01 -0000 1.2
***************
*** 2,6 ****
package net.sf.hibernate.impl;
- import java.util.HashMap;
import java.io.Serializable;
import java.math.BigDecimal;
--- 2,5 ----
***************
*** 10,17 ****
import java.util.Collection;
import java.util.Date;
! import java.util.Map;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import net.sf.hibernate.Hibernate;
--- 9,17 ----
import java.util.Collection;
import java.util.Date;
! import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
+ import java.util.Map;
import net.sf.hibernate.Hibernate;
***************
*** 21,40 ****
import net.sf.hibernate.Query;
import net.sf.hibernate.ScrollableResults;
! import net.sf.hibernate.engine.*;
import net.sf.hibernate.util.ArrayHelper;
import net.sf.hibernate.util.ReflectHelper;
import net.sf.hibernate.util.StringHelper;
- import net.sf.hibernate.type.Type;
- import net.sf.hibernate.type.TypeFactory;
public class QueryImpl implements Query {
! final SessionImplementor session;
! String queryString;
! RowSelection selection;
! ArrayList values = new ArrayList(4);
! ArrayList types = new ArrayList(4);
! Map namedParams = new HashMap(4);
public QueryImpl(String queryString, SessionImplementor session) {
--- 21,42 ----
import net.sf.hibernate.Query;
import net.sf.hibernate.ScrollableResults;
! import net.sf.hibernate.engine.RowSelection;
! import net.sf.hibernate.engine.SessionImplementor;
! import net.sf.hibernate.engine.TypedValue;
! import net.sf.hibernate.type.Type;
! import net.sf.hibernate.type.TypeFactory;
import net.sf.hibernate.util.ArrayHelper;
import net.sf.hibernate.util.ReflectHelper;
import net.sf.hibernate.util.StringHelper;
public class QueryImpl implements Query {
! private final SessionImplementor session;
! private String queryString;
! private RowSelection selection;
! private ArrayList values = new ArrayList(4);
! private ArrayList types = new ArrayList(4);
! private Map namedParams = new HashMap(4);
public QueryImpl(String queryString, SessionImplementor session) {
***************
*** 46,63 ****
static final Type[] NO_TYPES = new Type[0];
- public static final class TypedValue {
- protected TypedValue(Type t, Object o) {
- type=t; value=o;
- }
- public Type type;
- public Object value;
- }
-
- public static final class RowSelection {
- public Integer firstRow;
- public Integer maxRows;
- public Integer timeout;
- }
-
public Iterator iterate() throws SQLException, HibernateException {
return session.iterate(queryString, values.toArray(), (Type[]) types.toArray(NO_TYPES), selection, namedParams);
--- 48,51 ----
***************
*** 73,85 ****
public void setMaxResults(int maxResults) {
! selection.maxRows = new Integer(maxResults);
}
public void setTimeout(int timeout) {
! selection.timeout = new Integer(timeout);
}
public void setFirstResult(int firstResult) {
! selection.firstRow = new Integer(firstResult);
}
--- 61,73 ----
public void setMaxResults(int maxResults) {
! selection.setMaxRows(new Integer(maxResults));
}
public void setTimeout(int timeout) {
! selection.setTimeout(new Integer(timeout));
}
public void setFirstResult(int firstResult) {
! selection.setFirstRow(new Integer(firstResult));
}
***************
*** 330,333 ****
--- 318,345 ----
catch (PropertyNotFoundException pnfe) {}
}
+ }
+
+ SessionImplementor getSession() {
+ return session;
+ }
+
+ ArrayList getValues() {
+ return values;
+ }
+
+ ArrayList getTypes() {
+ return types;
+ }
+
+ RowSelection getSelection() {
+ return selection;
+ }
+
+ String getQueryString() {
+ return queryString;
+ }
+
+ Map getNamedParams() {
+ return namedParams;
}
Index: ScheduledCollectionAction.java
===================================================================
RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/impl/ScheduledCollectionAction.java,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -C2 -d -r1.1.1.1 -r1.2
*** ScheduledCollectionAction.java 1 Jan 2003 13:55:48 -0000 1.1.1.1
--- ScheduledCollectionAction.java 3 Jan 2003 13:36:01 -0000 1.2
***************
*** 5,8 ****
--- 5,9 ----
import net.sf.hibernate.cache.CacheException;
+ import net.sf.hibernate.collection.*;
import net.sf.hibernate.engine.*;
import net.sf.hibernate.impl.SessionImpl.Executable;
Index: ScheduledCollectionRecreate.java
===================================================================
RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/impl/ScheduledCollectionRecreate.java,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -C2 -d -r1.1.1.1 -r1.2
*** ScheduledCollectionRecreate.java 1 Jan 2003 13:55:48 -0000 1.1.1.1
--- ScheduledCollectionRecreate.java 3 Jan 2003 13:36:01 -0000 1.2
***************
*** 5,8 ****
--- 5,9 ----
import java.sql.SQLException;
import net.sf.hibernate.*;
+ import net.sf.hibernate.collection.*;
import net.sf.hibernate.collection.PersistentCollection;
import net.sf.hibernate.engine.*;
Index: ScheduledCollectionRemove.java
===================================================================
RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/impl/ScheduledCollectionRemove.java,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -C2 -d -r1.1.1.1 -r1.2
*** ScheduledCollectionRemove.java 1 Jan 2003 13:55:48 -0000 1.1.1.1
--- ScheduledCollectionRemove.java 3 Jan 2003 13:36:01 -0000 1.2
***************
*** 5,8 ****
--- 5,9 ----
import java.sql.SQLException;
import net.sf.hibernate.*;
+ import net.sf.hibernate.collection.*;
import net.sf.hibernate.engine.*;
Index: ScheduledCollectionUpdate.java
===================================================================
RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/impl/ScheduledCollectionUpdate.java,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -C2 -d -r1.1.1.1 -r1.2
*** ScheduledCollectionUpdate.java 1 Jan 2003 13:55:49 -0000 1.1.1.1
--- ScheduledCollectionUpdate.java 3 Jan 2003 13:36:01 -0000 1.2
***************
*** 5,8 ****
--- 5,9 ----
import java.sql.SQLException;
import net.sf.hibernate.*;
+ import net.sf.hibernate.collection.*;
import net.sf.hibernate.collection.PersistentCollection;
import net.sf.hibernate.engine.*;
Index: SessionFactoryImpl.java
===================================================================
RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/impl/SessionFactoryImpl.java,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -C2 -d -r1.1.1.1 -r1.2
*** SessionFactoryImpl.java 1 Jan 2003 13:55:53 -0000 1.1.1.1
--- SessionFactoryImpl.java 3 Jan 2003 13:36:01 -0000 1.2
***************
*** 45,48 ****
--- 45,49 ----
import net.sf.hibernate.SessionFactory;
import net.sf.hibernate.cache.Timestamper;
+ import net.sf.hibernate.collection.*;
import net.sf.hibernate.connection.ConnectionProvider;
import net.sf.hibernate.connection.ConnectionProviderFactory;
Index: SessionImpl.java
===================================================================
RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/impl/SessionImpl.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** SessionImpl.java 2 Jan 2003 11:01:49 -0000 1.3
--- SessionImpl.java 3 Jan 2003 13:36:01 -0000 1.4
***************
*** 47,50 ****
--- 47,51 ----
import net.sf.hibernate.type.TypeFactory;
import net.sf.hibernate.cache.CacheException;
+ import net.sf.hibernate.collection.*;
import net.sf.hibernate.collection.PersistentCollection;
import net.sf.hibernate.collection.ArrayHolder;
***************
*** 482,487 ****
if (object==null) throw new NullPointerException("attempted to save null");
! Serializable id = getPersister(object).getIdentifierGenerator().generate(this, object);
! return doSave(object, id);
}
--- 483,495 ----
if (object==null) throw new NullPointerException("attempted to save null");
! EntityEntry e = getEntry(object);
! if ( e!=null ) {
! log.trace( "object already associated with session" );
! return e.id;
! }
! else {
! Serializable id = getPersister(object).getIdentifierGenerator().generate(this, object);
! return doSave(object, id);
! }
}
***************
*** 494,498 ****
if (id==null) throw new NullPointerException("null identifier passed to insert()");
! doSave(object, id);
}
--- 502,516 ----
if (id==null) throw new NullPointerException("null identifier passed to insert()");
! EntityEntry e = getEntry(object);
! if ( e!=null ) {
! if ( !id.equals(e.id) ) throw new PersistentObjectException(
! "object passed to save() was already persistent: " +
! infoString(e.persister, id)
! );
! log.trace( "object already associated with session" );
! }
! else {
! doSave(object, id);
! }
}
***************
*** 500,508 ****
ClassPersister persister = getPersister(object);
!
! if ( isEntryFor(object) ) throw new PersistentObjectException(
! "attempted to save an instance of that was already associated with the Session: " + infoString(persister, id)
! );
!
Key key = null;
final boolean identityCol;
--- 518,522 ----
ClassPersister persister = getPersister(object);
!
Key key = null;
final boolean identityCol;
***************
*** 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);
--- 533,545 ----
}
! 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);
***************
*** 695,699 ****
final ClassPersister persister;
if (entry==null) {
! log.trace("deleting a transient object");
persister = getPersister(object);
--- 712,716 ----
final ClassPersister persister;
if (entry==null) {
! log.trace("deleting a transient instance");
persister = getPersister(object);
***************
*** 703,707 ****
if (old!=null) {
! throw new HibernateException( "Another object with the same id was already associated with the session: " + infoString(persister, id) );
}
--- 720,727 ----
if (old!=null) {
! throw new HibernateException(
! "Another object with the same id was already associated with the session: " +
! infoString(persister, id)
! );
}
***************
*** 721,730 ****
}
else {
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) );
--- 741,757 ----
}
else {
+ log.trace("deleting a persistent instance");
+
+ if ( entry.status==DELETED || entry.status==GONE ) {
+ log.trace("object was already deleted");
+ return;
+ }
persister = entry.persister;
}
!
! if ( !persister.isMutable() ) throw new HibernateException(
! "attempted to delete an object of immutable class: " +
! infoString(persister)
! );
if ( log.isTraceEnabled() ) log.trace( "deleting " + infoString(persister, entry.id) );
***************
*** 882,887 ****
if ( persister.hasIdentifierProperty() ) {
! if ( !isEntryFor(object) ) { //the object is transient
!
Serializable id = persister.getIdentifier(object);
--- 909,918 ----
if ( persister.hasIdentifierProperty() ) {
! if ( isEntryFor(object) ) {
! log.trace("object already associated with session");
! // do nothing
! }
! else {
! // the object is transient
Serializable id = persister.getIdentifier(object);
***************
*** 907,912 ****
Object object = HibernateProxyHelper.unproxy(obj, this);
! if ( !isEntryFor(object) ) { //the object is transient
!
ClassPersister persister = getPersister(object);
if ( persister.hasIdentifierProperty() ) {
--- 938,948 ----
Object object = HibernateProxyHelper.unproxy(obj, this);
! if ( isEntryFor(object) ) {
! // do nothing for persistent instances
! log.trace("object already associated with session");
! }
! else {
!
! // the object is transient
ClassPersister persister = getPersister(object);
if ( persister.hasIdentifierProperty() ) {
***************
*** 927,931 ****
}
! // else do nothing for persistent instances
}
--- 963,967 ----
}
!
}
***************
*** 943,947 ****
else {
if ( !e.id.equals(id) ) throw new PersistentObjectException(
! "The instance passed to update() was already persistent with a different id: " + e.id
);
}
--- 979,984 ----
else {
if ( !e.id.equals(id) ) throw new PersistentObjectException(
! "The instance passed to update() was already persistent: " +
! infoString(e.persister, id)
);
}
***************
*** 1006,1010 ****
}
! public List find(String query, Object[] values, Type[] types, QueryImpl.RowSelection selection, Map namedParams) throws SQLException, HibernateException {
if ( log.isTraceEnabled() ) {
--- 1043,1047 ----
}
! public List find(String query, Object[] values, Type[] types, RowSelection selection, Map namedParams) throws SQLException, HibernateException {
if ( log.isTraceEnabled() ) {
***************
*** 1065,1069 ****
}
! public Iterator iterate(String query, Object[] values, Type[] types, QueryImpl.RowSelection selection, Map namedParams) throws HibernateException, SQLException {
if ( log.isTraceEnabled() ) {
--- 1102,1106 ----
}
! public Iterator iterate(String query, Object[] values, Type[] types, RowSelection selection, Map namedParams) throws HibernateException, SQLException {
if ( log.isTraceEnabled() ) {
***************
*** 1094,1098 ****
}
! public ScrollableResults scroll(String query, Object[] values, Type[] types, QueryImpl.RowSelection selection, Map namedParams) throws HibernateException, SQLException {
if ( log.isTraceEnabled() ) {
--- 1131,1135 ----
}
! public ScrollableResults scroll(String query, Object[] values, Type[] types, RowSelection selection, Map namedParams) throws HibernateException, SQLException {
if ( log.isTraceEnabled() ) {
***************
*** 1470,1474 ****
if ( log.isTraceEnabled() ) log.trace( "attempting to resolve " + infoString(theClass, id) );
- final Object finalResult;
final boolean isOptionalObject = optionalObject!=null;
--- 1507,1510 ----
***************
*** 1484,1488 ****
}
lock(old, lockMode);
! finalResult = old;
}
--- 1520,1524 ----
}
lock(old, lockMode);
! return old;
}
***************
*** 1493,1508 ****
if (entry!=null) {
ClassPersister subclassPersister = getPersister( entry.getSubclass() );
! finalResult = (isOptionalObject) ? optionalObject : subclassPersister.instantiate(id);
! addEntry(finalResult, LOADING, null, id, null, LockMode.NONE, true, subclassPersister); //make it circular-reference safe
! addEntity( new Key(id, persister), finalResult );
! Object[] values = entry.assemble(finalResult, id, subclassPersister, this); // intializes cached by side-effect
Type[] types = subclassPersister.getPropertyTypes();
TypeFactory.deepCopy(values, types, values);
Object version = Versioning.getVersion(values, subclassPersister);
if ( log.isTraceEnabled() ) log.trace("Cached Version: " + version);
! addEntry(finalResult, LOADED, values, id, version, LockMode.NONE, true, subclassPersister);
// upgrade the lock if necessary:
! lock(finalResult, lockMode);
//if ( persister.isMutable() ) tableAccesses.add( persister.getQualifiedTableName() ); // TODO: not necessary for readonly cache
}
--- 1529,1545 ----
if (entry!=null) {
ClassPersister subclassPersister = getPersister( entry.getSubclass() );
! Object result = (isOptionalObject) ? optionalObject : subclassPersister.instantiate(id);
! addEntry(result, LOADING, null, id, null, LockMode.NONE, true, subclassPersister); //make it circular-reference safe
! addEntity( new Key(id, persister), result );
! Object[] values = entry.assemble(result, id, subclassPersister, this); // intializes cached by side-effect
Type[] types = subclassPersister.getPropertyTypes();
TypeFactory.deepCopy(values, types, values);
Object version = Versioning.getVersion(values, subclassPersister);
if ( log.isTraceEnabled() ) log.trace("Cached Version: " + version);
! addEntry(result, LOADED, values, id, version, LockMode.NONE, true, subclassPersister);
// upgrade the lock if necessary:
! lock(result, lockMode);
//if ( persister.isMutable() ) tableAccesses.add( persister.getQualifiedTableName() ); // TODO: not necessary for readonly cache
+ return result;
}
***************
*** 1511,1520 ****
//otherwise go ahead and load it!
// Note: you can't use "for update" with an outer join
! finalResult = persister.load(id, optionalObject, lockMode, this);
}
}
- return finalResult;
}
--- 1548,1556 ----
//otherwise go ahead and load it!
// Note: you can't use "for update" with an outer join
! return persister.load(id, optionalObject, lockMode, this);
}
}
}
***************
*** 2191,2203 ****
if ( log.isTraceEnabled() ) log.trace( "initializing collection " + infoString(ce.loadedPersister, ce.loadedID) );
!
! CollectionPersister p = ce.loadedPersister;
! collection.beforeInitialize(p);
! p.getInitializer().initialize(ce.loadedID, collection, this);
//tableAccesses.add( ce.loadedPersister.getQualifiedTableName() );
ce.initialized = true;
ce.postInitialize(collection);
! if (!writing) ce.loadedPersister.cache(ce.loadedID, collection, this);
}
--- 2227,2243 ----
if ( log.isTraceEnabled() ) log.trace( "initializing collection " + infoString(ce.loadedPersister, ce.loadedID) );
!
! CollectionPersister persister = ce.loadedPersister;
! Serializable id = ce.loadedID;
!
! Object owner = getEntity( new Key( id, getPersister( persister.getOwnerClass() ) ) );
!
! collection.beforeInitialize(persister);
! persister.getInitializer().initialize(id, collection, owner, this);
//tableAccesses.add( ce.loadedPersister.getQualifiedTableName() );
ce.initialized = true;
ce.postInitialize(collection);
! if (!writing) persister.cache(id, collection, this);
}
***************
*** 2323,2327 ****
! private FilterTranslator getFilterTranslator(Object collection, String filter, Object[] values, Type[] types, QueryImpl.RowSelection selection, Map namedParams, boolean scalar) throws SQLException, HibernateException {
if ( log.isTraceEnabled() ) {
--- 2363,2367 ----
! private FilterTranslator getFilterTranslator(Object collection, String filter, Object[] values, Type[] types, RowSelection selection, Map namedParams, boolean scalar) throws SQLException, HibernateException {
if ( log.isTraceEnabled() ) {
***************
*** 2360,2364 ****
}
! public List filter(Object collection, String filter, Object[] values, Type[] types, QueryImpl.RowSelection selection, Map namedParams) throws SQLException, HibernateException {
String[] concreteFilters = QueryTranslator.concreteQueries(filter, factory);
--- 2400,2404 ----
}
! public List filter(Object collection, String filter, Object[] values, Type[] types, RowSelection selection, Map namedParams) throws SQLException, HibernateException {
String[] concreteFilters = QueryTranslator.concreteQueries(filter, factory);
***************
*** 2386,2390 ****
}
! public Iterator iterateFilter(Object collection, String filter, Object[] values, Type[] types, QueryImpl.RowSelection selection, Map namedParams) throws SQLException, HibernateException {
String[] concreteFilters = QueryTranslator.concreteQueries(filter, factory);
--- 2426,2430 ----
}
! public Iterator iterateFilter(Object collection, String filter, Object[] values, Type[] types, RowSelection selection, Map namedParams) throws SQLException, HibernateException {
String[] concreteFilters = QueryTranslator.concreteQueries(filter, factory);
--- CollectionPersister.java DELETED ---
|