Skip to content
This repository has been archived by the owner on Dec 15, 2021. It is now read-only.

Commit

Permalink
Using HSQL integrated db
Browse files Browse the repository at this point in the history
  • Loading branch information
Alessandro Polverini committed Feb 10, 2014
1 parent da6634b commit ae4b429
Show file tree
Hide file tree
Showing 5 changed files with 153 additions and 146 deletions.
6 changes: 3 additions & 3 deletions SPR-11406/nbactions.xml
Expand Up @@ -12,7 +12,7 @@
</goals>
<properties>
<netbeans.deploy>true</netbeans.deploy>
<netbeans.deploy.clientUrlPart>/adm/info</netbeans.deploy.clientUrlPart>
<netbeans.deploy.clientUrlPart>/newUser/test</netbeans.deploy.clientUrlPart>
</properties>
</action>
<action>
Expand All @@ -28,7 +28,7 @@
<properties>
<netbeans.deploy.debugmode>true</netbeans.deploy.debugmode>
<netbeans.deploy>true</netbeans.deploy>
<netbeans.deploy.clientUrlPart>/adm/info</netbeans.deploy.clientUrlPart>
<netbeans.deploy.clientUrlPart>/newUser/test</netbeans.deploy.clientUrlPart>
</properties>
</action>
<action>
Expand All @@ -44,7 +44,7 @@
<properties>
<netbeans.deploy>true</netbeans.deploy>
<netbeans.deploy.profilemode>true</netbeans.deploy.profilemode>
<netbeans.deploy.clientUrlPart>/adm/info</netbeans.deploy.clientUrlPart>
<netbeans.deploy.clientUrlPart>/newUser/test</netbeans.deploy.clientUrlPart>
</properties>
</action>
</actions>
242 changes: 124 additions & 118 deletions SPR-11406/pom.xml
@@ -1,128 +1,134 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<name>SPR-11406</name>
<groupId>it.nibbles</groupId>
<artifactId>SPR-11406</artifactId>
<packaging>war</packaging>
<version>0.1-wip</version>
<url>http://maven.apache.org</url>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<spring.version>4.0.1.RELEASE</spring.version>
<slf4j.version>1.7.5</slf4j.version>
</properties>

<dependencies>

<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<version>${slf4j.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>${slf4j.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>

<!-- Spring -->

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${spring.version}</version>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>${spring.version}</version>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>${spring.version}</version>
</dependency>
<modelVersion>4.0.0</modelVersion>
<name>SPR-11406</name>
<groupId>it.nibbles</groupId>
<artifactId>SPR-11406</artifactId>
<packaging>war</packaging>
<version>0.1-wip</version>
<url>http://maven.apache.org</url>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<spring.version>4.0.1.RELEASE</spring.version>
<slf4j.version>1.7.5</slf4j.version>
</properties>

<dependencies>

<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<version>${slf4j.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>${slf4j.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>

<!-- Spring -->

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${spring.version}</version>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>${spring.version}</version>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>${spring.version}</version>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>${spring.version}</version>
</dependency>

<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<version>1.4.3.RELEASE</version>
</dependency>

<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>4.3.0.Final</version>
</dependency>

</dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>${spring.version}</version>
</dependency>

<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<version>1.4.3.RELEASE</version>
</dependency>

<dependency>
<groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<version>2.3.1</version>
</dependency>

<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>4.3.0.Final</version>
</dependency>

</dependencies>


<build>
<build>

<plugins>
<plugins>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<showDeprecation>true</showDeprecation>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<showDeprecation>true</showDeprecation>
</configuration>
</plugin>

</plugins>
<finalName>SPR-11406</finalName>
</build>
</plugins>
<finalName>SPR-11406</finalName>
</build>

</project>
6 changes: 5 additions & 1 deletion SPR-11406/src/main/java/it/nibbles/test/objs/User.java
@@ -1,5 +1,6 @@
package it.nibbles.test.objs;

import java.util.Random;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
Expand All @@ -14,13 +15,16 @@ public class User {
public static final int STR_LEN = 64;

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private Integer id;

@Column(name = "username", nullable = false)
private String name;

public User() {
setId(new Random().nextInt());
}

public Integer getId() {
return id;
}
Expand Down
7 changes: 7 additions & 0 deletions SPR-11406/src/main/resources/schema.sql
@@ -0,0 +1,7 @@
-- For HSQL
CREATE TABLE UserTest(id int, username varchar(100), PRIMARY KEY (id));
--ALTER TABLE User ALTER COLUMN id
-- SET GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1);

-- For Mysql
-- CREATE TABLE UserTest(id int AUTO_INCREMENT, username varchar(100), PRIMARY KEY (id));
38 changes: 14 additions & 24 deletions SPR-11406/src/main/webapp/WEB-INF/applicationContext.xml
Expand Up @@ -8,42 +8,32 @@
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:jpa="http://www.springframework.org/schema/data/jpa"
xmlns:jdbc="http://www.springframework.org/schema/jdbc"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd
http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd
">

<context:annotation-config />
<context:component-scan base-package="it.nibbles.test"/>

<!--
// Create this table on the "test" with this statement:
<jdbc:embedded-database id="dataSource" type="HSQL">
<jdbc:script location="classpath:schema.sql" encoding="UTF-8" />
</jdbc:embedded-database>

CREATE TABLE UserTest (
id int(11) NOT NULL AUTO_INCREMENT,
username varchar(64) NOT NULL,
PRIMARY KEY (id),
UNIQUE KEY username (username)
)
-->
<bean name="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost:3306/test" />
<property name="username" value="test" />
<property name="password" value="test" />
</bean>

<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="showSql" value="false" />
<property name="generateDdl" value="false" />
<property name="generateDdl" value="true" />
<property name="databasePlatform" value="org.hibernate.dialect.MySQL5InnoDBDialect" />
<property name="database" value="HSQL" />
</bean>
</property>
<property name="packagesToScan">
Expand All @@ -59,6 +49,6 @@

<tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="false" />
<jpa:repositories base-package="it.nibbles.test.dao"
entity-manager-factory-ref="entityManagerFactory" transaction-manager-ref="transactionManager"/>
entity-manager-factory-ref="entityManagerFactory" transaction-manager-ref="transactionManager"/>

</beans>

0 comments on commit ae4b429

Please sign in to comment.