HHH-11506 - Fix update of lazy attributes when there are attributes not loaded

HHH-11506 - Deprecate methods

HHH-11506 : Added original TypeHelper#findModfied and deprecated; changed deprecated methods to call the new methods.
This commit is contained in:
barreiro 2017-03-08 17:10:28 +00:00 committed by Gail Badner
parent 12a1b3c225
commit aaebcdf454
5 changed files with 76 additions and 7 deletions

View File

@ -4210,7 +4210,6 @@ public abstract class AbstractEntityPersister
currentState,
previousState,
propertyColumnUpdateable,
hasUninitializedLazyProperties( entity ),
session
);
if ( props == null ) {
@ -4242,7 +4241,6 @@ public abstract class AbstractEntityPersister
old,
propertyColumnUpdateable,
getPropertyUpdateability(),
hasUninitializedLazyProperties( entity ),
session
);
if ( props == null ) {

View File

@ -86,7 +86,7 @@ public abstract class AbstractNonIdentifierAttribute extends AbstractAttribute i
@Override
public boolean isDirtyCheckable(boolean hasUninitializedProperties) {
return isDirtyCheckable() && ( !hasUninitializedProperties || !isLazy() );
return isDirtyCheckable();
}
@Override

View File

@ -24,6 +24,10 @@ public interface NonIdentifierAttribute extends Attribute, AttributeDefinition {
public boolean isNullable();
/**
* @deprecated Use {@link org.hibernate.tuple.NonIdentifierAttribute#isDirtyCheckable()} instead
*/
@Deprecated
public boolean isDirtyCheckable(boolean hasUninitializedProperties);
public boolean isDirtyCheckable();

View File

@ -281,7 +281,10 @@ public class TypeHelper {
* @param session The session from which the dirty check request originated.
*
* @return Array containing indices of the dirty properties, or null if no properties considered dirty.
*
* @deprecated Use {org.hibernate.type.TypeHelper{@link #findDirty(NonIdentifierAttribute[], Object[], Object[], boolean[][], SharedSessionContractImplementor)} indtead
*/
@Deprecated
public static int[] findDirty(
final NonIdentifierAttribute[] properties,
final Object[] currentState,
@ -289,13 +292,36 @@ public class TypeHelper {
final boolean[][] includeColumns,
final boolean anyUninitializedProperties,
final SharedSessionContractImplementor session) {
return findDirty( properties, currentState, previousState, includeColumns, session );
}
/**
* Determine if any of the given field values are dirty, returning an array containing
* indices of the dirty fields.
* <p/>
* If it is determined that no fields are dirty, null is returned.
*
* @param properties The property definitions
* @param currentState The current state of the entity
* @param previousState The baseline state of the entity
* @param includeColumns Columns to be included in the dirty checking, per property
* @param session The session from which the dirty check request originated.
*
* @return Array containing indices of the dirty properties, or null if no properties considered dirty.
*/
public static int[] findDirty(
final NonIdentifierAttribute[] properties,
final Object[] currentState,
final Object[] previousState,
final boolean[][] includeColumns,
final SharedSessionContractImplementor session) {
int[] results = null;
int count = 0;
int span = properties.length;
for ( int i = 0; i < span; i++ ) {
final boolean dirty = currentState[i] != LazyPropertyInitializer.UNFETCHED_PROPERTY
&& properties[i].isDirtyCheckable( anyUninitializedProperties )
&& properties[i].isDirtyCheckable()
&& properties[i].getType().isDirty( previousState[i], currentState[i], includeColumns[i], session );
if ( dirty ) {
if ( results == null ) {
@ -330,7 +356,11 @@ public class TypeHelper {
* @param session The session from which the dirty check request originated.
*
* @return Array containing indices of the modified properties, or null if no properties considered modified.
*
* @deprecated Use {@link #findModified(NonIdentifierAttribute[], Object[], Object[], boolean[][], boolean[], boolean, SharedSessionContractImplementor)}
* instead.
*/
@Deprecated
public static int[] findModified(
final NonIdentifierAttribute[] properties,
final Object[] currentState,
@ -339,6 +369,32 @@ public class TypeHelper {
final boolean[] includeProperties,
final boolean anyUninitializedProperties,
final SharedSessionContractImplementor session) {
return findModified( properties, currentState, previousState, includeColumns, includeProperties, session );
}
/**
* Determine if any of the given field values are modified, returning an array containing
* indices of the modified fields.
* <p/>
* If it is determined that no fields are dirty, null is returned.
*
* @param properties The property definitions
* @param currentState The current state of the entity
* @param previousState The baseline state of the entity
* @param includeColumns Columns to be included in the mod checking, per property
* @param includeProperties Array of property indices that identify which properties participate in check
* @param anyUninitializedProperties Does the entity currently hold any uninitialized property values?
* @param session The session from which the dirty check request originated.
*
* @return Array containing indices of the modified properties, or null if no properties considered modified.
**/
public static int[] findModified(
final NonIdentifierAttribute[] properties,
final Object[] currentState,
final Object[] previousState,
final boolean[][] includeColumns,
final boolean[] includeProperties,
final SharedSessionContractImplementor session) {
int[] results = null;
int count = 0;
int span = properties.length;
@ -346,7 +402,7 @@ public class TypeHelper {
for ( int i = 0; i < span; i++ ) {
final boolean modified = currentState[ i ] != LazyPropertyInitializer.UNFETCHED_PROPERTY
&& includeProperties[ i ]
&& properties[ i ].isDirtyCheckable( anyUninitializedProperties )
&& properties[ i ].isDirtyCheckable()
&& properties[ i ].getType().isModified( previousState[ i ], currentState[ i ], includeColumns[ i ], session );
if ( modified ) {
if ( results == null ) {

View File

@ -140,7 +140,7 @@ public class EnhancerTest extends BaseUnitTestCase {
@Test
@TestForIssue( jiraKey = "HHH-11173" )
@RequiresDialectFeature( value = DialectChecks.SupportsIdentityColumns.class)
@RequiresDialectFeature( DialectChecks.SupportsIdentityColumns.class)
public void testLazyCache() {
EnhancerTestUtils.runEnhancerTestTask( LazyInCacheTestTask.class );
}
@ -181,6 +181,17 @@ public class EnhancerTest extends BaseUnitTestCase {
EnhancerTestUtils.runEnhancerTestTask( SimpleLazyGroupUpdateTestTask.class );
}
@Test
@TestForIssue( jiraKey = "HHH-11506" )
public void testLazyGroupsUpdateWithoutDirtyChecking() {
EnhancerTestUtils.runEnhancerTestTask( SimpleLazyGroupUpdateTestTask.class , new EnhancerTestContext() {
@Override
public boolean doDirtyCheckingInline(UnloadedClass classDescriptor) {
return false;
}
} );
}
@Test
public void testLazyCollectionNoTransactionHandling() {
EnhancerTestUtils.runEnhancerTestTask( LazyCollectionNoTransactionLoadingTestTask.class );