Author: steve.ebersole(a)jboss.com
Date: 2006-11-21 11:04:45 -0500 (Tue, 21 Nov 2006)
New Revision: 10847
Added:
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/lob/BlobTest.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/lob/LobHolder.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/lob/LobMappings.hbm.xml
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/lob/LobSuite.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/lob/MaterializedBlobType.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/lob/SerializableTypeTest.java
Removed:
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/lob/ClobHoldingEntity.hbm.xml
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/lob/ClobHoldingEntity.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/lob/LobTest.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/lob/Name.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/lob/User.hbm.xml
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/lob/User.java
Modified:
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/AllTests.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/lob/ClobTest.java
Log:
lob testing
Modified: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/AllTests.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/AllTests.java 2006-11-18
04:21:05 UTC (rev 10846)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/AllTests.java 2006-11-21
16:04:45 UTC (rev 10847)
@@ -27,6 +27,7 @@
import org.hibernate.test.criteria.CriteriaQueryTest;
import org.hibernate.test.cuk.CompositePropertyRefTest;
import org.hibernate.test.cut.CompositeUserTypeTest;
+import org.hibernate.test.dialect.cache.SQLFunctionsInterSystemsTest;
import org.hibernate.test.discriminator.DiscriminatorTest;
import org.hibernate.test.dom4j.Dom4jAccessorTest;
import org.hibernate.test.dom4j.Dom4jManyToOneTest;
@@ -82,6 +83,7 @@
import org.hibernate.test.legacy.SQLFunctionsTest;
import org.hibernate.test.legacy.SQLLoaderTest;
import org.hibernate.test.legacy.StatisticsTest;
+import org.hibernate.test.lob.LobSuite;
import org.hibernate.test.manytomany.ManyToManyTest;
import org.hibernate.test.map.MapIndexFormulaTest;
import org.hibernate.test.mapcompelem.MapCompositeElementTest;
@@ -130,9 +132,6 @@
import org.hibernate.test.version.db.DbVersionTest;
import org.hibernate.test.version.sybase.SybaseTimestampVersioningTest;
import org.hibernate.test.where.WhereTest;
-import org.hibernate.test.dialect.cache.SQLFunctionsInterSystemsTest;
-import org.hibernate.test.lob.LobTest;
-import org.hibernate.test.lob.ClobTest;
/**
* @author Gavin King
@@ -292,8 +291,7 @@
suite.addTest( UtilSuite.suite() );
suite.addTest( AnyTypeTest.suite() );
suite.addTest( SQLFunctionsInterSystemsTest.suite() );
- suite.addTest( LobTest.suite() );
- suite.addTest( ClobTest.suite() );
+ suite.addTest( LobSuite.suite() );
return filter( suite );
//return suite;
Added: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/lob/BlobTest.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/lob/BlobTest.java 2006-11-18
04:21:05 UTC (rev 10846)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/lob/BlobTest.java 2006-11-21
16:04:45 UTC (rev 10847)
@@ -0,0 +1,196 @@
+package org.hibernate.test.lob;
+
+import java.sql.Blob;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+import junit.framework.AssertionFailedError;
+
+import org.hibernate.test.DatabaseSpecificTestCase;
+import org.hibernate.Session;
+import org.hibernate.Hibernate;
+import org.hibernate.LockMode;
+import org.hibernate.dialect.Dialect;
+import org.hibernate.util.ArrayHelper;
+
+/**
+ * {@inheritDoc}
+ *
+ * @author Steve Ebersole
+ */
+public class BlobTest extends DatabaseSpecificTestCase {
+ private static final int BLOB_SIZE = 10000;
+
+ public BlobTest(String name) {
+ super( name );
+ }
+
+ protected String[] getMappings() {
+ return new String[] { "lob/LobMappings.hbm.xml" };
+ }
+
+ public static Test suite() {
+ return new TestSuite( BlobTest.class );
+ }
+
+ public boolean appliesTo(Dialect dialect) {
+ return supportsExpectedLobUsagePattern();
+ }
+
+ public void testBoundedMaterializedBlobAccess() {
+ byte[] original = buildRecursively( BLOB_SIZE, true );
+ byte[] changed = buildRecursively( BLOB_SIZE, false );
+
+ Session s = openSession();
+ s.beginTransaction();
+ LobHolder entity = new LobHolder();
+ entity.setMaterializedBlob( original );
+ s.save( entity );
+ s.getTransaction().commit();
+ s.close();
+
+ s = openSession();
+ s.beginTransaction();
+ entity = ( LobHolder ) s.get( LobHolder.class, entity.getId() );
+ assertEquals( BLOB_SIZE, entity.getMaterializedBlob().length );
+ assertEquals( original, entity.getMaterializedBlob() );
+ entity.setMaterializedBlob( changed );
+ s.getTransaction().commit();
+ s.close();
+
+ s = openSession();
+ s.beginTransaction();
+ entity = ( LobHolder ) s.get( LobHolder.class, entity.getId() );
+ assertEquals( BLOB_SIZE, entity.getMaterializedBlob().length );
+ assertEquals( changed, entity.getMaterializedBlob() );
+ s.delete( entity );
+ s.getTransaction().commit();
+ s.close();
+ }
+
+ public void testBoundedBlobLocatorAccess() throws Throwable {
+ byte[] original = buildRecursively( BLOB_SIZE, true );
+ byte[] changed = buildRecursively( BLOB_SIZE, false );
+
+ Session s = openSession();
+ s.beginTransaction();
+ LobHolder entity = new LobHolder();
+ entity.setBlobLocator( Hibernate.createBlob( original ) );
+ s.save( entity );
+ s.getTransaction().commit();
+ s.close();
+
+ s = openSession();
+ s.beginTransaction();
+ entity = ( LobHolder ) s.get( LobHolder.class, entity.getId() );
+ assertEquals( BLOB_SIZE, entity.getBlobLocator().length() );
+ assertEquals( original, extractData( entity.getBlobLocator() ) );
+ s.getTransaction().commit();
+ s.close();
+
+ // test mutation via setting the new clob data...
+ if ( supportsLobValueChangePropogation() ) {
+ s = openSession();
+ s.beginTransaction();
+ entity = ( LobHolder ) s.get( LobHolder.class, entity.getId(), LockMode.UPGRADE );
+ entity.getBlobLocator().truncate( 1 );
+ entity.getBlobLocator().setBytes( 1, changed );
+ s.getTransaction().commit();
+ s.close();
+
+ s = openSession();
+ s.beginTransaction();
+ entity = ( LobHolder ) s.get( LobHolder.class, entity.getId(), LockMode.UPGRADE );
+ assertNotNull( entity.getBlobLocator() );
+ assertEquals( BLOB_SIZE, entity.getBlobLocator().length() );
+ assertEquals( changed, extractData( entity.getBlobLocator() ) );
+ entity.getBlobLocator().truncate( 1 );
+ entity.getBlobLocator().setBytes( 1, original );
+ s.getTransaction().commit();
+ s.close();
+ }
+
+ // test mutation via supplying a new clob locator instance...
+ s = openSession();
+ s.beginTransaction();
+ entity = ( LobHolder ) s.get( LobHolder.class, entity.getId(), LockMode.UPGRADE );
+ assertNotNull( entity.getBlobLocator() );
+ assertEquals( BLOB_SIZE, entity.getBlobLocator().length() );
+ assertEquals( original, extractData( entity.getBlobLocator() ) );
+ entity.setBlobLocator( Hibernate.createBlob( changed ) );
+ s.getTransaction().commit();
+ s.close();
+
+ s = openSession();
+ s.beginTransaction();
+ entity = ( LobHolder ) s.get( LobHolder.class, entity.getId() );
+ assertEquals( BLOB_SIZE, entity.getBlobLocator().length() );
+ assertEquals( changed, extractData( entity.getBlobLocator() ) );
+ s.delete( entity );
+ s.getTransaction().commit();
+ s.close();
+
+ }
+
+ public void testUnboundedBlobLocatorAccess() throws Throwable {
+ if ( ! supportsUnboundedLobLocatorMaterialization() ) {
+ return;
+ }
+
+ // Note: unbounded mutation of the underlying lob data is completely
+ // unsupported; most databases would not allow such a construct anyway.
+ // Thus here we are only testing materialization...
+
+ byte[] original = buildRecursively( BLOB_SIZE, true );
+
+ Session s = openSession();
+ s.beginTransaction();
+ LobHolder entity = new LobHolder();
+ entity.setBlobLocator( Hibernate.createBlob( original ) );
+ s.save( entity );
+ s.getTransaction().commit();
+ s.close();
+
+ // load the entity with the clob locator, and close the session/transaction;
+ // at that point it is unbounded...
+ s = openSession();
+ s.beginTransaction();
+ entity = ( LobHolder ) s.get( LobHolder.class, entity.getId() );
+ s.getTransaction().commit();
+ s.close();
+
+ assertEquals( BLOB_SIZE, entity.getBlobLocator().length() );
+ assertEquals( original, extractData( entity.getBlobLocator() ) );
+
+ s = openSession();
+ s.beginTransaction();
+ s.delete( entity );
+ s.getTransaction().commit();
+ s.close();
+ }
+
+ private byte[] extractData(Blob blob) throws Throwable {
+ return blob.getBytes( 1, ( int ) blob.length() );
+ }
+
+
+ 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" );
+ }
+ }
+}
Deleted:
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/lob/ClobHoldingEntity.hbm.xml
===================================================================
---
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/lob/ClobHoldingEntity.hbm.xml 2006-11-18
04:21:05 UTC (rev 10846)
+++
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/lob/ClobHoldingEntity.hbm.xml 2006-11-21
16:04:45 UTC (rev 10847)
@@ -1,16 +0,0 @@
-<?xml version="1.0"?>
-<!DOCTYPE hibernate-mapping PUBLIC
- "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
- "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
-
-<hibernate-mapping package="org.hibernate.test.lob">
-
- <class name="ClobHoldingEntity" table="CLOB_ENTITY">
- <id name="id" type="long" column="ID">
- <generator class="increment"/>
- </id>
- <property name="serialData" column="SER_DATA"
type="text"/>
- <property name="clobData" column="CLOB_DATA"
type="clob" />
- </class>
-
-</hibernate-mapping>
\ No newline at end of file
Deleted:
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/lob/ClobHoldingEntity.java
===================================================================
---
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/lob/ClobHoldingEntity.java 2006-11-18
04:21:05 UTC (rev 10846)
+++
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/lob/ClobHoldingEntity.java 2006-11-21
16:04:45 UTC (rev 10847)
@@ -1,57 +0,0 @@
-package org.hibernate.test.lob;
-
-import java.sql.Clob;
-
-/**
- * Used to test materialized and lazy-materialized CLOB data.
- * <p/>
- * The {@link #serialData} field is used to hold CLOB data that is
- * materialized into a String immediately (mapped via the
- * Hibernate text type).
- * <p/>
- * The {@link #clobData} field is used to hold CLOB data that is
- * materialized lazily via a JDBC CLOB locator (mapped via
- * the Hibernate clob type).
- *
- * @author Steve Ebersole
- */
-public class ClobHoldingEntity {
- private Long id;
- private String serialData;
- private Clob clobData;
-
- public ClobHoldingEntity() {
- }
-
- public ClobHoldingEntity(String serialData) {
- this.serialData = serialData;
- }
-
- public ClobHoldingEntity(Clob clobData) {
- this.clobData = clobData;
- }
-
- public Long getId() {
- return id;
- }
-
- public void setId(Long id) {
- this.id = id;
- }
-
- public String getSerialData() {
- return serialData;
- }
-
- public void setSerialData(String serialData) {
- this.serialData = serialData;
- }
-
- public Clob getClobData() {
- return clobData;
- }
-
- public void setClobData(Clob clobData) {
- this.clobData = clobData;
- }
-}
Modified: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/lob/ClobTest.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/lob/ClobTest.java 2006-11-18
04:21:05 UTC (rev 10846)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/lob/ClobTest.java 2006-11-21
16:04:45 UTC (rev 10847)
@@ -5,11 +5,12 @@
import junit.framework.Test;
import junit.framework.TestSuite;
-import org.hibernate.test.TestCase;
+import org.hibernate.test.DatabaseSpecificTestCase;
import org.hibernate.Session;
import org.hibernate.Hibernate;
import org.hibernate.LockMode;
import org.hibernate.dialect.H2Dialect;
+import org.hibernate.dialect.Dialect;
/**
* Test various access scenarios for eager and lazy materialization
@@ -18,7 +19,7 @@
*
* @author Steve Ebersole
*/
-public class ClobTest extends TestCase {
+public class ClobTest extends DatabaseSpecificTestCase {
private static final int CLOB_SIZE = 10000;
public ClobTest(String name) {
@@ -26,69 +27,65 @@
}
protected String[] getMappings() {
- return new String[] { "lob/ClobHoldingEntity.hbm.xml" };
+ return new String[] { "lob/LobMappings.hbm.xml" };
}
public static Test suite() {
return new TestSuite( ClobTest.class );
}
- public void testBoundedMaterializedClobAccess() {
- if ( !supportsExpectedLobUsagePattern() ) {
- return;
- }
+ public boolean appliesTo(Dialect dialect) {
+ return supportsExpectedLobUsagePattern();
+ }
+ public void testBoundedMaterializedClobAccess() {
String original = buildRecursively( CLOB_SIZE, 'x' );
String changed = buildRecursively( CLOB_SIZE, 'y' );
Session s = openSession();
s.beginTransaction();
- ClobHoldingEntity entity = new ClobHoldingEntity();
- entity.setSerialData( original );
+ LobHolder entity = new LobHolder();
+ entity.setMaterializedClob( original );
s.save( entity );
s.getTransaction().commit();
s.close();
s = openSession();
s.beginTransaction();
- entity = ( ClobHoldingEntity ) s.get( ClobHoldingEntity.class, entity.getId() );
- assertEquals( CLOB_SIZE, entity.getSerialData().length() );
- assertEquals( original, entity.getSerialData() );
- entity.setSerialData( changed );
+ entity = ( LobHolder ) s.get( LobHolder.class, entity.getId() );
+ assertEquals( CLOB_SIZE, entity.getMaterializedClob().length() );
+ assertEquals( original, entity.getMaterializedClob() );
+ entity.setMaterializedClob( changed );
s.getTransaction().commit();
s.close();
s = openSession();
s.beginTransaction();
- entity = ( ClobHoldingEntity ) s.get( ClobHoldingEntity.class, entity.getId() );
- assertEquals( CLOB_SIZE, entity.getSerialData().length() );
- assertEquals( changed, entity.getSerialData() );
+ entity = ( LobHolder ) s.get( LobHolder.class, entity.getId() );
+ assertEquals( CLOB_SIZE, entity.getMaterializedClob().length() );
+ assertEquals( changed, entity.getMaterializedClob() );
s.delete( entity );
s.getTransaction().commit();
s.close();
}
public void testBoundedClobLocatorAccess() throws Throwable {
- if ( !supportsExpectedLobUsagePattern() ) {
- return;
- }
-
String original = buildRecursively( CLOB_SIZE, 'x' );
String changed = buildRecursively( CLOB_SIZE, 'y' );
Session s = openSession();
s.beginTransaction();
- ClobHoldingEntity entity = new ClobHoldingEntity();
- entity.setClobData( Hibernate.createClob( original ) );
+ LobHolder entity = new LobHolder();
+ entity.setClobLocator( Hibernate.createClob( original ) );
s.save( entity );
s.getTransaction().commit();
s.close();
s = openSession();
s.beginTransaction();
- entity = ( ClobHoldingEntity ) s.get( ClobHoldingEntity.class, entity.getId() );
- assertEquals( CLOB_SIZE, entity.getClobData().length() );
- assertEquals( original, extractData( entity.getClobData() ) );
+ entity = ( LobHolder ) s.get( LobHolder.class, entity.getId() );
+ assertEquals( CLOB_SIZE, entity.getClobLocator().length() );
+ assertEquals( original, extractData( entity.getClobLocator() ) );
s.getTransaction().commit();
s.close();
@@ -96,20 +93,20 @@
if ( supportsLobValueChangePropogation() ) {
s = openSession();
s.beginTransaction();
- entity = ( ClobHoldingEntity ) s.get( ClobHoldingEntity.class, entity.getId(),
LockMode.UPGRADE );
- entity.getClobData().truncate( 1 );
- entity.getClobData().setString( 1, changed );
+ entity = ( LobHolder ) s.get( LobHolder.class, entity.getId(), LockMode.UPGRADE );
+ entity.getClobLocator().truncate( 1 );
+ entity.getClobLocator().setString( 1, changed );
s.getTransaction().commit();
s.close();
s = openSession();
s.beginTransaction();
- entity = ( ClobHoldingEntity ) s.get( ClobHoldingEntity.class, entity.getId(),
LockMode.UPGRADE );
- assertNotNull( entity.getClobData() );
- assertEquals( CLOB_SIZE, entity.getClobData().length() );
- assertEquals( changed, extractData( entity.getClobData() ) );
- entity.getClobData().truncate( 1 );
- entity.getClobData().setString( 1, original );
+ entity = ( LobHolder ) s.get( LobHolder.class, entity.getId(), LockMode.UPGRADE );
+ assertNotNull( entity.getClobLocator() );
+ assertEquals( CLOB_SIZE, entity.getClobLocator().length() );
+ assertEquals( changed, extractData( entity.getClobLocator() ) );
+ entity.getClobLocator().truncate( 1 );
+ entity.getClobLocator().setString( 1, original );
s.getTransaction().commit();
s.close();
}
@@ -117,19 +114,19 @@
// test mutation via supplying a new clob locator instance...
s = openSession();
s.beginTransaction();
- entity = ( ClobHoldingEntity ) s.get( ClobHoldingEntity.class, entity.getId(),
LockMode.UPGRADE );
- assertNotNull( entity.getClobData() );
- assertEquals( CLOB_SIZE, entity.getClobData().length() );
- assertEquals( original, extractData( entity.getClobData() ) );
- entity.setClobData( Hibernate.createClob( changed ) );
+ entity = ( LobHolder ) s.get( LobHolder.class, entity.getId(), LockMode.UPGRADE );
+ assertNotNull( entity.getClobLocator() );
+ assertEquals( CLOB_SIZE, entity.getClobLocator().length() );
+ assertEquals( original, extractData( entity.getClobLocator() ) );
+ entity.setClobLocator( Hibernate.createClob( changed ) );
s.getTransaction().commit();
s.close();
s = openSession();
s.beginTransaction();
- entity = ( ClobHoldingEntity ) s.get( ClobHoldingEntity.class, entity.getId() );
- assertEquals( CLOB_SIZE, entity.getClobData().length() );
- assertEquals( changed, extractData( entity.getClobData() ) );
+ entity = ( LobHolder ) s.get( LobHolder.class, entity.getId() );
+ assertEquals( CLOB_SIZE, entity.getClobLocator().length() );
+ assertEquals( changed, extractData( entity.getClobLocator() ) );
s.delete( entity );
s.getTransaction().commit();
s.close();
@@ -137,7 +134,7 @@
}
public void testUnboundedClobLocatorAccess() throws Throwable {
- if ( !supportsExpectedLobUsagePattern() || !
supportsUnboundedLobLocatorMaterialization() ) {
+ if ( ! supportsUnboundedLobLocatorMaterialization() ) {
return;
}
@@ -149,8 +146,8 @@
Session s = openSession();
s.beginTransaction();
- ClobHoldingEntity entity = new ClobHoldingEntity();
- entity.setClobData( Hibernate.createClob( original ) );
+ LobHolder entity = new LobHolder();
+ entity.setClobLocator( Hibernate.createClob( original ) );
s.save( entity );
s.getTransaction().commit();
s.close();
@@ -159,12 +156,12 @@
// at that point it is unbounded...
s = openSession();
s.beginTransaction();
- entity = ( ClobHoldingEntity ) s.get( ClobHoldingEntity.class, entity.getId() );
+ entity = ( LobHolder ) s.get( LobHolder.class, entity.getId() );
s.getTransaction().commit();
s.close();
- assertEquals( CLOB_SIZE, entity.getClobData().length() );
- assertEquals( original, extractData( entity.getClobData() ) );
+ assertEquals( CLOB_SIZE, entity.getClobLocator().length() );
+ assertEquals( original, extractData( entity.getClobLocator() ) );
s = openSession();
s.beginTransaction();
Added: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/lob/LobHolder.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/lob/LobHolder.java 2006-11-18
04:21:05 UTC (rev 10846)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/lob/LobHolder.java 2006-11-21
16:04:45 UTC (rev 10847)
@@ -0,0 +1,90 @@
+package org.hibernate.test.lob;
+
+import java.io.Serializable;
+import java.sql.Clob;
+import java.sql.Blob;
+
+/**
+ * An entity containing all kinds of good LOB-type data...
+ * <p/>
+ * {@link #serialData} is used to hold general serializable data which is
+ * mapped via the {@link org.hibernate.type.SerializableType}.
+ * <p/>
+ * {@link #materializedClob} is used to hold CLOB data that is materialized
+ * into a String immediately; it is mapped via the
+ * {@link org.hibernate.type.TextType}.
+ * <p/>
+ * {@link #clobLocator} is used to hold CLOB data that is materialized lazily
+ * via a JDBC CLOB locator; it is mapped via the
+ * {@link org.hibernate.type.ClobType}
+ * <p/>
+ * {@link #materializedBlob} is used to hold BLOB data that is materialized
+ * into a byte array immediately; it is mapped via the
+ * {@link org.hibernate.test.lob.MaterializedBlobType}.
+ * <p/>
+ * {@link #blobLocator} is used to hold BLOB data that is materialized lazily
+ * via a JDBC BLOB locator; it is mapped via the
+ * {@link org.hibernate.type.BlobType}
+ *
+ *
+ * @author Steve Ebersole
+ */
+public class LobHolder {
+ private Long id;
+
+ private Serializable serialData;
+
+ private String materializedClob;
+ private Clob clobLocator;
+
+ private byte[] materializedBlob;
+ private Blob blobLocator;
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public Serializable getSerialData() {
+ return serialData;
+ }
+
+ public void setSerialData(Serializable serialData) {
+ this.serialData = serialData;
+ }
+
+ public String getMaterializedClob() {
+ return materializedClob;
+ }
+
+ public void setMaterializedClob(String materializedClob) {
+ this.materializedClob = materializedClob;
+ }
+
+ public Clob getClobLocator() {
+ return clobLocator;
+ }
+
+ public void setClobLocator(Clob clobLocator) {
+ this.clobLocator = clobLocator;
+ }
+
+ public byte[] getMaterializedBlob() {
+ return materializedBlob;
+ }
+
+ public void setMaterializedBlob(byte[] materializedBlob) {
+ this.materializedBlob = materializedBlob;
+ }
+
+ public Blob getBlobLocator() {
+ return blobLocator;
+ }
+
+ public void setBlobLocator(Blob blobLocator) {
+ this.blobLocator = blobLocator;
+ }
+}
Added: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/lob/LobMappings.hbm.xml
===================================================================
---
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/lob/LobMappings.hbm.xml 2006-11-18
04:21:05 UTC (rev 10846)
+++
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/lob/LobMappings.hbm.xml 2006-11-21
16:04:45 UTC (rev 10847)
@@ -0,0 +1,22 @@
+<?xml version="1.0"?>
+<!DOCTYPE hibernate-mapping PUBLIC
+ "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
+ "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
+
+<hibernate-mapping package="org.hibernate.test.lob">
+
+ <class name="LobHolder" table="LOB_ENTITY">
+ <id name="id" type="long" column="ID">
+ <generator class="increment"/>
+ </id>
+
+ <property name="serialData" column="SER_DATA"
type="serializable"/>
+
+ <property name="materializedClob" column="MAT_CLOB_DATA"
type="text"/>
+ <property name="clobLocator" column="CLOB_DATA"
type="clob" />
+
+ <property name="materializedBlob" column="MAT_BLOB_DATA"
type="org.hibernate.test.lob.MaterializedBlobType"/>
+ <property name="blobLocator" column="BLOB_DATA"
type="blob" />
+ </class>
+
+</hibernate-mapping>
\ No newline at end of file
Added: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/lob/LobSuite.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/lob/LobSuite.java 2006-11-18
04:21:05 UTC (rev 10846)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/lob/LobSuite.java 2006-11-21
16:04:45 UTC (rev 10847)
@@ -0,0 +1,19 @@
+package org.hibernate.test.lob;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * {@inheritDoc}
+ *
+ * @author Steve Ebersole
+ */
+public class LobSuite {
+ public static Test suite() {
+ TestSuite suite = new TestSuite( "LOB handling tests" );
+ suite.addTest( SerializableTypeTest.suite() );
+ suite.addTest( BlobTest.suite() );
+ suite.addTest( ClobTest.suite() );
+ return suite;
+ }
+}
Deleted: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/lob/LobTest.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/lob/LobTest.java 2006-11-18
04:21:05 UTC (rev 10846)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/lob/LobTest.java 2006-11-21
16:04:45 UTC (rev 10847)
@@ -1,73 +0,0 @@
-// $Id$
-package org.hibernate.test.lob;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-
-import org.hibernate.Session;
-import org.hibernate.Transaction;
-import org.hibernate.test.TestCase;
-
-/**
- * Implementation of DynamicFilterTest.
- *
- * @author Steve
- */
-public class LobTest extends TestCase {
-
- public LobTest(String testName) {
- super(testName);
- }
-
- public void testNewSerializableType() {
- Session session = openSession();
- Transaction txn = session.beginTransaction();
-
- User user = new User();
- user.setEmail("nobody(a)nowhere.com");
- user.setName(new Name());
- user.getName().setFirstName("John");
- user.getName().setInitial(new Character('Q'));
- user.getName().setLastName("Public");
- user.setPassword("password");
- user.setHandle("myHandle");
-
- String payloadText = "Initial payload";
- user.setSerialData( new SerializableData(payloadText) );
-
- session.save(user);
- txn.commit();
-
- session.close();
- user = null;
-
- session = openSession();
- user = (User) session.createQuery("select u from User as u where u.handle =
:myHandle")
- .setString("myHandle", "myHandle")
- .uniqueResult();
-
- SerializableData serialData = (SerializableData) user.getSerialData();
- assertTrue(payloadText.equals(serialData.getPayload()));
- session.close();
- }
-
- /**
- * Define the mappings needed for these tests.
- *
- * @return Mappings for these tests.
- */
- protected String[] getMappings() {
- return new String[] {
- "lob/User.hbm.xml"
- };
- }
-
- public String getCacheConcurrencyStrategy() {
- return null;
- }
-
- public static Test suite() {
- return new TestSuite(LobTest.class);
- }
-
-}
Added:
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/lob/MaterializedBlobType.java
===================================================================
---
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/lob/MaterializedBlobType.java 2006-11-18
04:21:05 UTC (rev 10846)
+++
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/lob/MaterializedBlobType.java 2006-11-21
16:04:45 UTC (rev 10847)
@@ -0,0 +1,33 @@
+package org.hibernate.test.lob;
+
+import java.sql.Types;
+
+import org.hibernate.type.AbstractBynaryType;
+
+/**
+ * {@inheritDoc}
+ *
+ * @author Steve Ebersole
+ */
+public class MaterializedBlobType extends AbstractBynaryType {
+
+ public int sqlType() {
+ return Types.BLOB;
+ }
+
+ public String getName() {
+ return "materialized-blob";
+ }
+
+ public Class getReturnedClass() {
+ return byte[].class;
+ }
+
+ protected Object toExternalFormat(byte[] bytes) {
+ return bytes;
+ }
+
+ protected byte[] toInternalFormat(Object bytes) {
+ return ( byte[] ) bytes;
+ }
+}
Deleted: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/lob/Name.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/lob/Name.java 2006-11-18
04:21:05 UTC (rev 10846)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/lob/Name.java 2006-11-21
16:04:45 UTC (rev 10847)
@@ -1,58 +0,0 @@
-// $Id$
-package org.hibernate.test.lob;
-
-import java.io.Serializable;
-
-/**
- * Implementation of Name.
- *
- * @author Steve
- */
-public class Name implements Serializable {
-
- private String firstName;
- private String lastName;
- private Character initial;
-
- public Name() {}
-
- public Name(String first, Character middle, String last) {
- firstName = first;
- initial = middle;
- lastName = last;
- }
-
- public String getFirstName() {
- return firstName;
- }
-
- public void setFirstName(String firstName) {
- this.firstName = firstName;
- }
-
- public Character getInitial() {
- return initial;
- }
-
- public void setInitial(Character initial) {
- this.initial = initial;
- }
-
- public String getLastName() {
- return lastName;
- }
-
- public void setLastName(String lastName) {
- this.lastName = lastName;
- }
-
- public String toString() {
- StringBuffer buf = new StringBuffer()
- .append(firstName)
- .append(' ');
- if (initial!=null) buf.append(initial)
- .append(' ');
- return buf.append(lastName)
- .toString();
- }
-}
Copied:
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/lob/SerializableTypeTest.java (from
rev 10805, branches/Branch_3_2/Hibernate3/test/org/hibernate/test/lob/LobTest.java)
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/lob/LobTest.java 2006-11-14
13:07:51 UTC (rev 10805)
+++
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/lob/SerializableTypeTest.java 2006-11-21
16:04:45 UTC (rev 10847)
@@ -0,0 +1,55 @@
+// $Id$
+package org.hibernate.test.lob;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.hibernate.Session;
+import org.hibernate.test.TestCase;
+
+/**
+ * Tests of {@link org.hibernate.type.SerializableType}
+ *
+ * @author Steve Ebersole
+ */
+public class SerializableTypeTest extends TestCase {
+
+ public SerializableTypeTest(String testName) {
+ super( testName );
+ }
+
+ public static Test suite() {
+ return new TestSuite( SerializableTypeTest.class );
+ }
+
+ protected String[] getMappings() {
+ return new String[] { "lob/LobMappings.hbm.xml" };
+ }
+
+ public String getCacheConcurrencyStrategy() {
+ return null;
+ }
+
+ public void testNewSerializableType() {
+ final String payloadText = "Initial payload";
+
+ Session s = openSession();
+ s.beginTransaction();
+ LobHolder holder = new LobHolder();
+ holder.setSerialData( new SerializableData( payloadText ) );
+ s.save( holder );
+ s.getTransaction().commit();
+ s.close();
+
+ s = openSession();
+ s.beginTransaction();
+ holder = ( LobHolder ) s.get( LobHolder.class, holder.getId() );
+ SerializableData serialData = ( SerializableData ) holder.getSerialData();
+ assertEquals( payloadText, serialData.getPayload() );
+ s.delete( holder );
+ s.getTransaction().commit();
+ s.close();
+ }
+
+
+}
Property changes on:
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/lob/SerializableTypeTest.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native
Deleted: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/lob/User.hbm.xml
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/lob/User.hbm.xml 2006-11-18
04:21:05 UTC (rev 10846)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/lob/User.hbm.xml 2006-11-21
16:04:45 UTC (rev 10847)
@@ -1,34 +0,0 @@
-<?xml version="1.0"?>
-<!DOCTYPE hibernate-mapping PUBLIC
- "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
- "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
-
-<hibernate-mapping package="org.hibernate.test.lob">
-
- <class name="User" table="users">
-
- <id name="id" type="long" unsaved-value="null">
- <generator class="increment"/>
- </id>
-
- <!-- We don't change the handle, so map it with update="false".
-->
- <property name="handle" unique="true" not-null="true"
update="false"/>
-
- <!-- password is a keyword in some databases, so quote it -->
- <property name="password" column="`password`"
not-null="true"/>
-
- <property name="email"/>
-
- <property name="serialData" column="ser_data"
type="serializable"/>
-
- <!-- Mapping for the component class Name -->
- <component name="name">
- <property name="firstName"/>
- <!-- initial is a keyword in some databases, so quote it -->
- <property name="initial" column="`initial`"/>
- <property name="lastName"/>
- </component>
-
- </class>
-
-</hibernate-mapping>
\ No newline at end of file
Deleted: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/lob/User.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/lob/User.java 2006-11-18
04:21:05 UTC (rev 10846)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/lob/User.java 2006-11-21
16:04:45 UTC (rev 10847)
@@ -1,79 +0,0 @@
-// $Id$
-package org.hibernate.test.lob;
-
-import java.io.Serializable;
-
-/**
- * Implementation of User.
- *
- * @author Steve
- */
-public class User implements Serializable {
- private Long id;
- private String handle;
- private String password;
- private Name name;
- private String email;
- private Serializable serialData;
-
- public String getHandle() {
- return handle;
- }
-
- public void setHandle(String handle) {
- this.handle = handle;
- }
-
- public Long getId() {
- return id;
- }
-
- protected void setId(Long id) {
- this.id = id;
- }
-
- public Name getName() {
- return name;
- }
-
- public void setName(Name name) {
- this.name = name;
- }
-
- public String getPassword() {
- return password;
- }
-
- public void setPassword(String password) {
- this.password = password;
- }
-
- public String getEmail() {
- return email;
- }
-
- public void setEmail(String email) {
- this.email = email;
- }
-
- public boolean equals(Object other) {
- if (other==null) return false;
- if ( !(other instanceof User) ) return false;
- return ( (User) other ).getHandle().equals(handle);
- }
-
- public int hashCode() {
- return handle.hashCode();
- }
-
-
- public Serializable getSerialData()
- {
- return serialData;
- }
-
- public void setSerialData(Serializable serialData)
- {
- this.serialData = serialData;
- }
-}