aboutsummaryrefslogtreecommitdiff
path: root/id/server/moa-id-commons/src/main/java/at/gv
diff options
context:
space:
mode:
Diffstat (limited to 'id/server/moa-id-commons/src/main/java/at/gv')
-rw-r--r--id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/config/SpringProfileConstants.java8
-rw-r--r--id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/MOASessionDBUtils.java4
-rw-r--r--id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/StatisticLogDBUtils.java184
-rw-r--r--id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/dao/session/AssertionStore.java2
-rw-r--r--id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/dao/statistic/StatisticLog.java2
5 files changed, 53 insertions, 147 deletions
diff --git a/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/config/SpringProfileConstants.java b/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/config/SpringProfileConstants.java
new file mode 100644
index 000000000..14824b1f8
--- /dev/null
+++ b/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/config/SpringProfileConstants.java
@@ -0,0 +1,8 @@
+package at.gv.egovernment.moa.id.commons.config;
+
+public final class SpringProfileConstants {
+
+ public static final String ADVANCED_LOG = "advancedLogOn";
+ public static final String REDIS_BACKEND = "redisBackend";
+ public static final String DB_BACKEND = "dbBackend";
+}
diff --git a/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/MOASessionDBUtils.java b/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/MOASessionDBUtils.java
index fbbaf9476..5cdd607ac 100644
--- a/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/MOASessionDBUtils.java
+++ b/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/MOASessionDBUtils.java
@@ -30,19 +30,21 @@ import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import at.gv.egovernment.moa.id.commons.db.ex.MOADatabaseException;
import at.gv.egovernment.moa.logging.Logger;
-@Transactional
+@Transactional("sessionTransactionManager")
public class MOASessionDBUtils {
private SessionFactory sessionFactory;
@Autowired
+ @Qualifier("sessionSessionFactory")
public void setSessionFactory(SessionFactory sessionFactory) {
this.sessionFactory = sessionFactory;
}
diff --git a/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/StatisticLogDBUtils.java b/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/StatisticLogDBUtils.java
index 7e031cc76..51bb0eb6d 100644
--- a/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/StatisticLogDBUtils.java
+++ b/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/StatisticLogDBUtils.java
@@ -24,169 +24,65 @@ package at.gv.egovernment.moa.id.commons.db;
import java.util.Properties;
-import org.apache.commons.lang3.StringUtils;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
-import org.hibernate.Transaction;
-import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.Configuration;
-import org.hibernate.service.ServiceRegistry;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.transaction.annotation.Transactional;
import at.gv.egovernment.moa.id.commons.db.ex.MOADatabaseException;
import at.gv.egovernment.moa.logging.Logger;
-public final class StatisticLogDBUtils {
+@Transactional("statisticLogTransactionManager")
+public class StatisticLogDBUtils {
+
+ private SessionFactory sessionFactory;
- private static SessionFactory sessionFactory;
- private static ServiceRegistry serviceRegistry;
-
- @SuppressWarnings("rawtypes")
- private static final ThreadLocal THREAD_LOCAL_STATISTIC = new ThreadLocal();
- private static boolean automaticSessionHandling = false;
+ @Autowired
+ @Qualifier("statisticLogSessionFactory")
+ public void setstatisticLogSessionFactory(SessionFactory sessionFactory) {
+ this.sessionFactory = sessionFactory;
+ }
- private static final String[] AUTOMATIC_SESSION_HANDLING_VALUES = new String[] { "jta", "thread" };
- private static final String SESSION_HANDLING_KEY = "hibernate.current_session_context_class";
-
- protected StatisticLogDBUtils() { }
public static void initHibernate(Configuration config, Properties hibernateProperties) {
- String scm = StringUtils.trimToNull(hibernateProperties.getProperty(SESSION_HANDLING_KEY));
- if (scm != null) {
- automaticSessionHandling = scm.indexOf(AUTOMATIC_SESSION_HANDLING_VALUES[0]) != -1 || scm.indexOf(AUTOMATIC_SESSION_HANDLING_VALUES[1]) != -1;
- }
- Logger.debug("Evaluating hibernate property \"" + SESSION_HANDLING_KEY + "\".");
- if (automaticSessionHandling) {
- Logger.info("Hibernate is automatically handling session context management.");
- } else {
- Logger.info("Hibernate is NOT automatically handling session context management. Using build-in ThreadLocal session handling.");
- }
- try {
- //Create the SessionFactory
- Logger.debug("Creating initial StatisicLogger session factory...");
-
- config.configure("hibernate_statistic.cfg.xml");
- //serviceRegistry = new ServiceRegistryBuilder().applySettings(config.getProperties()).buildServiceRegistry();
-
- serviceRegistry = new StandardServiceRegistryBuilder().
- applySettings(config.getProperties()).build();
-
- sessionFactory = config.buildSessionFactory(serviceRegistry);
- Logger.debug("Initial StatisicLogger session factory successfully created.");
-
- } catch (Throwable ex) {
- Logger.error("Initial StatisicLogger session factory creation failed: " + ex.getMessage());
- throw new ExceptionInInitializerError(ex);
- }
- }
-
- /**
- * Checks if a session factory is currently available. If necessary a new
- * session factory is created.
- *
- * @return current (or new) session factory
- * @throws HibernateException
- * thrown if a hibernate error occurs
- */
- public static Session getCurrentSession() {
- if (automaticSessionHandling) {
- return sessionFactory.getCurrentSession();
- }
- Session session = (Session) THREAD_LOCAL_STATISTIC.get();
- // Open a new Session, if this Thread has none yet
- if (session == null || !session.isConnected()) {
- session = getNewSession();
- }
- return session;
}
- @SuppressWarnings("unchecked")
- public static Session getNewSession() {
- if (automaticSessionHandling) {
- Logger.warn("Session is being automatically handled by hibernate. Therefore this session maybe not being newly created. Use HibernateUtil.getCurrentSession() instead.");
- return sessionFactory.getCurrentSession();
- }
- Session session = (Session) THREAD_LOCAL_STATISTIC.get();
- if (session != null) {
- Logger.warn("Previous StatisicLogger session has not been closed; closing session now.");
- closeSession();
- }
- Logger.debug("Opening new StatisicLogger hibernate session...");
- try {
- session = sessionFactory.openSession();
- THREAD_LOCAL_STATISTIC.set(session);
- } catch (HibernateException hex) {
- Logger.error(hex.getMessage());
- }
- return session;
- }
-
- /**
- * Closes the current session.
- *
- * @throws HibernateException
- * thrown if session is already closed or a hibernate error
- * occurs.
- */
- @SuppressWarnings("unchecked")
- public static void closeSession() {
- if (automaticSessionHandling) {
- Logger.warn("Session is being automatically handled by hibernate. Therefore the current session cannot be closed on demand.");
- return;
- }
- Logger.debug("Closing current StatisicLogger hibernate session...");
- Session session = (Session) THREAD_LOCAL_STATISTIC.get();
- THREAD_LOCAL_STATISTIC.set(null);
- if (session != null) {
- try {
- session.close();
-
- } catch (HibernateException hex) {
- Logger.error(hex.getMessage());
- }
- }
- }
-
- public static boolean saveOrUpdate(Object dbo) throws MOADatabaseException {
- Transaction tx = null;
- try {
- Session session = StatisticLogDBUtils.getCurrentSession();
-
- synchronized (session) {
- tx = session.beginTransaction();
- session.saveOrUpdate(dbo);
- tx.commit();
- }
-
- Logger.info("Insert advanced statistic log entry into database");
- return true;
-
- } catch(HibernateException e) {
- Logger.warn("Error during StatisicLogger database saveOrUpdate. Rollback.", e);
- tx.rollback();
- throw new MOADatabaseException(e);
- }
- }
+ public boolean saveOrUpdate(Object dbo) throws MOADatabaseException {
- public static boolean delete(Object dbo) {
- Transaction tx = null;
- try {
- Session session = StatisticLogDBUtils.getCurrentSession();
-
- synchronized (session) {
- tx = session.beginTransaction();
- session.delete(dbo);
- tx.commit();
- }
-
- return true;
+ try {
+ Session session = sessionFactory.getCurrentSession();
+ session.saveOrUpdate(dbo);
+ //session.persist(dbo);
+ return true;
} catch(HibernateException e) {
- Logger.warn("Error during StatisicLogger database delete. Rollback.", e);
- tx.rollback();
- return false;
+ Logger.warn("Error during StatisicLogger database saveOrUpdate.", e);
+
+ throw new MOADatabaseException(e);
}
+
}
+
+ public boolean delete(Object dbo) {
+ try {
+ Session session = sessionFactory.getCurrentSession();
+ session.delete(dbo);
+ return true;
+
+ } catch(HibernateException e) {
+ Logger.warn("Error during StatisicLogger database delete. Rollback.");
+ return false;
+ }
+ }
+
+
+ public Session getCurrentSession() {
+ // TODO Auto-generated method stub
+ return sessionFactory.getCurrentSession();
+ }
}
diff --git a/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/dao/session/AssertionStore.java b/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/dao/session/AssertionStore.java
index d9528cbed..4c6cd16c0 100644
--- a/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/dao/session/AssertionStore.java
+++ b/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/dao/session/AssertionStore.java
@@ -65,7 +65,7 @@ public class AssertionStore implements Serializable{
@Id
- @GeneratedValue(strategy = GenerationType.AUTO)
+ @GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id", unique=true, nullable=false)
private long id;
diff --git a/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/dao/statistic/StatisticLog.java b/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/dao/statistic/StatisticLog.java
index 97f26812f..ba48f8caf 100644
--- a/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/dao/statistic/StatisticLog.java
+++ b/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/dao/statistic/StatisticLog.java
@@ -39,7 +39,7 @@ import org.hibernate.annotations.DynamicUpdate;
@Entity
-@DynamicUpdate(value=true)
+//@DynamicUpdate(value=true)
@Table(name = "statisticlog")
@NamedQueries({
@NamedQuery(name="getAllEntriesNotBeforeTimeStamp", query = "select statisiclog from StatisticLog statisiclog where statisiclog.timestamp > :timeout")