From fd809717ca774dfabeddd3984fbbbbdfd029601e Mon Sep 17 00:00:00 2001 From: Jim Hahn Date: Mon, 26 Aug 2019 12:20:27 -0400 Subject: Replace copyTo methods with copy constructors Deleted the copyTo() method from PfConcepts and replaced uses with deep-copy constructors. Also added mapMap() and makeCopy() methods to PfUtils to facilitate. Change-Id: Id6391bb806ef0dfab6c1089278bf2b514c7e303e Issue-ID: POLICY-1600 Signed-off-by: Jim Hahn --- .../main/java/org/onap/policy/models/dao/impl/DefaultPfDao.java | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'models-dao/src/main/java') diff --git a/models-dao/src/main/java/org/onap/policy/models/dao/impl/DefaultPfDao.java b/models-dao/src/main/java/org/onap/policy/models/dao/impl/DefaultPfDao.java index b5739a610..62b9c41a3 100644 --- a/models-dao/src/main/java/org/onap/policy/models/dao/impl/DefaultPfDao.java +++ b/models-dao/src/main/java/org/onap/policy/models/dao/impl/DefaultPfDao.java @@ -35,6 +35,7 @@ import org.onap.policy.models.base.PfConceptKey; import org.onap.policy.models.base.PfModelException; import org.onap.policy.models.base.PfModelRuntimeException; import org.onap.policy.models.base.PfReferenceKey; +import org.onap.policy.models.base.PfUtils; import org.onap.policy.models.dao.DaoParameters; import org.onap.policy.models.dao.PfDao; import org.slf4j.Logger; @@ -327,9 +328,7 @@ public class DefaultPfDao implements PfDao { if (t != null) { // This clone is created to force the JPA DAO to recurse down through the object try { - final T clonedT = someClass.newInstance(); - t.copyTo(clonedT); - return clonedT; + return PfUtils.makeCopy(t); } catch (final Exception e) { LOGGER.warn("Could not clone object of class \"" + someClass.getName() + "\"", e); return null; @@ -352,9 +351,7 @@ public class DefaultPfDao implements PfDao { final T t = mg.find(someClass, key); if (t != null) { try { - final T clonedT = someClass.newInstance(); - t.copyTo(clonedT); - return clonedT; + return PfUtils.makeCopy(t); } catch (final Exception e) { LOGGER.warn("Could not clone object of class \"" + someClass.getName() + "\"", e); return null; -- cgit 1.2.3-korg