diff options
author | Jorge Hernandez <jorge.hernandez-herrero@att.com> | 2020-01-28 16:35:34 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2020-01-28 16:35:34 +0000 |
commit | 172a67f92943d64d5a1eda2b1dabf6c1c1c77f7e (patch) | |
tree | 456434d2005bae20a5031726990f5eee9f2032d3 /models-base | |
parent | 820b0e8e62e3821875ed32c4ab0f0b3183050c8f (diff) | |
parent | 252dc4ea8da89739ed18d6509ea72d2321676034 (diff) |
Merge "Add service template persistence provider"
Diffstat (limited to 'models-base')
-rw-r--r-- | models-base/src/main/java/org/onap/policy/models/base/PfConceptContainer.java | 51 |
1 files changed, 33 insertions, 18 deletions
diff --git a/models-base/src/main/java/org/onap/policy/models/base/PfConceptContainer.java b/models-base/src/main/java/org/onap/policy/models/base/PfConceptContainer.java index b4c19cd16..2ecf8c1c6 100644 --- a/models-base/src/main/java/org/onap/policy/models/base/PfConceptContainer.java +++ b/models-base/src/main/java/org/onap/policy/models/base/PfConceptContainer.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019 Nordix Foundation. + * Copyright (C) 2019-2020 Nordix Foundation. * Modifications Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -30,16 +30,21 @@ import java.util.Map.Entry; import java.util.NavigableMap; import java.util.Set; import java.util.TreeMap; + import javax.persistence.CascadeType; import javax.persistence.EmbeddedId; import javax.persistence.Entity; -import javax.persistence.FetchType; +import javax.persistence.JoinColumn; +import javax.persistence.JoinTable; import javax.persistence.ManyToMany; +import javax.persistence.MappedSuperclass; import javax.persistence.Table; import javax.ws.rs.core.Response; + import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NonNull; + import org.onap.policy.models.base.PfValidationResult.ValidationResult; // @formatter:off @@ -55,6 +60,7 @@ import org.onap.policy.models.base.PfValidationResult.ValidationResult; * @param C the concept being contained */ //@formatter:on +@MappedSuperclass @Entity @Table(name = "PfConceptContainer") @Data @@ -67,7 +73,19 @@ public class PfConceptContainer<C extends PfConcept, A extends PfNameVersion> ex @EmbeddedId private PfConceptKey key; - @ManyToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL) + @ManyToMany(cascade = CascadeType.ALL) + // @formatter:off + @JoinTable( + joinColumns = { + @JoinColumn(name = "conceptContainerMapName", referencedColumnName = "name"), + @JoinColumn(name = "concpetContainerMapVersion", referencedColumnName = "version") + }, + inverseJoinColumns = { + @JoinColumn(name = "conceptContainerName", referencedColumnName = "name"), + @JoinColumn(name = "conceptContainerVersion", referencedColumnName = "version") + } + ) + // @formatter:on private Map<PfConceptKey, C> conceptMap; /** @@ -181,8 +199,7 @@ public class PfConceptContainer<C extends PfConcept, A extends PfNameVersion> ex if (incomingConceptEntry.getValue().getVersion() != null) { conceptKey.setVersion(incomingConceptEntry.getValue().getVersion()); - } - else { + } else { conceptKey.setVersion(PfKey.NULL_KEY_VERSION); } @@ -240,19 +257,17 @@ public class PfConceptContainer<C extends PfConcept, A extends PfNameVersion> ex if (conceptEntry.getKey().equals(PfConceptKey.getNullKey())) { result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID, "key on concept entry " + conceptEntry.getKey() + " may not be the null key")); - } else - if (conceptEntry.getValue() == null) { - result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID, - "value on concept entry " + conceptEntry.getKey() + " may not be null")); - } else - if (!conceptEntry.getKey().equals(conceptEntry.getValue().getKey())) { - result.addValidationMessage(new PfValidationMessage(key, this.getClass(), - ValidationResult.INVALID, "key on concept entry key " + conceptEntry.getKey() - + " does not equal concept value key " + conceptEntry.getValue().getKey())); - result = conceptEntry.getValue().validate(result); - } else { - result = conceptEntry.getValue().validate(result); - } + } else if (conceptEntry.getValue() == null) { + result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID, + "value on concept entry " + conceptEntry.getKey() + " may not be null")); + } else if (!conceptEntry.getKey().equals(conceptEntry.getValue().getKey())) { + result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID, + "key on concept entry key " + conceptEntry.getKey() + " does not equal concept value key " + + conceptEntry.getValue().getKey())); + result = conceptEntry.getValue().validate(result); + } else { + result = conceptEntry.getValue().validate(result); + } } return result; } |