diff options
Diffstat (limited to 'utils/src/main/java/org/onap/policy/common/utils/jpa')
3 files changed, 37 insertions, 70 deletions
diff --git a/utils/src/main/java/org/onap/policy/common/utils/jpa/EntityMgrCloser.java b/utils/src/main/java/org/onap/policy/common/utils/jpa/EntityMgrCloser.java index 3532002e..f1798516 100644 --- a/utils/src/main/java/org/onap/policy/common/utils/jpa/EntityMgrCloser.java +++ b/utils/src/main/java/org/onap/policy/common/utils/jpa/EntityMgrCloser.java @@ -2,14 +2,15 @@ * ============LICENSE_START======================================================= * Common Utils * ================================================================================ - * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2018, 2021 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 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. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -20,40 +21,26 @@ package org.onap.policy.common.utils.jpa; -import javax.persistence.EntityManager; +import jakarta.persistence.EntityManager; +import lombok.AllArgsConstructor; +import lombok.Getter; /** * Wrapper for an <i>EntityManager</i>, providing auto-close functionality. This is useful in * try-with-resources statements. */ +@AllArgsConstructor public class EntityMgrCloser implements AutoCloseable { /** * The wrapped manager. */ - private final EntityManager em; - - /** - * Construct an instance with the EntityManager. - * - * @param em manager to be auto-closed - */ - public EntityMgrCloser(EntityManager em) { - this.em = em; - } - - /** - * Gets the EntityManager wrapped within this object. - * - * @return the associated EntityManager - */ - public EntityManager getManager() { - return em; - } + @Getter + private final EntityManager manager; @Override public void close() { - em.close(); + manager.close(); } } diff --git a/utils/src/main/java/org/onap/policy/common/utils/jpa/EntityMgrFactoryCloser.java b/utils/src/main/java/org/onap/policy/common/utils/jpa/EntityMgrFactoryCloser.java index b046cc55..5f3a6ea8 100644 --- a/utils/src/main/java/org/onap/policy/common/utils/jpa/EntityMgrFactoryCloser.java +++ b/utils/src/main/java/org/onap/policy/common/utils/jpa/EntityMgrFactoryCloser.java @@ -2,14 +2,15 @@ * ============LICENSE_START======================================================= * Common Utils * ================================================================================ - * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2018, 2021 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 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. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -20,40 +21,26 @@ package org.onap.policy.common.utils.jpa; -import javax.persistence.EntityManagerFactory; +import jakarta.persistence.EntityManagerFactory; +import lombok.AllArgsConstructor; +import lombok.Getter; /** * Wrapper for an <i>EntityManagerFactory</i>, providing auto-close functionality. This is useful in * try-with-resources statements. */ +@AllArgsConstructor public class EntityMgrFactoryCloser implements AutoCloseable { /** * The wrapped factory. */ - private final EntityManagerFactory emf; - - /** - * Construct an instance with the given EntityManagerFactory. - * - * @param emf manager to be auto-closed - */ - public EntityMgrFactoryCloser(EntityManagerFactory emf) { - this.emf = emf; - } - - /** - * Gets the EntityManagerFactory wrapped within this object. - * - * @return the associated EntityManagerFactory - */ - public EntityManagerFactory getFactory() { - return emf; - } + @Getter + private final EntityManagerFactory factory; @Override public void close() { - emf.close(); + factory.close(); } } diff --git a/utils/src/main/java/org/onap/policy/common/utils/jpa/EntityTransCloser.java b/utils/src/main/java/org/onap/policy/common/utils/jpa/EntityTransCloser.java index 3552a6fa..131e87a4 100644 --- a/utils/src/main/java/org/onap/policy/common/utils/jpa/EntityTransCloser.java +++ b/utils/src/main/java/org/onap/policy/common/utils/jpa/EntityTransCloser.java @@ -2,14 +2,15 @@ * ============LICENSE_START======================================================= * Common Utils * ================================================================================ - * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2018, 2021 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 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. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -20,7 +21,8 @@ package org.onap.policy.common.utils.jpa; -import javax.persistence.EntityTransaction; +import jakarta.persistence.EntityTransaction; +import lombok.Getter; /** * Wrapper for an <i>EntityTransaction</i> that is auto-rolled back when closed. This is useful in @@ -31,46 +33,37 @@ public class EntityTransCloser implements AutoCloseable { /** * Transaction to be rolled back. */ - private final EntityTransaction trans; + @Getter + private final EntityTransaction transaction; /** * Begins a transaction. - * + * * @param et transaction to wrap/begin */ public EntityTransCloser(EntityTransaction et) { - trans = et; - trans.begin(); - } - - /** - * Gets the wrapped transaction. - * - * @return the transaction - */ - public EntityTransaction getTransation() { - return trans; + transaction = et; + transaction.begin(); } /** * Commits the transaction. */ public void commit() { - trans.commit(); + transaction.commit(); } /** * Rolls back the transaction. */ public void rollback() { - trans.rollback(); + transaction.rollback(); } @Override public void close() { - if (trans.isActive()) { - trans.rollback(); + if (transaction.isActive()) { + transaction.rollback(); } } - } |