Skip to content

Commit

Permalink
JDO-823: Cognitive Complexity of methods should not be too high (#77)
Browse files Browse the repository at this point in the history
* JDO-823: Cognitive Complexity of methods should not be too high

* JDO-823: Type parameter names should comply with naming convention

Changed code formatting
  • Loading branch information
mboapache authored May 11, 2023
1 parent a4f0234 commit 51e3f00
Showing 1 changed file with 71 additions and 123 deletions.
194 changes: 71 additions & 123 deletions api/src/main/java/javax/jdo/JDOHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -518,60 +518,16 @@ public static ObjectState getObjectState(Object pc) {
}

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;
}
}
}
Expand Down Expand Up @@ -1013,79 +969,48 @@ public static PersistenceManagerFactory getPersistenceManagerFactory(
*/
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);
}
}

Expand Down Expand Up @@ -1808,4 +1733,27 @@ private static <T> T doPrivileged(PrivilegedExceptionAction<T> privilegedAction)
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;
}
}

0 comments on commit 51e3f00

Please sign in to comment.