Skip to content

Commit

Permalink
HHH-11506 - Fix update of lazy attributes when there are attributes n…
Browse files Browse the repository at this point in the history
…ot loaded

HHH-11506 - Deprecate methods

HHH-11506 : Added original TypeHelper#findModfied and deprecated; changed deprecated methods to call the new methods.

(cherry picked from commit aaebcdf)
  • Loading branch information
barreiro authored and gbadner committed Mar 14, 2017
1 parent 3b75488 commit a9022e5
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 9 deletions.
Expand Up @@ -4206,7 +4206,6 @@ public int[] findDirty(Object[] currentState, Object[] previousState, Object ent
currentState,
previousState,
propertyColumnUpdateable,
hasUninitializedLazyProperties( entity ),
session
);
if ( props == null ) {
Expand Down Expand Up @@ -4237,7 +4236,6 @@ public int[] findModified(Object[] old, Object[] current, Object entity, Session
current,
old,
propertyColumnUpdateable,
hasUninitializedLazyProperties( entity ),
session
);
if ( props == null ) {
Expand Down
Expand Up @@ -86,7 +86,7 @@ public boolean isDirtyCheckable() {

@Override
public boolean isDirtyCheckable(boolean hasUninitializedProperties) {
return isDirtyCheckable() && ( !hasUninitializedProperties || !isLazy() );
return isDirtyCheckable();
}

@Override
Expand Down
Expand Up @@ -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();
Expand Down
64 changes: 58 additions & 6 deletions hibernate-core/src/main/java/org/hibernate/type/TypeHelper.java
Expand Up @@ -276,23 +276,49 @@ else if ( !types[i].isAssociationType() ) {
* @param includeColumns Columns to be included in the dirty checking, per property
* @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 dirty properties, or null if no properties considered dirty.
*
* @deprecated Use {org.hibernate.type.TypeHelper{@link #findDirty(NonIdentifierAttribute[], Object[], Object[], boolean[][], SessionImplementor)} instead
*/
@Deprecated
public static int[] findDirty(
final NonIdentifierAttribute[] properties,
final Object[] currentState,
final Object[] previousState,
final boolean[][] includeColumns,
final boolean anyUninitializedProperties,
final SessionImplementor 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 SessionImplementor 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 ) {
Expand Down Expand Up @@ -326,23 +352,49 @@ public static int[] findDirty(
* @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, SessionImplementor)}
* instead.
*/
@Deprecated
public static int[] findModified(
final NonIdentifierAttribute[] properties,
final Object[] currentState,
final Object[] previousState,
final boolean[][] includeColumns,
final boolean anyUninitializedProperties,
final SessionImplementor session) {
return findModified( properties, currentState, previousState, includeColumns, 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 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 SessionImplementor session) {
int[] results = null;
int count = 0;
int span = properties.length;

for ( int i = 0; i < span; i++ ) {
final boolean modified = currentState[i]!=LazyPropertyInitializer.UNFETCHED_PROPERTY
&& properties[i].isDirtyCheckable(anyUninitializedProperties)
&& properties[i].getType().isModified( previousState[i], currentState[i], includeColumns[i], session );

final boolean modified = currentState[ i ] != LazyPropertyInitializer.UNFETCHED_PROPERTY
&& properties[ i ].isDirtyCheckable()
&& properties[ i ].getType().isModified( previousState[ i ], currentState[ i ], includeColumns[ i ], session );
if ( modified ) {
if ( results == null ) {
results = new int[span];
Expand Down
Expand Up @@ -14,7 +14,9 @@
import org.hibernate.test.bytecode.enhancement.association.InheritedAttributeAssociationTestTask;
import org.hibernate.test.bytecode.enhancement.otherentityentrycontext.OtherEntityEntryContextTestTask;
import org.hibernate.test.bytecode.enhancement.cascade.CascadeWithFkConstraintTestTask;
import org.hibernate.testing.DialectChecks;
import org.hibernate.testing.FailureExpected;
import org.hibernate.testing.RequiresDialectFeature;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.bytecode.enhancement.EnhancerTestContext;
import org.hibernate.testing.bytecode.enhancement.EnhancerTestUtils;
Expand Down Expand Up @@ -122,6 +124,7 @@ public boolean hasLazyLoadableAttributes(CtClass classDescriptor) {

@Test
@TestForIssue( jiraKey = "HHH-11173" )
@RequiresDialectFeature( DialectChecks.SupportsIdentityColumns.class)
public void testLazyCache() {
EnhancerTestUtils.runEnhancerTestTask( LazyInCacheTestTask.class );
}
Expand Down Expand Up @@ -162,6 +165,17 @@ public void testLazyGroupsUpdateSimple() {
EnhancerTestUtils.runEnhancerTestTask( SimpleLazyGroupUpdateTestTask.class );
}

@Test
@TestForIssue( jiraKey = "HHH-11506" )
public void testLazyGroupsUpdateWithoutDirtyChecking() {
EnhancerTestUtils.runEnhancerTestTask( SimpleLazyGroupUpdateTestTask.class , new EnhancerTestContext() {
@Override
public boolean doDirtyCheckingInline(CtClass classDescriptor) {
return false;
}
} );
}

@Test
public void testLazyCollectionNoTransactionHandling() {
EnhancerTestUtils.runEnhancerTestTask( LazyCollectionNoTransactionLoadingTestTask.class );
Expand Down

0 comments on commit a9022e5

Please sign in to comment.