X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=models-dao%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fpolicy%2Fmodels%2Fdao%2Fimpl%2FProxyDao.java;h=ec0c357e655a426887edd9191bb9685d12176f0d;hb=389c85c8e7213c10c17896f4c63d94e2b5e9d27a;hp=72d56834d072c21a3007ccc5047f38af20f9de71;hpb=083868f1eab56b45baff7278ffb9acfd4126e02a;p=policy%2Fmodels.git diff --git a/models-dao/src/main/java/org/onap/policy/models/dao/impl/ProxyDao.java b/models-dao/src/main/java/org/onap/policy/models/dao/impl/ProxyDao.java index 72d56834d..ec0c357e6 100644 --- a/models-dao/src/main/java/org/onap/policy/models/dao/impl/ProxyDao.java +++ b/models-dao/src/main/java/org/onap/policy/models/dao/impl/ProxyDao.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2021 Nordix Foundation. + * Copyright (C) 2021, 2023-2024 Nordix Foundation. + * Modifications Copyright (C) 2022 Bell Canada. 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. @@ -20,19 +21,16 @@ package org.onap.policy.models.dao.impl; -import java.sql.Timestamp; -import java.time.Instant; +import jakarta.persistence.EntityManager; +import jakarta.persistence.Persistence; +import jakarta.persistence.TypedQuery; import java.util.Collection; import java.util.Collections; import java.util.List; -import javax.persistence.EntityManager; -import javax.persistence.Persistence; -import javax.persistence.TypedQuery; import lombok.RequiredArgsConstructor; import org.apache.commons.lang3.StringUtils; import org.onap.policy.models.base.PfConcept; import org.onap.policy.models.base.PfConceptKey; -import org.onap.policy.models.base.PfGeneratedIdKey; import org.onap.policy.models.base.PfModelException; import org.onap.policy.models.base.PfReferenceKey; import org.onap.policy.models.base.PfReferenceTimestampKey; @@ -48,70 +46,12 @@ import org.slf4j.LoggerFactory; /** * The Class ProxyDao is an JPA implementation of the {@link ProxyDao} class for Policy Framework concepts - * ({@link PfConcept}). It uses the default JPA implementation in the javax {@link Persistence} class. + * ({@link PfConcept}). It uses the default JPA implementation in the jakarta {@link Persistence} class. */ @RequiredArgsConstructor public class ProxyDao implements PfDao { private static final Logger LOGGER = LoggerFactory.getLogger(ProxyDao.class); - // @formatter:off - private static final String NAME = "name"; - private static final String VERSION = "version"; - private static final String TIMESTAMP = "timeStamp"; - private static final String GENERATEDID = "Id"; - private static final String PARENT_NAME = "parentname"; - private static final String PARENT_VERSION = "parentversion"; - private static final String LOCAL_NAME = "localname"; - - private static final String TABLE_TOKEN = "__TABLE__"; - - private static final String DELETE_FROM_TABLE = "DELETE FROM __TABLE__ c"; - - private static final String SELECT_FROM_TABLE = "SELECT c FROM __TABLE__ c"; - - private static final String WHERE = " WHERE "; - private static final String AND = " AND "; - private static final String ORDER_BY = " ORDER BY c."; - - private static final String NAME_FILTER = "c.key.name = :name"; - private static final String VERSION_FILTER = "c.key.version = :version"; - private static final String TIMESTAMP_FILTER = "c.key.timeStamp = :timeStamp"; - private static final String TIMESTAMP_FILTER_NOKEY = "c.timeStamp = :timeStamp"; - private static final String GENERATED_ID_FILTER = "c.key.generatedId = :Id"; - private static final String PARENT_NAME_FILTER = "c.key.parentKeyName = :parentname"; - private static final String PARENT_VERSION_FILTER = "c.key.parentKeyVersion = :parentversion"; - private static final String LOCAL_NAME_FILTER = "c.key.localName = :localname"; - - private static final String CLONE_ERR_MSG = "Could not clone object of class \"{}\""; - - private static final String DELETE_BY_CONCEPT_KEY = - DELETE_FROM_TABLE + WHERE + NAME_FILTER + AND + VERSION_FILTER; - - private static final String DELETE_BY_TIMESTAMP_KEY = - DELETE_FROM_TABLE + WHERE + NAME_FILTER + AND + VERSION_FILTER + AND + TIMESTAMP_FILTER; - - private static final String DELETE_BY_GENERATED_ID_KEY = - DELETE_FROM_TABLE + WHERE + NAME_FILTER + AND + VERSION_FILTER + AND + GENERATED_ID_FILTER; - - private static final String DELETE_BY_REFERENCE_KEY = - DELETE_FROM_TABLE + WHERE + PARENT_NAME_FILTER + AND + PARENT_VERSION_FILTER + AND + LOCAL_NAME_FILTER; - - private static final String SELECT_ALL_FOR_PARENT = - SELECT_FROM_TABLE + WHERE + PARENT_NAME_FILTER + AND + PARENT_VERSION_FILTER; - - private static final String SELECT_ALL_VERSIONS_FOR_PARENT = - SELECT_FROM_TABLE + WHERE + PARENT_NAME_FILTER; - - private static final String SELECT_ALL_VERSIONS = SELECT_FROM_TABLE + WHERE + NAME_FILTER; - - private static final String SELECT_BY_CONCEPT_KEY = - SELECT_FROM_TABLE + WHERE + NAME_FILTER + AND + VERSION_FILTER; - - private static final String SELECT_BY_TIMESTAMP_NOKEY = - SELECT_FROM_TABLE + WHERE + NAME_FILTER + AND + VERSION_FILTER + AND + TIMESTAMP_FILTER_NOKEY; - - private static final String SELECT_BY_REFERENCE_KEY = - SELECT_FROM_TABLE + WHERE + PARENT_NAME_FILTER + AND + PARENT_VERSION_FILTER + AND + LOCAL_NAME_FILTER; // @formatter:on // Entity manager for JPA @@ -186,21 +126,6 @@ public class ProxyDao implements PfDao { // @formatter:on } - @Override - public void delete(final Class someClass, final PfGeneratedIdKey key) { - if (key == null) { - return; - } - - // @formatter:off - mg.createQuery(setQueryTable(DELETE_BY_GENERATED_ID_KEY, someClass), someClass) - .setParameter(NAME, key.getName()) - .setParameter(VERSION, key.getVersion()) - .setParameter(GENERATEDID, key.getGeneratedId()) - .executeUpdate(); - // @formatter:on - } - @Override public void createCollection(final Collection objs) { if (objs == null || objs.isEmpty()) { @@ -307,11 +232,6 @@ public class ProxyDao implements PfDao { return genericGet(someClass, key); } - @Override - public T get(final Class someClass, final PfGeneratedIdKey key) { - return genericGet(someClass, key); - } - @Override public T get(final Class someClass, final PfTimestampKey key) { return genericGet(someClass, key); @@ -396,22 +316,6 @@ public class ProxyDao implements PfDao { // @formatter:on } - @Override - public List getByTimestamp(final Class someClass, final PfGeneratedIdKey key, - final Instant timeStamp) { - if (someClass == null || key == null || timeStamp == null) { - return Collections.emptyList(); - } - - // @formatter:off - return mg.createQuery(setQueryTable(SELECT_BY_TIMESTAMP_NOKEY, someClass), someClass) - .setParameter(NAME, key.getName()) - .setParameter(VERSION, key.getVersion()) - .setParameter(TIMESTAMP, Timestamp.from(timeStamp)) - .getResultList(); - // @formatter:on - } - @Override public T getConcept(final Class someClass, final PfConceptKey key) { if (someClass == null || key == null) {