diff options
author | Jim Hahn <jrh3@att.com> | 2020-04-06 15:33:23 -0400 |
---|---|---|
committer | Jim Hahn <jrh3@att.com> | 2020-04-06 19:30:02 -0400 |
commit | 15014b8ca386a8bfd5c26435f45de94ca06e95e8 (patch) | |
tree | 3cca518b950dfa35da0ea64dab2f9ff2b80f4595 /feature-session-persistence/src/main | |
parent | ece155048af47ea83ff898c999aa5137dc99a988 (diff) |
Address sonar issues in drools-pdp
Addressed the following sonar issues:
- add "final" to public static fields
- commented code; some were bogus - just updated the comments
so sonar is happy
- use "{}" instead of string concatenation
- junit should assert something
- when using logger, invoke compute-intensive tasks conditionally
- use superclass name instead of subclass name to access static fields
- don't always return the same value
- remove "transient" from fields of classes that aren't Serializable
- don't nest try/catch blocks
- use appropriate class name in Logger.getLogger()
- use Predicate<T> instead of Function<T,Boolean>
- remove unused parameters from private methods
- either log or throw
- remove duplicate methods
- use remove() TLS instead of set(null)
- null check is implicit in instanceof check
- do something with return value
- don't use volatile
- don't return "null" list; used Optional instead
- add no-arg constructor to non-Serializable superclass
- add callSuper=true for EqualsAndHashCode
- don't declare "throws XXX" where XXX is a subclass of RuntimeException
- remove serialVersionUID field if the class isn't Serializable
Also addressed some eclipse warnings:
- unused fields
- suppress generic typic cast warnings
Issue-ID: POLICY-2305
Change-Id: I906d5bf71c1f86531423e23b3667a585cdba45e1
Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'feature-session-persistence/src/main')
-rw-r--r-- | feature-session-persistence/src/main/java/org/onap/policy/drools/persistence/PersistenceFeature.java | 29 |
1 files changed, 13 insertions, 16 deletions
diff --git a/feature-session-persistence/src/main/java/org/onap/policy/drools/persistence/PersistenceFeature.java b/feature-session-persistence/src/main/java/org/onap/policy/drools/persistence/PersistenceFeature.java index cc826905..a4965888 100644 --- a/feature-session-persistence/src/main/java/org/onap/policy/drools/persistence/PersistenceFeature.java +++ b/feature-session-persistence/src/main/java/org/onap/policy/drools/persistence/PersistenceFeature.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * feature-session-persistence * ================================================================================ - * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2020 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -38,6 +38,7 @@ import javax.transaction.UserTransaction; import org.apache.commons.dbcp2.BasicDataSource; import org.apache.commons.dbcp2.BasicDataSourceFactory; +import org.hibernate.cfg.AvailableSettings; import org.kie.api.KieServices; import org.kie.api.runtime.Environment; import org.kie.api.runtime.EnvironmentName; @@ -94,7 +95,7 @@ public class PersistenceFeature implements PolicySessionFeatureApi, PolicyEngine Object rval = policyContainer.getAdjunct(this); - if (rval == null || !(rval instanceof ContainerAdjunct)) { + if (!(rval instanceof ContainerAdjunct)) { // adjunct does not exist, or has the wrong type (should never // happen) rval = new ContainerAdjunct(policyContainer); @@ -199,11 +200,7 @@ public class PersistenceFeature implements PolicySessionFeatureApi, PolicyEngine **/ @Override public boolean beforeStart(PolicyEngine engine) { - synchronized (cleanupLock) { - sessInfoCleaned = false; - } - - return false; + return cleanup(); } /** @@ -211,6 +208,10 @@ public class PersistenceFeature implements PolicySessionFeatureApi, PolicyEngine **/ @Override public boolean beforeActivate(PolicyEngine engine) { + return cleanup(); + } + + private boolean cleanup() { synchronized (cleanupLock) { sessInfoCleaned = false; } @@ -641,7 +642,7 @@ public class PersistenceFeature implements PolicySessionFeatureApi, PolicyEngine try { minSleepTime = Math.max(1, Integer.valueOf(sleepTimeString)); } catch (Exception e) { - logger.error(sleepTimeString + ": Illegal value for 'minSleepTime'", e); + logger.error("{}: Illegal value for 'minSleepTime'", sleepTimeString, e); } } @@ -652,18 +653,14 @@ public class PersistenceFeature implements PolicySessionFeatureApi, PolicyEngine try { maxSleepTime = Math.max(1, Integer.valueOf(sleepTimeString)); } catch (Exception e) { - logger.error(sleepTimeString + ": Illegal value for 'maxSleepTime'", e); + logger.error("{}: Illegal value for 'maxSleepTime'", sleepTimeString, e); } } // swap values if needed if (minSleepTime > maxSleepTime) { - logger.error( - "minSleepTime(" - + minSleepTime - + ") is greater than maxSleepTime(" - + maxSleepTime - + ") -- swapping"); + logger.error("minSleepTime({}) is greater than maxSleepTime({}) -- swapping", minSleepTime, + maxSleepTime); long tmp = minSleepTime; minSleepTime = maxSleepTime; maxSleepTime = tmp; @@ -791,7 +788,7 @@ public class PersistenceFeature implements PolicySessionFeatureApi, PolicyEngine public DsEmf(BasicDataSource bds) { try { Map<String, Object> props = new HashMap<>(); - props.put(org.hibernate.cfg.Environment.JPA_JTA_DATASOURCE, bds); + props.put(AvailableSettings.JPA_JTA_DATASOURCE, bds); this.bds = bds; this.emf = makeEntMgrFact(props); |