aboutsummaryrefslogtreecommitdiffstats
path: root/models-dao/src
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2019-08-26 12:20:27 -0400
committerJim Hahn <jrh3@att.com>2019-08-27 11:49:30 -0400
commitfd809717ca774dfabeddd3984fbbbbdfd029601e (patch)
treea4070c2529b0be1899ece44e3687b72ed32505a4 /models-dao/src
parenta930b0105c2e45a657427cfcb41fc0330d0c2e99 (diff)
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 <jrh3@att.com>
Diffstat (limited to 'models-dao/src')
-rw-r--r--models-dao/src/main/java/org/onap/policy/models/dao/impl/DefaultPfDao.java9
-rw-r--r--models-dao/src/test/java/org/onap/policy/models/dao/DummyConceptEntity.java27
-rw-r--r--models-dao/src/test/java/org/onap/policy/models/dao/DummyReferenceEntity.java19
3 files changed, 20 insertions, 35 deletions
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;
diff --git a/models-dao/src/test/java/org/onap/policy/models/dao/DummyConceptEntity.java b/models-dao/src/test/java/org/onap/policy/models/dao/DummyConceptEntity.java
index fa2e71a08..c61a585ba 100644
--- a/models-dao/src/test/java/org/onap/policy/models/dao/DummyConceptEntity.java
+++ b/models-dao/src/test/java/org/onap/policy/models/dao/DummyConceptEntity.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2019 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.
@@ -62,6 +63,17 @@ public class DummyConceptEntity extends PfConcept {
this.key = new PfConceptKey();
}
+ /**
+ * Copy constructor.
+ *
+ * @param source object from which to copy
+ */
+ public DummyConceptEntity(DummyConceptEntity source) {
+ this.key = source.key;
+ this.uuid = source.uuid;
+ this.description = source.description;
+ }
+
public DummyConceptEntity(final Double doubleValue) {
this.key = new PfConceptKey();
}
@@ -101,21 +113,6 @@ public class DummyConceptEntity extends PfConcept {
}
@Override
- public PfConcept copyTo(final PfConcept target) {
- Assertions.argumentNotNull(target, "target may not be null");
-
- final PfConcept copyObject = target;
- Assertions.instanceOf(copyObject, DummyConceptEntity.class);
-
- final DummyConceptEntity copy = ((DummyConceptEntity) copyObject);
- copy.setKey(key);
- copy.setUuid(uuid);
- copy.setDescription(description);
-
- return copyObject;
- }
-
- @Override
public int compareTo(final PfConcept otherObj) {
Assertions.argumentNotNull(otherObj, "comparison object may not be null");
diff --git a/models-dao/src/test/java/org/onap/policy/models/dao/DummyReferenceEntity.java b/models-dao/src/test/java/org/onap/policy/models/dao/DummyReferenceEntity.java
index aad2aa5bc..41ead40cc 100644
--- a/models-dao/src/test/java/org/onap/policy/models/dao/DummyReferenceEntity.java
+++ b/models-dao/src/test/java/org/onap/policy/models/dao/DummyReferenceEntity.java
@@ -61,6 +61,11 @@ public class DummyReferenceEntity extends PfConcept {
this.doubleValue = 123.45;
}
+ public DummyReferenceEntity(DummyReferenceEntity source) {
+ this.key = source.key;
+ this.doubleValue = source.doubleValue;
+ }
+
/**
* Constructor.
*
@@ -89,20 +94,6 @@ public class DummyReferenceEntity extends PfConcept {
key.clean();
}
- @Override
- public PfConcept copyTo(final PfConcept target) {
- Assertions.argumentNotNull(target, "target may not be null");
-
- final PfConcept copyObject = target;
- Assertions.instanceOf(copyObject, DummyReferenceEntity.class);
-
- final DummyReferenceEntity copy = ((DummyReferenceEntity) copyObject);
- copy.setKey(key);
- copy.setDoubleValue(doubleValue);
-
- return copyObject;
- }
-
@Override
public int compareTo(final PfConcept otherObj) {