Hibernate SVN: r17666 - sandbox/trunk.
by hibernate-commits@lists.jboss.org
Author: cbredesen
Date: 2009-10-08 22:58:26 -0400 (Thu, 08 Oct 2009)
New Revision: 17666
Removed:
sandbox/trunk/lobtest-ear/
Log:
Erroneously added
14 years, 7 months
Hibernate SVN: r17665 - in sandbox/trunk: lobtest-ee5 and 33 other directories.
by hibernate-commits@lists.jboss.org
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;
+
+@Stateless
+(a)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;
+
+@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;
+
+@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;
+
+@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;
+
+@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
14 years, 7 months
Hibernate SVN: r17664 - in sandbox/trunk: .settings and 33 other directories.
by hibernate-commits@lists.jboss.org
Author: cbredesen
Date: 2009-10-08 22:54:36 -0400 (Thu, 08 Oct 2009)
New Revision: 17664
Added:
sandbox/trunk/.project
sandbox/trunk/.settings/
sandbox/trunk/.settings/org.maven.ide.eclipse.prefs
sandbox/trunk/lobtest-ear/
sandbox/trunk/lobtest-ear/pom.xml
sandbox/trunk/lobtest-ear/src/
sandbox/trunk/lobtest-ear/src/main/
sandbox/trunk/lobtest-ear/src/main/application/
sandbox/trunk/lobtest-ear/src/main/application/META-INF/
sandbox/trunk/lobtest-ear/src/main/application/META-INF/application.xml
sandbox/trunk/lobtest-ejb/
sandbox/trunk/lobtest-ejb/java/
sandbox/trunk/lobtest-ejb/java/com/
sandbox/trunk/lobtest-ejb/java/com/redhat/
sandbox/trunk/lobtest-ejb/java/com/redhat/gss/
sandbox/trunk/lobtest-ejb/java/com/redhat/gss/lobtest/
sandbox/trunk/lobtest-ejb/java/com/redhat/gss/lobtest/jpa/
sandbox/trunk/lobtest-ejb/java/com/redhat/gss/lobtest/jpa/LobTest.java
sandbox/trunk/lobtest-ejb/lobtestdb-ds.xml
sandbox/trunk/lobtest-ejb/pom.xml
sandbox/trunk/lobtest-ejb/src/
sandbox/trunk/lobtest-ejb/src/main/
sandbox/trunk/lobtest-ejb/src/main/java/
sandbox/trunk/lobtest-ejb/src/main/java/com/
sandbox/trunk/lobtest-ejb/src/main/java/com/redhat/
sandbox/trunk/lobtest-ejb/src/main/java/com/redhat/gss/
sandbox/trunk/lobtest-ejb/src/main/java/com/redhat/gss/lobtest/
sandbox/trunk/lobtest-ejb/src/main/java/com/redhat/gss/lobtest/ejb/
sandbox/trunk/lobtest-ejb/src/main/java/com/redhat/gss/lobtest/ejb/LobTestService.java
sandbox/trunk/lobtest-ejb/src/main/java/com/redhat/gss/lobtest/ejb/LobTestServiceBean.java
sandbox/trunk/lobtest-ejb/src/main/java/com/redhat/gss/lobtest/ejb/ThingService.java
sandbox/trunk/lobtest-ejb/src/main/java/com/redhat/gss/lobtest/ejb/ThingServiceBean.java
sandbox/trunk/lobtest-ejb/src/main/java/com/redhat/gss/lobtest/hibernate/
sandbox/trunk/lobtest-ejb/src/main/java/com/redhat/gss/lobtest/hibernate/HibernateUtil.java
sandbox/trunk/lobtest-ejb/src/main/java/com/redhat/gss/lobtest/jpa/
sandbox/trunk/lobtest-ejb/src/main/java/com/redhat/gss/lobtest/jpa/Image.java
sandbox/trunk/lobtest-ejb/src/main/java/com/redhat/gss/lobtest/jpa/Item.java
sandbox/trunk/lobtest-ejb/src/main/java/com/redhat/gss/lobtest/jpa/Thing.java
sandbox/trunk/lobtest-ejb/src/main/resources/
sandbox/trunk/lobtest-ejb/src/main/resources/META-INF/
sandbox/trunk/lobtest-ejb/src/main/resources/META-INF/MANIFEST.MF
sandbox/trunk/lobtest-ejb/src/main/resources/META-INF/persistence.xml
sandbox/trunk/lobtest-ejb/src/main/resources/hibernate.cfg.xml
sandbox/trunk/lobtest-ejb/src/test/
sandbox/trunk/lobtest-ejb/src/test/resources/
sandbox/trunk/lobtest-ejb/src/test/resources/META-INF/
sandbox/trunk/lobtest-ejb/src/test/resources/META-INF/persistence.xml
sandbox/trunk/lobtest-web/
sandbox/trunk/lobtest-web/pom.xml
sandbox/trunk/lobtest-web/src/
sandbox/trunk/lobtest-web/src/main/
sandbox/trunk/lobtest-web/src/main/webapp/
sandbox/trunk/lobtest-web/src/main/webapp/META-INF/
sandbox/trunk/lobtest-web/src/main/webapp/META-INF/MANIFEST.MF
sandbox/trunk/lobtest-web/src/main/webapp/WEB-INF/
sandbox/trunk/lobtest-web/src/main/webapp/WEB-INF/lib/
sandbox/trunk/lobtest-web/src/main/webapp/WEB-INF/web.xml
sandbox/trunk/lobtest-web/src/main/webapp/basic.jsp
sandbox/trunk/lobtest-web/src/main/webapp/index.html
sandbox/trunk/lobtest-web/src/main/webapp/lob.jsp
sandbox/trunk/pom.xml
Log:
Initial import for testing CGLIB in-container
Added: sandbox/trunk/.project
===================================================================
--- sandbox/trunk/.project (rev 0)
+++ sandbox/trunk/.project 2009-10-09 02:54:36 UTC (rev 17664)
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>lobtest-ee5</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.wst.common.project.facet.core.builder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.maven.ide.eclipse.maven2Builder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.maven.ide.eclipse.maven2Nature</nature>
+ <nature>org.eclipse.wst.common.project.facet.core.nature</nature>
+ </natures>
+</projectDescription>
Added: sandbox/trunk/.settings/org.maven.ide.eclipse.prefs
===================================================================
--- sandbox/trunk/.settings/org.maven.ide.eclipse.prefs (rev 0)
+++ sandbox/trunk/.settings/org.maven.ide.eclipse.prefs 2009-10-09 02:54:36 UTC (rev 17664)
@@ -0,0 +1,9 @@
+#Thu Oct 08 21:51:21 EDT 2009
+activeProfiles=
+eclipse.preferences.version=1
+fullBuildGoals=process-test-resources
+includeModules=false
+resolveWorkspaceProjects=true
+resourceFilterGoals=process-resources resources\:testResources
+skipCompilerPlugin=true
+version=1
Added: sandbox/trunk/lobtest-ear/pom.xml
===================================================================
--- sandbox/trunk/lobtest-ear/pom.xml (rev 0)
+++ sandbox/trunk/lobtest-ear/pom.xml 2009-10-09 02:54:36 UTC (rev 17664)
@@ -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-ear/src/main/application/META-INF/application.xml
===================================================================
--- sandbox/trunk/lobtest-ear/src/main/application/META-INF/application.xml (rev 0)
+++ sandbox/trunk/lobtest-ear/src/main/application/META-INF/application.xml 2009-10-09 02:54:36 UTC (rev 17664)
@@ -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-ejb/java/com/redhat/gss/lobtest/jpa/LobTest.java
===================================================================
--- sandbox/trunk/lobtest-ejb/java/com/redhat/gss/lobtest/jpa/LobTest.java (rev 0)
+++ sandbox/trunk/lobtest-ejb/java/com/redhat/gss/lobtest/jpa/LobTest.java 2009-10-09 02:54:36 UTC (rev 17664)
@@ -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-ejb/lobtestdb-ds.xml
===================================================================
--- sandbox/trunk/lobtest-ejb/lobtestdb-ds.xml (rev 0)
+++ sandbox/trunk/lobtest-ejb/lobtestdb-ds.xml 2009-10-09 02:54:36 UTC (rev 17664)
@@ -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-ejb/pom.xml
===================================================================
--- sandbox/trunk/lobtest-ejb/pom.xml (rev 0)
+++ sandbox/trunk/lobtest-ejb/pom.xml 2009-10-09 02:54:36 UTC (rev 17664)
@@ -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-ejb/src/main/java/com/redhat/gss/lobtest/ejb/LobTestService.java
===================================================================
--- sandbox/trunk/lobtest-ejb/src/main/java/com/redhat/gss/lobtest/ejb/LobTestService.java (rev 0)
+++ sandbox/trunk/lobtest-ejb/src/main/java/com/redhat/gss/lobtest/ejb/LobTestService.java 2009-10-09 02:54:36 UTC (rev 17664)
@@ -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-ejb/src/main/java/com/redhat/gss/lobtest/ejb/LobTestServiceBean.java
===================================================================
--- sandbox/trunk/lobtest-ejb/src/main/java/com/redhat/gss/lobtest/ejb/LobTestServiceBean.java (rev 0)
+++ sandbox/trunk/lobtest-ejb/src/main/java/com/redhat/gss/lobtest/ejb/LobTestServiceBean.java 2009-10-09 02:54:36 UTC (rev 17664)
@@ -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;
+
+@Stateless
+(a)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-ejb/src/main/java/com/redhat/gss/lobtest/ejb/ThingService.java
===================================================================
--- sandbox/trunk/lobtest-ejb/src/main/java/com/redhat/gss/lobtest/ejb/ThingService.java (rev 0)
+++ sandbox/trunk/lobtest-ejb/src/main/java/com/redhat/gss/lobtest/ejb/ThingService.java 2009-10-09 02:54:36 UTC (rev 17664)
@@ -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-ejb/src/main/java/com/redhat/gss/lobtest/ejb/ThingServiceBean.java
===================================================================
--- sandbox/trunk/lobtest-ejb/src/main/java/com/redhat/gss/lobtest/ejb/ThingServiceBean.java (rev 0)
+++ sandbox/trunk/lobtest-ejb/src/main/java/com/redhat/gss/lobtest/ejb/ThingServiceBean.java 2009-10-09 02:54:36 UTC (rev 17664)
@@ -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;
+
+@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-ejb/src/main/java/com/redhat/gss/lobtest/hibernate/HibernateUtil.java
===================================================================
--- sandbox/trunk/lobtest-ejb/src/main/java/com/redhat/gss/lobtest/hibernate/HibernateUtil.java (rev 0)
+++ sandbox/trunk/lobtest-ejb/src/main/java/com/redhat/gss/lobtest/hibernate/HibernateUtil.java 2009-10-09 02:54:36 UTC (rev 17664)
@@ -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-ejb/src/main/java/com/redhat/gss/lobtest/jpa/Image.java
===================================================================
--- sandbox/trunk/lobtest-ejb/src/main/java/com/redhat/gss/lobtest/jpa/Image.java (rev 0)
+++ sandbox/trunk/lobtest-ejb/src/main/java/com/redhat/gss/lobtest/jpa/Image.java 2009-10-09 02:54:36 UTC (rev 17664)
@@ -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;
+
+@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-ejb/src/main/java/com/redhat/gss/lobtest/jpa/Item.java
===================================================================
--- sandbox/trunk/lobtest-ejb/src/main/java/com/redhat/gss/lobtest/jpa/Item.java (rev 0)
+++ sandbox/trunk/lobtest-ejb/src/main/java/com/redhat/gss/lobtest/jpa/Item.java 2009-10-09 02:54:36 UTC (rev 17664)
@@ -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;
+
+@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-ejb/src/main/java/com/redhat/gss/lobtest/jpa/Thing.java
===================================================================
--- sandbox/trunk/lobtest-ejb/src/main/java/com/redhat/gss/lobtest/jpa/Thing.java (rev 0)
+++ sandbox/trunk/lobtest-ejb/src/main/java/com/redhat/gss/lobtest/jpa/Thing.java 2009-10-09 02:54:36 UTC (rev 17664)
@@ -0,0 +1,37 @@
+package com.redhat.gss.lobtest.jpa;
+
+import javax.persistence.Basic;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+
+@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-ejb/src/main/resources/META-INF/MANIFEST.MF
===================================================================
--- sandbox/trunk/lobtest-ejb/src/main/resources/META-INF/MANIFEST.MF (rev 0)
+++ sandbox/trunk/lobtest-ejb/src/main/resources/META-INF/MANIFEST.MF 2009-10-09 02:54:36 UTC (rev 17664)
@@ -0,0 +1,3 @@
+Manifest-Version: 1.0
+Class-Path:
+
Added: sandbox/trunk/lobtest-ejb/src/main/resources/META-INF/persistence.xml
===================================================================
--- sandbox/trunk/lobtest-ejb/src/main/resources/META-INF/persistence.xml (rev 0)
+++ sandbox/trunk/lobtest-ejb/src/main/resources/META-INF/persistence.xml 2009-10-09 02:54:36 UTC (rev 17664)
@@ -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-ejb/src/main/resources/hibernate.cfg.xml
===================================================================
--- sandbox/trunk/lobtest-ejb/src/main/resources/hibernate.cfg.xml (rev 0)
+++ sandbox/trunk/lobtest-ejb/src/main/resources/hibernate.cfg.xml 2009-10-09 02:54:36 UTC (rev 17664)
@@ -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-ejb/src/test/resources/META-INF/persistence.xml
===================================================================
--- sandbox/trunk/lobtest-ejb/src/test/resources/META-INF/persistence.xml (rev 0)
+++ sandbox/trunk/lobtest-ejb/src/test/resources/META-INF/persistence.xml 2009-10-09 02:54:36 UTC (rev 17664)
@@ -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-web/pom.xml
===================================================================
--- sandbox/trunk/lobtest-web/pom.xml (rev 0)
+++ sandbox/trunk/lobtest-web/pom.xml 2009-10-09 02:54:36 UTC (rev 17664)
@@ -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-web/src/main/webapp/META-INF/MANIFEST.MF
===================================================================
--- sandbox/trunk/lobtest-web/src/main/webapp/META-INF/MANIFEST.MF (rev 0)
+++ sandbox/trunk/lobtest-web/src/main/webapp/META-INF/MANIFEST.MF 2009-10-09 02:54:36 UTC (rev 17664)
@@ -0,0 +1,3 @@
+Manifest-Version: 1.0
+Class-Path: lobtest-ejb-1.0-SNAPSHOT.jar
+
Added: sandbox/trunk/lobtest-web/src/main/webapp/WEB-INF/web.xml
===================================================================
--- sandbox/trunk/lobtest-web/src/main/webapp/WEB-INF/web.xml (rev 0)
+++ sandbox/trunk/lobtest-web/src/main/webapp/WEB-INF/web.xml 2009-10-09 02:54:36 UTC (rev 17664)
@@ -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-web/src/main/webapp/basic.jsp
===================================================================
--- sandbox/trunk/lobtest-web/src/main/webapp/basic.jsp (rev 0)
+++ sandbox/trunk/lobtest-web/src/main/webapp/basic.jsp 2009-10-09 02:54:36 UTC (rev 17664)
@@ -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-web/src/main/webapp/index.html
===================================================================
--- sandbox/trunk/lobtest-web/src/main/webapp/index.html (rev 0)
+++ sandbox/trunk/lobtest-web/src/main/webapp/index.html 2009-10-09 02:54:36 UTC (rev 17664)
@@ -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-web/src/main/webapp/lob.jsp
===================================================================
--- sandbox/trunk/lobtest-web/src/main/webapp/lob.jsp (rev 0)
+++ sandbox/trunk/lobtest-web/src/main/webapp/lob.jsp 2009-10-09 02:54:36 UTC (rev 17664)
@@ -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/pom.xml
===================================================================
--- sandbox/trunk/pom.xml (rev 0)
+++ sandbox/trunk/pom.xml 2009-10-09 02:54:36 UTC (rev 17664)
@@ -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
14 years, 7 months
Hibernate SVN: r17663 - core/trunk/documentation/jbosscache2/src/main/docbook/en-US/content.
by hibernate-commits@lists.jboss.org
Author: bstansberry(a)jboss.com
Date: 2009-10-08 22:25:15 -0400 (Thu, 08 Oct 2009)
New Revision: 17663
Modified:
core/trunk/documentation/jbosscache2/src/main/docbook/en-US/content/eviction.xml
Log:
Typo
Modified: core/trunk/documentation/jbosscache2/src/main/docbook/en-US/content/eviction.xml
===================================================================
--- core/trunk/documentation/jbosscache2/src/main/docbook/en-US/content/eviction.xml 2009-10-08 23:23:42 UTC (rev 17662)
+++ core/trunk/documentation/jbosscache2/src/main/docbook/en-US/content/eviction.xml 2009-10-09 02:25:15 UTC (rev 17663)
@@ -2,7 +2,7 @@
<!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd">
<!--
- ~ Copyright (c) 2008, Red Hat Middleware, LLC. All rights reserved.
+ ~ Copyright (c) 2009, Red Hat, Inc. All rights reserved.
~
~ This copyrighted material is made available to anyone wishing to use, modify,
~ copy, or redistribute it subject to the terms and conditions of the GNU
@@ -42,7 +42,7 @@
<para>
The JBoss Cache eviction process is fairly straightforward. Whenever
- a node in a cache read or written to, added or removed, the cache
+ a node in a cache is read or written to, added or removed, the cache
finds the <emphasis>eviction region</emphasis> (see below) that
contains the node and passes an <emphasis>eviction event</emphasis>
object to the <emphasis>eviction policy</emphasis> (see below)
14 years, 7 months
Hibernate SVN: r17662 - core/trunk/cache-jbosscache/src/main/java/org/hibernate/cache/jbc2.
by hibernate-commits@lists.jboss.org
Author: bstansberry(a)jboss.com
Date: 2009-10-08 19:23:42 -0400 (Thu, 08 Oct 2009)
New Revision: 17662
Added:
core/trunk/cache-jbosscache/src/main/java/org/hibernate/cache/jbc2/JBossCacheRegionFactory.java
core/trunk/cache-jbosscache/src/main/java/org/hibernate/cache/jbc2/JndiMultiplexedJBossCacheRegionFactory.java
core/trunk/cache-jbosscache/src/main/java/org/hibernate/cache/jbc2/JndiSharedJBossCacheRegionFactory.java
core/trunk/cache-jbosscache/src/main/java/org/hibernate/cache/jbc2/MultiplexedJBossCacheRegionFactory.java
core/trunk/cache-jbosscache/src/main/java/org/hibernate/cache/jbc2/SharedJBossCacheRegionFactory.java
Log:
[HHH-4487] Restore versions of the old public API jbc2 package classes
Copied: core/trunk/cache-jbosscache/src/main/java/org/hibernate/cache/jbc2/JBossCacheRegionFactory.java (from rev 17661, core/branches/Branch_3_3/cache-jbosscache2/src/main/java/org/hibernate/cache/jbc2/JBossCacheRegionFactory.java)
===================================================================
--- core/trunk/cache-jbosscache/src/main/java/org/hibernate/cache/jbc2/JBossCacheRegionFactory.java (rev 0)
+++ core/trunk/cache-jbosscache/src/main/java/org/hibernate/cache/jbc2/JBossCacheRegionFactory.java 2009-10-08 23:23:42 UTC (rev 17662)
@@ -0,0 +1,69 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2009, Red Hat, Inc. or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat, Inc.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+package org.hibernate.cache.jbc2;
+
+import java.util.Properties;
+
+import org.hibernate.cache.jbc.CacheInstanceManager;
+
+/**
+ * Deprecated version of superclass maintained solely for forwards
+ * compatibility.
+ *
+ * @deprecated use {@link org.hibernate.cache.jbc.JBossCacheRegionFactory}
+ *
+ * @author Steve Ebersole
+ * @author Brian Stansberry
+ */
+@Deprecated
+public class JBossCacheRegionFactory extends org.hibernate.cache.jbc.JBossCacheRegionFactory {
+
+ /**
+ * FIXME Per the RegionFactory class Javadoc, this constructor version
+ * should not be necessary.
+ *
+ * @param props The configuration properties
+ */
+ public JBossCacheRegionFactory(Properties props) {
+ super(props);
+ }
+
+ /**
+ * Create a new JBossCacheRegionFactory.
+ */
+ public JBossCacheRegionFactory() {
+ super();
+ }
+
+ /**
+ * Create a new JBossCacheRegionFactory that uses the provided
+ * {@link CacheInstanceManager}.
+ *
+ * @param cacheInstanceManager The contract for how we get JBC cache instances.
+ */
+ public JBossCacheRegionFactory(CacheInstanceManager cacheInstanceManager) {
+ super(cacheInstanceManager);
+ }
+
+}
Copied: core/trunk/cache-jbosscache/src/main/java/org/hibernate/cache/jbc2/JndiMultiplexedJBossCacheRegionFactory.java (from rev 17661, core/branches/Branch_3_3/cache-jbosscache2/src/main/java/org/hibernate/cache/jbc2/JndiMultiplexedJBossCacheRegionFactory.java)
===================================================================
--- core/trunk/cache-jbosscache/src/main/java/org/hibernate/cache/jbc2/JndiMultiplexedJBossCacheRegionFactory.java (rev 0)
+++ core/trunk/cache-jbosscache/src/main/java/org/hibernate/cache/jbc2/JndiMultiplexedJBossCacheRegionFactory.java 2009-10-08 23:23:42 UTC (rev 17662)
@@ -0,0 +1,58 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2009, Red Hat, Inc. or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat, Inc.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+package org.hibernate.cache.jbc2;
+
+import java.util.Properties;
+
+/**
+ * Deprecated version of superclass maintained solely for forwards
+ * compatibility.
+ *
+ * @deprecated use {@link org.hibernate.cache.jbc.JndiMultiplexedJBossCacheRegionFactory}
+ *
+ * @author Brian Stansberry
+ * @version $Revision$
+ */
+@Deprecated
+public class JndiMultiplexedJBossCacheRegionFactory extends org.hibernate.cache.jbc.JndiMultiplexedJBossCacheRegionFactory {
+
+ /**
+ * FIXME Per the RegionFactory class Javadoc, this constructor version
+ * should not be necessary.
+ *
+ * @param props The configuration properties
+ */
+ public JndiMultiplexedJBossCacheRegionFactory(Properties props) {
+ super(props);
+ }
+
+ /**
+ * Create a new MultiplexedJBossCacheRegionFactory.
+ *
+ */
+ public JndiMultiplexedJBossCacheRegionFactory() {
+ super();
+ }
+
+}
Copied: core/trunk/cache-jbosscache/src/main/java/org/hibernate/cache/jbc2/JndiSharedJBossCacheRegionFactory.java (from rev 17661, core/branches/Branch_3_3/cache-jbosscache2/src/main/java/org/hibernate/cache/jbc2/JndiSharedJBossCacheRegionFactory.java)
===================================================================
--- core/trunk/cache-jbosscache/src/main/java/org/hibernate/cache/jbc2/JndiSharedJBossCacheRegionFactory.java (rev 0)
+++ core/trunk/cache-jbosscache/src/main/java/org/hibernate/cache/jbc2/JndiSharedJBossCacheRegionFactory.java 2009-10-08 23:23:42 UTC (rev 17662)
@@ -0,0 +1,58 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2009, Red Hat, Inc. or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat, Inc.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+package org.hibernate.cache.jbc2;
+
+import java.util.Properties;
+
+/**
+ * Deprecated version of superclass maintained solely for forwards
+ * compatibility.
+ *
+ * @deprecated use {@link org.hibernate.cache.jbc.JndiSharedJBossCacheRegionFactory}
+ *
+ * @author Brian Stansberry
+ * @version $Revision$
+ */
+@Deprecated
+public class JndiSharedJBossCacheRegionFactory extends org.hibernate.cache.jbc.JndiSharedJBossCacheRegionFactory {
+
+ /**
+ * FIXME Per the RegionFactory class Javadoc, this constructor version
+ * should not be necessary.
+ *
+ * @param props The configuration properties
+ */
+ public JndiSharedJBossCacheRegionFactory(Properties props) {
+ super(props);
+ }
+
+ /**
+ * Create a new JndiSharedJBossCacheRegionFactory.
+ *
+ */
+ public JndiSharedJBossCacheRegionFactory() {
+ super();
+ }
+
+}
Copied: core/trunk/cache-jbosscache/src/main/java/org/hibernate/cache/jbc2/MultiplexedJBossCacheRegionFactory.java (from rev 17661, core/branches/Branch_3_3/cache-jbosscache2/src/main/java/org/hibernate/cache/jbc2/MultiplexedJBossCacheRegionFactory.java)
===================================================================
--- core/trunk/cache-jbosscache/src/main/java/org/hibernate/cache/jbc2/MultiplexedJBossCacheRegionFactory.java (rev 0)
+++ core/trunk/cache-jbosscache/src/main/java/org/hibernate/cache/jbc2/MultiplexedJBossCacheRegionFactory.java 2009-10-08 23:23:42 UTC (rev 17662)
@@ -0,0 +1,57 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2009, Red Hat, Inc. or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat, Inc.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+package org.hibernate.cache.jbc2;
+
+import java.util.Properties;
+
+/**
+ * Deprecated version of superclass maintained solely for forwards
+ * compatibility.
+ *
+ * @deprecated use {@link org.hibernate.cache.jbc.MultiplexedJBossCacheRegionFactory}
+ *
+ * @author Brian Stansberry
+ * @version $Revision$
+ */
+public class MultiplexedJBossCacheRegionFactory extends org.hibernate.cache.jbc.MultiplexedJBossCacheRegionFactory {
+
+ /**
+ * FIXME Per the RegionFactory class Javadoc, this constructor version
+ * should not be necessary.
+ *
+ * @param props The configuration properties
+ */
+ public MultiplexedJBossCacheRegionFactory(Properties props) {
+ super(props);
+ }
+
+ /**
+ * Create a new MultiplexedJBossCacheRegionFactory.
+ *
+ */
+ public MultiplexedJBossCacheRegionFactory() {
+ super();
+ }
+
+}
Copied: core/trunk/cache-jbosscache/src/main/java/org/hibernate/cache/jbc2/SharedJBossCacheRegionFactory.java (from rev 17661, core/branches/Branch_3_3/cache-jbosscache2/src/main/java/org/hibernate/cache/jbc2/SharedJBossCacheRegionFactory.java)
===================================================================
--- core/trunk/cache-jbosscache/src/main/java/org/hibernate/cache/jbc2/SharedJBossCacheRegionFactory.java (rev 0)
+++ core/trunk/cache-jbosscache/src/main/java/org/hibernate/cache/jbc2/SharedJBossCacheRegionFactory.java 2009-10-08 23:23:42 UTC (rev 17662)
@@ -0,0 +1,58 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2009, Red Hat, Inc. or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat, Inc.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+package org.hibernate.cache.jbc2;
+
+import java.util.Properties;
+
+/**
+ * Deprecated version of superclass maintained solely for forwards
+ * compatibility.
+ *
+ * @deprecated use {@link org.hibernate.cache.jbc.SharedJBossCacheRegionFactory}
+ *
+ * @author Brian Stansberry
+ * @version $Revision$
+ */
+@Deprecated
+public class SharedJBossCacheRegionFactory extends org.hibernate.cache.jbc.SharedJBossCacheRegionFactory {
+
+ /**
+ * FIXME Per the RegionFactory class Javadoc, this constructor version
+ * should not be necessary.
+ *
+ * @param props The configuration properties
+ */
+ public SharedJBossCacheRegionFactory(Properties props) {
+ super(props);
+ }
+
+ /**
+ * Create a new SharedJBossCacheRegionFactory.
+ *
+ */
+ public SharedJBossCacheRegionFactory() {
+ super();
+ }
+
+}
14 years, 7 months
Hibernate SVN: r17660 - in core/trunk/cache-jbosscache/src/main/java/org/hibernate/cache/jbc: query and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: bstansberry(a)jboss.com
Date: 2009-10-08 18:40:42 -0400 (Thu, 08 Oct 2009)
New Revision: 17660
Modified:
core/trunk/cache-jbosscache/src/main/java/org/hibernate/cache/jbc/builder/MultiplexingCacheInstanceManager.java
core/trunk/cache-jbosscache/src/main/java/org/hibernate/cache/jbc/builder/SharedCacheInstanceManager.java
core/trunk/cache-jbosscache/src/main/java/org/hibernate/cache/jbc/query/QueryResultsRegionImpl.java
Log:
[HHH-4485] Replace the JBoss Cache integration configuration properties with "jbc2"-less versions
Modified: core/trunk/cache-jbosscache/src/main/java/org/hibernate/cache/jbc/builder/MultiplexingCacheInstanceManager.java
===================================================================
--- core/trunk/cache-jbosscache/src/main/java/org/hibernate/cache/jbc/builder/MultiplexingCacheInstanceManager.java 2009-10-08 20:59:56 UTC (rev 17659)
+++ core/trunk/cache-jbosscache/src/main/java/org/hibernate/cache/jbc/builder/MultiplexingCacheInstanceManager.java 2009-10-08 22:40:42 UTC (rev 17660)
@@ -62,7 +62,13 @@
*
* @see #DEF_CACHE_FACTORY_RESOURCE
*/
- public static final String CACHE_FACTORY_RESOURCE_PROP = "hibernate.cache.region.jbc2.configs";
+ public static final String CACHE_FACTORY_RESOURCE_PROP = "hibernate.cache.jbc.configs";
+ /**
+ * Legacy name for configuration property {@link #CACHE_FACTORY_RESOURCE_PROP}.
+ *
+ * @see #DEF_CACHE_FACTORY_RESOURCE
+ */
+ public static final String LEGACY_CACHE_FACTORY_RESOURCE_PROP = "hibernate.cache.region.jbc2.configs";
/**
* Classpath or filesystem resource containing JGroups protocol
* stack configurations the <code>org.jgroups.ChannelFactory</code>
@@ -70,15 +76,27 @@
*
* @see #DEF_JGROUPS_RESOURCE
*/
- public static final String CHANNEL_FACTORY_RESOURCE_PROP = "hibernate.cache.region.jbc2.jgroups.stacks";
+ public static final String CHANNEL_FACTORY_RESOURCE_PROP = "hibernate.cache.jbc.jgroups.stacks";
+ /**
+ * Legacy name for configuration property {@link #CHANNEL_FACTORY_RESOURCE_PROP}.
+ *
+ * @see #DEF_JGROUPS_RESOURCE
+ */
+ public static final String LEGACY_CHANNEL_FACTORY_RESOURCE_PROP = "hibernate.cache.region.jbc2.cfg.jgroups.stacks";
/**
* Name of the configuration that should be used for entity caches.
*
* @see #DEF_ENTITY_RESOURCE
*/
- public static final String ENTITY_CACHE_RESOURCE_PROP = "hibernate.cache.region.jbc2.cfg.entity";
+ public static final String ENTITY_CACHE_RESOURCE_PROP = "hibernate.cache.jbc.cfg.entity";
/**
+ * Legacy name for configuration property {@link #ENTITY_CACHE_RESOURCE_PROP}.
+ *
+ * @see #DEF_ENTITY_RESOURCE
+ */
+ public static final String LEGACY_ENTITY_CACHE_RESOURCE_PROP = "hibernate.cache.region.jbc2.cfg.entity";
+ /**
* Name of the configuration that should be used for collection caches.
* No default value, as by default we try to use the same JBoss Cache
* instance we use for entity caching.
@@ -86,21 +104,41 @@
* @see #ENTITY_CACHE_RESOURCE_PROP
* @see #DEF_ENTITY_RESOURCE
*/
- public static final String COLLECTION_CACHE_RESOURCE_PROP = "hibernate.cache.region.jbc2.cfg.collection";
+ public static final String COLLECTION_CACHE_RESOURCE_PROP = "hibernate.cache.jbc.cfg.collection";
/**
+ * Legacy name for configuration property {@link #COLLECTION_CACHE_RESOURCE_PROP}.
+ *
+ * @see #ENTITY_CACHE_RESOURCE_PROP
+ * @see #DEF_ENTITY_RESOURCE
+ */
+ public static final String LEGACY_COLLECTION_CACHE_RESOURCE_PROP = "hibernate.cache.region.jbc2.cfg.collection";
+ /**
* Name of the configuration that should be used for timestamp caches.
*
* @see #DEF_TS_RESOURCE
*/
- public static final String TIMESTAMP_CACHE_RESOURCE_PROP = "hibernate.cache.region.jbc2.cfg.ts";
+ public static final String TIMESTAMP_CACHE_RESOURCE_PROP = "hibernate.cache.jbc.cfg.timestamps";
/**
+ * Legacy name for configuration property {@link #TIMESTAMP_CACHE_RESOURCE_PROP}.
+ *
+ * @see #DEF_TS_RESOURCE
+ */
+ public static final String LEGACY_TIMESTAMP_CACHE_RESOURCE_PROP = "hibernate.cache.region.jbc2.cfg.ts";
+ /**
* Name of the configuration that should be used for query caches.
*
* @see #DEF_QUERY_RESOURCE
*/
- public static final String QUERY_CACHE_RESOURCE_PROP = "hibernate.cache.region.jbc2.cfg.query";
+ public static final String QUERY_CACHE_RESOURCE_PROP = "hibernate.cache.jbc.cfg.query";
/**
+ * Legacy name for configuration property {@link #QUERY_CACHE_RESOURCE_PROP}.
+ *
+ * @see #DEF_QUERY_RESOURCE
+ */
+ public static final String LEGACY_QUERY_CACHE_RESOURCE_PROP = "hibernate.cache.region.jbc2.cfg.query";
+
+ /**
* Default value for {@link #CACHE_FACTORY_RESOURCE_PROP}. Specifies
* the "jbc2-configs.xml" file in this package.
*/
@@ -279,14 +317,20 @@
if (buildCaches && jbcFactory == null) {
// See if the user configured a multiplexer stack
if (channelFactory == null) {
- String muxStacks = PropertiesHelper.getString(CHANNEL_FACTORY_RESOURCE_PROP, properties, DEF_JGROUPS_RESOURCE);
+ String muxStacks = PropertiesHelper.getString(CHANNEL_FACTORY_RESOURCE_PROP, properties, null);
+ if (muxStacks == null) {
+ muxStacks = PropertiesHelper.getString(LEGACY_CHANNEL_FACTORY_RESOURCE_PROP, properties, DEF_JGROUPS_RESOURCE);
+ }
if (muxStacks != null) {
channelFactory = new JChannelFactory();
channelFactory.setMultiplexerConfig(muxStacks);
}
}
- String factoryRes = PropertiesHelper.getString(CACHE_FACTORY_RESOURCE_PROP, properties, DEF_CACHE_FACTORY_RESOURCE);
+ String factoryRes = PropertiesHelper.getString(CACHE_FACTORY_RESOURCE_PROP, properties, null);
+ if (factoryRes == null) {
+ factoryRes = PropertiesHelper.getString(LEGACY_CACHE_FACTORY_RESOURCE_PROP, properties, DEF_CACHE_FACTORY_RESOURCE);
+ }
jbcFactory = new CacheManagerImpl(factoryRes, channelFactory);
((CacheManagerImpl) jbcFactory).start();
selfCreatedFactory = true;
@@ -296,11 +340,18 @@
if (buildCaches) {
entityConfig = PropertiesHelper
- .getString(ENTITY_CACHE_RESOURCE_PROP, properties, DEF_ENTITY_RESOURCE);
+ .getString(ENTITY_CACHE_RESOURCE_PROP, properties, null);
+ if (entityConfig == null) {
+ entityConfig = PropertiesHelper.getString(LEGACY_ENTITY_CACHE_RESOURCE_PROP,
+ properties, DEF_ENTITY_RESOURCE);
+ }
jbcEntityCache = jbcFactory.getCache(entityConfig, true);
// Default to collections sharing entity cache if there is one
- collectionConfig = PropertiesHelper.getString(COLLECTION_CACHE_RESOURCE_PROP, properties, entityConfig);
+ collectionConfig = PropertiesHelper.getString(COLLECTION_CACHE_RESOURCE_PROP, properties, null);
+ if (collectionConfig == null) {
+ collectionConfig = PropertiesHelper.getString(LEGACY_COLLECTION_CACHE_RESOURCE_PROP, properties, entityConfig);
+ }
if (entityConfig.equals(collectionConfig)) {
jbcCollectionCache = jbcEntityCache;
}
@@ -329,7 +380,10 @@
if (buildCaches) {
// Default to sharing the entity cache if there is one
String dfltQueryResource = (entityConfig == null ? DEF_QUERY_RESOURCE : entityConfig);
- queryConfig = PropertiesHelper.getString(QUERY_CACHE_RESOURCE_PROP, properties, dfltQueryResource);
+ queryConfig = PropertiesHelper.getString(QUERY_CACHE_RESOURCE_PROP, properties, null);
+ if (queryConfig == null) {
+ queryConfig = PropertiesHelper.getString(LEGACY_QUERY_CACHE_RESOURCE_PROP, properties, dfltQueryResource);
+ }
if (queryConfig.equals(entityConfig)) {
jbcQueryCache = jbcEntityCache;
} else if (queryConfig.equals(collectionConfig)) {
@@ -339,7 +393,10 @@
}
// For Timestamps, we default to a separate config
- tsConfig = PropertiesHelper.getString(TIMESTAMP_CACHE_RESOURCE_PROP, properties, DEF_TS_RESOURCE);
+ tsConfig = PropertiesHelper.getString(TIMESTAMP_CACHE_RESOURCE_PROP, properties, null);
+ if (tsConfig == null) {
+ tsConfig = PropertiesHelper.getString(LEGACY_TIMESTAMP_CACHE_RESOURCE_PROP, properties, DEF_TS_RESOURCE);
+ }
if (tsConfig.equals(queryConfig)) {
jbcTsCache = jbcQueryCache;
}
Modified: core/trunk/cache-jbosscache/src/main/java/org/hibernate/cache/jbc/builder/SharedCacheInstanceManager.java
===================================================================
--- core/trunk/cache-jbosscache/src/main/java/org/hibernate/cache/jbc/builder/SharedCacheInstanceManager.java 2009-10-08 20:59:56 UTC (rev 17659)
+++ core/trunk/cache-jbosscache/src/main/java/org/hibernate/cache/jbc/builder/SharedCacheInstanceManager.java 2009-10-08 22:40:42 UTC (rev 17660)
@@ -61,9 +61,16 @@
*
* @see #DEFAULT_CACHE_RESOURCE
*/
- public static final String CACHE_RESOURCE_PROP = "hibernate.cache.region.jbc2.cfg.shared";
+ public static final String CACHE_RESOURCE_PROP = "hibernate.cache.jbc.cfg.shared";
/**
+ * Legacy name for configuration property {@link #CACHE_RESOURCE_PROP}.
+ *
+ * @see #DEFAULT_CACHE_RESOURCE
+ */
+ public static final String LEGACY_CACHE_RESOURCE_PROP = "hibernate.cache.region.jbc2.cfg.shared";
+
+ /**
* Default name for the JBoss Cache configuration file.
*/
public static final String DEFAULT_CACHE_RESOURCE = "treecache.xml";
@@ -74,8 +81,14 @@
*
* @see #DEF_JGROUPS_RESOURCE
*/
- public static final String CHANNEL_FACTORY_RESOURCE_PROP = "hibernate.cache.region.jbc2.cfg.jgroups.stacks";
+ public static final String CHANNEL_FACTORY_RESOURCE_PROP = "hibernate.cache.jbc.cfg.jgroups.stacks";
/**
+ * Legacy name for configuration property {@link #CHANNEL_FACTORY_RESOURCE_PROP}.
+ *
+ * @see #DEF_JGROUPS_RESOURCE
+ */
+ public static final String LEGACY_CHANNEL_FACTORY_RESOURCE_PROP = "hibernate.cache.region.jbc2.cfg.jgroups.stacks";
+ /**
* Default value for {@link #CHANNEL_FACTORY_RESOURCE_PROP}. Specifies
* the "jgroups-stacks.xml" file in this package.
*/
@@ -136,7 +149,10 @@
if (cache == null) {
if (channelFactory == null) {
- String muxStacks = PropertiesHelper.getString(CHANNEL_FACTORY_RESOURCE_PROP, properties, DEF_JGROUPS_RESOURCE);
+ String muxStacks = PropertiesHelper.getString(CHANNEL_FACTORY_RESOURCE_PROP, properties, null);
+ if (muxStacks == null) {
+ PropertiesHelper.getString(LEGACY_CHANNEL_FACTORY_RESOURCE_PROP, properties, DEF_JGROUPS_RESOURCE);
+ }
if (muxStacks != null) {
channelFactory = new JChannelFactory();
try {
@@ -189,7 +205,10 @@
*/
protected Cache createSharedCache(Settings settings, Properties properties)
{
- String configResource = PropertiesHelper.getString(CACHE_RESOURCE_PROP, properties, DEFAULT_CACHE_RESOURCE);
+ String configResource = PropertiesHelper.getString(CACHE_RESOURCE_PROP, properties, null);
+ if (configResource == null) {
+ configResource = PropertiesHelper.getString(LEGACY_CACHE_RESOURCE_PROP, properties, DEFAULT_CACHE_RESOURCE);
+ }
return new DefaultCacheFactory().createCache(configResource, false);
}
Modified: core/trunk/cache-jbosscache/src/main/java/org/hibernate/cache/jbc/query/QueryResultsRegionImpl.java
===================================================================
--- core/trunk/cache-jbosscache/src/main/java/org/hibernate/cache/jbc/query/QueryResultsRegionImpl.java 2009-10-08 20:59:56 UTC (rev 17659)
+++ core/trunk/cache-jbosscache/src/main/java/org/hibernate/cache/jbc/query/QueryResultsRegionImpl.java 2009-10-08 22:40:42 UTC (rev 17660)
@@ -46,7 +46,8 @@
@CacheListener
public class QueryResultsRegionImpl extends TransactionalDataRegionAdapter implements QueryResultsRegion {
- public static final String QUERY_CACHE_LOCAL_ONLY_PROP = "hibernate.cache.region.jbc2.query.localonly";
+ public static final String QUERY_CACHE_LOCAL_ONLY_PROP = "hibernate.cache.jbc.query.localonly";
+ public static final String LEGACY_QUERY_CACHE_LOCAL_ONLY_PROP = "hibernate.cache.region.jbc2.query.localonly";
public static final String TYPE = "QUERY";
/**
@@ -72,9 +73,15 @@
if (!localOnly) {
// We don't want to waste effort setting an option if JBC is
// already in LOCAL mode. If JBC is REPL_(A)SYNC then check
- // if they passed an config option to disable query replication
- localOnly = CacheHelper.isClusteredReplication(jbcCache)
- && PropertiesHelper.getBoolean(QUERY_CACHE_LOCAL_ONLY_PROP, properties, false);
+ // if they passed an config option to disable query replication
+ if (CacheHelper.isClusteredReplication(jbcCache)) {
+ if (properties.containsKey(QUERY_CACHE_LOCAL_ONLY_PROP)) {
+ localOnly = PropertiesHelper.getBoolean(QUERY_CACHE_LOCAL_ONLY_PROP, properties, false);
+ }
+ else {
+ localOnly = PropertiesHelper.getBoolean(LEGACY_QUERY_CACHE_LOCAL_ONLY_PROP, properties, false);
+ }
+ }
}
}
14 years, 7 months
Hibernate SVN: r17659 - core/trunk/cache-jbosscache/src/main/java/org/hibernate/cache/jbc/access.
by hibernate-commits@lists.jboss.org
Author: bstansberry(a)jboss.com
Date: 2009-10-08 16:59:56 -0400 (Thu, 08 Oct 2009)
New Revision: 17659
Modified:
core/trunk/cache-jbosscache/src/main/java/org/hibernate/cache/jbc/access/OptimisticTransactionalAccessDelegate.java
core/trunk/cache-jbosscache/src/main/java/org/hibernate/cache/jbc/access/TransactionalAccessDelegate.java
Log:
[HHH-4484] When JBoss Cache is configured for INVALIDATION don't send cluster message on entity insert
Modified: core/trunk/cache-jbosscache/src/main/java/org/hibernate/cache/jbc/access/OptimisticTransactionalAccessDelegate.java
===================================================================
--- core/trunk/cache-jbosscache/src/main/java/org/hibernate/cache/jbc/access/OptimisticTransactionalAccessDelegate.java 2009-10-08 19:43:00 UTC (rev 17658)
+++ core/trunk/cache-jbosscache/src/main/java/org/hibernate/cache/jbc/access/OptimisticTransactionalAccessDelegate.java 2009-10-08 20:59:56 UTC (rev 17659)
@@ -102,6 +102,9 @@
region.ensureRegionRootExists();
Option opt = getDataVersionOption(version, null);
+ if (this.invalidation) {
+ opt.setCacheModeLocal(true);
+ }
CacheHelper.put(cache, regionFqn, key, value, opt);
return true;
}
Modified: core/trunk/cache-jbosscache/src/main/java/org/hibernate/cache/jbc/access/TransactionalAccessDelegate.java
===================================================================
--- core/trunk/cache-jbosscache/src/main/java/org/hibernate/cache/jbc/access/TransactionalAccessDelegate.java 2009-10-08 19:43:00 UTC (rev 17658)
+++ core/trunk/cache-jbosscache/src/main/java/org/hibernate/cache/jbc/access/TransactionalAccessDelegate.java 2009-10-08 20:59:56 UTC (rev 17659)
@@ -33,6 +33,7 @@
import org.hibernate.cache.jbc.util.CacheHelper;
import org.jboss.cache.Cache;
import org.jboss.cache.Fqn;
+import org.jboss.cache.config.Option;
/**
* Defines the strategy for transactional access to entity or collection data in
@@ -49,6 +50,7 @@
protected final Cache cache;
protected final Fqn regionFqn;
+ protected final boolean invalidation;
protected final BasicRegionAdapter region;
protected final PutFromLoadValidator putValidator;
@@ -57,6 +59,7 @@
this.cache = adapter.getCacheInstance();
this.regionFqn = adapter.getRegionFqn();
this.putValidator = validator;
+ this.invalidation = CacheHelper.isClusteredInvalidation(this.cache);
}
public Object get(Object key, long txTimestamp) throws CacheException {
@@ -125,8 +128,14 @@
return false;
region.ensureRegionRootExists();
-
- CacheHelper.put(cache, regionFqn, key, value);
+ if (invalidation) {
+ Option opt = new Option();
+ opt.setCacheModeLocal(true);
+ CacheHelper.put(cache, regionFqn, key, value, opt);
+ }
+ else {
+ CacheHelper.put(cache, regionFqn, key, value);
+ }
return true;
}
14 years, 7 months
Hibernate SVN: r17658 - core/trunk/cache-jbosscache/src/main/java/org/hibernate/cache/jbc/access.
by hibernate-commits@lists.jboss.org
Author: bstansberry(a)jboss.com
Date: 2009-10-08 15:43:00 -0400 (Thu, 08 Oct 2009)
New Revision: 17658
Modified:
core/trunk/cache-jbosscache/src/main/java/org/hibernate/cache/jbc/access/PutFromLoadValidator.java
Log:
Fix code style
Modified: core/trunk/cache-jbosscache/src/main/java/org/hibernate/cache/jbc/access/PutFromLoadValidator.java
===================================================================
--- core/trunk/cache-jbosscache/src/main/java/org/hibernate/cache/jbc/access/PutFromLoadValidator.java 2009-10-08 17:50:07 UTC (rev 17657)
+++ core/trunk/cache-jbosscache/src/main/java/org/hibernate/cache/jbc/access/PutFromLoadValidator.java 2009-10-08 19:43:00 UTC (rev 17658)
@@ -39,7 +39,6 @@
import org.hibernate.cache.CacheException;
-
/**
* Encapsulates logic to allow a {@link TransactionalAccessDelegate} to determine
* whether a {@link TransactionalAccessDelegate#putFromLoad(Object, Object, long, Object, boolean)
@@ -52,443 +51,450 @@
*
* @version $Revision: $
*/
-public class PutFromLoadValidator
-{
- /**
- * Period in ms after a removal during which a call to {@link #isPutValid(Object)}
- * that hasn't been {@link #registerPendingPut(Object) pre-registered}
- * (aka a "naked put") will return false.
- */
- public static final long NAKED_PUT_INVALIDATION_PERIOD = 10 * 1000;
-
- /** Period after which a pending put is placed in the over-age queue */
- private static final long PENDING_PUT_OVERAGE_PERIOD = 5 * 1000;
-
- /** Period before which we stop trying to clean out pending puts */
- private static final long PENDING_PUT_RECENT_PERIOD = 2 * 1000;
-
- /** Period after which a pending put is never expected to come in
- * and should be cleaned */
- private static final long MAX_PENDING_PUT_DELAY = 2 * 60 * 1000;
-
- /** Used to determine whether the owner of a pending put is a thread or a transaction */
- private final TransactionManager transactionManager;
-
- private final long nakedPutInvalidationPeriod;
- private final long pendingPutOveragePeriod;
- private final long pendingPutRecentPeriod;
- private final long maxPendingPutDelay;
-
- /**
- * Registry of expected, future, isPutValid calls. If a key+owner is registered
- * in this map, it is not a "naked put" and is allowed to proceed.
- */
- private final ConcurrentMap<Object, PendingPutMap> pendingPuts =
- new ConcurrentHashMap<Object, PendingPutMap>();
- /** List of pending puts. Used to ensure we don't leak memory via the pendingPuts map */
- private final List<WeakReference<PendingPut>> pendingQueue = new LinkedList<WeakReference<PendingPut>>();
- /** Separate list of pending puts that haven't been resolved within PENDING_PUT_OVERAGE_PERIOD.
- * Used to ensure we don't leak memory via the pendingPuts map.
- * Tracked separately from more recent pending puts for efficiency reasons. */
- private final List<WeakReference<PendingPut>> overagePendingQueue = new LinkedList<WeakReference<PendingPut>>();
- /** Lock controlling access to pending put queues */
- private final Lock pendingLock = new ReentrantLock();
- private final ConcurrentMap<Object, Long> recentRemovals = new ConcurrentHashMap<Object, Long>();
- /** List of recent removals. Used to ensure we don't leak memory via the recentRemovals map */
- private final List<RecentRemoval> removalsQueue = new LinkedList<RecentRemoval>();
- /** The time when the first element in removalsQueue will expire. No reason to do
- * housekeeping on the queue before this time. */
- private volatile long earliestRemovalTimestamp;
- /** Lock controlling access to removalsQueue */
- private final Lock removalsLock = new ReentrantLock();
-
- /**
- * The time of the last call to regionRemoved(), plus NAKED_PUT_INVALIDATION_PERIOD.
- * All naked puts will be rejected until the current time is greater than this value.
- */
- private volatile long invalidationTimestamp;
-
- /**
- * Creates a new PutFromLoadValidator.
- *
- * @param transactionManager transaction manager to use to associated changes with a transaction;
- * may be <code>null</code>
- */
- public PutFromLoadValidator(TransactionManager transactionManager) {
- this(transactionManager, NAKED_PUT_INVALIDATION_PERIOD, PENDING_PUT_OVERAGE_PERIOD,
- PENDING_PUT_RECENT_PERIOD, MAX_PENDING_PUT_DELAY);
- }
-
- /** Constructor variant for use by unit tests; allows control of various timeouts by the test. */
- protected PutFromLoadValidator(TransactionManager transactionManager,
- long nakedPutInvalidationPeriod, long pendingPutOveragePeriod,
- long pendingPutRecentPeriod, long maxPendingPutDelay) {
- this.transactionManager = transactionManager;
- this.nakedPutInvalidationPeriod = nakedPutInvalidationPeriod;
- this.pendingPutOveragePeriod = pendingPutOveragePeriod;
- this.pendingPutRecentPeriod = pendingPutRecentPeriod;
- this.maxPendingPutDelay = maxPendingPutDelay;
- }
+public class PutFromLoadValidator {
+ /**
+ * Period in ms after a removal during which a call to
+ * {@link #isPutValid(Object)} that hasn't been
+ * {@link #registerPendingPut(Object) pre-registered} (aka a "naked put")
+ * will return false.
+ */
+ public static final long NAKED_PUT_INVALIDATION_PERIOD = 10 * 1000;
- // ----------------------------------------------------------------- Public
-
- public boolean isPutValid(Object key)
- {
- boolean valid = false;
- long now = System.currentTimeMillis();
-
- PendingPutMap pending = pendingPuts.get(key);
- if (pending != null) {
- synchronized (pending) {
- PendingPut toCancel = pending.remove(getOwnerForPut());
- valid = toCancel != null;
- if (valid) {
- toCancel.completed = true;
- if (pending.size() == 0) {
- pendingPuts.remove(key);
- }
- }
- }
- }
-
- if (!valid) {
- if (now > invalidationTimestamp) {
- Long removedTime = recentRemovals.get(key);
- if (removedTime == null || now > removedTime.longValue()) {
- valid = true;
- }
- }
- }
-
- cleanOutdatedPendingPuts(now, true);
-
- return valid;
- }
+ /** Period after which a pending put is placed in the over-age queue */
+ private static final long PENDING_PUT_OVERAGE_PERIOD = 5 * 1000;
- public void keyRemoved(Object key)
- {
- // Invalidate any pending puts
- pendingPuts.remove(key);
-
- // Record when this occurred to invalidate later naked puts
- RecentRemoval removal = new RecentRemoval(key, this.nakedPutInvalidationPeriod);
- recentRemovals.put(key, removal.timestamp);
-
- // Don't let recentRemovals map become a memory leak
- RecentRemoval toClean = null;
- boolean attemptClean = removal.timestamp.longValue() > earliestRemovalTimestamp;
- removalsLock.lock();
- try {
- removalsQueue.add(removal);
-
- if (attemptClean) {
- if (removalsQueue.size() > 1) { // we have at least one as we just added it
- toClean = removalsQueue.remove(0);
- }
- earliestRemovalTimestamp = removalsQueue.get(0).timestamp.longValue();
- }
- }
- finally {
- removalsLock.unlock();
- }
-
- if (toClean != null) {
- Long cleaned = recentRemovals.get(toClean.key);
- if (cleaned != null && cleaned.equals(toClean.timestamp)) {
- cleaned = recentRemovals.remove(toClean.key);
- if (cleaned != null && cleaned.equals(toClean.timestamp) == false) {
- // Oops; removed the wrong timestamp; restore it
- recentRemovals.putIfAbsent(toClean.key, cleaned);
- }
- }
- }
- }
+ /** Period before which we stop trying to clean out pending puts */
+ private static final long PENDING_PUT_RECENT_PERIOD = 2 * 1000;
- public void regionRemoved()
- {
- invalidationTimestamp = System.currentTimeMillis() + this.nakedPutInvalidationPeriod;
- pendingLock.lock();
- try {
- removalsLock.lock();
- try {
- pendingPuts.clear();
- pendingQueue.clear();
- overagePendingQueue.clear();
- recentRemovals.clear();
- removalsQueue.clear();
- earliestRemovalTimestamp = invalidationTimestamp;
-
- }
- finally {
- removalsLock.unlock();
- }
- }
- finally {
- pendingLock.unlock();
- }
- }
+ /**
+ * Period after which a pending put is never expected to come in and should
+ * be cleaned
+ */
+ private static final long MAX_PENDING_PUT_DELAY = 2 * 60 * 1000;
- /**
- * Notifies this validator that it is expected that a database read followed by a
- * subsequent {@link #isPutValid(Object)} call will occur. The intent is this method
- * would be called following a cache miss wherein it is expected that a database
- * read plus cache put will occur. Calling this method allows the validator to treat
- * the subsequent <code>isPutValid</code> as if the database read occurred when
- * this method was invoked. This allows the validator to compare the timestamp of
- * this call against the timestamp of subsequent removal notifications. A put that
- * occurs without this call preceding it is "naked"; i.e the validator must assume
- * the put is not valid if any relevant removal has occurred within
- * {@link #NAKED_PUT_INVALIDATION_PERIOD} milliseconds.
- *
- * @param key key that will be used for subsequent put
- */
- public void registerPendingPut(Object key)
- {
- PendingPut pendingPut = new PendingPut(key, getOwnerForPut());
- PendingPutMap pendingForKey = new PendingPutMap();
- synchronized (pendingForKey) {
- for (;;) {
- PendingPutMap existing = pendingPuts.putIfAbsent(key, pendingForKey);
- if (existing != null && existing != pendingForKey) {
- synchronized (existing) {
- existing.put(pendingPut);
- PendingPutMap doublecheck = pendingPuts.putIfAbsent(key, existing);
- if (doublecheck == null || doublecheck == existing) {
- break;
- }
- // else we hit a race and need to loop to try again
- }
- }
- else {
- pendingForKey.put(pendingPut);
- break;
- }
- }
- }
-
- // Guard against memory leaks
- preventOutdatedPendingPuts(pendingPut);
- }
- // -------------------------------------------------------------- Protected
-
- /** Only for use by unit tests; may be removed at any time */
- protected int getPendingPutQueueLength() {
- pendingLock.lock();
- try {
- return pendingQueue.size();
- }
- finally {
- pendingLock.unlock();
- }
- }
-
- /** Only for use by unit tests; may be removed at any time */
- protected int getOveragePendingPutQueueLength() {
- pendingLock.lock();
- try {
- return overagePendingQueue.size();
- }
- finally {
- pendingLock.unlock();
- }
- }
-
- /** Only for use by unit tests; may be removed at any time */
- protected int getRemovalQueueLength() {
- removalsLock.lock();
- try {
- return removalsQueue.size();
- }
- finally {
- removalsLock.unlock();
- }
- }
- // ---------------------------------------------------------------- Private
+ /**
+ * Used to determine whether the owner of a pending put is a thread or a
+ * transaction
+ */
+ private final TransactionManager transactionManager;
- private Object getOwnerForPut()
- {
- Transaction tx = null;
- try {
- if (transactionManager != null) {
- tx = transactionManager.getTransaction();
- }
- } catch (SystemException se) {
- throw new CacheException("Could not obtain transaction", se);
- }
- return tx == null ? Thread.currentThread() : tx;
-
- }
-
- private void preventOutdatedPendingPuts(PendingPut pendingPut)
- {
- pendingLock.lock();
- try {
- pendingQueue.add(new WeakReference<PendingPut>(pendingPut));
- cleanOutdatedPendingPuts(pendingPut.timestamp, false);
- }
- finally {
- pendingLock.unlock();
- }
- }
+ private final long nakedPutInvalidationPeriod;
+ private final long pendingPutOveragePeriod;
+ private final long pendingPutRecentPeriod;
+ private final long maxPendingPutDelay;
- private void cleanOutdatedPendingPuts(long now, boolean lock)
- {
-
- PendingPut toClean = null;
- if (lock) {
- pendingLock.lock();
- }
- try {
-
- // Clean items out of the basic queue
-
- long overaged = now - this.pendingPutOveragePeriod;
- long recent = now - this.pendingPutRecentPeriod;
-
- int pos = 0;
- while (pendingQueue.size() > pos) {
- WeakReference<PendingPut> ref = pendingQueue.get(pos);
- PendingPut item = ref.get();
- if (item == null || item.completed) {
- pendingQueue.remove(pos);
- }
- else if (item.timestamp < overaged) {
- // Potential leak; move to the overaged queued
- pendingQueue.remove(pos);
- overagePendingQueue.add(ref);
- }
- else if (item.timestamp >= recent) {
- // Don't waste time on very recent items
- break;
- }
- else if (pos > 2) {
- // Don't spend too much time getting nowhere
- break;
- }
- else {
- // Move on to the next item
- pos++;
- }
- }
-
- // Process the overage queue until we find an item to clean
- // or an incomplete item that hasn't aged out
- long mustCleanTime = now - this.maxPendingPutDelay;
-
- while (overagePendingQueue.size() > 0) {
- WeakReference<PendingPut> ref = overagePendingQueue.get(0);
- PendingPut item = ref.get();
- if (item == null || item.completed) {
- overagePendingQueue.remove(0);
- }
- else {
- if (item.timestamp < mustCleanTime) {
- overagePendingQueue.remove(0);
- toClean = item;
- }
- break;
- }
- }
- }
- finally {
- if (lock) {
- pendingLock.unlock();
- }
- }
-
- // We've found a pendingPut that never happened; clean it up
- if (toClean != null) {
- PendingPutMap map = pendingPuts.get(toClean.key);
- if (map != null) {
- synchronized (map) {
- PendingPut cleaned = map.remove(toClean.owner);
- if (toClean.equals(cleaned) == false) {
- // Oops. Restore it.
- map.put(cleaned);
- }
- else if (map.size() == 0) {
- pendingPuts.remove(toClean.key);
- }
- }
- }
- }
-
- }
-
- /**
- * Lazy-initialization map for PendingPut. Optimized
- * for the expected usual case where only a single put
- * is pending for a given key.
- *
- * This class is NOT THREAD SAFE. All operations on it
- * must be performed with the object monitor held.
- */
- private static class PendingPutMap {
- private PendingPut singlePendingPut;
- private Map<Object, PendingPut> fullMap;
-
- public void put(PendingPut pendingPut)
- {
- if (singlePendingPut == null) {
- if (fullMap == null) {
- // initial put
- singlePendingPut = pendingPut;
- }
- else {
- fullMap.put(pendingPut.owner, pendingPut);
- }
- }
- else {
- // 2nd put; need a map
- fullMap = new HashMap<Object, PendingPut>(4);
- fullMap.put(singlePendingPut.owner, singlePendingPut);
- singlePendingPut = null;
- fullMap.put(pendingPut.owner, pendingPut);
- }
- }
+ /**
+ * Registry of expected, future, isPutValid calls. If a key+owner is
+ * registered in this map, it is not a "naked put" and is allowed to
+ * proceed.
+ */
+ private final ConcurrentMap<Object, PendingPutMap> pendingPuts = new ConcurrentHashMap<Object, PendingPutMap>();
+ /**
+ * List of pending puts. Used to ensure we don't leak memory via the
+ * pendingPuts map
+ */
+ private final List<WeakReference<PendingPut>> pendingQueue = new LinkedList<WeakReference<PendingPut>>();
+ /**
+ * Separate list of pending puts that haven't been resolved within
+ * PENDING_PUT_OVERAGE_PERIOD. Used to ensure we don't leak memory via the
+ * pendingPuts map. Tracked separately from more recent pending puts for
+ * efficiency reasons.
+ */
+ private final List<WeakReference<PendingPut>> overagePendingQueue = new LinkedList<WeakReference<PendingPut>>();
+ /** Lock controlling access to pending put queues */
+ private final Lock pendingLock = new ReentrantLock();
+ private final ConcurrentMap<Object, Long> recentRemovals = new ConcurrentHashMap<Object, Long>();
+ /**
+ * List of recent removals. Used to ensure we don't leak memory via the
+ * recentRemovals map
+ */
+ private final List<RecentRemoval> removalsQueue = new LinkedList<RecentRemoval>();
+ /**
+ * The time when the first element in removalsQueue will expire. No reason
+ * to do housekeeping on the queue before this time.
+ */
+ private volatile long earliestRemovalTimestamp;
+ /** Lock controlling access to removalsQueue */
+ private final Lock removalsLock = new ReentrantLock();
- public PendingPut remove(Object ownerForPut)
- {
- PendingPut removed = null;
- if (fullMap == null) {
- if (singlePendingPut != null && singlePendingPut.owner.equals(ownerForPut)) {
- removed = singlePendingPut;
- singlePendingPut = null;
- }
- }
- else {
- removed = fullMap.remove(ownerForPut);
- }
- return removed;
- }
+ /**
+ * The time of the last call to regionRemoved(), plus
+ * NAKED_PUT_INVALIDATION_PERIOD. All naked puts will be rejected until the
+ * current time is greater than this value.
+ */
+ private volatile long invalidationTimestamp;
- public int size()
- {
- return fullMap == null ? (singlePendingPut == null ? 0 : 1) : fullMap.size();
- }
- }
-
- private static class PendingPut {
- private final Object key;
- private final Object owner;
- private final long timestamp = System.currentTimeMillis();
- private volatile boolean completed;
-
- private PendingPut(Object key, Object owner) {
- this.key = key;
- this.owner = owner;
- }
-
- }
-
- private static class RecentRemoval {
- private final Object key;
- private final Long timestamp;
-
- private RecentRemoval(Object key, long nakedPutInvalidationPeriod) {
- this.key = key;
- timestamp = Long.valueOf(System.currentTimeMillis() + nakedPutInvalidationPeriod);
- }
- }
-
+ /**
+ * Creates a new PutFromLoadValidator.
+ *
+ * @param transactionManager
+ * transaction manager to use to associated changes with a
+ * transaction; may be <code>null</code>
+ */
+ public PutFromLoadValidator(TransactionManager transactionManager) {
+ this(transactionManager, NAKED_PUT_INVALIDATION_PERIOD,
+ PENDING_PUT_OVERAGE_PERIOD, PENDING_PUT_RECENT_PERIOD,
+ MAX_PENDING_PUT_DELAY);
+ }
+
+ /**
+ * Constructor variant for use by unit tests; allows control of various
+ * timeouts by the test.
+ */
+ protected PutFromLoadValidator(TransactionManager transactionManager,
+ long nakedPutInvalidationPeriod, long pendingPutOveragePeriod,
+ long pendingPutRecentPeriod, long maxPendingPutDelay) {
+ this.transactionManager = transactionManager;
+ this.nakedPutInvalidationPeriod = nakedPutInvalidationPeriod;
+ this.pendingPutOveragePeriod = pendingPutOveragePeriod;
+ this.pendingPutRecentPeriod = pendingPutRecentPeriod;
+ this.maxPendingPutDelay = maxPendingPutDelay;
+ }
+
+ // ----------------------------------------------------------------- Public
+
+ public boolean isPutValid(Object key) {
+ boolean valid = false;
+ long now = System.currentTimeMillis();
+
+ PendingPutMap pending = pendingPuts.get(key);
+ if (pending != null) {
+ synchronized (pending) {
+ PendingPut toCancel = pending.remove(getOwnerForPut());
+ valid = toCancel != null;
+ if (valid) {
+ toCancel.completed = true;
+ if (pending.size() == 0) {
+ pendingPuts.remove(key);
+ }
+ }
+ }
+ }
+
+ if (!valid) {
+ if (now > invalidationTimestamp) {
+ Long removedTime = recentRemovals.get(key);
+ if (removedTime == null || now > removedTime.longValue()) {
+ valid = true;
+ }
+ }
+ }
+
+ cleanOutdatedPendingPuts(now, true);
+
+ return valid;
+ }
+
+ public void keyRemoved(Object key) {
+ // Invalidate any pending puts
+ pendingPuts.remove(key);
+
+ // Record when this occurred to invalidate later naked puts
+ RecentRemoval removal = new RecentRemoval(key,
+ this.nakedPutInvalidationPeriod);
+ recentRemovals.put(key, removal.timestamp);
+
+ // Don't let recentRemovals map become a memory leak
+ RecentRemoval toClean = null;
+ boolean attemptClean = removal.timestamp.longValue() > earliestRemovalTimestamp;
+ removalsLock.lock();
+ try {
+ removalsQueue.add(removal);
+
+ if (attemptClean) {
+ if (removalsQueue.size() > 1) { // we have at least one as we
+ // just added it
+ toClean = removalsQueue.remove(0);
+ }
+ earliestRemovalTimestamp = removalsQueue.get(0).timestamp
+ .longValue();
+ }
+ } finally {
+ removalsLock.unlock();
+ }
+
+ if (toClean != null) {
+ Long cleaned = recentRemovals.get(toClean.key);
+ if (cleaned != null && cleaned.equals(toClean.timestamp)) {
+ cleaned = recentRemovals.remove(toClean.key);
+ if (cleaned != null
+ && cleaned.equals(toClean.timestamp) == false) {
+ // Oops; removed the wrong timestamp; restore it
+ recentRemovals.putIfAbsent(toClean.key, cleaned);
+ }
+ }
+ }
+ }
+
+ public void regionRemoved() {
+ invalidationTimestamp = System.currentTimeMillis()
+ + this.nakedPutInvalidationPeriod;
+ pendingLock.lock();
+ try {
+ removalsLock.lock();
+ try {
+ pendingPuts.clear();
+ pendingQueue.clear();
+ overagePendingQueue.clear();
+ recentRemovals.clear();
+ removalsQueue.clear();
+ earliestRemovalTimestamp = invalidationTimestamp;
+
+ } finally {
+ removalsLock.unlock();
+ }
+ } finally {
+ pendingLock.unlock();
+ }
+ }
+
+ /**
+ * Notifies this validator that it is expected that a database read followed
+ * by a subsequent {@link #isPutValid(Object)} call will occur. The intent
+ * is this method would be called following a cache miss wherein it is
+ * expected that a database read plus cache put will occur. Calling this
+ * method allows the validator to treat the subsequent
+ * <code>isPutValid</code> as if the database read occurred when this method
+ * was invoked. This allows the validator to compare the timestamp of this
+ * call against the timestamp of subsequent removal notifications. A put
+ * that occurs without this call preceding it is "naked"; i.e the validator
+ * must assume the put is not valid if any relevant removal has occurred
+ * within {@link #NAKED_PUT_INVALIDATION_PERIOD} milliseconds.
+ *
+ * @param key
+ * key that will be used for subsequent put
+ */
+ public void registerPendingPut(Object key) {
+ PendingPut pendingPut = new PendingPut(key, getOwnerForPut());
+ PendingPutMap pendingForKey = new PendingPutMap();
+ synchronized (pendingForKey) {
+ for (;;) {
+ PendingPutMap existing = pendingPuts.putIfAbsent(key,
+ pendingForKey);
+ if (existing != null && existing != pendingForKey) {
+ synchronized (existing) {
+ existing.put(pendingPut);
+ PendingPutMap doublecheck = pendingPuts.putIfAbsent(
+ key, existing);
+ if (doublecheck == null || doublecheck == existing) {
+ break;
+ }
+ // else we hit a race and need to loop to try again
+ }
+ } else {
+ pendingForKey.put(pendingPut);
+ break;
+ }
+ }
+ }
+
+ // Guard against memory leaks
+ preventOutdatedPendingPuts(pendingPut);
+ }
+
+ // -------------------------------------------------------------- Protected
+
+ /** Only for use by unit tests; may be removed at any time */
+ protected int getPendingPutQueueLength() {
+ pendingLock.lock();
+ try {
+ return pendingQueue.size();
+ } finally {
+ pendingLock.unlock();
+ }
+ }
+
+ /** Only for use by unit tests; may be removed at any time */
+ protected int getOveragePendingPutQueueLength() {
+ pendingLock.lock();
+ try {
+ return overagePendingQueue.size();
+ } finally {
+ pendingLock.unlock();
+ }
+ }
+
+ /** Only for use by unit tests; may be removed at any time */
+ protected int getRemovalQueueLength() {
+ removalsLock.lock();
+ try {
+ return removalsQueue.size();
+ } finally {
+ removalsLock.unlock();
+ }
+ }
+
+ // ---------------------------------------------------------------- Private
+
+ private Object getOwnerForPut() {
+ Transaction tx = null;
+ try {
+ if (transactionManager != null) {
+ tx = transactionManager.getTransaction();
+ }
+ } catch (SystemException se) {
+ throw new CacheException("Could not obtain transaction", se);
+ }
+ return tx == null ? Thread.currentThread() : tx;
+
+ }
+
+ private void preventOutdatedPendingPuts(PendingPut pendingPut) {
+ pendingLock.lock();
+ try {
+ pendingQueue.add(new WeakReference<PendingPut>(pendingPut));
+ cleanOutdatedPendingPuts(pendingPut.timestamp, false);
+ } finally {
+ pendingLock.unlock();
+ }
+ }
+
+ private void cleanOutdatedPendingPuts(long now, boolean lock) {
+
+ PendingPut toClean = null;
+ if (lock) {
+ pendingLock.lock();
+ }
+ try {
+
+ // Clean items out of the basic queue
+
+ long overaged = now - this.pendingPutOveragePeriod;
+ long recent = now - this.pendingPutRecentPeriod;
+
+ int pos = 0;
+ while (pendingQueue.size() > pos) {
+ WeakReference<PendingPut> ref = pendingQueue.get(pos);
+ PendingPut item = ref.get();
+ if (item == null || item.completed) {
+ pendingQueue.remove(pos);
+ } else if (item.timestamp < overaged) {
+ // Potential leak; move to the overaged queued
+ pendingQueue.remove(pos);
+ overagePendingQueue.add(ref);
+ } else if (item.timestamp >= recent) {
+ // Don't waste time on very recent items
+ break;
+ } else if (pos > 2) {
+ // Don't spend too much time getting nowhere
+ break;
+ } else {
+ // Move on to the next item
+ pos++;
+ }
+ }
+
+ // Process the overage queue until we find an item to clean
+ // or an incomplete item that hasn't aged out
+ long mustCleanTime = now - this.maxPendingPutDelay;
+
+ while (overagePendingQueue.size() > 0) {
+ WeakReference<PendingPut> ref = overagePendingQueue.get(0);
+ PendingPut item = ref.get();
+ if (item == null || item.completed) {
+ overagePendingQueue.remove(0);
+ } else {
+ if (item.timestamp < mustCleanTime) {
+ overagePendingQueue.remove(0);
+ toClean = item;
+ }
+ break;
+ }
+ }
+ } finally {
+ if (lock) {
+ pendingLock.unlock();
+ }
+ }
+
+ // We've found a pendingPut that never happened; clean it up
+ if (toClean != null) {
+ PendingPutMap map = pendingPuts.get(toClean.key);
+ if (map != null) {
+ synchronized (map) {
+ PendingPut cleaned = map.remove(toClean.owner);
+ if (toClean.equals(cleaned) == false) {
+ // Oops. Restore it.
+ map.put(cleaned);
+ } else if (map.size() == 0) {
+ pendingPuts.remove(toClean.key);
+ }
+ }
+ }
+ }
+
+ }
+
+ /**
+ * Lazy-initialization map for PendingPut. Optimized for the expected usual
+ * case where only a single put is pending for a given key.
+ *
+ * This class is NOT THREAD SAFE. All operations on it must be performed
+ * with the object monitor held.
+ */
+ private static class PendingPutMap {
+ private PendingPut singlePendingPut;
+ private Map<Object, PendingPut> fullMap;
+
+ public void put(PendingPut pendingPut) {
+ if (singlePendingPut == null) {
+ if (fullMap == null) {
+ // initial put
+ singlePendingPut = pendingPut;
+ } else {
+ fullMap.put(pendingPut.owner, pendingPut);
+ }
+ } else {
+ // 2nd put; need a map
+ fullMap = new HashMap<Object, PendingPut>(4);
+ fullMap.put(singlePendingPut.owner, singlePendingPut);
+ singlePendingPut = null;
+ fullMap.put(pendingPut.owner, pendingPut);
+ }
+ }
+
+ public PendingPut remove(Object ownerForPut) {
+ PendingPut removed = null;
+ if (fullMap == null) {
+ if (singlePendingPut != null
+ && singlePendingPut.owner.equals(ownerForPut)) {
+ removed = singlePendingPut;
+ singlePendingPut = null;
+ }
+ } else {
+ removed = fullMap.remove(ownerForPut);
+ }
+ return removed;
+ }
+
+ public int size() {
+ return fullMap == null ? (singlePendingPut == null ? 0 : 1)
+ : fullMap.size();
+ }
+ }
+
+ private static class PendingPut {
+ private final Object key;
+ private final Object owner;
+ private final long timestamp = System.currentTimeMillis();
+ private volatile boolean completed;
+
+ private PendingPut(Object key, Object owner) {
+ this.key = key;
+ this.owner = owner;
+ }
+
+ }
+
+ private static class RecentRemoval {
+ private final Object key;
+ private final Long timestamp;
+
+ private RecentRemoval(Object key, long nakedPutInvalidationPeriod) {
+ this.key = key;
+ timestamp = Long.valueOf(System.currentTimeMillis()
+ + nakedPutInvalidationPeriod);
+ }
+ }
+
}
14 years, 7 months