Fix config files to remove outdated configuration for hibernate
[policy/models.git] / models-dao / src / main / java / org / onap / policy / models / dao / impl / ProxyDao.java
index 72d5683..ec0c357 100644 (file)
@@ -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.
 
 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 <T extends PfConcept> void delete(final Class<T> 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 <T extends PfConcept> void createCollection(final Collection<T> objs) {
         if (objs == null || objs.isEmpty()) {
@@ -307,11 +232,6 @@ public class ProxyDao implements PfDao {
         return genericGet(someClass, key);
     }
 
-    @Override
-    public <T extends PfConcept> T get(final Class<T> someClass, final PfGeneratedIdKey key) {
-        return genericGet(someClass, key);
-    }
-
     @Override
     public <T extends PfConcept> T get(final Class<T> someClass, final PfTimestampKey key) {
         return genericGet(someClass, key);
@@ -396,22 +316,6 @@ public class ProxyDao implements PfDao {
         // @formatter:on
     }
 
-    @Override
-    public <T extends PfConcept> List<T> getByTimestamp(final Class<T> 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 extends PfConcept> T getConcept(final Class<T> someClass, final PfConceptKey key) {
         if (someClass == null || key == null) {