[hibernate-commits] Hibernate SVN: r17665 - in sandbox/trunk: lobtest-ee5 and 33 other directories.
hibernate-commits at lists.jboss.org
hibernate-commits at lists.jboss.org
Thu Oct 8 22:56:58 EDT 2009
Author: cbredesen
Date: 2009-10-08 22:56:57 -0400 (Thu, 08 Oct 2009)
New Revision: 17665
Added:
sandbox/trunk/lobtest-ee5/
sandbox/trunk/lobtest-ee5/lobtest-ear/
sandbox/trunk/lobtest-ee5/lobtest-ear/pom.xml
sandbox/trunk/lobtest-ee5/lobtest-ear/src/
sandbox/trunk/lobtest-ee5/lobtest-ear/src/main/
sandbox/trunk/lobtest-ee5/lobtest-ear/src/main/application/
sandbox/trunk/lobtest-ee5/lobtest-ear/src/main/application/META-INF/
sandbox/trunk/lobtest-ee5/lobtest-ear/src/main/application/META-INF/application.xml
sandbox/trunk/lobtest-ee5/lobtest-ejb/
sandbox/trunk/lobtest-ee5/lobtest-ejb/java/
sandbox/trunk/lobtest-ee5/lobtest-ejb/java/com/
sandbox/trunk/lobtest-ee5/lobtest-ejb/java/com/redhat/
sandbox/trunk/lobtest-ee5/lobtest-ejb/java/com/redhat/gss/
sandbox/trunk/lobtest-ee5/lobtest-ejb/java/com/redhat/gss/lobtest/
sandbox/trunk/lobtest-ee5/lobtest-ejb/java/com/redhat/gss/lobtest/jpa/
sandbox/trunk/lobtest-ee5/lobtest-ejb/java/com/redhat/gss/lobtest/jpa/LobTest.java
sandbox/trunk/lobtest-ee5/lobtest-ejb/lobtestdb-ds.xml
sandbox/trunk/lobtest-ee5/lobtest-ejb/pom.xml
sandbox/trunk/lobtest-ee5/lobtest-ejb/src/
sandbox/trunk/lobtest-ee5/lobtest-ejb/src/main/
sandbox/trunk/lobtest-ee5/lobtest-ejb/src/main/java/
sandbox/trunk/lobtest-ee5/lobtest-ejb/src/main/java/com/
sandbox/trunk/lobtest-ee5/lobtest-ejb/src/main/java/com/redhat/
sandbox/trunk/lobtest-ee5/lobtest-ejb/src/main/java/com/redhat/gss/
sandbox/trunk/lobtest-ee5/lobtest-ejb/src/main/java/com/redhat/gss/lobtest/
sandbox/trunk/lobtest-ee5/lobtest-ejb/src/main/java/com/redhat/gss/lobtest/ejb/
sandbox/trunk/lobtest-ee5/lobtest-ejb/src/main/java/com/redhat/gss/lobtest/ejb/LobTestService.java
sandbox/trunk/lobtest-ee5/lobtest-ejb/src/main/java/com/redhat/gss/lobtest/ejb/LobTestServiceBean.java
sandbox/trunk/lobtest-ee5/lobtest-ejb/src/main/java/com/redhat/gss/lobtest/ejb/ThingService.java
sandbox/trunk/lobtest-ee5/lobtest-ejb/src/main/java/com/redhat/gss/lobtest/ejb/ThingServiceBean.java
sandbox/trunk/lobtest-ee5/lobtest-ejb/src/main/java/com/redhat/gss/lobtest/hibernate/
sandbox/trunk/lobtest-ee5/lobtest-ejb/src/main/java/com/redhat/gss/lobtest/hibernate/HibernateUtil.java
sandbox/trunk/lobtest-ee5/lobtest-ejb/src/main/java/com/redhat/gss/lobtest/jpa/
sandbox/trunk/lobtest-ee5/lobtest-ejb/src/main/java/com/redhat/gss/lobtest/jpa/Image.java
sandbox/trunk/lobtest-ee5/lobtest-ejb/src/main/java/com/redhat/gss/lobtest/jpa/Item.java
sandbox/trunk/lobtest-ee5/lobtest-ejb/src/main/java/com/redhat/gss/lobtest/jpa/Thing.java
sandbox/trunk/lobtest-ee5/lobtest-ejb/src/main/resources/
sandbox/trunk/lobtest-ee5/lobtest-ejb/src/main/resources/META-INF/
sandbox/trunk/lobtest-ee5/lobtest-ejb/src/main/resources/META-INF/MANIFEST.MF
sandbox/trunk/lobtest-ee5/lobtest-ejb/src/main/resources/META-INF/persistence.xml
sandbox/trunk/lobtest-ee5/lobtest-ejb/src/main/resources/hibernate.cfg.xml
sandbox/trunk/lobtest-ee5/lobtest-ejb/src/test/
sandbox/trunk/lobtest-ee5/lobtest-ejb/src/test/resources/
sandbox/trunk/lobtest-ee5/lobtest-ejb/src/test/resources/META-INF/
sandbox/trunk/lobtest-ee5/lobtest-ejb/src/test/resources/META-INF/persistence.xml
sandbox/trunk/lobtest-ee5/lobtest-web/
sandbox/trunk/lobtest-ee5/lobtest-web/pom.xml
sandbox/trunk/lobtest-ee5/lobtest-web/src/
sandbox/trunk/lobtest-ee5/lobtest-web/src/main/
sandbox/trunk/lobtest-ee5/lobtest-web/src/main/webapp/
sandbox/trunk/lobtest-ee5/lobtest-web/src/main/webapp/META-INF/
sandbox/trunk/lobtest-ee5/lobtest-web/src/main/webapp/META-INF/MANIFEST.MF
sandbox/trunk/lobtest-ee5/lobtest-web/src/main/webapp/WEB-INF/
sandbox/trunk/lobtest-ee5/lobtest-web/src/main/webapp/WEB-INF/lib/
sandbox/trunk/lobtest-ee5/lobtest-web/src/main/webapp/WEB-INF/web.xml
sandbox/trunk/lobtest-ee5/lobtest-web/src/main/webapp/basic.jsp
sandbox/trunk/lobtest-ee5/lobtest-web/src/main/webapp/index.html
sandbox/trunk/lobtest-ee5/lobtest-web/src/main/webapp/lob.jsp
sandbox/trunk/lobtest-ee5/pom.xml
Log:
Initial import for testing CGLIB in-container
Added: sandbox/trunk/lobtest-ee5/lobtest-ear/pom.xml
===================================================================
--- sandbox/trunk/lobtest-ee5/lobtest-ear/pom.xml (rev 0)
+++ sandbox/trunk/lobtest-ee5/lobtest-ear/pom.xml 2009-10-09 02:56:57 UTC (rev 17665)
@@ -0,0 +1,86 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<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">
+ <parent>
+ <artifactId>lobtest-ee5</artifactId>
+ <groupId>gss</groupId>
+ <version>1.0-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>lobtest-ear</artifactId>
+ <packaging>ear</packaging>
+ <name>LOB Test EAR</name>
+ <build>
+ <finalName>lobtest</finalName>
+ <plugins>
+ <plugin>
+ <artifactId>maven-ear-plugin</artifactId>
+ <configuration>
+ <modules>
+ <ejbModule>
+ <groupId>${parent.groupId}</groupId>
+ <artifactId>lobtest-ejb</artifactId>
+ </ejbModule>
+ <webModule>
+ <groupId>${parent.groupId}</groupId>
+ <artifactId>lobtest-web</artifactId>
+ </webModule>
+ </modules>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ <dependencies>
+ <!-- EAR modules need to be listed as dependencies -->
+ <dependency>
+ <groupId>${parent.groupId}</groupId>
+ <artifactId>lobtest-ejb</artifactId>
+ <version>${parent.version}</version>
+ <type>ejb</type>
+ </dependency>
+ <dependency>
+ <groupId>${parent.groupId}</groupId>
+ <artifactId>lobtest-web</artifactId>
+ <version>${parent.version}</version>
+ <type>war</type>
+ </dependency>
+
+ <!-- These modules are re-listed here to they can be excluded from the EAR -->
+ <dependency>
+ <groupId>javax.persistence</groupId>
+ <artifactId>persistence-api</artifactId>
+ <version>1.0</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.hibernate</groupId>
+ <artifactId>hibernate</artifactId>
+ <version>3.2.4.sp1</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.hibernate</groupId>
+ <artifactId>hibernate-annotations</artifactId>
+ <version>3.2.1.ga</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.hibernate</groupId>
+ <artifactId>hibernate-entitymanager</artifactId>
+ <version>3.2.1.ga</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>geronimo-spec</groupId>
+ <artifactId>geronimo-spec-jta</artifactId>
+ <version>1.0.1B-rc4</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.ejb</groupId>
+ <artifactId>ejb-api</artifactId>
+ <version>3.0</version>
+ <scope>provided</scope>
+ </dependency>
+ </dependencies>
+</project>
Added: sandbox/trunk/lobtest-ee5/lobtest-ear/src/main/application/META-INF/application.xml
===================================================================
--- sandbox/trunk/lobtest-ee5/lobtest-ear/src/main/application/META-INF/application.xml (rev 0)
+++ sandbox/trunk/lobtest-ee5/lobtest-ear/src/main/application/META-INF/application.xml 2009-10-09 02:56:57 UTC (rev 17665)
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE application PUBLIC "-//Sun Microsystems, Inc.//DTD J2EE Application 1.3//EN" "http://java.sun.com/dtd/application_1_3.dtd">
+<application id="Application_ID">
+ <display-name>lobtest-ear</display-name>
+ <module id="EjbModule_1255048702485">
+ <ejb>lobtest-ejb-1.0-SNAPSHOT.jar</ejb>
+ </module>
+ <module id="WebModule_1255048702585">
+ <web>
+ <web-uri>lobtest-web-1.0-SNAPSHOT.war</web-uri>
+ <context-root>lobtest-web</context-root>
+ </web>
+ </module>
+</application>
Added: sandbox/trunk/lobtest-ee5/lobtest-ejb/java/com/redhat/gss/lobtest/jpa/LobTest.java
===================================================================
--- sandbox/trunk/lobtest-ee5/lobtest-ejb/java/com/redhat/gss/lobtest/jpa/LobTest.java (rev 0)
+++ sandbox/trunk/lobtest-ee5/lobtest-ejb/java/com/redhat/gss/lobtest/jpa/LobTest.java 2009-10-09 02:56:57 UTC (rev 17665)
@@ -0,0 +1,94 @@
+package com.redhat.gss.lobtest.jpa;
+
+import java.io.IOException;
+import java.io.Reader;
+import java.sql.Blob;
+import java.sql.Clob;
+import java.sql.SQLException;
+
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.Persistence;
+
+import junit.framework.TestCase;
+
+import org.hibernate.Hibernate;
+
+public class LobTest extends TestCase {
+ private EntityManagerFactory emf = Persistence.createEntityManagerFactory("lobtest");
+ private static final long ID = 1l;
+ private static final String DESCRIPTION = "Long description requiring more space than I have time to consume.";
+ private static final byte[] IMAGE_DATA = { 'E', 'A', 'D', 'G', 'B', 'E' };
+
+ public void testClob() throws Exception {
+
+ // transaction 1
+ EntityManager em = this.emf.createEntityManager();
+ em.getTransaction().begin();
+ Clob description = Hibernate.createClob(DESCRIPTION);
+ Item item = new Item(ID);
+ item.setName("item");
+ item.setDescription(description);
+ em.persist(item);
+ em.getTransaction().commit();
+ em.close();
+
+ // transaction 2
+ em = this.emf.createEntityManager();
+ em.getTransaction().begin();
+ Item actualItem = em.find(Item.class, ID);
+ String actualDescription = readClob(actualItem.getDescription());
+ assertEquals(DESCRIPTION, actualDescription);
+ em.remove(actualItem);
+ em.getTransaction().commit();
+ em.close();
+
+ }
+
+ public void testBlob() throws Exception {
+
+ // transaction 1
+ EntityManager em = this.emf.createEntityManager();
+ em.getTransaction().begin();
+ Blob imageData = Hibernate.createBlob(IMAGE_DATA);
+ Image image = new Image(ID);
+ image.setName("item");
+ image.setImageData(imageData);
+ em.persist(image);
+ em.getTransaction().commit();
+ em.close();
+
+ // transaction 2
+ em = this.emf.createEntityManager();
+ em.getTransaction().begin();
+ Image actualImage = em.find(Image.class, ID);
+ byte[] actualImageData = readBlob(actualImage.getImageData());
+ assertEquals(IMAGE_DATA, actualImageData);
+ em.remove(actualImage);
+ em.getTransaction().commit();
+ em.close();
+
+ }
+
+ private String readClob(Clob clob) throws SQLException, IOException {
+ Reader stream = clob.getCharacterStream();
+ StringBuffer sb = new StringBuffer();
+ int count = 0;
+ char[] buffer = new char[10];
+ while ((count = stream.read(buffer)) != -1)
+ sb.append(buffer, 0, count);
+ stream.close();
+ return sb.toString();
+ }
+
+ private byte[] readBlob(Blob blob) throws SQLException, IOException {
+ return blob.getBytes(1, (int) blob.length());
+ }
+
+ private void assertEquals(byte[] expected, byte[] actual) {
+ if (expected.length != actual.length) fail("byte arrays were not of the same length.");
+ for (int i = 0; i < expected.length; i++) {
+ assertEquals(expected[i], actual[i]);
+ }
+ }
+}
\ No newline at end of file
Added: sandbox/trunk/lobtest-ee5/lobtest-ejb/lobtestdb-ds.xml
===================================================================
--- sandbox/trunk/lobtest-ee5/lobtest-ejb/lobtestdb-ds.xml (rev 0)
+++ sandbox/trunk/lobtest-ee5/lobtest-ejb/lobtestdb-ds.xml 2009-10-09 02:56:57 UTC (rev 17665)
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<datasources>
+ <local-tx-datasource>
+ <jndi-name>LobTestDS</jndi-name>
+ <connection-url>jdbc:hsqldb:mem:lobtest</connection-url>
+ <driver-class>org.hsqldb.jdbcDriver</driver-class>
+ <user-name>sa</user-name>
+ <password></password>
+ <min-pool-size>5</min-pool-size>
+ <max-pool-size>20</max-pool-size>
+ <idle-timeout-minutes>0</idle-timeout-minutes>
+ <track-statements/>
+ <prepared-statement-cache-size>32</prepared-statement-cache-size>
+ </local-tx-datasource>
+</datasources>
Added: sandbox/trunk/lobtest-ee5/lobtest-ejb/pom.xml
===================================================================
--- sandbox/trunk/lobtest-ee5/lobtest-ejb/pom.xml (rev 0)
+++ sandbox/trunk/lobtest-ee5/lobtest-ejb/pom.xml 2009-10-09 02:56:57 UTC (rev 17665)
@@ -0,0 +1,74 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<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">
+ <parent>
+ <artifactId>lobtest-ee5</artifactId>
+ <groupId>gss</groupId>
+ <version>1.0-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>lobtest-ejb</artifactId>
+ <packaging>ejb</packaging>
+ <name>LOB Test EJB</name>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-ejb-plugin</artifactId>
+ <configuration>
+ <ejbVersion>3.0</ejbVersion>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ <dependencies>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>3.8.1</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.persistence</groupId>
+ <artifactId>persistence-api</artifactId>
+ <version>1.0</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.hibernate</groupId>
+ <artifactId>hibernate</artifactId>
+ <version>3.2.4.sp1</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.hibernate</groupId>
+ <artifactId>hibernate-annotations</artifactId>
+ <version>3.2.1.ga</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.hibernate</groupId>
+ <artifactId>hibernate-entitymanager</artifactId>
+ <version>3.2.1.ga</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>geronimo-spec</groupId>
+ <artifactId>geronimo-spec-jta</artifactId>
+ <version>1.0.1B-rc4</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>hsqldb</groupId>
+ <artifactId>hsqldb</artifactId>
+ <version>1.8.0.7</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.ejb</groupId>
+ <artifactId>ejb-api</artifactId>
+ <version>3.0</version>
+ <scope>provided</scope>
+ </dependency>
+ </dependencies>
+</project>
\ No newline at end of file
Added: sandbox/trunk/lobtest-ee5/lobtest-ejb/src/main/java/com/redhat/gss/lobtest/ejb/LobTestService.java
===================================================================
--- sandbox/trunk/lobtest-ee5/lobtest-ejb/src/main/java/com/redhat/gss/lobtest/ejb/LobTestService.java (rev 0)
+++ sandbox/trunk/lobtest-ee5/lobtest-ejb/src/main/java/com/redhat/gss/lobtest/ejb/LobTestService.java 2009-10-09 02:56:57 UTC (rev 17665)
@@ -0,0 +1,15 @@
+package com.redhat.gss.lobtest.ejb;
+
+public interface LobTestService {
+
+ void runTests();
+
+ long writeClob(long id, String s);
+
+ String readClob(long id);
+
+ long writeBlob(long id, byte[] data);
+
+ byte[] readBlob(long id);
+
+}
Added: sandbox/trunk/lobtest-ee5/lobtest-ejb/src/main/java/com/redhat/gss/lobtest/ejb/LobTestServiceBean.java
===================================================================
--- sandbox/trunk/lobtest-ee5/lobtest-ejb/src/main/java/com/redhat/gss/lobtest/ejb/LobTestServiceBean.java (rev 0)
+++ sandbox/trunk/lobtest-ee5/lobtest-ejb/src/main/java/com/redhat/gss/lobtest/ejb/LobTestServiceBean.java 2009-10-09 02:56:57 UTC (rev 17665)
@@ -0,0 +1,108 @@
+package com.redhat.gss.lobtest.ejb;
+
+import java.io.IOException;
+import java.io.Reader;
+import java.sql.Blob;
+import java.sql.Clob;
+import java.sql.SQLException;
+
+import javax.ejb.Stateless;
+import javax.ejb.TransactionAttribute;
+import javax.ejb.TransactionAttributeType;
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+
+import org.hibernate.Hibernate;
+
+import com.redhat.gss.lobtest.jpa.Image;
+import com.redhat.gss.lobtest.jpa.Item;
+
+ at Stateless
+ at TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
+public class LobTestServiceBean implements LobTestService {
+ private static final long ID = 1l;
+ private static final String DESCRIPTION = "Long description requiring more space than I have time to consume.";
+ private static final byte[] IMAGE_DATA = { 'E', 'A', 'D', 'G', 'B', 'E' };
+
+ @PersistenceContext(name="lobtest-jpa") private EntityManager em;
+
+ public void runTests() {
+ // CLOB
+ writeClob(ID, DESCRIPTION);
+ String actualDescription = readClob(ID);
+ if (!DESCRIPTION.equals(actualDescription)) {
+ throw new RuntimeException("CLOB data did not match. Actual: " + actualDescription);
+ }
+
+ // BLOB
+ writeBlob(ID, IMAGE_DATA);
+ byte[] actualImageData = readBlob(ID);
+ assertEquals(IMAGE_DATA, actualImageData);
+ }
+
+ public long writeClob(long id, String s) {
+ Clob description = Hibernate.createClob(s);
+ Item item = new Item(id);
+ item.setName("item");
+ item.setDescription(description);
+ em.persist(item);
+ return item.getId();
+ }
+
+ public String readClob(long id) {
+ Item actualItem = em.find(Item.class, id);
+ String actualDescription;
+ try {
+ actualDescription = readClobData(actualItem.getDescription());
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ em.remove(actualItem);
+ return actualDescription;
+ }
+
+
+ public long writeBlob(long id, byte[] data) {
+ Blob imageData = Hibernate.createBlob(data);
+ Image image = new Image(id);
+ image.setName("item");
+ image.setImageData(imageData);
+ em.persist(image);
+ return image.getId();
+ }
+
+ public byte[] readBlob(long id) {
+ Image actualImage = em.find(Image.class, id);
+ byte[] actualImageData;
+ try {
+ actualImageData = readBlobData(actualImage.getImageData());
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ em.remove(actualImage);
+ return actualImageData;
+ }
+
+ private String readClobData(Clob clob) throws SQLException, IOException {
+ Reader stream = clob.getCharacterStream();
+ StringBuffer sb = new StringBuffer();
+ int count = 0;
+ char[] buffer = new char[10];
+ while ((count = stream.read(buffer)) != -1)
+ sb.append(buffer, 0, count);
+ stream.close();
+ return sb.toString();
+ }
+
+ private byte[] readBlobData(Blob blob) throws SQLException, IOException {
+ return blob.getBytes(1, (int) blob.length());
+ }
+
+ private void assertEquals(byte[] expected, byte[] actual) {
+ if (expected.length != actual.length) throw new RuntimeException("byte arrays were not of the same length.");
+ for (int i = 0; i < expected.length; i++) {
+ if (actual[i] != expected[i]) throw new RuntimeException("byte arrays were not equivalent.");
+ }
+ }
+
+}
\ No newline at end of file
Added: sandbox/trunk/lobtest-ee5/lobtest-ejb/src/main/java/com/redhat/gss/lobtest/ejb/ThingService.java
===================================================================
--- sandbox/trunk/lobtest-ee5/lobtest-ejb/src/main/java/com/redhat/gss/lobtest/ejb/ThingService.java (rev 0)
+++ sandbox/trunk/lobtest-ee5/lobtest-ejb/src/main/java/com/redhat/gss/lobtest/ejb/ThingService.java 2009-10-09 02:56:57 UTC (rev 17665)
@@ -0,0 +1,19 @@
+package com.redhat.gss.lobtest.ejb;
+
+import java.util.List;
+
+import com.redhat.gss.lobtest.jpa.Thing;
+
+public interface ThingService {
+
+ public void setUp();
+
+ public List<Thing> findAllThingsHibernate();
+
+ public Thing findThingHibernate(Long id);
+
+ public List<Thing> findAllThingsJPA();
+
+ public Thing findThingJPA(Long id);
+
+}
Added: sandbox/trunk/lobtest-ee5/lobtest-ejb/src/main/java/com/redhat/gss/lobtest/ejb/ThingServiceBean.java
===================================================================
--- sandbox/trunk/lobtest-ee5/lobtest-ejb/src/main/java/com/redhat/gss/lobtest/ejb/ThingServiceBean.java (rev 0)
+++ sandbox/trunk/lobtest-ee5/lobtest-ejb/src/main/java/com/redhat/gss/lobtest/ejb/ThingServiceBean.java 2009-10-09 02:56:57 UTC (rev 17665)
@@ -0,0 +1,44 @@
+package com.redhat.gss.lobtest.ejb;
+
+import java.util.List;
+
+import javax.ejb.Stateless;
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+
+import org.hibernate.Session;
+
+import com.redhat.gss.lobtest.hibernate.HibernateUtil;
+import com.redhat.gss.lobtest.jpa.Thing;
+
+ at Stateless
+public class ThingServiceBean implements ThingService {
+
+ @PersistenceContext private EntityManager em;
+
+ @SuppressWarnings("unchecked")
+ public List<Thing> findAllThingsHibernate() {
+ Session s = HibernateUtil.getSession();
+ return s.createQuery("from Thing").list();
+ }
+
+ @SuppressWarnings("unchecked")
+ public List<Thing> findAllThingsJPA() {
+ return em.createQuery("from Thing").getResultList();
+ }
+
+ public Thing findThingHibernate(Long id) {
+ Session s = HibernateUtil.getSession();
+ return (Thing) s.load(Thing.class, id);
+ }
+
+ public Thing findThingJPA(Long id) {
+ return em.getReference(Thing.class, id);
+ }
+
+ public void setUp() {
+ Thing t1 = new Thing(System.currentTimeMillis(), "One");
+ em.persist(t1);
+ }
+
+}
Added: sandbox/trunk/lobtest-ee5/lobtest-ejb/src/main/java/com/redhat/gss/lobtest/hibernate/HibernateUtil.java
===================================================================
--- sandbox/trunk/lobtest-ee5/lobtest-ejb/src/main/java/com/redhat/gss/lobtest/hibernate/HibernateUtil.java (rev 0)
+++ sandbox/trunk/lobtest-ee5/lobtest-ejb/src/main/java/com/redhat/gss/lobtest/hibernate/HibernateUtil.java 2009-10-09 02:56:57 UTC (rev 17665)
@@ -0,0 +1,59 @@
+package com.redhat.gss.lobtest.hibernate;
+
+import org.hibernate.Session;
+import org.hibernate.SessionFactory;
+import org.hibernate.cfg.AnnotationConfiguration;
+import org.hibernate.cfg.Configuration;
+import org.hibernate.tool.hbm2ddl.SchemaExport;
+
+import com.redhat.gss.lobtest.jpa.Thing;
+
+public class HibernateUtil {
+ private static SessionFactory factory;
+
+ public static Configuration getInitializedConfiguration() {
+ AnnotationConfiguration config = new AnnotationConfiguration();
+ config.addAnnotatedClass(Thing.class);
+ config.configure();
+ return config;
+ }
+
+ public static Session getSession() {
+ if (factory == null) {
+ Configuration config = HibernateUtil.getInitializedConfiguration();
+ factory = config.buildSessionFactory();
+ }
+ Session hibernateSession = factory.getCurrentSession();
+ return hibernateSession;
+ }
+
+ public static void closeSession() {
+ HibernateUtil.getSession().close();
+ }
+
+ public static void recreateDatabase() {
+ Configuration config;
+ config = HibernateUtil.getInitializedConfiguration();
+ new SchemaExport(config).create(true, true);
+ }
+
+ public static Session beginTransaction() {
+ Session hibernateSession;
+ hibernateSession = HibernateUtil.getSession();
+ hibernateSession.beginTransaction();
+ return hibernateSession;
+ }
+
+ public static void commitTransaction() {
+ HibernateUtil.getSession().getTransaction().commit();
+ }
+
+ public static void rollbackTransaction() {
+ HibernateUtil.getSession().getTransaction().rollback();
+ }
+
+ public static void main(String args[]) {
+ HibernateUtil.recreateDatabase();
+ }
+
+}
\ No newline at end of file
Added: sandbox/trunk/lobtest-ee5/lobtest-ejb/src/main/java/com/redhat/gss/lobtest/jpa/Image.java
===================================================================
--- sandbox/trunk/lobtest-ee5/lobtest-ejb/src/main/java/com/redhat/gss/lobtest/jpa/Image.java (rev 0)
+++ sandbox/trunk/lobtest-ee5/lobtest-ejb/src/main/java/com/redhat/gss/lobtest/jpa/Image.java 2009-10-09 02:56:57 UTC (rev 17665)
@@ -0,0 +1,52 @@
+package com.redhat.gss.lobtest.jpa;
+
+import java.sql.Blob;
+
+import javax.persistence.Basic;
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.Lob;
+
+ at Entity
+public class Image {
+ private long id;
+ private String name;
+ private Blob imageData;
+
+ Image() {}
+
+ public Image(long id) {
+ this.id = id;
+ }
+
+ @Id
+ @Column(name="ID")
+ public long getId() {
+ return id;
+ }
+
+ public void setId(long id) {
+ this.id = id;
+ }
+
+ @Basic
+ @Column(name="NAME")
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ @Lob
+ @Column(name="IMAGE_DATA")
+ public Blob getImageData() {
+ return imageData;
+ }
+
+ public void setImageData(Blob imageData) {
+ this.imageData = imageData;
+ }
+}
\ No newline at end of file
Added: sandbox/trunk/lobtest-ee5/lobtest-ejb/src/main/java/com/redhat/gss/lobtest/jpa/Item.java
===================================================================
--- sandbox/trunk/lobtest-ee5/lobtest-ejb/src/main/java/com/redhat/gss/lobtest/jpa/Item.java (rev 0)
+++ sandbox/trunk/lobtest-ee5/lobtest-ejb/src/main/java/com/redhat/gss/lobtest/jpa/Item.java 2009-10-09 02:56:57 UTC (rev 17665)
@@ -0,0 +1,52 @@
+package com.redhat.gss.lobtest.jpa;
+
+import java.sql.Clob;
+
+import javax.persistence.Basic;
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.Lob;
+
+ at Entity
+public class Item {
+ private long id;
+ private String name;
+ private Clob description;
+
+ Item() {}
+
+ public Item(long id) {
+ this.id = id;
+ }
+
+ @Id
+ @Column(name="ID")
+ public long getId() {
+ return id;
+ }
+
+ public void setId(long id) {
+ this.id = id;
+ }
+
+ @Basic
+ @Column(name="NAME")
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ @Lob
+ @Column(name="DESCRIPTION")
+ public Clob getDescription() {
+ return description;
+ }
+
+ public void setDescription(Clob description) {
+ this.description = description;
+ }
+}
\ No newline at end of file
Added: sandbox/trunk/lobtest-ee5/lobtest-ejb/src/main/java/com/redhat/gss/lobtest/jpa/Thing.java
===================================================================
--- sandbox/trunk/lobtest-ee5/lobtest-ejb/src/main/java/com/redhat/gss/lobtest/jpa/Thing.java (rev 0)
+++ sandbox/trunk/lobtest-ee5/lobtest-ejb/src/main/java/com/redhat/gss/lobtest/jpa/Thing.java 2009-10-09 02:56:57 UTC (rev 17665)
@@ -0,0 +1,37 @@
+package com.redhat.gss.lobtest.jpa;
+
+import javax.persistence.Basic;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+
+ at Entity
+public class Thing {
+ private Long id;
+ private String name;
+
+ Thing() {}
+
+ public Thing(Long id, String name) {
+ this.id = id;
+ this.name = name;
+ }
+
+ @Id
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ @Basic
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+}
Added: sandbox/trunk/lobtest-ee5/lobtest-ejb/src/main/resources/META-INF/MANIFEST.MF
===================================================================
--- sandbox/trunk/lobtest-ee5/lobtest-ejb/src/main/resources/META-INF/MANIFEST.MF (rev 0)
+++ sandbox/trunk/lobtest-ee5/lobtest-ejb/src/main/resources/META-INF/MANIFEST.MF 2009-10-09 02:56:57 UTC (rev 17665)
@@ -0,0 +1,3 @@
+Manifest-Version: 1.0
+Class-Path:
+
Added: sandbox/trunk/lobtest-ee5/lobtest-ejb/src/main/resources/META-INF/persistence.xml
===================================================================
--- sandbox/trunk/lobtest-ee5/lobtest-ejb/src/main/resources/META-INF/persistence.xml (rev 0)
+++ sandbox/trunk/lobtest-ee5/lobtest-ejb/src/main/resources/META-INF/persistence.xml 2009-10-09 02:56:57 UTC (rev 17665)
@@ -0,0 +1,12 @@
+<persistence version="1.0"
+ 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_1_0.xsd">
+ <persistence-unit name="lobtest-jpa">
+ <jta-data-source>java:/DefaultDS</jta-data-source>
+ <properties>
+ <property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect"/>
+ <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
+ </properties>
+ </persistence-unit>
+</persistence>
\ No newline at end of file
Added: sandbox/trunk/lobtest-ee5/lobtest-ejb/src/main/resources/hibernate.cfg.xml
===================================================================
--- sandbox/trunk/lobtest-ee5/lobtest-ejb/src/main/resources/hibernate.cfg.xml (rev 0)
+++ sandbox/trunk/lobtest-ee5/lobtest-ejb/src/main/resources/hibernate.cfg.xml 2009-10-09 02:56:57 UTC (rev 17665)
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE hibernate-configuration PUBLIC
+ "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
+ "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
+<hibernate-configuration>
+ <session-factory name="lobtest-hibernate">
+ <property name="hibernate.connection.datasource">java:/DefaultDS</property>
+ <property name="hibernate.dialect">org.hibernate.dialect.HSQLDialect</property>
+ <property name="hibernate.hbm2ddl.auto">create-drop</property>
+ <property name="hibernate.transaction.factory_class">org.hibernate.transaction.CMTTransactionFactory</property>
+ <property name="hibernate.transaction.manager_lookup_class">org.hibernate.transaction.JBossTransactionManagerLookup</property>
+ </session-factory>
+</hibernate-configuration>
Added: sandbox/trunk/lobtest-ee5/lobtest-ejb/src/test/resources/META-INF/persistence.xml
===================================================================
--- sandbox/trunk/lobtest-ee5/lobtest-ejb/src/test/resources/META-INF/persistence.xml (rev 0)
+++ sandbox/trunk/lobtest-ee5/lobtest-ejb/src/test/resources/META-INF/persistence.xml 2009-10-09 02:56:57 UTC (rev 17665)
@@ -0,0 +1,16 @@
+<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_1_0.xsd"
+ version="1.0">
+ <persistence-unit name="lobtest" transaction-type="RESOURCE_LOCAL">
+ <class>com.redhat.gss.lobtest.jpa.Item</class>
+ <class>com.redhat.gss.lobtest.jpa.Image</class>
+ <properties>
+ <property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect" />
+ <property name="hibernate.connection.driver_class" value="org.hsqldb.jdbcDriver" />
+ <property name="hibernate.connection.username" value="sa" />
+ <property name="hibernate.connection.password" value="" />
+ <property name="hibernate.connection.url" value="jdbc:hsqldb:mem:lobtest" />
+ <property name="hibernate.hbm2ddl.auto" value="create-drop" />
+ </properties>
+ </persistence-unit>
+</persistence>
\ No newline at end of file
Added: sandbox/trunk/lobtest-ee5/lobtest-web/pom.xml
===================================================================
--- sandbox/trunk/lobtest-ee5/lobtest-web/pom.xml (rev 0)
+++ sandbox/trunk/lobtest-ee5/lobtest-web/pom.xml 2009-10-09 02:56:57 UTC (rev 17665)
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<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">
+ <parent>
+ <artifactId>lobtest-ee5</artifactId>
+ <groupId>gss</groupId>
+ <version>1.0-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>lobtest-web</artifactId>
+ <packaging>war</packaging>
+ <name>LOB Test Webapp</name>
+ <build>
+ <finalName>lobtest-web</finalName>
+ <plugins>
+ <plugin>
+ <artifactId>maven-war-plugin</artifactId>
+ <configuration>
+ <packagingExcludes>WEB-INF/lib/*.jar</packagingExcludes>
+ <archive>
+ <manifest>
+ <addClasspath>true</addClasspath>
+ </manifest>
+ </archive>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ <dependencies>
+ <dependency>
+ <groupId>${parent.groupId}</groupId>
+ <artifactId>lobtest-ejb</artifactId>
+ <version>${parent.version}</version>
+ </dependency>
+ </dependencies>
+</project>
\ No newline at end of file
Added: sandbox/trunk/lobtest-ee5/lobtest-web/src/main/webapp/META-INF/MANIFEST.MF
===================================================================
--- sandbox/trunk/lobtest-ee5/lobtest-web/src/main/webapp/META-INF/MANIFEST.MF (rev 0)
+++ sandbox/trunk/lobtest-ee5/lobtest-web/src/main/webapp/META-INF/MANIFEST.MF 2009-10-09 02:56:57 UTC (rev 17665)
@@ -0,0 +1,3 @@
+Manifest-Version: 1.0
+Class-Path: lobtest-ejb-1.0-SNAPSHOT.jar
+
Added: sandbox/trunk/lobtest-ee5/lobtest-web/src/main/webapp/WEB-INF/web.xml
===================================================================
--- sandbox/trunk/lobtest-ee5/lobtest-web/src/main/webapp/WEB-INF/web.xml (rev 0)
+++ sandbox/trunk/lobtest-ee5/lobtest-web/src/main/webapp/WEB-INF/web.xml 2009-10-09 02:56:57 UTC (rev 17665)
@@ -0,0 +1,7 @@
+<!DOCTYPE web-app PUBLIC
+ "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
+ "http://java.sun.com/dtd/web-app_2_3.dtd" >
+
+<web-app>
+ <display-name>Archetype Created Web Application</display-name>
+</web-app>
Added: sandbox/trunk/lobtest-ee5/lobtest-web/src/main/webapp/basic.jsp
===================================================================
--- sandbox/trunk/lobtest-ee5/lobtest-web/src/main/webapp/basic.jsp (rev 0)
+++ sandbox/trunk/lobtest-ee5/lobtest-web/src/main/webapp/basic.jsp 2009-10-09 02:56:57 UTC (rev 17665)
@@ -0,0 +1,10 @@
+<%@page import="javax.naming.InitialContext"%>
+<%@page import="com.redhat.gss.lobtest.ejb.ThingService"%>
+<%
+ InitialContext ctx = new InitialContext();
+ ThingService ts = (ThingService) ctx.lookup("lobtest-ear/ThingServiceBean/local");
+ ts.setUp();
+ out.print("Tests set up.</br>");
+ ts.findAllThingsHibernate();
+%>
+Tests run successfully.
Added: sandbox/trunk/lobtest-ee5/lobtest-web/src/main/webapp/index.html
===================================================================
--- sandbox/trunk/lobtest-ee5/lobtest-web/src/main/webapp/index.html (rev 0)
+++ sandbox/trunk/lobtest-ee5/lobtest-web/src/main/webapp/index.html 2009-10-09 02:56:57 UTC (rev 17665)
@@ -0,0 +1,16 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+<title>LOB Test Application</title>
+</head>
+<body>
+
+<ul>
+ <li><a href="lob.jsp">LOB Test</a></li>
+ <li><a href="basic.jsp">Basic Thing Test</a></li>
+</ul>
+
+
+</body>
+</html>
\ No newline at end of file
Added: sandbox/trunk/lobtest-ee5/lobtest-web/src/main/webapp/lob.jsp
===================================================================
--- sandbox/trunk/lobtest-ee5/lobtest-web/src/main/webapp/lob.jsp (rev 0)
+++ sandbox/trunk/lobtest-ee5/lobtest-web/src/main/webapp/lob.jsp 2009-10-09 02:56:57 UTC (rev 17665)
@@ -0,0 +1,8 @@
+<%@page import="javax.naming.InitialContext"%>
+<%@page import="com.redhat.gss.lobtest.ejb.LobTestService"%>
+<%
+ InitialContext ctx = new InitialContext();
+ LobTestService lts = (LobTestService) ctx.lookup("lobtest-ear/LobTestServiceBean/local");
+ lts.runTests();
+%>
+Tests run successfully.
\ No newline at end of file
Added: sandbox/trunk/lobtest-ee5/pom.xml
===================================================================
--- sandbox/trunk/lobtest-ee5/pom.xml (rev 0)
+++ sandbox/trunk/lobtest-ee5/pom.xml 2009-10-09 02:56:57 UTC (rev 17665)
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<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>
+ <groupId>gss</groupId>
+ <artifactId>lobtest-ee5</artifactId>
+ <packaging>pom</packaging>
+ <version>1.0-SNAPSHOT</version>
+ <name>LOB Test EE5 Parent</name>
+ <modules>
+ <module>lobtest-ejb</module>
+ <module>lobtest-web</module>
+ <module>lobtest-ear</module>
+ </modules>
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <source>1.5</source>
+ <target>1.5</target>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
\ No newline at end of file
More information about the hibernate-commits
mailing list