Skip to content

Commit 1e44e74

Browse files
committed
HHH-10267 - Support defining lazy attribute fetch groups
1 parent 6afc759 commit 1e44e74

File tree

69 files changed

+1304
-575
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+1304
-575
lines changed

hibernate-core/src/main/java/org/hibernate/action/internal/AbstractEntityInsertAction.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,7 @@ public final void makeEntityManaged() {
132132
LockMode.WRITE,
133133
isExecuted,
134134
getPersister(),
135-
isVersionIncrementDisabled,
136-
false
135+
isVersionIncrementDisabled
137136
);
138137
}
139138

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Hibernate, Relational Persistence for Idiomatic Java
3+
*
4+
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
5+
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
6+
*/
7+
package org.hibernate.annotations;
8+
9+
import java.lang.annotation.ElementType;
10+
import java.lang.annotation.Retention;
11+
import java.lang.annotation.RetentionPolicy;
12+
13+
/**
14+
* For use with bytecode-enhanced lazy-loading support.
15+
* <p/>
16+
* Identifies grouping for performing lazy attribute loading. By default all
17+
* non-collection attributes are loaded in one group named {@code "DEFAULT"}.
18+
* This annotation allows defining different groups of attributes to be
19+
* initialized together when access one attribute in the group.
20+
*
21+
* @author Steve Ebersole
22+
*/
23+
@java.lang.annotation.Target({ElementType.METHOD, ElementType.FIELD})
24+
@Retention(RetentionPolicy.RUNTIME)
25+
public @interface LazyGroup {
26+
String value();
27+
}

hibernate-core/src/main/java/org/hibernate/bytecode/enhance/spi/LazyPropertyInitializer.java

+8-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
package org.hibernate.bytecode.enhance.spi;
88

99
import java.io.Serializable;
10+
import java.util.Set;
1011

1112
import org.hibernate.engine.spi.SessionImplementor;
1213

@@ -20,7 +21,7 @@ public interface LazyPropertyInitializer {
2021
/**
2122
* Marker value for uninitialized properties.
2223
*/
23-
public static final Serializable UNFETCHED_PROPERTY = new Serializable() {
24+
Serializable UNFETCHED_PROPERTY = new Serializable() {
2425
@Override
2526
public String toString() {
2627
return "<lazy>";
@@ -31,6 +32,11 @@ public Object readResolve() {
3132
}
3233
};
3334

35+
interface InterceptorImplementor {
36+
Set<String> getInitializedLazyAttributeNames();
37+
void attributeInitialized(String name);
38+
}
39+
3440
/**
3541
* Initialize the property, and return its new value.
3642
*
@@ -40,6 +46,6 @@ public Object readResolve() {
4046
*
4147
* @return ?
4248
*/
43-
public Object initializeLazyProperty(String fieldName, Object entity, SessionImplementor session);
49+
Object initializeLazyProperty(String fieldName, Object entity, SessionImplementor session);
4450

4551
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
/*
2+
* Hibernate, Relational Persistence for Idiomatic Java
3+
*
4+
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
5+
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
6+
*/
7+
package org.hibernate.bytecode.enhance.spi.interceptor;
8+
9+
import org.hibernate.mapping.Property;
10+
import org.hibernate.type.Type;
11+
12+
/**
13+
* Descriptor for an attribute which is enabled for bytecode lazy fetching
14+
*
15+
* @author Steve Ebersole
16+
*/
17+
public class LazyAttributeDescriptor {
18+
public static LazyAttributeDescriptor from(
19+
Property property,
20+
int attributeIndex,
21+
int lazyIndex) {
22+
String fetchGroupName = property.getLazyGroup();
23+
if ( fetchGroupName == null ) {
24+
fetchGroupName = property.getType().isCollectionType()
25+
? property.getName()
26+
: "DEFAULT";
27+
}
28+
29+
return new LazyAttributeDescriptor(
30+
attributeIndex,
31+
lazyIndex,
32+
property.getName(),
33+
property.getType(),
34+
fetchGroupName
35+
);
36+
}
37+
38+
private final int attributeIndex;
39+
private final int lazyIndex;
40+
private final String name;
41+
private final Type type;
42+
private final String fetchGroupName;
43+
44+
private LazyAttributeDescriptor(
45+
int attributeIndex,
46+
int lazyIndex,
47+
String name,
48+
Type type,
49+
String fetchGroupName) {
50+
assert attributeIndex >= lazyIndex;
51+
this.attributeIndex = attributeIndex;
52+
this.lazyIndex = lazyIndex;
53+
this.name = name;
54+
this.type = type;
55+
this.fetchGroupName = fetchGroupName;
56+
}
57+
58+
/**
59+
* Access to the index of the attribute in terms of its position in the entity persister
60+
*
61+
* @return The persister attribute index
62+
*/
63+
public int getAttributeIndex() {
64+
return attributeIndex;
65+
}
66+
67+
/**
68+
* Access to the index of the attribute in terms of its position withing the lazy attributes of the persister
69+
*
70+
* @return The persister lazy attribute index
71+
*/
72+
public int getLazyIndex() {
73+
return lazyIndex;
74+
}
75+
76+
/**
77+
* Access to the name of the attribute
78+
*
79+
* @return The attribute name
80+
*/
81+
public String getName() {
82+
return name;
83+
}
84+
85+
/**
86+
* Access to the attribute's type
87+
*
88+
* @return The attribute type
89+
*/
90+
public Type getType() {
91+
return type;
92+
}
93+
94+
/**
95+
* Access to the name of the fetch group to which the attribute belongs
96+
*
97+
* @return The name of the fetch group the attribute belongs to
98+
*/
99+
public String getFetchGroupName() {
100+
return fetchGroupName;
101+
}
102+
}

0 commit comments

Comments
 (0)