Hibernate SVN: r17693 - core/branches.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2009-10-12 11:34:58 -0400 (Mon, 12 Oct 2009)
New Revision: 17693
Added:
core/branches/gradle/
Log:
create a branch of trunk for Gradle PoC
Copied: core/branches/gradle (from rev 17692, core/trunk)
14 years, 8 months
Hibernate SVN: r17692 - in core/trunk/annotations/src/test/java/org/hibernate/test/annotations: lob and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2009-10-12 10:08:37 -0400 (Mon, 12 Oct 2009)
New Revision: 17692
Modified:
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/TestCase.java
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/lob/LobTest.java
Log:
HHH-4415
Made sure that the the superclass dialect is checked.
Did not apply provided patch though.
Modified: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/TestCase.java
===================================================================
--- core/trunk/annotations/src/test/java/org/hibernate/test/annotations/TestCase.java 2009-10-12 06:20:12 UTC (rev 17691)
+++ core/trunk/annotations/src/test/java/org/hibernate/test/annotations/TestCase.java 2009-10-12 14:08:37 UTC (rev 17692)
@@ -11,6 +11,9 @@
import java.util.HashSet;
import java.util.Set;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
import org.hibernate.HibernateException;
import org.hibernate.Interceptor;
import org.hibernate.Session;
@@ -21,18 +24,16 @@
import org.hibernate.dialect.Dialect;
import org.hibernate.jdbc.Work;
import org.hibernate.tool.hbm2ddl.SchemaExport;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
/**
* A base class for all tests.
- *
+ *
* @author Emmnauel Bernand
* @author Hardy Ferentschik
*/
public abstract class TestCase extends junit.framework.TestCase {
- public static final Logger log = LoggerFactory.getLogger(TestCase.class);
+ public static final Logger log = LoggerFactory.getLogger( TestCase.class );
private static SessionFactory sessions;
private static AnnotationConfiguration cfg;
@@ -46,27 +47,34 @@
private Method runMethod = null;
/**
- * Flag indicating whether the test should be skipped.
+ * Flag indicating whether the test should be run or skipped.
*/
- private boolean skip = false;
+ private boolean runTest = true;
+ /**
+ * List of required dialect for the current {@code runMethod}. If the list is empty any dialect is allowed.
+ * Otherwise the current dialect or a superclass of the current dialect must be in the list.
+ */
+ private final Set<Class<? extends Dialect>> requiredDialectList = new HashSet<Class<? extends Dialect>>();
+
public TestCase() {
super();
}
public TestCase(String x) {
- super(x);
+ super( x );
}
- protected void buildSessionFactory( Class<?>[] classes, String[] packages, String[] xmlFiles ) throws Exception {
+ protected void buildSessionFactory(Class<?>[] classes, String[] packages, String[] xmlFiles) throws Exception {
- if ( getSessions() != null )
+ if ( getSessions() != null ) {
getSessions().close();
+ }
try {
- setCfg(new AnnotationConfiguration());
- configure(cfg);
+ setCfg( new AnnotationConfiguration() );
+ configure( cfg );
if ( recreateSchema() ) {
- cfg.setProperty(Environment.HBM2DDL_AUTO, "create-drop");
+ cfg.setProperty( Environment.HBM2DDL_AUTO, "create-drop" );
}
for ( String aPackage : packages ) {
getCfg().addPackage( aPackage );
@@ -78,9 +86,10 @@
InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream( xmlFile );
getCfg().addInputStream( is );
}
- setDialect(Dialect.getDialect());
- setSessions(getCfg().buildSessionFactory( /* new TestInterceptor() */));
- } catch ( Exception e ) {
+ setDialect( Dialect.getDialect() );
+ setSessions( getCfg().buildSessionFactory( /* new TestInterceptor() */ ) );
+ }
+ catch ( Exception e ) {
e.printStackTrace();
throw e;
}
@@ -88,63 +97,85 @@
protected void setUp() throws Exception {
runMethod = findTestMethod();
- checkSkip(runMethod);
- if ( !skip ) {
+ setRunTestFlag( runMethod );
+ if ( runTest ) {
if ( getSessions() == null || lastTestClass != getClass() ) {
- buildSessionFactory(getMappings(), getAnnotatedPackages(), getXmlFiles());
+ buildSessionFactory( getMappings(), getAnnotatedPackages(), getXmlFiles() );
lastTestClass = getClass();
- } else {
+ }
+ else {
runSchemaGeneration();
}
}
}
-
+
protected void runTest() throws Throwable {
try {
- if ( !skip ) {
- runTestMethod(runMethod);
+ if ( runTest ) {
+ runTestMethod( runMethod );
handleUnclosedSession();
}
- } catch ( Throwable e ) {
- closeSession(e);
}
+ catch ( Throwable e ) {
+ closeSession( e );
+ }
}
- private void checkSkip( Method runMethod ) {
- Set<Class<? extends Dialect>> dialectList = new HashSet<Class<? extends Dialect>>();
+ private void setRunTestFlag(Method runMethod) {
+ updateRequiredDialectList( runMethod );
- RequiresDialect requiresDialectMethodAnn = runMethod.getAnnotation(RequiresDialect.class);
+ if ( runForCurrentDialect() ) {
+ runTest = true;
+ }
+ else {
+ log.warn(
+ "Skipping test {}, because test does not apply for dialect {}", runMethod.getName(), Dialect
+ .getDialect().getClass()
+ );
+ runTest = false;
+ }
+ }
+
+ private void updateRequiredDialectList(Method runMethod) {
+ requiredDialectList.clear();
+
+ RequiresDialect requiresDialectMethodAnn = runMethod.getAnnotation( RequiresDialect.class );
if ( requiresDialectMethodAnn != null ) {
Class<? extends Dialect>[] requiredDialects = requiresDialectMethodAnn.value();
- dialectList.addAll(Arrays.asList(requiredDialects));
+ requiredDialectList.addAll( Arrays.asList( requiredDialects ) );
}
- RequiresDialect requiresDialectClassAnn = getClass().getAnnotation(RequiresDialect.class);
+ RequiresDialect requiresDialectClassAnn = getClass().getAnnotation( RequiresDialect.class );
if ( requiresDialectClassAnn != null ) {
Class<? extends Dialect>[] requiredDialects = requiresDialectClassAnn.value();
- dialectList.addAll(Arrays.asList(requiredDialects));
+ requiredDialectList.addAll( Arrays.asList( requiredDialects ) );
}
+ }
- if ( (dialectList.isEmpty() || dialectList.contains(Dialect.getDialect().getClass())) && appliesTo(Dialect.getDialect()) ) {
- skip = false;
- } else {
- log.warn("Skipping test {}, because test does not apply for dialect {}", runMethod.getName(), Dialect
- .getDialect().getClass());
- skip = true;
+ protected boolean runForCurrentDialect() {
+ if ( requiredDialectList.isEmpty() ) {
+ return true;
}
+ else {
+ // check whether the current dialect is assignableFrom from any of the specified required dialects.
+ for ( Class<? extends Dialect> dialect : requiredDialectList ) {
+ if ( dialect.isAssignableFrom( Dialect.getDialect().getClass() ) ) {
+ return true;
+ }
+ }
+ return false;
+ }
}
-
- protected boolean appliesTo( Dialect dialect ) {
- return true;
- }
-
- private void runTestMethod( Method runMethod ) throws Throwable {
+
+ private void runTestMethod(Method runMethod) throws Throwable {
try {
- runMethod.invoke(this, new Class[0]);
- } catch ( InvocationTargetException e ) {
+ runMethod.invoke( this, new Class[0] );
+ }
+ catch ( InvocationTargetException e ) {
e.fillInStackTrace();
throw e.getTargetException();
- } catch ( IllegalAccessException e ) {
+ }
+ catch ( IllegalAccessException e ) {
e.fillInStackTrace();
throw e;
}
@@ -152,47 +183,53 @@
private Method findTestMethod() {
String fName = getName();
- assertNotNull(fName);
+ assertNotNull( fName );
Method runMethod = null;
try {
- runMethod = getClass().getMethod(fName, null);
- } catch ( NoSuchMethodException e ) {
- fail("Method \"" + fName + "\" not found");
+ runMethod = getClass().getMethod( fName, null );
}
- if ( !Modifier.isPublic(runMethod.getModifiers()) ) {
- fail("Method \"" + fName + "\" should be public");
+ catch ( NoSuchMethodException e ) {
+ fail( "Method \"" + fName + "\" not found" );
}
+ if ( !Modifier.isPublic( runMethod.getModifiers() ) ) {
+ fail( "Method \"" + fName + "\" should be public" );
+ }
return runMethod;
}
private void handleUnclosedSession() {
if ( session != null && session.isOpen() ) {
- if ( session.isConnected() )
- session.doWork(new RollbackWork());
+ if ( session.isConnected() ) {
+ session.doWork( new RollbackWork() );
+ }
session.close();
session = null;
- fail("unclosed session");
- } else {
+ fail( "unclosed session" );
+ }
+ else {
session = null;
}
}
- private void closeSession( Throwable e ) throws Throwable {
+ private void closeSession(Throwable e) throws Throwable {
try {
if ( session != null && session.isOpen() ) {
- if ( session.isConnected() )
- session.doWork(new RollbackWork());
+ if ( session.isConnected() ) {
+ session.doWork( new RollbackWork() );
+ }
session.close();
}
- } catch ( Exception ignore ) {
}
+ catch ( Exception ignore ) {
+ }
try {
if ( sessions != null ) {
sessions.close();
sessions = null;
}
- } catch ( Exception ignore ) {
}
+ catch ( Exception ignore ) {
+ }
throw e;
}
@@ -201,22 +238,22 @@
return session;
}
- public Session openSession( Interceptor interceptor ) throws HibernateException {
- session = getSessions().openSession(interceptor);
+ public Session openSession(Interceptor interceptor) throws HibernateException {
+ session = getSessions().openSession( interceptor );
return session;
}
protected abstract Class<?>[] getMappings();
protected String[] getAnnotatedPackages() {
- return new String[] {};
+ return new String[] { };
}
protected String[] getXmlFiles() {
- return new String[] {};
+ return new String[] { };
}
- private void setSessions( SessionFactory sessions ) {
+ private void setSessions(SessionFactory sessions) {
TestCase.sessions = sessions;
}
@@ -224,7 +261,7 @@
return sessions;
}
- private void setDialect( Dialect dialect ) {
+ private void setDialect(Dialect dialect) {
TestCase.dialect = dialect;
}
@@ -232,7 +269,7 @@
return dialect;
}
- protected static void setCfg( AnnotationConfiguration cfg ) {
+ protected static void setCfg(AnnotationConfiguration cfg) {
TestCase.cfg = cfg;
}
@@ -240,7 +277,7 @@
return cfg;
}
- protected void configure( Configuration cfg ) {
+ protected void configure(Configuration cfg) {
}
protected boolean recreateSchema() {
@@ -248,13 +285,13 @@
}
protected void runSchemaGeneration() {
- SchemaExport export = new SchemaExport(cfg);
- export.create(true, true);
+ SchemaExport export = new SchemaExport( cfg );
+ export.create( true, true );
}
public class RollbackWork implements Work {
- public void execute( Connection connection ) throws SQLException {
+ public void execute(Connection connection) throws SQLException {
connection.rollback();
}
}
Modified: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/lob/LobTest.java
===================================================================
--- core/trunk/annotations/src/test/java/org/hibernate/test/annotations/lob/LobTest.java 2009-10-12 06:20:12 UTC (rev 17691)
+++ core/trunk/annotations/src/test/java/org/hibernate/test/annotations/lob/LobTest.java 2009-10-12 14:08:37 UTC (rev 17692)
@@ -3,7 +3,6 @@
import org.hibernate.Session;
import org.hibernate.Transaction;
-import org.hibernate.dialect.Dialect;
import org.hibernate.test.annotations.TestCase;
/**
@@ -15,7 +14,7 @@
Editor editor = new Editor();
editor.setName( "O'Reilly" );
book.setEditor( editor );
- book.setCode2( new char[]{'r'} );
+ book.setCode2( new char[] { 'r' } );
Session s;
Transaction tx;
s = openSession();
@@ -25,7 +24,7 @@
s.close();
s = openSession();
tx = s.beginTransaction();
- Book loadedBook = (Book) s.get( Book.class, book.getId() );
+ Book loadedBook = ( Book ) s.get( Book.class, book.getId() );
assertNotNull( loadedBook.getEditor() );
assertEquals( book.getEditor().getName(), loadedBook.getEditor().getName() );
loadedBook.setEditor( null );
@@ -33,7 +32,7 @@
s.close();
s = openSession();
tx = s.beginTransaction();
- loadedBook = (Book) s.get( Book.class, book.getId() );
+ loadedBook = ( Book ) s.get( Book.class, book.getId() );
assertNull( loadedBook.getEditor() );
tx.commit();
s.close();
@@ -48,15 +47,15 @@
Book b = new Book();
b.setShortDescription( "Hibernate Bible" );
b.setFullText( "Hibernate in Action aims to..." );
- b.setCode( new Character[]{'a', 'b', 'c'} );
- b.setCode2( new char[]{'a', 'b', 'c'} );
+ b.setCode( new Character[] { 'a', 'b', 'c' } );
+ b.setCode2( new char[] { 'a', 'b', 'c' } );
s.persist( b );
tx.commit();
s.close();
s = openSession();
tx = s.beginTransaction();
- Book b2 = (Book) s.get( Book.class, b.getId() );
+ Book b2 = ( Book ) s.get( Book.class, b.getId() );
assertNotNull( b2 );
assertEquals( b2.getFullText(), b.getFullText() );
assertEquals( b2.getCode()[1].charValue(), b.getCode()[1].charValue() );
@@ -72,13 +71,13 @@
tx = s.beginTransaction();
CompiledCode cc = new CompiledCode();
Byte[] header = new Byte[2];
- header[0] = new Byte( (byte) 3 );
- header[1] = new Byte( (byte) 0 );
+ header[0] = new Byte( ( byte ) 3 );
+ header[1] = new Byte( ( byte ) 0 );
cc.setHeader( header );
int codeSize = 5;
byte[] full = new byte[codeSize];
- for ( int i = 0; i < codeSize ; i++ ) {
- full[i] = (byte) ( 1 + i );
+ for ( int i = 0; i < codeSize; i++ ) {
+ full[i] = ( byte ) ( 1 + i );
}
cc.setFullCode( full );
s.persist( cc );
@@ -86,7 +85,7 @@
s.close();
s = openSession();
tx = s.beginTransaction();
- CompiledCode recompiled = (CompiledCode) s.get( CompiledCode.class, cc.getId() );
+ CompiledCode recompiled = ( CompiledCode ) s.get( CompiledCode.class, cc.getId() );
assertEquals( recompiled.getHeader()[1], cc.getHeader()[1] );
assertEquals( recompiled.getFullCode()[codeSize - 1], cc.getFullCode()[codeSize - 1] );
tx.commit();
@@ -100,15 +99,15 @@
tx = s.beginTransaction();
CompiledCode cc = new CompiledCode();
byte[] metadata = new byte[2];
- metadata[0] = (byte) 3;
- metadata[1] = (byte) 0;
+ metadata[0] = ( byte ) 3;
+ metadata[1] = ( byte ) 0;
cc.setMetadata( metadata );
s.persist( cc );
tx.commit();
s.close();
s = openSession();
tx = s.beginTransaction();
- CompiledCode recompiled = (CompiledCode) s.get( CompiledCode.class, cc.getId() );
+ CompiledCode recompiled = ( CompiledCode ) s.get( CompiledCode.class, cc.getId() );
assertEquals( recompiled.getMetadata()[1], cc.getMetadata()[1] );
tx.commit();
s.close();
@@ -117,14 +116,14 @@
public LobTest(String x) {
super( x );
}
-
+
@Override
- protected boolean appliesTo(Dialect dialect) {
- return dialect.supportsExpectedLobUsagePattern();
+ protected boolean runForCurrentDialect() {
+ return super.runForCurrentDialect() && getDialect().supportsExpectedLobUsagePattern();
}
protected Class[] getMappings() {
- return new Class[]{
+ return new Class[] {
Book.class,
CompiledCode.class
};
14 years, 8 months
You've received a postcard
by 123greetings.com
Good day.
Your family member has sent you an ecard from 123greetings.com.
Send free ecards from 123greetings.com with your choice of colors, words and music.
Your ecard will be available with us for the next 30 days.
If you wish to keep the ecard longer, you may save it on your computer or take a print.
To view your ecard, open zip attached file.
14 years, 8 months
Hibernate SVN: r17691 - in sandbox/trunk/lobtest-ee5: lobtest-ear/src/main/application/META-INF and 5 other directories.
by hibernate-commits@lists.jboss.org
Author: dstephan
Date: 2009-10-12 02:20:12 -0400 (Mon, 12 Oct 2009)
New Revision: 17691
Added:
sandbox/trunk/lobtest-ee5/lobtest-ejb/src/main/resources/hibernate.properties
Removed:
sandbox/trunk/lobtest-ee5/lobtest-ear/src/main/application/META-INF/application.xml
Modified:
sandbox/trunk/lobtest-ee5/lobtest-ear/pom.xml
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/resources/META-INF/persistence.xml
sandbox/trunk/lobtest-ee5/lobtest-sar/src/main/resources/META-INF/jboss-service.xml
sandbox/trunk/lobtest-ee5/lobtest-web/src/main/webapp/basic.jsp
Log:
Updated to include deployment and tests for additional use cases.
Modified: sandbox/trunk/lobtest-ee5/lobtest-ear/pom.xml
===================================================================
--- sandbox/trunk/lobtest-ee5/lobtest-ear/pom.xml 2009-10-12 02:53:54 UTC (rev 17690)
+++ sandbox/trunk/lobtest-ee5/lobtest-ear/pom.xml 2009-10-12 06:20:12 UTC (rev 17691)
@@ -31,7 +31,7 @@
<artifactId>lobtest-web</artifactId>
</webModule>
</modules>
- <applicationXml>${project.build.directory}/application.xml</applicationXml>
+ <!-- <applicationXml>${project.build.directory}/application.xml</applicationXml> -->
</configuration>
</plugin>
</plugins>
Deleted: 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 2009-10-12 02:53:54 UTC (rev 17690)
+++ sandbox/trunk/lobtest-ee5/lobtest-ear/src/main/application/META-INF/application.xml 2009-10-12 06:20:12 UTC (rev 17691)
@@ -1,14 +0,0 @@
-<?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.war</web-uri>
- <context-root>lobtest-web</context-root>
- </web>
- </module>
-</application>
Modified: 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 2009-10-12 02:53:54 UTC (rev 17690)
+++ sandbox/trunk/lobtest-ee5/lobtest-ejb/src/main/java/com/redhat/gss/lobtest/ejb/LobTestServiceBean.java 2009-10-12 06:20:12 UTC (rev 17691)
@@ -24,7 +24,7 @@
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")
+ @PersistenceContext(unitName="lobtest-jpa")//(name="lobtest-jpa")
private EntityManager em;
public void runTests() {
Modified: 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 2009-10-12 02:53:54 UTC (rev 17690)
+++ sandbox/trunk/lobtest-ee5/lobtest-ejb/src/main/java/com/redhat/gss/lobtest/ejb/ThingService.java 2009-10-12 06:20:12 UTC (rev 17691)
@@ -16,5 +16,9 @@
public Thing findThingJPA(Long id);
+ public Thing findThingJPAjndi(Long id) throws Exception;
+
public Thing findThingHibernateMBean(Long id) throws Exception;
+
+ public Thing findThingJPAThruHibernate(Long id);
}
Modified: 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 2009-10-12 02:53:54 UTC (rev 17690)
+++ sandbox/trunk/lobtest-ee5/lobtest-ejb/src/main/java/com/redhat/gss/lobtest/ejb/ThingServiceBean.java 2009-10-12 06:20:12 UTC (rev 17691)
@@ -18,7 +18,7 @@
public class ThingServiceBean implements ThingService
{
- @PersistenceContext
+ @PersistenceContext(unitName="lobtest-jpa")
private EntityManager em;
@SuppressWarnings("unchecked")
@@ -34,6 +34,34 @@
return em.createQuery("from Thing").getResultList();
}
+ // Use Cae A-1
+ public Thing findThingJPA(Long id)
+ {
+ Thing t = em.getReference(Thing.class, id);
+ System.out.println("Thing: id=" + t.getId() + " name=" + t.getName() + " class=" + t.getClass());
+ return t;
+ }
+
+ //Use Case A-2
+ public Thing findThingJPAjndi(Long id) throws Exception
+ {
+ InitialContext ctx = new InitialContext();
+ EntityManager em = (EntityManager) ctx.lookup("persistence/EntityManager");
+ Thing t = em.getReference(Thing.class, id);
+ System.out.println("Thing: id=" + t.getId() + " name=" + t.getName() + " class=" + t.getClass());
+ return t;
+ }
+
+ //Use Case A-3
+ public Thing findThingJPAThruHibernate(Long id)
+ {
+ Session s = (Session)em.getDelegate();
+ Thing t = (Thing) s.load(Thing.class, id);
+ System.out.println("Thing: id=" + t.getId() + " name=" + t.getName() + " class=" + t.getClass());
+ return t;
+ }
+
+ // Use Case B-1
public Thing findThingHibernate(Long id)
{
Session s = HibernateUtil.getSession();
@@ -43,12 +71,13 @@
return t;
}
+ // Use Case B-2
public Thing findThingHibernateMBean(Long id) throws Exception
{
Thing t = null;
Session s = null;
InitialContext ctx = new InitialContext();
- SessionFactory sf = (SessionFactory) ctx.lookup("java:hibernate/SessionFactory");
+ SessionFactory sf = (SessionFactory) ctx.lookup("java:/hibernate/LobTestSessionFactory");
s = sf.getCurrentSession();
t = (Thing) s.load(Thing.class, id);
@@ -56,13 +85,7 @@
return t;
}
- public Thing findThingJPA(Long id)
- {
- Thing t = em.getReference(Thing.class, id);
- System.out.println("Thing: id=" + t.getId() + " name=" + t.getName() + " class=" + t.getClass());
- return t;
- }
-
+
public Thing setUp()
{
Thing t1 = new Thing(System.currentTimeMillis(), "One");
Modified: 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 2009-10-12 02:53:54 UTC (rev 17690)
+++ sandbox/trunk/lobtest-ee5/lobtest-ejb/src/main/resources/META-INF/persistence.xml 2009-10-12 06:20:12 UTC (rev 17691)
@@ -7,6 +7,16 @@
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect"/>
<property name="hibernate.hbm2ddl.auto" value="create-drop"/>
+ <!-- <property name="hibernate.bytecode.provide" value="javassist"/>-->
</properties>
</persistence-unit>
+ <persistence-unit name="lobtest-jpa-jndi">
+ <jta-data-source>java:/DefaultDS</jta-data-source>
+ <properties>
+ <property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect"/>
+ <property name="jboss.entity.manager.factory.jndi.name"
+ value="persistence/EntityManagerFactory" />
+ <property name="jboss.entity.manager.jndi.name" value="persistence/EntityManager"/>
+ </properties>
+ </persistence-unit>
</persistence>
\ No newline at end of file
Added: sandbox/trunk/lobtest-ee5/lobtest-ejb/src/main/resources/hibernate.properties
===================================================================
--- sandbox/trunk/lobtest-ee5/lobtest-ejb/src/main/resources/hibernate.properties (rev 0)
+++ sandbox/trunk/lobtest-ee5/lobtest-ejb/src/main/resources/hibernate.properties 2009-10-12 06:20:12 UTC (rev 17691)
@@ -0,0 +1 @@
+#hibernate.bytecode.provider=cglib
\ No newline at end of file
Modified: sandbox/trunk/lobtest-ee5/lobtest-sar/src/main/resources/META-INF/jboss-service.xml
===================================================================
--- sandbox/trunk/lobtest-ee5/lobtest-sar/src/main/resources/META-INF/jboss-service.xml 2009-10-12 02:53:54 UTC (rev 17690)
+++ sandbox/trunk/lobtest-ee5/lobtest-sar/src/main/resources/META-INF/jboss-service.xml 2009-10-12 06:20:12 UTC (rev 17691)
@@ -1,13 +1,13 @@
<?xml version="1.0"?>
<server>
- <mbean code="org.hibernate.jmx.HibernateService" name="jboss.jca:service=HibernateFactory,name=HibernateFactory">
+ <mbean code="org.hibernate.jmx.HibernateService" name="jboss.jca:service=HibernateFactory,name=LobTestHibernateFactory">
- <depends>jboss.jca:service=RARDeployer</depends>
+ <!-- <depends>jboss.jca:service=RARDeployer</depends>-->
<depends>jboss.jca:service=LocalTxCM,name=DefaultDS</depends>
<!-- Bind the Hibernate service to JNDI -->
- <attribute name="JndiName">java:/hibernate/SessionFactory</attribute>
+ <attribute name="JndiName">java:/hibernate/LobTestSessionFactory</attribute>
<!-- hibernate dialect -->
<property name="hibernate.dialect">org.hibernate.dialect.HSQLDialect</property>
Modified: sandbox/trunk/lobtest-ee5/lobtest-web/src/main/webapp/basic.jsp
===================================================================
--- sandbox/trunk/lobtest-ee5/lobtest-web/src/main/webapp/basic.jsp 2009-10-12 02:53:54 UTC (rev 17690)
+++ sandbox/trunk/lobtest-ee5/lobtest-web/src/main/webapp/basic.jsp 2009-10-12 06:20:12 UTC (rev 17691)
@@ -14,13 +14,35 @@
System.out.println("basic.jsp from query: Thing: id=" + t.getId() + " name=" + t.getName() + " class=" + t.getClass());
}
+ t = ts.findThingJPA(t.getId());
+ System.out.println("A-1 - basic.jsp from ts.findThingJPA(): Thing: id=" + t.getId() + " name=" + t.getName() + " class=" + t.getClass());
+ out.println("A-1 - basic.jsp from ts.findThingJPA(): Thing: id=" + t.getId() + " name=" + t.getName() + " class=" + t.getClass());
+ %>
+ </br>
+ <%
+ t = ts.findThingJPAjndi(t.getId());
+ System.out.println("A-2 - basic.jsp from ts.findJPAjndi(): Thing: id=" + t.getId() + " name=" + t.getName() + " class=" + t.getClass());
+ out.println("A-2 - basic.jsp from ts.findJPAjndi(): Thing: id=" + t.getId() + " name=" + t.getName() + " class=" + t.getClass());
+ %>
+ </br>
+ <%
+ t = ts.findThingJPAThruHibernate(t.getId());
+ System.out.println("A-3 - basic.jsp from ts.findThingJPAThruHibernate(): Thing: id=" + t.getId() + " name=" + t.getName() + " class=" + t.getClass());
+ out.println("A-3 - basic.jsp from ts.findThingJPAThruHibernate(): Thing: id=" + t.getId() + " name=" + t.getName() + " class=" + t.getClass());
+ %>
+ </br>
+ <%
t = ts.findThingHibernate(t.getId());
- System.out.println("basic.jsp from ts.findThingHibernate(): Thing: id=" + t.getId() + " name=" + t.getName() + " class=" + t.getClass());
-
- t = ts.findThingJPA(t.getId());
- System.out.println("basic.jsp from ts.findThingJPA(): Thing: id=" + t.getId() + " name=" + t.getName() + " class=" + t.getClass());
-
+ System.out.println("B-1 - basic.jsp from ts.findThingHibernate(): Thing: id=" + t.getId() + " name=" + t.getName() + " class=" + t.getClass());
+ out.println("B-1 - basic.jsp from ts.findThingHibernate(): Thing: id=" + t.getId() + " name=" + t.getName() + " class=" + t.getClass());
+ %>
+ </br>
+ <%
t = ts.findThingHibernateMBean(t.getId());
- System.out.println("basic.jsp from ts.findThingHibernateMBean(): Thing: id=" + t.getId() + " name=" + t.getName() + " class=" + t.getClass());
+ System.out.println("B-2 - basic.jsp from ts.findThingHibernateMBean(): Thing: id=" + t.getId() + " name=" + t.getName() + " class=" + t.getClass());
+ out.println("B-2 - basic.jsp from ts.findThingHibernateMBean(): Thing: id=" + t.getId() + " name=" + t.getName() + " class=" + t.getClass());
+
+
%>
+</br>
Tests run successfully.
14 years, 8 months
Hibernate SVN: r17690 - sandbox/trunk/lobtest-ee5.
by hibernate-commits@lists.jboss.org
Author: dstephan
Date: 2009-10-11 22:53:54 -0400 (Sun, 11 Oct 2009)
New Revision: 17690
Modified:
sandbox/trunk/lobtest-ee5/
Log:
Modified to include correct deployment of HibernateService and Test
Property changes on: sandbox/trunk/lobtest-ee5
___________________________________________________________________
Name: svn:ignore
+ .classpath
.project
src
14 years, 8 months
Hibernate SVN: r17689 - in sandbox/trunk/lobtest-ee5: lobtest-ejb and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: dstephan
Date: 2009-10-11 22:52:13 -0400 (Sun, 11 Oct 2009)
New Revision: 17689
Modified:
sandbox/trunk/lobtest-ee5/lobtest-ear/
sandbox/trunk/lobtest-ee5/lobtest-ejb/
Log:
Modified to include correct deployment of HibernateService and Test
Property changes on: sandbox/trunk/lobtest-ee5/lobtest-ear
___________________________________________________________________
Name: svn:ignore
+ target
Property changes on: sandbox/trunk/lobtest-ee5/lobtest-ejb
___________________________________________________________________
Name: svn:ignore
+ target
14 years, 8 months
Hibernate SVN: r17688 - sandbox/trunk/lobtest-ee5/lobtest-web.
by hibernate-commits@lists.jboss.org
Author: dstephan
Date: 2009-10-11 22:49:50 -0400 (Sun, 11 Oct 2009)
New Revision: 17688
Modified:
sandbox/trunk/lobtest-ee5/lobtest-web/
Log:
Modified to include correct deployment of HibernateService and Test
Property changes on: sandbox/trunk/lobtest-ee5/lobtest-web
___________________________________________________________________
Name: svn:ignore
+ target
14 years, 8 months
Hibernate SVN: r17687 - sandbox/trunk/lobtest-ee5/lobtest-sar.
by hibernate-commits@lists.jboss.org
Author: dstephan
Date: 2009-10-11 22:41:03 -0400 (Sun, 11 Oct 2009)
New Revision: 17687
Modified:
sandbox/trunk/lobtest-ee5/lobtest-sar/
Log:
Modified to include correct deployment of HibernateService and Test
Property changes on: sandbox/trunk/lobtest-ee5/lobtest-sar
___________________________________________________________________
Name: svn:ignore
+ target
14 years, 8 months
Hibernate SVN: r17686 - in sandbox/trunk/lobtest-ee5: lobtest-ear and 14 other directories.
by hibernate-commits@lists.jboss.org
Author: dstephan
Date: 2009-10-11 22:39:48 -0400 (Sun, 11 Oct 2009)
New Revision: 17686
Added:
sandbox/trunk/lobtest-ee5/lobtest-ejb/src/main/resources/com/
sandbox/trunk/lobtest-ee5/lobtest-ejb/src/main/resources/com/redhat/
sandbox/trunk/lobtest-ee5/lobtest-ejb/src/main/resources/com/redhat/gss/
sandbox/trunk/lobtest-ee5/lobtest-ejb/src/main/resources/com/redhat/gss/lobtest/
sandbox/trunk/lobtest-ee5/lobtest-ejb/src/main/resources/com/redhat/gss/lobtest/hibernate/
sandbox/trunk/lobtest-ee5/lobtest-ejb/src/main/resources/com/redhat/gss/lobtest/hibernate/Thing.hbm.xml
sandbox/trunk/lobtest-ee5/lobtest-sar/
sandbox/trunk/lobtest-ee5/lobtest-sar/pom.xml
sandbox/trunk/lobtest-ee5/lobtest-sar/src/
sandbox/trunk/lobtest-ee5/lobtest-sar/src/main/
sandbox/trunk/lobtest-ee5/lobtest-sar/src/main/resources/
sandbox/trunk/lobtest-ee5/lobtest-sar/src/main/resources/META-INF/
sandbox/trunk/lobtest-ee5/lobtest-sar/src/main/resources/META-INF/jboss-service.xml
Removed:
sandbox/trunk/lobtest-ee5/lobtest-ejb/hibernate-service.xml
Modified:
sandbox/trunk/lobtest-ee5/lobtest-ear/pom.xml
sandbox/trunk/lobtest-ee5/lobtest-ejb/src/main/java/com/redhat/gss/lobtest/ejb/ThingServiceBean.java
sandbox/trunk/lobtest-ee5/lobtest-web/src/main/webapp/basic.jsp
sandbox/trunk/lobtest-ee5/pom.xml
Log:
Modified to include correct deployment of HibernateService and Test
Modified: sandbox/trunk/lobtest-ee5/lobtest-ear/pom.xml
===================================================================
--- sandbox/trunk/lobtest-ee5/lobtest-ear/pom.xml 2009-10-10 16:10:38 UTC (rev 17685)
+++ sandbox/trunk/lobtest-ee5/lobtest-ear/pom.xml 2009-10-12 02:39:48 UTC (rev 17686)
@@ -21,11 +21,17 @@
<groupId>${parent.groupId}</groupId>
<artifactId>lobtest-ejb</artifactId>
</ejbModule>
+ <ejbModule>
+ <groupId>${parent.groupId}</groupId>
+ <artifactId>lobtest-sar</artifactId>
+ <bundleFileName>lobtest-sar.sar</bundleFileName>
+ </ejbModule>
<webModule>
<groupId>${parent.groupId}</groupId>
<artifactId>lobtest-web</artifactId>
</webModule>
</modules>
+ <applicationXml>${project.build.directory}/application.xml</applicationXml>
</configuration>
</plugin>
</plugins>
@@ -40,6 +46,12 @@
</dependency>
<dependency>
<groupId>${parent.groupId}</groupId>
+ <artifactId>lobtest-sar</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>
Deleted: sandbox/trunk/lobtest-ee5/lobtest-ejb/hibernate-service.xml
===================================================================
--- sandbox/trunk/lobtest-ee5/lobtest-ejb/hibernate-service.xml 2009-10-10 16:10:38 UTC (rev 17685)
+++ sandbox/trunk/lobtest-ee5/lobtest-ejb/hibernate-service.xml 2009-10-12 02:39:48 UTC (rev 17686)
@@ -1,45 +0,0 @@
-<?xml version="1.0"?>
-<server>
-
- <mbean code="org.hibernate.jmx.HibernateService"
- name="jboss.jca:service=HibernateFactory,name=HibernateFactory">
-
- com.redhat.gss.lobtest.jpa.Thing
-
- <depends>jboss.jca:service=RARDeployer
- </depends>
- <depends>jboss.jca:service=LocalTxCM,name=DefaultDS
- </depends>
-
- <!-- Bind the Hibernate service to JNDI -->
- <attribute name="JndiName">java:/hibernate/SessionFactory
- </attribute>
- <!-- hibernate dialect -->
-
- <property name="hibernate.dialect">org.hibernate.dialect.HSQLDialect
- </property>
- <attribute name="Dialect">org.hibernate.dialect.HSQLDialect
- </attribute>
-
-
- <attribute name="Datasource">java:DefaultDS</attribute>
-
- <!-- DataSource properties (end) -->
-
- <!-- JTA transaction properties (begin) -->
- <attribute name="TransactionStrategy">
- org.hibernate.transaction.JTATransactionFactory</attribute>
- <attribute name="TransactionManagerLookupStrategy">
- org.hibernate.transaction.JBossTransactionManagerLookup</attribute>
- <attribute name="FlushBeforeCompletionEnabled">true</attribute>
- <attribute name="AutoCloseSessionEnabled">true</attribute>
-
- <!-- Simple memory-only cache -->
- <property name="hibernate.cache.provider_class">org.hibernate.cache.HashtableCacheProvider
- </property>
-
-
- </mbean>
-
-</server>
-
Modified: 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 2009-10-10 16:10:38 UTC (rev 17685)
+++ sandbox/trunk/lobtest-ee5/lobtest-ejb/src/main/java/com/redhat/gss/lobtest/ejb/ThingServiceBean.java 2009-10-12 02:39:48 UTC (rev 17686)
@@ -47,19 +47,12 @@
{
Thing t = null;
Session s = null;
- try
- {
- InitialContext ctx = new InitialContext();
- SessionFactory sf = (SessionFactory) ctx.lookup("java:hibernate/SessionFactory");
- s = sf.getCurrentSession();
+ InitialContext ctx = new InitialContext();
+ SessionFactory sf = (SessionFactory) ctx.lookup("java:hibernate/SessionFactory");
+ s = sf.getCurrentSession();
- t = (Thing) s.load(Thing.class, id);
- System.out.println("Thing: id=" + t.getId() + " name=" + t.getName() + " class=" + t.getClass());
- }
- finally
- {
- s.close();
- }
+ t = (Thing) s.load(Thing.class, id);
+ System.out.println("Thing: id=" + t.getId() + " name=" + t.getName() + " class=" + t.getClass());
return t;
}
Added: sandbox/trunk/lobtest-ee5/lobtest-ejb/src/main/resources/com/redhat/gss/lobtest/hibernate/Thing.hbm.xml
===================================================================
--- sandbox/trunk/lobtest-ee5/lobtest-ejb/src/main/resources/com/redhat/gss/lobtest/hibernate/Thing.hbm.xml (rev 0)
+++ sandbox/trunk/lobtest-ee5/lobtest-ejb/src/main/resources/com/redhat/gss/lobtest/hibernate/Thing.hbm.xml 2009-10-12 02:39:48 UTC (rev 17686)
@@ -0,0 +1,11 @@
+<?xml version="1.0"?>
+<!DOCTYPE hibernate-mapping PUBLIC
+ "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
+ "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
+
+<hibernate-mapping>
+ <class name="com.redhat.gss.lobtest.jpa.Thing" >
+ <id name="id"/>
+ <property name="name" />
+ </class>
+</hibernate-mapping>
\ No newline at end of file
Added: sandbox/trunk/lobtest-ee5/lobtest-sar/pom.xml
===================================================================
--- sandbox/trunk/lobtest-ee5/lobtest-sar/pom.xml (rev 0)
+++ sandbox/trunk/lobtest-ee5/lobtest-sar/pom.xml 2009-10-12 02:39:48 UTC (rev 17686)
@@ -0,0 +1,73 @@
+<?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-sar</artifactId>
+
+ <name>LOB Test SAR</name>
+ <!-- <build>
+ <plugins>
+ <plugin>
+ <groupId>net.sf.maven-sar</groupId>
+ <artifactId>maven-sar-plugin</artifactId>
+ <version>1.0</version>
+ <extensions>true</extensions>
+ </plugin>
+ </plugins>
+ </build>-->
+ <packaging>jar</packaging>
+ <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-sar/src/main/resources/META-INF/jboss-service.xml
===================================================================
--- sandbox/trunk/lobtest-ee5/lobtest-sar/src/main/resources/META-INF/jboss-service.xml (rev 0)
+++ sandbox/trunk/lobtest-ee5/lobtest-sar/src/main/resources/META-INF/jboss-service.xml 2009-10-12 02:39:48 UTC (rev 17686)
@@ -0,0 +1,34 @@
+<?xml version="1.0"?>
+<server>
+
+ <mbean code="org.hibernate.jmx.HibernateService" name="jboss.jca:service=HibernateFactory,name=HibernateFactory">
+
+ <depends>jboss.jca:service=RARDeployer</depends>
+ <depends>jboss.jca:service=LocalTxCM,name=DefaultDS</depends>
+
+ <!-- Bind the Hibernate service to JNDI -->
+ <attribute name="JndiName">java:/hibernate/SessionFactory</attribute>
+ <!-- hibernate dialect -->
+
+ <property name="hibernate.dialect">org.hibernate.dialect.HSQLDialect</property>
+ <attribute name="Dialect">org.hibernate.dialect.HSQLDialect</attribute>
+
+
+ <attribute name="Datasource">java:DefaultDS</attribute>
+
+ <!-- DataSource properties (end) -->
+
+ <!-- JTA transaction properties (begin) -->
+ <attribute name="TransactionStrategy">org.hibernate.transaction.JTATransactionFactory</attribute>
+ <attribute name="TransactionManagerLookupStrategy">org.hibernate.transaction.JBossTransactionManagerLookup</attribute>
+ <attribute name="FlushBeforeCompletionEnabled">true</attribute>
+ <attribute name="AutoCloseSessionEnabled">true</attribute>
+
+ <!-- Simple memory-only cache -->
+ <property name="hibernate.cache.provider_class">org.hibernate.cache.HashtableCacheProvider</property>
+
+ <attribute name="MapResources">com/redhat/gss/lobtest/hibernate/Thing.hbm.xml</attribute>
+ </mbean>
+
+</server>
+
Modified: sandbox/trunk/lobtest-ee5/lobtest-web/src/main/webapp/basic.jsp
===================================================================
--- sandbox/trunk/lobtest-ee5/lobtest-web/src/main/webapp/basic.jsp 2009-10-10 16:10:38 UTC (rev 17685)
+++ sandbox/trunk/lobtest-ee5/lobtest-web/src/main/webapp/basic.jsp 2009-10-12 02:39:48 UTC (rev 17686)
@@ -20,7 +20,7 @@
t = ts.findThingJPA(t.getId());
System.out.println("basic.jsp from ts.findThingJPA(): Thing: id=" + t.getId() + " name=" + t.getName() + " class=" + t.getClass());
- //t = ts.findThingHibernateMBean(t.getId());
- //System.out.println("basic.jsp from ts.findThingHibernateMBean(): Thing: id=" + t.getId() + " name=" + t.getName() + " class=" + t.getClass());
+ t = ts.findThingHibernateMBean(t.getId());
+ System.out.println("basic.jsp from ts.findThingHibernateMBean(): Thing: id=" + t.getId() + " name=" + t.getName() + " class=" + t.getClass());
%>
Tests run successfully.
Modified: sandbox/trunk/lobtest-ee5/pom.xml
===================================================================
--- sandbox/trunk/lobtest-ee5/pom.xml 2009-10-10 16:10:38 UTC (rev 17685)
+++ sandbox/trunk/lobtest-ee5/pom.xml 2009-10-12 02:39:48 UTC (rev 17686)
@@ -9,6 +9,7 @@
<name>LOB Test EE5 Parent</name>
<modules>
<module>lobtest-ejb</module>
+ <module>lobtest-sar</module>
<module>lobtest-web</module>
<module>lobtest-ear</module>
</modules>
14 years, 8 months
Hibernate SVN: r17685 - in core/trunk/annotations/src: main/java/org/hibernate/type and 2 other directories.
by hibernate-commits@lists.jboss.org
Author: stliu
Date: 2009-10-10 12:10:38 -0400 (Sat, 10 Oct 2009)
New Revision: 17685
Added:
core/trunk/annotations/src/main/java/org/hibernate/type/WrappedMaterializedBlobType.java
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/lob/CharacterArrayTextType.java
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/lob/Dog.java
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/lob/ImageHolder.java
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/lob/ImageTest.java
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/lob/LongStringHolder.java
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/lob/PrimitiveCharacterArrayTextType.java
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/lob/SerializableToImageType.java
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/lob/TextTest.java
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/lob/WrappedImageType.java
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/lob/package-info.java
Modified:
core/trunk/annotations/src/main/java/org/hibernate/cfg/annotations/SimpleValueBinder.java
core/trunk/annotations/src/main/java/org/hibernate/type/ByteArrayBlobType.java
core/trunk/annotations/src/main/java/org/hibernate/type/PrimitiveByteArrayBlobType.java
core/trunk/annotations/src/main/java/org/hibernate/type/StringClobType.java
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/TestCase.java
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/lob/LobTest.java
Log:
HHH-4405 Integrate new long string and binary property types in core with annotations
Modified: core/trunk/annotations/src/main/java/org/hibernate/cfg/annotations/SimpleValueBinder.java
===================================================================
--- core/trunk/annotations/src/main/java/org/hibernate/cfg/annotations/SimpleValueBinder.java 2009-10-10 15:44:29 UTC (rev 17684)
+++ core/trunk/annotations/src/main/java/org/hibernate/cfg/annotations/SimpleValueBinder.java 2009-10-10 16:10:38 UTC (rev 17685)
@@ -1,7 +1,7 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
- * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * Copyright (c) 2009, Red Hat Middleware LLC 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 Middleware LLC.
@@ -34,6 +34,7 @@
import org.hibernate.AnnotationException;
import org.hibernate.AssertionFailure;
+import org.hibernate.Hibernate;
import org.hibernate.annotations.Parameter;
import org.hibernate.annotations.Type;
import org.hibernate.annotations.common.reflection.XClass;
@@ -45,13 +46,11 @@
import org.hibernate.cfg.SetSimpleValueTypeSecondPass;
import org.hibernate.mapping.SimpleValue;
import org.hibernate.mapping.Table;
-import org.hibernate.type.ByteArrayBlobType;
import org.hibernate.type.CharacterArrayClobType;
import org.hibernate.type.EnumType;
-import org.hibernate.type.PrimitiveByteArrayBlobType;
import org.hibernate.type.PrimitiveCharacterArrayClobType;
import org.hibernate.type.SerializableToBlobType;
-import org.hibernate.type.StringClobType;
+import org.hibernate.type.WrappedMaterializedBlobType;
import org.hibernate.util.StringHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -158,7 +157,7 @@
type = "blob";
}
else if ( mappings.getReflectionManager().equals( returnedClassOrElement, String.class ) ) {
- type = StringClobType.class.getName();
+ type = Hibernate.MATERIALIZED_CLOB.getName();
}
else if ( mappings.getReflectionManager().equals( returnedClassOrElement, Character.class ) && isArray ) {
type = CharacterArrayClobType.class.getName();
@@ -167,10 +166,10 @@
type = PrimitiveCharacterArrayClobType.class.getName();
}
else if ( mappings.getReflectionManager().equals( returnedClassOrElement, Byte.class ) && isArray ) {
- type = ByteArrayBlobType.class.getName();
+ type = WrappedMaterializedBlobType.class.getName();
}
else if ( mappings.getReflectionManager().equals( returnedClassOrElement, byte.class ) && isArray ) {
- type = PrimitiveByteArrayBlobType.class.getName();
+ type = Hibernate.MATERIALIZED_BLOB.getName();
}
else if ( mappings.getReflectionManager()
.toXClass( Serializable.class )
Modified: core/trunk/annotations/src/main/java/org/hibernate/type/ByteArrayBlobType.java
===================================================================
--- core/trunk/annotations/src/main/java/org/hibernate/type/ByteArrayBlobType.java 2009-10-10 15:44:29 UTC (rev 17684)
+++ core/trunk/annotations/src/main/java/org/hibernate/type/ByteArrayBlobType.java 2009-10-10 16:10:38 UTC (rev 17685)
@@ -45,8 +45,11 @@
* Map a Byte[] into a Blob
* Experimental
*
+ * @deprecated replaced by Hibernate Core's {@link org.hibernate.type.WrappedMaterializedBlobType}
+ *
* @author Emmanuel Bernard
*/
+@Deprecated
public class ByteArrayBlobType extends AbstractLobType {
public int[] sqlTypes(Mapping mapping) throws MappingException {
Modified: core/trunk/annotations/src/main/java/org/hibernate/type/PrimitiveByteArrayBlobType.java
===================================================================
--- core/trunk/annotations/src/main/java/org/hibernate/type/PrimitiveByteArrayBlobType.java 2009-10-10 15:44:29 UTC (rev 17684)
+++ core/trunk/annotations/src/main/java/org/hibernate/type/PrimitiveByteArrayBlobType.java 2009-10-10 16:10:38 UTC (rev 17685)
@@ -25,9 +25,11 @@
/**
* Map a byte[] to a Blob
- *
+ * @deprecated replaced by Hibernate Core's {@link org.hibernate.type.MaterializedBlobType}
+ *
* @author Emmanuel Bernard
*/
+@Deprecated
public class PrimitiveByteArrayBlobType extends ByteArrayBlobType {
public Class getReturnedClass() {
return byte[].class;
Modified: core/trunk/annotations/src/main/java/org/hibernate/type/StringClobType.java
===================================================================
--- core/trunk/annotations/src/main/java/org/hibernate/type/StringClobType.java 2009-10-10 15:44:29 UTC (rev 17684)
+++ core/trunk/annotations/src/main/java/org/hibernate/type/StringClobType.java 2009-10-10 16:10:38 UTC (rev 17685)
@@ -37,9 +37,11 @@
/**
* Map a String to a Clob
- *
+ * @deprecated replaced by Hibernate Core's {@link org.hibernate.type.MaterializedClobType}
+ *
* @author Emmanuel Bernard
*/
+@Deprecated
public class StringClobType implements UserType, Serializable {
public int[] sqlTypes() {
return new int[]{Types.CLOB};
Added: core/trunk/annotations/src/main/java/org/hibernate/type/WrappedMaterializedBlobType.java
===================================================================
--- core/trunk/annotations/src/main/java/org/hibernate/type/WrappedMaterializedBlobType.java (rev 0)
+++ core/trunk/annotations/src/main/java/org/hibernate/type/WrappedMaterializedBlobType.java 2009-10-10 16:10:38 UTC (rev 17685)
@@ -0,0 +1,42 @@
+package org.hibernate.type;
+
+/**
+ * <tt>materialized_blob</tt>: A type that maps an SQL BLOB to Java Byte[].
+ *
+ * @author Strong Liu
+ */
+public class WrappedMaterializedBlobType extends MaterializedBlobType {
+ public Class getReturnedClass() {
+ return Byte[].class;
+ }
+
+ protected Object toExternalFormat(byte[] bytes) {
+ if (bytes == null)
+ return null;
+ return wrapPrimitive(bytes);
+ }
+
+ protected byte[] toInternalFormat(Object bytes) {
+ if (bytes == null)
+ return null;
+ return unwrapNonPrimitive((Byte[]) bytes);
+ }
+
+ private Byte[] wrapPrimitive(byte[] bytes) {
+ int length = bytes.length;
+ Byte[] result = new Byte[length];
+ for (int index = 0; index < length; index++) {
+ result[index] = Byte.valueOf(bytes[index]);
+ }
+ return result;
+ }
+
+ private byte[] unwrapNonPrimitive(Byte[] bytes) {
+ int length = bytes.length;
+ byte[] result = new byte[length];
+ for (int i = 0; i < length; i++) {
+ result[i] = bytes[i].byteValue();
+ }
+ return result;
+ }
+}
Modified: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/TestCase.java
===================================================================
--- core/trunk/annotations/src/test/java/org/hibernate/test/annotations/TestCase.java 2009-10-10 15:44:29 UTC (rev 17684)
+++ core/trunk/annotations/src/test/java/org/hibernate/test/annotations/TestCase.java 2009-10-10 16:10:38 UTC (rev 17685)
@@ -125,7 +125,7 @@
dialectList.addAll(Arrays.asList(requiredDialects));
}
- if ( dialectList.isEmpty() || dialectList.contains(Dialect.getDialect().getClass()) ) {
+ if ( (dialectList.isEmpty() || dialectList.contains(Dialect.getDialect().getClass())) && appliesTo(Dialect.getDialect()) ) {
skip = false;
} else {
log.warn("Skipping test {}, because test does not apply for dialect {}", runMethod.getName(), Dialect
@@ -133,7 +133,11 @@
skip = true;
}
}
-
+
+ protected boolean appliesTo( Dialect dialect ) {
+ return true;
+ }
+
private void runTestMethod( Method runMethod ) throws Throwable {
try {
runMethod.invoke(this, new Class[0]);
Added: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/lob/CharacterArrayTextType.java
===================================================================
--- core/trunk/annotations/src/test/java/org/hibernate/test/annotations/lob/CharacterArrayTextType.java (rev 0)
+++ core/trunk/annotations/src/test/java/org/hibernate/test/annotations/lob/CharacterArrayTextType.java 2009-10-10 16:10:38 UTC (rev 17685)
@@ -0,0 +1,79 @@
+//$Id: $
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2009, Red Hat Middleware LLC 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 Middleware LLC.
+ *
+ * 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.test.annotations.lob;
+
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+
+import org.hibernate.HibernateException;
+
+/**
+ * A type that maps an SQL LONGVARCHAR to a Java Character [].
+ *
+ * @author Strong Liu
+ */
+public class CharacterArrayTextType extends PrimitiveCharacterArrayTextType {
+
+ public Class getReturnedClass() {
+ return Character[].class;
+ }
+
+ @Override
+ public Object get(ResultSet rs, String name) throws HibernateException,
+ SQLException {
+ char[] text = (char[]) super.get(rs, name);
+ if (text == null)
+ return null;
+ return wrapPrimitive(text);
+ }
+
+ @Override
+ public void set(PreparedStatement st, Object value, int index)
+ throws HibernateException, SQLException {
+ Character[] cs = (Character[]) value;
+ super.set(st, unwrapNonPrimitive(cs), index);
+ }
+
+ private Character[] wrapPrimitive(char[] bytes) {
+ int length = bytes.length;
+ Character[] result = new Character[length];
+ for (int index = 0; index < length; index++) {
+ result[index] = Character.valueOf(bytes[index]);
+ }
+ return result;
+ }
+
+ private char[] unwrapNonPrimitive(Character[] bytes) {
+ int length = bytes.length;
+ char[] result = new char[length];
+ for (int i = 0; i < length; i++) {
+ result[i] = bytes[i].charValue();
+ }
+ return result;
+ }
+
+}
Added: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/lob/Dog.java
===================================================================
--- core/trunk/annotations/src/test/java/org/hibernate/test/annotations/lob/Dog.java (rev 0)
+++ core/trunk/annotations/src/test/java/org/hibernate/test/annotations/lob/Dog.java 2009-10-10 16:10:38 UTC (rev 17685)
@@ -0,0 +1,15 @@
+package org.hibernate.test.annotations.lob;
+
+import java.io.Serializable;
+
+public class Dog implements Serializable {
+ private String name;
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+}
Added: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/lob/ImageHolder.java
===================================================================
--- core/trunk/annotations/src/test/java/org/hibernate/test/annotations/lob/ImageHolder.java (rev 0)
+++ core/trunk/annotations/src/test/java/org/hibernate/test/annotations/lob/ImageHolder.java 2009-10-10 16:10:38 UTC (rev 17685)
@@ -0,0 +1,81 @@
+//$Id: $
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2009, Red Hat Middleware LLC 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 Middleware LLC.
+ *
+ * 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.test.annotations.lob;
+
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+
+/**
+ * An entity containing data that is materialized into a byte array immediately.
+ * The hibernate type mapped for {@link #longByteArray} determines the SQL type
+ * asctually used.
+ *
+ * @author Gail Badner
+ */
+@Entity
+public class ImageHolder {
+ private Long id;
+ private byte[] longByteArray;
+ private Dog dog;
+ private Byte[] picByteArray;
+
+ @Id
+ @GeneratedValue
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ @org.hibernate.annotations.Type(type="image")
+ public byte[] getLongByteArray() {
+ return longByteArray;
+ }
+
+ public void setLongByteArray(byte[] longByteArray) {
+ this.longByteArray = longByteArray;
+ }
+ @org.hibernate.annotations.Type(type="serializable_image")
+ public Dog getDog() {
+ return dog;
+ }
+
+ public void setDog(Dog dog) {
+ this.dog = dog;
+ }
+ @org.hibernate.annotations.Type(type="wrapped_image")
+ public Byte[] getPicByteArray() {
+ return picByteArray;
+ }
+
+ public void setPicByteArray(Byte[] picByteArray) {
+ this.picByteArray = picByteArray;
+ }
+
+}
\ No newline at end of file
Added: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/lob/ImageTest.java
===================================================================
--- core/trunk/annotations/src/test/java/org/hibernate/test/annotations/lob/ImageTest.java (rev 0)
+++ core/trunk/annotations/src/test/java/org/hibernate/test/annotations/lob/ImageTest.java 2009-10-10 16:10:38 UTC (rev 17685)
@@ -0,0 +1,168 @@
+//$Id: $
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2009, Red Hat Middleware LLC 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 Middleware LLC.
+ *
+ * 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.test.annotations.lob;
+
+import junit.framework.AssertionFailedError;
+
+import org.hibernate.Session;
+import org.hibernate.dialect.SQLServerDialect;
+import org.hibernate.dialect.Sybase11Dialect;
+import org.hibernate.dialect.SybaseASE15Dialect;
+import org.hibernate.dialect.SybaseDialect;
+import org.hibernate.test.annotations.RequiresDialect;
+import org.hibernate.test.annotations.TestCase;
+import org.hibernate.util.ArrayHelper;
+
+/**
+ * Tests eager materialization and mutation of data mapped by
+ * {@link org.hibernate.type.ImageType}.
+ *
+ * @author Gail Badner
+ */
+@RequiresDialect( { SybaseASE15Dialect.class, SQLServerDialect.class,
+ SybaseDialect.class, Sybase11Dialect.class })
+public class ImageTest extends TestCase {
+ private static final int ARRAY_SIZE = 10000;
+
+ public void testBoundedLongByteArrayAccess() {
+ byte[] original = buildRecursively(ARRAY_SIZE, true);
+ byte[] changed = buildRecursively(ARRAY_SIZE, false);
+
+ Session s = openSession();
+ s.beginTransaction();
+ ImageHolder entity = new ImageHolder();
+ s.save(entity);
+ s.getTransaction().commit();
+ s.close();
+
+ s = openSession();
+ s.beginTransaction();
+ entity = (ImageHolder) s.get(ImageHolder.class, entity.getId());
+ assertNull(entity.getLongByteArray());
+ assertNull(entity.getDog());
+ assertNull(entity.getPicByteArray());
+ entity.setLongByteArray(original);
+ Dog dog = new Dog();
+ dog.setName("rabbit");
+ entity.setDog(dog);
+ entity.setPicByteArray(wrapPrimitive(original));
+ s.getTransaction().commit();
+ s.close();
+
+ s = openSession();
+ s.beginTransaction();
+ entity = (ImageHolder) s.get(ImageHolder.class, entity.getId());
+ assertEquals(ARRAY_SIZE, entity.getLongByteArray().length);
+ assertEquals(original, entity.getLongByteArray());
+ assertEquals(ARRAY_SIZE, entity.getPicByteArray().length);
+ assertEquals(original, unwrapNonPrimitive(entity.getPicByteArray()));
+ assertNotNull(entity.getDog());
+ assertEquals(dog.getName(), entity.getDog().getName());
+ entity.setLongByteArray(changed);
+ entity.setPicByteArray(wrapPrimitive(changed));
+ dog.setName("papa");
+ entity.setDog(dog);
+ s.getTransaction().commit();
+ s.close();
+
+ s = openSession();
+ s.beginTransaction();
+ entity = (ImageHolder) s.get(ImageHolder.class, entity.getId());
+ assertEquals(ARRAY_SIZE, entity.getLongByteArray().length);
+ assertEquals(changed, entity.getLongByteArray());
+ assertEquals(ARRAY_SIZE, entity.getPicByteArray().length);
+ assertEquals(changed, unwrapNonPrimitive(entity.getPicByteArray()));
+ assertNotNull(entity.getDog());
+ assertEquals(dog.getName(), entity.getDog().getName());
+ entity.setLongByteArray(null);
+ entity.setPicByteArray(null);
+ entity.setDog(null);
+ s.getTransaction().commit();
+ s.close();
+
+ s = openSession();
+ s.beginTransaction();
+ entity = (ImageHolder) s.get(ImageHolder.class, entity.getId());
+ assertNull(entity.getLongByteArray());
+ assertNull(entity.getDog());
+ assertNull(entity.getPicByteArray());
+ s.delete(entity);
+ s.getTransaction().commit();
+ s.close();
+ }
+
+ private Byte[] wrapPrimitive(byte[] bytes) {
+ int length = bytes.length;
+ Byte[] result = new Byte[length];
+ for (int index = 0; index < length; index++) {
+ result[index] = Byte.valueOf(bytes[index]);
+ }
+ return result;
+ }
+
+ private byte[] unwrapNonPrimitive(Byte[] bytes) {
+ int length = bytes.length;
+ byte[] result = new byte[length];
+ for (int i = 0; i < length; i++) {
+ result[i] = bytes[i].byteValue();
+ }
+ return result;
+ }
+
+ private byte[] buildRecursively(int size, boolean on) {
+ byte[] data = new byte[size];
+ data[0] = mask(on);
+ for (int i = 0; i < size; i++) {
+ data[i] = mask(on);
+ on = !on;
+ }
+ return data;
+ }
+
+ private byte mask(boolean on) {
+ return on ? (byte) 1 : (byte) 0;
+ }
+
+ public static void assertEquals(byte[] val1, byte[] val2) {
+ if (!ArrayHelper.isEquals(val1, val2)) {
+ throw new AssertionFailedError("byte arrays did not match");
+ }
+ }
+
+ public ImageTest(String name) {
+ super(name);
+ }
+
+ @Override
+ protected String[] getAnnotatedPackages() {
+ return new String[] { "org.hibernate.test.annotations.lob" };
+ }
+
+ public Class<?>[] getMappings() {
+ return new Class[] { ImageHolder.class };
+ }
+
+}
\ No newline at end of file
Modified: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/lob/LobTest.java
===================================================================
--- core/trunk/annotations/src/test/java/org/hibernate/test/annotations/lob/LobTest.java 2009-10-10 15:44:29 UTC (rev 17684)
+++ core/trunk/annotations/src/test/java/org/hibernate/test/annotations/lob/LobTest.java 2009-10-10 16:10:38 UTC (rev 17685)
@@ -3,6 +3,7 @@
import org.hibernate.Session;
import org.hibernate.Transaction;
+import org.hibernate.dialect.Dialect;
import org.hibernate.test.annotations.TestCase;
/**
@@ -116,6 +117,11 @@
public LobTest(String x) {
super( x );
}
+
+ @Override
+ protected boolean appliesTo(Dialect dialect) {
+ return dialect.supportsExpectedLobUsagePattern();
+ }
protected Class[] getMappings() {
return new Class[]{
Added: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/lob/LongStringHolder.java
===================================================================
--- core/trunk/annotations/src/test/java/org/hibernate/test/annotations/lob/LongStringHolder.java (rev 0)
+++ core/trunk/annotations/src/test/java/org/hibernate/test/annotations/lob/LongStringHolder.java 2009-10-10 16:10:38 UTC (rev 17685)
@@ -0,0 +1,82 @@
+//$Id: $
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2009, Red Hat Middleware LLC 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 Middleware LLC.
+ *
+ * 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.test.annotations.lob;
+
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+
+import org.hibernate.annotations.Type;
+
+/**
+ * An entity containing data that is materialized into a String immediately.
+ * The hibernate type mapped for {@link #LONGVARCHAR} determines the SQL type
+ * asctually used.
+ *
+ * @author Gail Badner
+ */
+@Entity
+public class LongStringHolder {
+ private Long id;
+ private char[] name;
+ private Character[] whatEver;
+ private String longString;
+
+ @Id
+ @GeneratedValue
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ @Type(type = "text")
+ public String getLongString() {
+ return longString;
+ }
+
+ public void setLongString(String longString) {
+ this.longString = longString;
+ }
+ @Type(type = "char_text")
+ public char[] getName() {
+ return name;
+ }
+
+ public void setName(char[] name) {
+ this.name = name;
+ }
+ @Type(type = "wrapped_char_text")
+ public Character[] getWhatEver() {
+ return whatEver;
+ }
+
+ public void setWhatEver(Character[] whatEver) {
+ this.whatEver = whatEver;
+ }
+}
Added: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/lob/PrimitiveCharacterArrayTextType.java
===================================================================
--- core/trunk/annotations/src/test/java/org/hibernate/test/annotations/lob/PrimitiveCharacterArrayTextType.java (rev 0)
+++ core/trunk/annotations/src/test/java/org/hibernate/test/annotations/lob/PrimitiveCharacterArrayTextType.java 2009-10-10 16:10:38 UTC (rev 17685)
@@ -0,0 +1,68 @@
+//$Id: $
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2009, Red Hat Middleware LLC 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 Middleware LLC.
+ *
+ * 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.test.annotations.lob;
+
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+
+import org.hibernate.HibernateException;
+import org.hibernate.type.TextType;
+
+/**
+ * A type that maps an SQL LONGVARCHAR to a Java char [].
+ *
+ * @author Strong Liu
+ */
+public class PrimitiveCharacterArrayTextType extends TextType {
+ public Class getReturnedClass() {
+ return char[].class;
+ }
+
+ @Override
+ public Object get(ResultSet rs, String name) throws HibernateException,
+ SQLException {
+ String text = (String) super.get(rs, name);
+ if (text == null)
+ return null;
+ return text.toCharArray();
+ }
+
+ @Override
+ public void set(PreparedStatement st, Object value, int index)
+ throws HibernateException, SQLException {
+ char[] cs = (char[]) value;
+ String text = String.valueOf(cs);
+
+ super.set(st, text, index);
+ }
+
+ @Override
+ public String toString(Object val) {
+ return String.valueOf(val);
+ }
+
+}
Added: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/lob/SerializableToImageType.java
===================================================================
--- core/trunk/annotations/src/test/java/org/hibernate/test/annotations/lob/SerializableToImageType.java (rev 0)
+++ core/trunk/annotations/src/test/java/org/hibernate/test/annotations/lob/SerializableToImageType.java 2009-10-10 16:10:38 UTC (rev 17685)
@@ -0,0 +1,52 @@
+//$Id: $
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2009, Red Hat Middleware LLC 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 Middleware LLC.
+ *
+ * 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.test.annotations.lob;
+
+import java.io.Serializable;
+
+import org.hibernate.type.ImageType;
+import org.hibernate.util.SerializationHelper;
+
+/**
+ * A type that maps an SQL LONGVARBINARY to a serializable Java object.
+ *
+ * @author Strong Liu
+ */
+public class SerializableToImageType extends ImageType {
+ public Class getReturnedClass() {
+ return Serializable.class;
+ }
+
+ protected Object toExternalFormat(byte[] bytes) {
+ if (bytes == null)
+ return null;
+ return SerializationHelper.deserialize(bytes);
+ }
+
+ protected byte[] toInternalFormat(Object bytes) {
+ return SerializationHelper.serialize((Serializable) bytes);
+ }
+}
Added: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/lob/TextTest.java
===================================================================
--- core/trunk/annotations/src/test/java/org/hibernate/test/annotations/lob/TextTest.java (rev 0)
+++ core/trunk/annotations/src/test/java/org/hibernate/test/annotations/lob/TextTest.java 2009-10-10 16:10:38 UTC (rev 17685)
@@ -0,0 +1,163 @@
+//$Id: $
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2009, Red Hat Middleware LLC 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 Middleware LLC.
+ *
+ * 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.test.annotations.lob;
+
+import junit.framework.AssertionFailedError;
+
+import org.hibernate.Session;
+import org.hibernate.dialect.SQLServerDialect;
+import org.hibernate.dialect.Sybase11Dialect;
+import org.hibernate.dialect.SybaseASE15Dialect;
+import org.hibernate.dialect.SybaseDialect;
+import org.hibernate.test.annotations.RequiresDialect;
+import org.hibernate.test.annotations.TestCase;
+import org.hibernate.util.ArrayHelper;
+
+/**
+ * Tests eager materialization and mutation of long strings.
+ *
+ * @author Steve Ebersole
+ */
+(a)RequiresDialect({SybaseASE15Dialect.class,SQLServerDialect.class,SybaseDialect.class,Sybase11Dialect.class})
+public class TextTest extends TestCase {
+
+ @Override
+ protected Class<?>[] getMappings() {
+ return new Class[] { LongStringHolder.class };
+ }
+
+ private static final int LONG_STRING_SIZE = 10000;
+
+ public void testBoundedLongStringAccess() {
+ String original = buildRecursively(LONG_STRING_SIZE, 'x');
+ String changed = buildRecursively(LONG_STRING_SIZE, 'y');
+
+ Session s = openSession();
+ s.beginTransaction();
+ LongStringHolder entity = new LongStringHolder();
+ s.save(entity);
+ s.getTransaction().commit();
+ s.close();
+
+ s = openSession();
+ s.beginTransaction();
+ entity = (LongStringHolder) s.get(LongStringHolder.class, entity
+ .getId());
+ assertNull(entity.getLongString());
+ assertNull(entity.getName());
+ assertNull(entity.getWhatEver());
+ entity.setLongString(original);
+ entity.setName(original.toCharArray());
+ entity.setWhatEver(wrapPrimitive(original.toCharArray()));
+ s.getTransaction().commit();
+ s.close();
+
+ s = openSession();
+ s.beginTransaction();
+ entity = (LongStringHolder) s.get(LongStringHolder.class, entity
+ .getId());
+ assertEquals(LONG_STRING_SIZE, entity.getLongString().length());
+ assertEquals(original, entity.getLongString());
+ assertNotNull(entity.getName());
+ assertEquals(LONG_STRING_SIZE, entity.getName().length);
+ assertEquals(original.toCharArray(), entity.getName());
+ assertNotNull(entity.getWhatEver());
+ assertEquals(LONG_STRING_SIZE, entity.getWhatEver().length);
+ assertEquals(original.toCharArray(), unwrapNonPrimitive(entity.getWhatEver()));
+ entity.setLongString(changed);
+ entity.setName(changed.toCharArray());
+ entity.setWhatEver(wrapPrimitive(changed.toCharArray()));
+ s.getTransaction().commit();
+ s.close();
+
+ s = openSession();
+ s.beginTransaction();
+ entity = (LongStringHolder) s.get(LongStringHolder.class, entity
+ .getId());
+ assertEquals(LONG_STRING_SIZE, entity.getLongString().length());
+ assertEquals(changed, entity.getLongString());
+ assertNotNull(entity.getName());
+ assertEquals(LONG_STRING_SIZE, entity.getName().length);
+ assertEquals(changed.toCharArray(), entity.getName());
+ assertNotNull(entity.getWhatEver());
+ assertEquals(LONG_STRING_SIZE, entity.getWhatEver().length);
+ assertEquals(changed.toCharArray(), unwrapNonPrimitive(entity.getWhatEver()));
+ entity.setLongString(null);
+ entity.setName(null);
+ entity.setWhatEver(null);
+ s.getTransaction().commit();
+ s.close();
+
+ s = openSession();
+ s.beginTransaction();
+ entity = (LongStringHolder) s.get(LongStringHolder.class, entity
+ .getId());
+ assertNull(entity.getLongString());
+ assertNull(entity.getName());
+ assertNull(entity.getWhatEver());
+ s.delete(entity);
+ s.getTransaction().commit();
+ s.close();
+ }
+
+ public static void assertEquals(char[] val1, char[] val2) {
+ if (!ArrayHelper.isEquals(val1, val2)) {
+ throw new AssertionFailedError("byte arrays did not match");
+ }
+ }
+
+ private String buildRecursively(int size, char baseChar) {
+ StringBuffer buff = new StringBuffer();
+ for (int i = 0; i < size; i++) {
+ buff.append(baseChar);
+ }
+ return buff.toString();
+ }
+
+ private Character[] wrapPrimitive(char[] bytes) {
+ int length = bytes.length;
+ Character[] result = new Character[length];
+ for (int index = 0; index < length; index++) {
+ result[index] = Character.valueOf(bytes[index]);
+ }
+ return result;
+ }
+
+ private char[] unwrapNonPrimitive(Character[] bytes) {
+ int length = bytes.length;
+ char[] result = new char[length];
+ for (int i = 0; i < length; i++) {
+ result[i] = bytes[i].charValue();
+ }
+ return result;
+ }
+
+ @Override
+ protected String[] getAnnotatedPackages() {
+ return new String[] { "org.hibernate.test.annotations.lob" };
+ }
+
+}
Added: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/lob/WrappedImageType.java
===================================================================
--- core/trunk/annotations/src/test/java/org/hibernate/test/annotations/lob/WrappedImageType.java (rev 0)
+++ core/trunk/annotations/src/test/java/org/hibernate/test/annotations/lob/WrappedImageType.java 2009-10-10 16:10:38 UTC (rev 17685)
@@ -0,0 +1,66 @@
+//$Id: $
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2009, Red Hat Middleware LLC 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 Middleware LLC.
+ *
+ * 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.test.annotations.lob;
+
+import org.hibernate.type.ImageType;
+
+/**
+ * A type that maps an SQL LONGVARBINARY to Java Byte[].
+ *
+ * @author Strong Liu
+ */
+public class WrappedImageType extends ImageType{
+ public Class getReturnedClass() {
+ return Byte[].class;
+ }
+
+ protected Object toExternalFormat(byte[] bytes) {
+ if(bytes==null)return null;
+ return wrapPrimitive(bytes);
+ }
+
+ protected byte[] toInternalFormat(Object bytes) {
+ if(bytes==null)return null;
+ return unwrapNonPrimitive(( Byte[] ) bytes);
+ }
+ private Byte[] wrapPrimitive(byte[] bytes) {
+ int length = bytes.length;
+ Byte[] result = new Byte[length];
+ for ( int index = 0; index < length ; index++ ) {
+ result[index] = Byte.valueOf( bytes[index] );
+ }
+ return result;
+ }
+
+ private byte[] unwrapNonPrimitive(Byte[] bytes) {
+ int length = bytes.length;
+ byte[] result = new byte[length];
+ for ( int i = 0; i < length ; i++ ) {
+ result[i] = bytes[i].byteValue();
+ }
+ return result;
+ }
+}
Added: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/lob/package-info.java
===================================================================
--- core/trunk/annotations/src/test/java/org/hibernate/test/annotations/lob/package-info.java (rev 0)
+++ core/trunk/annotations/src/test/java/org/hibernate/test/annotations/lob/package-info.java 2009-10-10 16:10:38 UTC (rev 17685)
@@ -0,0 +1,29 @@
+/**
+ * Test package for metatata facilities
+ * It contains an example of filter metadata
+ */
+@TypeDefs(
+ {
+ @TypeDef(
+ name = "wrapped_char_text",
+ typeClass = org.hibernate.test.annotations.lob.CharacterArrayTextType.class
+ ),
+ @TypeDef(
+ name = "char_text",
+ typeClass = org.hibernate.test.annotations.lob.PrimitiveCharacterArrayTextType.class
+ ),
+ @TypeDef(
+ name = "wrapped_image",
+ typeClass = org.hibernate.test.annotations.lob.WrappedImageType.class
+ ),
+ @TypeDef(
+ name = "serializable_image",
+ typeClass = org.hibernate.test.annotations.lob.SerializableToImageType.class
+ )
+ }
+)
+package org.hibernate.test.annotations.lob;
+
+import org.hibernate.annotations.TypeDef;
+import org.hibernate.annotations.TypeDefs;
+
14 years, 8 months