summaryrefslogtreecommitdiffstats
path: root/feature-session-persistence
diff options
context:
space:
mode:
Diffstat (limited to 'feature-session-persistence')
-rw-r--r--feature-session-persistence/src/main/java/org/onap/policy/drools/persistence/DroolsPersistenceProperties.java9
-rw-r--r--feature-session-persistence/src/main/java/org/onap/policy/drools/persistence/DroolsSessionEntity.java72
-rw-r--r--feature-session-persistence/src/main/java/org/onap/policy/drools/persistence/EntityMgrTrans.java27
-rw-r--r--feature-session-persistence/src/main/java/org/onap/policy/drools/persistence/JpaDroolsSessionConnector.java8
-rw-r--r--feature-session-persistence/src/main/java/org/onap/policy/drools/persistence/PersistenceFeature.java6
-rw-r--r--feature-session-persistence/src/test/java/org/onap/policy/drools/persistence/DroolsSessionEntityTest.java17
-rw-r--r--feature-session-persistence/src/test/java/org/onap/policy/drools/persistence/PersistenceFeatureTest.java6
7 files changed, 32 insertions, 113 deletions
diff --git a/feature-session-persistence/src/main/java/org/onap/policy/drools/persistence/DroolsPersistenceProperties.java b/feature-session-persistence/src/main/java/org/onap/policy/drools/persistence/DroolsPersistenceProperties.java
index 93440dad..ab85864f 100644
--- a/feature-session-persistence/src/main/java/org/onap/policy/drools/persistence/DroolsPersistenceProperties.java
+++ b/feature-session-persistence/src/main/java/org/onap/policy/drools/persistence/DroolsPersistenceProperties.java
@@ -20,9 +20,12 @@
package org.onap.policy.drools.persistence;
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
import org.eclipse.persistence.config.PersistenceUnitProperties;
-public class DroolsPersistenceProperties {
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class DroolsPersistenceProperties {
/*
* feature-session-persistence.properties parameter key values
*/
@@ -32,8 +35,4 @@ public class DroolsPersistenceProperties {
public static final String DB_PWD = PersistenceUnitProperties.JDBC_PASSWORD;
public static final String DB_SESSIONINFO_TIMEOUT = "persistence.sessioninfo.timeout";
public static final String JTA_OBJECTSTORE_DIR = "persistence.objectstore.dir";
-
- private DroolsPersistenceProperties() {
- super();
- }
}
diff --git a/feature-session-persistence/src/main/java/org/onap/policy/drools/persistence/DroolsSessionEntity.java b/feature-session-persistence/src/main/java/org/onap/policy/drools/persistence/DroolsSessionEntity.java
index ec9e5b76..9ac68567 100644
--- a/feature-session-persistence/src/main/java/org/onap/policy/drools/persistence/DroolsSessionEntity.java
+++ b/feature-session-persistence/src/main/java/org/onap/policy/drools/persistence/DroolsSessionEntity.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* feature-session-persistence
* ================================================================================
- * Copyright (C) 2017-2018, 2020 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2018, 2020-2021 AT&T Intellectual Property. 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.
@@ -29,14 +29,23 @@ import javax.persistence.PrePersist;
import javax.persistence.PreUpdate;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
+import lombok.EqualsAndHashCode;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
@Entity
+@Getter
+@Setter
+@EqualsAndHashCode(onlyExplicitlyIncluded = true)
+@NoArgsConstructor
public class DroolsSessionEntity implements Serializable, DroolsSession {
private static final long serialVersionUID = -5495057038819948709L;
@Id
@Column(name = "sessionName", nullable = false)
+ @EqualsAndHashCode.Include
private String sessionName = "-1";
@Column(name = "sessionId", nullable = false)
@@ -50,9 +59,6 @@ public class DroolsSessionEntity implements Serializable, DroolsSession {
@Column(name = "updatedDate", nullable = false)
private Date updatedDate;
- public DroolsSessionEntity() {
- }
-
public DroolsSessionEntity(String sessionName, long sessionId) {
this.sessionName = sessionName;
this.sessionId = sessionId;
@@ -70,64 +76,6 @@ public class DroolsSessionEntity implements Serializable, DroolsSession {
}
@Override
- public String getSessionName() {
- return sessionName;
- }
-
- @Override
- public void setSessionName(String sessionName) {
- this.sessionName = sessionName;
- }
-
- @Override
- public long getSessionId() {
- return sessionId;
- }
-
- @Override
- public void setSessionId(long sessionId) {
- this.sessionId = sessionId;
- }
-
- @Override
- public Date getCreatedDate() {
- return createdDate;
- }
-
- @Override
- public void setCreatedDate(Date createdDate) {
- this.createdDate = createdDate;
- }
-
- @Override
- public Date getUpdatedDate() {
- return updatedDate;
- }
-
- @Override
- public void setUpdatedDate(Date updatedDate) {
- this.updatedDate = updatedDate;
- }
-
- @Override
- public boolean equals(Object other) {
- if (other instanceof DroolsSession) {
- DroolsSession session = (DroolsSession) other;
- return this.getSessionName().equals(session.getSessionName());
- } else {
- return false;
- }
- }
-
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + getSessionName().hashCode();
- return result;
- }
-
- @Override
public String toString() {
return "{name=" + getSessionName() + ", id=" + getSessionId() + "}";
}
diff --git a/feature-session-persistence/src/main/java/org/onap/policy/drools/persistence/EntityMgrTrans.java b/feature-session-persistence/src/main/java/org/onap/policy/drools/persistence/EntityMgrTrans.java
index 988cd9c2..7103c47c 100644
--- a/feature-session-persistence/src/main/java/org/onap/policy/drools/persistence/EntityMgrTrans.java
+++ b/feature-session-persistence/src/main/java/org/onap/policy/drools/persistence/EntityMgrTrans.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* feature-session-persistence
* ================================================================================
- * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2018, 2021 AT&T Intellectual Property. 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.
@@ -28,6 +28,9 @@ import javax.transaction.RollbackException;
import javax.transaction.Status;
import javax.transaction.SystemException;
import javax.transaction.UserTransaction;
+import lombok.AccessLevel;
+import lombok.Getter;
+import lombok.Setter;
import org.onap.policy.common.utils.jpa.EntityMgrCloser;
/**
@@ -40,6 +43,8 @@ public class EntityMgrTrans extends EntityMgrCloser {
/**
* Transaction to be rolled back.
*/
+ @Getter(AccessLevel.PROTECTED)
+ @Setter(AccessLevel.PROTECTED)
private static UserTransaction userTrans = com.arjuna.ats.jta.UserTransaction.userTransaction();
/**
@@ -71,24 +76,6 @@ public class EntityMgrTrans extends EntityMgrCloser {
}
/**
- * Gets the user transaction. For use by junit tests.
- *
- * @return the user transaction
- */
- protected static UserTransaction getUserTrans() {
- return userTrans;
- }
-
- /**
- * Sets the user transaction. For use by junit tests.
- *
- * @param userTrans the new user transaction
- */
- protected static void setUserTrans(UserTransaction userTrans) {
- EntityMgrTrans.userTrans = userTrans;
- }
-
- /**
* Commits the transaction.
*/
public void commit() {
@@ -146,7 +133,7 @@ public class EntityMgrTrans extends EntityMgrCloser {
/**
* Constructor.
- *
+ *
* @param ex exception to be wrapped
*/
public EntityMgrException(Exception ex) {
diff --git a/feature-session-persistence/src/main/java/org/onap/policy/drools/persistence/JpaDroolsSessionConnector.java b/feature-session-persistence/src/main/java/org/onap/policy/drools/persistence/JpaDroolsSessionConnector.java
index d682e563..8fcbc795 100644
--- a/feature-session-persistence/src/main/java/org/onap/policy/drools/persistence/JpaDroolsSessionConnector.java
+++ b/feature-session-persistence/src/main/java/org/onap/policy/drools/persistence/JpaDroolsSessionConnector.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* feature-session-persistence
* ================================================================================
- * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2018, 2021 AT&T Intellectual Property. 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.
@@ -22,19 +22,17 @@ package org.onap.policy.drools.persistence;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
+import lombok.AllArgsConstructor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+@AllArgsConstructor
public class JpaDroolsSessionConnector implements DroolsSessionConnector {
private static Logger logger = LoggerFactory.getLogger(JpaDroolsSessionConnector.class);
private final EntityManagerFactory emf;
- public JpaDroolsSessionConnector(EntityManagerFactory emf) {
- this.emf = emf;
- }
-
@Override
public DroolsSession get(String sessName) {
diff --git a/feature-session-persistence/src/main/java/org/onap/policy/drools/persistence/PersistenceFeature.java b/feature-session-persistence/src/main/java/org/onap/policy/drools/persistence/PersistenceFeature.java
index 3c3e5008..a929c712 100644
--- a/feature-session-persistence/src/main/java/org/onap/policy/drools/persistence/PersistenceFeature.java
+++ b/feature-session-persistence/src/main/java/org/onap/policy/drools/persistence/PersistenceFeature.java
@@ -151,7 +151,7 @@ public class PersistenceFeature implements PolicySessionFeatureApi, PolicyEngine
@Override
public PolicySession.ThreadModel selectThreadModel(PolicySession session) {
- var policyContainer = session.getPolicyContainer();
+ var policyContainer = session.getContainer();
if (isPersistenceEnabled(policyContainer, session.getName())) {
return new PersistentThreadModel(session, getProperties(policyContainer));
}
@@ -165,7 +165,7 @@ public class PersistenceFeature implements PolicySessionFeatureApi, PolicyEngine
public void disposeKieSession(PolicySession policySession) {
ContainerAdjunct contAdj =
- (ContainerAdjunct) policySession.getPolicyContainer().getAdjunct(this);
+ (ContainerAdjunct) policySession.getContainer().getAdjunct(this);
if (contAdj != null) {
contAdj.disposeKieSession(policySession.getName());
}
@@ -178,7 +178,7 @@ public class PersistenceFeature implements PolicySessionFeatureApi, PolicyEngine
public void destroyKieSession(PolicySession policySession) {
ContainerAdjunct contAdj =
- (ContainerAdjunct) policySession.getPolicyContainer().getAdjunct(this);
+ (ContainerAdjunct) policySession.getContainer().getAdjunct(this);
if (contAdj != null) {
contAdj.destroyKieSession(policySession.getName());
}
diff --git a/feature-session-persistence/src/test/java/org/onap/policy/drools/persistence/DroolsSessionEntityTest.java b/feature-session-persistence/src/test/java/org/onap/policy/drools/persistence/DroolsSessionEntityTest.java
index 2cc7d33a..bd979162 100644
--- a/feature-session-persistence/src/test/java/org/onap/policy/drools/persistence/DroolsSessionEntityTest.java
+++ b/feature-session-persistence/src/test/java/org/onap/policy/drools/persistence/DroolsSessionEntityTest.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* feature-session-persistence
* ================================================================================
- * Copyright (C) 2017-2018, 2020 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2018, 2020-2021 AT&T Intellectual Property. 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.
@@ -173,20 +173,7 @@ public class DroolsSessionEntityTest {
* @param sessid session id
* @return a new session Entity
*/
- @SuppressWarnings("serial")
private DroolsSessionEntity makeEnt2(String sessnm, long sessid) {
-
- return new DroolsSessionEntity() {
-
- @Override
- public String getSessionName() {
- return sessnm;
- }
-
- @Override
- public long getSessionId() {
- return sessid;
- }
- };
+ return new DroolsSessionEntity(sessnm, sessid);
}
}
diff --git a/feature-session-persistence/src/test/java/org/onap/policy/drools/persistence/PersistenceFeatureTest.java b/feature-session-persistence/src/test/java/org/onap/policy/drools/persistence/PersistenceFeatureTest.java
index ec261982..4450b8c8 100644
--- a/feature-session-persistence/src/test/java/org/onap/policy/drools/persistence/PersistenceFeatureTest.java
+++ b/feature-session-persistence/src/test/java/org/onap/policy/drools/persistence/PersistenceFeatureTest.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* feature-session-persistence
* ================================================================================
- * Copyright (C) 2017-2018, 2020 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2018, 2020-2021 AT&T Intellectual Property. 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.
@@ -188,7 +188,7 @@ public class PersistenceFeatureTest {
KieContainer kiecont = mock(KieContainer.class);
when(polcont.getKieContainer()).thenReturn(kiecont);
- when(polsess.getPolicyContainer()).thenReturn(polcont);
+ when(polsess.getContainer()).thenReturn(polcont);
when(kiecont.getKieBase(anyString())).thenReturn(kiebase);
}
@@ -1167,7 +1167,7 @@ public class PersistenceFeatureTest {
when(sess.getSessionId()).thenReturn(sessid);
- when(polsess.getPolicyContainer()).thenReturn(polcont);
+ when(polsess.getContainer()).thenReturn(polcont);
when(polsess.getName()).thenReturn(sessnm);
if (loadOk) {