Added c3p0 datasource configuration to Spring default-config-xml.
Change-Id: Iab9038233b8f74a4645e920ae2e009882a08ccf5
diff --git a/full/src/main/java/de/ids_mannheim/korap/config/AuthCodeInfo.java b/full/src/main/java/de/ids_mannheim/korap/config/AuthCodeInfo.java
deleted file mode 100644
index 03c22d5..0000000
--- a/full/src/main/java/de/ids_mannheim/korap/config/AuthCodeInfo.java
+++ /dev/null
@@ -1,33 +0,0 @@
-package de.ids_mannheim.korap.config;
-
-import lombok.Data;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * @author hanl
- * @date 13/05/2015
- */
-@Data
-public class AuthCodeInfo {
- private String clientId;
- private String scopes;
- private Integer userId;
- private Boolean status;
- private String code;
- private List<String> tokens;
-
-
- public AuthCodeInfo () {
- this.setStatus(true);
- this.tokens = new ArrayList<>();
- }
-
-
- public AuthCodeInfo (String clientid, String authcode) {
- this();
- this.clientId = clientid;
- this.code = authcode;
- }
-}
diff --git a/full/src/main/java/de/ids_mannheim/korap/handlers/OAuth2Handler.java b/full/src/main/java/de/ids_mannheim/korap/handlers/OAuth2Handler.java
deleted file mode 100644
index 28e848b..0000000
--- a/full/src/main/java/de/ids_mannheim/korap/handlers/OAuth2Handler.java
+++ /dev/null
@@ -1,66 +0,0 @@
-package de.ids_mannheim.korap.handlers;
-
-import de.ids_mannheim.korap.config.AuthCodeInfo;
-import de.ids_mannheim.korap.config.ClientInfo;
-import de.ids_mannheim.korap.config.KustvaktCacheable;
-import de.ids_mannheim.korap.exceptions.KustvaktException;
-import de.ids_mannheim.korap.interfaces.db.PersistenceClient;
-import de.ids_mannheim.korap.user.User;
-
-/**
- * extends OAuthDb to allow temporary caching of tokens
- * and authorization codes.
- * Authorization codes are not persisted in db,
- * but stored in file of ehcache
- *
- * @author hanl
- * @date 04/05/2015
- */
-public class OAuth2Handler extends KustvaktCacheable {
-
- private OAuthDb oauthdb;
-
- public OAuth2Handler (PersistenceClient client) {
- super("auth_codes", "key:auth_codes");
- this.oauthdb = new OAuthDb(client);
- }
-
-
- // fixme: caching should not be obligatory here. alternative to caching if not available?
- public AuthCodeInfo getAuthorization (String code) {
- Object value = this.getCacheValue(code);
- if (value != null)
- return (AuthCodeInfo) value;
- return null;
- }
-
-
- public void authorize (AuthCodeInfo info, User user) throws KustvaktException {
-
- info.setUserId(user.getId());
- this.storeInCache(info.getCode(), info);
- }
-
-
- public boolean addToken (String code, String token, String refresh, int ttl)
- throws KustvaktException {
- Object o = this.getCacheValue(code);
- if (o != null) {
- AuthCodeInfo info = (AuthCodeInfo) o;
- this.removeCacheEntry(code);
- return oauthdb.addToken(token, refresh, info.getUserId(),
- info.getClientId(), info.getScopes(), ttl);
- }
- return false;
- }
-
-
- public void exchangeToken (String refresh) {
- // todo:
- }
-
- public OAuthDb getPersistenceHandler(){
- return this.oauthdb;
- }
-
-}
diff --git a/full/src/main/resources/default-config.xml b/full/src/main/resources/default-config.xml
index ac243e3..8a30f95 100644
--- a/full/src/main/resources/default-config.xml
+++ b/full/src/main/resources/default-config.xml
@@ -18,9 +18,6 @@
<context:component-scan base-package="de.ids_mannheim.korap" />
<context:annotation-config />
- <!-- <bean id="test" class="de.ids_mannheim.korap.web.Test"> <property name="config"
- ref="kustvakt_config" /> </bean> -->
-
<bean id="props"
class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<property name="ignoreResourceNotFound" value="true" />
@@ -70,9 +67,23 @@
<property name="maxTotal" value="4" />
<property name="maxIdle" value="2" />
<property name="minIdle" value="1" />
- <property name="maxWaitMillis" value="15000" />
+ <property name="maxWaitMillis" value="-1" />
<!--<property name="poolPreparedStatements" value="true"/> -->
</bean>
+
+ <bean id="c3p0DataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
+ destroy-method="close" lazy-init="true">
+ <property name="driverClass" value="${jdbc.driverClassName}" />
+ <property name="jdbcUrl" value="${jdbc.url}" />
+ <property name="user" value="${jdbc.username}" />
+ <property name="password" value="${jdbc.password}" />
+ <property name="maxPoolSize" value="4" />
+ <property name="minPoolSize" value="1" />
+ <property name="maxStatements" value="100" />
+ <!-- <property name="testConnectionOnCheckOut" value="true" /> -->
+ <property name="idleConnectionTestPeriod" value="60" />
+ <property name="testConnectionOnCheckin" value="true" />
+ </bean>
<bean id="sqliteDataSource"
class="org.springframework.jdbc.datasource.SingleConnectionDataSource"
@@ -102,7 +113,9 @@
<!-- <property name="cleanOnValidationError" value="true" /> -->
<property name="locations" value="${jdbc.schemaPath}" />
<!-- <property name="dataSource" ref="dataSource" /> -->
- <property name="dataSource" ref="sqliteDataSource" />
+ <!-- <property name="dataSource" ref="sqliteDataSource" /> -->
+ <property name="dataSource" ref="c3p0DataSource" />
+
</bean>
@@ -115,7 +128,8 @@
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<!-- <property name="dataSource" ref="dataSource" /> -->
- <property name="dataSource" ref="sqliteDataSource" />
+ <!-- <property name="dataSource" ref="sqliteDataSource" /> -->
+ <property name="dataSource" ref="c3p0DataSource" />
<property name="packagesToScan">
<array>
@@ -140,11 +154,6 @@
<prop key="hibernate.cache.provider_class">${hibernate.cache.provider}</prop>
<prop key="hibernate.cache.region.factory_class">${hibernate.cache.region.factory}</prop>
<prop key="hibernate.jdbc.time_zone">${hibernate.jdbc.time_zone}</prop>
- <!-- <prop key="net.sf.ehcache.configurationResourceName">classpath:ehcache.xml</prop> -->
-
- <prop key="connection.autoReconnect">true</prop>
- <prop key="connection.autoReconnectForPools">true</prop>
- <prop key="connection.is-connection-validation-required">true</prop>
</props>
</property>
</bean>
@@ -328,7 +337,8 @@
<bean id="txManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<!-- <property name="dataSource" ref="dataSource" /> -->
- <property name="dataSource" ref="sqliteDataSource" />
+ <!-- <property name="dataSource" ref="sqliteDataSource" /> -->
+ <property name="dataSource" ref="c3p0DataSource" />
</bean>
<!-- mail -->
diff --git a/full/src/main/resources/properties/jdbc.properties b/full/src/main/resources/properties/jdbc.properties
index 1f5e8ab..aea7ab9 100644
--- a/full/src/main/resources/properties/jdbc.properties
+++ b/full/src/main/resources/properties/jdbc.properties
@@ -4,7 +4,7 @@
#jdbc.database=mysql
#jdbc.driverClassName=com.mysql.jdbc.Driver
-#jdbc.url=jdbc:mysql://localhost:3306/kustvakt?autoReconnect=true&useSSL=false&useLegacyDatetimeCode=false&serverTimezone=UTC
+#jdbc.url=jdbc:mysql://localhost:3306/kustvakt?useSSL=false&useLegacyDatetimeCode=false&serverTimezone=UTC
#jdbc.username=korap
#jdbc.password=password