HHH-4881 - restrict polymorphic query results

This commit is contained in:
Strong Liu 2011-10-09 14:36:15 +08:00
parent e05b3a6c38
commit 884f6a2455
4 changed files with 9 additions and 20 deletions

View File

@ -63,7 +63,7 @@ public class UpdateTimestampsCache {
LOG.startingUpdateTimestampsCache(regionName); LOG.startingUpdateTimestampsCache(regionName);
this.region = settings.getRegionFactory().buildTimestampsRegion( regionName, props ); this.region = settings.getRegionFactory().buildTimestampsRegion( regionName, props );
} }
@SuppressWarnings({"UnusedDeclaration"})
public UpdateTimestampsCache(Settings settings, Properties props) public UpdateTimestampsCache(Settings settings, Properties props)
throws HibernateException { throws HibernateException {
this(settings, props, null); this(settings, props, null);
@ -71,8 +71,6 @@ public class UpdateTimestampsCache {
@SuppressWarnings({"UnnecessaryBoxing"}) @SuppressWarnings({"UnnecessaryBoxing"})
public void preinvalidate(Serializable[] spaces) throws CacheException { public void preinvalidate(Serializable[] spaces) throws CacheException {
// TODO: to handle concurrent writes correctly, this should return a Lock to the client
readWriteLock.writeLock().lock(); readWriteLock.writeLock().lock();
try { try {
@ -86,7 +84,6 @@ public class UpdateTimestampsCache {
factory.getStatisticsImplementor().updateTimestampsCachePut(); factory.getStatisticsImplementor().updateTimestampsCachePut();
} }
} }
//TODO: return new Lock(ts);
} }
finally { finally {
readWriteLock.writeLock().unlock(); readWriteLock.writeLock().unlock();
@ -95,13 +92,10 @@ public class UpdateTimestampsCache {
@SuppressWarnings({"UnnecessaryBoxing"}) @SuppressWarnings({"UnnecessaryBoxing"})
public void invalidate(Serializable[] spaces) throws CacheException { public void invalidate(Serializable[] spaces) throws CacheException {
//TODO: to handle concurrent writes correctly, the client should pass in a Lock
readWriteLock.writeLock().lock(); readWriteLock.writeLock().lock();
try { try {
Long ts = new Long( region.nextTimestamp() ); Long ts = new Long( region.nextTimestamp() );
//TODO: if lock.getTimestamp().equals(ts)
for (Serializable space : spaces) { for (Serializable space : spaces) {
LOG.debugf("Invalidating space [%s], timestamp: %s", space, ts); LOG.debugf("Invalidating space [%s], timestamp: %s", space, ts);
//put() has nowait semantics, is this really appropriate? //put() has nowait semantics, is this really appropriate?
@ -144,7 +138,7 @@ public class UpdateTimestampsCache {
if ( factory != null && factory.getStatistics().isStatisticsEnabled() ) { if ( factory != null && factory.getStatistics().isStatisticsEnabled() ) {
factory.getStatisticsImplementor().updateTimestampsCacheHit(); factory.getStatisticsImplementor().updateTimestampsCacheHit();
} }
if ( lastUpdate.longValue() >= timestamp.longValue() ) return false; if ( lastUpdate >= timestamp ) return false;
} }
} }
return true; return true;

View File

@ -87,12 +87,7 @@ public class DiscriminatorType extends AbstractType {
throw new HibernateException( "Unable to resolve discriminator value [" + discriminatorValue + "] to entity name" ); throw new HibernateException( "Unable to resolve discriminator value [" + discriminatorValue + "] to entity name" );
} }
final EntityPersister entityPersister = session.getEntityPersister( entityName, null ); final EntityPersister entityPersister = session.getEntityPersister( entityName, null );
if ( EntityMode.POJO == entityPersister.getEntityMode() ) { return ( EntityMode.POJO == entityPersister.getEntityMode() ) ? entityPersister.getMappedClass() : entityName;
return entityPersister.getMappedClass();
}
else {
return entityName;
}
} }
public void nullSafeSet( public void nullSafeSet(

View File

@ -131,7 +131,7 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister {
if ( persistentClass.isPolymorphic() ) { if ( persistentClass.isPolymorphic() ) {
try { try {
discriminatorValue = new Integer( persistentClass.getSubclassId() ); discriminatorValue = persistentClass.getSubclassId();
discriminatorSQLString = discriminatorValue.toString(); discriminatorSQLString = discriminatorValue.toString();
} }
catch ( Exception e ) { catch ( Exception e ) {
@ -416,7 +416,7 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister {
factory.getSettings().getDefaultCatalogName(), factory.getSettings().getDefaultCatalogName(),
factory.getSettings().getDefaultSchemaName() factory.getSettings().getDefaultSchemaName()
); );
Integer tabnum = new Integer( getTableId( tabname, subclassTableNameClosure ) ); Integer tabnum = getTableId( tabname, subclassTableNameClosure );
propTableNumbers.add( tabnum ); propTableNumbers.add( tabnum );
Iterator citer = prop.getColumnIterator(); Iterator citer = prop.getColumnIterator();
@ -474,7 +474,7 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister {
// we now use subclass ids that are consistent across all // we now use subclass ids that are consistent across all
// persisters for a class hierarchy, so that the use of // persisters for a class hierarchy, so that the use of
// "foo.class = Bar" works in HQL // "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() ); subclassesByDiscriminatorValue.put( subclassId, sc.getEntityName() );
discriminatorValues[k] = subclassId.toString(); discriminatorValues[k] = subclassId.toString();
int id = getTableId( int id = getTableId(

View File

@ -145,7 +145,7 @@ public class UnionSubclassEntityPersister extends AbstractEntityPersister {
deleteCallable = new boolean[] { callable }; deleteCallable = new boolean[] { callable };
deleteResultCheckStyles = new ExecuteUpdateResultCheckStyle[] { checkStyle }; deleteResultCheckStyles = new ExecuteUpdateResultCheckStyle[] { checkStyle };
discriminatorValue = new Integer( persistentClass.getSubclassId() ); discriminatorValue = persistentClass.getSubclassId();
discriminatorSQLValue = String.valueOf( persistentClass.getSubclassId() ); discriminatorSQLValue = String.valueOf( persistentClass.getSubclassId() );
// PROPERTIES // PROPERTIES
@ -156,7 +156,7 @@ public class UnionSubclassEntityPersister extends AbstractEntityPersister {
// SUBCLASSES // SUBCLASSES
subclassByDiscriminatorValue.put( subclassByDiscriminatorValue.put(
new Integer( persistentClass.getSubclassId() ), persistentClass.getSubclassId(),
persistentClass.getEntityName() persistentClass.getEntityName()
); );
if ( persistentClass.isPolymorphic() ) { if ( persistentClass.isPolymorphic() ) {
@ -165,7 +165,7 @@ public class UnionSubclassEntityPersister extends AbstractEntityPersister {
while ( iter.hasNext() ) { while ( iter.hasNext() ) {
Subclass sc = (Subclass) iter.next(); Subclass sc = (Subclass) iter.next();
subclassClosure[k++] = sc.getEntityName(); subclassClosure[k++] = sc.getEntityName();
subclassByDiscriminatorValue.put( new Integer( sc.getSubclassId() ), sc.getEntityName() ); subclassByDiscriminatorValue.put( sc.getSubclassId(), sc.getEntityName() );
} }
} }