Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fix for GRAILS-5823 "JAR Locking / Resource Clean Up"

  • Loading branch information...
commit b67cc42727e9a6221923108b7df851c601396935 1 parent 023209f
@graemerocher graemerocher authored
View
22 ...ate/src/main/groovy/org/codehaus/groovy/grails/orm/hibernate/metaclass/AbstractSavePersistentMethod.java
@@ -69,12 +69,7 @@
* the value. Note that this only works because the session is
* flushed when a domain instance is saved without validation.
*/
- private static ThreadLocal<Set<Integer>> disableAutoValidationFor = new ThreadLocal<Set<Integer>>() {
- @Override
- protected Set<Integer> initialValue() {
- return new HashSet<Integer>();
- }
- };
+ private static ThreadLocal<Set<Integer>> disableAutoValidationFor = new ThreadLocal<Set<Integer>>();
static {
ShutdownOperations.addOperation(new Runnable() {
@@ -84,17 +79,24 @@ public void run() {
});
}
- public static boolean isAutoValidationDisabled(Object obj) {
+ private static Set<Integer> getDisableAutoValidationFor() {
Set<Integer> identifiers = disableAutoValidationFor.get();
+ if (identifiers == null)
+ disableAutoValidationFor.set(identifiers = new HashSet<Integer>());
+ return identifiers;
+ }
+
+ public static boolean isAutoValidationDisabled(Object obj) {
+ Set<Integer> identifiers = getDisableAutoValidationFor();
return obj != null && identifiers.contains(System.identityHashCode(obj));
}
public static void clearDisabledValidations(Object obj) {
- disableAutoValidationFor.get().remove(System.identityHashCode(obj));
+ getDisableAutoValidationFor().remove(System.identityHashCode(obj));
}
public static void clearDisabledValidations() {
- disableAutoValidationFor.get().clear();
+ getDisableAutoValidationFor().clear();
}
public AbstractSavePersistentMethod(Pattern pattern, SessionFactory sessionFactory,
@@ -199,7 +201,7 @@ protected Object doInvokeInternal(final Object target, Object[] arguments) {
}
if (!shouldValidate) {
- Set<Integer> identifiers = disableAutoValidationFor.get();
+ Set<Integer> identifiers = getDisableAutoValidationFor();
identifiers.add(System.identityHashCode(target));
}
View
30 ...main/groovy/org/codehaus/groovy/grails/orm/hibernate/support/HibernatePersistenceContextInterceptor.java
@@ -47,19 +47,8 @@ public void run() {
});
}
- private static ThreadLocal<Boolean> participate = new ThreadLocal<Boolean>() {
- @Override
- protected Boolean initialValue() {
- return Boolean.FALSE;
- }
- };
-
- private static ThreadLocal<Integer> nestingCount = new ThreadLocal<Integer>() {
- @Override
- protected Integer initialValue() {
- return Integer.valueOf(0);
- }
- };
+ private static ThreadLocal<Boolean> participate = new ThreadLocal<Boolean>();
+ private static ThreadLocal<Integer> nestingCount = new ThreadLocal<Integer>();
/* (non-Javadoc)
* @see org.codehaus.groovy.grails.support.PersistenceContextInterceptor#destroy()
@@ -170,25 +159,28 @@ public void setSessionFactory(SessionFactory sessionFactory) {
}
private int incNestingCount() {
- int value = nestingCount.get().intValue() + 1;
- nestingCount.set(Integer.valueOf(value));
+ Integer current = nestingCount.get();
+ int value = (current != null) ? current + 1 : 1;
+ nestingCount.set(value);
return value;
}
private int decNestingCount() {
- int value = nestingCount.get().intValue() - 1;
+ Integer current = nestingCount.get();
+ int value = (current != null) ? current - 1 : 0;
if (value < 0) {
value = 0;
}
- nestingCount.set(Integer.valueOf(value));
+ nestingCount.set(value);
return value;
}
private void setParticipate(boolean flag) {
- participate.set(Boolean.valueOf(flag));
+ participate.set(flag);
}
private boolean getParticipate() {
- return participate.get().booleanValue();
+ Boolean ret = participate.get();
+ return (ret != null) ? ret : false;
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.