From 884f6a245510f00c271c9d13eb70285106842445 Mon Sep 17 00:00:00 2001 From: Strong Liu Date: Sun, 9 Oct 2011 14:36:15 +0800 Subject: [PATCH] HHH-4881 - restrict polymorphic query results --- .../org/hibernate/cache/spi/UpdateTimestampsCache.java | 10 ++-------- .../hibernate/persister/entity/DiscriminatorType.java | 7 +------ .../entity/JoinedSubclassEntityPersister.java | 6 +++--- .../persister/entity/UnionSubclassEntityPersister.java | 6 +++--- 4 files changed, 9 insertions(+), 20 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/cache/spi/UpdateTimestampsCache.java b/hibernate-core/src/main/java/org/hibernate/cache/spi/UpdateTimestampsCache.java index 03e96c156f..e2c1f16343 100644 --- a/hibernate-core/src/main/java/org/hibernate/cache/spi/UpdateTimestampsCache.java +++ b/hibernate-core/src/main/java/org/hibernate/cache/spi/UpdateTimestampsCache.java @@ -63,7 +63,7 @@ public class UpdateTimestampsCache { LOG.startingUpdateTimestampsCache(regionName); this.region = settings.getRegionFactory().buildTimestampsRegion( regionName, props ); } - + @SuppressWarnings({"UnusedDeclaration"}) public UpdateTimestampsCache(Settings settings, Properties props) throws HibernateException { this(settings, props, null); @@ -71,8 +71,6 @@ public class UpdateTimestampsCache { @SuppressWarnings({"UnnecessaryBoxing"}) public void preinvalidate(Serializable[] spaces) throws CacheException { - // TODO: to handle concurrent writes correctly, this should return a Lock to the client - readWriteLock.writeLock().lock(); try { @@ -86,7 +84,6 @@ public class UpdateTimestampsCache { factory.getStatisticsImplementor().updateTimestampsCachePut(); } } - //TODO: return new Lock(ts); } finally { readWriteLock.writeLock().unlock(); @@ -95,13 +92,10 @@ public class UpdateTimestampsCache { @SuppressWarnings({"UnnecessaryBoxing"}) public void invalidate(Serializable[] spaces) throws CacheException { - //TODO: to handle concurrent writes correctly, the client should pass in a Lock - readWriteLock.writeLock().lock(); try { Long ts = new Long( region.nextTimestamp() ); - //TODO: if lock.getTimestamp().equals(ts) for (Serializable space : spaces) { LOG.debugf("Invalidating space [%s], timestamp: %s", space, ts); //put() has nowait semantics, is this really appropriate? @@ -144,7 +138,7 @@ public class UpdateTimestampsCache { if ( factory != null && factory.getStatistics().isStatisticsEnabled() ) { factory.getStatisticsImplementor().updateTimestampsCacheHit(); } - if ( lastUpdate.longValue() >= timestamp.longValue() ) return false; + if ( lastUpdate >= timestamp ) return false; } } return true; diff --git a/hibernate-core/src/main/java/org/hibernate/persister/entity/DiscriminatorType.java b/hibernate-core/src/main/java/org/hibernate/persister/entity/DiscriminatorType.java index 05039e1e14..e3df8972f3 100644 --- a/hibernate-core/src/main/java/org/hibernate/persister/entity/DiscriminatorType.java +++ b/hibernate-core/src/main/java/org/hibernate/persister/entity/DiscriminatorType.java @@ -87,12 +87,7 @@ public class DiscriminatorType extends AbstractType { throw new HibernateException( "Unable to resolve discriminator value [" + discriminatorValue + "] to entity name" ); } final EntityPersister entityPersister = session.getEntityPersister( entityName, null ); - if ( EntityMode.POJO == entityPersister.getEntityMode() ) { - return entityPersister.getMappedClass(); - } - else { - return entityName; - } + return ( EntityMode.POJO == entityPersister.getEntityMode() ) ? entityPersister.getMappedClass() : entityName; } public void nullSafeSet( diff --git a/hibernate-core/src/main/java/org/hibernate/persister/entity/JoinedSubclassEntityPersister.java b/hibernate-core/src/main/java/org/hibernate/persister/entity/JoinedSubclassEntityPersister.java index 0e9270a5b9..a9121b43ee 100644 --- a/hibernate-core/src/main/java/org/hibernate/persister/entity/JoinedSubclassEntityPersister.java +++ b/hibernate-core/src/main/java/org/hibernate/persister/entity/JoinedSubclassEntityPersister.java @@ -131,7 +131,7 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister { if ( persistentClass.isPolymorphic() ) { try { - discriminatorValue = new Integer( persistentClass.getSubclassId() ); + discriminatorValue = persistentClass.getSubclassId(); discriminatorSQLString = discriminatorValue.toString(); } catch ( Exception e ) { @@ -416,7 +416,7 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister { factory.getSettings().getDefaultCatalogName(), factory.getSettings().getDefaultSchemaName() ); - Integer tabnum = new Integer( getTableId( tabname, subclassTableNameClosure ) ); + Integer tabnum = getTableId( tabname, subclassTableNameClosure ); propTableNumbers.add( tabnum ); Iterator citer = prop.getColumnIterator(); @@ -474,7 +474,7 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister { // we now use subclass ids that are consistent across all // persisters for a class hierarchy, so that the use of // "foo.class = Bar" works in HQL - Integer subclassId = new Integer( sc.getSubclassId() );//new Integer(k+1); + Integer subclassId = sc.getSubclassId(); subclassesByDiscriminatorValue.put( subclassId, sc.getEntityName() ); discriminatorValues[k] = subclassId.toString(); int id = getTableId( diff --git a/hibernate-core/src/main/java/org/hibernate/persister/entity/UnionSubclassEntityPersister.java b/hibernate-core/src/main/java/org/hibernate/persister/entity/UnionSubclassEntityPersister.java index a95fc50b19..dd725afd26 100644 --- a/hibernate-core/src/main/java/org/hibernate/persister/entity/UnionSubclassEntityPersister.java +++ b/hibernate-core/src/main/java/org/hibernate/persister/entity/UnionSubclassEntityPersister.java @@ -145,7 +145,7 @@ public class UnionSubclassEntityPersister extends AbstractEntityPersister { deleteCallable = new boolean[] { callable }; deleteResultCheckStyles = new ExecuteUpdateResultCheckStyle[] { checkStyle }; - discriminatorValue = new Integer( persistentClass.getSubclassId() ); + discriminatorValue = persistentClass.getSubclassId(); discriminatorSQLValue = String.valueOf( persistentClass.getSubclassId() ); // PROPERTIES @@ -156,7 +156,7 @@ public class UnionSubclassEntityPersister extends AbstractEntityPersister { // SUBCLASSES subclassByDiscriminatorValue.put( - new Integer( persistentClass.getSubclassId() ), + persistentClass.getSubclassId(), persistentClass.getEntityName() ); if ( persistentClass.isPolymorphic() ) { @@ -165,7 +165,7 @@ public class UnionSubclassEntityPersister extends AbstractEntityPersister { while ( iter.hasNext() ) { Subclass sc = (Subclass) iter.next(); subclassClosure[k++] = sc.getEntityName(); - subclassByDiscriminatorValue.put( new Integer( sc.getSubclassId() ), sc.getEntityName() ); + subclassByDiscriminatorValue.put( sc.getSubclassId(), sc.getEntityName() ); } }