HHH-8336 remove deprecated types
This commit is contained in:
parent
2e78a00482
commit
21c3a17d4c
|
@ -1,186 +0,0 @@
|
||||||
/*
|
|
||||||
* Hibernate, Relational Persistence for Idiomatic Java
|
|
||||||
*
|
|
||||||
* Copyright (c) 2010, Red Hat Inc. or third-party contributors as
|
|
||||||
* indicated by the @author tags or express copyright attribution
|
|
||||||
* statements applied by the authors. All third-party contributions are
|
|
||||||
* distributed under license by Red Hat Inc.
|
|
||||||
*
|
|
||||||
* This copyrighted material is made available to anyone wishing to use, modify,
|
|
||||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
|
||||||
* Lesser General Public License, as published by the Free Software Foundation.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
||||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
|
||||||
* for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Lesser General Public License
|
|
||||||
* along with this distribution; if not, write to:
|
|
||||||
* Free Software Foundation, Inc.
|
|
||||||
* 51 Franklin Street, Fifth Floor
|
|
||||||
* Boston, MA 02110-1301 USA
|
|
||||||
*/
|
|
||||||
package org.hibernate.type;
|
|
||||||
import java.io.ByteArrayInputStream;
|
|
||||||
import java.io.ByteArrayOutputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.sql.PreparedStatement;
|
|
||||||
import java.sql.ResultSet;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.sql.Types;
|
|
||||||
import java.util.Comparator;
|
|
||||||
|
|
||||||
import org.hibernate.HibernateException;
|
|
||||||
import org.hibernate.cfg.Environment;
|
|
||||||
import org.hibernate.engine.spi.SessionImplementor;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Logic to bind stream of byte into a VARBINARY
|
|
||||||
*
|
|
||||||
* @author Gavin King
|
|
||||||
* @author Emmanuel Bernard
|
|
||||||
*
|
|
||||||
* @deprecated Use the {@link AbstractStandardBasicType} approach instead
|
|
||||||
*/
|
|
||||||
public abstract class AbstractBynaryType extends MutableType implements VersionType, Comparator {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Convert the byte[] into the expected object type
|
|
||||||
*/
|
|
||||||
abstract protected Object toExternalFormat(byte[] bytes);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Convert the object into the internal byte[] representation
|
|
||||||
*/
|
|
||||||
abstract protected byte[] toInternalFormat(Object bytes);
|
|
||||||
|
|
||||||
public void set(PreparedStatement st, Object value, int index) throws HibernateException, SQLException {
|
|
||||||
byte[] internalValue = toInternalFormat( value );
|
|
||||||
if ( Environment.useStreamsForBinary() ) {
|
|
||||||
st.setBinaryStream( index, new ByteArrayInputStream( internalValue ), internalValue.length );
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
st.setBytes( index, internalValue );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Object get(ResultSet rs, String name) throws HibernateException, SQLException {
|
|
||||||
|
|
||||||
if ( Environment.useStreamsForBinary() ) {
|
|
||||||
|
|
||||||
InputStream inputStream = rs.getBinaryStream(name);
|
|
||||||
|
|
||||||
if (inputStream==null) return toExternalFormat( null ); // is this really necessary?
|
|
||||||
|
|
||||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream(2048);
|
|
||||||
byte[] buffer = new byte[2048];
|
|
||||||
|
|
||||||
try {
|
|
||||||
while (true) {
|
|
||||||
int amountRead = inputStream.read(buffer);
|
|
||||||
if (amountRead == -1) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
outputStream.write(buffer, 0, amountRead);
|
|
||||||
}
|
|
||||||
|
|
||||||
inputStream.close();
|
|
||||||
outputStream.close();
|
|
||||||
}
|
|
||||||
catch (IOException ioe) {
|
|
||||||
throw new HibernateException( "IOException occurred reading a binary value", ioe );
|
|
||||||
}
|
|
||||||
|
|
||||||
return toExternalFormat( outputStream.toByteArray() );
|
|
||||||
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return toExternalFormat( rs.getBytes(name) );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public int sqlType() {
|
|
||||||
return Types.VARBINARY;
|
|
||||||
}
|
|
||||||
|
|
||||||
// VersionType impl ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
||||||
// Note : simply returns null for seed() and next() as the only known
|
|
||||||
// application of binary types for versioning is for use with the
|
|
||||||
// TIMESTAMP datatype supported by Sybase and SQL Server, which
|
|
||||||
// are completely db-generated values...
|
|
||||||
public Object seed(SessionImplementor session) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Object next(Object current, SessionImplementor session) {
|
|
||||||
return current;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Comparator getComparator() {
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
||||||
|
|
||||||
public boolean isEqual(Object x, Object y) {
|
|
||||||
return x==y || ( x!=null && y!=null && java.util.Arrays.equals( toInternalFormat(x), toInternalFormat(y) ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getHashCode(Object x) {
|
|
||||||
byte[] bytes = toInternalFormat(x);
|
|
||||||
int hashCode = 1;
|
|
||||||
for ( int j=0; j<bytes.length; j++ ) {
|
|
||||||
hashCode = 31 * hashCode + bytes[j];
|
|
||||||
}
|
|
||||||
return hashCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int compare(Object x, Object y) {
|
|
||||||
byte[] xbytes = toInternalFormat(x);
|
|
||||||
byte[] ybytes = toInternalFormat(y);
|
|
||||||
if ( xbytes.length < ybytes.length ) return -1;
|
|
||||||
if ( xbytes.length > ybytes.length ) return 1;
|
|
||||||
for ( int i=0; i<xbytes.length; i++ ) {
|
|
||||||
if ( xbytes[i] < ybytes[i] ) return -1;
|
|
||||||
if ( xbytes[i] > ybytes[i] ) return 1;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public abstract String getName();
|
|
||||||
|
|
||||||
public String toString(Object val) {
|
|
||||||
byte[] bytes = toInternalFormat(val);
|
|
||||||
StringBuilder buf = new StringBuilder();
|
|
||||||
for ( int i=0; i<bytes.length; i++ ) {
|
|
||||||
String hexStr = Integer.toHexString( bytes[i] - Byte.MIN_VALUE );
|
|
||||||
if ( hexStr.length()==1 ) buf.append('0');
|
|
||||||
buf.append(hexStr);
|
|
||||||
}
|
|
||||||
return buf.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Object deepCopyNotNull(Object value) {
|
|
||||||
byte[] bytes = toInternalFormat(value);
|
|
||||||
byte[] result = new byte[bytes.length];
|
|
||||||
System.arraycopy(bytes, 0, result, 0, bytes.length);
|
|
||||||
return toExternalFormat(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Object fromStringValue(String xml) throws HibernateException {
|
|
||||||
if (xml == null)
|
|
||||||
return null;
|
|
||||||
if (xml.length() % 2 != 0)
|
|
||||||
throw new IllegalArgumentException("The string is not a valid xml representation of a binary content.");
|
|
||||||
byte[] bytes = new byte[xml.length() / 2];
|
|
||||||
for (int i = 0; i < bytes.length; i++) {
|
|
||||||
String hexStr = xml.substring(i * 2, (i + 1) * 2);
|
|
||||||
bytes[i] = (byte) (Integer.parseInt(hexStr, 16) + Byte.MIN_VALUE);
|
|
||||||
}
|
|
||||||
return toExternalFormat(bytes);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,120 +0,0 @@
|
||||||
/*
|
|
||||||
* Hibernate, Relational Persistence for Idiomatic Java
|
|
||||||
*
|
|
||||||
* Copyright (c) 2010, Red Hat Inc. or third-party contributors as
|
|
||||||
* indicated by the @author tags or express copyright attribution
|
|
||||||
* statements applied by the authors. All third-party contributions are
|
|
||||||
* distributed under license by Red Hat Inc.
|
|
||||||
*
|
|
||||||
* This copyrighted material is made available to anyone wishing to use, modify,
|
|
||||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
|
||||||
* Lesser General Public License, as published by the Free Software Foundation.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
||||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
|
||||||
* for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Lesser General Public License
|
|
||||||
* along with this distribution; if not, write to:
|
|
||||||
* Free Software Foundation, Inc.
|
|
||||||
* 51 Franklin Street, Fifth Floor
|
|
||||||
* Boston, MA 02110-1301 USA
|
|
||||||
*/
|
|
||||||
package org.hibernate.type;
|
|
||||||
|
|
||||||
import java.io.CharArrayReader;
|
|
||||||
import java.io.CharArrayWriter;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.Reader;
|
|
||||||
import java.sql.PreparedStatement;
|
|
||||||
import java.sql.ResultSet;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.sql.Types;
|
|
||||||
|
|
||||||
import org.hibernate.HibernateException;
|
|
||||||
import org.hibernate.dialect.Dialect;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Logic to bind stream of char into a VARCHAR
|
|
||||||
*
|
|
||||||
* @author Emmanuel Bernard
|
|
||||||
*
|
|
||||||
* @deprecated Use the {@link AbstractStandardBasicType} approach instead
|
|
||||||
*/
|
|
||||||
public abstract class AbstractCharArrayType extends MutableType {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Convert the char[] into the expected object type
|
|
||||||
*/
|
|
||||||
abstract protected Object toExternalFormat(char[] chars);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Convert the object into the internal char[] representation
|
|
||||||
*/
|
|
||||||
abstract protected char[] toInternalFormat(Object chars);
|
|
||||||
|
|
||||||
public Object get(ResultSet rs, String name) throws SQLException {
|
|
||||||
Reader stream = rs.getCharacterStream(name);
|
|
||||||
if ( stream == null ) return toExternalFormat( null );
|
|
||||||
CharArrayWriter writer = new CharArrayWriter();
|
|
||||||
for(;;) {
|
|
||||||
try {
|
|
||||||
int c = stream.read();
|
|
||||||
if ( c == -1) return toExternalFormat( writer.toCharArray() );
|
|
||||||
writer.write( c );
|
|
||||||
}
|
|
||||||
catch (IOException e) {
|
|
||||||
throw new HibernateException("Unable to read character stream from rs");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public abstract Class getReturnedClass();
|
|
||||||
|
|
||||||
public void set(PreparedStatement st, Object value, int index) throws SQLException {
|
|
||||||
char[] chars = toInternalFormat( value );
|
|
||||||
st.setCharacterStream(index, new CharArrayReader(chars), chars.length);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int sqlType() {
|
|
||||||
return Types.VARCHAR;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String objectToSQLString(Object value, Dialect dialect) throws Exception {
|
|
||||||
|
|
||||||
return '\'' + new String( toInternalFormat( value ) ) + '\'';
|
|
||||||
}
|
|
||||||
|
|
||||||
public Object stringToObject(String xml) throws Exception {
|
|
||||||
if (xml == null) return toExternalFormat( null );
|
|
||||||
int length = xml.length();
|
|
||||||
char[] chars = new char[length];
|
|
||||||
for (int index = 0 ; index < length ; index++ ) {
|
|
||||||
chars[index] = xml.charAt( index );
|
|
||||||
}
|
|
||||||
return toExternalFormat( chars );
|
|
||||||
}
|
|
||||||
|
|
||||||
public String toString(Object value) {
|
|
||||||
if (value == null) return null;
|
|
||||||
return new String( toInternalFormat( value ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
public Object fromStringValue(String xml) {
|
|
||||||
if (xml == null) return null;
|
|
||||||
int length = xml.length();
|
|
||||||
char[] chars = new char[length];
|
|
||||||
for (int index = 0 ; index < length ; index++ ) {
|
|
||||||
chars[index] = xml.charAt( index );
|
|
||||||
}
|
|
||||||
return toExternalFormat( chars );
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Object deepCopyNotNull(Object value) throws HibernateException {
|
|
||||||
char[] chars = toInternalFormat(value);
|
|
||||||
char[] result = new char[chars.length];
|
|
||||||
System.arraycopy(chars, 0, result, 0, chars.length);
|
|
||||||
return toExternalFormat(result);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,37 +0,0 @@
|
||||||
/*
|
|
||||||
* Hibernate, Relational Persistence for Idiomatic Java
|
|
||||||
*
|
|
||||||
* Copyright (c) 2010, Red Hat Inc. or third-party contributors as
|
|
||||||
* indicated by the @author tags or express copyright attribution
|
|
||||||
* statements applied by the authors. All third-party contributions are
|
|
||||||
* distributed under license by Red Hat Inc.
|
|
||||||
*
|
|
||||||
* This copyrighted material is made available to anyone wishing to use, modify,
|
|
||||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
|
||||||
* Lesser General Public License, as published by the Free Software Foundation.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
||||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
|
||||||
* for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Lesser General Public License
|
|
||||||
* along with this distribution; if not, write to:
|
|
||||||
* Free Software Foundation, Inc.
|
|
||||||
* 51 Franklin Street, Fifth Floor
|
|
||||||
* Boston, MA 02110-1301 USA
|
|
||||||
*/
|
|
||||||
package org.hibernate.type;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Enables other Component-like types to hold collections and have cascades, etc.
|
|
||||||
*
|
|
||||||
* @see ComponentType
|
|
||||||
* @see AnyType
|
|
||||||
* @author Gavin King
|
|
||||||
*
|
|
||||||
* @deprecated in favor of {@link org.hibernate.type.CompositeType}
|
|
||||||
*/
|
|
||||||
public interface AbstractComponentType extends CompositeType {
|
|
||||||
}
|
|
|
@ -1,100 +0,0 @@
|
||||||
/*
|
|
||||||
* 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.Serializable;
|
|
||||||
import java.sql.PreparedStatement;
|
|
||||||
import java.sql.ResultSet;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
|
|
||||||
import org.hibernate.HibernateException;
|
|
||||||
import org.hibernate.MappingException;
|
|
||||||
import org.hibernate.engine.spi.Mapping;
|
|
||||||
import org.hibernate.engine.spi.SessionImplementor;
|
|
||||||
import org.hibernate.metamodel.spi.relational.Size;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Emmanuel Bernard
|
|
||||||
* @deprecated
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public abstract class AbstractLobType extends AbstractType implements Serializable {
|
|
||||||
public boolean isDirty(Object old, Object current, boolean[] checkable, SessionImplementor session)
|
|
||||||
throws HibernateException {
|
|
||||||
return checkable[0] ? ! isEqual( old, current ) : false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Size[] dictatedSizes(Mapping mapping) throws MappingException {
|
|
||||||
return new Size[] { LEGACY_DICTATED_SIZE };
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Size[] defaultSizes(Mapping mapping) throws MappingException {
|
|
||||||
return new Size[] { LEGACY_DEFAULT_SIZE };
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isEqual(Object x, Object y) {
|
|
||||||
return isEqual( x, y, null );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getHashCode(Object x) {
|
|
||||||
return getHashCode( x, null );
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return this.getClass().getName();
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getColumnSpan(Mapping mapping) throws MappingException {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected abstract Object get(ResultSet rs, String name) throws SQLException;
|
|
||||||
|
|
||||||
public Object nullSafeGet(ResultSet rs, String[] names, SessionImplementor session, Object owner)
|
|
||||||
throws HibernateException, SQLException {
|
|
||||||
return get( rs, names[0] );
|
|
||||||
}
|
|
||||||
|
|
||||||
public Object nullSafeGet(ResultSet rs, String name, SessionImplementor session, Object owner)
|
|
||||||
throws HibernateException, SQLException {
|
|
||||||
return get( rs, name );
|
|
||||||
}
|
|
||||||
|
|
||||||
public void nullSafeSet(
|
|
||||||
PreparedStatement st, Object value, int index, boolean[] settable, SessionImplementor session
|
|
||||||
) throws HibernateException, SQLException {
|
|
||||||
if ( settable[0] ) set( st, value, index, session );
|
|
||||||
}
|
|
||||||
|
|
||||||
protected abstract void set(PreparedStatement st, Object value, int index, SessionImplementor session)
|
|
||||||
throws SQLException;
|
|
||||||
|
|
||||||
public void nullSafeSet(PreparedStatement st, Object value, int index, SessionImplementor session)
|
|
||||||
throws HibernateException, SQLException {
|
|
||||||
set( st, value, index, session );
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,47 +0,0 @@
|
||||||
/*
|
|
||||||
* Hibernate, Relational Persistence for Idiomatic Java
|
|
||||||
*
|
|
||||||
* Copyright (c) 2010, Red Hat Inc. or third-party contributors as
|
|
||||||
* indicated by the @author tags or express copyright attribution
|
|
||||||
* statements applied by the authors. All third-party contributions are
|
|
||||||
* distributed under license by Red Hat Inc.
|
|
||||||
*
|
|
||||||
* This copyrighted material is made available to anyone wishing to use, modify,
|
|
||||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
|
||||||
* Lesser General Public License, as published by the Free Software Foundation.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
||||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
|
||||||
* for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Lesser General Public License
|
|
||||||
* along with this distribution; if not, write to:
|
|
||||||
* Free Software Foundation, Inc.
|
|
||||||
* 51 Franklin Street, Fifth Floor
|
|
||||||
* Boston, MA 02110-1301 USA
|
|
||||||
*/
|
|
||||||
package org.hibernate.type;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* An abstract type for mapping long binary SQL types to Java byte[].
|
|
||||||
*
|
|
||||||
* @author Gail Badner
|
|
||||||
*
|
|
||||||
* @deprecated Use the {@link AbstractStandardBasicType} approach instead
|
|
||||||
*/
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,94 +0,0 @@
|
||||||
/*
|
|
||||||
* Hibernate, Relational Persistence for Idiomatic Java
|
|
||||||
*
|
|
||||||
* Copyright (c) 2010, Red Hat Inc. or third-party contributors as
|
|
||||||
* indicated by the @author tags or express copyright attribution
|
|
||||||
* statements applied by the authors. All third-party contributions are
|
|
||||||
* distributed under license by Red Hat Inc.
|
|
||||||
*
|
|
||||||
* This copyrighted material is made available to anyone wishing to use, modify,
|
|
||||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
|
||||||
* Lesser General Public License, as published by the Free Software Foundation.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
||||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
|
||||||
* for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Lesser General Public License
|
|
||||||
* along with this distribution; if not, write to:
|
|
||||||
* Free Software Foundation, Inc.
|
|
||||||
* 51 Franklin Street, Fifth Floor
|
|
||||||
* Boston, MA 02110-1301 USA
|
|
||||||
*/
|
|
||||||
package org.hibernate.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)
|
|
||||||
*
|
|
||||||
* @deprecated Use the {@link AbstractStandardBasicType} approach instead
|
|
||||||
*/
|
|
||||||
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 StringBuilder
|
|
||||||
StringBuilder sb = new StringBuilder();
|
|
||||||
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 StringBuilder 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,193 +0,0 @@
|
||||||
/*
|
|
||||||
* Hibernate, Relational Persistence for Idiomatic Java
|
|
||||||
*
|
|
||||||
* Copyright (c) 2010, Red Hat Inc. or third-party contributors as
|
|
||||||
* indicated by the @author tags or express copyright attribution
|
|
||||||
* statements applied by the authors. All third-party contributions are
|
|
||||||
* distributed under license by Red Hat Inc.
|
|
||||||
*
|
|
||||||
* This copyrighted material is made available to anyone wishing to use, modify,
|
|
||||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
|
||||||
* Lesser General Public License, as published by the Free Software Foundation.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
||||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
|
||||||
* for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Lesser General Public License
|
|
||||||
* along with this distribution; if not, write to:
|
|
||||||
* Free Software Foundation, Inc.
|
|
||||||
* 51 Franklin Street, Fifth Floor
|
|
||||||
* Boston, MA 02110-1301 USA
|
|
||||||
*/
|
|
||||||
package org.hibernate.type;
|
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
|
||||||
import java.sql.Blob;
|
|
||||||
import java.sql.PreparedStatement;
|
|
||||||
import java.sql.ResultSet;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.sql.Types;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import org.hibernate.Hibernate;
|
|
||||||
import org.hibernate.HibernateException;
|
|
||||||
import org.hibernate.engine.spi.Mapping;
|
|
||||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
|
||||||
import org.hibernate.engine.spi.SessionImplementor;
|
|
||||||
import org.hibernate.internal.util.collections.ArrayHelper;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Map a Byte[] into a Blob
|
|
||||||
* Experimental
|
|
||||||
*
|
|
||||||
* @author Emmanuel Bernard
|
|
||||||
* @deprecated replaced by {@link org.hibernate.type.WrappedMaterializedBlobType}
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public class ByteArrayBlobType extends AbstractLobType {
|
|
||||||
private static final int[] TYPES = new int[] { Types.BLOB };
|
|
||||||
|
|
||||||
public int[] sqlTypes(Mapping mapping) {
|
|
||||||
return TYPES;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isEqual(Object x, Object y, SessionFactoryImplementor factory) {
|
|
||||||
if ( x == y ) return true;
|
|
||||||
if ( x == null || y == null ) return false;
|
|
||||||
if ( x instanceof Byte[] ) {
|
|
||||||
Object[] o1 = (Object[]) x;
|
|
||||||
Object[] o2 = (Object[]) y;
|
|
||||||
return ArrayHelper.isEquals( o1, o2 );
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
byte[] c1 = (byte[]) x;
|
|
||||||
byte[] c2 = (byte[]) y;
|
|
||||||
return ArrayHelper.isEquals( c1, c2 );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getHashCode(Object x, SessionFactoryImplementor factory) {
|
|
||||||
if ( x instanceof Character[] ) {
|
|
||||||
Object[] o = (Object[]) x;
|
|
||||||
return ArrayHelper.hash( o );
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
byte[] c = (byte[]) x;
|
|
||||||
return ArrayHelper.hash( c );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Object deepCopy(Object value, SessionFactoryImplementor factory)
|
|
||||||
throws HibernateException {
|
|
||||||
if ( value == null ) return null;
|
|
||||||
if ( value instanceof Byte[] ) {
|
|
||||||
Byte[] array = (Byte[]) value;
|
|
||||||
int length = array.length;
|
|
||||||
Byte[] copy = new Byte[length];
|
|
||||||
for ( int index = 0; index < length ; index++ ) {
|
|
||||||
copy[index] = array[index];
|
|
||||||
}
|
|
||||||
return copy;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
byte[] array = (byte[]) value;
|
|
||||||
int length = array.length;
|
|
||||||
byte[] copy = new byte[length];
|
|
||||||
System.arraycopy( array, 0, copy, 0, length );
|
|
||||||
return copy;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Class getReturnedClass() {
|
|
||||||
return Byte[].class;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Object get(ResultSet rs, String name) throws SQLException {
|
|
||||||
Blob blob = rs.getBlob( name );
|
|
||||||
if ( rs.wasNull() ) return null;
|
|
||||||
int length = (int) blob.length();
|
|
||||||
byte[] primaryResult = blob.getBytes( 1, length );
|
|
||||||
return wrap( primaryResult );
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void set(PreparedStatement st, Object value, int index, SessionImplementor session) throws SQLException {
|
|
||||||
if ( value == null ) {
|
|
||||||
st.setNull( index, sqlTypes( null )[0] );
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
byte[] toSet = unWrap( value );
|
|
||||||
final boolean useInputStream = session.getFactory().getDialect().useInputStreamToInsertBlob();
|
|
||||||
|
|
||||||
if ( useInputStream ) {
|
|
||||||
st.setBinaryStream( index, new ByteArrayInputStream( toSet ), toSet.length );
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
st.setBlob( index, Hibernate.getLobCreator( session ).createBlob( toSet ) );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public String toString(Object val) {
|
|
||||||
byte[] bytes = unWrap( val );
|
|
||||||
StringBuilder buf = new StringBuilder( 2 * bytes.length );
|
|
||||||
for ( int i = 0; i < bytes.length ; i++ ) {
|
|
||||||
String hexStr = Integer.toHexString( bytes[i] - Byte.MIN_VALUE );
|
|
||||||
if ( hexStr.length() == 1 ) buf.append( '0' );
|
|
||||||
buf.append( hexStr );
|
|
||||||
}
|
|
||||||
return buf.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
public String toLoggableString(Object value, SessionFactoryImplementor factory) {
|
|
||||||
return value == null ? "null" : toString( value );
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Object wrap(byte[] bytes) {
|
|
||||||
return wrapPrimitive( bytes );
|
|
||||||
}
|
|
||||||
|
|
||||||
protected byte[] unWrap(Object bytes) {
|
|
||||||
return unwrapNonPrimitive( (Byte[]) bytes );
|
|
||||||
}
|
|
||||||
|
|
||||||
private byte[] unwrapNonPrimitive(Byte[] bytes) {
|
|
||||||
int length = bytes.length;
|
|
||||||
byte[] result = new byte[length];
|
|
||||||
for ( int i = 0; i < length ; i++ ) {
|
|
||||||
result[i] = bytes[i];
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Byte[] wrapPrimitive(byte[] bytes) {
|
|
||||||
int length = bytes.length;
|
|
||||||
Byte[] result = new Byte[length];
|
|
||||||
for ( int index = 0; index < length ; index++ ) {
|
|
||||||
result[index] = bytes[index];
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isMutable() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Object replace(
|
|
||||||
Object original,
|
|
||||||
Object target,
|
|
||||||
SessionImplementor session,
|
|
||||||
Object owner,
|
|
||||||
Map copyCache
|
|
||||||
)
|
|
||||||
throws HibernateException {
|
|
||||||
if ( isEqual( original, target ) ) return original;
|
|
||||||
return deepCopy( original, session.getFactory() );
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean[] toColumnNullness(Object value, Mapping mapping) {
|
|
||||||
return value == null ? ArrayHelper.FALSE : ArrayHelper.TRUE;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,60 +0,0 @@
|
||||||
/*
|
|
||||||
* Hibernate, Relational Persistence for Idiomatic Java
|
|
||||||
*
|
|
||||||
* Copyright (c) 2010, Red Hat Inc. or third-party contributors as
|
|
||||||
* indicated by the @author tags or express copyright attribution
|
|
||||||
* statements applied by the authors. All third-party contributions are
|
|
||||||
* distributed under license by Red Hat Inc.
|
|
||||||
*
|
|
||||||
* This copyrighted material is made available to anyone wishing to use, modify,
|
|
||||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
|
||||||
* Lesser General Public License, as published by the Free Software Foundation.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
||||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
|
||||||
* for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Lesser General Public License
|
|
||||||
* along with this distribution; if not, write to:
|
|
||||||
* Free Software Foundation, Inc.
|
|
||||||
* 51 Franklin Street, Fifth Floor
|
|
||||||
* Boston, MA 02110-1301 USA
|
|
||||||
*/
|
|
||||||
package org.hibernate.type;
|
|
||||||
import org.hibernate.type.descriptor.java.BooleanTypeDescriptor;
|
|
||||||
import org.hibernate.type.descriptor.sql.CharTypeDescriptor;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Superclass for types that map Java boolean to SQL CHAR(1).
|
|
||||||
*
|
|
||||||
* @author Gavin King
|
|
||||||
*
|
|
||||||
* @deprecated Use the {@link AbstractStandardBasicType} approach instead
|
|
||||||
*/
|
|
||||||
public abstract class CharBooleanType extends BooleanType {
|
|
||||||
private final String stringValueTrue;
|
|
||||||
private final String stringValueFalse;
|
|
||||||
|
|
||||||
protected CharBooleanType(char characterValueTrue, char characterValueFalse) {
|
|
||||||
super( CharTypeDescriptor.INSTANCE, new BooleanTypeDescriptor( characterValueTrue, characterValueFalse ) );
|
|
||||||
|
|
||||||
stringValueTrue = String.valueOf( characterValueTrue );
|
|
||||||
stringValueFalse = String.valueOf( characterValueFalse );
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated Pass the true/false values into constructor instead.
|
|
||||||
*/
|
|
||||||
protected final String getTrueString() {
|
|
||||||
return stringValueTrue;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated Pass the true/false values into constructor instead.
|
|
||||||
*/
|
|
||||||
protected final String getFalseString() {
|
|
||||||
return stringValueFalse;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,58 +0,0 @@
|
||||||
/*
|
|
||||||
* Hibernate, Relational Persistence for Idiomatic Java
|
|
||||||
*
|
|
||||||
* Copyright (c) 2010, Red Hat Inc. or third-party contributors as
|
|
||||||
* indicated by the @author tags or express copyright attribution
|
|
||||||
* statements applied by the authors. All third-party contributions are
|
|
||||||
* distributed under license by Red Hat Inc.
|
|
||||||
*
|
|
||||||
* This copyrighted material is made available to anyone wishing to use, modify,
|
|
||||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
|
||||||
* Lesser General Public License, as published by the Free Software Foundation.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
||||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
|
||||||
* for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Lesser General Public License
|
|
||||||
* along with this distribution; if not, write to:
|
|
||||||
* Free Software Foundation, Inc.
|
|
||||||
* 51 Franklin Street, Fifth Floor
|
|
||||||
* Boston, MA 02110-1301 USA
|
|
||||||
*/
|
|
||||||
package org.hibernate.type;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import org.hibernate.HibernateException;
|
|
||||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
|
||||||
import org.hibernate.engine.spi.SessionImplementor;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Superclass of nullable immutable types.
|
|
||||||
* @author Gavin King
|
|
||||||
*
|
|
||||||
* @deprecated Use the {@link AbstractStandardBasicType} approach instead
|
|
||||||
*/
|
|
||||||
public abstract class ImmutableType extends NullableType {
|
|
||||||
|
|
||||||
public final Object deepCopy(Object value, SessionFactoryImplementor factory) {
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public final boolean isMutable() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Object replace(
|
|
||||||
Object original,
|
|
||||||
Object target,
|
|
||||||
SessionImplementor session,
|
|
||||||
Object owner,
|
|
||||||
Map copyCache)
|
|
||||||
throws HibernateException {
|
|
||||||
return original;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,61 +0,0 @@
|
||||||
/*
|
|
||||||
* Hibernate, Relational Persistence for Idiomatic Java
|
|
||||||
*
|
|
||||||
* Copyright (c) 2010, Red Hat Inc. or third-party contributors as
|
|
||||||
* indicated by the @author tags or express copyright attribution
|
|
||||||
* statements applied by the authors. All third-party contributions are
|
|
||||||
* distributed under license by Red Hat Inc.
|
|
||||||
*
|
|
||||||
* This copyrighted material is made available to anyone wishing to use, modify,
|
|
||||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
|
||||||
* Lesser General Public License, as published by the Free Software Foundation.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
||||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
|
||||||
* for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Lesser General Public License
|
|
||||||
* along with this distribution; if not, write to:
|
|
||||||
* Free Software Foundation, Inc.
|
|
||||||
* 51 Franklin Street, Fifth Floor
|
|
||||||
* Boston, MA 02110-1301 USA
|
|
||||||
*/
|
|
||||||
package org.hibernate.type;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import org.hibernate.HibernateException;
|
|
||||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
|
||||||
import org.hibernate.engine.spi.SessionImplementor;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Superclass for mutable nullable types
|
|
||||||
* @author Gavin King
|
|
||||||
*
|
|
||||||
* @deprecated Use the {@link AbstractStandardBasicType} approach instead
|
|
||||||
*/
|
|
||||||
public abstract class MutableType extends NullableType {
|
|
||||||
|
|
||||||
public final boolean isMutable() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected abstract Object deepCopyNotNull(Object value) throws HibernateException;
|
|
||||||
|
|
||||||
public final Object deepCopy(Object value, SessionFactoryImplementor factory) throws HibernateException {
|
|
||||||
return (value==null) ? null : deepCopyNotNull(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Object replace(
|
|
||||||
Object original,
|
|
||||||
Object target,
|
|
||||||
SessionImplementor session,
|
|
||||||
Object owner,
|
|
||||||
Map copyCache) throws HibernateException {
|
|
||||||
if ( isEqual( original, target ) ) {
|
|
||||||
return original;
|
|
||||||
}
|
|
||||||
return deepCopy( original, session.getFactory() );
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,244 +0,0 @@
|
||||||
/*
|
|
||||||
* Hibernate, Relational Persistence for Idiomatic Java
|
|
||||||
*
|
|
||||||
* Copyright (c) 2010, Red Hat Inc. or third-party contributors as
|
|
||||||
* indicated by the @author tags or express copyright attribution
|
|
||||||
* statements applied by the authors. All third-party contributions are
|
|
||||||
* distributed under license by Red Hat Inc.
|
|
||||||
*
|
|
||||||
* This copyrighted material is made available to anyone wishing to use, modify,
|
|
||||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
|
||||||
* Lesser General Public License, as published by the Free Software Foundation.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
||||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
|
||||||
* for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Lesser General Public License
|
|
||||||
* along with this distribution; if not, write to:
|
|
||||||
* Free Software Foundation, Inc.
|
|
||||||
* 51 Franklin Street, Fifth Floor
|
|
||||||
* Boston, MA 02110-1301 USA
|
|
||||||
*/
|
|
||||||
package org.hibernate.type;
|
|
||||||
|
|
||||||
import java.sql.PreparedStatement;
|
|
||||||
import java.sql.ResultSet;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
|
|
||||||
import org.jboss.logging.Logger;
|
|
||||||
|
|
||||||
import org.hibernate.HibernateException;
|
|
||||||
import org.hibernate.MappingException;
|
|
||||||
import org.hibernate.engine.spi.Mapping;
|
|
||||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
|
||||||
import org.hibernate.engine.spi.SessionImplementor;
|
|
||||||
import org.hibernate.internal.CoreMessageLogger;
|
|
||||||
import org.hibernate.internal.util.collections.ArrayHelper;
|
|
||||||
import org.hibernate.internal.util.compare.EqualsHelper;
|
|
||||||
import org.hibernate.metamodel.spi.relational.Size;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Superclass of single-column nullable types.
|
|
||||||
*
|
|
||||||
* @author Gavin King
|
|
||||||
*
|
|
||||||
* @deprecated Use the {@link AbstractStandardBasicType} approach instead
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public abstract class NullableType extends AbstractType implements StringRepresentableType {
|
|
||||||
private static final CoreMessageLogger LOG = Logger.getMessageLogger(CoreMessageLogger.class, NullableType.class.getName());
|
|
||||||
|
|
||||||
private final Size dictatedSize = new Size();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A convenience form of {@link #sqlTypes(org.hibernate.engine.spi.Mapping)}, returning
|
|
||||||
* just a single type value since these are explicitly dealing with single column
|
|
||||||
* mappings.
|
|
||||||
*
|
|
||||||
* @return The {@link java.sql.Types} mapping value.
|
|
||||||
*/
|
|
||||||
public abstract int sqlType();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A convenience form of {@link #dictatedSizes}, returning just a single size since we are explicitly dealing with
|
|
||||||
* single column mappings here.
|
|
||||||
*
|
|
||||||
* @return The {@link java.sql.Types} mapping value.
|
|
||||||
*/
|
|
||||||
public Size dictatedSize() {
|
|
||||||
return dictatedSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A convenience form of {@link #defaultSizes}, returning just a single size since we are explicitly dealing with
|
|
||||||
* single column mappings here.
|
|
||||||
*
|
|
||||||
* @return The {@link java.sql.Types} mapping value.
|
|
||||||
*/
|
|
||||||
public Size defaultSize() {
|
|
||||||
return LEGACY_DEFAULT_SIZE;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a column value from a result set, without worrying about the
|
|
||||||
* possibility of null values. Called from {@link #nullSafeGet} after
|
|
||||||
* nullness checks have been performed.
|
|
||||||
*
|
|
||||||
* @param rs The result set from which to extract the value.
|
|
||||||
* @param name The name of the value to extract.
|
|
||||||
*
|
|
||||||
* @return The extracted value.
|
|
||||||
*
|
|
||||||
* @throws org.hibernate.HibernateException Generally some form of mismatch error.
|
|
||||||
* @throws java.sql.SQLException Indicates problem making the JDBC call(s).
|
|
||||||
*/
|
|
||||||
public abstract Object get(ResultSet rs, String name) throws HibernateException, SQLException;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set a parameter value without worrying about the possibility of null
|
|
||||||
* values. Called from {@link #nullSafeSet} after nullness checks have
|
|
||||||
* been performed.
|
|
||||||
*
|
|
||||||
* @param st The statement into which to bind the parameter value.
|
|
||||||
* @param value The parameter value to bind.
|
|
||||||
* @param index The position or index at which to bind the param value.
|
|
||||||
*
|
|
||||||
* @throws org.hibernate.HibernateException Generally some form of mismatch error.
|
|
||||||
* @throws java.sql.SQLException Indicates problem making the JDBC call(s).
|
|
||||||
*/
|
|
||||||
public abstract void set(PreparedStatement st, Object value, int index) throws HibernateException, SQLException;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A null-safe version of {@link #toString(Object)}. Specifically we are
|
|
||||||
* worried about null safeness in regards to the incoming value parameter,
|
|
||||||
* not the return.
|
|
||||||
*
|
|
||||||
* @param value The value to convert to a string representation; may be null.
|
|
||||||
* @return The string representation; may be null.
|
|
||||||
* @throws HibernateException Thrown by {@link #toString(Object)}, which this calls.
|
|
||||||
*/
|
|
||||||
public String nullSafeToString(Object value) throws HibernateException {
|
|
||||||
return value == null ? null : toString( value );
|
|
||||||
}
|
|
||||||
|
|
||||||
public abstract String toString(Object value) throws HibernateException;
|
|
||||||
|
|
||||||
public abstract Object fromStringValue(String xml) throws HibernateException;
|
|
||||||
|
|
||||||
public final void nullSafeSet(
|
|
||||||
PreparedStatement st,
|
|
||||||
Object value,
|
|
||||||
int index,
|
|
||||||
boolean[] settable,
|
|
||||||
SessionImplementor session)
|
|
||||||
throws HibernateException, SQLException {
|
|
||||||
if ( settable[0] ) nullSafeSet(st, value, index);
|
|
||||||
}
|
|
||||||
|
|
||||||
public final void nullSafeSet(PreparedStatement st, Object value, int index, SessionImplementor session)
|
|
||||||
throws HibernateException, SQLException {
|
|
||||||
nullSafeSet(st, value, index);
|
|
||||||
}
|
|
||||||
|
|
||||||
public final void nullSafeSet(PreparedStatement st, Object value, int index)
|
|
||||||
throws HibernateException, SQLException {
|
|
||||||
try {
|
|
||||||
if ( value == null ) {
|
|
||||||
LOG.tracev("Binding null to parameter: {0}", index);
|
|
||||||
|
|
||||||
st.setNull( index, sqlType() );
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if (LOG.isTraceEnabled()) LOG.tracev("Binding '{0}' to parameter: {1}", toString(value), index);
|
|
||||||
|
|
||||||
set( st, value, index );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch ( RuntimeException re ) {
|
|
||||||
LOG.unableToBindValueToParameter( nullSafeToString( value ), index, re.getMessage() );
|
|
||||||
throw re;
|
|
||||||
}
|
|
||||||
catch ( SQLException se ) {
|
|
||||||
LOG.unableToBindValueToParameter( nullSafeToString( value ), index, se.getMessage() );
|
|
||||||
throw se;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public final Object nullSafeGet(
|
|
||||||
ResultSet rs,
|
|
||||||
String[] names,
|
|
||||||
SessionImplementor session,
|
|
||||||
Object owner)
|
|
||||||
throws HibernateException, SQLException {
|
|
||||||
return nullSafeGet(rs, names[0]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public final Object nullSafeGet(ResultSet rs, String[] names)
|
|
||||||
throws HibernateException, SQLException {
|
|
||||||
return nullSafeGet(rs, names[0]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public final Object nullSafeGet(ResultSet rs, String name)
|
|
||||||
throws HibernateException, SQLException {
|
|
||||||
try {
|
|
||||||
Object value = get(rs, name);
|
|
||||||
if ( value == null || rs.wasNull() ) {
|
|
||||||
LOG.tracev( "Returning null as column {0}", name );
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
if ( LOG.isTraceEnabled() ) LOG.trace( "Returning '" + toString( value ) + "' as column " + name );
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
catch ( RuntimeException re ) {
|
|
||||||
LOG.unableToReadColumnValueFromResultSet( name, re.getMessage() );
|
|
||||||
throw re;
|
|
||||||
}
|
|
||||||
catch ( SQLException se ) {
|
|
||||||
LOG.unableToReadColumnValueFromResultSet( name, se.getMessage() );
|
|
||||||
throw se;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public final Object nullSafeGet(ResultSet rs, String name, SessionImplementor session, Object owner)
|
|
||||||
throws HibernateException, SQLException {
|
|
||||||
return nullSafeGet( rs, name );
|
|
||||||
}
|
|
||||||
|
|
||||||
public final int getColumnSpan(Mapping session) {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
public final int[] sqlTypes(Mapping session) {
|
|
||||||
return new int[] { sqlType() };
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Size[] dictatedSizes(Mapping mapping) throws MappingException {
|
|
||||||
return new Size[] { dictatedSize() };
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Size[] defaultSizes(Mapping mapping) throws MappingException {
|
|
||||||
return new Size[] { defaultSize() };
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isEqual(Object x, Object y) {
|
|
||||||
return EqualsHelper.equals( x, y );
|
|
||||||
}
|
|
||||||
|
|
||||||
public String toLoggableString(Object value, SessionFactoryImplementor factory) {
|
|
||||||
return value == null ? "null" : toString(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean[] toColumnNullness(Object value, Mapping mapping) {
|
|
||||||
return value==null ? ArrayHelper.FALSE : ArrayHelper.TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isDirty(Object old, Object current, boolean[] checkable, SessionImplementor session)
|
|
||||||
throws HibernateException {
|
|
||||||
return checkable[0] && isDirty(old, current, session);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,46 +0,0 @@
|
||||||
/*
|
|
||||||
* Hibernate, Relational Persistence for Idiomatic Java
|
|
||||||
*
|
|
||||||
* Copyright (c) 2010, Red Hat Inc. or third-party contributors as
|
|
||||||
* indicated by the @author tags or express copyright attribution
|
|
||||||
* statements applied by the authors. All third-party contributions are
|
|
||||||
* distributed under license by Red Hat Inc.
|
|
||||||
*
|
|
||||||
* This copyrighted material is made available to anyone wishing to use, modify,
|
|
||||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
|
||||||
* Lesser General Public License, as published by the Free Software Foundation.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
||||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
|
||||||
* for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Lesser General Public License
|
|
||||||
* along with this distribution; if not, write to:
|
|
||||||
* Free Software Foundation, Inc.
|
|
||||||
* 51 Franklin Street, Fifth Floor
|
|
||||||
* Boston, MA 02110-1301 USA
|
|
||||||
*/
|
|
||||||
package org.hibernate.type;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Map a byte[] to a Blob
|
|
||||||
*
|
|
||||||
* @author Emmanuel Bernard
|
|
||||||
* @deprecated replaced by {@link org.hibernate.type.MaterializedBlobType}
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public class PrimitiveByteArrayBlobType extends ByteArrayBlobType {
|
|
||||||
public Class getReturnedClass() {
|
|
||||||
return byte[].class;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Object wrap(byte[] bytes) {
|
|
||||||
return bytes;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected byte[] unWrap(Object bytes) {
|
|
||||||
return (byte[]) bytes;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,110 +0,0 @@
|
||||||
/*
|
|
||||||
* Hibernate, Relational Persistence for Idiomatic Java
|
|
||||||
*
|
|
||||||
* Copyright (c) 2010, Red Hat Inc. or third-party contributors as
|
|
||||||
* indicated by the @author tags or express copyright attribution
|
|
||||||
* statements applied by the authors. All third-party contributions are
|
|
||||||
* distributed under license by Red Hat Inc.
|
|
||||||
*
|
|
||||||
* This copyrighted material is made available to anyone wishing to use, modify,
|
|
||||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
|
||||||
* Lesser General Public License, as published by the Free Software Foundation.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
||||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
|
||||||
* for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Lesser General Public License
|
|
||||||
* along with this distribution; if not, write to:
|
|
||||||
* Free Software Foundation, Inc.
|
|
||||||
* 51 Franklin Street, Fifth Floor
|
|
||||||
* Boston, MA 02110-1301 USA
|
|
||||||
*/
|
|
||||||
package org.hibernate.type;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.Reader;
|
|
||||||
import java.io.Serializable;
|
|
||||||
import java.io.StringReader;
|
|
||||||
import java.sql.PreparedStatement;
|
|
||||||
import java.sql.ResultSet;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.sql.Types;
|
|
||||||
|
|
||||||
import org.hibernate.HibernateException;
|
|
||||||
import org.hibernate.engine.spi.SessionImplementor;
|
|
||||||
import org.hibernate.usertype.UserType;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Map a String to a Clob
|
|
||||||
*
|
|
||||||
* @author Emmanuel Bernard
|
|
||||||
* @deprecated replaced by {@link org.hibernate.type.MaterializedClobType}
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public class StringClobType implements UserType, Serializable {
|
|
||||||
public int[] sqlTypes() {
|
|
||||||
return new int[]{Types.CLOB};
|
|
||||||
}
|
|
||||||
|
|
||||||
public Class returnedClass() {
|
|
||||||
return String.class;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean equals(Object x, Object y) throws HibernateException {
|
|
||||||
return ( x == y ) || ( x != null && x.equals( y ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
public int hashCode(Object x) throws HibernateException {
|
|
||||||
return x.hashCode();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Object nullSafeGet(ResultSet rs, String[] names, SessionImplementor session, Object owner) throws HibernateException, SQLException {
|
|
||||||
Reader reader = rs.getCharacterStream( names[0] );
|
|
||||||
if ( reader == null ) return null;
|
|
||||||
StringBuilder result = new StringBuilder( 4096 );
|
|
||||||
try {
|
|
||||||
char[] charbuf = new char[4096];
|
|
||||||
for ( int i = reader.read( charbuf ); i > 0 ; i = reader.read( charbuf ) ) {
|
|
||||||
result.append( charbuf, 0, i );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (IOException e) {
|
|
||||||
throw new SQLException( e.getMessage() );
|
|
||||||
}
|
|
||||||
return result.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void nullSafeSet(PreparedStatement st, Object value, int index, SessionImplementor session) throws HibernateException, SQLException {
|
|
||||||
if ( value != null ) {
|
|
||||||
String string = (String) value;
|
|
||||||
StringReader reader = new StringReader( string );
|
|
||||||
st.setCharacterStream( index, reader, string.length() );
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
st.setNull( index, sqlTypes()[0] );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Object deepCopy(Object value) throws HibernateException {
|
|
||||||
//returning value should be OK since String are immutable
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isMutable() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Serializable disassemble(Object value) throws HibernateException {
|
|
||||||
return (Serializable) value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Object assemble(Serializable cached, Object owner) throws HibernateException {
|
|
||||||
return cached;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Object replace(Object original, Object target, Object owner) throws HibernateException {
|
|
||||||
return original;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -41,7 +41,7 @@ import org.hibernate.internal.CoreMessageLogger;
|
||||||
public class JdbcTypeNameMapper {
|
public class JdbcTypeNameMapper {
|
||||||
|
|
||||||
private static final CoreMessageLogger LOG = Logger.getMessageLogger(CoreMessageLogger.class, JdbcTypeNameMapper.class.getName());
|
private static final CoreMessageLogger LOG = Logger.getMessageLogger(CoreMessageLogger.class, JdbcTypeNameMapper.class.getName());
|
||||||
private static Map<Integer,String> JDBC_TYPE_MAP = buildJdbcTypeMap();
|
private static final Map<Integer,String> JDBC_TYPE_MAP = buildJdbcTypeMap();
|
||||||
|
|
||||||
private static Map<Integer, String> buildJdbcTypeMap() {
|
private static Map<Integer, String> buildJdbcTypeMap() {
|
||||||
HashMap<Integer, String> map = new HashMap<Integer, String>();
|
HashMap<Integer, String> map = new HashMap<Integer, String>();
|
||||||
|
|
Loading…
Reference in New Issue