Implemented Jersey spring dependency injection.
Change-Id: I0d6520c7d489f384d3d03a70b23d9979ba3f11da
diff --git a/pom.xml b/pom.xml
index 2272a63..713412f 100644
--- a/pom.xml
+++ b/pom.xml
@@ -14,6 +14,8 @@
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ <spring-framework.version>4.3.7.RELEASE</spring-framework.version>
+ <jersey.version>1.19.4</jersey.version>
</properties>
<profiles>
<!-- mvn -Plight builds additionally the light server version with reduced functionality! -->
@@ -239,31 +241,70 @@
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-bundle</artifactId>
- <version>1.8</version>
+ <version>${jersey.version}</version>
</dependency>
+ <!--EM: added -->
+ <dependency>
+ <groupId>com.sun.jersey</groupId>
+ <artifactId>jersey-server</artifactId>
+ <version>${jersey.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>com.sun.jersey.contribs</groupId>
+ <artifactId>jersey-spring</artifactId>
+ <version>${jersey.version}</version>
+ <exclusions>
+ <exclusion>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-core</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-web</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-beans</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-context</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-aop</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <!-- EM:done -->
<dependency>
<groupId>com.sun.jersey.jersey-test-framework</groupId>
<artifactId>jersey-test-framework-core</artifactId>
- <version>1.19</version>
+ <version>${jersey.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.sun.jersey.jersey-test-framework</groupId>
<artifactId>jersey-test-framework-grizzly</artifactId>
- <version>1.19</version>
+ <version>${jersey.version}</version>
<scope>test</scope>
</dependency>
- <dependency>
+ <!-- <dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.5</version>
- </dependency>
+ </dependency> -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.5</version>
</dependency>
- <dependency>
+ <!-- <dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
@@ -272,7 +313,7 @@
<groupId>log4j</groupId>
<artifactId>apache-log4j-extras</artifactId>
<version>1.2.17</version>
- </dependency>
+ </dependency> -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
@@ -301,18 +342,6 @@
</exclusion>
</exclusions>
</dependency>
- <!--
- <dependency>
- <groupId>com.sun.jersey</groupId>
- <artifactId>jersey-grizzly2</artifactId>
- <version>1.8</version>
- </dependency>
- <dependency>
- <groupId>com.sun.grizzly</groupId>
- <artifactId>grizzly-servlet-webserver</artifactId>
- <version>1.9.18-i</version>
- </dependency>
- -->
<dependency>
<groupId>org.xerial</groupId>
@@ -325,19 +354,13 @@
<artifactId>mysql-connector-java</artifactId>
<version>5.1.6</version>
</dependency>
-
+
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-dbcp2</artifactId>
<version>2.1.1</version>
</dependency>
-<!--
- <dependency>
- <groupId>org.owasp.esapi</groupId>
- <artifactId>esapi</artifactId>
- <version>2.1.0</version>
- </dependency>
--->
+
<dependency>
<groupId>commons-validator</groupId>
<artifactId>commons-validator</artifactId>
@@ -372,39 +395,53 @@
<artifactId>reflections</artifactId>
<version>0.9.9-RC1</version>
</dependency>
- <!-- deprecated? -->
- <!--<dependency>-->
- <!--<groupId>com.restfuse</groupId>-->
- <!--<artifactId>com.eclipsesource.restfuse</artifactId>-->
- <!--<version>1.0.0</version>-->
- <!--<scope>provided</scope>-->
- <!--</dependency>-->
- <!-- deprecated -->
- <!--<dependency>-->
- <!--<groupId>com.jayway.restassured</groupId>-->
- <!--<artifactId>rest-assured</artifactId>-->
- <!--<version>2.4.0</version>-->
- <!--<scope>provided</scope>-->
- <!--</dependency>-->
- <!--<dependency>-->
- <!--<groupId>org.springframework</groupId>-->
- <!--<artifactId>spring-core</artifactId>-->
- <!--<version>4.0.5.RELEASE</version>-->
- <!--</dependency>-->
+ <!-- EM: added -->
+ <dependency>
+ <groupId>org.hibernate</groupId>
+ <artifactId>hibernate-entitymanager</artifactId>
+ <version>5.1.8.Final</version>
+ </dependency>
+ <dependency>
+ <groupId>org.hibernate</groupId>
+ <artifactId>hibernate-ehcache</artifactId>
+ <version>5.1.8.Final</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-core</artifactId>
+ <version>${spring-framework.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-web</artifactId>
+ <version>${spring-framework.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-asm</artifactId>
+ <version>3.1.4.RELEASE</version>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-orm</artifactId>
+ <version>${spring-framework.version}</version>
+ </dependency>
+ <!-- EM: done -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
- <version>4.0.5.RELEASE</version>
+ <version>${spring-framework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
- <version>4.1.6.RELEASE</version>
+ <version>${spring-framework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
- <version>4.1.6.RELEASE</version>
+ <version>${spring-framework.version}</version>
<scope>compile</scope>
</dependency>
@@ -413,37 +450,36 @@
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
- <version>4.1.6.RELEASE</version>
+ <version>${spring-framework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
- <version>4.1.6.RELEASE</version>
+ <version>${spring-framework.version}</version>
</dependency>
<!-- copied from extension -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
- <version>4.1.6.RELEASE</version>
+ <version>${spring-framework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
- <version>4.1.6.RELEASE</version>
+ <version>${spring-framework.version}</version>
</dependency>
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-core</artifactId>
- <!-- version>3.2.1</version -->
<version>4.0</version>
</dependency>
- <dependency>
+ <!-- <dependency>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache-core</artifactId>
<version>2.6.5</version>
- </dependency>
+ </dependency> -->
<dependency>
<groupId>org.apache.oltu.oauth2</groupId>
diff --git a/src/main/java/de/ids_mannheim/korap/config/KustvaktCacheable.java b/src/main/java/de/ids_mannheim/korap/config/KustvaktCacheable.java
index 1cbec73..b58e66e 100644
--- a/src/main/java/de/ids_mannheim/korap/config/KustvaktCacheable.java
+++ b/src/main/java/de/ids_mannheim/korap/config/KustvaktCacheable.java
@@ -97,7 +97,8 @@
Cache c = getCache(this.name);
if (enabled()) {
c.removeAll();
- c.clearStatistics();
+// c.clearStatistics();
+
}
}
diff --git a/src/main/java/de/ids_mannheim/korap/dao/AnnotationDao.java b/src/main/java/de/ids_mannheim/korap/dao/AnnotationDao.java
index 8677b87..622ed76 100644
--- a/src/main/java/de/ids_mannheim/korap/dao/AnnotationDao.java
+++ b/src/main/java/de/ids_mannheim/korap/dao/AnnotationDao.java
@@ -4,7 +4,6 @@
import org.slf4j.LoggerFactory;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
-import de.ids_mannheim.korap.handlers.EntityDao;
/**
* AnnotationDao manages SQL queries regarding information about
diff --git a/src/main/java/de/ids_mannheim/korap/dao/ResourceDao.java b/src/main/java/de/ids_mannheim/korap/dao/ResourceDao.java
index 9d6b268..564ec4e 100644
--- a/src/main/java/de/ids_mannheim/korap/dao/ResourceDao.java
+++ b/src/main/java/de/ids_mannheim/korap/dao/ResourceDao.java
@@ -1,36 +1,39 @@
package de.ids_mannheim.korap.dao;
+import java.util.List;
+
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+import javax.persistence.Query;
+import javax.persistence.criteria.CriteriaBuilder;
+import javax.persistence.criteria.CriteriaQuery;
+import javax.persistence.criteria.Root;
+
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
-import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
-import org.springframework.jdbc.core.namedparam.SqlParameterSource;
+import org.springframework.stereotype.Component;
-import de.ids_mannheim.korap.handlers.RowMapperFactory;
-import de.ids_mannheim.korap.interfaces.db.PersistenceClient;
+import de.ids_mannheim.korap.entity.Resource;
-/** ResourceDao manages SQL queries regarding resource info and layers.
+/**
+ * ResourceDao manages SQL queries regarding resource info and layers.
*
* @author margaretha
*
*/
+@Component
public class ResourceDao {
private static Logger jlog = LoggerFactory.getLogger(ResourceDao.class);
- private NamedParameterJdbcTemplate jdbcTemplate;
+ @PersistenceContext
+ private EntityManager entityManager;
- public ResourceDao (PersistenceClient<?> client) {
- this.jdbcTemplate = (NamedParameterJdbcTemplate) client.getSource();
+ public List<Resource> getAllResources () {
+ CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
+ CriteriaQuery<Resource> query = criteriaBuilder.createQuery(Resource.class);
+ Root<Resource> r = query.from(Resource.class);
+ Query q = entityManager.createQuery(query.select(r));
+ return q.getResultList();
}
-
- // EM: use JPA?
- public void getResourceInfo (String resourceId) {
- SqlParameterSource namedParameters = new MapSqlParameterSource(
- "resourceId", resourceId);
- String sql = "select * from resource where id=:resourceId";
-// this.jdbcTemplate.queryForObject(sql, namedParameters,
-// new RowMapperFactory.ResourceMapper());
- }
-
}
diff --git a/src/main/java/de/ids_mannheim/korap/entity/Annotation.java b/src/main/java/de/ids_mannheim/korap/entity/Annotation.java
new file mode 100644
index 0000000..8943e9c
--- /dev/null
+++ b/src/main/java/de/ids_mannheim/korap/entity/Annotation.java
@@ -0,0 +1,23 @@
+package de.ids_mannheim.korap.entity;
+
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.Table;
+
+import lombok.Getter;
+import lombok.Setter;
+
+@Getter
+@Setter
+@Entity
+@Table(name = "annotation")
+public class Annotation {
+ @Id
+ @GeneratedValue(strategy = GenerationType.IDENTITY)
+ private int id;
+ private String symbol;
+ private String type;
+ private String description;
+}
diff --git a/src/main/java/de/ids_mannheim/korap/entity/AnnotationPair.java b/src/main/java/de/ids_mannheim/korap/entity/AnnotationPair.java
new file mode 100644
index 0000000..1b9ca7a
--- /dev/null
+++ b/src/main/java/de/ids_mannheim/korap/entity/AnnotationPair.java
@@ -0,0 +1,29 @@
+package de.ids_mannheim.korap.entity;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.Table;
+
+import lombok.Getter;
+import lombok.Setter;
+
+@Getter
+@Setter
+@Entity
+@Table(name = "annotation_pair")
+public class AnnotationPair {
+ @Id
+ @GeneratedValue(strategy = GenerationType.IDENTITY)
+ private int id;
+ @Column(name = "annotation1")
+ private int annotationId1;
+ @Column(name = "annotation2")
+ private int annotationId2;
+ @Column(name = "de_description")
+ private String germanDescription;
+ // english description
+ private String description;
+}
diff --git a/src/main/java/de/ids_mannheim/korap/entity/Resource.java b/src/main/java/de/ids_mannheim/korap/entity/Resource.java
new file mode 100644
index 0000000..b71cf88
--- /dev/null
+++ b/src/main/java/de/ids_mannheim/korap/entity/Resource.java
@@ -0,0 +1,36 @@
+package de.ids_mannheim.korap.entity;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.Table;
+
+import lombok.Getter;
+import lombok.Setter;
+
+@Getter
+@Setter
+@Entity
+@Table(name = "resource")
+public class Resource {
+
+ @Id
+ private String id;
+
+ // german title
+ private String title;
+
+ @Column(name = "en_title")
+ private String englishTitle;
+ private String description;
+
+
+ @Override
+ public String toString () {
+ return "id=" + id + ", title=" + title + ", english title="
+ + englishTitle + ", description="+description;
+ }
+
+}
diff --git a/src/main/java/de/ids_mannheim/korap/web/KustvaktBaseServer.java b/src/main/java/de/ids_mannheim/korap/web/KustvaktBaseServer.java
index 159a786..3b7c5c8 100644
--- a/src/main/java/de/ids_mannheim/korap/web/KustvaktBaseServer.java
+++ b/src/main/java/de/ids_mannheim/korap/web/KustvaktBaseServer.java
@@ -3,23 +3,31 @@
import com.sun.jersey.api.core.PackagesResourceConfig;
import com.sun.jersey.api.core.ResourceConfig;
import com.sun.jersey.spi.container.servlet.ServletContainer;
+import com.sun.jersey.spi.spring.container.servlet.SpringServlet;
+
import de.ids_mannheim.korap.config.*;
import lombok.Getter;
import lombok.Setter;
+
+import javax.servlet.ServletContextListener;
+
import org.eclipse.jetty.server.Connector;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.bio.SocketConnector;
-import org.eclipse.jetty.server.ssl.SslSocketConnector;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder;
import org.eclipse.jetty.util.ssl.SslContextFactory;
+import org.springframework.web.context.ContextLoaderListener;
/**
* @author hanl
* @date 01/06/2015
*/
public abstract class KustvaktBaseServer {
-
+
+ protected static KustvaktConfiguration config;
+ protected static String rootPackages;
+
public KustvaktBaseServer () {
KustvaktConfiguration.loadLogger();
}
@@ -38,7 +46,9 @@
BeansFactory.loadClasspathContext();
kargs.setRootPackages(new String[] { "de.ids_mannheim.korap.web.service.light" });
-
+ rootPackages = "de.ids_mannheim.korap.web.service.light";
+
+ config = BeansFactory.getKustvaktContext().getConfiguration();
server.startServer(kargs);
}
@@ -76,7 +86,51 @@
protected abstract void setup ();
- protected void startServer (KustvaktArgs kargs) {
+ protected void startServer(KustvaktArgs kargs){
+ if (kargs.init){
+ setup();
+ }
+ if (kargs.port == -1){
+ kargs.setPort(BeansFactory.getKustvaktContext().getConfiguration().getPort());
+ }
+
+ Server server = new Server();
+// WebAppContext contextHandler = new WebAppContext();
+// contextHandler.setWar("src/main/webappkustvakt.war");
+ ServletContextHandler contextHandler = new ServletContextHandler(
+ ServletContextHandler.NO_SESSIONS);
+ contextHandler.setContextPath("/");
+ contextHandler.setInitParameter("contextConfigLocation", "classpath:default-config.xml");
+
+ ServletContextListener listener = new ContextLoaderListener();
+ contextHandler.addEventListener(listener);
+
+ ServletHolder servletHolder = new ServletHolder(new SpringServlet());
+ servletHolder.setInitParameter("com.sun.jersey.config.property.packages",
+ rootPackages);
+ servletHolder.setInitOrder(1);
+ contextHandler.addServlet(servletHolder, "/kustvakt/*");
+
+ SocketConnector connector = new SocketConnector();
+ connector.setPort(kargs.port);
+ connector.setMaxIdleTime(60000);
+
+ server.setHandler(contextHandler);
+ server.setConnectors(new Connector[] { connector });
+ try {
+ server.start();
+ server.join();
+ }
+ catch (Exception e) {
+ System.out.println("Server could not be started!");
+ System.out.println(e.getMessage());
+ System.exit(-1);
+// e.printStackTrace();
+ }
+ }
+
+ @Deprecated
+ protected void startServerOld (KustvaktArgs kargs) {
if (kargs.init)
setup();
@@ -92,7 +146,7 @@
ServletContextHandler contextHandler = new ServletContextHandler(
ServletContextHandler.NO_SESSIONS);
contextHandler.setContextPath("/");
-
+
SocketConnector connector = new SocketConnector();
connector.setPort(kargs.port);
connector.setMaxIdleTime(60000);
@@ -100,10 +154,9 @@
// http://stackoverflow.com/questions/9670363/how-do-i-programmatically-configure-jersey-to-use-jackson-for-json-deserializa
final ResourceConfig rc = new PackagesResourceConfig(
kargs.rootPackages);
-
+
// from http://stackoverflow.com/questions/7421574/embedded-jetty-with-jersey-or-resteasy
- contextHandler.addServlet(new ServletHolder(
- new ServletContainer(rc)), "/api/*");
+ contextHandler.addServlet(new ServletHolder(new ServletContainer(rc)), "/api/*");
server.setHandler(contextHandler);
server.setConnectors(new Connector[] { connector });
diff --git a/src/main/java/de/ids_mannheim/korap/web/service/full/ResourceService.java b/src/main/java/de/ids_mannheim/korap/web/service/full/ResourceService.java
index 36e41bf..9e669b4 100644
--- a/src/main/java/de/ids_mannheim/korap/web/service/full/ResourceService.java
+++ b/src/main/java/de/ids_mannheim/korap/web/service/full/ResourceService.java
@@ -12,10 +12,14 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
import com.sun.jersey.spi.container.ResourceFilters;
-import de.ids_mannheim.korap.web.KustvaktServer;
+import de.ids_mannheim.korap.dao.ResourceDao;
+import de.ids_mannheim.korap.entity.Resource;
+import de.ids_mannheim.korap.utils.JsonUtils;
import de.ids_mannheim.korap.web.filter.AuthFilter;
import de.ids_mannheim.korap.web.filter.DemoUserFilter;
import de.ids_mannheim.korap.web.filter.PiwikFilter;
@@ -26,19 +30,24 @@
* @author margaretha
*
*/
-@Path(KustvaktServer.API_VERSION + "/resource/")
+@Service
+@Path("resource/")
@ResourceFilters({ AuthFilter.class, DemoUserFilter.class, PiwikFilter.class })
@Produces(MediaType.APPLICATION_JSON + ";charset=utf-8")
public class ResourceService {
private static Logger jlog = LoggerFactory.getLogger(ResourceService.class);
-
-
+
+ @Autowired
+ private ResourceDao resourceDao;
+
@GET
@Path("info")
- public Response getResourceInfo () {
- // TODO Auto-generated method stub
- return Response.status(200).build();
+ public Response getAllResourceInfo () {
+ List<Resource> resources = resourceDao.getAllResources();
+ String result = JsonUtils.toJSON(resources);
+// System.out.println(result);
+ return Response.ok(result).build();
}
diff --git a/src/main/resources/META-INF/persistence.xml b/src/main/resources/META-INF/persistence.xml
new file mode 100644
index 0000000..ae76d18
--- /dev/null
+++ b/src/main/resources/META-INF/persistence.xml
@@ -0,0 +1,5 @@
+<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="1.0">
+ <persistence-unit name="entityManagerUnit" transaction-type="RESOURCE_LOCAL">
+ <exclude-unlisted-classes/>
+ </persistence-unit>
+</persistence>
\ No newline at end of file
diff --git a/src/main/resources/db/new-mysql/V1__create_tables.sql b/src/main/resources/db/new-mysql/V1__create_tables.sql
index 1225d1c..9c73af8 100644
--- a/src/main/resources/db/new-mysql/V1__create_tables.sql
+++ b/src/main/resources/db/new-mysql/V1__create_tables.sql
@@ -17,7 +17,7 @@
annotation1 INTEGER NOT NULL,
annotation2 INTEGER NOT NULL,
description VARCHAR(300) NOT NULL,
- german_description VARCHAR(300),
+ de_description VARCHAR(300),
UNIQUE INDEX unique_index (annotation1, annotation2),
FOREIGN KEY (annotation1)
REFERENCES annotation (id)
diff --git a/src/main/resources/default-config.xml b/src/main/resources/default-config.xml
index be9f080..64b1bdc 100644
--- a/src/main/resources/default-config.xml
+++ b/src/main/resources/default-config.xml
@@ -1,255 +1,270 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns:p="http://www.springframework.org/schema/p"
- xmlns:util="http://www.springframework.org/schema/util"
- xmlns:aop="http://www.springframework.org/schema/aop"
- xmlns:tx="http://www.springframework.org/schema/tx"
- xmlns="http://www.springframework.org/schema/beans"
- xmlns:cache="http://www.springframework.org/schema/cache"
- xsi:schemaLocation="http://www.springframework.org/schema/beans
- http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
- http://www.springframework.org/schema/tx
- http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
- http://www.springframework.org/schema/aop
- http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
+ xmlns:p="http://www.springframework.org/schema/p" xmlns:util="http://www.springframework.org/schema/util"
+ xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
+ xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context"
+ xmlns:cache="http://www.springframework.org/schema/cache"
+ xsi:schemaLocation="http://www.springframework.org/schema/beans
+ http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
+ http://www.springframework.org/schema/tx
+ http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
+ http://www.springframework.org/schema/aop
+ http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
+ http://www.springframework.org/schema/context
+ http://www.springframework.org/schema/context/spring-context-4.0.xsd
+ http://www.springframework.org/schema/util
+ http://www.springframework.org/schema/util/spring-util-4.0.xsd">
+
+ <context:component-scan base-package="de.ids_mannheim.korap" />
+ <context:annotation-config />
+
+ <bean id="props"
+ class="org.springframework.beans.factory.config.PropertiesFactoryBean">
+ <property name="ignoreResourceNotFound" value="true" />
+ <property name="locations">
+ <array>
+ <value>classpath:kustvakt.conf</value>
+ <value>file:./kustvakt.conf</value>
+ </array>
+ </property>
+ </bean>
+
+ <bean id="placeholders"
+ class="org.springframework.context.support.PropertySourcesPlaceholderConfigurer">
+ <property name="ignoreResourceNotFound" value="true" />
+ <property name="locations">
+ <array>
+ <value>classpath:jdbc.properties</value>
+ <value>classpath:hibernate.properties</value>
+ <!-- <value>file:./jdbc.properties</value> -->
+ </array>
+ </property>
+ </bean>
+
+ <bean id='cacheManager' class='org.springframework.cache.ehcache.EhCacheCacheManager'
+ p:cacheManager-ref='ehcache' />
+
+ <bean id='ehcache'
+ class='org.springframework.cache.ehcache.EhCacheManagerFactoryBean'
+ p:configLocation='classpath:ehcache.xml' p:shared='true' />
+
+ <!-- props are injected from default-config.xml -->
+ <bean id="kustvakt_config" class="de.ids_mannheim.korap.config.KustvaktConfiguration">
+ <property name="properties" ref="props" />
+ </bean>
+
+ <!--class="org.apache.commons.dbcp2.BasicDataSource" -->
+ <!-- org.springframework.jdbc.datasource.SingleConnectionDataSource -->
+ <bean id="dataSource" class="org.apache.commons.dbcp2.BasicDataSource"
+ lazy-init="true">
+ <property name="driverClassName" value="${jdbc.driverClassName}" />
+ <property name="url" value="${jdbc.url}" />
+ <property name="username" value="${jdbc.username}" />
+ <property name="password" value="${jdbc.password}" />
+ <!-- relevant for single connection datasource and sqlite -->
+ <!-- <property name="suppressClose"> <value>true</value> </property> -->
+ <!--<property name="initialSize" value="2"/> -->
+ <property name="maxTotal" value="4" />
+ <property name="maxIdle" value="2" />
+ <property name="minIdle" value="1" />
+ <property name="maxWaitMillis" value="15000" />
+ <!--<property name="poolPreparedStatements" value="true"/> -->
+ </bean>
+
+ <bean id="sqliteDataSource"
+ class="org.springframework.jdbc.datasource.SingleConnectionDataSource"
+ lazy-init="true">
+ <property name="driverClassName" value="${jdbc.driverClassName}" />
+ <property name="url" value="${jdbc.url}" />
+ <property name="username" value="${jdbc.username}" />
+ <property name="password" value="${jdbc.password}" />
+ <!-- relevant for single connection datasource and sqlite -->
+ <property name="suppressClose">
+ <value>true</value>
+ </property>
+ <!--<property name="initialSize" value="2"/> -->
+ <!--<property name="poolPreparedStatements" value="true"/> -->
+ </bean>
+
+ <!-- to configure database for sqlite, mysql, etc. migrations -->
+ <bean id="flyway" class="org.flywaydb.core.Flyway" init-method="migrate">
+ <property name="baselineOnMigrate" value="false" />
+ <property name="validateOnMigrate" value="false" />
+ <property name="locations" value="${jdbc.schemaPath}" />
+ <property name="dataSource" ref="dataSource" />
+ </bean>
+
+ <bean id="kustvakt_db" class="de.ids_mannheim.korap.handlers.JDBCClient">
+ <constructor-arg index="0" ref="dataSource" />
+ <!-- deprecated property -->
+ <property name="database" value="${jdbc.database}" />
+ </bean>
+
+ <bean id="entityManagerFactory"
+ class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
+ <property name="dataSource" ref="dataSource" />
+ <property name="packagesToScan" value="de.ids_mannheim.korap.entity" />
+ <property name="jpaVendorAdapter">
+ <bean id="jpaVendorAdapter"
+ class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
+ <property name="databasePlatform" value="${hibernate.dialect}" />
+ </bean>
+ </property>
+ <property name="jpaProperties">
+ <props>
+ <prop key="hibernate.dialect">${hibernate.dialect}</prop>
+ <prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop>
+ <prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
+ <prop key="hibernate.cache.use_query_cache">${hibernate.cache.use_query_cache}</prop>
+ <prop key="hibernate.cache.use_second_level_cache">${hibernate.cache.use_second_level_cache}
+ </prop>
+ <prop key="hibernate.cache.provider_class">${hibernate.cache.provider}</prop>
+ <prop key="hibernate.cache.region.factory_class">${hibernate.cache.region.factory}</prop>
+ <!-- <prop key="net.sf.ehcache.configurationResourceName">classpath:ehcache.xml</prop> -->
+ </props>
+ </property>
+ </bean>
+
+ <tx:annotation-driven proxy-target-class="true"
+ transaction-manager="transactionManager" />
+ <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
+ <property name="entityManagerFactory" ref="entityManagerFactory" />
+ </bean>
+
+ <bean id="transactionTemplate"
+ class="org.springframework.transaction.support.TransactionTemplate">
+ <constructor-arg ref="transactionManager" />
+ </bean>
+
+ <bean id="resourceDao" class="de.ids_mannheim.korap.dao.ResourceDao">
+ </bean>
+
+ <bean id="kustvakt_auditing" class="de.ids_mannheim.korap.handlers.JDBCAuditing">
+ <constructor-arg ref="kustvakt_db" />
+ </bean>
+
+ <bean id="kustvakt_userdb" class="de.ids_mannheim.korap.handlers.EntityDao">
+ <constructor-arg ref="kustvakt_db" />
+ </bean>
+
+ <bean id="kustvakt_admindb" class="de.ids_mannheim.korap.handlers.AdminDao">
+ <constructor-arg ref="kustvakt_db" />
+ </bean>
+
+ <bean id="resource_provider" class="de.ids_mannheim.korap.handlers.ResourceDao">
+ <constructor-arg ref="kustvakt_db" />
+ </bean>
+
+ <bean id="document_provider" class="de.ids_mannheim.korap.handlers.DocumentDao">
+ <constructor-arg ref="kustvakt_db" />
+ </bean>
+
+ <bean id="kustvakt_policies" class="de.ids_mannheim.korap.security.ac.PolicyDao">
+ <constructor-arg ref="kustvakt_db" />
+ </bean>
+
+ <bean name="kustvakt_encryption"
+ class="de.ids_mannheim.korap.interfaces.defaults.KustvaktEncryption">
+ <constructor-arg ref="kustvakt_config" />
+ </bean>
+
+ <!-- authentication providers to use -->
+ <bean id="api_auth" class="de.ids_mannheim.korap.security.auth.APIAuthentication">
+ <constructor-arg type="de.ids_mannheim.korap.config.KustvaktConfiguration"
+ ref="kustvakt_config" />
+ </bean>
+
+ <bean id="openid_auth"
+ class="de.ids_mannheim.korap.security.auth.OpenIDconnectAuthentication">
+ <constructor-arg type="de.ids_mannheim.korap.config.KustvaktConfiguration"
+ ref="kustvakt_config" />
+ <constructor-arg
+ type="de.ids_mannheim.korap.interfaces.db.PersistenceClient" ref="kustvakt_db" />
+ </bean>
+
+ <bean id="basic_auth" class="de.ids_mannheim.korap.security.auth.BasicHttpAuth" />
- http://www.springframework.org/schema/util
- http://www.springframework.org/schema/util/spring-util-4.0.xsd">
+ <bean id="session_auth"
+ class="de.ids_mannheim.korap.security.auth.SessionAuthentication">
+ <constructor-arg type="de.ids_mannheim.korap.config.KustvaktConfiguration"
+ ref="kustvakt_config" />
+ <constructor-arg type="de.ids_mannheim.korap.interfaces.EncryptionIface"
+ ref="kustvakt_encryption" />
+ </bean>
- <bean id="props"
- class="org.springframework.beans.factory.config.PropertiesFactoryBean">
- <property name="ignoreResourceNotFound" value="true"/>
- <property name="locations">
- <array>
- <value>classpath:kustvakt.conf</value>
- <value>file:./kustvakt.conf</value>
- </array>
- </property>
- </bean>
-
- <bean id="jdbc_props"
- class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
- <property name="ignoreResourceNotFound" value="true"/>
- <property name="locations">
- <array>
- <value>classpath:jdbc.properties</value>
- <value>file:./jdbc.properties</value>
- </array>
- </property>
- </bean>
-
- <bean id='cacheManager'
- class='org.springframework.cache.ehcache.EhCacheCacheManager'
- p:cacheManager-ref='ehcache'/>
-
- <bean id='ehcache'
- class='org.springframework.cache.ehcache.EhCacheManagerFactoryBean'
- p:configLocation='classpath:ehcache.xml'
- p:shared='true'/>
-
- <!-- props are injected from default-config.xml -->
- <bean id="kustvakt_config"
- class="de.ids_mannheim.korap.config.KustvaktConfiguration">
- <property name="properties" ref="props"/>
- </bean>
-
- <!--class="org.apache.commons.dbcp2.BasicDataSource"-->
- <!-- org.springframework.jdbc.datasource.SingleConnectionDataSource -->
- <bean id="dataSource"
- class="org.apache.commons.dbcp2.BasicDataSource"
- lazy-init="true">
- <property name="driverClassName" value="${jdbc.driverClassName}"/>
- <property name="url" value="${jdbc.url}"/>
- <property name="username" value="${jdbc.username}"/>
- <property name="password" value="${jdbc.password}"/>
- <!-- relevant for single connection datasource and sqlite -->
- <!-- <property name="suppressClose">
- <value>true</value>
- </property> -->
- <!--<property name="initialSize" value="2"/>-->
- <property name="maxTotal" value="4"/>
- <property name="maxIdle" value="2"/>
- <property name="minIdle" value="1"/>
- <property name="maxWaitMillis" value="15000"/>
- <!--<property name="poolPreparedStatements" value="true"/>-->
- </bean>
-
- <bean id="sqliteDataSource"
- class="org.springframework.jdbc.datasource.SingleConnectionDataSource"
- lazy-init="true">
- <property name="driverClassName" value="${jdbc.driverClassName}"/>
- <property name="url" value="${jdbc.url}"/>
- <property name="username" value="${jdbc.username}"/>
- <property name="password" value="${jdbc.password}"/>
- <!-- relevant for single connection datasource and sqlite -->
- <property name="suppressClose">
- <value>true</value>
- </property>
- <!--<property name="initialSize" value="2"/>-->
- <!--<property name="poolPreparedStatements" value="true"/>-->
- </bean>
-
- <!-- to configure database for sqlite, mysql, etc. migrations -->
- <bean id="flyway" class="org.flywaydb.core.Flyway" init-method="migrate">
- <property name="baselineOnMigrate" value="false"/>
- <property name="locations"
- value="${jdbc.schemaPath}"/>
- <property name="dataSource" ref="sqliteDataSource"/>
- </bean>
-
- <bean id="kustvakt_db"
- class="de.ids_mannheim.korap.handlers.JDBCClient">
- <constructor-arg index="0" ref="dataSource"/>
- <!-- deprecated property -->
- <property name="database" value="${jdbc.database}"/>
- </bean>
-
- <bean id="kustvakt_auditing"
- class="de.ids_mannheim.korap.handlers.JDBCAuditing">
- <constructor-arg ref="kustvakt_db"/>
- </bean>
-
- <bean id="kustvakt_userdb"
- class="de.ids_mannheim.korap.handlers.EntityDao">
- <constructor-arg ref="kustvakt_db"/>
- </bean>
-
- <bean id="kustvakt_admindb"
- class="de.ids_mannheim.korap.handlers.AdminDao">
- <constructor-arg ref="kustvakt_db"/>
- </bean>
-
- <bean id="resource_provider"
- class="de.ids_mannheim.korap.handlers.ResourceDao">
- <constructor-arg ref="kustvakt_db"/>
- </bean>
-
- <bean id="document_provider"
- class="de.ids_mannheim.korap.handlers.DocumentDao">
- <constructor-arg ref="kustvakt_db"/>
- </bean>
-
- <bean id="kustvakt_policies"
- class="de.ids_mannheim.korap.security.ac.PolicyDao">
- <constructor-arg ref="kustvakt_db"/>
- </bean>
-
- <bean name="kustvakt_encryption"
- class="de.ids_mannheim.korap.interfaces.defaults.KustvaktEncryption">
- <constructor-arg ref="kustvakt_config"/>
- </bean>
-
- <!-- authentication providers to use -->
- <bean id="api_auth"
- class="de.ids_mannheim.korap.security.auth.APIAuthentication">
- <constructor-arg
- type="de.ids_mannheim.korap.config.KustvaktConfiguration"
- ref="kustvakt_config"/>
- </bean>
-
- <bean id="openid_auth"
- class="de.ids_mannheim.korap.security.auth.OpenIDconnectAuthentication">
- <constructor-arg
- type="de.ids_mannheim.korap.config.KustvaktConfiguration"
- ref="kustvakt_config"/>
- <constructor-arg
- type="de.ids_mannheim.korap.interfaces.db.PersistenceClient"
- ref="kustvakt_db"/>
- </bean>
-
- <bean id="basic_auth"
- class="de.ids_mannheim.korap.security.auth.BasicHttpAuth"/>
+ <util:list id="kustvakt_authproviders"
+ value-type="de.ids_mannheim.korap.interfaces.AuthenticationIface">
+ <ref bean="basic_auth" />
+ <ref bean="session_auth" />
+ <ref bean="api_auth" />
+ <ref bean="openid_auth" />
+ </util:list>
- <bean id="session_auth"
- class="de.ids_mannheim.korap.security.auth.SessionAuthentication">
- <constructor-arg
- type="de.ids_mannheim.korap.config.KustvaktConfiguration"
- ref="kustvakt_config"/>
- <constructor-arg
- type="de.ids_mannheim.korap.interfaces.EncryptionIface"
- ref="kustvakt_encryption"/>
- </bean>
+ <bean id="userdata_details" class="de.ids_mannheim.korap.handlers.UserDetailsDao">
+ <constructor-arg ref="kustvakt_db" />
+ </bean>
- <util:list id="kustvakt_authproviders"
- value-type="de.ids_mannheim.korap.interfaces.AuthenticationIface">
- <ref bean="basic_auth"/>
- <ref bean="session_auth"/>
- <ref bean="api_auth"/>
- <ref bean="openid_auth"/>
- </util:list>
+ <bean id="userdata_settings" class="de.ids_mannheim.korap.handlers.UserSettingsDao">
+ <constructor-arg ref="kustvakt_db" />
+ </bean>
+
+ <util:list id="kustvakt_userdata"
+ value-type="de.ids_mannheim.korap.interfaces.db.UserdataDbIface">
+ <ref bean="userdata_details" />
+ <ref bean="userdata_settings" />
+ </util:list>
- <bean id="userdata_details"
- class="de.ids_mannheim.korap.handlers.UserDetailsDao">
- <constructor-arg
- ref="kustvakt_db"/>
- </bean>
+ <util:list id="kustvakt_resources"
+ value-type="de.ids_mannheim.korap.interfaces.db.ResourceOperationIface">
+ <ref bean="document_provider" />
+ <ref bean="resource_provider" />
+ </util:list>
- <bean id="userdata_settings"
- class="de.ids_mannheim.korap.handlers.UserSettingsDao">
- <constructor-arg
- ref="kustvakt_db"/>
- </bean>
+ <!-- specify type for constructor argument -->
+ <bean id="kustvakt_authenticationmanager"
+ class="de.ids_mannheim.korap.security.auth.KustvaktAuthenticationManager">
+ <constructor-arg
+ type="de.ids_mannheim.korap.interfaces.db.EntityHandlerIface" ref="kustvakt_userdb" />
+ <constructor-arg
+ type="de.ids_mannheim.korap.interfaces.db.AdminHandlerIface" ref="kustvakt_admindb" />
+ <constructor-arg type="de.ids_mannheim.korap.interfaces.EncryptionIface"
+ ref="kustvakt_encryption" />
+ <constructor-arg ref="kustvakt_config" />
+ <constructor-arg type="de.ids_mannheim.korap.interfaces.db.AuditingIface"
+ ref="kustvakt_auditing" />
+ <constructor-arg ref="kustvakt_userdata" />
+ <!-- inject authentication providers to use -->
+ <property name="providers" ref="kustvakt_authproviders" />
+ </bean>
- <util:list id="kustvakt_userdata"
- value-type="de.ids_mannheim.korap.interfaces.db.UserdataDbIface">
- <ref bean="userdata_details"/>
- <ref bean="userdata_settings"/>
- </util:list>
+ <!-- todo: if db interfaces not loaded via spring, does transaction even
+ work then? -->
+ <!-- the transactional advice (i.e. what 'happens'; see the <aop:advisor/>
+ bean below) -->
+ <tx:advice id="txAdvice" transaction-manager="txManager">
+ <!-- the transactional semantics... -->
+ <tx:attributes>
+ <!-- all methods starting with 'get' are read-only -->
+ <tx:method name="get*" read-only="true" rollback-for="KorAPException" />
+ <!-- other methods use the default transaction settings (see below) -->
+ <tx:method name="*" rollback-for="KorAPException" />
+ </tx:attributes>
+ </tx:advice>
+ <!-- ensure that the above transactional advice runs for any execution of
+ an operation defined by the service interface -->
+ <aop:config>
+ <aop:pointcut id="service"
+ expression="execution(* de.ids_mannheim.korap.interfaces.db.*.*(..))" />
+ <aop:advisor advice-ref="txAdvice" pointcut-ref="service" />
+ </aop:config>
- <util:list id="kustvakt_resources"
- value-type="de.ids_mannheim.korap.interfaces.db.ResourceOperationIface">
- <ref bean="document_provider"/>
- <ref bean="resource_provider"/>
- </util:list>
-
- <!-- specify type for constructor argument -->
- <bean id="kustvakt_authenticationmanager"
- class="de.ids_mannheim.korap.security.auth.KustvaktAuthenticationManager">
- <constructor-arg
- type="de.ids_mannheim.korap.interfaces.db.EntityHandlerIface"
- ref="kustvakt_userdb"/>
- <constructor-arg
- type="de.ids_mannheim.korap.interfaces.db.AdminHandlerIface"
- ref="kustvakt_admindb"/>
- <constructor-arg type="de.ids_mannheim.korap.interfaces.EncryptionIface"
- ref="kustvakt_encryption"/>
- <constructor-arg ref="kustvakt_config"/>
- <constructor-arg
- type="de.ids_mannheim.korap.interfaces.db.AuditingIface"
- ref="kustvakt_auditing"/>
- <constructor-arg ref="kustvakt_userdata"/>
- <!-- inject authentication providers to use -->
- <property name="providers" ref="kustvakt_authproviders"/>
- </bean>
-
- <!-- todo: if db interfaces not loaded via spring, does transaction even work then? -->
- <!-- the transactional advice (i.e. what 'happens'; see the <aop:advisor/> bean below) -->
- <tx:advice id="txAdvice" transaction-manager="txManager">
- <!-- the transactional semantics... -->
- <tx:attributes>
- <!-- all methods starting with 'get' are read-only -->
- <tx:method name="get*" read-only="true"
- rollback-for="KorAPException"/>
- <!-- other methods use the default transaction settings (see below) -->
- <tx:method name="*" rollback-for="KorAPException"/>
- </tx:attributes>
- </tx:advice>
-
- <!-- ensure that the above transactional advice runs for any execution
- of an operation defined by the service interface -->
- <aop:config>
- <aop:pointcut id="service"
- expression="execution(* de.ids_mannheim.korap.interfaces.db.*.*(..))"/>
- <aop:advisor advice-ref="txAdvice" pointcut-ref="service"/>
- </aop:config>
-
- <!-- similarly, don't forget the PlatformTransactionManager -->
- <bean id="txManager"
- class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
- <property name="dataSource" ref="dataSource"/>
- </bean>
+ <!-- similarly, don't forget the PlatformTransactionManager -->
+ <bean id="txManager"
+ class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
+ <property name="dataSource" ref="dataSource" />
+ </bean>
</beans>
\ No newline at end of file
diff --git a/src/main/resources/hibernate.properties b/src/main/resources/hibernate.properties
new file mode 100644
index 0000000..fa35ac7
--- /dev/null
+++ b/src/main/resources/hibernate.properties
@@ -0,0 +1,7 @@
+hibernate.dialect=org.hibernate.dialect.MySQLDialect
+hibernate.hbm2ddl.auto=create-drop
+hibernate.show_sql=true
+hibernate.cache.use_query_cache=false
+hibernate.cache.use_second_level_cache=false
+hibernate.cache.provider=org.hibernate.cache.EhCacheProvider
+hibernate.cache.region.factory=org.hibernate.cache.ehcache.EhCacheRegionFactory
\ No newline at end of file