Skip to content

Commit 750d6fb

Browse files
committed
HHH-9857 - Reuse of EntityEntry for bytecode enhanced read-only reference cached entities
1 parent 3a515b5 commit 750d6fb

File tree

3 files changed

+19
-51
lines changed

3 files changed

+19
-51
lines changed

hibernate-core/src/main/java/org/hibernate/engine/internal/AbstractEntityEntry.java

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
*/
77
package org.hibernate.engine.internal;
88

9+
import java.io.IOException;
10+
import java.io.ObjectOutputStream;
11+
import java.io.Serializable;
12+
913
import org.hibernate.AssertionFailure;
1014
import org.hibernate.CustomEntityDirtinessStrategy;
1115
import org.hibernate.EntityMode;
@@ -26,15 +30,8 @@
2630
import org.hibernate.persister.entity.UniqueKeyLoadable;
2731
import org.hibernate.pretty.MessageHelper;
2832

29-
import java.io.IOException;
30-
import java.io.ObjectOutputStream;
31-
import java.io.Serializable;
32-
3333
/**
34-
* We need an entry to tell us all about the current state of an mutable object with respect to its persistent state
35-
*
36-
* Implementation Warning: Hibernate needs to instantiate a high amount of instances of this class,
37-
* therefore we need to take care of its impact on memory consumption.
34+
* A base implementation of EntityEntry
3835
*
3936
* @author Gavin King
4037
* @author Emmanuel Bernard <[email protected]>
@@ -69,7 +66,7 @@ public abstract class AbstractEntityEntry implements Serializable, EntityEntry {
6966
* 0000 0000 | 0000 0000 | 0654 3333 | 2222 1111
7067
* </pre>
7168
* Use {@link #setCompressedValue(org.hibernate.engine.internal.AbstractEntityEntry.EnumState, Enum)},
72-
* {@link #getCompressedValue(org.hibernate.engine.internal.AbstractEntityEntry.EnumState, Class)} etc
69+
* {@link #getCompressedValue(org.hibernate.engine.internal.AbstractEntityEntry.EnumState)} etc
7370
* to access the enums and booleans stored in this value.
7471
* <p>
7572
* Representing enum values by their ordinal value is acceptable for our case as this value itself is never

hibernate-core/src/main/java/org/hibernate/engine/internal/ImmutableEntityEntry.java

Lines changed: 8 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
*/
77
package org.hibernate.engine.internal;
88

9+
import java.io.IOException;
10+
import java.io.ObjectInputStream;
11+
import java.io.Serializable;
12+
913
import org.hibernate.EntityMode;
1014
import org.hibernate.LockMode;
1115
import org.hibernate.UnsupportedLockAttemptException;
@@ -15,49 +19,19 @@
1519
import org.hibernate.engine.spi.Status;
1620
import org.hibernate.persister.entity.EntityPersister;
1721

18-
import java.io.IOException;
19-
import java.io.ObjectInputStream;
20-
import java.io.Serializable;
21-
2222
/**
23-
* We need an entry to tell us all about the current state of an mutable object with respect to its persistent state
24-
*
25-
* Implementation Warning: Hibernate needs to instantiate a high amount of instances of this class,
26-
* therefore we need to take care of its impact on memory consumption.
23+
* An EntityEntry implementation for immutable entities. Note that this implementation is not completely
24+
* immutable in terms of its internal state; the term immutable here refers to the entity is describes.
2725
*
2826
* @author Gavin King
2927
* @author Emmanuel Bernard <[email protected]>
3028
* @author Gunnar Morling
3129
* @author Sanne Grinovero <[email protected]>
30+
*
31+
* @see org.hibernate.annotations.Immutable
3232
*/
3333
public final class ImmutableEntityEntry extends AbstractEntityEntry {
3434

35-
/**
36-
* Holds several boolean and enum typed attributes in a very compact manner. Enum values are stored in 4 bits
37-
* (where 0 represents {@code null}, and each enum value is represented by its ordinal value + 1), thus allowing
38-
* for up to 15 values per enum. Boolean values are stored in one bit.
39-
* <p>
40-
* The value is structured as follows:
41-
*
42-
* <pre>
43-
* 1 - Lock mode
44-
* 2 - Status
45-
* 3 - Previous Status
46-
* 4 - existsInDatabase
47-
* 5 - isBeingReplicated
48-
* 6 - loadedWithLazyPropertiesUnfetched; NOTE: this is not updated when properties are fetched lazily!
49-
*
50-
* 0000 0000 | 0000 0000 | 0654 3333 | 2222 1111
51-
* </pre>
52-
* Use {@link #setCompressedValue(org.hibernate.engine.internal.ImmutableEntityEntry.EnumState, Enum)},
53-
* {@link #getCompressedValue(org.hibernate.engine.internal.ImmutableEntityEntry.EnumState, Class)} etc
54-
* to access the enums and booleans stored in this value.
55-
* <p>
56-
* Representing enum values by their ordinal value is acceptable for our case as this value itself is never
57-
* serialized or deserialized and thus is not affected should ordinal values change.
58-
*/
59-
private transient int compressedState;
60-
6135
/**
6236
* @deprecated the tenantId and entityMode parameters where removed: this constructor accepts but ignores them.
6337
* Use the other constructor!

hibernate-core/src/main/java/org/hibernate/engine/internal/MutableEntityEntry.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
*/
77
package org.hibernate.engine.internal;
88

9+
import java.io.IOException;
10+
import java.io.ObjectInputStream;
11+
import java.io.Serializable;
12+
913
import org.hibernate.EntityMode;
1014
import org.hibernate.LockMode;
1115
import org.hibernate.engine.spi.EntityEntry;
@@ -14,15 +18,8 @@
1418
import org.hibernate.engine.spi.Status;
1519
import org.hibernate.persister.entity.EntityPersister;
1620

17-
import java.io.IOException;
18-
import java.io.ObjectInputStream;
19-
import java.io.Serializable;
20-
2121
/**
22-
* We need an entry to tell us all about the current state of an mutable object with respect to its persistent state
23-
*
24-
* Implementation Warning: Hibernate needs to instantiate a high amount of instances of this class,
25-
* therefore we need to take care of its impact on memory consumption.
22+
* An EntityEntry implementation for mutable entities.
2623
*
2724
* @author Gavin King
2825
* @author Emmanuel Bernard <[email protected]>

0 commit comments

Comments
 (0)