Skip to content

Commit

Permalink
Draft Hibernate integration. Not used yet (one new repository comment…
Browse files Browse the repository at this point in the history
…ed).
  • Loading branch information
clacote committed Jul 22, 2011
1 parent 291c3a3 commit a6ffe66
Show file tree
Hide file tree
Showing 6 changed files with 121 additions and 19 deletions.
39 changes: 35 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@
<version>${spring.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>${spring.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
Expand Down Expand Up @@ -103,17 +109,42 @@
<version>4.7</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.8.5</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache-core</artifactId>
<version>2.4.1</version>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>${hibernate.version}</version>
</dependency>
<!-- Hibernate uses slf4j for logging, for our purposes here use the simple backend -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.6.1</version>
</dependency>
<!-- Hibernate gives you a choice of bytecode providers between cglib and javassist -->
<dependency>
<groupId>javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.12.1.GA</version>
</dependency>

<dependency>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache-core</artifactId>
<version>2.4.1</version>
</dependency>

</dependencies>

<properties>
<spring.version>3.1.0.M2</spring.version>
<spring.version>3.1.0.M2</spring.version>
<hibernate.version>3.6.6.Final</hibernate.version>
<project.build.sourceEncoding>UTF8</project.build.sourceEncoding>
</properties>
</project>
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
package com.programmez.samples.gigreservation.domain;

import javax.persistence.Basic;
import javax.persistence.Entity;
import javax.persistence.Id;

/**
* Ticketing
* @author agnes007
*/
@Entity
public class Ticketing {

@Id
private Long id;
@Basic
private Long nbTickets;
@Basic
private String band;

public Ticketing() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.programmez.samples.gigreservation.repository.internal;

import com.programmez.samples.gigreservation.domain.Ticketing;
import com.programmez.samples.gigreservation.repository.TicketingRepository;
import java.util.List;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

/**
*
* @author Sryl <[email protected]>
*/
// @Repository("hibernate")
public class HibernateTicketingRepository implements TicketingRepository {

@Autowired
private SessionFactory sessionFactory;

@Override
public Ticketing findById(Long ticketingId) {
return (Ticketing) sessionFactory.getCurrentSession().get(Ticketing.class, ticketingId);
}

@Override
public void updateNbTickets(Ticketing ticketing) {
throw new UnsupportedOperationException("Not supported yet.");
}

@Override
public List<Ticketing> findByBand(String ticketingBand, boolean audit) {
throw new UnsupportedOperationException("Not supported yet.");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*
* @author agnes007
*/
@Repository
@Repository("jdbcTicketingRepository")
public class JdbcTicketingRepository implements TicketingRepository {

private JdbcTemplate jdbcTemplate;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,28 @@
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd">

<context:component-scan base-package="com.programmez.samples.gigreservation.service"/>
<context:component-scan base-package="com.programmez.samples.gigreservation.repository"/>
<context:component-scan base-package="com.programmez.samples.gigreservation.service"/>
<context:component-scan base-package="com.programmez.samples.gigreservation.repository"/>

<context:annotation-config/>
<context:annotation-config/>

<beans profile="dev">
<jdbc:embedded-database id="dataSource" type="H2">
<jdbc:script location="classpath:com/programmez/samples/gigreservation/config/sql/schema.sql"/>
<jdbc:script location="classpath:com/programmez/samples/gigreservation/config/sql/test-data.sql"/>
</jdbc:embedded-database>
</beans>

<beans profile="production">
<jee:jndi-lookup id="dataSource" jndi-name="java:comp/env/jdbc/datasource"/>
</beans>

<beans profile="dev">
<jdbc:embedded-database id="dataSource" type="H2">
<jdbc:script location="classpath:com/programmez/samples/gigreservation/config/sql/schema.sql"/>
<jdbc:script location="classpath:com/programmez/samples/gigreservation/config/sql/test-data.sql"/>
</jdbc:embedded-database>

<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
</bean>
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>

</beans>

<beans profile="production">
<jee:jndi-lookup id="dataSource" jndi-name="java:comp/env/jdbc/datasource"/>
</beans>

</beans>
18 changes: 18 additions & 0 deletions src/main/resources/hibernate.cfg.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?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>
<!-- Database connection settings -->
<property name="connection.driver_class">org.h2.Driver</property>
<property name="connection.url">jdbc:h2://localhost</property>
<!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">1</property> <!-- SQL dialect -->
<property name="dialect">org.hibernate.dialect.H2Dialect</property> <!-- Enable Hibernate's automatic session context management -->
<property name="current_session_context_class">thread</property> <!-- Disable the second-level cache -->
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property> <!-- Echo all executed SQL to stdout -->
<property name="show_sql">true</property>
<!-- Drop and re-create the database schema on startup -->
<property name="hbm2ddl.auto">update</property>
</session-factory>
</hibernate-configuration>

0 comments on commit a6ffe66

Please sign in to comment.