Hibernate SVN: r16664 - core/branches/Branch_3_3/core/src/main/java/org/hibernate/event/def.
by hibernate-commits@lists.jboss.org
Author: gbadner
Date: 2009-06-02 04:44:49 -0400 (Tue, 02 Jun 2009)
New Revision: 16664
Added:
core/branches/Branch_3_3/core/src/main/java/org/hibernate/event/def/EventCache.java
Removed:
core/branches/Branch_3_3/core/src/main/java/org/hibernate/event/def/CopyCache.java
Modified:
core/branches/Branch_3_3/core/src/main/java/org/hibernate/event/def/DefaultMergeEventListener.java
Log:
HHH-3810 : rename CopyCache to EventCache to be more generic
Deleted: core/branches/Branch_3_3/core/src/main/java/org/hibernate/event/def/CopyCache.java
===================================================================
--- core/branches/Branch_3_3/core/src/main/java/org/hibernate/event/def/CopyCache.java 2009-06-02 08:07:35 UTC (rev 16663)
+++ core/branches/Branch_3_3/core/src/main/java/org/hibernate/event/def/CopyCache.java 2009-06-02 08:44:49 UTC (rev 16664)
@@ -1,244 +0,0 @@
-//$Id: $
-/*
- * Hibernate, Relational Persistence for Idiomatic Java
- *
- * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
- * indicated by the @author tags or express copyright attribution
- * statements applied by the authors. All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
- *
- * This copyrighted material is made available to anyone wishing to use, modify,
- * copy, or redistribute it subject to the terms and conditions of the GNU
- * Lesser General Public License, as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
- * for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this distribution; if not, write to:
- * Free Software Foundation, Inc.
- * 51 Franklin Street, Fifth Floor
- * Boston, MA 02110-1301 USA
- *
- */
-package org.hibernate.event.def;
-
-import java.util.Map;
-import java.util.Set;
-import java.util.Iterator;
-import java.util.Collection;
-
-import org.hibernate.util.IdentityMap;
-import org.hibernate.AssertionFailure;
-
-/**
- * CopyCache is intended to be the Map implementation used by
- * {@link DefaultMergeEventListener} to keep track of entities and their copies
- * being merged into the session. This implementation also tracks whether a
- * an entity in the CopyCache is included in the merge. This allows a
- * an entity and its copy to be added to a CopyCache before merge has cascaded
- * to that entity.
- *
- * @author Gail Badner
- */
-class CopyCache implements Map {
- private Map entityToCopyMap = IdentityMap.instantiate(10);
- // key is an entity involved with the merge;
- // value can be either a copy of the entity or the entity itself
-
- private Map entityToIncludeInMergeFlagMap = IdentityMap.instantiate(10);
- // key is an entity involved with the merge;
- // value is a flag indicating if the entity is included in the merge
-
- /**
- * Clears the CopyCache.
- */
- public void clear() {
- entityToCopyMap.clear();
- entityToIncludeInMergeFlagMap.clear();
- }
-
- /**
- * Returns true if this CopyCache contains a mapping for the specified entity.
- * @param entity must be non-null
- * @return true if this CopyCache contains a mapping for the specified entity
- * @throws NullPointerException if entity is null
- */
- public boolean containsKey(Object entity) {
- if ( entity == null ) {
- throw new NullPointerException( "null entities are not supported by " + getClass().getName() );
- }
- return entityToCopyMap.containsKey( entity );
- }
-
- /**
- * Returns true if this CopyCache maps one or more entities to the specified copy.
- * @param copy must be non-null
- * @return true if this CopyCache maps one or more entities to the specified copy
- * @throws NullPointerException if copy is null
- */
- public boolean containsValue(Object copy) {
- if ( copy == null ) {
- throw new NullPointerException( "null copies are not supported by " + getClass().getName() );
- }
- return entityToCopyMap.containsValue( copy );
- }
-
- /**
- * Returns a set view of the entity-to-copy mappings contained in this CopyCache.
- * @return set view of the entity-to-copy mappings contained in this CopyCache
- */
- public Set entrySet() {
- return entityToCopyMap.entrySet();
- }
-
- /**
- * Returns the copy to which this CopyCache maps the specified entity.
- * @param entity must be non-null
- * @return the copy to which this CopyCache maps the specified entity
- * @throws NullPointerException if entity is null
- */
- public Object get(Object entity) {
- if ( entity == null ) {
- throw new NullPointerException( "null entities are not supported by " + getClass().getName() );
- }
- return entityToCopyMap.get( entity );
- }
-
- /**
- * Returns true if this CopyCache contains no entity-copy mappings.
- * @return true if this CopyCache contains no entity-copy mappings
- */
- public boolean isEmpty() {
- return entityToCopyMap.isEmpty();
- }
-
- /**
- * Returns a set view of the entities contained in this CopyCache
- * @return a set view of the entities contained in this CopyCache
- */
- public Set keySet() {
- return entityToCopyMap.keySet();
- }
-
- /**
- * Associates the specified entity with the specified copy in this CopyCache;
- * @param entity must be non-null
- * @param copy must be non- null
- * @return previous copy associated with specified entity, or null if
- * there was no mapping for entity.
- * @throws NullPointerException if entity or copy is null
- */
- public Object put(Object entity, Object copy) {
- if ( entity == null || copy == null ) {
- throw new NullPointerException( "null entities and copies are not supported by " + getClass().getName() );
- }
- entityToIncludeInMergeFlagMap.put( entity, Boolean.FALSE );
- return entityToCopyMap.put( entity, copy );
- }
-
- /**
- * Associates the specified entity with the specified copy in this CopyCache;
- * @param entity must be non-null
- * @param copy must be non- null
- * @param isIncludedInMerge indicates if the entity is included in merge
- *
- * @return previous copy associated with specified entity, or null if
- * there was no mapping for entity.
- * @throws NullPointerException if entity or copy is null
- */
- /* package-private */ Object put(Object entity, Object copy, boolean isIncludedInMerge) {
- if ( entity == null || copy == null ) {
- throw new NullPointerException( "null entities and copies are not supported by " + getClass().getName() );
- }
- entityToIncludeInMergeFlagMap.put( entity, Boolean.valueOf( isIncludedInMerge ) );
- return entityToCopyMap.put( entity, copy );
- }
-
- /**
- * Copies all of the mappings from the specified map to this CopyCache
- * @param map keys and values must be non-null
- * @throws NullPointerException if any map keys or values are null
- */
- public void putAll(Map map) {
- for ( Iterator it=map.entrySet().iterator(); it.hasNext(); ) {
- Map.Entry entry = ( Map.Entry ) it.next();
- if ( entry.getKey() == null || entry.getValue() == null ) {
- throw new NullPointerException( "null entities and copies are not supported by " + getClass().getName() );
- }
- entityToCopyMap.put( entry.getKey(), entry.getValue() );
- entityToIncludeInMergeFlagMap.put( entry.getKey(), Boolean.FALSE );
- }
- }
-
- /**
- * Removes the mapping for this entity from this CopyCache if it is present
- * @param entity must be non-null
- * @return previous value associated with specified entity, or null if there was no mapping for entity.
- * @throws NullPointerException if entity is null
- */
- public Object remove(Object entity) {
- if ( entity == null ) {
- throw new NullPointerException( "null entities are not supported by " + getClass().getName() );
- }
- entityToIncludeInMergeFlagMap.remove( entity );
- return entityToCopyMap.remove( entity );
- }
-
- /**
- * Returns the number of entity-copy mappings in this CopyCache
- * @return the number of entity-copy mappings in this CopyCache
- */
- public int size() {
- return entityToCopyMap.size();
- }
-
- /**
- * Returns a collection view of the entity copies contained in this CopyCache.
- * @return a collection view of the entity copies contained in this CopyCache
- */
- public Collection values() {
- return entityToCopyMap.values();
- }
-
- /**
- * Returns true if the specified entity is included in the merge.
- * @param entity must be non-null
- * @return true if the specified entity is included in the merge.
- * @throws NullPointerException if entity is null
- */
- public boolean isIncludedInMerge(Object entity) {
- if ( entity == null ) {
- throw new NullPointerException( "null entities are not supported by " + getClass().getName() );
- }
- return ( ( Boolean ) entityToIncludeInMergeFlagMap.get( entity ) ).booleanValue();
- }
-
- /**
- * Set flag to indicate if an entity is included in the merge.
- * @param entity must be non-null and this CopyCache must contain a mapping for this entity
- * @return true if the specified entity is included in the merge
- * @throws NullPointerException if entity is null
- * @throws AssertionFailure if this CopyCache does not contain a mapping for the specified entity
- */
- /* package-private */ void setIncludedInMerge(Object entity, boolean isIncludedInMerge) {
- if ( entity == null ) {
- throw new NullPointerException( "null entities are not supported by " + getClass().getName() );
- }
- if ( ! entityToIncludeInMergeFlagMap.containsKey( entity ) ||
- ! entityToCopyMap.containsKey( entity ) ) {
- throw new AssertionFailure( "called CopyCache.setInMergeProcess() for entity not found in CopyCache" );
- }
- entityToIncludeInMergeFlagMap.put( entity, Boolean.valueOf( isIncludedInMerge ) );
- }
-
- /**
- * Returns the copy-entity mappings
- * @return the copy-entity mappings
- */
- public Map getMergeMap() {
- return IdentityMap.invert( entityToCopyMap );
- }
-}
\ No newline at end of file
Modified: core/branches/Branch_3_3/core/src/main/java/org/hibernate/event/def/DefaultMergeEventListener.java
===================================================================
--- core/branches/Branch_3_3/core/src/main/java/org/hibernate/event/def/DefaultMergeEventListener.java 2009-06-02 08:07:35 UTC (rev 16663)
+++ core/branches/Branch_3_3/core/src/main/java/org/hibernate/event/def/DefaultMergeEventListener.java 2009-06-02 08:44:49 UTC (rev 16664)
@@ -70,7 +70,7 @@
private static final Logger log = LoggerFactory.getLogger(DefaultMergeEventListener.class);
protected Map getMergeMap(Object anything) {
- return ( ( CopyCache ) anything ).getMergeMap();
+ return ( ( EventCache ) anything ).invertMap();
}
/**
@@ -80,7 +80,7 @@
* @throws HibernateException
*/
public void onMerge(MergeEvent event) throws HibernateException {
- CopyCache copyCache = new CopyCache();
+ EventCache copyCache = new EventCache();
onMerge( event, copyCache );
// TODO: iteratively get transient entities and retry merge until one of the following conditions:
// 1) transientCopyCache.size() == 0
@@ -110,8 +110,8 @@
copyCache = null;
}
- protected CopyCache getTransientCopyCache(MergeEvent event, CopyCache copyCache) {
- CopyCache transientCopyCache = new CopyCache();
+ protected EventCache getTransientCopyCache(MergeEvent event, EventCache copyCache) {
+ EventCache transientCopyCache = new EventCache();
for ( Iterator it=copyCache.entrySet().iterator(); it.hasNext(); ) {
Map.Entry mapEntry = ( Map.Entry ) it.next();
Object entity = mapEntry.getKey();
@@ -131,7 +131,7 @@
);
}
else if ( copyEntry.getStatus() == Status.SAVING ) {
- transientCopyCache.put( entity, copy, copyCache.isIncludedInMerge( entity ) );
+ transientCopyCache.put( entity, copy, copyCache.isOperatedOn( entity ) );
}
else if ( copyEntry.getStatus() != Status.MANAGED && copyEntry.getStatus() != Status.READ_ONLY ) {
throw new AssertionFailure( "Merged entity does not have status set to MANAGED or READ_ONLY; "+copy+" status="+copyEntry.getStatus() );
@@ -140,7 +140,7 @@
return transientCopyCache;
}
- protected void retryMergeTransientEntities(MergeEvent event, Map transientCopyCache, CopyCache copyCache) {
+ protected void retryMergeTransientEntities(MergeEvent event, Map transientCopyCache, EventCache copyCache) {
// TODO: The order in which entities are saved may matter (e.g., a particular transient entity
// may need to be saved before other transient entities can be saved;
// Keep retrying the batch of transient entities until either:
@@ -169,7 +169,7 @@
*/
public void onMerge(MergeEvent event, Map copiedAlready) throws HibernateException {
- final CopyCache copyCache = ( CopyCache ) copiedAlready;
+ final EventCache copyCache = ( EventCache ) copiedAlready;
final EventSource source = event.getSession();
final Object original = event.getOriginal();
@@ -192,14 +192,14 @@
}
if ( copyCache.containsKey( entity ) &&
- ( copyCache.isIncludedInMerge( entity ) ) ) {
+ ( copyCache.isOperatedOn( entity ) ) ) {
log.trace("already in merge process");
event.setResult( entity );
}
else {
if ( copyCache.containsKey( entity ) ) {
log.trace("already in copyCache; setting in merge process");
- copyCache.setIncludedInMerge( entity, true );
+ copyCache.setOperatedOn( entity, true );
}
event.setEntity( entity );
int entityState = -1;
@@ -261,7 +261,7 @@
final EventSource source = event.getSession();
final EntityPersister persister = source.getEntityPersister( event.getEntityName(), entity );
- ( ( CopyCache ) copyCache ).put( entity, entity, true ); //before cascade!
+ ( ( EventCache ) copyCache ).put( entity, entity, true ); //before cascade!
cascadeOnMerge(source, persister, entity, copyCache);
copyValues(persister, entity, entity, source, copyCache);
@@ -295,7 +295,7 @@
persister.setIdentifier( copyCache.get( entity ), id, source.getEntityMode() );
}
else {
- ( ( CopyCache ) copyCache ).put( entity, persister.instantiate( id, source.getEntityMode() ), true ); //before cascade!
+ ( ( EventCache ) copyCache ).put( entity, persister.instantiate( id, source.getEntityMode() ), true ); //before cascade!
//TODO: should this be Session.instantiate(Persister, ...)?
}
final Object copy = copyCache.get( entity );
@@ -333,7 +333,7 @@
"' from original entity is not in copyCache; " + propertyName + " =["+propertyFromEntity+"]");
throw ex;
}
- if ( ( ( CopyCache ) copyCache ).isIncludedInMerge( propertyFromEntity ) ) {
+ if ( ( ( EventCache ) copyCache ).isOperatedOn( propertyFromEntity ) ) {
log.trace( "property '" + copyEntry.getEntityName() + "." + propertyName +
"' from original entity is in copyCache and is in the process of being merged; " +
propertyName + " =["+propertyFromEntity+"]");
@@ -397,7 +397,7 @@
entityIsTransient(event, copyCache);
}
else {
- ( ( CopyCache ) copyCache ).put( entity, result, true ); //before cascade!
+ ( ( EventCache ) copyCache ).put( entity, result, true ); //before cascade!
final Object target = source.getPersistenceContext().unproxy(result);
if ( target == entity ) {
Copied: core/branches/Branch_3_3/core/src/main/java/org/hibernate/event/def/EventCache.java (from rev 16662, core/branches/Branch_3_3/core/src/main/java/org/hibernate/event/def/CopyCache.java)
===================================================================
--- core/branches/Branch_3_3/core/src/main/java/org/hibernate/event/def/EventCache.java (rev 0)
+++ core/branches/Branch_3_3/core/src/main/java/org/hibernate/event/def/EventCache.java 2009-06-02 08:44:49 UTC (rev 16664)
@@ -0,0 +1,253 @@
+//$Id: $
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ *
+ */
+package org.hibernate.event.def;
+
+import java.util.Map;
+import java.util.Set;
+import java.util.Iterator;
+import java.util.Collection;
+
+import org.hibernate.util.IdentityMap;
+import org.hibernate.AssertionFailure;
+
+/**
+ * EventCache is a Map implementation that can be used by an event
+ * listener to keep track of entities involved in the operation
+ * being performed. This implementation allows entities to be added
+ * to the EventCache before the operation has cascaded to that
+ * entity.
+ * <p/>
+ * The following methods can be used by event listeners (and other
+ * classes) in the same package to add entities to an EventCache
+ * and indicate if the operation is being performed on the entity:<p/>
+ * {@link EventCache#put(Object entity, Object copy, boolean isOperatedOn)}
+ * <p/>
+ * The following method can be used by event listeners (and other
+ * classes) in the same package to indicate that the operation is being
+ * performed on an entity already in the EventCache:
+ * {@link EventCache#setOperatedOn(Object entity, boolean isOperatedOn)
+ *
+ * @author Gail Badner
+ */
+class EventCache implements Map {
+ private Map entityToCopyMap = IdentityMap.instantiate(10);
+ // key is an entity involved with the operation performed by the listener;
+ // value can be either a copy of the entity or the entity itself
+
+ private Map entityToOperatedOnFlagMap = IdentityMap.instantiate(10);
+ // key is an entity involved with the operation performed by the listener;
+ // value is a flag indicating if the listener explicitly operates on the entity
+
+ /**
+ * Clears the EventCache.
+ */
+ public void clear() {
+ entityToCopyMap.clear();
+ entityToOperatedOnFlagMap.clear();
+ }
+
+ /**
+ * Returns true if this EventCache contains a mapping for the specified entity.
+ * @param entity must be non-null
+ * @return true if this EventCache contains a mapping for the specified entity
+ * @throws NullPointerException if entity is null
+ */
+ public boolean containsKey(Object entity) {
+ if ( entity == null ) {
+ throw new NullPointerException( "null entities are not supported by " + getClass().getName() );
+ }
+ return entityToCopyMap.containsKey( entity );
+ }
+
+ /**
+ * Returns true if this EventCache maps one or more entities to the specified copy.
+ * @param copy must be non-null
+ * @return true if this EventCache maps one or more entities to the specified copy
+ * @throws NullPointerException if copy is null
+ */
+ public boolean containsValue(Object copy) {
+ if ( copy == null ) {
+ throw new NullPointerException( "null copies are not supported by " + getClass().getName() );
+ }
+ return entityToCopyMap.containsValue( copy );
+ }
+
+ /**
+ * Returns a set view of the entity-to-copy mappings contained in this EventCache.
+ * @return set view of the entity-to-copy mappings contained in this EventCache
+ */
+ public Set entrySet() {
+ return entityToCopyMap.entrySet();
+ }
+
+ /**
+ * Returns the copy to which this EventCache maps the specified entity.
+ * @param entity must be non-null
+ * @return the copy to which this EventCache maps the specified entity
+ * @throws NullPointerException if entity is null
+ */
+ public Object get(Object entity) {
+ if ( entity == null ) {
+ throw new NullPointerException( "null entities are not supported by " + getClass().getName() );
+ }
+ return entityToCopyMap.get( entity );
+ }
+
+ /**
+ * Returns true if this EventCache contains no entity-copy mappings.
+ * @return true if this EventCache contains no entity-copy mappings
+ */
+ public boolean isEmpty() {
+ return entityToCopyMap.isEmpty();
+ }
+
+ /**
+ * Returns a set view of the entities contained in this EventCache
+ * @return a set view of the entities contained in this EventCache
+ */
+ public Set keySet() {
+ return entityToCopyMap.keySet();
+ }
+
+ /**
+ * Associates the specified entity with the specified copy in this EventCache;
+ * @param entity must be non-null
+ * @param copy must be non- null
+ * @return previous copy associated with specified entity, or null if
+ * there was no mapping for entity.
+ * @throws NullPointerException if entity or copy is null
+ */
+ public Object put(Object entity, Object copy) {
+ if ( entity == null || copy == null ) {
+ throw new NullPointerException( "null entities and copies are not supported by " + getClass().getName() );
+ }
+ entityToOperatedOnFlagMap.put( entity, Boolean.FALSE );
+ return entityToCopyMap.put( entity, copy );
+ }
+
+ /**
+ * Associates the specified entity with the specified copy in this EventCache;
+ * @param entity must be non-null
+ * @param copy must be non- null
+ * @param isOperatedOn indicates if the operation is performed on the entity
+ *
+ * @return previous copy associated with specified entity, or null if
+ * there was no mapping for entity.
+ * @throws NullPointerException if entity or copy is null
+ */
+ /* package-private */ Object put(Object entity, Object copy, boolean isOperatedOn) {
+ if ( entity == null || copy == null ) {
+ throw new NullPointerException( "null entities and copies are not supported by " + getClass().getName() );
+ }
+ entityToOperatedOnFlagMap.put( entity, Boolean.valueOf( isOperatedOn ) );
+ return entityToCopyMap.put( entity, copy );
+ }
+
+ /**
+ * Copies all of the mappings from the specified map to this EventCache
+ * @param map keys and values must be non-null
+ * @throws NullPointerException if any map keys or values are null
+ */
+ public void putAll(Map map) {
+ for ( Iterator it=map.entrySet().iterator(); it.hasNext(); ) {
+ Map.Entry entry = ( Map.Entry ) it.next();
+ if ( entry.getKey() == null || entry.getValue() == null ) {
+ throw new NullPointerException( "null entities and copies are not supported by " + getClass().getName() );
+ }
+ entityToCopyMap.put( entry.getKey(), entry.getValue() );
+ entityToOperatedOnFlagMap.put( entry.getKey(), Boolean.FALSE );
+ }
+ }
+
+ /**
+ * Removes the mapping for this entity from this EventCache if it is present
+ * @param entity must be non-null
+ * @return previous value associated with specified entity, or null if there was no mapping for entity.
+ * @throws NullPointerException if entity is null
+ */
+ public Object remove(Object entity) {
+ if ( entity == null ) {
+ throw new NullPointerException( "null entities are not supported by " + getClass().getName() );
+ }
+ entityToOperatedOnFlagMap.remove( entity );
+ return entityToCopyMap.remove( entity );
+ }
+
+ /**
+ * Returns the number of entity-copy mappings in this EventCache
+ * @return the number of entity-copy mappings in this EventCache
+ */
+ public int size() {
+ return entityToCopyMap.size();
+ }
+
+ /**
+ * Returns a collection view of the entity copies contained in this EventCache.
+ * @return a collection view of the entity copies contained in this EventCache
+ */
+ public Collection values() {
+ return entityToCopyMap.values();
+ }
+
+ /**
+ * Returns true if the listener is performing the operation on the specified entity.
+ * @param entity must be non-null
+ * @return true if the listener is performing the operation on the specified entity.
+ * @throws NullPointerException if entity is null
+ */
+ public boolean isOperatedOn(Object entity) {
+ if ( entity == null ) {
+ throw new NullPointerException( "null entities are not supported by " + getClass().getName() );
+ }
+ return ( ( Boolean ) entityToOperatedOnFlagMap.get( entity ) ).booleanValue();
+ }
+
+ /**
+ * Set flag to indicate if the listener is performing the operation on the specified entity.
+ * @param entity must be non-null and this EventCache must contain a mapping for this entity
+ * @return true if the listener is performing the operation on the specified entity
+ * @throws NullPointerException if entity is null
+ * @throws AssertionFailure if this EventCache does not contain a mapping for the specified entity
+ */
+ /* package-private */ void setOperatedOn(Object entity, boolean isOperatedOn) {
+ if ( entity == null ) {
+ throw new NullPointerException( "null entities are not supported by " + getClass().getName() );
+ }
+ if ( ! entityToOperatedOnFlagMap.containsKey( entity ) ||
+ ! entityToCopyMap.containsKey( entity ) ) {
+ throw new AssertionFailure( "called EventCache.setOperatedOn() for entity not found in EventCache" );
+ }
+ entityToOperatedOnFlagMap.put( entity, Boolean.valueOf( isOperatedOn ) );
+ }
+
+ /**
+ * Returns the copy-entity mappings
+ * @return the copy-entity mappings
+ */
+ public Map invertMap() {
+ return IdentityMap.invert( entityToCopyMap );
+ }
+}
\ No newline at end of file
15 years, 7 months
Hibernate SVN: r16663 - core/branches/Branch_3_2/src/org/hibernate/event/def.
by hibernate-commits@lists.jboss.org
Author: gbadner
Date: 2009-06-02 04:07:35 -0400 (Tue, 02 Jun 2009)
New Revision: 16663
Added:
core/branches/Branch_3_2/src/org/hibernate/event/def/EventCache.java
Removed:
core/branches/Branch_3_2/src/org/hibernate/event/def/CopyCache.java
Modified:
core/branches/Branch_3_2/src/org/hibernate/event/def/DefaultMergeEventListener.java
Log:
HHH-3810 : : rename CopyCache to EventCache to be more generic
Deleted: core/branches/Branch_3_2/src/org/hibernate/event/def/CopyCache.java
===================================================================
--- core/branches/Branch_3_2/src/org/hibernate/event/def/CopyCache.java 2009-06-01 22:09:10 UTC (rev 16662)
+++ core/branches/Branch_3_2/src/org/hibernate/event/def/CopyCache.java 2009-06-02 08:07:35 UTC (rev 16663)
@@ -1,244 +0,0 @@
-//$Id: $
-/*
- * Hibernate, Relational Persistence for Idiomatic Java
- *
- * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
- * indicated by the @author tags or express copyright attribution
- * statements applied by the authors. All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
- *
- * This copyrighted material is made available to anyone wishing to use, modify,
- * copy, or redistribute it subject to the terms and conditions of the GNU
- * Lesser General Public License, as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
- * for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this distribution; if not, write to:
- * Free Software Foundation, Inc.
- * 51 Franklin Street, Fifth Floor
- * Boston, MA 02110-1301 USA
- *
- */
-package org.hibernate.event.def;
-
-import java.util.Map;
-import java.util.Set;
-import java.util.Iterator;
-import java.util.Collection;
-
-import org.hibernate.util.IdentityMap;
-import org.hibernate.AssertionFailure;
-
-/**
- * CopyCache is intended to be the Map implementation used by
- * {@link DefaultMergeEventListener} to keep track of entities and their copies
- * being merged into the session. This implementation also tracks whether a
- * an entity in the CopyCache is included in the merge. This allows a
- * an entity and its copy to be added to a CopyCache before merge has cascaded
- * to that entity.
- *
- * @author Gail Badner
- */
-class CopyCache implements Map {
- private Map entityToCopyMap = IdentityMap.instantiate(10);
- // key is an entity involved with the merge;
- // value can be either a copy of the entity or the entity itself
-
- private Map entityToIncludeInMergeFlagMap = IdentityMap.instantiate(10);
- // key is an entity involved with the merge;
- // value is a flag indicating if the entity is included in the merge
-
- /**
- * Clears the CopyCache.
- */
- public void clear() {
- entityToCopyMap.clear();
- entityToIncludeInMergeFlagMap.clear();
- }
-
- /**
- * Returns true if this CopyCache contains a mapping for the specified entity.
- * @param entity must be non-null
- * @return true if this CopyCache contains a mapping for the specified entity
- * @throws NullPointerException if entity is null
- */
- public boolean containsKey(Object entity) {
- if ( entity == null ) {
- throw new NullPointerException( "null entities are not supported by " + getClass().getName() );
- }
- return entityToCopyMap.containsKey( entity );
- }
-
- /**
- * Returns true if this CopyCache maps one or more entities to the specified copy.
- * @param copy must be non-null
- * @return true if this CopyCache maps one or more entities to the specified copy
- * @throws NullPointerException if copy is null
- */
- public boolean containsValue(Object copy) {
- if ( copy == null ) {
- throw new NullPointerException( "null copies are not supported by " + getClass().getName() );
- }
- return entityToCopyMap.containsValue( copy );
- }
-
- /**
- * Returns a set view of the entity-to-copy mappings contained in this CopyCache.
- * @return set view of the entity-to-copy mappings contained in this CopyCache
- */
- public Set entrySet() {
- return entityToCopyMap.entrySet();
- }
-
- /**
- * Returns the copy to which this CopyCache maps the specified entity.
- * @param entity must be non-null
- * @return the copy to which this CopyCache maps the specified entity
- * @throws NullPointerException if entity is null
- */
- public Object get(Object entity) {
- if ( entity == null ) {
- throw new NullPointerException( "null entities are not supported by " + getClass().getName() );
- }
- return entityToCopyMap.get( entity );
- }
-
- /**
- * Returns true if this CopyCache contains no entity-copy mappings.
- * @return true if this CopyCache contains no entity-copy mappings
- */
- public boolean isEmpty() {
- return entityToCopyMap.isEmpty();
- }
-
- /**
- * Returns a set view of the entities contained in this CopyCache
- * @return a set view of the entities contained in this CopyCache
- */
- public Set keySet() {
- return entityToCopyMap.keySet();
- }
-
- /**
- * Associates the specified entity with the specified copy in this CopyCache;
- * @param entity must be non-null
- * @param copy must be non- null
- * @return previous copy associated with specified entity, or null if
- * there was no mapping for entity.
- * @throws NullPointerException if entity or copy is null
- */
- public Object put(Object entity, Object copy) {
- if ( entity == null || copy == null ) {
- throw new NullPointerException( "null entities and copies are not supported by " + getClass().getName() );
- }
- entityToIncludeInMergeFlagMap.put( entity, Boolean.FALSE );
- return entityToCopyMap.put( entity, copy );
- }
-
- /**
- * Associates the specified entity with the specified copy in this CopyCache;
- * @param entity must be non-null
- * @param copy must be non- null
- * @param isIncludedInMerge indicates if the entity is included in merge
- *
- * @return previous copy associated with specified entity, or null if
- * there was no mapping for entity.
- * @throws NullPointerException if entity or copy is null
- */
- /* package-private */ Object put(Object entity, Object copy, boolean isIncludedInMerge) {
- if ( entity == null || copy == null ) {
- throw new NullPointerException( "null entities and copies are not supported by " + getClass().getName() );
- }
- entityToIncludeInMergeFlagMap.put( entity, Boolean.valueOf( isIncludedInMerge ) );
- return entityToCopyMap.put( entity, copy );
- }
-
- /**
- * Copies all of the mappings from the specified map to this CopyCache
- * @param map keys and values must be non-null
- * @throws NullPointerException if any map keys or values are null
- */
- public void putAll(Map map) {
- for ( Iterator it=map.entrySet().iterator(); it.hasNext(); ) {
- Map.Entry entry = ( Map.Entry ) it.next();
- if ( entry.getKey() == null || entry.getValue() == null ) {
- throw new NullPointerException( "null entities and copies are not supported by " + getClass().getName() );
- }
- entityToCopyMap.put( entry.getKey(), entry.getValue() );
- entityToIncludeInMergeFlagMap.put( entry.getKey(), Boolean.FALSE );
- }
- }
-
- /**
- * Removes the mapping for this entity from this CopyCache if it is present
- * @param entity must be non-null
- * @return previous value associated with specified entity, or null if there was no mapping for entity.
- * @throws NullPointerException if entity is null
- */
- public Object remove(Object entity) {
- if ( entity == null ) {
- throw new NullPointerException( "null entities are not supported by " + getClass().getName() );
- }
- entityToIncludeInMergeFlagMap.remove( entity );
- return entityToCopyMap.remove( entity );
- }
-
- /**
- * Returns the number of entity-copy mappings in this CopyCache
- * @return the number of entity-copy mappings in this CopyCache
- */
- public int size() {
- return entityToCopyMap.size();
- }
-
- /**
- * Returns a collection view of the entity copies contained in this CopyCache.
- * @return a collection view of the entity copies contained in this CopyCache
- */
- public Collection values() {
- return entityToCopyMap.values();
- }
-
- /**
- * Returns true if the specified entity is included in the merge.
- * @param entity must be non-null
- * @return true if the specified entity is included in the merge.
- * @throws NullPointerException if entity is null
- */
- public boolean isIncludedInMerge(Object entity) {
- if ( entity == null ) {
- throw new NullPointerException( "null entities are not supported by " + getClass().getName() );
- }
- return ( ( Boolean ) entityToIncludeInMergeFlagMap.get( entity ) ).booleanValue();
- }
-
- /**
- * Set flag to indicate if an entity is included in the merge.
- * @param entity must be non-null and this CopyCache must contain a mapping for this entity
- * @return true if the specified entity is included in the merge
- * @throws NullPointerException if entity is null
- * @throws AssertionFailure if this CopyCache does not contain a mapping for the specified entity
- */
- /* package-private */ void setIncludedInMerge(Object entity, boolean isIncludedInMerge) {
- if ( entity == null ) {
- throw new NullPointerException( "null entities are not supported by " + getClass().getName() );
- }
- if ( ! entityToIncludeInMergeFlagMap.containsKey( entity ) ||
- ! entityToCopyMap.containsKey( entity ) ) {
- throw new AssertionFailure( "called CopyCache.setInMergeProcess() for entity not found in CopyCache" );
- }
- entityToIncludeInMergeFlagMap.put( entity, Boolean.valueOf( isIncludedInMerge ) );
- }
-
- /**
- * Returns the copy-entity mappings
- * @return the copy-entity mappings
- */
- public Map getMergeMap() {
- return IdentityMap.invert( entityToCopyMap );
- }
-}
\ No newline at end of file
Modified: core/branches/Branch_3_2/src/org/hibernate/event/def/DefaultMergeEventListener.java
===================================================================
--- core/branches/Branch_3_2/src/org/hibernate/event/def/DefaultMergeEventListener.java 2009-06-01 22:09:10 UTC (rev 16662)
+++ core/branches/Branch_3_2/src/org/hibernate/event/def/DefaultMergeEventListener.java 2009-06-02 08:07:35 UTC (rev 16663)
@@ -71,7 +71,7 @@
private static final Log log = LogFactory.getLog(DefaultMergeEventListener.class);
protected Map getMergeMap(Object anything) {
- return ( ( CopyCache ) anything ).getMergeMap();
+ return ( ( EventCache ) anything ).invertMap();
}
/**
@@ -81,7 +81,7 @@
* @throws HibernateException
*/
public void onMerge(MergeEvent event) throws HibernateException {
- CopyCache copyCache = new CopyCache();
+ EventCache copyCache = new EventCache();
onMerge( event, copyCache );
// TODO: iteratively get transient entities and retry merge until one of the following conditions:
// 1) transientCopyCache.size() == 0
@@ -111,8 +111,8 @@
copyCache = null;
}
- protected CopyCache getTransientCopyCache(MergeEvent event, CopyCache copyCache) {
- CopyCache transientCopyCache = new CopyCache();
+ protected EventCache getTransientCopyCache(MergeEvent event, EventCache copyCache) {
+ EventCache transientCopyCache = new EventCache();
for ( Iterator it=copyCache.entrySet().iterator(); it.hasNext(); ) {
Map.Entry mapEntry = ( Map.Entry ) it.next();
Object entity = mapEntry.getKey();
@@ -132,7 +132,7 @@
);
}
else if ( copyEntry.getStatus() == Status.SAVING ) {
- transientCopyCache.put( entity, copy, copyCache.isIncludedInMerge( entity ) );
+ transientCopyCache.put( entity, copy, copyCache.isOperatedOn( entity ) );
}
else if ( copyEntry.getStatus() != Status.MANAGED && copyEntry.getStatus() != Status.READ_ONLY ) {
throw new AssertionFailure( "Merged entity does not have status set to MANAGED or READ_ONLY; "+copy+" status="+copyEntry.getStatus() );
@@ -141,7 +141,7 @@
return transientCopyCache;
}
- protected void retryMergeTransientEntities(MergeEvent event, Map transientCopyCache, CopyCache copyCache) {
+ protected void retryMergeTransientEntities(MergeEvent event, Map transientCopyCache, EventCache copyCache) {
// TODO: The order in which entities are saved may matter (e.g., a particular transient entity
// may need to be saved before other transient entities can be saved;
// Keep retrying the batch of transient entities until either:
@@ -170,7 +170,7 @@
*/
public void onMerge(MergeEvent event, Map copiedAlready) throws HibernateException {
- final CopyCache copyCache = ( CopyCache ) copiedAlready;
+ final EventCache copyCache = ( EventCache ) copiedAlready;
final EventSource source = event.getSession();
final Object original = event.getOriginal();
@@ -193,14 +193,14 @@
}
if ( copyCache.containsKey( entity ) &&
- ( copyCache.isIncludedInMerge( entity ) ) ) {
+ ( copyCache.isOperatedOn( entity ) ) ) {
log.trace("already in merge process");
event.setResult( entity );
}
else {
if ( copyCache.containsKey( entity ) ) {
log.trace("already in copyCache; setting in merge process");
- copyCache.setIncludedInMerge( entity, true );
+ copyCache.setOperatedOn( entity, true );
}
event.setEntity( entity );
int entityState = -1;
@@ -262,7 +262,7 @@
final EventSource source = event.getSession();
final EntityPersister persister = source.getEntityPersister( event.getEntityName(), entity );
- ( ( CopyCache ) copyCache ).put( entity, entity, true ); //before cascade!
+ ( ( EventCache ) copyCache ).put( entity, entity, true ); //before cascade!
cascadeOnMerge(source, persister, entity, copyCache);
copyValues(persister, entity, entity, source, copyCache);
@@ -296,7 +296,7 @@
persister.setIdentifier( copyCache.get( entity ), id, source.getEntityMode() );
}
else {
- ( ( CopyCache ) copyCache ).put( entity, persister.instantiate( id, source.getEntityMode() ), true ); //before cascade!
+ ( ( EventCache ) copyCache ).put( entity, persister.instantiate( id, source.getEntityMode() ), true ); //before cascade!
//TODO: should this be Session.instantiate(Persister, ...)?
}
final Object copy = copyCache.get( entity );
@@ -334,7 +334,7 @@
"' from original entity is not in copyCache; " + propertyName + " =["+propertyFromEntity+"]");
throw ex;
}
- if ( ( ( CopyCache ) copyCache ).isIncludedInMerge( propertyFromEntity ) ) {
+ if ( ( ( EventCache ) copyCache ).isOperatedOn( propertyFromEntity ) ) {
log.trace( "property '" + copyEntry.getEntityName() + "." + propertyName +
"' from original entity is in copyCache and is in the process of being merged; " +
propertyName + " =["+propertyFromEntity+"]");
@@ -398,7 +398,7 @@
entityIsTransient(event, copyCache);
}
else {
- ( ( CopyCache ) copyCache ).put( entity, result, true ); //before cascade!
+ ( ( EventCache ) copyCache ).put( entity, result, true ); //before cascade!
final Object target = source.getPersistenceContext().unproxy(result);
if ( target == entity ) {
Copied: core/branches/Branch_3_2/src/org/hibernate/event/def/EventCache.java (from rev 16662, core/branches/Branch_3_2/src/org/hibernate/event/def/CopyCache.java)
===================================================================
--- core/branches/Branch_3_2/src/org/hibernate/event/def/EventCache.java (rev 0)
+++ core/branches/Branch_3_2/src/org/hibernate/event/def/EventCache.java 2009-06-02 08:07:35 UTC (rev 16663)
@@ -0,0 +1,253 @@
+//$Id: $
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ *
+ */
+package org.hibernate.event.def;
+
+import java.util.Map;
+import java.util.Set;
+import java.util.Iterator;
+import java.util.Collection;
+
+import org.hibernate.util.IdentityMap;
+import org.hibernate.AssertionFailure;
+
+/**
+ * EventCache is a Map implementation that can be used by an event
+ * listener to keep track of entities involved in the operation
+ * being performed. This implementation allows entities to be added
+ * to the EventCache before the operation has cascaded to that
+ * entity.
+ * <p/>
+ * The following methods can be used by event listeners (and other
+ * classes) in the same package to add entities to an EventCache
+ * and indicate if the operation is being performed on the entity:<p/>
+ * {@link EventCache#put(Object entity, Object copy, boolean isOperatedOn)}
+ * <p/>
+ * The following method can be used by event listeners (and other
+ * classes) in the same package to indicate that the operation is being
+ * performed on an entity already in the EventCache:
+ * {@link EventCache#setOperatedOn(Object entity, boolean isOperatedOn)
+ *
+ * @author Gail Badner
+ */
+class EventCache implements Map {
+ private Map entityToCopyMap = IdentityMap.instantiate(10);
+ // key is an entity involved with the operation performed by the listener;
+ // value can be either a copy of the entity or the entity itself
+
+ private Map entityToOperatedOnFlagMap = IdentityMap.instantiate(10);
+ // key is an entity involved with the operation performed by the listener;
+ // value is a flag indicating if the listener explicitly operates on the entity
+
+ /**
+ * Clears the EventCache.
+ */
+ public void clear() {
+ entityToCopyMap.clear();
+ entityToOperatedOnFlagMap.clear();
+ }
+
+ /**
+ * Returns true if this EventCache contains a mapping for the specified entity.
+ * @param entity must be non-null
+ * @return true if this EventCache contains a mapping for the specified entity
+ * @throws NullPointerException if entity is null
+ */
+ public boolean containsKey(Object entity) {
+ if ( entity == null ) {
+ throw new NullPointerException( "null entities are not supported by " + getClass().getName() );
+ }
+ return entityToCopyMap.containsKey( entity );
+ }
+
+ /**
+ * Returns true if this EventCache maps one or more entities to the specified copy.
+ * @param copy must be non-null
+ * @return true if this EventCache maps one or more entities to the specified copy
+ * @throws NullPointerException if copy is null
+ */
+ public boolean containsValue(Object copy) {
+ if ( copy == null ) {
+ throw new NullPointerException( "null copies are not supported by " + getClass().getName() );
+ }
+ return entityToCopyMap.containsValue( copy );
+ }
+
+ /**
+ * Returns a set view of the entity-to-copy mappings contained in this EventCache.
+ * @return set view of the entity-to-copy mappings contained in this EventCache
+ */
+ public Set entrySet() {
+ return entityToCopyMap.entrySet();
+ }
+
+ /**
+ * Returns the copy to which this EventCache maps the specified entity.
+ * @param entity must be non-null
+ * @return the copy to which this EventCache maps the specified entity
+ * @throws NullPointerException if entity is null
+ */
+ public Object get(Object entity) {
+ if ( entity == null ) {
+ throw new NullPointerException( "null entities are not supported by " + getClass().getName() );
+ }
+ return entityToCopyMap.get( entity );
+ }
+
+ /**
+ * Returns true if this EventCache contains no entity-copy mappings.
+ * @return true if this EventCache contains no entity-copy mappings
+ */
+ public boolean isEmpty() {
+ return entityToCopyMap.isEmpty();
+ }
+
+ /**
+ * Returns a set view of the entities contained in this EventCache
+ * @return a set view of the entities contained in this EventCache
+ */
+ public Set keySet() {
+ return entityToCopyMap.keySet();
+ }
+
+ /**
+ * Associates the specified entity with the specified copy in this EventCache;
+ * @param entity must be non-null
+ * @param copy must be non- null
+ * @return previous copy associated with specified entity, or null if
+ * there was no mapping for entity.
+ * @throws NullPointerException if entity or copy is null
+ */
+ public Object put(Object entity, Object copy) {
+ if ( entity == null || copy == null ) {
+ throw new NullPointerException( "null entities and copies are not supported by " + getClass().getName() );
+ }
+ entityToOperatedOnFlagMap.put( entity, Boolean.FALSE );
+ return entityToCopyMap.put( entity, copy );
+ }
+
+ /**
+ * Associates the specified entity with the specified copy in this EventCache;
+ * @param entity must be non-null
+ * @param copy must be non- null
+ * @param isOperatedOn indicates if the operation is performed on the entity
+ *
+ * @return previous copy associated with specified entity, or null if
+ * there was no mapping for entity.
+ * @throws NullPointerException if entity or copy is null
+ */
+ /* package-private */ Object put(Object entity, Object copy, boolean isOperatedOn) {
+ if ( entity == null || copy == null ) {
+ throw new NullPointerException( "null entities and copies are not supported by " + getClass().getName() );
+ }
+ entityToOperatedOnFlagMap.put( entity, Boolean.valueOf( isOperatedOn ) );
+ return entityToCopyMap.put( entity, copy );
+ }
+
+ /**
+ * Copies all of the mappings from the specified map to this EventCache
+ * @param map keys and values must be non-null
+ * @throws NullPointerException if any map keys or values are null
+ */
+ public void putAll(Map map) {
+ for ( Iterator it=map.entrySet().iterator(); it.hasNext(); ) {
+ Map.Entry entry = ( Map.Entry ) it.next();
+ if ( entry.getKey() == null || entry.getValue() == null ) {
+ throw new NullPointerException( "null entities and copies are not supported by " + getClass().getName() );
+ }
+ entityToCopyMap.put( entry.getKey(), entry.getValue() );
+ entityToOperatedOnFlagMap.put( entry.getKey(), Boolean.FALSE );
+ }
+ }
+
+ /**
+ * Removes the mapping for this entity from this EventCache if it is present
+ * @param entity must be non-null
+ * @return previous value associated with specified entity, or null if there was no mapping for entity.
+ * @throws NullPointerException if entity is null
+ */
+ public Object remove(Object entity) {
+ if ( entity == null ) {
+ throw new NullPointerException( "null entities are not supported by " + getClass().getName() );
+ }
+ entityToOperatedOnFlagMap.remove( entity );
+ return entityToCopyMap.remove( entity );
+ }
+
+ /**
+ * Returns the number of entity-copy mappings in this EventCache
+ * @return the number of entity-copy mappings in this EventCache
+ */
+ public int size() {
+ return entityToCopyMap.size();
+ }
+
+ /**
+ * Returns a collection view of the entity copies contained in this EventCache.
+ * @return a collection view of the entity copies contained in this EventCache
+ */
+ public Collection values() {
+ return entityToCopyMap.values();
+ }
+
+ /**
+ * Returns true if the listener is performing the operation on the specified entity.
+ * @param entity must be non-null
+ * @return true if the listener is performing the operation on the specified entity.
+ * @throws NullPointerException if entity is null
+ */
+ public boolean isOperatedOn(Object entity) {
+ if ( entity == null ) {
+ throw new NullPointerException( "null entities are not supported by " + getClass().getName() );
+ }
+ return ( ( Boolean ) entityToOperatedOnFlagMap.get( entity ) ).booleanValue();
+ }
+
+ /**
+ * Set flag to indicate if the listener is performing the operation on the specified entity.
+ * @param entity must be non-null and this EventCache must contain a mapping for this entity
+ * @return true if the listener is performing the operation on the specified entity
+ * @throws NullPointerException if entity is null
+ * @throws AssertionFailure if this EventCache does not contain a mapping for the specified entity
+ */
+ /* package-private */ void setOperatedOn(Object entity, boolean isOperatedOn) {
+ if ( entity == null ) {
+ throw new NullPointerException( "null entities are not supported by " + getClass().getName() );
+ }
+ if ( ! entityToOperatedOnFlagMap.containsKey( entity ) ||
+ ! entityToCopyMap.containsKey( entity ) ) {
+ throw new AssertionFailure( "called EventCache.setOperatedOn() for entity not found in EventCache" );
+ }
+ entityToOperatedOnFlagMap.put( entity, Boolean.valueOf( isOperatedOn ) );
+ }
+
+ /**
+ * Returns the copy-entity mappings
+ * @return the copy-entity mappings
+ */
+ public Map invertMap() {
+ return IdentityMap.invert( entityToCopyMap );
+ }
+}
\ No newline at end of file
15 years, 7 months
Hibernate SVN: r16662 - core/branches/Branch_3_3/core/src/main/java/org/hibernate/cache.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2009-06-01 18:09:10 -0400 (Mon, 01 Jun 2009)
New Revision: 16662
Modified:
core/branches/Branch_3_3/core/src/main/java/org/hibernate/cache/QueryKey.java
Log:
HHH-3383 - QueryKey is storing references to entities instead of identifiers
Modified: core/branches/Branch_3_3/core/src/main/java/org/hibernate/cache/QueryKey.java
===================================================================
--- core/branches/Branch_3_3/core/src/main/java/org/hibernate/cache/QueryKey.java 2009-06-01 22:08:53 UTC (rev 16661)
+++ core/branches/Branch_3_3/core/src/main/java/org/hibernate/cache/QueryKey.java 2009-06-01 22:09:10 UTC (rev 16662)
@@ -91,20 +91,26 @@
}
// disassemble named parameters
- Map namedParameters = CollectionHelper.mapOfSize( queryParameters.getNamedParameters().size() );
- Iterator itr = queryParameters.getNamedParameters().entrySet().iterator();
- while ( itr.hasNext() ) {
- final Map.Entry namedParameterEntry = ( Map.Entry ) itr.next();
- final TypedValue original = ( TypedValue ) namedParameterEntry.getValue();
- namedParameters.put(
- namedParameterEntry.getKey(),
- new TypedValue(
- original.getType(),
- original.getType().disassemble( original.getValue(), session, null ),
- session.getEntityMode()
- )
- );
+ final Map namedParameters;
+ if ( queryParameters.getNamedParameters() == null ) {
+ namedParameters = null;
}
+ else {
+ namedParameters = CollectionHelper.mapOfSize( queryParameters.getNamedParameters().size() );
+ Iterator itr = queryParameters.getNamedParameters().entrySet().iterator();
+ while ( itr.hasNext() ) {
+ final Map.Entry namedParameterEntry = ( Map.Entry ) itr.next();
+ final TypedValue original = ( TypedValue ) namedParameterEntry.getValue();
+ namedParameters.put(
+ namedParameterEntry.getKey(),
+ new TypedValue(
+ original.getType(),
+ original.getType().disassemble( original.getValue(), session, null ),
+ session.getEntityMode()
+ )
+ );
+ }
+ }
// decode row selection...
final RowSelection selection = queryParameters.getRowSelection();
15 years, 7 months
Hibernate SVN: r16661 - core/branches/Branch_3_2/src/org/hibernate/cache.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2009-06-01 18:08:53 -0400 (Mon, 01 Jun 2009)
New Revision: 16661
Modified:
core/branches/Branch_3_2/src/org/hibernate/cache/QueryKey.java
Log:
HHH-3383 - QueryKey is storing references to entities instead of identifiers
Modified: core/branches/Branch_3_2/src/org/hibernate/cache/QueryKey.java
===================================================================
--- core/branches/Branch_3_2/src/org/hibernate/cache/QueryKey.java 2009-06-01 22:08:28 UTC (rev 16660)
+++ core/branches/Branch_3_2/src/org/hibernate/cache/QueryKey.java 2009-06-01 22:08:53 UTC (rev 16661)
@@ -91,20 +91,26 @@
}
// disassemble named parameters
- Map namedParameters = CollectionHelper.mapOfSize( queryParameters.getNamedParameters().size() );
- Iterator itr = queryParameters.getNamedParameters().entrySet().iterator();
- while ( itr.hasNext() ) {
- final Map.Entry namedParameterEntry = ( Map.Entry ) itr.next();
- final TypedValue original = ( TypedValue ) namedParameterEntry.getValue();
- namedParameters.put(
- namedParameterEntry.getKey(),
- new TypedValue(
- original.getType(),
- original.getType().disassemble( original.getValue(), session, null ),
- session.getEntityMode()
- )
- );
+ final Map namedParameters;
+ if ( queryParameters.getNamedParameters() == null ) {
+ namedParameters = null;
}
+ else {
+ namedParameters = CollectionHelper.mapOfSize( queryParameters.getNamedParameters().size() );
+ Iterator itr = queryParameters.getNamedParameters().entrySet().iterator();
+ while ( itr.hasNext() ) {
+ final Map.Entry namedParameterEntry = ( Map.Entry ) itr.next();
+ final TypedValue original = ( TypedValue ) namedParameterEntry.getValue();
+ namedParameters.put(
+ namedParameterEntry.getKey(),
+ new TypedValue(
+ original.getType(),
+ original.getType().disassemble( original.getValue(), session, null ),
+ session.getEntityMode()
+ )
+ );
+ }
+ }
// decode row selection...
final RowSelection selection = queryParameters.getRowSelection();
15 years, 7 months
Hibernate SVN: r16660 - core/trunk/core/src/main/java/org/hibernate/cache.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2009-06-01 18:08:28 -0400 (Mon, 01 Jun 2009)
New Revision: 16660
Modified:
core/trunk/core/src/main/java/org/hibernate/cache/QueryKey.java
Log:
HHH-3383 - QueryKey is storing references to entities instead of identifiers
Modified: core/trunk/core/src/main/java/org/hibernate/cache/QueryKey.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/cache/QueryKey.java 2009-06-01 21:50:17 UTC (rev 16659)
+++ core/trunk/core/src/main/java/org/hibernate/cache/QueryKey.java 2009-06-01 22:08:28 UTC (rev 16660)
@@ -91,20 +91,26 @@
}
// disassemble named parameters
- Map namedParameters = CollectionHelper.mapOfSize( queryParameters.getNamedParameters().size() );
- Iterator itr = queryParameters.getNamedParameters().entrySet().iterator();
- while ( itr.hasNext() ) {
- final Map.Entry namedParameterEntry = ( Map.Entry ) itr.next();
- final TypedValue original = ( TypedValue ) namedParameterEntry.getValue();
- namedParameters.put(
- namedParameterEntry.getKey(),
- new TypedValue(
- original.getType(),
- original.getType().disassemble( original.getValue(), session, null ),
- session.getEntityMode()
- )
- );
+ final Map namedParameters;
+ if ( queryParameters.getNamedParameters() == null ) {
+ namedParameters = null;
}
+ else {
+ namedParameters = CollectionHelper.mapOfSize( queryParameters.getNamedParameters().size() );
+ Iterator itr = queryParameters.getNamedParameters().entrySet().iterator();
+ while ( itr.hasNext() ) {
+ final Map.Entry namedParameterEntry = ( Map.Entry ) itr.next();
+ final TypedValue original = ( TypedValue ) namedParameterEntry.getValue();
+ namedParameters.put(
+ namedParameterEntry.getKey(),
+ new TypedValue(
+ original.getType(),
+ original.getType().disassemble( original.getValue(), session, null ),
+ session.getEntityMode()
+ )
+ );
+ }
+ }
// decode row selection...
final RowSelection selection = queryParameters.getRowSelection();
15 years, 7 months
Hibernate SVN: r16659 - in core/trunk/core/src/main/java/org/hibernate: tool/hbm2ddl and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2009-06-01 17:50:17 -0400 (Mon, 01 Jun 2009)
New Revision: 16659
Modified:
core/trunk/core/src/main/java/org/hibernate/cfg/Configuration.java
core/trunk/core/src/main/java/org/hibernate/tool/hbm2ddl/ForeignKeyMetadata.java
core/trunk/core/src/main/java/org/hibernate/tool/hbm2ddl/TableMetadata.java
Log:
HHH-3532 - schema update task should look for foreign key signature
Modified: core/trunk/core/src/main/java/org/hibernate/cfg/Configuration.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/cfg/Configuration.java 2009-06-01 21:50:00 UTC (rev 16658)
+++ core/trunk/core/src/main/java/org/hibernate/cfg/Configuration.java 2009-06-01 21:50:17 UTC (rev 16659)
@@ -1048,7 +1048,7 @@
ForeignKey fk = (ForeignKey) subIter.next();
if ( fk.isPhysicalConstraint() ) {
boolean create = tableInfo == null || (
- tableInfo.getForeignKeyMetadata( fk.getName() ) == null && (
+ tableInfo.getForeignKeyMetadata( fk ) == null && (
//Icky workaround for MySQL bug:
!( dialect instanceof MySQLDialect ) ||
tableInfo.getIndexMetadata( fk.getName() ) == null
Modified: core/trunk/core/src/main/java/org/hibernate/tool/hbm2ddl/ForeignKeyMetadata.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/tool/hbm2ddl/ForeignKeyMetadata.java 2009-06-01 21:50:00 UTC (rev 16658)
+++ core/trunk/core/src/main/java/org/hibernate/tool/hbm2ddl/ForeignKeyMetadata.java 2009-06-01 21:50:17 UTC (rev 16659)
@@ -20,39 +20,73 @@
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
- *
*/
package org.hibernate.tool.hbm2ddl;
import java.sql.ResultSet;
import java.sql.SQLException;
-import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
+import org.hibernate.mapping.Column;
+import org.hibernate.mapping.ForeignKey;
+
/**
* JDBC foreign key metadata
+ *
* @author Christoph Sturm
*/
public class ForeignKeyMetadata {
private final String name;
- private final List columns = new ArrayList();
+ private final String refTable;
+ private final Map references = new HashMap();
ForeignKeyMetadata(ResultSet rs) throws SQLException {
name = rs.getString("FK_NAME");
+ refTable = rs.getString("PKTABLE_NAME");
}
public String getName() {
return name;
}
- void addColumn(ColumnMetadata column) {
- if (column != null) columns.add(column);
+ public String getReferencedTableName() {
+ return refTable;
}
- public ColumnMetadata[] getColumns() {
- return (ColumnMetadata[]) columns.toArray(new ColumnMetadata[0]);
+ void addReference(ResultSet rs) throws SQLException {
+ references.put( rs.getString("FKCOLUMN_NAME").toLowerCase(), rs.getString("PKCOLUMN_NAME") );
}
+ private boolean hasReference(Column column, Column ref) {
+ String refName = (String) references.get(column.getName().toLowerCase());
+ return ref.getName().equalsIgnoreCase(refName);
+ }
+
+ public boolean matches(ForeignKey fk) {
+ if ( refTable.equalsIgnoreCase( fk.getReferencedTable().getName() ) ) {
+ if ( fk.getColumnSpan() == references.size() ) {
+ List fkRefs;
+ if ( fk.isReferenceToPrimaryKey() ) {
+ fkRefs = fk.getReferencedTable().getPrimaryKey().getColumns();
+ }
+ else {
+ fkRefs = fk.getReferencedColumns();
+ }
+ for ( int i = 0; i < fk.getColumnSpan(); i++ ) {
+ Column column = fk.getColumn( i );
+ Column ref = ( Column ) fkRefs.get( i );
+ if ( !hasReference( column, ref ) ) {
+ return false;
+ }
+ }
+ return true;
+ }
+ }
+ return false;
+ }
+
public String toString() {
return "ForeignKeyMetadata(" + name + ')';
}
Modified: core/trunk/core/src/main/java/org/hibernate/tool/hbm2ddl/TableMetadata.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/tool/hbm2ddl/TableMetadata.java 2009-06-01 21:50:00 UTC (rev 16658)
+++ core/trunk/core/src/main/java/org/hibernate/tool/hbm2ddl/TableMetadata.java 2009-06-01 21:50:17 UTC (rev 16659)
@@ -20,7 +20,6 @@
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
- *
*/
package org.hibernate.tool.hbm2ddl;
@@ -29,16 +28,20 @@
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;
+import java.util.Iterator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.hibernate.mapping.ForeignKey;
+
/**
* JDBC table metadata
- * @author Christoph Sturm, Max Rydahl Andersen
+ *
+ * @author Christoph Sturm
+ * @author Max Rydahl Andersen
*/
public class TableMetadata {
-
private static final Logger log = LoggerFactory.getLogger(TableMetadata.class);
private final String catalog;
@@ -91,6 +94,17 @@
return (ForeignKeyMetadata) foreignKeys.get( keyName.toLowerCase() );
}
+ public ForeignKeyMetadata getForeignKeyMetadata(ForeignKey fk) {
+ Iterator it = foreignKeys.values().iterator();
+ while ( it.hasNext() ) {
+ ForeignKeyMetadata existingFk = ( ForeignKeyMetadata ) it.next();
+ if ( existingFk.matches( fk ) ) {
+ return existingFk;
+ }
+ }
+ return null;
+ }
+
public IndexMetadata getIndexMetadata(String indexName) {
return (IndexMetadata) indexes.get( indexName.toLowerCase() );
}
@@ -98,7 +112,9 @@
private void addForeignKey(ResultSet rs) throws SQLException {
String fk = rs.getString("FK_NAME");
- if (fk == null) return;
+ if (fk == null) {
+ return;
+ }
ForeignKeyMetadata info = getForeignKeyMetadata(fk);
if (info == null) {
@@ -106,13 +122,15 @@
foreignKeys.put( info.getName().toLowerCase(), info );
}
- info.addColumn( getColumnMetadata( rs.getString("FKCOLUMN_NAME") ) );
+ info.addReference( rs );
}
private void addIndex(ResultSet rs) throws SQLException {
String index = rs.getString("INDEX_NAME");
- if (index == null) return;
+ if (index == null) {
+ return;
+ }
IndexMetadata info = getIndexMetadata(index);
if (info == null) {
@@ -126,7 +144,9 @@
public void addColumn(ResultSet rs) throws SQLException {
String column = rs.getString("COLUMN_NAME");
- if (column==null) return;
+ if (column==null) {
+ return;
+ }
if ( getColumnMetadata(column) == null ) {
ColumnMetadata info = new ColumnMetadata(rs);
@@ -139,10 +159,14 @@
try {
rs = meta.getImportedKeys(catalog, schema, name);
- while ( rs.next() ) addForeignKey(rs);
+ while ( rs.next() ) {
+ addForeignKey(rs);
+ }
}
finally {
- if (rs != null) rs.close();
+ if (rs != null) {
+ rs.close();
+ }
}
}
@@ -153,12 +177,16 @@
rs = meta.getIndexInfo(catalog, schema, name, false, true);
while ( rs.next() ) {
- if ( rs.getShort("TYPE") == DatabaseMetaData.tableIndexStatistic ) continue;
+ if ( rs.getShort("TYPE") == DatabaseMetaData.tableIndexStatistic ) {
+ continue;
+ }
addIndex(rs);
}
}
finally {
- if (rs != null) rs.close();
+ if (rs != null) {
+ rs.close();
+ }
}
}
@@ -167,10 +195,14 @@
try {
rs = meta.getColumns(catalog, schema, name, "%");
- while ( rs.next() ) addColumn(rs);
+ while ( rs.next() ) {
+ addColumn(rs);
+ }
}
finally {
- if (rs != null) rs.close();
+ if (rs != null) {
+ rs.close();
+ }
}
}
15 years, 7 months
Hibernate SVN: r16658 - in core/branches/Branch_3_2/src/org/hibernate: tool/hbm2ddl and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2009-06-01 17:50:00 -0400 (Mon, 01 Jun 2009)
New Revision: 16658
Modified:
core/branches/Branch_3_2/src/org/hibernate/cfg/Configuration.java
core/branches/Branch_3_2/src/org/hibernate/tool/hbm2ddl/ForeignKeyMetadata.java
core/branches/Branch_3_2/src/org/hibernate/tool/hbm2ddl/TableMetadata.java
Log:
HHH-3532 - schema update task should look for foreign key signature
Modified: core/branches/Branch_3_2/src/org/hibernate/cfg/Configuration.java
===================================================================
--- core/branches/Branch_3_2/src/org/hibernate/cfg/Configuration.java 2009-06-01 21:49:42 UTC (rev 16657)
+++ core/branches/Branch_3_2/src/org/hibernate/cfg/Configuration.java 2009-06-01 21:50:00 UTC (rev 16658)
@@ -1020,7 +1020,7 @@
ForeignKey fk = (ForeignKey) subIter.next();
if ( fk.isPhysicalConstraint() ) {
boolean create = tableInfo == null || (
- tableInfo.getForeignKeyMetadata( fk.getName() ) == null && (
+ tableInfo.getForeignKeyMetadata( fk ) == null && (
//Icky workaround for MySQL bug:
!( dialect instanceof MySQLDialect ) ||
tableInfo.getIndexMetadata( fk.getName() ) == null
Modified: core/branches/Branch_3_2/src/org/hibernate/tool/hbm2ddl/ForeignKeyMetadata.java
===================================================================
--- core/branches/Branch_3_2/src/org/hibernate/tool/hbm2ddl/ForeignKeyMetadata.java 2009-06-01 21:49:42 UTC (rev 16657)
+++ core/branches/Branch_3_2/src/org/hibernate/tool/hbm2ddl/ForeignKeyMetadata.java 2009-06-01 21:50:00 UTC (rev 16658)
@@ -3,33 +3,64 @@
import java.sql.ResultSet;
import java.sql.SQLException;
-import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
+import org.hibernate.mapping.Column;
+import org.hibernate.mapping.ForeignKey;
+
/**
* JDBC foreign key metadata
* @author Christoph Sturm
*/
public class ForeignKeyMetadata {
private final String name;
- private final List columns = new ArrayList();
+ private final String refTable;
+ private final Map references = new HashMap();
ForeignKeyMetadata(ResultSet rs) throws SQLException {
name = rs.getString("FK_NAME");
+ refTable = rs.getString("PKTABLE_NAME");
}
public String getName() {
return name;
}
- void addColumn(ColumnMetadata column) {
- if (column != null) columns.add(column);
+ void addReference(ResultSet rs) throws SQLException {
+ references.put(rs.getString("FKCOLUMN_NAME").toLowerCase(),
+ rs.getString("PKCOLUMN_NAME"));
}
- public ColumnMetadata[] getColumns() {
- return (ColumnMetadata[]) columns.toArray(new ColumnMetadata[0]);
+ private boolean hasReference(Column column, Column ref) {
+ String refName = (String) references.get(column.getName().toLowerCase());
+ return ref.getName().equalsIgnoreCase(refName);
}
+ public boolean matches(ForeignKey fk) {
+ if (refTable.equalsIgnoreCase(fk.getReferencedTable().getName())) {
+ if (fk.getColumnSpan() == references.size()) {
+ List fkRefs;
+ if (fk.isReferenceToPrimaryKey()) {
+ fkRefs = fk.getReferencedTable().getPrimaryKey().getColumns();
+ }
+ else {
+ fkRefs = fk.getReferencedColumns();
+ }
+ for (int i = 0; i < fk.getColumnSpan(); i++) {
+ Column column = fk.getColumn(i);
+ Column ref = (Column) fkRefs.get(i);
+ if (!hasReference(column, ref)) {
+ return false;
+ }
+ }
+ return true;
+ }
+ }
+ return false;
+ }
+
public String toString() {
return "ForeignKeyMetadata(" + name + ')';
}
Modified: core/branches/Branch_3_2/src/org/hibernate/tool/hbm2ddl/TableMetadata.java
===================================================================
--- core/branches/Branch_3_2/src/org/hibernate/tool/hbm2ddl/TableMetadata.java 2009-06-01 21:49:42 UTC (rev 16657)
+++ core/branches/Branch_3_2/src/org/hibernate/tool/hbm2ddl/TableMetadata.java 2009-06-01 21:50:00 UTC (rev 16658)
@@ -5,8 +5,10 @@
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;
+import java.util.Iterator;
import java.util.Map;
+import org.hibernate.mapping.ForeignKey;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -67,6 +69,17 @@
public ForeignKeyMetadata getForeignKeyMetadata(String keyName) {
return (ForeignKeyMetadata) foreignKeys.get( keyName.toLowerCase() );
}
+
+ public ForeignKeyMetadata getForeignKeyMetadata(ForeignKey fk) {
+ Iterator it = foreignKeys.values().iterator();
+ while ( it.hasNext() ) {
+ ForeignKeyMetadata existingFk = (ForeignKeyMetadata) it.next();
+ if (existingFk.matches(fk)) {
+ return existingFk;
+ }
+ }
+ return null;
+ }
public IndexMetadata getIndexMetadata(String indexName) {
return (IndexMetadata) indexes.get( indexName.toLowerCase() );
@@ -83,7 +96,7 @@
foreignKeys.put( info.getName().toLowerCase(), info );
}
- info.addColumn( getColumnMetadata( rs.getString("FKCOLUMN_NAME") ) );
+ info.addReference( rs );
}
private void addIndex(ResultSet rs) throws SQLException {
15 years, 7 months
Hibernate SVN: r16657 - in core/branches/Branch_3_3/core/src/main/java/org/hibernate: tool/hbm2ddl and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2009-06-01 17:49:42 -0400 (Mon, 01 Jun 2009)
New Revision: 16657
Modified:
core/branches/Branch_3_3/core/src/main/java/org/hibernate/cfg/Configuration.java
core/branches/Branch_3_3/core/src/main/java/org/hibernate/tool/hbm2ddl/ForeignKeyMetadata.java
core/branches/Branch_3_3/core/src/main/java/org/hibernate/tool/hbm2ddl/TableMetadata.java
Log:
HHH-3532 - schema update task should look for foreign key signature
Modified: core/branches/Branch_3_3/core/src/main/java/org/hibernate/cfg/Configuration.java
===================================================================
--- core/branches/Branch_3_3/core/src/main/java/org/hibernate/cfg/Configuration.java 2009-06-01 21:12:25 UTC (rev 16656)
+++ core/branches/Branch_3_3/core/src/main/java/org/hibernate/cfg/Configuration.java 2009-06-01 21:49:42 UTC (rev 16657)
@@ -1048,7 +1048,7 @@
ForeignKey fk = (ForeignKey) subIter.next();
if ( fk.isPhysicalConstraint() ) {
boolean create = tableInfo == null || (
- tableInfo.getForeignKeyMetadata( fk.getName() ) == null && (
+ tableInfo.getForeignKeyMetadata( fk ) == null && (
//Icky workaround for MySQL bug:
!( dialect instanceof MySQLDialect ) ||
tableInfo.getIndexMetadata( fk.getName() ) == null
Modified: core/branches/Branch_3_3/core/src/main/java/org/hibernate/tool/hbm2ddl/ForeignKeyMetadata.java
===================================================================
--- core/branches/Branch_3_3/core/src/main/java/org/hibernate/tool/hbm2ddl/ForeignKeyMetadata.java 2009-06-01 21:12:25 UTC (rev 16656)
+++ core/branches/Branch_3_3/core/src/main/java/org/hibernate/tool/hbm2ddl/ForeignKeyMetadata.java 2009-06-01 21:49:42 UTC (rev 16657)
@@ -26,33 +26,64 @@
import java.sql.ResultSet;
import java.sql.SQLException;
-import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
+import org.hibernate.mapping.Column;
+import org.hibernate.mapping.ForeignKey;
+
/**
* JDBC foreign key metadata
* @author Christoph Sturm
*/
public class ForeignKeyMetadata {
private final String name;
- private final List columns = new ArrayList();
+ private final String refTable;
+ private final Map references = new HashMap();
ForeignKeyMetadata(ResultSet rs) throws SQLException {
name = rs.getString("FK_NAME");
+ refTable = rs.getString("PKTABLE_NAME");
}
public String getName() {
return name;
}
- void addColumn(ColumnMetadata column) {
- if (column != null) columns.add(column);
+ void addReference(ResultSet rs) throws SQLException {
+ references.put(rs.getString("FKCOLUMN_NAME").toLowerCase(),
+ rs.getString("PKCOLUMN_NAME"));
}
- public ColumnMetadata[] getColumns() {
- return (ColumnMetadata[]) columns.toArray(new ColumnMetadata[0]);
+ private boolean hasReference(Column column, Column ref) {
+ String refName = (String) references.get(column.getName().toLowerCase());
+ return ref.getName().equalsIgnoreCase(refName);
}
+ public boolean matches(ForeignKey fk) {
+ if (refTable.equalsIgnoreCase(fk.getReferencedTable().getName())) {
+ if (fk.getColumnSpan() == references.size()) {
+ List fkRefs;
+ if (fk.isReferenceToPrimaryKey()) {
+ fkRefs = fk.getReferencedTable().getPrimaryKey().getColumns();
+ }
+ else {
+ fkRefs = fk.getReferencedColumns();
+ }
+ for (int i = 0; i < fk.getColumnSpan(); i++) {
+ Column column = fk.getColumn(i);
+ Column ref = (Column) fkRefs.get(i);
+ if (!hasReference(column, ref)) {
+ return false;
+ }
+ }
+ return true;
+ }
+ }
+ return false;
+ }
+
public String toString() {
return "ForeignKeyMetadata(" + name + ')';
}
Modified: core/branches/Branch_3_3/core/src/main/java/org/hibernate/tool/hbm2ddl/TableMetadata.java
===================================================================
--- core/branches/Branch_3_3/core/src/main/java/org/hibernate/tool/hbm2ddl/TableMetadata.java 2009-06-01 21:12:25 UTC (rev 16656)
+++ core/branches/Branch_3_3/core/src/main/java/org/hibernate/tool/hbm2ddl/TableMetadata.java 2009-06-01 21:49:42 UTC (rev 16657)
@@ -29,10 +29,13 @@
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;
+import java.util.Iterator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.hibernate.mapping.ForeignKey;
+
/**
* JDBC table metadata
* @author Christoph Sturm, Max Rydahl Andersen
@@ -91,6 +94,17 @@
return (ForeignKeyMetadata) foreignKeys.get( keyName.toLowerCase() );
}
+ public ForeignKeyMetadata getForeignKeyMetadata(ForeignKey fk) {
+ Iterator it = foreignKeys.values().iterator();
+ while ( it.hasNext() ) {
+ ForeignKeyMetadata existingFk = ( ForeignKeyMetadata ) it.next();
+ if ( existingFk.matches( fk ) ) {
+ return existingFk;
+ }
+ }
+ return null;
+ }
+
public IndexMetadata getIndexMetadata(String indexName) {
return (IndexMetadata) indexes.get( indexName.toLowerCase() );
}
@@ -106,7 +120,7 @@
foreignKeys.put( info.getName().toLowerCase(), info );
}
- info.addColumn( getColumnMetadata( rs.getString("FKCOLUMN_NAME") ) );
+ info.addReference( rs );
}
private void addIndex(ResultSet rs) throws SQLException {
15 years, 7 months
Hibernate SVN: r16656 - in core/trunk/core/src/main/java/org/hibernate: util and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2009-06-01 17:12:25 -0400 (Mon, 01 Jun 2009)
New Revision: 16656
Modified:
core/trunk/core/src/main/java/org/hibernate/cache/QueryKey.java
core/trunk/core/src/main/java/org/hibernate/util/CollectionHelper.java
Log:
HHH-3383 - QueryKey is storing references to entities instead of identifiers
Modified: core/trunk/core/src/main/java/org/hibernate/cache/QueryKey.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/cache/QueryKey.java 2009-06-01 21:12:04 UTC (rev 16655)
+++ core/trunk/core/src/main/java/org/hibernate/cache/QueryKey.java 2009-06-01 21:12:25 UTC (rev 16656)
@@ -20,7 +20,6 @@
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
- *
*/
package org.hibernate.cache;
@@ -41,20 +40,24 @@
import org.hibernate.util.CollectionHelper;
/**
- * A key that identifies a particular query with bound parameter values
+ * A key that identifies a particular query with bound parameter values. This is the object Hibernate uses
+ * as its key into its query cache.
+ *
* @author Gavin King
+ * @author Steve Ebersole
*/
public class QueryKey implements Serializable {
private final String sqlQueryString;
- private final Type[] types;
- private final Object[] values;
+ private final Type[] positionalParameterTypes;
+ private final Object[] positionalParameterValues;
+ private final Map namedParameters;
private final Integer firstRow;
private final Integer maxRows;
- private final Map namedParameters;
private final EntityMode entityMode;
- private final Set filters;
+ private final Set filterKeys;
- // the user provided resulttransformer, not the one used with "select new". Here to avoid mangling transformed/non-transformed results.
+ // the user provided resulttransformer, not the one used with "select new". Here to avoid mangling
+ // transformed/non-transformed results.
private final ResultTransformer customTransformer;
/**
@@ -63,10 +66,20 @@
*/
private transient int hashCode;
+ /**
+ * Generates a QueryKey.
+ *
+ * @param queryString The sql query string.
+ * @param queryParameters The query parameters
+ * @param filterKeys The keys of any enabled filters.
+ * @param session The current session.
+ *
+ * @return The generate query cache key.
+ */
public static QueryKey generateQueryKey(
String queryString,
QueryParameters queryParameters,
- Set filters,
+ Set filterKeys,
SessionImplementor session) {
// disassemble positional parameters
final int positionalParameterCount = queryParameters.getPositionalParameterTypes().length;
@@ -113,54 +126,55 @@
namedParameters,
firstRow,
maxRows,
- filters,
+ filterKeys,
session.getEntityMode(),
queryParameters.getResultTransformer()
);
}
- /*package*/ QueryKey(
+ /**
+ * Package-protected constructor.
+ *
+ * @param sqlQueryString The sql query string.
+ * @param positionalParameterTypes Positional parameter types.
+ * @param positionalParameterValues Positional parameter values.
+ * @param namedParameters Named parameters.
+ * @param firstRow First row selection, if any.
+ * @param maxRows Max-rows selection, if any.
+ * @param filterKeys Enabled filter keys, if any.
+ * @param entityMode The entity mode.
+ * @param customTransformer Custom result transformer, if one.
+ */
+ QueryKey(
String sqlQueryString,
- Type[] types,
- Object[] values,
+ Type[] positionalParameterTypes,
+ Object[] positionalParameterValues,
Map namedParameters,
Integer firstRow,
Integer maxRows,
- Set filters,
+ Set filterKeys,
EntityMode entityMode,
ResultTransformer customTransformer) {
this.sqlQueryString = sqlQueryString;
- this.types = types;
- this.values = values;
+ this.positionalParameterTypes = positionalParameterTypes;
+ this.positionalParameterValues = positionalParameterValues;
this.namedParameters = namedParameters;
this.firstRow = firstRow;
this.maxRows = maxRows;
this.entityMode = entityMode;
- this.filters = filters;
+ this.filterKeys = filterKeys;
this.customTransformer = customTransformer;
this.hashCode = generateHashCode();
}
-// public QueryKey(String queryString, QueryParameters queryParameters, Set filters, EntityMode entityMode) {
-// this.sqlQueryString = queryString;
-// this.types = queryParameters.getPositionalParameterTypes();
-// this.values = queryParameters.getPositionalParameterValues();
-// RowSelection selection = queryParameters.getRowSelection();
-// if (selection!=null) {
-// firstRow = selection.getFirstRow();
-// maxRows = selection.getMaxRows();
-// }
-// else {
-// firstRow = null;
-// maxRows = null;
-// }
-// this.namedParameters = queryParameters.getNamedParameters();
-// this.entityMode = entityMode;
-// this.filters = filters;
-// this.customTransformer = queryParameters.getResultTransformer();
-// this.hashCode = generateHashCode();
-// }
-
+ /**
+ * Deserialization hook used to re-init the cached hashcode which is needed for proper clustering support.
+ *
+ * @param in The object input stream.
+ *
+ * @throws IOException Thrown by normal deserialization
+ * @throws ClassNotFoundException Thrown by normal deserialization
+ */
private void readObject(java.io.ObjectInputStream in) throws IOException, ClassNotFoundException {
in.defaultReadObject();
this.hashCode = generateHashCode();
@@ -170,16 +184,19 @@
int result = 13;
result = 37 * result + ( firstRow==null ? 0 : firstRow.hashCode() );
result = 37 * result + ( maxRows==null ? 0 : maxRows.hashCode() );
- for ( int i=0; i<values.length; i++ ) {
- result = 37 * result + ( values[i]==null ? 0 : types[i].getHashCode( values[i], entityMode ) );
+ for ( int i=0; i< positionalParameterValues.length; i++ ) {
+ result = 37 * result + ( positionalParameterValues[i]==null ? 0 : positionalParameterTypes[i].getHashCode( positionalParameterValues[i], entityMode ) );
}
result = 37 * result + ( namedParameters==null ? 0 : namedParameters.hashCode() );
- result = 37 * result + ( filters==null ? 0 : filters.hashCode() );
+ result = 37 * result + ( filterKeys ==null ? 0 : filterKeys.hashCode() );
result = 37 * result + ( customTransformer==null ? 0 : customTransformer.hashCode() );
result = 37 * result + sqlQueryString.hashCode();
return result;
}
-
+
+ /**
+ * {@inheritDoc}
+ */
public boolean equals(Object other) {
if ( !( other instanceof QueryKey ) ) {
return false;
@@ -194,54 +211,57 @@
if ( !EqualsHelper.equals( customTransformer, that.customTransformer ) ) {
return false;
}
- if ( types == null ) {
- if ( that.types != null ) {
+ if ( positionalParameterTypes == null ) {
+ if ( that.positionalParameterTypes != null ) {
return false;
}
}
else {
- if ( that.types == null ) {
+ if ( that.positionalParameterTypes == null ) {
return false;
}
- if ( types.length != that.types.length ) {
+ if ( positionalParameterTypes.length != that.positionalParameterTypes.length ) {
return false;
}
- for ( int i = 0; i < types.length; i++ ) {
- if ( types[i].getReturnedClass() != that.types[i].getReturnedClass() ) {
+ for ( int i = 0; i < positionalParameterTypes.length; i++ ) {
+ if ( positionalParameterTypes[i].getReturnedClass() != that.positionalParameterTypes[i].getReturnedClass() ) {
return false;
}
- if ( !types[i].isEqual( values[i], that.values[i], entityMode ) ) {
+ if ( !positionalParameterTypes[i].isEqual( positionalParameterValues[i], that.positionalParameterValues[i], entityMode ) ) {
return false;
}
}
}
- return EqualsHelper.equals( filters, that.filters )
+ return EqualsHelper.equals( filterKeys, that.filterKeys )
&& EqualsHelper.equals( namedParameters, that.namedParameters );
}
-
+
+ /**
+ * {@inheritDoc}
+ */
public int hashCode() {
return hashCode;
}
+ /**
+ * {@inheritDoc}
+ */
public String toString() {
StringBuffer buf = new StringBuffer()
.append( "sql: " )
.append( sqlQueryString );
- if ( values != null ) {
+ if ( positionalParameterValues != null ) {
buf.append( "; parameters: " );
- for ( int i = 0; i < values.length; i++ ) {
- buf.append( values[i] )
- .append( ", " );
+ for ( int i = 0; i < positionalParameterValues.length; i++ ) {
+ buf.append( positionalParameterValues[i] ).append( ", " );
}
}
if ( namedParameters != null ) {
- buf.append( "; named parameters: " )
- .append( namedParameters );
+ buf.append( "; named parameters: " ).append( namedParameters );
}
- if ( filters != null ) {
- buf.append( "; filters: " )
- .append( filters );
+ if ( filterKeys != null ) {
+ buf.append( "; filterKeys: " ).append( filterKeys );
}
if ( firstRow != null ) {
buf.append( "; first row: " ).append( firstRow );
Modified: core/trunk/core/src/main/java/org/hibernate/util/CollectionHelper.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/util/CollectionHelper.java 2009-06-01 21:12:04 UTC (rev 16655)
+++ core/trunk/core/src/main/java/org/hibernate/util/CollectionHelper.java 2009-06-01 21:12:25 UTC (rev 16656)
@@ -20,7 +20,6 @@
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
- *
*/
package org.hibernate.util;
@@ -32,16 +31,28 @@
import java.util.Map;
/**
+ * Various help for handling collections.
+ *
* @author Gavin King
+ * @author Steve Ebersole
*/
public final class CollectionHelper {
public static final List EMPTY_LIST = Collections.unmodifiableList( new ArrayList(0) );
public static final Collection EMPTY_COLLECTION = Collections.unmodifiableCollection( new ArrayList(0) );
public static final Map EMPTY_MAP = Collections.unmodifiableMap( new HashMap(0) );
-
- private CollectionHelper() {}
+ private CollectionHelper() {
+ }
+
+ /**
+ * Build a properly sized map, especially handling load size and load factor to prevent immediate resizing.
+ * <p/>
+ * Especially helpful for copy map contents.
+ *
+ * @param size The size to make the map.
+ * @return The sized map.
+ */
public static Map mapOfSize(int size) {
final int currentSize = (int) (size / 0.75f);
return new HashMap( Math.max( currentSize+ 1, 16), 0.75f );
15 years, 7 months
Hibernate SVN: r16655 - core/branches/Branch_3_2/src/org/hibernate/cache.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2009-06-01 17:12:04 -0400 (Mon, 01 Jun 2009)
New Revision: 16655
Modified:
core/branches/Branch_3_2/src/org/hibernate/cache/QueryKey.java
Log:
HHH-3383 - QueryKey is storing references to entities instead of identifiers
Modified: core/branches/Branch_3_2/src/org/hibernate/cache/QueryKey.java
===================================================================
--- core/branches/Branch_3_2/src/org/hibernate/cache/QueryKey.java 2009-06-01 21:11:43 UTC (rev 16654)
+++ core/branches/Branch_3_2/src/org/hibernate/cache/QueryKey.java 2009-06-01 21:12:04 UTC (rev 16655)
@@ -40,21 +40,24 @@
import org.hibernate.util.CollectionHelper;
/**
- * A key that identifies a particular query with bound parameter values
+ * A key that identifies a particular query with bound parameter values. This is the object Hibernate uses
+ * as its key into its query cache.
*
* @author Gavin King
+ * @author Steve Ebersole
*/
public class QueryKey implements Serializable {
private final String sqlQueryString;
- private final Type[] types;
- private final Object[] values;
+ private final Type[] positionalParameterTypes;
+ private final Object[] positionalParameterValues;
+ private final Map namedParameters;
private final Integer firstRow;
private final Integer maxRows;
- private final Map namedParameters;
private final EntityMode entityMode;
- private final Set filters;
+ private final Set filterKeys;
- // the user provided resulttransformer, not the one used with "select new". Here to avoid mangling transformed/non-transformed results.
+ // the user provided resulttransformer, not the one used with "select new". Here to avoid mangling
+ // transformed/non-transformed results.
private final ResultTransformer customTransformer;
/**
@@ -63,10 +66,20 @@
*/
private transient int hashCode;
+ /**
+ * Generates a QueryKey.
+ *
+ * @param queryString The sql query string.
+ * @param queryParameters The query parameters
+ * @param filterKeys The keys of any enabled filters.
+ * @param session The current session.
+ *
+ * @return The generate query cache key.
+ */
public static QueryKey generateQueryKey(
String queryString,
QueryParameters queryParameters,
- Set filters,
+ Set filterKeys,
SessionImplementor session) {
// disassemble positional parameters
final int positionalParameterCount = queryParameters.getPositionalParameterTypes().length;
@@ -113,34 +126,55 @@
namedParameters,
firstRow,
maxRows,
- filters,
+ filterKeys,
session.getEntityMode(),
queryParameters.getResultTransformer()
);
}
- /*package*/ QueryKey(
+ /**
+ * Package-protected constructor.
+ *
+ * @param sqlQueryString The sql query string.
+ * @param positionalParameterTypes Positional parameter types.
+ * @param positionalParameterValues Positional parameter values.
+ * @param namedParameters Named parameters.
+ * @param firstRow First row selection, if any.
+ * @param maxRows Max-rows selection, if any.
+ * @param filterKeys Enabled filter keys, if any.
+ * @param entityMode The entity mode.
+ * @param customTransformer Custom result transformer, if one.
+ */
+ QueryKey(
String sqlQueryString,
- Type[] types,
- Object[] values,
+ Type[] positionalParameterTypes,
+ Object[] positionalParameterValues,
Map namedParameters,
Integer firstRow,
Integer maxRows,
- Set filters,
+ Set filterKeys,
EntityMode entityMode,
ResultTransformer customTransformer) {
this.sqlQueryString = sqlQueryString;
- this.types = types;
- this.values = values;
+ this.positionalParameterTypes = positionalParameterTypes;
+ this.positionalParameterValues = positionalParameterValues;
this.namedParameters = namedParameters;
this.firstRow = firstRow;
this.maxRows = maxRows;
this.entityMode = entityMode;
- this.filters = filters;
+ this.filterKeys = filterKeys;
this.customTransformer = customTransformer;
this.hashCode = generateHashCode();
}
+ /**
+ * Deserialization hook used to re-init the cached hashcode which is needed for proper clustering support.
+ *
+ * @param in The object input stream.
+ *
+ * @throws IOException Thrown by normal deserialization
+ * @throws ClassNotFoundException Thrown by normal deserialization
+ */
private void readObject(java.io.ObjectInputStream in) throws IOException, ClassNotFoundException {
in.defaultReadObject();
this.hashCode = generateHashCode();
@@ -150,16 +184,19 @@
int result = 13;
result = 37 * result + ( firstRow==null ? 0 : firstRow.hashCode() );
result = 37 * result + ( maxRows==null ? 0 : maxRows.hashCode() );
- for ( int i=0; i<values.length; i++ ) {
- result = 37 * result + ( values[i]==null ? 0 : types[i].getHashCode( values[i], entityMode ) );
+ for ( int i=0; i< positionalParameterValues.length; i++ ) {
+ result = 37 * result + ( positionalParameterValues[i]==null ? 0 : positionalParameterTypes[i].getHashCode( positionalParameterValues[i], entityMode ) );
}
result = 37 * result + ( namedParameters==null ? 0 : namedParameters.hashCode() );
- result = 37 * result + ( filters==null ? 0 : filters.hashCode() );
+ result = 37 * result + ( filterKeys ==null ? 0 : filterKeys.hashCode() );
result = 37 * result + ( customTransformer==null ? 0 : customTransformer.hashCode() );
result = 37 * result + sqlQueryString.hashCode();
return result;
}
+ /**
+ * {@inheritDoc}
+ */
public boolean equals(Object other) {
if ( !( other instanceof QueryKey ) ) {
return false;
@@ -174,54 +211,57 @@
if ( !EqualsHelper.equals( customTransformer, that.customTransformer ) ) {
return false;
}
- if ( types == null ) {
- if ( that.types != null ) {
+ if ( positionalParameterTypes == null ) {
+ if ( that.positionalParameterTypes != null ) {
return false;
}
}
else {
- if ( that.types == null ) {
+ if ( that.positionalParameterTypes == null ) {
return false;
}
- if ( types.length != that.types.length ) {
+ if ( positionalParameterTypes.length != that.positionalParameterTypes.length ) {
return false;
}
- for ( int i = 0; i < types.length; i++ ) {
- if ( types[i].getReturnedClass() != that.types[i].getReturnedClass() ) {
+ for ( int i = 0; i < positionalParameterTypes.length; i++ ) {
+ if ( positionalParameterTypes[i].getReturnedClass() != that.positionalParameterTypes[i].getReturnedClass() ) {
return false;
}
- if ( !types[i].isEqual( values[i], that.values[i], entityMode ) ) {
+ if ( !positionalParameterTypes[i].isEqual( positionalParameterValues[i], that.positionalParameterValues[i], entityMode ) ) {
return false;
}
}
}
- return EqualsHelper.equals( filters, that.filters )
+ return EqualsHelper.equals( filterKeys, that.filterKeys )
&& EqualsHelper.equals( namedParameters, that.namedParameters );
}
+ /**
+ * {@inheritDoc}
+ */
public int hashCode() {
return hashCode;
}
+ /**
+ * {@inheritDoc}
+ */
public String toString() {
StringBuffer buf = new StringBuffer()
.append( "sql: " )
.append( sqlQueryString );
- if ( values != null ) {
+ if ( positionalParameterValues != null ) {
buf.append( "; parameters: " );
- for ( int i = 0; i < values.length; i++ ) {
- buf.append( values[i] )
- .append( ", " );
+ for ( int i = 0; i < positionalParameterValues.length; i++ ) {
+ buf.append( positionalParameterValues[i] ).append( ", " );
}
}
if ( namedParameters != null ) {
- buf.append( "; named parameters: " )
- .append( namedParameters );
+ buf.append( "; named parameters: " ).append( namedParameters );
}
- if ( filters != null ) {
- buf.append( "; filters: " )
- .append( filters );
+ if ( filterKeys != null ) {
+ buf.append( "; filterKeys: " ).append( filterKeys );
}
if ( firstRow != null ) {
buf.append( "; first row: " ).append( firstRow );
15 years, 7 months