aboutsummaryrefslogtreecommitdiff
path: root/id/server/idserverlib/src/main/java/at/gv/egovernment
diff options
context:
space:
mode:
authorChristian Maierhofer <cmaierhofer@iaik.tugraz.at>2016-04-26 15:35:46 +0200
committerChristian Maierhofer <cmaierhofer@iaik.tugraz.at>2016-04-26 15:35:46 +0200
commit129285d2c6fcd82a3cba7fc5345e87699129c005 (patch)
treec325262f5fc6f2f3fa5fdd5fdc0f63a6725adf64 /id/server/idserverlib/src/main/java/at/gv/egovernment
parent851f8c8ed0959c75a2bd28a61ff4cd5dd49f98f5 (diff)
downloadmoa-id-spss-129285d2c6fcd82a3cba7fc5345e87699129c005.tar.gz
moa-id-spss-129285d2c6fcd82a3cba7fc5345e87699129c005.tar.bz2
moa-id-spss-129285d2c6fcd82a3cba7fc5345e87699129c005.zip
modified RedisTransactionStorage, modified beans definition
Diffstat (limited to 'id/server/idserverlib/src/main/java/at/gv/egovernment')
-rw-r--r--id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/storage/DBTransactionStorage.java89
-rw-r--r--id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/storage/RedisTransactionStorage.java26
2 files changed, 55 insertions, 60 deletions
diff --git a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/storage/DBTransactionStorage.java b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/storage/DBTransactionStorage.java
index 4699ad09c..89df47615 100644
--- a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/storage/DBTransactionStorage.java
+++ b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/storage/DBTransactionStorage.java
@@ -27,24 +27,31 @@ import java.util.ArrayList;
import java.util.Date;
import java.util.List;
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+import javax.persistence.PersistenceException;
+import javax.persistence.Query;
+
import org.apache.commons.lang.SerializationUtils;
import org.hibernate.HibernateException;
-import org.hibernate.Query;
-import org.hibernate.Session;
-import org.springframework.stereotype.Service;
+import org.springframework.stereotype.Repository;
+import org.springframework.transaction.annotation.Transactional;
import at.gv.egovernment.moa.id.auth.exception.AuthenticationException;
-import at.gv.egovernment.moa.id.commons.db.MOASessionDBUtils;
import at.gv.egovernment.moa.id.commons.db.dao.session.AssertionStore;
import at.gv.egovernment.moa.id.commons.db.ex.MOADatabaseException;
import at.gv.egovernment.moa.logging.Logger;
import at.gv.egovernment.moa.util.MiscUtil;
-@Service("TransactionStorage")
+@Repository
+@Transactional("sessionTransactionManager")
public class DBTransactionStorage implements ITransactionStorage {
-
+
+ @PersistenceContext(unitName="session")
+ private EntityManager entityManager;
+
public boolean containsKey(String key) {
- try {
+ try {
searchInDatabase(key);
return true;
@@ -151,16 +158,12 @@ public class DBTransactionStorage implements ITransactionStorage {
List<AssertionStore> results;
List<String> returnValues = new ArrayList<String>();;
- Session session = MOASessionDBUtils.getCurrentSession();
- synchronized (session) {
- session.beginTransaction();
- Query query = session.getNamedQuery("getAssertionWithTimeOut");
- query.setTimestamp("timeout", expioredate);
- results = query.list();
- session.getTransaction().commit();
- }
+ Query query = entityManager.createNamedQuery("getAssertionWithTimeOut");
+ query.setParameter("timeout", expioredate);
+ results = query.getResultList();
+
if (results != null) {
for (AssertionStore el : results)
returnValues.add(el.getArtifact());
@@ -187,24 +190,21 @@ public class DBTransactionStorage implements ITransactionStorage {
Logger.info("Sessioninformation not removed! (Message:"+ e.getMessage() + ")");
} catch (HibernateException e) {
- Logger.warn("Sessioninformation not removed! (Error during Database communication)", e);
+ Logger.warn("Sessioninformation not removed! (Erreor during Database communication)", e);
}
}
private void cleanDelete(AssertionStore element) {
- try {
- element.setAssertion("blank".getBytes());
- MOASessionDBUtils.saveOrUpdate(element);
-
- } catch (MOADatabaseException e) {
- Logger.warn("Blank shortTime session with artifact=" + element.getArtifact() + " FAILED.", e);
+
- } finally {
- if (!MOASessionDBUtils.delete(element))
+ try{
+ element.setAssertion("blank".getBytes());
+ entityManager.merge(element);
+ entityManager.remove(element);
+ }catch(PersistenceException e){
Logger.error("ShortTime session with artifact=" + element.getArtifact()
+ " not removed! (Error during Database communication)");
-
- }
+ }
}
@@ -212,29 +212,23 @@ public class DBTransactionStorage implements ITransactionStorage {
private AssertionStore searchInDatabase(String artifact) throws MOADatabaseException {
MiscUtil.assertNotNull(artifact, "artifact");
Logger.trace("Getting sessioninformation with ID " + artifact + " from database.");
- Session session = MOASessionDBUtils.getCurrentSession();
- List result;
+ List<AssertionStore> results;
- synchronized (session) {
- session.beginTransaction();
- Query query = session.getNamedQuery("getAssertionWithArtifact");
- query.setParameter("artifact", artifact);
- result = query.list();
+ Query query = entityManager.createNamedQuery("getAssertionWithArtifact");
+ query.setParameter("artifact", artifact);
- //send transaction
- session.getTransaction().commit();
- }
+ results = query.getResultList();
- Logger.trace("Found entries: " + result.size());
+ Logger.trace("Found entries: " + results.size());
//Assertion requires an unique artifact
- if (result.size() != 1) {
+ if (results.size() != 1) {
Logger.debug("No transaction information with ID:" + artifact + " found.");
return null;
}
- return (AssertionStore) result.get(0);
+ return results.get(0);
}
private void put(AssertionStore element, String key, Object value) throws MOADatabaseException {
@@ -253,15 +247,16 @@ public class DBTransactionStorage implements ITransactionStorage {
element.setAssertion(data);
//store AssertionStore element to Database
- try {
- MOASessionDBUtils.saveOrUpdate(element);
+ //try {
+ entityManager.merge(element);
+ //MOASessionDBUtils.saveOrUpdate(element);
Logger.debug(value.getClass().getName() + " with ID: " + key + " is stored in Database");
-
- } catch (MOADatabaseException e) {
- Logger.warn("Sessioninformation could not be stored.");
- throw new MOADatabaseException(e);
-
- }
+//
+// } catch (MOADatabaseException e) {
+// Logger.warn("Sessioninformation could not be stored.");
+// throw new MOADatabaseException(e);
+//
+// }
}
diff --git a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/storage/RedisTransactionStorage.java b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/storage/RedisTransactionStorage.java
index a8294fe88..cae73fafd 100644
--- a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/storage/RedisTransactionStorage.java
+++ b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/storage/RedisTransactionStorage.java
@@ -246,19 +246,19 @@ public class RedisTransactionStorage implements ITransactionStorage {
//Not used within REDIS store
private void cleanDelete(AssertionStore element) {
- try {
- element.setAssertion("blank".getBytes());
- MOASessionDBUtils.saveOrUpdate(element);
-
- } catch (MOADatabaseException e) {
- Logger.warn("Blank shortTime session with artifact=" + element.getArtifact() + " FAILED.", e);
-
- } finally {
- if (!MOASessionDBUtils.delete(element))
- Logger.error("ShortTime session with artifact=" + element.getArtifact()
- + " not removed! (Error during Database communication)");
-
- }
+// try {
+// element.setAssertion("blank".getBytes());
+// MOASessionDBUtils.saveOrUpdate(element);
+//
+// } catch (MOADatabaseException e) {
+// Logger.warn("Blank shortTime session with artifact=" + element.getArtifact() + " FAILED.", e);
+//
+// } finally {
+// if (!MOASessionDBUtils.delete(element))
+// Logger.error("ShortTime session with artifact=" + element.getArtifact()
+// + " not removed! (Error during Database communication)");
+//
+// }
}