aboutsummaryrefslogtreecommitdiffstats
path: root/models-provider/src
diff options
context:
space:
mode:
authorliamfallon <liam.fallon@est.tech>2023-02-02 14:43:12 +0000
committerliamfallon <liam.fallon@est.tech>2023-02-07 09:17:33 +0000
commite53df8d3f8ab0464b0876bdb339fa91dc9085cd2 (patch)
treee01029186ff980f7e00901c28aba09b80a85f8e8 /models-provider/src
parente3938e43b8a1f02f74368ecb75c38530285feac0 (diff)
Replace Eclipselink with Hibernate
Issue-ID: POLICY-4533 Change-Id: I77a6c44c96013963e141265758629cae83e49876 Signed-off-by: liamfallon <liam.fallon@est.tech>
Diffstat (limited to 'models-provider/src')
-rw-r--r--models-provider/src/main/java/org/onap/policy/models/provider/impl/ModelsProvider.java18
-rw-r--r--models-provider/src/test/java/org/onap/policy/models/provider/impl/DatabasePolicyModelsProviderTest.java14
-rw-r--r--models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyToscaPersistenceTest.java4
-rw-r--r--models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyTypePersistenceTest.java6
-rw-r--r--models-provider/src/test/java/org/onap/policy/models/provider/revisionhierarchy/HierarchyFetchTest.java38
-rw-r--r--models-provider/src/test/resources/META-INF/persistence.xml22
6 files changed, 48 insertions, 54 deletions
diff --git a/models-provider/src/main/java/org/onap/policy/models/provider/impl/ModelsProvider.java b/models-provider/src/main/java/org/onap/policy/models/provider/impl/ModelsProvider.java
index 36c762e01..d90847f56 100644
--- a/models-provider/src/main/java/org/onap/policy/models/provider/impl/ModelsProvider.java
+++ b/models-provider/src/main/java/org/onap/policy/models/provider/impl/ModelsProvider.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2021 Nordix Foundation.
+ * Copyright (C) 2021,2023 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -24,7 +24,6 @@ import java.util.Properties;
import javax.ws.rs.core.Response;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
-import org.eclipse.persistence.config.PersistenceUnitProperties;
import org.onap.policy.models.base.PfModelException;
import org.onap.policy.models.dao.DaoParameters;
import org.onap.policy.models.dao.PfDao;
@@ -48,13 +47,14 @@ public final class ModelsProvider {
// @formatter:off
var jdbcProperties = new Properties();
- jdbcProperties.setProperty(PersistenceUnitProperties.JDBC_DRIVER, parameters.getDatabaseDriver());
- jdbcProperties.setProperty(PersistenceUnitProperties.JDBC_URL, parameters.getDatabaseUrl());
- jdbcProperties.setProperty(PersistenceUnitProperties.JDBC_USER, parameters.getDatabaseUser());
- jdbcProperties.setProperty(PersistenceUnitProperties.JDBC_PASSWORD, parameters.getDatabasePassword());
- jdbcProperties.setProperty(PersistenceUnitProperties.TARGET_DATABASE,
- (parameters.getDatabaseType() == null ? "MySQL" : parameters.getDatabaseType()));
- // @formatter:on
+ jdbcProperties.setProperty("javax.persistence.jdbc.driver", parameters.getDatabaseDriver());
+ jdbcProperties.setProperty("javax.persistence.jdbc.url", parameters.getDatabaseUrl());
+ jdbcProperties.setProperty("javax.persistence.jdbc.user", parameters.getDatabaseUser());
+ jdbcProperties.setProperty("javax.persistence.jdbc.password", parameters.getDatabasePassword());
+ jdbcProperties.setProperty("hibernate.dialect",
+ (parameters.getDatabaseType() == null
+ ? "org.hibernate.dialect.MariaDBDialect"
+ : parameters.getDatabaseType())); // @formatter:on
daoParameters.setJdbcProperties(jdbcProperties);
diff --git a/models-provider/src/test/java/org/onap/policy/models/provider/impl/DatabasePolicyModelsProviderTest.java b/models-provider/src/test/java/org/onap/policy/models/provider/impl/DatabasePolicyModelsProviderTest.java
index ff3dae81a..6cf56cb96 100644
--- a/models-provider/src/test/java/org/onap/policy/models/provider/impl/DatabasePolicyModelsProviderTest.java
+++ b/models-provider/src/test/java/org/onap/policy/models/provider/impl/DatabasePolicyModelsProviderTest.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019-2022 Nordix Foundation.
+ * Copyright (C) 2019-2023 Nordix Foundation.
* Modifications Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2020, 2022 Bell Canada. All rights reserved.
* ================================================================================
@@ -90,6 +90,7 @@ public class DatabasePolicyModelsProviderTest {
parameters.setDatabaseUser("policy");
parameters.setDatabasePassword("P01icY");
parameters.setPersistenceUnit("ToscaConceptTest");
+ parameters.setDatabaseType("org.hibernate.dialect.H2Dialect");
}
/**
@@ -110,20 +111,23 @@ public class DatabasePolicyModelsProviderTest {
databaseProvider = new PolicyModelsProviderFactory().createPolicyModelsProvider(parameters);
+ final String savedDatabaseUrl = parameters.getDatabaseUrl();
parameters.setDatabaseUrl("jdbc://www.acmecorp.nonexist");
databaseProvider.close();
- databaseProvider.init();
+ assertThatThrownBy(() -> {
+ databaseProvider.init();
+ }).hasMessageContaining("could not create Data Access Object (DAO)");
databaseProvider.close();
- parameters.setDatabaseUrl("jdbc:h2:mem:DatabasePolicyModelsProviderTest");
+ parameters.setDatabaseUrl(savedDatabaseUrl);
+ final String savedPersistenceUnit = parameters.getPersistenceUnit();
parameters.setPersistenceUnit("WileECoyote");
assertThatThrownBy(databaseProvider::init).hasMessageContaining("could not create Data Access Object (DAO)");
-
- parameters.setPersistenceUnit("ToscaConceptTest");
+ parameters.setPersistenceUnit(savedPersistenceUnit);
databaseProvider.init();
databaseProvider.close();
diff --git a/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyToscaPersistenceTest.java b/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyToscaPersistenceTest.java
index c39eeb392..1f9931678 100644
--- a/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyToscaPersistenceTest.java
+++ b/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyToscaPersistenceTest.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019-2021 Nordix Foundation.
+ * Copyright (C) 2019-2021,2023 Nordix Foundation.
* Modifications Copyright (C) 2020 Bell Canada. All rights reserved.
* Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
@@ -81,9 +81,11 @@ public class PolicyToscaPersistenceTest {
if (System.getProperty("USE-MARIADB") != null) {
parameters.setDatabaseDriver("org.mariadb.jdbc.Driver");
parameters.setDatabaseUrl("jdbc:mariadb://localhost:3306/policy");
+ parameters.setDatabaseType("org.hibernate.dialect.MariaDBDialect");
} else {
parameters.setDatabaseDriver("org.h2.Driver");
parameters.setDatabaseUrl("jdbc:h2:mem:PolicyToscaPersistenceTest");
+ parameters.setDatabaseType("org.hibernate.dialect.H2Dialect");
}
parameters.setDatabaseUser("policy");
diff --git a/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyTypePersistenceTest.java b/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyTypePersistenceTest.java
index 786563a78..978a30346 100644
--- a/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyTypePersistenceTest.java
+++ b/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyTypePersistenceTest.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019-2021 Nordix Foundation.
+ * Copyright (C) 2019-2021,2023 Nordix Foundation.
* Modifications Copyright (C) 2020 Bell Canada. All rights reserved.
* Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
@@ -66,9 +66,11 @@ public class PolicyTypePersistenceTest {
if (System.getProperty("USE-MARIADB") != null) {
parameters.setDatabaseDriver("org.mariadb.jdbc.Driver");
parameters.setDatabaseUrl("jdbc:mariadb://localhost:3306/policy");
+ parameters.setDatabaseType("org.hibernate.dialect.MariaDBDialect");
} else {
parameters.setDatabaseDriver("org.h2.Driver");
- parameters.setDatabaseUrl("jdbc:h2:mem:PolicyTypePersistenceTest");
+ parameters.setDatabaseUrl("jdbc:h2:mem:PolicyToscaPersistenceTest");
+ parameters.setDatabaseType("org.hibernate.dialect.H2Dialect");
}
parameters.setDatabaseUser("policy");
diff --git a/models-provider/src/test/java/org/onap/policy/models/provider/revisionhierarchy/HierarchyFetchTest.java b/models-provider/src/test/java/org/onap/policy/models/provider/revisionhierarchy/HierarchyFetchTest.java
index c55325e57..2d2723f0f 100644
--- a/models-provider/src/test/java/org/onap/policy/models/provider/revisionhierarchy/HierarchyFetchTest.java
+++ b/models-provider/src/test/java/org/onap/policy/models/provider/revisionhierarchy/HierarchyFetchTest.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2020-2021 Nordix Foundation.
+ * Copyright (C) 2020-2021,2023 Nordix Foundation.
* Modifications Copyright (C) 2020 Bell Canada. All rights reserved.
* Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
@@ -55,6 +55,7 @@ public class HierarchyFetchTest {
parameters.setDatabaseUser("policy");
parameters.setDatabasePassword("P01icY");
parameters.setPersistenceUnit("ToscaConceptTest");
+ parameters.setDatabaseType("org.hibernate.dialect.H2Dialect");
}
/**
@@ -95,29 +96,28 @@ public class HierarchyFetchTest {
assertEquals(1, fetchedServiceTemplate.getPolicyTypes().size());
ToscaPolicyType fetchedPolicyType = fetchedServiceTemplate.getPolicyTypes().values().iterator().next();
checkEqualsPolicyType(fetchedPolicyType, "onap.policies.PolicyTypeLevel0",
- "3.0.0", fetchedServiceTemplate, 3);
-
+ "3.0.0", fetchedServiceTemplate, 3);
fetchedServiceTemplate = databaseProvider.getPolicies("onap.policies.PolicyLevel0", "1.0.0");
assertOldDataTypesAreReturned(fetchedServiceTemplate);
assertEquals(1, fetchedServiceTemplate.getPolicyTypes().size());
fetchedPolicyType = fetchedServiceTemplate.getPolicyTypes().values().iterator().next();
checkEqualsPolicyType(fetchedPolicyType, "onap.policies.PolicyTypeLevel0",
- "1.0.0", fetchedServiceTemplate, 1);
+ "1.0.0", fetchedServiceTemplate, 1);
fetchedServiceTemplate = databaseProvider.getPolicies("onap.policies.PolicyLevel0", "1.1.0");
assertOldDataTypesAreReturned(fetchedServiceTemplate);
assertEquals(1, fetchedServiceTemplate.getPolicyTypes().size());
fetchedPolicyType = fetchedServiceTemplate.getPolicyTypes().values().iterator().next();
checkEqualsPolicyType(fetchedPolicyType, "onap.policies.PolicyTypeLevel0",
- "2.0.0", fetchedServiceTemplate, 1);
+ "2.0.0", fetchedServiceTemplate, 1);
fetchedServiceTemplate = databaseProvider.getPolicies("onap.policies.PolicyLevel0", "1.2.0");
assertLatestDataTypesAreReturned(fetchedServiceTemplate);
assertEquals(1, fetchedServiceTemplate.getPolicyTypes().size());
fetchedPolicyType = fetchedServiceTemplate.getPolicyTypes().values().iterator().next();
checkEqualsPolicyType(fetchedPolicyType, "onap.policies.PolicyTypeLevel0",
- "3.0.0", fetchedServiceTemplate, 1);
+ "3.0.0", fetchedServiceTemplate, 1);
fetchedServiceTemplate = databaseProvider.getPolicies("onap.policies.PolicyLevel0.1", null);
assertLatestDataTypesAreReturned(fetchedServiceTemplate);
@@ -128,7 +128,7 @@ public class HierarchyFetchTest {
checkNameVersion(fetchedPolicyType, "onap.policies.PolicyTypeLevel0", "3.0.0");
fetchedPolicyType = fetchedPolicyTypeIterator.next();
checkEqualsPolicyType(fetchedPolicyType, "onap.policies.PolicyTypeLevel0.1",
- "3.0.0", fetchedServiceTemplate, 3);
+ "3.0.0", fetchedServiceTemplate, 3);
fetchedServiceTemplate = databaseProvider.getPolicies("onap.policies.PolicyLevel0.1", "1.0.0");
assertLatestDataTypesAreReturned(fetchedServiceTemplate);
@@ -138,7 +138,7 @@ public class HierarchyFetchTest {
checkNameVersion(fetchedPolicyType, "onap.policies.PolicyTypeLevel0", "3.0.0");
fetchedPolicyType = fetchedPolicyTypeIterator.next();
checkEqualsPolicyType(fetchedPolicyType, "onap.policies.PolicyTypeLevel0.1",
- "1.0.0", fetchedServiceTemplate, 1);
+ "1.0.0", fetchedServiceTemplate, 1);
fetchedServiceTemplate = databaseProvider.getPolicies("onap.policies.PolicyLevel0.1", "1.1.0");
assertLatestDataTypesAreReturned(fetchedServiceTemplate);
@@ -148,7 +148,7 @@ public class HierarchyFetchTest {
checkNameVersion(fetchedPolicyType, "onap.policies.PolicyTypeLevel0", "3.0.0");
fetchedPolicyType = fetchedPolicyTypeIterator.next();
checkEqualsPolicyType(fetchedPolicyType, "onap.policies.PolicyTypeLevel0.1",
- "2.0.0", fetchedServiceTemplate, 1);
+ "2.0.0", fetchedServiceTemplate, 1);
fetchedServiceTemplate = databaseProvider.getPolicies("onap.policies.PolicyLevel0.1", "1.2.0");
assertLatestDataTypesAreReturned(fetchedServiceTemplate);
@@ -158,7 +158,7 @@ public class HierarchyFetchTest {
checkNameVersion(fetchedPolicyType, "onap.policies.PolicyTypeLevel0", "3.0.0");
fetchedPolicyType = fetchedPolicyTypeIterator.next();
checkEqualsPolicyType(fetchedPolicyType, "onap.policies.PolicyTypeLevel0.1",
- "3.0.0", fetchedServiceTemplate, 1);
+ "3.0.0", fetchedServiceTemplate, 1);
fetchedServiceTemplate = databaseProvider.getPolicies("onap.policies.PolicyLevel0.1.2", null);
assertLatestDataTypesAreReturned(fetchedServiceTemplate);
@@ -170,7 +170,7 @@ public class HierarchyFetchTest {
checkNameVersion(fetchedPolicyType, "onap.policies.PolicyTypeLevel0.1", "3.0.0");
fetchedPolicyType = fetchedPolicyTypeIterator.next();
checkEqualsPolicyType(fetchedPolicyType, "onap.policies.PolicyTypeLevel0.1.2",
- "3.0.0", fetchedServiceTemplate, 3);
+ "3.0.0", fetchedServiceTemplate, 3);
fetchedServiceTemplate = databaseProvider.getPolicies("onap.policies.PolicyLevel0.1.2", "1.0.0");
assertLatestDataTypesAreReturned(fetchedServiceTemplate);
@@ -182,7 +182,7 @@ public class HierarchyFetchTest {
checkNameVersion(fetchedPolicyType, "onap.policies.PolicyTypeLevel0.1", "3.0.0");
fetchedPolicyType = fetchedPolicyTypeIterator.next();
checkEqualsPolicyType(fetchedPolicyType, "onap.policies.PolicyTypeLevel0.1.2",
- "1.0.0", fetchedServiceTemplate, 1);
+ "1.0.0", fetchedServiceTemplate, 1);
fetchedServiceTemplate = databaseProvider.getPolicies("onap.policies.PolicyLevel0.1.2", "1.1.0");
assertLatestDataTypesAreReturned(fetchedServiceTemplate);
@@ -194,7 +194,7 @@ public class HierarchyFetchTest {
checkNameVersion(fetchedPolicyType, "onap.policies.PolicyTypeLevel0.1", "3.0.0");
fetchedPolicyType = fetchedPolicyTypeIterator.next();
checkEqualsPolicyType(fetchedPolicyType, "onap.policies.PolicyTypeLevel0.1.2",
- "2.0.0", fetchedServiceTemplate, 1);
+ "2.0.0", fetchedServiceTemplate, 1);
fetchedServiceTemplate = databaseProvider.getPolicies("onap.policies.PolicyLevel0.1.2", "1.2.0");
assertLatestDataTypesAreReturned(fetchedServiceTemplate);
@@ -206,7 +206,7 @@ public class HierarchyFetchTest {
checkNameVersion(fetchedPolicyType, "onap.policies.PolicyTypeLevel0.1", "3.0.0");
fetchedPolicyType = fetchedPolicyTypeIterator.next();
checkEqualsPolicyType(fetchedPolicyType, "onap.policies.PolicyTypeLevel0.1.2",
- "3.0.0", fetchedServiceTemplate, 1);
+ "3.0.0", fetchedServiceTemplate, 1);
fetchedServiceTemplate = databaseProvider.getPolicies("onap.policies.PolicyLevel0.1.2.3", null);
assertLatestDataTypesAreReturned(fetchedServiceTemplate);
@@ -220,7 +220,7 @@ public class HierarchyFetchTest {
checkNameVersion(fetchedPolicyType, "onap.policies.PolicyTypeLevel0.1.2", "3.0.0");
fetchedPolicyType = fetchedPolicyTypeIterator.next();
checkEqualsPolicyType(fetchedPolicyType, "onap.policies.PolicyTypeLevel0.1.2.3",
- "3.0.0", fetchedServiceTemplate, 3);
+ "3.0.0", fetchedServiceTemplate, 3);
fetchedServiceTemplate = databaseProvider.getPolicies("onap.policies.PolicyLevel0.1.2.3", "1.0.0");
assertLatestDataTypesAreReturned(fetchedServiceTemplate);
@@ -234,7 +234,7 @@ public class HierarchyFetchTest {
checkNameVersion(fetchedPolicyType, "onap.policies.PolicyTypeLevel0.1.2", "3.0.0");
fetchedPolicyType = fetchedPolicyTypeIterator.next();
checkEqualsPolicyType(fetchedPolicyType, "onap.policies.PolicyTypeLevel0.1.2.3",
- "1.0.0", fetchedServiceTemplate, 1);
+ "1.0.0", fetchedServiceTemplate, 1);
fetchedServiceTemplate = databaseProvider.getPolicies("onap.policies.PolicyLevel0.1.2.3", "1.1.0");
assertLatestDataTypesAreReturned(fetchedServiceTemplate);
@@ -248,7 +248,7 @@ public class HierarchyFetchTest {
checkNameVersion(fetchedPolicyType, "onap.policies.PolicyTypeLevel0.1.2", "3.0.0");
fetchedPolicyType = fetchedPolicyTypeIterator.next();
checkEqualsPolicyType(fetchedPolicyType, "onap.policies.PolicyTypeLevel0.1.2.3",
- "2.0.0", fetchedServiceTemplate, 1);
+ "2.0.0", fetchedServiceTemplate, 1);
fetchedServiceTemplate = databaseProvider.getPolicies("onap.policies.PolicyLevel0.1.2.3", "1.2.0");
assertLatestDataTypesAreReturned(fetchedServiceTemplate);
@@ -262,7 +262,7 @@ public class HierarchyFetchTest {
checkNameVersion(fetchedPolicyType, "onap.policies.PolicyTypeLevel0.1.2", "3.0.0");
fetchedPolicyType = fetchedPolicyTypeIterator.next();
checkEqualsPolicyType(fetchedPolicyType, "onap.policies.PolicyTypeLevel0.1.2.3",
- "3.0.0", fetchedServiceTemplate, 1);
+ "3.0.0", fetchedServiceTemplate, 1);
databaseProvider.close();
}
@@ -273,7 +273,7 @@ public class HierarchyFetchTest {
}
private void checkEqualsPolicyType(ToscaPolicyType fetchedPolicyType, String name, String ver,
- ToscaServiceTemplate fetchedServiceTemplate, int policies) {
+ ToscaServiceTemplate fetchedServiceTemplate, int policies) {
checkNameVersion(fetchedPolicyType, name, ver);
assertEquals(policies, countReturnedPolicies(fetchedServiceTemplate));
}
diff --git a/models-provider/src/test/resources/META-INF/persistence.xml b/models-provider/src/test/resources/META-INF/persistence.xml
index 3b4d95656..8247f0850 100644
--- a/models-provider/src/test/resources/META-INF/persistence.xml
+++ b/models-provider/src/test/resources/META-INF/persistence.xml
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
============LICENSE_START=======================================================
- Copyright (C) 2019-2021 Nordix Foundation.
+ Copyright (C) 2019-2021,2023 Nordix Foundation.
Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
================================================================================
Licensed under the Apache License, Version 2.0 (the "License");
@@ -22,8 +22,6 @@
<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="2.0">
<persistence-unit name="ToscaConceptTest" transaction-type="RESOURCE_LOCAL">
- <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
-
<class>org.onap.policy.models.base.PfConceptKey</class>
<class>org.onap.policy.models.dao.converters.CDataConditioner</class>
<class>org.onap.policy.models.dao.converters.Uuid2String</class>
@@ -58,21 +56,9 @@
<class>org.onap.policy.models.tosca.simple.concepts.JpaToscaTrigger</class>
<properties>
- <property name="eclipselink.target-database" value="MySQL" />
- <property name="eclipselink.ddl-generation" value="drop-and-create-tables" />
- <property name="eclipselink.ddl-generation.output-mode" value="database" />
- <property name="eclipselink.logging.level" value="INFO" />
-
- <!-- property name="eclipselink.logging.level" value="ALL" />
- <property name="eclipselink.logging.level.jpa" value="ALL" />
- <property name="eclipselink.logging.level.ddl" value="ALL" />
- <property name="eclipselink.logging.level.connection" value="ALL" />
- <property name="eclipselink.logging.level.sql" value="ALL" />
- <property name="eclipselink.logging.level.transaction" value="ALL" />
- <property name="eclipselink.logging.level.sequencing" value="ALL" />
- <property name="eclipselink.logging.level.server" value="ALL" />
- <property name="eclipselink.logging.level.query" value="ALL" />
- <property name="eclipselink.logging.level.properties" value="ALL" /-->
+ <property name="javax.persistence.schema-generation.database.action" value="drop-and-create" />
+ <property name="hibernate.enable_lazy_load_no_trans" value="true" />
+ <property name="hibernate.show_sql" value="false" />
</properties>
</persistence-unit>
</persistence>