aboutsummaryrefslogtreecommitdiff
path: root/id/server/moa-id-commons/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'id/server/moa-id-commons/src/main')
-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.java2
-rw-r--r--id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/StatisticLogDBUtils.java182
-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/resources/META-INF/persistence.xml24
-rw-r--r--id/server/moa-id-commons/src/main/resources/configuration.beans.xml1
-rw-r--r--id/server/moa-id-commons/src/main/resources/hibernate_moasession.cfg.xml15
-rw-r--r--id/server/moa-id-commons/src/main/resources/hibernate_statistic.cfg.xml11
-rw-r--r--id/server/moa-id-commons/src/main/resources/statistic.logging.beans.xml73
9 files changed, 122 insertions, 196 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..a3d833f62 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
@@ -36,7 +36,7 @@ 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 {
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..f8ea1c8f6 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,63 @@ 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.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 static SessionFactory sessionFactory;
- private static ServiceRegistry serviceRegistry;
-
- @SuppressWarnings("rawtypes")
- private static final ThreadLocal THREAD_LOCAL_STATISTIC = new ThreadLocal();
- private static boolean automaticSessionHandling = false;
+ private SessionFactory sessionFactory;
+
+ @Autowired
+ public void setSessionFactory(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/resources/META-INF/persistence.xml b/id/server/moa-id-commons/src/main/resources/META-INF/persistence.xml
deleted file mode 100644
index 5c1558507..000000000
--- a/id/server/moa-id-commons/src/main/resources/META-INF/persistence.xml
+++ /dev/null
@@ -1,24 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<persistence xmlns="http://java.sun.com/xml/ns/persistence"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
-http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
- version="2.0">
-
- <persistence-unit name="config" transaction-type="RESOURCE_LOCAL">
- <provider>org.hibernate.ejb.HibernatePersistence</provider>
- <class>at.gv.egovernment.moa.id.commons.db.dao.config.ConfigProperty</class>
- <!-- <class>at.gv.egovernment.moa.id.commons.db.dao.config.UserDatabase</class> -->
- <properties>
- </properties>
- </persistence-unit>
-
- <persistence-unit name="session" transaction-type="RESOURCE_LOCAL">
- <provider>org.hibernate.ejb.HibernatePersistence</provider>
- <class>at.gv.egovernment.moa.id.commons.db.dao.session.AssertionStore</class>
- <!-- <class>at.gv.egovernment.moa.id.commons.db.dao.config.UserDatabase</class> -->
- <properties>
- </properties>
- </persistence-unit>
-
-</persistence> \ No newline at end of file
diff --git a/id/server/moa-id-commons/src/main/resources/configuration.beans.xml b/id/server/moa-id-commons/src/main/resources/configuration.beans.xml
index 4d3caea8c..b97b1c88b 100644
--- a/id/server/moa-id-commons/src/main/resources/configuration.beans.xml
+++ b/id/server/moa-id-commons/src/main/resources/configuration.beans.xml
@@ -17,6 +17,7 @@
<bean id="moaidconfig" class="at.gv.egovernment.moa.id.commons.config.persistence.MOAIDConfigurationImpl" />
<bean name="config" id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
+ <property name="packagesToScan" value="at.gv.egovernment.moa.id.commons.db.dao.config" />
<property name="dataSource" ref="dataSource" />
<property name="jpaVendorAdapter" ref="jpaVendorAdapter" />
<property name="persistenceUnitName" value="config" />
diff --git a/id/server/moa-id-commons/src/main/resources/hibernate_moasession.cfg.xml b/id/server/moa-id-commons/src/main/resources/hibernate_moasession.cfg.xml
deleted file mode 100644
index e40c8b8a9..000000000
--- a/id/server/moa-id-commons/src/main/resources/hibernate_moasession.cfg.xml
+++ /dev/null
@@ -1,15 +0,0 @@
-<?xml version='1.0' encoding='utf-8'?>
-<!DOCTYPE hibernate-configuration PUBLIC
-"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
-"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
-
-<hibernate-configuration>
- <session-factory>
- <!-- MOA Session handling mapping files -->
- <mapping class="at.gv.egovernment.moa.id.commons.db.dao.session.AssertionStore"/>
- <mapping class="at.gv.egovernment.moa.id.commons.db.dao.session.AuthenticatedSessionStore"/>
- <mapping class="at.gv.egovernment.moa.id.commons.db.dao.session.OASessionStore"/>
- <mapping class="at.gv.egovernment.moa.id.commons.db.dao.session.OldSSOSessionIDStore"/>
- <mapping class="at.gv.egovernment.moa.id.commons.db.dao.session.ExceptionStore"/>
- </session-factory>
-</hibernate-configuration> \ No newline at end of file
diff --git a/id/server/moa-id-commons/src/main/resources/hibernate_statistic.cfg.xml b/id/server/moa-id-commons/src/main/resources/hibernate_statistic.cfg.xml
deleted file mode 100644
index aa77a9c67..000000000
--- a/id/server/moa-id-commons/src/main/resources/hibernate_statistic.cfg.xml
+++ /dev/null
@@ -1,11 +0,0 @@
-<?xml version='1.0' encoding='utf-8'?>
-<!DOCTYPE hibernate-configuration PUBLIC
-"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
-"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
-
-<hibernate-configuration>
- <session-factory>
- <!-- MOA advanced statistic handling mapping files -->
- <mapping class="at.gv.egovernment.moa.id.commons.db.dao.statistic.StatisticLog"/>
- </session-factory>
-</hibernate-configuration> \ No newline at end of file
diff --git a/id/server/moa-id-commons/src/main/resources/statistic.logging.beans.xml b/id/server/moa-id-commons/src/main/resources/statistic.logging.beans.xml
new file mode 100644
index 000000000..fc8edf44e
--- /dev/null
+++ b/id/server/moa-id-commons/src/main/resources/statistic.logging.beans.xml
@@ -0,0 +1,73 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans profile="advancedLogOn"
+ xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:context="http://www.springframework.org/schema/context"
+ xmlns:tx="http://www.springframework.org/schema/tx"
+ xmlns:aop="http://www.springframework.org/schema/aop"
+ xmlns:p="http://www.springframework.org/schema/p"
+ xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
+ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
+ http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
+ http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
+
+ <context:annotation-config/>
+
+
+ <bean id="statisticLogDataSource" class="org.apache.commons.dbcp2.BasicDataSource" lazy-init="true" destroy-method="close">
+ <aop:scoped-proxy/>
+ <property name="driverClassName" value="${advancedlogging.hibernate.connection.driver_class}" />
+ <property name="url" value="${advancedlogging.hibernate.connection.url}"/>
+ <property name="username" value="${advancedlogging.hibernate.connection.username}" />
+ <property name="password" value="${advancedlogging.hibernate.connection.password}" />
+
+ <property name="connectionProperties" value="${advancedlogging.dbcp.connectionProperties}" />
+ <property name="initialSize" value="${advancedlogging.dbcp.initialSize}" />
+ <property name="maxTotal" value="${advancedlogging.dbcp.maxActive}" />
+ <property name="maxIdle" value="${advancedlogging.dbcp.maxIdle}" />
+ <property name="minIdle" value="${advancedlogging.dbcp.minIdle}" />
+ <!-- property name="maxWait" value="${moasession.dbcp.maxWaitMillis}" / -->
+ <property name="testOnBorrow" value="${advancedlogging.dbcp.testOnBorrow}" />
+ <property name="testOnReturn" value="${advancedlogging.dbcp.testOnReturn}" />
+ <property name="testWhileIdle" value="${advancedlogging.dbcp.testWhileIdle}" />
+ <property name="validationQuery" value="${advancedlogging.dbcp.validationQuery}" />
+ </bean>
+
+ <bean id="statisticLogSessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
+ <property name="dataSource" ref="statisticLogDataSource"/>
+ <property name="hibernateProperties">
+ <props>
+ <prop key="hibernate.dialect">${advancedlogging.hibernate.dialect}</prop>
+ <prop key="hibernate.show_sql">${advancedlogging.hibernate.show_sql}</prop>
+ <prop key="hibernate.hbm2ddl.auto">${advancedlogging.hibernate.hbm2ddl.auto}</prop>
+ <prop key="current_session_context_class">${advancedlogging.hibernate.current_session_context_class}</prop>
+ <prop key="hibernate.transaction.flush_before_completion">${advancedlogging.hibernate.transaction.flush_before_completion}</prop>
+ <prop key="hibernate.transaction.auto_close_session">${advancedlogging.hibernate.transaction.auto_close_session}</prop>
+ </props>
+ </property>
+ </bean>
+
+
+ <bean id="statisticLogDBUtils" class="at.gv.egovernment.moa.id.commons.db.StatisticLogDBUtils">
+ </bean>
+
+ <bean name="statisticLogTransactionManager" id="statisticLogTransactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
+ <property name="entityManagerFactory" ref="statisticEntityManagerFactory" />
+ </bean>
+
+ <bean id="statisticJpaVendorAdapter" class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
+ <property name="showSql" value="${advancedlogging.hibernate.show_sql}" />
+ <property name="generateDdl" value="${advancedlogging.jpaVendorAdapter.generateDdl}" />
+ <property name="databasePlatform" value="${advancedlogging.hibernate.dialect}" />
+ </bean>
+
+ <bean name="statisticLog" id="statisticEntityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
+ <property name="dataSource" ref="statisticLogDataSource" />
+ <property name="jpaVendorAdapter" ref="statisticJpaVendorAdapter" />
+ <property name="packagesToScan" value="at.gv.egovernment.moa.id.commons.db.dao.statistic" />
+ <property name="persistenceUnitName" value="statistic" />
+ </bean>
+ <tx:annotation-driven transaction-manager="statisticLogTransactionManager"/>
+
+
+</beans> \ No newline at end of file