HHH-3892 : Improve support for mapping SQL LONGVARCHAR and CLOB to Java String, SQL LONGVARBINARY and BLOB to Java byte[]
git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@16501 1b8cb986-b30d-0410-93ca-fae66ebed9b2
This commit is contained in:
parent
5ae4feefb9
commit
5ee21b3aa8
|
@ -79,6 +79,9 @@ import org.hibernate.type.YesNoType;
|
||||||
import org.hibernate.type.CharArrayType;
|
import org.hibernate.type.CharArrayType;
|
||||||
import org.hibernate.type.WrapperBinaryType;
|
import org.hibernate.type.WrapperBinaryType;
|
||||||
import org.hibernate.type.CharacterArrayType;
|
import org.hibernate.type.CharacterArrayType;
|
||||||
|
import org.hibernate.type.MaterializedBlobType;
|
||||||
|
import org.hibernate.type.ImageType;
|
||||||
|
import org.hibernate.type.MaterializedClobType;
|
||||||
import org.hibernate.usertype.CompositeUserType;
|
import org.hibernate.usertype.CompositeUserType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -177,10 +180,22 @@ public final class Hibernate {
|
||||||
* Hibernate Character[] type.
|
* Hibernate Character[] type.
|
||||||
*/
|
*/
|
||||||
public static final NullableType CHARACTER_ARRAY = new CharacterArrayType();
|
public static final NullableType CHARACTER_ARRAY = new CharacterArrayType();
|
||||||
|
/**
|
||||||
|
* Hibernate <tt>image</tt> type.
|
||||||
|
*/
|
||||||
|
public static final NullableType IMAGE = new ImageType();
|
||||||
/**
|
/**
|
||||||
* Hibernate <tt>text</tt> type.
|
* Hibernate <tt>text</tt> type.
|
||||||
*/
|
*/
|
||||||
public static final NullableType TEXT = new TextType();
|
public static final NullableType TEXT = new TextType();
|
||||||
|
/**
|
||||||
|
* Hibernate <tt>materialized_blob</tt> type.
|
||||||
|
*/
|
||||||
|
public static final NullableType MATERIALIZED_BLOB = new MaterializedBlobType();
|
||||||
|
/**
|
||||||
|
* Hibernate <tt>materialized_clob</tt> type.
|
||||||
|
*/
|
||||||
|
public static final NullableType MATERIALIZED_CLOB = new MaterializedClobType();
|
||||||
/**
|
/**
|
||||||
* Hibernate <tt>blob</tt> type.
|
* Hibernate <tt>blob</tt> type.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -61,6 +61,8 @@ public class DB2Dialect extends Dialect {
|
||||||
registerColumnType( Types.NUMERIC, "numeric($p,$s)" );
|
registerColumnType( Types.NUMERIC, "numeric($p,$s)" );
|
||||||
registerColumnType( Types.BLOB, "blob($l)" );
|
registerColumnType( Types.BLOB, "blob($l)" );
|
||||||
registerColumnType( Types.CLOB, "clob($l)" );
|
registerColumnType( Types.CLOB, "clob($l)" );
|
||||||
|
registerColumnType( Types.LONGVARCHAR, "long varchar" );
|
||||||
|
registerColumnType( Types.LONGVARBINARY, "long varchar for bit data" );
|
||||||
|
|
||||||
registerFunction("abs", new StandardSQLFunction("abs") );
|
registerFunction("abs", new StandardSQLFunction("abs") );
|
||||||
registerFunction("absval", new StandardSQLFunction("absval") );
|
registerFunction("absval", new StandardSQLFunction("absval") );
|
||||||
|
|
|
@ -81,6 +81,8 @@ public class HSQLDialect extends Dialect {
|
||||||
//HSQL has no Blob/Clob support .... but just put these here for now!
|
//HSQL has no Blob/Clob support .... but just put these here for now!
|
||||||
registerColumnType( Types.BLOB, "longvarbinary" );
|
registerColumnType( Types.BLOB, "longvarbinary" );
|
||||||
registerColumnType( Types.CLOB, "longvarchar" );
|
registerColumnType( Types.CLOB, "longvarchar" );
|
||||||
|
registerColumnType( Types.LONGVARBINARY, "longvarbinary" );
|
||||||
|
registerColumnType( Types.LONGVARCHAR, "longvarchar" );
|
||||||
|
|
||||||
registerFunction( "ascii", new StandardSQLFunction( "ascii", Hibernate.INTEGER ) );
|
registerFunction( "ascii", new StandardSQLFunction( "ascii", Hibernate.INTEGER ) );
|
||||||
registerFunction( "char", new StandardSQLFunction( "char", Hibernate.CHARACTER ) );
|
registerFunction( "char", new StandardSQLFunction( "char", Hibernate.CHARACTER ) );
|
||||||
|
|
|
@ -36,5 +36,6 @@ public class MySQL5Dialect extends MySQLDialect {
|
||||||
registerColumnType( Types.VARCHAR, "longtext" );
|
registerColumnType( Types.VARCHAR, "longtext" );
|
||||||
// registerColumnType( Types.VARCHAR, 16777215, "mediumtext" );
|
// registerColumnType( Types.VARCHAR, 16777215, "mediumtext" );
|
||||||
registerColumnType( Types.VARCHAR, 65535, "varchar($l)" );
|
registerColumnType( Types.VARCHAR, 65535, "varchar($l)" );
|
||||||
|
registerColumnType( Types.LONGVARCHAR, "longtext" );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,6 +59,8 @@ public class MySQLDialect extends Dialect {
|
||||||
registerColumnType( Types.VARBINARY, 16777215, "mediumblob" );
|
registerColumnType( Types.VARBINARY, 16777215, "mediumblob" );
|
||||||
registerColumnType( Types.VARBINARY, 65535, "blob" );
|
registerColumnType( Types.VARBINARY, 65535, "blob" );
|
||||||
registerColumnType( Types.VARBINARY, 255, "tinyblob" );
|
registerColumnType( Types.VARBINARY, 255, "tinyblob" );
|
||||||
|
registerColumnType( Types.LONGVARBINARY, "longblob" );
|
||||||
|
registerColumnType( Types.LONGVARBINARY, 16777215, "mediumblob" );
|
||||||
registerColumnType( Types.NUMERIC, "decimal($p,$s)" );
|
registerColumnType( Types.NUMERIC, "decimal($p,$s)" );
|
||||||
registerColumnType( Types.BLOB, "longblob" );
|
registerColumnType( Types.BLOB, "longblob" );
|
||||||
// registerColumnType( Types.BLOB, 16777215, "mediumblob" );
|
// registerColumnType( Types.BLOB, 16777215, "mediumblob" );
|
||||||
|
@ -181,6 +183,7 @@ public class MySQLDialect extends Dialect {
|
||||||
// registerColumnType( Types.VARCHAR, 16777215, "mediumtext" );
|
// registerColumnType( Types.VARCHAR, 16777215, "mediumtext" );
|
||||||
// registerColumnType( Types.VARCHAR, 65535, "text" );
|
// registerColumnType( Types.VARCHAR, 65535, "text" );
|
||||||
registerColumnType( Types.VARCHAR, 255, "varchar($l)" );
|
registerColumnType( Types.VARCHAR, 255, "varchar($l)" );
|
||||||
|
registerColumnType( Types.LONGVARCHAR, "longtext" );
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getAddColumnString() {
|
public String getAddColumnString() {
|
||||||
|
|
|
@ -98,6 +98,9 @@ public class Oracle8iDialect extends Dialect {
|
||||||
|
|
||||||
registerColumnType( Types.BLOB, "blob" );
|
registerColumnType( Types.BLOB, "blob" );
|
||||||
registerColumnType( Types.CLOB, "clob" );
|
registerColumnType( Types.CLOB, "clob" );
|
||||||
|
|
||||||
|
registerColumnType( Types.LONGVARCHAR, "long" );
|
||||||
|
registerColumnType( Types.LONGVARBINARY, "long raw" );
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void registerReverseHibernateTypeMappings() {
|
protected void registerReverseHibernateTypeMappings() {
|
||||||
|
|
|
@ -62,6 +62,8 @@ public class PostgreSQLDialect extends Dialect {
|
||||||
registerColumnType( Types.TIME, "time" );
|
registerColumnType( Types.TIME, "time" );
|
||||||
registerColumnType( Types.TIMESTAMP, "timestamp" );
|
registerColumnType( Types.TIMESTAMP, "timestamp" );
|
||||||
registerColumnType( Types.VARBINARY, "bytea" );
|
registerColumnType( Types.VARBINARY, "bytea" );
|
||||||
|
registerColumnType( Types.LONGVARCHAR, "text" );
|
||||||
|
registerColumnType( Types.LONGVARBINARY, "bytea" );
|
||||||
registerColumnType( Types.CLOB, "text" );
|
registerColumnType( Types.CLOB, "text" );
|
||||||
registerColumnType( Types.BLOB, "oid" );
|
registerColumnType( Types.BLOB, "oid" );
|
||||||
registerColumnType( Types.NUMERIC, "numeric($p, $s)" );
|
registerColumnType( Types.NUMERIC, "numeric($p, $s)" );
|
||||||
|
|
|
@ -42,6 +42,8 @@ public class SQLServerDialect extends SybaseDialect {
|
||||||
public SQLServerDialect() {
|
public SQLServerDialect() {
|
||||||
registerColumnType( Types.VARBINARY, "image" );
|
registerColumnType( Types.VARBINARY, "image" );
|
||||||
registerColumnType( Types.VARBINARY, 8000, "varbinary($l)" );
|
registerColumnType( Types.VARBINARY, 8000, "varbinary($l)" );
|
||||||
|
registerColumnType( Types.LONGVARBINARY, "image" );
|
||||||
|
registerColumnType( Types.LONGVARCHAR, "text" );
|
||||||
|
|
||||||
registerFunction( "second", new SQLFunctionTemplate( Hibernate.INTEGER, "datepart(second, ?1)" ) );
|
registerFunction( "second", new SQLFunctionTemplate( Hibernate.INTEGER, "datepart(second, ?1)" ) );
|
||||||
registerFunction( "minute", new SQLFunctionTemplate( Hibernate.INTEGER, "datepart(minute, ?1)" ) );
|
registerFunction( "minute", new SQLFunctionTemplate( Hibernate.INTEGER, "datepart(minute, ?1)" ) );
|
||||||
|
|
|
@ -50,6 +50,10 @@ import org.hibernate.dialect.function.VarArgsSQLFunction;
|
||||||
public class SybaseASE15Dialect extends AbstractTransactSQLDialect {
|
public class SybaseASE15Dialect extends AbstractTransactSQLDialect {
|
||||||
public SybaseASE15Dialect() {
|
public SybaseASE15Dialect() {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
|
registerColumnType( Types.LONGVARBINARY, "image" );
|
||||||
|
registerColumnType( Types.LONGVARCHAR, "text" );
|
||||||
|
|
||||||
registerFunction( "second", new SQLFunctionTemplate(Hibernate.INTEGER, "datepart(second, ?1)") );
|
registerFunction( "second", new SQLFunctionTemplate(Hibernate.INTEGER, "datepart(second, ?1)") );
|
||||||
registerFunction( "minute", new SQLFunctionTemplate(Hibernate.INTEGER, "datepart(minute, ?1)") );
|
registerFunction( "minute", new SQLFunctionTemplate(Hibernate.INTEGER, "datepart(minute, ?1)") );
|
||||||
registerFunction( "hour", new SQLFunctionTemplate(Hibernate.INTEGER, "datepart(hour, ?1)") );
|
registerFunction( "hour", new SQLFunctionTemplate(Hibernate.INTEGER, "datepart(hour, ?1)") );
|
||||||
|
|
|
@ -0,0 +1,46 @@
|
||||||
|
//$Id: $
|
||||||
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2008, 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.type;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An abstract type for mapping long binary SQL types to Java byte[].
|
||||||
|
*
|
||||||
|
* @author Gail Badner
|
||||||
|
*/
|
||||||
|
public abstract class AbstractLongBinaryType extends AbstractBynaryType {
|
||||||
|
|
||||||
|
public Class getReturnedClass() {
|
||||||
|
return byte[].class;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Object toExternalFormat(byte[] bytes) {
|
||||||
|
return bytes;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected byte[] toInternalFormat(Object bytes) {
|
||||||
|
return ( byte[] ) bytes;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,94 @@
|
||||||
|
//$Id: $
|
||||||
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2008, 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.type;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.Reader;
|
||||||
|
import java.io.StringReader;
|
||||||
|
import java.sql.PreparedStatement;
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
|
||||||
|
import org.hibernate.HibernateException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An abstract type for mapping long string SQL types to a Java String.
|
||||||
|
* @author Gavin King, Bertrand Renuart (from TextType)
|
||||||
|
*/
|
||||||
|
public abstract class AbstractLongStringType extends ImmutableType {
|
||||||
|
|
||||||
|
public void set(PreparedStatement st, Object value, int index) throws HibernateException, SQLException {
|
||||||
|
String str = (String) value;
|
||||||
|
st.setCharacterStream( index, new StringReader(str), str.length() );
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object get(ResultSet rs, String name) throws HibernateException, SQLException {
|
||||||
|
|
||||||
|
// Retrieve the value of the designated column in the current row of this
|
||||||
|
// ResultSet object as a java.io.Reader object
|
||||||
|
Reader charReader = rs.getCharacterStream(name);
|
||||||
|
|
||||||
|
// if the corresponding SQL value is NULL, the reader we got is NULL as well
|
||||||
|
if (charReader==null) return null;
|
||||||
|
|
||||||
|
// Fetch Reader content up to the end - and put characters in a StringBuffer
|
||||||
|
StringBuffer sb = new StringBuffer();
|
||||||
|
try {
|
||||||
|
char[] buffer = new char[2048];
|
||||||
|
while (true) {
|
||||||
|
int amountRead = charReader.read(buffer, 0, buffer.length);
|
||||||
|
if ( amountRead == -1 ) break;
|
||||||
|
sb.append(buffer, 0, amountRead);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (IOException ioe) {
|
||||||
|
throw new HibernateException( "IOException occurred reading text", ioe );
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
try {
|
||||||
|
charReader.close();
|
||||||
|
}
|
||||||
|
catch (IOException e) {
|
||||||
|
throw new HibernateException( "IOException occurred closing stream", e );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return StringBuffer content as a large String
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Class getReturnedClass() {
|
||||||
|
return String.class;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toString(Object val) {
|
||||||
|
return (String) val;
|
||||||
|
}
|
||||||
|
public Object fromStringValue(String xml) {
|
||||||
|
return xml;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,44 @@
|
||||||
|
//$Id: $
|
||||||
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2008, 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.type;
|
||||||
|
|
||||||
|
import java.sql.Types;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <tt>image</tt>: A type that maps an SQL LONGVARBINARY to Java byte[].
|
||||||
|
*
|
||||||
|
* @author Gail Badner
|
||||||
|
*/
|
||||||
|
public class ImageType extends AbstractLongBinaryType {
|
||||||
|
|
||||||
|
public int sqlType() {
|
||||||
|
return Types.LONGVARBINARY;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return "image";
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,44 @@
|
||||||
|
//$Id: $
|
||||||
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2008, 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.type;
|
||||||
|
|
||||||
|
import java.sql.Types;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <tt>materialized_blob</tt>: A type that maps an SQL BLOB to Java byte[].
|
||||||
|
*
|
||||||
|
* @author Gail Badner
|
||||||
|
*/
|
||||||
|
public class MaterializedBlobType extends AbstractLongBinaryType {
|
||||||
|
|
||||||
|
public int sqlType() {
|
||||||
|
return Types.BLOB;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return "materialized_blob";
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,42 @@
|
||||||
|
//$Id: $
|
||||||
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2008, 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.type;
|
||||||
|
|
||||||
|
import java.sql.Types;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <tt>materialized_clob</tt>: A type that maps an SQL CLOB to a Java String.
|
||||||
|
*
|
||||||
|
* @author Gail Badner
|
||||||
|
*/
|
||||||
|
public class MaterializedClobType extends AbstractLongStringType {
|
||||||
|
|
||||||
|
public int sqlType() {
|
||||||
|
return Types.CLOB;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() { return "materialized_clob"; }
|
||||||
|
}
|
|
@ -1,3 +1,4 @@
|
||||||
|
//$Id: $
|
||||||
/*
|
/*
|
||||||
* Hibernate, Relational Persistence for Idiomatic Java
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
*
|
*
|
||||||
|
@ -24,79 +25,21 @@
|
||||||
*/
|
*/
|
||||||
package org.hibernate.type;
|
package org.hibernate.type;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.Reader;
|
|
||||||
import java.io.StringReader;
|
|
||||||
import java.sql.PreparedStatement;
|
|
||||||
import java.sql.ResultSet;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.sql.Types;
|
import java.sql.Types;
|
||||||
|
|
||||||
import org.hibernate.HibernateException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <tt>text</tt>: A type that maps an SQL CLOB to a Java String.
|
* <tt>text</tt>: A type that maps an SQL LONGVARCHAR to a Java String.
|
||||||
* @author Gavin King, Bertrand Renuart
|
*
|
||||||
|
* @author Gail Badner
|
||||||
*/
|
*/
|
||||||
public class TextType extends ImmutableType {
|
public class TextType extends AbstractLongStringType {
|
||||||
|
|
||||||
public void set(PreparedStatement st, Object value, int index) throws HibernateException, SQLException {
|
|
||||||
String str = (String) value;
|
|
||||||
st.setCharacterStream( index, new StringReader(str), str.length() );
|
|
||||||
}
|
|
||||||
|
|
||||||
public Object get(ResultSet rs, String name) throws HibernateException, SQLException {
|
|
||||||
|
|
||||||
// Retrieve the value of the designated column in the current row of this
|
|
||||||
// ResultSet object as a java.io.Reader object
|
|
||||||
Reader charReader = rs.getCharacterStream(name);
|
|
||||||
|
|
||||||
// if the corresponding SQL value is NULL, the reader we got is NULL as well
|
|
||||||
if (charReader==null) return null;
|
|
||||||
|
|
||||||
// Fetch Reader content up to the end - and put characters in a StringBuffer
|
|
||||||
StringBuffer sb = new StringBuffer();
|
|
||||||
try {
|
|
||||||
char[] buffer = new char[2048];
|
|
||||||
while (true) {
|
|
||||||
int amountRead = charReader.read(buffer, 0, buffer.length);
|
|
||||||
if ( amountRead == -1 ) break;
|
|
||||||
sb.append(buffer, 0, amountRead);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (IOException ioe) {
|
|
||||||
throw new HibernateException( "IOException occurred reading text", ioe );
|
|
||||||
}
|
|
||||||
finally {
|
|
||||||
try {
|
|
||||||
charReader.close();
|
|
||||||
}
|
|
||||||
catch (IOException e) {
|
|
||||||
throw new HibernateException( "IOException occurred closing stream", e );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Return StringBuffer content as a large String
|
|
||||||
return sb.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
public int sqlType() {
|
public int sqlType() {
|
||||||
return Types.CLOB; //or Types.LONGVARCHAR?
|
return Types.LONGVARCHAR;
|
||||||
}
|
|
||||||
|
|
||||||
public Class getReturnedClass() {
|
|
||||||
return String.class;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() { return "text"; }
|
public String getName() { return "text"; }
|
||||||
|
|
||||||
public String toString(Object val) {
|
|
||||||
return (String) val;
|
|
||||||
}
|
|
||||||
public Object fromStringValue(String xml) {
|
|
||||||
return xml;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -90,7 +90,10 @@ public final class TypeFactory {
|
||||||
basics.put( Hibernate.TRUE_FALSE.getName(), Hibernate.TRUE_FALSE );
|
basics.put( Hibernate.TRUE_FALSE.getName(), Hibernate.TRUE_FALSE );
|
||||||
basics.put( Hibernate.YES_NO.getName(), Hibernate.YES_NO );
|
basics.put( Hibernate.YES_NO.getName(), Hibernate.YES_NO );
|
||||||
basics.put( Hibernate.BINARY.getName(), Hibernate.BINARY );
|
basics.put( Hibernate.BINARY.getName(), Hibernate.BINARY );
|
||||||
|
basics.put( Hibernate.IMAGE.getName(), Hibernate.IMAGE );
|
||||||
basics.put( Hibernate.TEXT.getName(), Hibernate.TEXT );
|
basics.put( Hibernate.TEXT.getName(), Hibernate.TEXT );
|
||||||
|
basics.put( Hibernate.MATERIALIZED_BLOB.getName(), Hibernate.MATERIALIZED_BLOB );
|
||||||
|
basics.put( Hibernate.MATERIALIZED_CLOB.getName(), Hibernate.MATERIALIZED_CLOB );
|
||||||
basics.put( Hibernate.BLOB.getName(), Hibernate.BLOB );
|
basics.put( Hibernate.BLOB.getName(), Hibernate.BLOB );
|
||||||
basics.put( Hibernate.CLOB.getName(), Hibernate.CLOB );
|
basics.put( Hibernate.CLOB.getName(), Hibernate.CLOB );
|
||||||
basics.put( Hibernate.BIG_DECIMAL.getName(), Hibernate.BIG_DECIMAL );
|
basics.put( Hibernate.BIG_DECIMAL.getName(), Hibernate.BIG_DECIMAL );
|
||||||
|
|
|
@ -1,3 +1,28 @@
|
||||||
|
//$Id: $
|
||||||
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2008, 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.lob;
|
package org.hibernate.test.lob;
|
||||||
|
|
||||||
import java.sql.Blob;
|
import java.sql.Blob;
|
||||||
|
@ -14,14 +39,16 @@ import org.hibernate.junit.functional.FunctionalTestClassTestSuite;
|
||||||
import org.hibernate.util.ArrayHelper;
|
import org.hibernate.util.ArrayHelper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* Tests lazy materialization of data mapped by
|
||||||
|
* {@link org.hibernate.type.BlobType}, as well as bounded and unbounded
|
||||||
|
* materialization and mutation.
|
||||||
*
|
*
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
*/
|
*/
|
||||||
public class BlobTest extends DatabaseSpecificFunctionalTestCase {
|
public class BlobLocatorTest extends DatabaseSpecificFunctionalTestCase {
|
||||||
private static final int BLOB_SIZE = 10000;
|
private static final int BLOB_SIZE = 10000;
|
||||||
|
|
||||||
public BlobTest(String name) {
|
public BlobLocatorTest(String name) {
|
||||||
super( name );
|
super( name );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,7 +57,7 @@ public class BlobTest extends DatabaseSpecificFunctionalTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Test suite() {
|
public static Test suite() {
|
||||||
return new FunctionalTestClassTestSuite( BlobTest.class );
|
return new FunctionalTestClassTestSuite( BlobLocatorTest.class );
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean appliesTo(Dialect dialect) {
|
public boolean appliesTo(Dialect dialect) {
|
||||||
|
@ -41,37 +68,6 @@ public class BlobTest extends DatabaseSpecificFunctionalTestCase {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
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 {
|
public void testBoundedBlobLocatorAccess() throws Throwable {
|
||||||
byte[] original = buildRecursively( BLOB_SIZE, true );
|
byte[] original = buildRecursively( BLOB_SIZE, true );
|
||||||
byte[] changed = buildRecursively( BLOB_SIZE, false );
|
byte[] changed = buildRecursively( BLOB_SIZE, false );
|
|
@ -1,3 +1,28 @@
|
||||||
|
//$Id: $
|
||||||
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2008, 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.lob;
|
package org.hibernate.test.lob;
|
||||||
|
|
||||||
import java.sql.Clob;
|
import java.sql.Clob;
|
||||||
|
@ -13,16 +38,16 @@ import org.hibernate.junit.functional.DatabaseSpecificFunctionalTestCase;
|
||||||
import org.hibernate.junit.functional.FunctionalTestClassTestSuite;
|
import org.hibernate.junit.functional.FunctionalTestClassTestSuite;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test various access scenarios for eager and lazy materialization
|
* Tests lazy materialization of data mapped by
|
||||||
* of CLOB data, as well as bounded and unbounded materialization
|
* {@link org.hibernate.type.ClobType} as well as bounded and unbounded
|
||||||
* and mutation.
|
* materialization and mutation.
|
||||||
*
|
*
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
*/
|
*/
|
||||||
public class ClobTest extends DatabaseSpecificFunctionalTestCase {
|
public class ClobLocatorTest extends DatabaseSpecificFunctionalTestCase {
|
||||||
private static final int CLOB_SIZE = 10000;
|
private static final int CLOB_SIZE = 10000;
|
||||||
|
|
||||||
public ClobTest(String name) {
|
public ClobLocatorTest(String name) {
|
||||||
super( name );
|
super( name );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,7 +56,7 @@ public class ClobTest extends DatabaseSpecificFunctionalTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Test suite() {
|
public static Test suite() {
|
||||||
return new FunctionalTestClassTestSuite( ClobTest.class );
|
return new FunctionalTestClassTestSuite( ClobLocatorTest.class );
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean appliesTo(Dialect dialect) {
|
public boolean appliesTo(Dialect dialect) {
|
||||||
|
@ -42,37 +67,6 @@ public class ClobTest extends DatabaseSpecificFunctionalTestCase {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testBoundedMaterializedClobAccess() {
|
|
||||||
String original = buildRecursively( CLOB_SIZE, 'x' );
|
|
||||||
String changed = buildRecursively( CLOB_SIZE, 'y' );
|
|
||||||
|
|
||||||
Session s = openSession();
|
|
||||||
s.beginTransaction();
|
|
||||||
LobHolder entity = new LobHolder();
|
|
||||||
entity.setMaterializedClob( original );
|
|
||||||
s.save( entity );
|
|
||||||
s.getTransaction().commit();
|
|
||||||
s.close();
|
|
||||||
|
|
||||||
s = openSession();
|
|
||||||
s.beginTransaction();
|
|
||||||
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 = ( 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 {
|
public void testBoundedClobLocatorAccess() throws Throwable {
|
||||||
String original = buildRecursively( CLOB_SIZE, 'x' );
|
String original = buildRecursively( CLOB_SIZE, 'x' );
|
||||||
String changed = buildRecursively( CLOB_SIZE, 'y' );
|
String changed = buildRecursively( CLOB_SIZE, 'y' );
|
|
@ -0,0 +1,16 @@
|
||||||
|
<?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="LongByteArrayHolder" table="LOB_ENTITY_IMAGE">
|
||||||
|
<id name="id" type="long" column="ID">
|
||||||
|
<generator class="increment"/>
|
||||||
|
</id>
|
||||||
|
|
||||||
|
<property name="longByteArray" column="LONG_BYTE_ARRAY" type="image" length="15000"/>
|
||||||
|
</class>
|
||||||
|
|
||||||
|
</hibernate-mapping>
|
|
@ -0,0 +1,51 @@
|
||||||
|
//$Id: $
|
||||||
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2008, 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.lob;
|
||||||
|
|
||||||
|
import junit.framework.Test;
|
||||||
|
|
||||||
|
import org.hibernate.junit.functional.FunctionalTestClassTestSuite;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests eager materialization and mutation of data mapped by
|
||||||
|
* {@link org.hibernate.type.ImageType}.
|
||||||
|
*
|
||||||
|
* @author Gail Badner
|
||||||
|
*/
|
||||||
|
public class ImageTest extends LongByteArrayTest {
|
||||||
|
|
||||||
|
public ImageTest(String name) {
|
||||||
|
super( name );
|
||||||
|
}
|
||||||
|
|
||||||
|
public String[] getMappings() {
|
||||||
|
return new String[] { "lob/ImageMappings.hbm.xml" };
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Test suite() {
|
||||||
|
return new FunctionalTestClassTestSuite( ImageTest.class );
|
||||||
|
}
|
||||||
|
}
|
|
@ -7,21 +7,10 @@ import java.sql.Blob;
|
||||||
/**
|
/**
|
||||||
* An entity containing all kinds of good LOB-type data...
|
* An entity containing all kinds of good LOB-type data...
|
||||||
* <p/>
|
* <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
|
* {@link #clobLocator} is used to hold CLOB data that is materialized lazily
|
||||||
* via a JDBC CLOB locator; it is mapped via the
|
* via a JDBC CLOB locator; it is mapped via the
|
||||||
* {@link org.hibernate.type.ClobType}
|
* {@link org.hibernate.type.ClobType}
|
||||||
* <p/>
|
* <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
|
* {@link #blobLocator} is used to hold BLOB data that is materialized lazily
|
||||||
* via a JDBC BLOB locator; it is mapped via the
|
* via a JDBC BLOB locator; it is mapped via the
|
||||||
* {@link org.hibernate.type.BlobType}
|
* {@link org.hibernate.type.BlobType}
|
||||||
|
@ -32,12 +21,8 @@ import java.sql.Blob;
|
||||||
public class LobHolder {
|
public class LobHolder {
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
private Serializable serialData;
|
|
||||||
|
|
||||||
private String materializedClob;
|
|
||||||
private Clob clobLocator;
|
private Clob clobLocator;
|
||||||
|
|
||||||
private byte[] materializedBlob;
|
|
||||||
private Blob blobLocator;
|
private Blob blobLocator;
|
||||||
|
|
||||||
public Long getId() {
|
public Long getId() {
|
||||||
|
@ -48,22 +33,6 @@ public class LobHolder {
|
||||||
this.id = 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() {
|
public Clob getClobLocator() {
|
||||||
return clobLocator;
|
return clobLocator;
|
||||||
}
|
}
|
||||||
|
@ -72,14 +41,6 @@ public class LobHolder {
|
||||||
this.clobLocator = clobLocator;
|
this.clobLocator = clobLocator;
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte[] getMaterializedBlob() {
|
|
||||||
return materializedBlob;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setMaterializedBlob(byte[] materializedBlob) {
|
|
||||||
this.materializedBlob = materializedBlob;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Blob getBlobLocator() {
|
public Blob getBlobLocator() {
|
||||||
return blobLocator;
|
return blobLocator;
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,13 +10,9 @@
|
||||||
<generator class="increment"/>
|
<generator class="increment"/>
|
||||||
</id>
|
</id>
|
||||||
|
|
||||||
<property name="serialData" column="SER_DATA" type="serializable"/>
|
<property name="clobLocator" column="CLOB_DATA" type="clob" length="15000" />
|
||||||
|
|
||||||
<property name="materializedClob" column="MAT_CLOB_DATA" type="text" length="15000"/>
|
<property name="blobLocator" column="BLOB_DATA" type="blob" length="15000" />
|
||||||
<property name="clobLocator" column="CLOB_DATA" type="clob" length="15000"/>
|
|
||||||
|
|
||||||
<property name="materializedBlob" column="MAT_BLOB_DATA" type="org.hibernate.test.lob.MaterializedBlobType" length="15000"/>
|
|
||||||
<property name="blobLocator" column="BLOB_DATA" type="blob" length="15000"/>
|
|
||||||
</class>
|
</class>
|
||||||
|
|
||||||
</hibernate-mapping>
|
</hibernate-mapping>
|
|
@ -0,0 +1,54 @@
|
||||||
|
//$Id: $
|
||||||
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2008, 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.lob;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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
|
||||||
|
*/
|
||||||
|
public class LongByteArrayHolder {
|
||||||
|
private Long id;
|
||||||
|
private byte[] longByteArray;
|
||||||
|
|
||||||
|
public Long getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(Long id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte[] getLongByteArray() {
|
||||||
|
return longByteArray;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLongByteArray(byte[] longByteArray) {
|
||||||
|
this.longByteArray = longByteArray;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,110 @@
|
||||||
|
//$Id: $
|
||||||
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2008, 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.lob;
|
||||||
|
|
||||||
|
import junit.framework.AssertionFailedError;
|
||||||
|
import org.hibernate.Session;
|
||||||
|
import org.hibernate.junit.functional.DatabaseSpecificFunctionalTestCase;
|
||||||
|
import org.hibernate.util.ArrayHelper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests eager materialization and mutation of long byte arrays.
|
||||||
|
*
|
||||||
|
* @author Steve Ebersole
|
||||||
|
*/
|
||||||
|
public abstract class LongByteArrayTest extends DatabaseSpecificFunctionalTestCase {
|
||||||
|
private static final int ARRAY_SIZE = 10000;
|
||||||
|
|
||||||
|
public LongByteArrayTest(String name) {
|
||||||
|
super( name );
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testBoundedLongByteArrayAccess() {
|
||||||
|
byte[] original = buildRecursively( ARRAY_SIZE, true );
|
||||||
|
byte[] changed = buildRecursively( ARRAY_SIZE, false );
|
||||||
|
|
||||||
|
Session s = openSession();
|
||||||
|
s.beginTransaction();
|
||||||
|
LongByteArrayHolder entity = new LongByteArrayHolder();
|
||||||
|
s.save( entity );
|
||||||
|
s.getTransaction().commit();
|
||||||
|
s.close();
|
||||||
|
|
||||||
|
s = openSession();
|
||||||
|
s.beginTransaction();
|
||||||
|
entity = ( LongByteArrayHolder ) s.get( LongByteArrayHolder.class, entity.getId() );
|
||||||
|
assertNull( entity.getLongByteArray() );
|
||||||
|
entity.setLongByteArray( original );
|
||||||
|
s.getTransaction().commit();
|
||||||
|
s.close();
|
||||||
|
|
||||||
|
s = openSession();
|
||||||
|
s.beginTransaction();
|
||||||
|
entity = ( LongByteArrayHolder ) s.get( LongByteArrayHolder.class, entity.getId() );
|
||||||
|
assertEquals( ARRAY_SIZE, entity.getLongByteArray().length );
|
||||||
|
assertEquals( original, entity.getLongByteArray() );
|
||||||
|
entity.setLongByteArray( changed );
|
||||||
|
s.getTransaction().commit();
|
||||||
|
s.close();
|
||||||
|
|
||||||
|
s = openSession();
|
||||||
|
s.beginTransaction();
|
||||||
|
entity = ( LongByteArrayHolder ) s.get( LongByteArrayHolder.class, entity.getId() );
|
||||||
|
assertEquals( ARRAY_SIZE, entity.getLongByteArray().length );
|
||||||
|
assertEquals( changed, entity.getLongByteArray() );
|
||||||
|
entity.setLongByteArray( null );
|
||||||
|
s.getTransaction().commit();
|
||||||
|
s.close();
|
||||||
|
|
||||||
|
s = openSession();
|
||||||
|
s.beginTransaction();
|
||||||
|
entity = ( LongByteArrayHolder ) s.get( LongByteArrayHolder.class, entity.getId() );
|
||||||
|
assertNull( entity.getLongByteArray() );
|
||||||
|
s.delete( entity );
|
||||||
|
s.getTransaction().commit();
|
||||||
|
s.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
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" );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,53 @@
|
||||||
|
//$Id: $
|
||||||
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2008, 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.lob;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An entity containing data that is materialized into a String immediately.
|
||||||
|
*
|
||||||
|
* @author Gail Badner
|
||||||
|
*/
|
||||||
|
public class LongStringHolder {
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
private String longString;
|
||||||
|
|
||||||
|
public Long getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(Long id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLongString() {
|
||||||
|
return longString;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLongString(String longString) {
|
||||||
|
this.longString = longString;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,99 @@
|
||||||
|
//$Id: $
|
||||||
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2008, 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.lob;
|
||||||
|
|
||||||
|
import junit.framework.Test;
|
||||||
|
|
||||||
|
import org.hibernate.Session;
|
||||||
|
import org.hibernate.junit.functional.DatabaseSpecificFunctionalTestCase;
|
||||||
|
import org.hibernate.junit.functional.FunctionalTestClassTestSuite;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests eager materialization and mutation of long strings.
|
||||||
|
*
|
||||||
|
* @author Steve Ebersole
|
||||||
|
*/
|
||||||
|
public abstract class LongStringTest extends DatabaseSpecificFunctionalTestCase {
|
||||||
|
private static final int LONG_STRING_SIZE = 10000;
|
||||||
|
|
||||||
|
public LongStringTest(String name) {
|
||||||
|
super( name );
|
||||||
|
}
|
||||||
|
|
||||||
|
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() );
|
||||||
|
entity.setLongString( original );
|
||||||
|
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() );
|
||||||
|
entity.setLongString( changed );
|
||||||
|
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() );
|
||||||
|
entity.setLongString( null );
|
||||||
|
s.getTransaction().commit();
|
||||||
|
s.close();
|
||||||
|
|
||||||
|
s = openSession();
|
||||||
|
s.beginTransaction();
|
||||||
|
entity = ( LongStringHolder ) s.get( LongStringHolder.class, entity.getId() );
|
||||||
|
assertNull( entity.getLongString() );
|
||||||
|
s.delete( entity );
|
||||||
|
s.getTransaction().commit();
|
||||||
|
s.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
private String buildRecursively(int size, char baseChar) {
|
||||||
|
StringBuffer buff = new StringBuffer();
|
||||||
|
for( int i = 0; i < size; i++ ) {
|
||||||
|
buff.append( baseChar );
|
||||||
|
}
|
||||||
|
return buff.toString();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,16 @@
|
||||||
|
<?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="LongByteArrayHolder" table="LOB_ENTITY_MAT_BLOB">
|
||||||
|
<id name="id" type="long" column="ID">
|
||||||
|
<generator class="increment"/>
|
||||||
|
</id>
|
||||||
|
|
||||||
|
<property name="longByteArray" column="LONG_BYTE_ARRAY" type="materialized_blob" length="15000"/>
|
||||||
|
</class>
|
||||||
|
|
||||||
|
</hibernate-mapping>
|
|
@ -0,0 +1,60 @@
|
||||||
|
//$Id: $
|
||||||
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2008, 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.lob;
|
||||||
|
|
||||||
|
import junit.framework.Test;
|
||||||
|
|
||||||
|
import org.hibernate.junit.functional.FunctionalTestClassTestSuite;
|
||||||
|
import org.hibernate.dialect.Dialect;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests eager materialization and mutation of data mapped by
|
||||||
|
* {@link org.hibernate.type.MaterializedBlobType}.
|
||||||
|
*
|
||||||
|
* @author Gail Badner
|
||||||
|
*/
|
||||||
|
public class MaterializedBlobTest extends LongByteArrayTest {
|
||||||
|
|
||||||
|
public MaterializedBlobTest(String name) {
|
||||||
|
super( name );
|
||||||
|
}
|
||||||
|
|
||||||
|
public String[] getMappings() {
|
||||||
|
return new String[] { "lob/MaterializedBlobMappings.hbm.xml" };
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Test suite() {
|
||||||
|
return new FunctionalTestClassTestSuite( MaterializedBlobTest.class );
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean appliesTo(Dialect dialect) {
|
||||||
|
if ( ! dialect.supportsExpectedLobUsagePattern() ) {
|
||||||
|
reportSkip( "database/driver does not support expected LOB usage pattern", "LOB support" );
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,33 +0,0 @@
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
<?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="LongStringHolder" table="LOB_ENTITY_MAT_CLOB">
|
||||||
|
<id name="id" type="long" column="ID">
|
||||||
|
<generator class="increment"/>
|
||||||
|
</id>
|
||||||
|
|
||||||
|
<property name="longString" column="LONG_STR" type="materialized_clob" length="15000"/>
|
||||||
|
</class>
|
||||||
|
|
||||||
|
</hibernate-mapping>
|
|
@ -0,0 +1,60 @@
|
||||||
|
//$Id: $
|
||||||
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2008, 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.lob;
|
||||||
|
|
||||||
|
import junit.framework.Test;
|
||||||
|
|
||||||
|
import org.hibernate.junit.functional.FunctionalTestClassTestSuite;
|
||||||
|
import org.hibernate.dialect.Dialect;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests eager materialization and mutation of data mapped by
|
||||||
|
* {@link org.hibernate.type.MaterializedClobType}.
|
||||||
|
*
|
||||||
|
* @author Gail Badner
|
||||||
|
*/
|
||||||
|
public class MaterializedClobTest extends LongStringTest {
|
||||||
|
|
||||||
|
public MaterializedClobTest(String name) {
|
||||||
|
super( name );
|
||||||
|
}
|
||||||
|
|
||||||
|
public String[] getMappings() {
|
||||||
|
return new String[] { "lob/MaterializedClobMappings.hbm.xml" };
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Test suite() {
|
||||||
|
return new FunctionalTestClassTestSuite( MaterializedClobTest.class );
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean appliesTo(Dialect dialect) {
|
||||||
|
if ( ! dialect.supportsExpectedLobUsagePattern() ) {
|
||||||
|
reportSkip( "database/driver does not support expected LOB usage pattern", "LOB support" );
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,56 @@
|
||||||
|
//$Id: $
|
||||||
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2008, 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.lob;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An entity containing serializable data which is
|
||||||
|
* mapped via the {@link org.hibernate.type.SerializableType}.
|
||||||
|
*
|
||||||
|
* @author Steve Ebersole
|
||||||
|
*/
|
||||||
|
public class SerializableHolder {
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
private Serializable serialData;
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,16 @@
|
||||||
|
<?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="SerializableHolder" table="LOB_ENTITY">
|
||||||
|
<id name="id" type="long" column="ID">
|
||||||
|
<generator class="increment"/>
|
||||||
|
</id>
|
||||||
|
|
||||||
|
<property name="serialData" column="SER_DATA" type="serializable"/>
|
||||||
|
</class>
|
||||||
|
|
||||||
|
</hibernate-mapping>
|
|
@ -24,7 +24,7 @@ public class SerializableTypeTest extends FunctionalTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public String[] getMappings() {
|
public String[] getMappings() {
|
||||||
return new String[] { "lob/LobMappings.hbm.xml" };
|
return new String[] { "lob/SerializableMappings.hbm.xml" };
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Test suite() {
|
public static Test suite() {
|
||||||
|
@ -37,30 +37,49 @@ public class SerializableTypeTest extends FunctionalTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testNewSerializableType() {
|
public void testNewSerializableType() {
|
||||||
// Sybase dialects do not support ResultSet.getBlob(String)
|
final String initialPayloadText = "Initial payload";
|
||||||
if ( getDialect() instanceof SybaseDialect || getDialect() instanceof Sybase11Dialect || getDialect() instanceof SybaseASE15Dialect || getDialect() instanceof SybaseAnywhereDialect ) {
|
final String changedPayloadText = "Changed payload";
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
final String payloadText = "Initial payload";
|
|
||||||
|
|
||||||
Session s = openSession();
|
Session s = openSession();
|
||||||
s.beginTransaction();
|
s.beginTransaction();
|
||||||
LobHolder holder = new LobHolder();
|
SerializableHolder holder = new SerializableHolder();
|
||||||
holder.setSerialData( new SerializableData( payloadText ) );
|
|
||||||
s.save( holder );
|
s.save( holder );
|
||||||
s.getTransaction().commit();
|
s.getTransaction().commit();
|
||||||
s.close();
|
s.close();
|
||||||
|
|
||||||
s = openSession();
|
s = openSession();
|
||||||
s.beginTransaction();
|
s.beginTransaction();
|
||||||
holder = ( LobHolder ) s.get( LobHolder.class, holder.getId() );
|
holder = ( SerializableHolder ) s.get( SerializableHolder.class, holder.getId() );
|
||||||
|
assertNull( holder.getSerialData() );
|
||||||
|
holder.setSerialData( new SerializableData( initialPayloadText ) );
|
||||||
|
s.getTransaction().commit();
|
||||||
|
s.close();
|
||||||
|
|
||||||
|
s = openSession();
|
||||||
|
s.beginTransaction();
|
||||||
|
holder = ( SerializableHolder ) s.get( SerializableHolder.class, holder.getId() );
|
||||||
SerializableData serialData = ( SerializableData ) holder.getSerialData();
|
SerializableData serialData = ( SerializableData ) holder.getSerialData();
|
||||||
assertEquals( payloadText, serialData.getPayload() );
|
assertEquals( initialPayloadText, serialData.getPayload() );
|
||||||
|
holder.setSerialData( new SerializableData( changedPayloadText ) );
|
||||||
|
s.getTransaction().commit();
|
||||||
|
s.close();
|
||||||
|
|
||||||
|
s = openSession();
|
||||||
|
s.beginTransaction();
|
||||||
|
holder = ( SerializableHolder ) s.get( SerializableHolder.class, holder.getId() );
|
||||||
|
serialData = ( SerializableData ) holder.getSerialData();
|
||||||
|
assertEquals( changedPayloadText, serialData.getPayload() );
|
||||||
|
holder.setSerialData( null );
|
||||||
|
s.getTransaction().commit();
|
||||||
|
s.close();
|
||||||
|
|
||||||
|
s = openSession();
|
||||||
|
s.beginTransaction();
|
||||||
|
holder = ( SerializableHolder ) s.get( SerializableHolder.class, holder.getId() );
|
||||||
|
assertNull( holder.getSerialData() );
|
||||||
s.delete( holder );
|
s.delete( holder );
|
||||||
s.getTransaction().commit();
|
s.getTransaction().commit();
|
||||||
s.close();
|
s.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
<?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="LongStringHolder" table="LOB_ENTITY_TEXT">
|
||||||
|
<id name="id" type="long" column="ID">
|
||||||
|
<generator class="increment"/>
|
||||||
|
</id>
|
||||||
|
|
||||||
|
<property name="longString" column="LONG_STR" type="text" length="15000"/>
|
||||||
|
</class>
|
||||||
|
|
||||||
|
</hibernate-mapping>
|
|
@ -0,0 +1,51 @@
|
||||||
|
//$Id: $
|
||||||
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2008, 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.lob;
|
||||||
|
|
||||||
|
import junit.framework.Test;
|
||||||
|
|
||||||
|
import org.hibernate.junit.functional.FunctionalTestClassTestSuite;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test eager materialization and mutation data mapped by
|
||||||
|
* #{@link org.hibernate.type.TextType}.
|
||||||
|
*
|
||||||
|
* @author Gail Badner
|
||||||
|
*/
|
||||||
|
public class TextTest extends LongStringTest {
|
||||||
|
|
||||||
|
public TextTest(String name) {
|
||||||
|
super( name );
|
||||||
|
}
|
||||||
|
|
||||||
|
public String[] getMappings() {
|
||||||
|
return new String[] { "lob/TextMappings.hbm.xml" };
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Test suite() {
|
||||||
|
return new FunctionalTestClassTestSuite( TextTest.class );
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue