8000 HHH-6868 Lazily initialize HashMap in LockOptions · JavaInCloud/hibernate-orm@588a9d6 · GitHub
[go: up one dir, main page]

Skip to content

Commit 588a9d6

Browse files
committed
HHH-6868 Lazily initialize HashMap in LockOptions
1 parent eb23512 commit 588a9d6

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

hibernate-core/src/main/java/org/hibernate/LockOptions.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
*/
2525
package org.hibernate;
2626
import java.io.Serializable;
27+
import java.util.Collections;
2728
import java.util.HashMap;
2829
import java.util.Iterator;
2930
import java.util.Map;
@@ -83,7 +84,7 @@ public LockOptions setLockMode(LockMode lockMode) {
8384
return this;
8485
}
8586

86-
private Map aliasSpecificLockModes = new HashMap();
87+
private Map aliasSpecificLockModes = null; //initialize lazily as LockOptions is frequently created without needing this
8788

8889
/**
8990
* Specify the {@link LockMode} to be used for a specific query alias.
@@ -97,6 +98,9 @@ public LockOptions setLockMode(LockMode lockMode) {
9798
* @see Criteria#setLockMode(String, LockMode)
9899
*/
99100
public LockOptions setAliasSpecificLockMode(String alias, LockMode lockMode) {
101+
if ( aliasSpecificLockModes == null ) {
102+
aliasSpecificLockModes = new HashMap();
103+
}
100104
aliasSpecificLockModes.put( alias, lockMode );
101105
return this;
102106
}
@@ -113,6 +117,9 @@ public LockOptions setAliasSpecificLockMode(String alias, LockMode lockMode) {
113117
* @return The explicit lock mode for that alias.
114118
*/
115119
public LockMode getAliasSpecificLockMode(String alias) {
120+
if ( aliasSpecificLockModes == null ) {
121+
return null;
122+
}
116123
return (LockMode) aliasSpecificLockModes.get( alias );
117124
}
118125

@@ -143,6 +150,9 @@ public LockMode getEffectiveLockMode(String alias) {
143150
* @return the number of explicitly defined alias lock modes.
144151
*/
145152
public int getAliasLockCount() {
153+
if ( aliasSpecificLockModes == null ) {
154+
return 0;
155+
}
146156
return aliasSpecificLockModes.size();
147157
}
148158

@@ -152,6 +162,9 @@ public int getAliasLockCount() {
152162
* @return Iterator for accessing the Map.Entry's
153163
*/
154164
public Iterator getAliasLockIterator() {
165+
if ( aliasSpecificLockModes == null ) {
166+
return Collections.emptyList().iterator();
167+
}
155168
return aliasSpecificLockModes.entrySet().iterator();
156169
}
157170

@@ -234,7 +247,9 @@ public static LockOptions copy(LockOptions from, LockOptions dest) {
234247
dest.setLockMode(from.getLockMode());
235248
dest.setScope(from.getScope());
236249
dest.setTimeOut(from.getTimeOut());
237-
dest.aliasSpecificLockModes = new HashMap(from.aliasSpecificLockModes );
250+
if ( from.aliasSpecificLockModes != null ) {
251+
dest.aliasSpecificLockModes = new HashMap( from.aliasSpecificLockModes );
252+
}
238253
return dest;
239254
}
240255
}

0 commit comments

Comments
 (0)
0