You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jdo-commits@db.apache.org by mb...@apache.org on 2023/05/10 20:22:40 UTC
[db-jdo] 01/01: JDO-823: Cognitive Complexity of methods should not be too high
This is an automated email from the ASF dual-hosted git repository.
mbo pushed a commit to branch JDO-823-4
in repository https://gitbox.apache.org/repos/asf/db-jdo.git
commit 9993193dcdcd1606b85f244b146187dc33a99f04
Author: Michael Bouschen <Mi...@akquinet.de>
AuthorDate: Wed May 10 22:22:29 2023 +0200
JDO-823: Cognitive Complexity of methods should not be too high
---
api/src/main/java/javax/jdo/JDOHelper.java | 195 +++++++++++------------------
1 file changed, 72 insertions(+), 123 deletions(-)
diff --git a/api/src/main/java/javax/jdo/JDOHelper.java b/api/src/main/java/javax/jdo/JDOHelper.java
index 0a5ae4bd..1b305a97 100644
--- a/api/src/main/java/javax/jdo/JDOHelper.java
+++ b/api/src/main/java/javax/jdo/JDOHelper.java
@@ -518,64 +518,21 @@ public class JDOHelper implements Constants {
}
if (isDetached(pc)) {
- if (isDirty(pc)) {
- // Detached Dirty
- return ObjectState.DETACHED_DIRTY;
- } else {
- // Detached Not Dirty
- return ObjectState.DETACHED_CLEAN;
- }
+ return isDirty(pc) ? ObjectState.DETACHED_DIRTY : ObjectState.DETACHED_CLEAN;
} else {
if (isPersistent(pc)) {
- if (isTransactional(pc)) {
- if (isDirty(pc)) {
- if (isNew(pc)) {
- if (isDeleted(pc)) {
- // Persistent Transactional Dirty New Deleted
- return ObjectState.PERSISTENT_NEW_DELETED;
- } else {
- // Persistent Transactional Dirty New Not Deleted
- return ObjectState.PERSISTENT_NEW;
- }
- } else {
- if (isDeleted(pc)) {
- // Persistent Transactional Dirty Not New Deleted
- return ObjectState.PERSISTENT_DELETED;
- } else {
- // Persistent Transactional Dirty Not New Not Deleted
- return ObjectState.PERSISTENT_DIRTY;
- }
- }
- } else {
- // Persistent Transactional Not Dirty
- return ObjectState.PERSISTENT_CLEAN;
- }
- } else {
- if (isDirty(pc)) {
- // Persistent Nontransactional Dirty
- return ObjectState.PERSISTENT_NONTRANSACTIONAL_DIRTY;
- } else {
- // Persistent Nontransactional Not Dirty
- return ObjectState.HOLLOW_PERSISTENT_NONTRANSACTIONAL;
- }
- }
+ return isTransactional(pc)
+ ? getPersistentTransactionalObjectState(pc)
+ : getPersistentNonTransactionalObjectState(pc);
} else {
- if (isTransactional(pc)) {
- if (isDirty(pc)) {
- // Not Persistent Transactional Dirty
- return ObjectState.TRANSIENT_DIRTY;
- } else {
- // Not Persistent Transactional Not Dirty
- return ObjectState.TRANSIENT_CLEAN;
- }
- } else {
- // Not Persistent Not Transactional
- return ObjectState.TRANSIENT;
- }
+ return isTransactional(pc)
+ ? getTransientTransactionalObjectState(pc)
+ : ObjectState.TRANSIENT;
}
}
}
+
/**
* Get the anonymous <code>PersistenceManagerFactory</code> configured via the standard
* configuration file resource "META-INF/jdoconfig.xml", using the current thread's context class
@@ -1013,79 +970,48 @@ public class JDOHelper implements Constants {
*/
protected static PersistenceManagerFactory invokeGetPersistenceManagerFactoryOnImplementation(
String pmfClassName, Map<?, ?> overrides, Map<?, ?> properties, ClassLoader cl) {
- if (overrides != null) {
- // overrides is not null; use getPersistenceManagerFactory(Map overrides, Map props)
- try {
- Class<?> implClass = forName(pmfClassName, true, cl);
- Method m =
- getMethod(
- implClass,
- "getPersistenceManagerFactory", // NOI18N
- new Class[] {Map.class, Map.class});
- PersistenceManagerFactory pmf =
- (PersistenceManagerFactory) invoke(m, null, new Object[] {overrides, properties});
- if (pmf == null) {
- throw new JDOFatalInternalException(MSG.msg("EXC_GetPMFNullPMF", pmfClassName)); // NOI18N
- }
- return pmf;
-
- } catch (ClassNotFoundException e) {
- throw new JDOFatalUserException(
- MSG.msg("EXC_GetPMFClassNotFound", pmfClassName), e); // NOI18N
- } catch (NoSuchMethodException e) {
- throw new JDOFatalInternalException(
- MSG.msg("EXC_GetPMFNoSuchMethod2", pmfClassName), e); // NOI18N
- } catch (NullPointerException e) {
- throw new JDOFatalInternalException(
- MSG.msg("EXC_GetPMFNullPointerException", pmfClassName), e); // NOI18N
- } catch (IllegalAccessException e) {
- throw new JDOFatalUserException(
- MSG.msg("EXC_GetPMFIllegalAccess", pmfClassName), e); // NOI18N
- } catch (ClassCastException e) {
- throw new JDOFatalInternalException(
- MSG.msg("EXC_GetPMFClassCastException", pmfClassName), e); // NOI18N
- } catch (InvocationTargetException ite) {
- Throwable nested = ite.getTargetException();
- if (nested instanceof JDOException) {
- throw (JDOException) nested;
- } else throw new JDOFatalInternalException(MSG.msg(EXC_GET_PMF_UNEXPECTED_EXCEPTION), ite);
- }
- } else {
- // overrides is null; use getPersistenceManagerFactory(Map props)
- try {
- Class<?> implClass = forName(pmfClassName, true, cl);
- Method m =
- getMethod(
- implClass,
- "getPersistenceManagerFactory", // NOI18N
- new Class[] {Map.class});
- PersistenceManagerFactory pmf =
- (PersistenceManagerFactory) invoke(m, null, new Object[] {properties});
- if (pmf == null) {
- throw new JDOFatalInternalException(MSG.msg("EXC_GetPMFNullPMF", pmfClassName)); // NOI18N
- }
- return pmf;
- } catch (ClassNotFoundException e) {
- throw new JDOFatalUserException(
- MSG.msg("EXC_GetPMFClassNotFound", pmfClassName), e); // NOI18N
- } catch (NoSuchMethodException e) {
- throw new JDOFatalInternalException(
- MSG.msg("EXC_GetPMFNoSuchMethod", pmfClassName), e); // NOI18N
- } catch (NullPointerException e) {
- throw new JDOFatalInternalException(
- MSG.msg("EXC_GetPMFNullPointerException", pmfClassName), e); // NOI18N
- } catch (IllegalAccessException e) {
- throw new JDOFatalUserException(
- MSG.msg("EXC_GetPMFIllegalAccess", pmfClassName), e); // NOI18N
- } catch (ClassCastException e) {
- throw new JDOFatalInternalException(
- MSG.msg("EXC_GetPMFClassCastException", pmfClassName), e); // NOI18N
- } catch (InvocationTargetException ite) {
- Throwable nested = ite.getTargetException();
- if (nested instanceof JDOException) {
- throw (JDOException) nested;
- } else throw new JDOFatalInternalException(MSG.msg(EXC_GET_PMF_UNEXPECTED_EXCEPTION), ite);
+ try {
+ Class<?> implClass = forName(pmfClassName, true, cl);
+ Method m =
+ getMethod(
+ implClass,
+ "getPersistenceManagerFactory", // NOI18N
+ overrides != null ? new Class[] {Map.class, Map.class} : new Class[] {Map.class});
+ PersistenceManagerFactory pmf =
+ (PersistenceManagerFactory)
+ invoke(
+ m,
+ null,
+ overrides != null
+ ? new Object[] {overrides, properties}
+ : new Object[] {properties});
+ if (pmf == null) {
+ throw new JDOFatalInternalException(MSG.msg("EXC_GetPMFNullPMF", pmfClassName)); // NOI18N
}
+ return pmf;
+ } catch (ClassNotFoundException e) {
+ throw new JDOFatalUserException(
+ MSG.msg("EXC_GetPMFClassNotFound", pmfClassName), e); // NOI18N
+ } catch (NoSuchMethodException e) {
+ throw new JDOFatalInternalException(
+ MSG.msg(
+ overrides != null ? "EXC_GetPMFNoSuchMethod2" : "EXC_GetPMFNoSuchMethod",
+ pmfClassName),
+ e); // NOI18N
+ } catch (NullPointerException e) {
+ throw new JDOFatalInternalException(
+ MSG.msg("EXC_GetPMFNullPointerException", pmfClassName), e); // NOI18N
+ } catch (IllegalAccessException e) {
+ throw new JDOFatalUserException(
+ MSG.msg("EXC_GetPMFIllegalAccess", pmfClassName), e); // NOI18N
+ } catch (ClassCastException e) {
+ throw new JDOFatalInternalException(
+ MSG.msg("EXC_GetPMFClassCastException", pmfClassName), e); // NOI18N
+ } catch (InvocationTargetException ite) {
+ Throwable nested = ite.getTargetException();
+ if (nested instanceof JDOException) {
+ throw (JDOException) nested;
+ } else throw new JDOFatalInternalException(MSG.msg(EXC_GET_PMF_UNEXPECTED_EXCEPTION), ite);
}
}
@@ -1808,4 +1734,27 @@ public class JDOHelper implements Constants {
throw new PrivilegedActionException(e);
}
}
+
+ private static ObjectState getPersistentTransactionalObjectState(Object pc) {
+ if (isDirty(pc)) {
+ if (isNew(pc)) {
+ return isDeleted(pc) ? ObjectState.PERSISTENT_NEW_DELETED : ObjectState.PERSISTENT_NEW;
+ } else {
+ return isDeleted(pc) ? ObjectState.PERSISTENT_DELETED : ObjectState.PERSISTENT_DIRTY;
+ }
+ } else {
+ // Persistent Transactional Not Dirty
+ return ObjectState.PERSISTENT_CLEAN;
+ }
+ }
+
+ private static ObjectState getPersistentNonTransactionalObjectState(Object pc) {
+ return isDirty(pc)
+ ? ObjectState.PERSISTENT_NONTRANSACTIONAL_DIRTY
+ : ObjectState.HOLLOW_PERSISTENT_NONTRANSACTIONAL;
+ }
+
+ private static ObjectState getTransientTransactionalObjectState(Object pc) {
+ return isDirty(pc) ? ObjectState.TRANSIENT_DIRTY : ObjectState.TRANSIENT_CLEAN;
+ }
}