aboutsummaryrefslogtreecommitdiff
path: root/id/server/idserverlib/src/main/java/at/gv
diff options
context:
space:
mode:
Diffstat (limited to 'id/server/idserverlib/src/main/java/at/gv')
-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)");
+//
+// }
}