HHH-5284 - Allow Type to dictate the default length/scale/precision
This commit is contained in:
parent
a933851765
commit
1421c3f54d
|
@ -30,6 +30,7 @@ import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.hibernate.LockMode;
|
import org.hibernate.LockMode;
|
||||||
import org.hibernate.LockOptions;
|
import org.hibernate.LockOptions;
|
||||||
import org.hibernate.type.Type;
|
import org.hibernate.type.Type;
|
||||||
|
@ -186,6 +187,14 @@ public final class ArrayHelper {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings( {"unchecked"})
|
||||||
|
public static <T> T[] join(T[] x, T[] y) {
|
||||||
|
T[] result = (T[]) Array.newInstance( x.getClass().getComponentType(), x.length + y.length );
|
||||||
|
System.arraycopy( x, 0, result, 0, x.length );
|
||||||
|
System.arraycopy( y, 0, result, x.length, y.length );
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
public static final boolean[] TRUE = { true };
|
public static final boolean[] TRUE = { true };
|
||||||
public static final boolean[] FALSE = { false };
|
public static final boolean[] FALSE = { false };
|
||||||
|
|
||||||
|
@ -362,6 +371,8 @@ public final class ArrayHelper {
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -131,100 +131,4 @@ public class Column extends AbstractSimpleValue implements SimpleValue {
|
||||||
return getTable().getLoggableValueQualifier() + '.' + getName();
|
return getTable().getLoggableValueQualifier() + '.' + getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Models size restrictions/requirements on a column's datatype.
|
|
||||||
* <p/>
|
|
||||||
* IMPL NOTE: since we do not necessarily know the datatype up front, and therefore do not necessarily know
|
|
||||||
* whether length or precision/scale sizing is needed, we simply account for both here. Additionally LOB
|
|
||||||
* definitions, by standard, are allowed a "multiplier" consisting of 'K' (Kb), 'M' (Mb) or 'G' (Gb).
|
|
||||||
*/
|
|
||||||
public static class Size {
|
|
||||||
private static enum LobMultiplier {
|
|
||||||
NONE( 1 ),
|
|
||||||
K( NONE.factor * 1024 ),
|
|
||||||
M( K.factor * 1024 ),
|
|
||||||
G( M.factor * 1024 );
|
|
||||||
|
|
||||||
private long factor;
|
|
||||||
|
|
||||||
private LobMultiplier(long factor) {
|
|
||||||
this.factor = factor;
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getFactor() {
|
|
||||||
return factor;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private int precision = - 1;
|
|
||||||
private int scale = -1;
|
|
||||||
private long length = -1;
|
|
||||||
private LobMultiplier lobMultiplier = LobMultiplier.NONE;
|
|
||||||
|
|
||||||
public Size() {
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Complete constructor.
|
|
||||||
*
|
|
||||||
* @param precision numeric precision
|
|
||||||
* @param scale numeric scale
|
|
||||||
* @param length type length
|
|
||||||
* @param lobMultiplier LOB length multiplier
|
|
||||||
*/
|
|
||||||
public Size(int precision, int scale, long length, LobMultiplier lobMultiplier) {
|
|
||||||
this.precision = precision;
|
|
||||||
this.scale = scale;
|
|
||||||
this.length = length;
|
|
||||||
this.lobMultiplier = lobMultiplier;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Size precision(int precision) {
|
|
||||||
return new Size( precision, -1, -1, null );
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Size precision(int precision, int scale) {
|
|
||||||
return new Size( precision, scale, -1, null );
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Size length(long length) {
|
|
||||||
return new Size( -1, -1, length, null );
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Size length(long length, LobMultiplier lobMultiplier) {
|
|
||||||
return new Size( -1, -1, length, lobMultiplier );
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getPrecision() {
|
|
||||||
return precision;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getScale() {
|
|
||||||
return scale;
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getLength() {
|
|
||||||
return length;
|
|
||||||
}
|
|
||||||
|
|
||||||
public LobMultiplier getLobMultiplier() {
|
|
||||||
return lobMultiplier;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPrecision(int precision) {
|
|
||||||
this.precision = precision;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setScale(int scale) {
|
|
||||||
this.scale = scale;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setLength(long length) {
|
|
||||||
this.length = length;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setLobMultiplier(LobMultiplier lobMultiplier) {
|
|
||||||
this.lobMultiplier = lobMultiplier;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,125 @@
|
||||||
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2011, 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.metamodel.relational;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Models size restrictions/requirements on a column's datatype.
|
||||||
|
* <p/>
|
||||||
|
* IMPL NOTE: since we do not necessarily know the datatype up front, and therefore do not necessarily know
|
||||||
|
* whether length or precision/scale sizing is needed, we simply account for both here. Additionally LOB
|
||||||
|
* definitions, by standard, are allowed a "multiplier" consisting of 'K' (Kb), 'M' (Mb) or 'G' (Gb).
|
||||||
|
*
|
||||||
|
* @author Steve Ebersole
|
||||||
|
*/
|
||||||
|
public class Size implements Serializable {
|
||||||
|
public static enum LobMultiplier {
|
||||||
|
NONE( 1 ),
|
||||||
|
K( NONE.factor * 1024 ),
|
||||||
|
M( K.factor * 1024 ),
|
||||||
|
G( M.factor * 1024 );
|
||||||
|
|
||||||
|
private long factor;
|
||||||
|
|
||||||
|
private LobMultiplier(long factor) {
|
||||||
|
this.factor = factor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getFactor() {
|
||||||
|
return factor;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private int precision = - 1;
|
||||||
|
private int scale = -1;
|
||||||
|
private long length = -1;
|
||||||
|
private LobMultiplier lobMultiplier = LobMultiplier.NONE;
|
||||||
|
|
||||||
|
public Size() {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Complete constructor.
|
||||||
|
*
|
||||||
|
* @param precision numeric precision
|
||||||
|
* @param scale numeric scale
|
||||||
|
* @param length type length
|
||||||
|
* @param lobMultiplier LOB length multiplier
|
||||||
|
*/
|
||||||
|
public Size(int precision, int scale, long length, LobMultiplier lobMultiplier) {
|
||||||
|
this.precision = precision;
|
||||||
|
this.scale = scale;
|
||||||
|
this.length = length;
|
||||||
|
this.lobMultiplier = lobMultiplier;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Size precision(int precision) {
|
||||||
|
return new Size( precision, -1, -1, null );
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Size precision(int precision, int scale) {
|
||||||
|
return new Size( precision, scale, -1, null );
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Size length(long length) {
|
||||||
|
return new Size( -1, -1, length, null );
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Size length(long length, LobMultiplier lobMultiplier) {
|
||||||
|
return new Size( -1, -1, length, lobMultiplier );
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getPrecision() {
|
||||||
|
return precision;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getScale() {
|
||||||
|
return scale;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getLength() {
|
||||||
|
return length;
|
||||||
|
}
|
||||||
|
|
||||||
|
public LobMultiplier getLobMultiplier() {
|
||||||
|
return lobMultiplier;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPrecision(int precision) {
|
||||||
|
this.precision = precision;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setScale(int scale) {
|
||||||
|
this.scale = scale;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLength(long length) {
|
||||||
|
this.length = length;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLobMultiplier(LobMultiplier lobMultiplier) {
|
||||||
|
this.lobMultiplier = lobMultiplier;
|
||||||
|
}
|
||||||
|
}
|
|
@ -22,11 +22,14 @@
|
||||||
* Boston, MA 02110-1301 USA
|
* Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
package org.hibernate.persister.entity;
|
package org.hibernate.persister.entity;
|
||||||
|
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.dom4j.Node;
|
import org.dom4j.Node;
|
||||||
|
|
||||||
import org.hibernate.EntityMode;
|
import org.hibernate.EntityMode;
|
||||||
import org.hibernate.HibernateException;
|
import org.hibernate.HibernateException;
|
||||||
import org.hibernate.MappingException;
|
import org.hibernate.MappingException;
|
||||||
|
@ -35,6 +38,7 @@ import org.hibernate.engine.SessionFactoryImplementor;
|
||||||
import org.hibernate.engine.SessionImplementor;
|
import org.hibernate.engine.SessionImplementor;
|
||||||
import org.hibernate.internal.util.collections.ArrayHelper;
|
import org.hibernate.internal.util.collections.ArrayHelper;
|
||||||
import org.hibernate.internal.util.compare.EqualsHelper;
|
import org.hibernate.internal.util.compare.EqualsHelper;
|
||||||
|
import org.hibernate.metamodel.relational.Size;
|
||||||
import org.hibernate.type.AbstractType;
|
import org.hibernate.type.AbstractType;
|
||||||
import org.hibernate.type.Type;
|
import org.hibernate.type.Type;
|
||||||
|
|
||||||
|
@ -141,6 +145,16 @@ public class DiscriminatorType extends AbstractType {
|
||||||
return underlyingType.sqlTypes( mapping );
|
return underlyingType.sqlTypes( mapping );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Size[] dictatedSizes(Mapping mapping) throws MappingException {
|
||||||
|
return underlyingType.dictatedSizes( mapping );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Size[] defaultSizes(Mapping mapping) throws MappingException {
|
||||||
|
return underlyingType.defaultSizes( mapping );
|
||||||
|
}
|
||||||
|
|
||||||
public int getColumnSpan(Mapping mapping) throws MappingException {
|
public int getColumnSpan(Mapping mapping) throws MappingException {
|
||||||
return underlyingType.getColumnSpan( mapping );
|
return underlyingType.getColumnSpan( mapping );
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,6 +31,7 @@ import org.hibernate.HibernateException;
|
||||||
import org.hibernate.MappingException;
|
import org.hibernate.MappingException;
|
||||||
import org.hibernate.engine.Mapping;
|
import org.hibernate.engine.Mapping;
|
||||||
import org.hibernate.engine.SessionImplementor;
|
import org.hibernate.engine.SessionImplementor;
|
||||||
|
import org.hibernate.metamodel.relational.Size;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Emmanuel Bernard
|
* @author Emmanuel Bernard
|
||||||
|
@ -43,6 +44,16 @@ public abstract class AbstractLobType extends AbstractType implements Serializab
|
||||||
return checkable[0] ? ! isEqual( old, current, session.getEntityMode() ) : false;
|
return checkable[0] ? ! isEqual( old, current, session.getEntityMode() ) : 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
|
@Override
|
||||||
public boolean isEqual(Object x, Object y, EntityMode entityMode) {
|
public boolean isEqual(Object x, Object y, EntityMode entityMode) {
|
||||||
return isEqual( x, y, entityMode, null );
|
return isEqual( x, y, entityMode, null );
|
||||||
|
|
|
@ -37,6 +37,7 @@ import org.hibernate.engine.Mapping;
|
||||||
import org.hibernate.engine.SessionFactoryImplementor;
|
import org.hibernate.engine.SessionFactoryImplementor;
|
||||||
import org.hibernate.engine.SessionImplementor;
|
import org.hibernate.engine.SessionImplementor;
|
||||||
import org.hibernate.engine.jdbc.LobCreator;
|
import org.hibernate.engine.jdbc.LobCreator;
|
||||||
|
import org.hibernate.metamodel.relational.Size;
|
||||||
import org.hibernate.type.descriptor.WrapperOptions;
|
import org.hibernate.type.descriptor.WrapperOptions;
|
||||||
import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
|
import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
|
||||||
import org.hibernate.type.descriptor.java.MutabilityPlan;
|
import org.hibernate.type.descriptor.java.MutabilityPlan;
|
||||||
|
@ -51,6 +52,9 @@ import org.hibernate.internal.util.collections.ArrayHelper;
|
||||||
public abstract class AbstractStandardBasicType<T>
|
public abstract class AbstractStandardBasicType<T>
|
||||||
implements BasicType, StringRepresentableType<T>, XmlRepresentableType<T> {
|
implements BasicType, StringRepresentableType<T>, XmlRepresentableType<T> {
|
||||||
|
|
||||||
|
private static final Size DEFAULT_SIZE = new Size( 19, 2, 255, Size.LobMultiplier.NONE ); // to match legacy behavior
|
||||||
|
private final Size dictatedSize = new Size();
|
||||||
|
|
||||||
private final SqlTypeDescriptor sqlTypeDescriptor;
|
private final SqlTypeDescriptor sqlTypeDescriptor;
|
||||||
private final JavaTypeDescriptor<T> javaTypeDescriptor;
|
private final JavaTypeDescriptor<T> javaTypeDescriptor;
|
||||||
|
|
||||||
|
@ -109,6 +113,14 @@ public abstract class AbstractStandardBasicType<T>
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected static Size getDefaultSize() {
|
||||||
|
return DEFAULT_SIZE;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Size getDictatedSize() {
|
||||||
|
return dictatedSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// final implementations ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
// final implementations ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
@ -124,12 +136,22 @@ public abstract class AbstractStandardBasicType<T>
|
||||||
return javaTypeDescriptor.getJavaTypeClass();
|
return javaTypeDescriptor.getJavaTypeClass();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public final int getColumnSpan(Mapping mapping) throws MappingException {
|
||||||
|
return sqlTypes( mapping ).length;
|
||||||
|
}
|
||||||
|
|
||||||
public final int[] sqlTypes(Mapping mapping) throws MappingException {
|
public final int[] sqlTypes(Mapping mapping) throws MappingException {
|
||||||
return new int[] { sqlTypeDescriptor.getSqlType() };
|
return new int[] { sqlTypeDescriptor.getSqlType() };
|
||||||
}
|
}
|
||||||
|
|
||||||
public final int getColumnSpan(Mapping mapping) throws MappingException {
|
@Override
|
||||||
return sqlTypes( mapping ).length;
|
public Size[] dictatedSizes(Mapping mapping) throws MappingException {
|
||||||
|
return new Size[] { getDictatedSize() };
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Size[] defaultSizes(Mapping mapping) throws MappingException {
|
||||||
|
return new Size[] { getDefaultSize() };
|
||||||
}
|
}
|
||||||
|
|
||||||
public final boolean isAssociationType() {
|
public final boolean isAssociationType() {
|
||||||
|
|
|
@ -33,6 +33,7 @@ import org.hibernate.HibernateException;
|
||||||
import org.hibernate.engine.SessionFactoryImplementor;
|
import org.hibernate.engine.SessionFactoryImplementor;
|
||||||
import org.hibernate.engine.SessionImplementor;
|
import org.hibernate.engine.SessionImplementor;
|
||||||
import org.hibernate.internal.util.compare.EqualsHelper;
|
import org.hibernate.internal.util.compare.EqualsHelper;
|
||||||
|
import org.hibernate.metamodel.relational.Size;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Abstract superclass of the built in Type hierarchy.
|
* Abstract superclass of the built in Type hierarchy.
|
||||||
|
@ -40,6 +41,8 @@ import org.hibernate.internal.util.compare.EqualsHelper;
|
||||||
* @author Gavin King
|
* @author Gavin King
|
||||||
*/
|
*/
|
||||||
public abstract class AbstractType implements Type {
|
public abstract class AbstractType implements Type {
|
||||||
|
protected static final Size LEGACY_DICTATED_SIZE = new Size();
|
||||||
|
protected static final Size LEGACY_DEFAULT_SIZE = new Size( 19, 2, 255, Size.LobMultiplier.NONE ); // to match legacy behavior
|
||||||
|
|
||||||
public boolean isAssociationType() {
|
public boolean isAssociationType() {
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -42,6 +42,7 @@ import org.hibernate.engine.Mapping;
|
||||||
import org.hibernate.engine.SessionFactoryImplementor;
|
import org.hibernate.engine.SessionFactoryImplementor;
|
||||||
import org.hibernate.engine.SessionImplementor;
|
import org.hibernate.engine.SessionImplementor;
|
||||||
import org.hibernate.internal.util.collections.ArrayHelper;
|
import org.hibernate.internal.util.collections.ArrayHelper;
|
||||||
|
import org.hibernate.metamodel.relational.Size;
|
||||||
import org.hibernate.persister.entity.Joinable;
|
import org.hibernate.persister.entity.Joinable;
|
||||||
import org.hibernate.proxy.HibernateProxyHelper;
|
import org.hibernate.proxy.HibernateProxyHelper;
|
||||||
|
|
||||||
|
@ -172,6 +173,22 @@ public class AnyType extends AbstractType implements CompositeType, AssociationT
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Size[] dictatedSizes(Mapping mapping) throws MappingException {
|
||||||
|
return ArrayHelper.join(
|
||||||
|
metaType.dictatedSizes( mapping ),
|
||||||
|
identifierType.dictatedSizes( mapping )
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Size[] defaultSizes(Mapping mapping) throws MappingException {
|
||||||
|
return ArrayHelper.join(
|
||||||
|
metaType.defaultSizes( mapping ),
|
||||||
|
identifierType.defaultSizes( mapping )
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
public void setToXMLNode(Node xml, Object value, SessionFactoryImplementor factory) {
|
public void setToXMLNode(Node xml, Object value, SessionFactoryImplementor factory) {
|
||||||
throw new UnsupportedOperationException("any types cannot be stringified");
|
throw new UnsupportedOperationException("any types cannot be stringified");
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,6 +46,7 @@ import org.hibernate.engine.SessionFactoryImplementor;
|
||||||
import org.hibernate.engine.SessionImplementor;
|
import org.hibernate.engine.SessionImplementor;
|
||||||
import org.hibernate.internal.util.MarkerObject;
|
import org.hibernate.internal.util.MarkerObject;
|
||||||
import org.hibernate.internal.util.collections.ArrayHelper;
|
import org.hibernate.internal.util.collections.ArrayHelper;
|
||||||
|
import org.hibernate.metamodel.relational.Size;
|
||||||
import org.hibernate.persister.collection.CollectionPersister;
|
import org.hibernate.persister.collection.CollectionPersister;
|
||||||
import org.hibernate.persister.collection.QueryableCollection;
|
import org.hibernate.persister.collection.QueryableCollection;
|
||||||
import org.hibernate.persister.entity.EntityPersister;
|
import org.hibernate.persister.entity.EntityPersister;
|
||||||
|
@ -154,6 +155,16 @@ public abstract class CollectionType extends AbstractType implements Association
|
||||||
return ArrayHelper.EMPTY_INT_ARRAY;
|
return ArrayHelper.EMPTY_INT_ARRAY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@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 };
|
||||||
|
}
|
||||||
|
|
||||||
public int getColumnSpan(Mapping session) throws MappingException {
|
public int getColumnSpan(Mapping session) throws MappingException {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,8 +30,10 @@ import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.dom4j.Element;
|
import org.dom4j.Element;
|
||||||
import org.dom4j.Node;
|
import org.dom4j.Node;
|
||||||
|
|
||||||
import org.hibernate.EntityMode;
|
import org.hibernate.EntityMode;
|
||||||
import org.hibernate.FetchMode;
|
import org.hibernate.FetchMode;
|
||||||
import org.hibernate.HibernateException;
|
import org.hibernate.HibernateException;
|
||||||
|
@ -43,6 +45,7 @@ import org.hibernate.engine.SessionFactoryImplementor;
|
||||||
import org.hibernate.engine.SessionImplementor;
|
import org.hibernate.engine.SessionImplementor;
|
||||||
import org.hibernate.internal.util.StringHelper;
|
import org.hibernate.internal.util.StringHelper;
|
||||||
import org.hibernate.internal.util.collections.ArrayHelper;
|
import org.hibernate.internal.util.collections.ArrayHelper;
|
||||||
|
import org.hibernate.metamodel.relational.Size;
|
||||||
import org.hibernate.tuple.EntityModeToTuplizerMapping;
|
import org.hibernate.tuple.EntityModeToTuplizerMapping;
|
||||||
import org.hibernate.tuple.StandardProperty;
|
import org.hibernate.tuple.StandardProperty;
|
||||||
import org.hibernate.tuple.component.ComponentMetamodel;
|
import org.hibernate.tuple.component.ComponentMetamodel;
|
||||||
|
@ -97,6 +100,14 @@ public class ComponentType extends AbstractType implements CompositeType {
|
||||||
return tuplizerMapping;
|
return tuplizerMapping;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getColumnSpan(Mapping mapping) throws MappingException {
|
||||||
|
int span = 0;
|
||||||
|
for ( int i = 0; i < propertySpan; i++ ) {
|
||||||
|
span += propertyTypes[i].getColumnSpan( mapping );
|
||||||
|
}
|
||||||
|
return span;
|
||||||
|
}
|
||||||
|
|
||||||
public int[] sqlTypes(Mapping mapping) throws MappingException {
|
public int[] sqlTypes(Mapping mapping) throws MappingException {
|
||||||
//Not called at runtime so doesn't matter if its slow :)
|
//Not called at runtime so doesn't matter if its slow :)
|
||||||
int[] sqlTypes = new int[getColumnSpan( mapping )];
|
int[] sqlTypes = new int[getColumnSpan( mapping )];
|
||||||
|
@ -110,14 +121,33 @@ public class ComponentType extends AbstractType implements CompositeType {
|
||||||
return sqlTypes;
|
return sqlTypes;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getColumnSpan(Mapping mapping) throws MappingException {
|
@Override
|
||||||
int span = 0;
|
public Size[] dictatedSizes(Mapping mapping) throws MappingException {
|
||||||
for ( int i = 0; i < propertySpan; i++ ) {
|
//Not called at runtime so doesn't matter if its slow :)
|
||||||
span += propertyTypes[i].getColumnSpan( mapping );
|
final Size[] sizes = new Size[ getColumnSpan( mapping ) ];
|
||||||
|
int soFar = 0;
|
||||||
|
for ( Type propertyType : propertyTypes ) {
|
||||||
|
final Size[] propertySizes = propertyType.dictatedSizes( mapping );
|
||||||
|
System.arraycopy( propertySizes, 0, sizes, soFar, propertySizes.length );
|
||||||
|
soFar += propertySizes.length;
|
||||||
}
|
}
|
||||||
return span;
|
return sizes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Size[] defaultSizes(Mapping mapping) throws MappingException {
|
||||||
|
//Not called at runtime so doesn't matter if its slow :)
|
||||||
|
final Size[] sizes = new Size[ getColumnSpan( mapping ) ];
|
||||||
|
int soFar = 0;
|
||||||
|
for ( Type propertyType : propertyTypes ) {
|
||||||
|
final Size[] propertySizes = propertyType.defaultSizes( mapping );
|
||||||
|
System.arraycopy( propertySizes, 0, sizes, soFar, propertySizes.length );
|
||||||
|
soFar += propertySizes.length;
|
||||||
|
}
|
||||||
|
return sizes;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final boolean isComponentType() {
|
public final boolean isComponentType() {
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -39,6 +39,7 @@ import org.hibernate.engine.Mapping;
|
||||||
import org.hibernate.engine.SessionFactoryImplementor;
|
import org.hibernate.engine.SessionFactoryImplementor;
|
||||||
import org.hibernate.engine.SessionImplementor;
|
import org.hibernate.engine.SessionImplementor;
|
||||||
import org.hibernate.internal.util.collections.ArrayHelper;
|
import org.hibernate.internal.util.collections.ArrayHelper;
|
||||||
|
import org.hibernate.metamodel.relational.Size;
|
||||||
import org.hibernate.usertype.CompositeUserType;
|
import org.hibernate.usertype.CompositeUserType;
|
||||||
import org.hibernate.usertype.LoggableUserType;
|
import org.hibernate.usertype.LoggableUserType;
|
||||||
|
|
||||||
|
@ -197,7 +198,7 @@ public class CompositeCustomType extends AbstractType implements CompositeType,
|
||||||
Object owner)
|
Object owner)
|
||||||
throws HibernateException, SQLException {
|
throws HibernateException, SQLException {
|
||||||
|
|
||||||
return userType.nullSafeGet(rs, new String[] {columnName}, session, owner);
|
return userType.nullSafeGet( rs, new String[] {columnName}, session, owner );
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object nullSafeGet(
|
public Object nullSafeGet(
|
||||||
|
@ -230,7 +231,6 @@ public class CompositeCustomType extends AbstractType implements CompositeType,
|
||||||
throws HibernateException, SQLException {
|
throws HibernateException, SQLException {
|
||||||
|
|
||||||
userType.nullSafeSet(st, value, index, session);
|
userType.nullSafeSet(st, value, index, session);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int[] sqlTypes(Mapping mapping) throws MappingException {
|
public int[] sqlTypes(Mapping mapping) throws MappingException {
|
||||||
|
@ -244,6 +244,32 @@ public class CompositeCustomType extends AbstractType implements CompositeType,
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Size[] dictatedSizes(Mapping mapping) throws MappingException {
|
||||||
|
//Not called at runtime so doesn't matter if its slow :)
|
||||||
|
final Size[] sizes = new Size[ getColumnSpan( mapping ) ];
|
||||||
|
int soFar = 0;
|
||||||
|
for ( Type propertyType : userType.getPropertyTypes() ) {
|
||||||
|
final Size[] propertySizes = propertyType.dictatedSizes( mapping );
|
||||||
|
System.arraycopy( propertySizes, 0, sizes, soFar, propertySizes.length );
|
||||||
|
soFar += propertySizes.length;
|
||||||
|
}
|
||||||
|
return sizes;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Size[] defaultSizes(Mapping mapping) throws MappingException {
|
||||||
|
//Not called at runtime so doesn't matter if its slow :)
|
||||||
|
final Size[] sizes = new Size[ getColumnSpan( mapping ) ];
|
||||||
|
int soFar = 0;
|
||||||
|
for ( Type propertyType : userType.getPropertyTypes() ) {
|
||||||
|
final Size[] propertySizes = propertyType.defaultSizes( mapping );
|
||||||
|
System.arraycopy( propertySizes, 0, sizes, soFar, propertySizes.length );
|
||||||
|
soFar += propertySizes.length;
|
||||||
|
}
|
||||||
|
return sizes;
|
||||||
|
}
|
||||||
|
|
||||||
public String toLoggableString(Object value, SessionFactoryImplementor factory) throws HibernateException {
|
public String toLoggableString(Object value, SessionFactoryImplementor factory) throws HibernateException {
|
||||||
if ( value == null ) {
|
if ( value == null ) {
|
||||||
return "null";
|
return "null";
|
||||||
|
|
|
@ -38,8 +38,10 @@ import org.hibernate.engine.Mapping;
|
||||||
import org.hibernate.engine.SessionFactoryImplementor;
|
import org.hibernate.engine.SessionFactoryImplementor;
|
||||||
import org.hibernate.engine.SessionImplementor;
|
import org.hibernate.engine.SessionImplementor;
|
||||||
import org.hibernate.internal.util.collections.ArrayHelper;
|
import org.hibernate.internal.util.collections.ArrayHelper;
|
||||||
|
import org.hibernate.metamodel.relational.Size;
|
||||||
import org.hibernate.usertype.EnhancedUserType;
|
import org.hibernate.usertype.EnhancedUserType;
|
||||||
import org.hibernate.usertype.LoggableUserType;
|
import org.hibernate.usertype.LoggableUserType;
|
||||||
|
import org.hibernate.usertype.Sized;
|
||||||
import org.hibernate.usertype.UserType;
|
import org.hibernate.usertype.UserType;
|
||||||
import org.hibernate.usertype.UserVersionType;
|
import org.hibernate.usertype.UserVersionType;
|
||||||
|
|
||||||
|
@ -54,6 +56,8 @@ public class CustomType extends AbstractType implements IdentifierType, Discrimi
|
||||||
private final UserType userType;
|
private final UserType userType;
|
||||||
private final String name;
|
private final String name;
|
||||||
private final int[] types;
|
private final int[] types;
|
||||||
|
private final Size[] dictatedSizes;
|
||||||
|
private final Size[] defaultSizes;
|
||||||
private final boolean customLogging;
|
private final boolean customLogging;
|
||||||
private final String[] registrationKeys;
|
private final String[] registrationKeys;
|
||||||
|
|
||||||
|
@ -65,6 +69,12 @@ public class CustomType extends AbstractType implements IdentifierType, Discrimi
|
||||||
this.userType = userType;
|
this.userType = userType;
|
||||||
this.name = userType.getClass().getName();
|
this.name = userType.getClass().getName();
|
||||||
this.types = userType.sqlTypes();
|
this.types = userType.sqlTypes();
|
||||||
|
this.dictatedSizes = Sized.class.isInstance( userType )
|
||||||
|
? ( (Sized) userType ).dictatedSizes()
|
||||||
|
: new Size[ types.length ];
|
||||||
|
this.defaultSizes = Sized.class.isInstance( userType )
|
||||||
|
? ( (Sized) userType ).defaultSizes()
|
||||||
|
: new Size[ types.length ];
|
||||||
this.customLogging = LoggableUserType.class.isInstance( userType );
|
this.customLogging = LoggableUserType.class.isInstance( userType );
|
||||||
this.registrationKeys = registrationKeys;
|
this.registrationKeys = registrationKeys;
|
||||||
}
|
}
|
||||||
|
@ -81,6 +91,16 @@ public class CustomType extends AbstractType implements IdentifierType, Discrimi
|
||||||
return types;
|
return types;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Size[] dictatedSizes(Mapping mapping) throws MappingException {
|
||||||
|
return dictatedSizes;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Size[] defaultSizes(Mapping mapping) throws MappingException {
|
||||||
|
return defaultSizes;
|
||||||
|
}
|
||||||
|
|
||||||
public int getColumnSpan(Mapping session) {
|
public int getColumnSpan(Mapping session) {
|
||||||
return types.length;
|
return types.length;
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,6 +34,7 @@ import org.hibernate.engine.EntityKey;
|
||||||
import org.hibernate.engine.ForeignKeys;
|
import org.hibernate.engine.ForeignKeys;
|
||||||
import org.hibernate.engine.Mapping;
|
import org.hibernate.engine.Mapping;
|
||||||
import org.hibernate.engine.SessionImplementor;
|
import org.hibernate.engine.SessionImplementor;
|
||||||
|
import org.hibernate.metamodel.relational.Size;
|
||||||
import org.hibernate.persister.entity.EntityPersister;
|
import org.hibernate.persister.entity.EntityPersister;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -110,6 +111,16 @@ public class ManyToOneType extends EntityType {
|
||||||
return getIdentifierOrUniqueKeyType( mapping ).sqlTypes( mapping );
|
return getIdentifierOrUniqueKeyType( mapping ).sqlTypes( mapping );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Size[] dictatedSizes(Mapping mapping) throws MappingException {
|
||||||
|
return getIdentifierOrUniqueKeyType( mapping ).dictatedSizes( mapping );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Size[] defaultSizes(Mapping mapping) throws MappingException {
|
||||||
|
return getIdentifierOrUniqueKeyType( mapping ).defaultSizes( mapping );
|
||||||
|
}
|
||||||
|
|
||||||
public void nullSafeSet(
|
public void nullSafeSet(
|
||||||
PreparedStatement st,
|
PreparedStatement st,
|
||||||
Object value,
|
Object value,
|
||||||
|
|
|
@ -35,6 +35,7 @@ import org.hibernate.MappingException;
|
||||||
import org.hibernate.engine.Mapping;
|
import org.hibernate.engine.Mapping;
|
||||||
import org.hibernate.engine.SessionFactoryImplementor;
|
import org.hibernate.engine.SessionFactoryImplementor;
|
||||||
import org.hibernate.engine.SessionImplementor;
|
import org.hibernate.engine.SessionImplementor;
|
||||||
|
import org.hibernate.metamodel.relational.Size;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Gavin King
|
* @author Gavin King
|
||||||
|
@ -65,6 +66,16 @@ public class MetaType extends AbstractType {
|
||||||
return baseType.sqlTypes(mapping);
|
return baseType.sqlTypes(mapping);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Size[] dictatedSizes(Mapping mapping) throws MappingException {
|
||||||
|
return baseType.dictatedSizes( mapping );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Size[] defaultSizes(Mapping mapping) throws MappingException {
|
||||||
|
return baseType.defaultSizes( mapping );
|
||||||
|
}
|
||||||
|
|
||||||
public int getColumnSpan(Mapping mapping) throws MappingException {
|
public int getColumnSpan(Mapping mapping) throws MappingException {
|
||||||
return baseType.getColumnSpan(mapping);
|
return baseType.getColumnSpan(mapping);
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,19 +22,24 @@
|
||||||
* Boston, MA 02110-1301 USA
|
* Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
package org.hibernate.type;
|
package org.hibernate.type;
|
||||||
|
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
|
||||||
import org.dom4j.Node;
|
import org.dom4j.Node;
|
||||||
|
import org.jboss.logging.Logger;
|
||||||
|
|
||||||
import org.hibernate.EntityMode;
|
import org.hibernate.EntityMode;
|
||||||
import org.hibernate.HibernateException;
|
import org.hibernate.HibernateException;
|
||||||
import org.hibernate.HibernateLogger;
|
import org.hibernate.HibernateLogger;
|
||||||
|
import org.hibernate.MappingException;
|
||||||
import org.hibernate.engine.Mapping;
|
import org.hibernate.engine.Mapping;
|
||||||
import org.hibernate.engine.SessionFactoryImplementor;
|
import org.hibernate.engine.SessionFactoryImplementor;
|
||||||
import org.hibernate.engine.SessionImplementor;
|
import org.hibernate.engine.SessionImplementor;
|
||||||
import org.hibernate.internal.util.collections.ArrayHelper;
|
import org.hibernate.internal.util.collections.ArrayHelper;
|
||||||
import org.hibernate.internal.util.compare.EqualsHelper;
|
import org.hibernate.internal.util.compare.EqualsHelper;
|
||||||
import org.jboss.logging.Logger;
|
import org.hibernate.metamodel.relational.Size;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Superclass of single-column nullable types.
|
* Superclass of single-column nullable types.
|
||||||
|
@ -45,10 +50,39 @@ import org.jboss.logging.Logger;
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public abstract class NullableType extends AbstractType implements StringRepresentableType, XmlRepresentableType {
|
public abstract class NullableType extends AbstractType implements StringRepresentableType, XmlRepresentableType {
|
||||||
|
|
||||||
|
|
||||||
private static final HibernateLogger LOG = Logger.getMessageLogger(HibernateLogger.class, NullableType.class.getName());
|
private static final HibernateLogger LOG = Logger.getMessageLogger(HibernateLogger.class, NullableType.class.getName());
|
||||||
|
|
||||||
|
private final Size dictatedSize = new Size();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A convenience form of {@link #sqlTypes(org.hibernate.engine.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
|
* Get a column value from a result set, without worrying about the
|
||||||
* possibility of null values. Called from {@link #nullSafeGet} after
|
* possibility of null values. Called from {@link #nullSafeGet} after
|
||||||
|
@ -78,15 +112,6 @@ public abstract class NullableType extends AbstractType implements StringReprese
|
||||||
*/
|
*/
|
||||||
public abstract void set(PreparedStatement st, Object value, int index) throws HibernateException, SQLException;
|
public abstract void set(PreparedStatement st, Object value, int index) throws HibernateException, SQLException;
|
||||||
|
|
||||||
/**
|
|
||||||
* A convenience form of {@link #sqlTypes(org.hibernate.engine.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 null-safe version of {@link #toString(Object)}. Specifically we are
|
* A null-safe version of {@link #toString(Object)}. Specifically we are
|
||||||
* worried about null safeness in regards to the incoming value parameter,
|
* worried about null safeness in regards to the incoming value parameter,
|
||||||
|
@ -200,6 +225,16 @@ public abstract class NullableType extends AbstractType implements StringReprese
|
||||||
return new int[] { sqlType() };
|
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
|
@Override
|
||||||
public final boolean isEqual(Object x, Object y, EntityMode entityMode) {
|
public final boolean isEqual(Object x, Object y, EntityMode entityMode) {
|
||||||
return isEqual(x, y);
|
return isEqual(x, y);
|
||||||
|
|
|
@ -32,6 +32,7 @@ import org.hibernate.engine.EntityKey;
|
||||||
import org.hibernate.engine.Mapping;
|
import org.hibernate.engine.Mapping;
|
||||||
import org.hibernate.engine.SessionImplementor;
|
import org.hibernate.engine.SessionImplementor;
|
||||||
import org.hibernate.internal.util.collections.ArrayHelper;
|
import org.hibernate.internal.util.collections.ArrayHelper;
|
||||||
|
import org.hibernate.metamodel.relational.Size;
|
||||||
import org.hibernate.persister.entity.EntityPersister;
|
import org.hibernate.persister.entity.EntityPersister;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -92,6 +93,18 @@ public class OneToOneType extends EntityType {
|
||||||
return ArrayHelper.EMPTY_INT_ARRAY;
|
return ArrayHelper.EMPTY_INT_ARRAY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static final Size[] SIZES = new Size[0];
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Size[] dictatedSizes(Mapping mapping) throws MappingException {
|
||||||
|
return SIZES;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Size[] defaultSizes(Mapping mapping) throws MappingException {
|
||||||
|
return SIZES;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean[] toColumnNullness(Object value, Mapping mapping) {
|
public boolean[] toColumnNullness(Object value, Mapping mapping) {
|
||||||
return ArrayHelper.EMPTY_BOOLEAN_ARRAY;
|
return ArrayHelper.EMPTY_BOOLEAN_ARRAY;
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,6 +31,7 @@ import org.hibernate.MappingException;
|
||||||
import org.hibernate.engine.ForeignKeys;
|
import org.hibernate.engine.ForeignKeys;
|
||||||
import org.hibernate.engine.Mapping;
|
import org.hibernate.engine.Mapping;
|
||||||
import org.hibernate.engine.SessionImplementor;
|
import org.hibernate.engine.SessionImplementor;
|
||||||
|
import org.hibernate.metamodel.relational.Size;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A one-to-one association that maps to specific formula(s)
|
* A one-to-one association that maps to specific formula(s)
|
||||||
|
@ -63,11 +64,21 @@ public class SpecialOneToOneType extends OneToOneType {
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getColumnSpan(Mapping mapping) throws MappingException {
|
public int getColumnSpan(Mapping mapping) throws MappingException {
|
||||||
return super.getIdentifierOrUniqueKeyType(mapping).getColumnSpan(mapping);
|
return super.getIdentifierOrUniqueKeyType( mapping ).getColumnSpan( mapping );
|
||||||
}
|
}
|
||||||
|
|
||||||
public int[] sqlTypes(Mapping mapping) throws MappingException {
|
public int[] sqlTypes(Mapping mapping) throws MappingException {
|
||||||
return super.getIdentifierOrUniqueKeyType(mapping).sqlTypes(mapping);
|
return super.getIdentifierOrUniqueKeyType( mapping ).sqlTypes( mapping );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Size[] dictatedSizes(Mapping mapping) throws MappingException {
|
||||||
|
return super.getIdentifierOrUniqueKeyType( mapping ).dictatedSizes( mapping );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Size[] defaultSizes(Mapping mapping) throws MappingException {
|
||||||
|
return super.getIdentifierOrUniqueKeyType( mapping ).defaultSizes( mapping );
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean useLHSPrimaryKey() {
|
public boolean useLHSPrimaryKey() {
|
||||||
|
|
|
@ -22,18 +22,22 @@
|
||||||
* Boston, MA 02110-1301 USA
|
* Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
package org.hibernate.type;
|
package org.hibernate.type;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.dom4j.Node;
|
import org.dom4j.Node;
|
||||||
|
|
||||||
import org.hibernate.EntityMode;
|
import org.hibernate.EntityMode;
|
||||||
import org.hibernate.HibernateException;
|
import org.hibernate.HibernateException;
|
||||||
import org.hibernate.MappingException;
|
import org.hibernate.MappingException;
|
||||||
import org.hibernate.engine.Mapping;
|
import org.hibernate.engine.Mapping;
|
||||||
import org.hibernate.engine.SessionFactoryImplementor;
|
import org.hibernate.engine.SessionFactoryImplementor;
|
||||||
import org.hibernate.engine.SessionImplementor;
|
import org.hibernate.engine.SessionImplementor;
|
||||||
|
import org.hibernate.metamodel.relational.Size;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Defines a mapping between a Java type and one or more JDBC {@linkplain java.sql.Types types}, as well
|
* Defines a mapping between a Java type and one or more JDBC {@linkplain java.sql.Types types}, as well
|
||||||
|
@ -102,8 +106,21 @@ public interface Type extends Serializable {
|
||||||
*/
|
*/
|
||||||
public boolean isComponentType();
|
public boolean isComponentType();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* How many columns are used to persist this type. Always the same as {@code sqlTypes(mapping).length}
|
||||||
|
*
|
||||||
|
* @param mapping The mapping object :/
|
||||||
|
*
|
||||||
|
* @return The number of columns
|
||||||
|
*
|
||||||
|
* @throws MappingException Generally indicates an issue accessing the passed mapping object.
|
||||||
|
*/
|
||||||
|
public int getColumnSpan(Mapping mapping) throws MappingException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the JDBC types codes (per {@link java.sql.Types}) for the columns mapped by this type.
|
* Return the JDBC types codes (per {@link java.sql.Types}) for the columns mapped by this type.
|
||||||
|
* <p/>
|
||||||
|
* NOTE: The number of elements in this array matches the return from {@link #getColumnSpan}.
|
||||||
*
|
*
|
||||||
* @param mapping The mapping object :/
|
* @param mapping The mapping object :/
|
||||||
*
|
*
|
||||||
|
@ -114,15 +131,34 @@ public interface Type extends Serializable {
|
||||||
public int[] sqlTypes(Mapping mapping) throws MappingException;
|
public int[] sqlTypes(Mapping mapping) throws MappingException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* How many columns are used to persist this type. Always the same as {@code sqlTypes(mapping).length}
|
* Return the column sizes dictated by this type. For example, the mapping for a {@code char}/{@link Character} would
|
||||||
|
* have a dictated length limit of 1; for a string-based {@link java.util.UUID} would have a size limit of 36; etc.
|
||||||
|
* <p/>
|
||||||
|
* NOTE: The number of elements in this array matches the return from {@link #getColumnSpan}.
|
||||||
*
|
*
|
||||||
* @param mapping The mapping object :/
|
* @param mapping The mapping object :/
|
||||||
|
* @todo Would be much much better to have this aware of Dialect once the service/metamodel split is done
|
||||||
*
|
*
|
||||||
* @return The number of columns
|
* @return The dictated sizes.
|
||||||
*
|
*
|
||||||
* @throws MappingException Generally indicates an issue accessing the passed mapping object.
|
* @throws MappingException Generally indicates an issue accessing the passed mapping object.
|
||||||
*/
|
*/
|
||||||
public int getColumnSpan(Mapping mapping) throws MappingException;
|
public Size[] dictatedSizes(Mapping mapping) throws MappingException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Defines the column sizes to use according to this type if the user did not explicitly say (and if no
|
||||||
|
* {@link #dictatedSizes} were given).
|
||||||
|
* <p/>
|
||||||
|
* NOTE: The number of elements in this array matches the return from {@link #getColumnSpan}.
|
||||||
|
*
|
||||||
|
* @param mapping The mapping object :/
|
||||||
|
* @todo Would be much much better to have this aware of Dialect once the service/metamodel split is done
|
||||||
|
*
|
||||||
|
* @return The default sizes.
|
||||||
|
*
|
||||||
|
* @throws MappingException Generally indicates an issue accessing the passed mapping object.
|
||||||
|
*/
|
||||||
|
public Size[] defaultSizes(Mapping mapping) throws MappingException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The class returned by {@link #nullSafeGet} methods. This is used to establish the class of an array of
|
* The class returned by {@link #nullSafeGet} methods. This is used to establish the class of an array of
|
||||||
|
|
|
@ -22,7 +22,9 @@
|
||||||
* Boston, MA 02110-1301 USA
|
* Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
package org.hibernate.type.descriptor.sql;
|
package org.hibernate.type.descriptor.sql;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
import org.hibernate.type.descriptor.ValueBinder;
|
import org.hibernate.type.descriptor.ValueBinder;
|
||||||
import org.hibernate.type.descriptor.ValueExtractor;
|
import org.hibernate.type.descriptor.ValueExtractor;
|
||||||
import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
|
import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
|
||||||
|
|
|
@ -0,0 +1,58 @@
|
||||||
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2011, 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.usertype;
|
||||||
|
|
||||||
|
import org.hibernate.metamodel.relational.Size;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extends dictated/default column size declarations from {@link org.hibernate.type.Type} to the {@link UserType}
|
||||||
|
* hierarchy as well via an optional interface.
|
||||||
|
*
|
||||||
|
* @author Steve Ebersole
|
||||||
|
*/
|
||||||
|
public interface Sized {
|
||||||
|
/**
|
||||||
|
* Return the column sizes dictated by this type. For example, the mapping for a {@code char}/{@link Character} would
|
||||||
|
* have a dictated length limit of 1; for a string-based {@link java.util.UUID} would have a size limit of 36; etc.
|
||||||
|
*
|
||||||
|
* @todo Would be much much better to have this aware of Dialect once the service/metamodel split is done
|
||||||
|
*
|
||||||
|
* @return The dictated sizes.
|
||||||
|
*
|
||||||
|
* @see org.hibernate.type.Type#dictatedSizes
|
||||||
|
*/
|
||||||
|
public Size[] dictatedSizes();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Defines the column sizes to use according to this type if the user did not explicitly say (and if no
|
||||||
|
* {@link #dictatedSizes} were given).
|
||||||
|
*
|
||||||
|
* @todo Would be much much better to have this aware of Dialect once the service/metamodel split is done
|
||||||
|
*
|
||||||
|
* @return The default sizes.
|
||||||
|
*
|
||||||
|
* @see org.hibernate.type.Type#defaultSizes
|
||||||
|
*/
|
||||||
|
public Size[] defaultSizes();
|
||||||
|
}
|
|
@ -1,10 +1,10 @@
|
||||||
/*
|
/*
|
||||||
* Hibernate, Relational Persistence for Idiomatic Java
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
*
|
*
|
||||||
* Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
|
* Copyright (c) 2011, Red Hat Inc. or third-party contributors as
|
||||||
* indicated by the @author tags or express copyright attribution
|
* indicated by the @author tags or express copyright attribution
|
||||||
* statements applied by the authors. All third-party contributions are
|
* statements applied by the authors. All third-party contributions are
|
||||||
* distributed under license by Red Hat Middleware LLC.
|
* distributed under license by Red Hat Inc.
|
||||||
*
|
*
|
||||||
* This copyrighted material is made available to anyone wishing to use, modify,
|
* 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
|
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||||
|
@ -20,15 +20,17 @@
|
||||||
* Free Software Foundation, Inc.
|
* Free Software Foundation, Inc.
|
||||||
* 51 Franklin Street, Fifth Floor
|
* 51 Franklin Street, Fifth Floor
|
||||||
* Boston, MA 02110-1301 USA
|
* Boston, MA 02110-1301 USA
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
package org.hibernate.usertype;
|
package org.hibernate.usertype;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
|
||||||
import org.hibernate.HibernateException;
|
import org.hibernate.HibernateException;
|
||||||
import org.hibernate.engine.SessionImplementor;
|
import org.hibernate.engine.SessionImplementor;
|
||||||
|
import org.hibernate.metamodel.relational.Size;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This interface should be implemented by user-defined "types".
|
* This interface should be implemented by user-defined "types".
|
||||||
|
@ -176,6 +178,7 @@ public interface UserType {
|
||||||
* @return the value to be merged
|
* @return the value to be merged
|
||||||
*/
|
*/
|
||||||
public Object replace(Object original, Object target, Object owner) throws HibernateException;
|
public Object replace(Object original, Object target, Object owner) throws HibernateException;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -30,6 +30,7 @@ import org.hibernate.metamodel.domain.SingularAttribute;
|
||||||
import org.hibernate.metamodel.relational.Column;
|
import org.hibernate.metamodel.relational.Column;
|
||||||
import org.hibernate.metamodel.relational.Datatype;
|
import org.hibernate.metamodel.relational.Datatype;
|
||||||
import org.hibernate.metamodel.relational.Schema;
|
import org.hibernate.metamodel.relational.Schema;
|
||||||
|
import org.hibernate.metamodel.relational.Size;
|
||||||
import org.hibernate.metamodel.relational.Table;
|
import org.hibernate.metamodel.relational.Table;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
@ -64,7 +65,7 @@ public class SimpleValueBindingTests extends BaseUnitTestCase {
|
||||||
|
|
||||||
Column idColumn = table.createColumn( "id" );
|
Column idColumn = table.createColumn( "id" );
|
||||||
idColumn.setDatatype( BIGINT );
|
idColumn.setDatatype( BIGINT );
|
||||||
idColumn.setSize( Column.Size.precision( 18, 0 ) );
|
idColumn.setSize( Size.precision( 18, 0 ) );
|
||||||
table.getPrimaryKey().addColumn( idColumn );
|
table.getPrimaryKey().addColumn( idColumn );
|
||||||
table.getPrimaryKey().setName( "my_table_pk" );
|
table.getPrimaryKey().setName( "my_table_pk" );
|
||||||
attributeBinding.setValue( idColumn );
|
attributeBinding.setValue( idColumn );
|
||||||
|
|
|
@ -54,7 +54,7 @@ public class TableManipulationTests extends BaseUnitTestCase {
|
||||||
|
|
||||||
Column idColumn = table.createColumn( "id" );
|
Column idColumn = table.createColumn( "id" );
|
||||||
idColumn.setDatatype( INTEGER );
|
idColumn.setDatatype( INTEGER );
|
||||||
idColumn.setSize( Column.Size.precision( 18, 0 ) );
|
idColumn.setSize( Size.precision( 18, 0 ) );
|
||||||
table.getPrimaryKey().addColumn( idColumn );
|
table.getPrimaryKey().addColumn( idColumn );
|
||||||
table.getPrimaryKey().setName( "my_table_pk" );
|
table.getPrimaryKey().setName( "my_table_pk" );
|
||||||
assertEquals( "my_table_pk", table.getPrimaryKey().getName() );
|
assertEquals( "my_table_pk", table.getPrimaryKey().getName() );
|
||||||
|
@ -62,7 +62,7 @@ public class TableManipulationTests extends BaseUnitTestCase {
|
||||||
|
|
||||||
Column col_1 = table.createColumn( "col_1" );
|
Column col_1 = table.createColumn( "col_1" );
|
||||||
col_1.setDatatype( VARCHAR );
|
col_1.setDatatype( VARCHAR );
|
||||||
col_1.setSize( Column.Size.length( 512 ) );
|
col_1.setSize( Size.length( 512 ) );
|
||||||
|
|
||||||
for ( Value value : table.values() ) {
|
for ( Value value : table.values() ) {
|
||||||
assertTrue( Column.class.isInstance( value ) );
|
assertTrue( Column.class.isInstance( value ) );
|
||||||
|
@ -92,7 +92,7 @@ public class TableManipulationTests extends BaseUnitTestCase {
|
||||||
|
|
||||||
Column bookId = book.createColumn( "id" );
|
Column bookId = book.createColumn( "id" );
|
||||||
bookId.setDatatype( INTEGER );
|
bookId.setDatatype( INTEGER );
|
||||||
bookId.setSize( Column.Size.precision( 18, 0 ) );
|
bookId.setSize( Size.precision( 18, 0 ) );
|
||||||
book.getPrimaryKey().addColumn( bookId );
|
book.getPrimaryKey().addColumn( bookId );
|
||||||
book.getPrimaryKey().setName( "BOOK_PK" );
|
book.getPrimaryKey().setName( "BOOK_PK" );
|
||||||
|
|
||||||
|
@ -100,13 +100,13 @@ public class TableManipulationTests extends BaseUnitTestCase {
|
||||||
|
|
||||||
Column pageId = page.createColumn( "id" );
|
Column pageId = page.createColumn( "id" );
|
||||||
pageId.setDatatype( INTEGER );
|
pageId.setDatatype( INTEGER );
|
||||||
pageId.setSize( Column.Size.precision( 18, 0 ) );
|
pageId.setSize( Size.precision( 18, 0 ) );
|
||||||
page.getPrimaryKey().addColumn( pageId );
|
page.getPrimaryKey().addColumn( pageId );
|
||||||
page.getPrimaryKey().setName( "PAGE_PK" );
|
page.getPrimaryKey().setName( "PAGE_PK" );
|
||||||
|
|
||||||
Column pageBookId = page.createColumn( "BOOK_ID" );
|
Column pageBookId = page.createColumn( "BOOK_ID" );
|
||||||
pageId.setDatatype( INTEGER );
|
pageId.setDatatype( INTEGER );
|
||||||
pageId.setSize( Column.Size.precision( 18, 0 ) );
|
pageId.setSize( Size.precision( 18, 0 ) );
|
||||||
ForeignKey pageBookFk = page.createForeignKey( book, "PAGE_BOOK_FK" );
|
ForeignKey pageBookFk = page.createForeignKey( book, "PAGE_BOOK_FK" );
|
||||||
pageBookFk.addColumn( pageBookId );
|
pageBookFk.addColumn( pageBookId );
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue