HHH-6520 Some formatting and method name changes. Also moving AbstractAttributeTypeResolver into the type sub-package
This commit is contained in:
parent
3689e533fb
commit
f2338af9eb
|
@ -46,9 +46,9 @@ import org.hibernate.metamodel.source.annotations.JPADotNames;
|
|||
import org.hibernate.metamodel.source.annotations.JandexHelper;
|
||||
import org.hibernate.metamodel.source.annotations.TypeEnumConversionHelper;
|
||||
import org.hibernate.metamodel.source.annotations.attribute.type.AttributeTypeResolver;
|
||||
import org.hibernate.metamodel.source.annotations.attribute.type.AttributeTypeResolverImpl;
|
||||
import org.hibernate.metamodel.source.annotations.attribute.type.CompositeAttributeTypeResolver;
|
||||
import org.hibernate.metamodel.source.annotations.attribute.type.EnumeratedTypeResolver;
|
||||
import org.hibernate.metamodel.source.annotations.attribute.type.ExplicitAttributeTypeResolver;
|
||||
import org.hibernate.metamodel.source.annotations.attribute.type.LobTypeResolver;
|
||||
import org.hibernate.metamodel.source.annotations.attribute.type.TemporalTypeResolver;
|
||||
|
||||
|
@ -105,7 +105,7 @@ public class BasicAttribute extends MappedAttribute {
|
|||
private final String customWriteFragment;
|
||||
private final String customReadFragment;
|
||||
private final String checkCondition;
|
||||
private AttributeTypeResolver resolver;
|
||||
private final AttributeTypeResolver resolver;
|
||||
|
||||
public static BasicAttribute createSimpleAttribute(String name,
|
||||
Class<?> attributeType,
|
||||
|
@ -156,6 +156,7 @@ public class BasicAttribute extends MappedAttribute {
|
|||
this.customReadFragment = readWrite[0];
|
||||
this.customWriteFragment = readWrite[1];
|
||||
this.checkCondition = parseCheckAnnotation();
|
||||
this.resolver = getDefaultHibernateTypeResolver();
|
||||
}
|
||||
|
||||
public final ColumnValues getColumnValues() {
|
||||
|
@ -358,16 +359,12 @@ public class BasicAttribute extends MappedAttribute {
|
|||
|
||||
@Override
|
||||
public AttributeTypeResolver getHibernateTypeResolver() {
|
||||
if ( resolver == null ) {
|
||||
resolver = getDefaultHibernateTypeResolver();
|
||||
}
|
||||
return resolver;
|
||||
}
|
||||
|
||||
protected AttributeTypeResolver getDefaultHibernateTypeResolver() {
|
||||
|
||||
private AttributeTypeResolver getDefaultHibernateTypeResolver() {
|
||||
CompositeAttributeTypeResolver resolver = new CompositeAttributeTypeResolver(
|
||||
new ExplicitAttributeTypeResolver(
|
||||
new AttributeTypeResolverImpl(
|
||||
this
|
||||
)
|
||||
);
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
package org.hibernate.metamodel.source.annotations.attribute;
|
||||
package org.hibernate.metamodel.source.annotations.attribute.type;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
@ -30,36 +30,28 @@ import java.util.Map;
|
|||
import org.jboss.jandex.AnnotationInstance;
|
||||
|
||||
import org.hibernate.internal.util.StringHelper;
|
||||
import org.hibernate.metamodel.source.annotations.attribute.type.AttributeTypeResolver;
|
||||
|
||||
/**
|
||||
* @author Strong Liu
|
||||
*/
|
||||
public abstract class AbstractAttributeTypeResolver implements AttributeTypeResolver {
|
||||
protected abstract AnnotationInstance getAnnotationInstance();
|
||||
protected abstract AnnotationInstance getTypeDeterminingAnnotationInstance();
|
||||
|
||||
protected abstract String resolveHibernateTypeName(AnnotationInstance annotationInstance);
|
||||
|
||||
protected Map<String, String> resolveHibernateTypeParameters(AnnotationInstance annotationInstance) {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
// private String explicitHibernateTypeName;
|
||||
// private Map<String,String> explicitHibernateTypeParameters;
|
||||
/**
|
||||
* An optional explicit hibernate type name specified via {@link org.hibernate.annotations.Type}.
|
||||
*/
|
||||
|
||||
@Override
|
||||
final public String getExplicitHibernateTypeName() {
|
||||
return resolveHibernateTypeName( getAnnotationInstance() );
|
||||
return resolveHibernateTypeName( getTypeDeterminingAnnotationInstance() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Optional type parameters. See {@link #getExplicitHibernateTypeName()}.
|
||||
*/
|
||||
@Override
|
||||
final public Map<String, String> getExplicitHibernateTypeParameters() {
|
||||
if ( StringHelper.isNotEmpty( getExplicitHibernateTypeName() ) ) {
|
||||
return resolveHibernateTypeParameters( getAnnotationInstance() );
|
||||
return resolveHibernateTypeParameters( getTypeDeterminingAnnotationInstance() );
|
||||
}
|
||||
else {
|
||||
return Collections.emptyMap();
|
|
@ -27,9 +27,23 @@ package org.hibernate.metamodel.source.annotations.attribute.type;
|
|||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Determines explicit Hibernate type information for JPA mapped attributes when additional type information is
|
||||
* provided via annotations like {@link javax.persistence.Lob}, {@link javax.persistence.Enumerated} and
|
||||
* {@link javax.persistence.Temporal}.
|
||||
*
|
||||
* @author Strong Liu
|
||||
*/
|
||||
public interface AttributeTypeResolver {
|
||||
/**
|
||||
* @return returns an explicit hibernate type name in case the mapped attribute has an additional
|
||||
* {@link org.hibernate.annotations.Type} annotation or an implicit type is given via the use of annotations like
|
||||
* {@link javax.persistence.Lob}, {@link javax.persistence.Enumerated} and
|
||||
* {@link javax.persistence.Temporal}.
|
||||
*/
|
||||
String getExplicitHibernateTypeName();
|
||||
|
||||
/**
|
||||
* @return Returns a map of optional type parameters. See {@link #getExplicitHibernateTypeName()}.
|
||||
*/
|
||||
Map<String, String> getExplicitHibernateTypeParameters();
|
||||
}
|
||||
|
|
|
@ -0,0 +1,79 @@
|
|||
/*
|
||||
* 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.source.annotations.attribute.type;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.jboss.jandex.AnnotationInstance;
|
||||
import org.jboss.jandex.AnnotationValue;
|
||||
|
||||
import org.hibernate.metamodel.source.annotations.HibernateDotNames;
|
||||
import org.hibernate.metamodel.source.annotations.JandexHelper;
|
||||
import org.hibernate.metamodel.source.annotations.attribute.MappedAttribute;
|
||||
|
||||
/**
|
||||
* @author Strong Liu
|
||||
*/
|
||||
public class AttributeTypeResolverImpl extends AbstractAttributeTypeResolver {
|
||||
private final MappedAttribute mappedAttribute;
|
||||
|
||||
public AttributeTypeResolverImpl(MappedAttribute mappedAttribute) {
|
||||
this.mappedAttribute = mappedAttribute;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String resolveHibernateTypeName(AnnotationInstance typeAnnotation) {
|
||||
String typeName = null;
|
||||
if ( typeAnnotation != null ) {
|
||||
typeName = JandexHelper.getValue( typeAnnotation, "type", String.class );
|
||||
}
|
||||
return typeName;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Map<String, String> resolveHibernateTypeParameters(AnnotationInstance typeAnnotation) {
|
||||
HashMap<String, String> typeParameters = new HashMap<String, String>();
|
||||
AnnotationValue parameterAnnotationValue = typeAnnotation.value( "parameters" );
|
||||
if ( parameterAnnotationValue != null ) {
|
||||
AnnotationInstance[] parameterAnnotations = parameterAnnotationValue.asNestedArray();
|
||||
for ( AnnotationInstance parameterAnnotationInstance : parameterAnnotations ) {
|
||||
typeParameters.put(
|
||||
JandexHelper.getValue( parameterAnnotationInstance, "name", String.class ),
|
||||
JandexHelper.getValue( parameterAnnotationInstance, "value", String.class )
|
||||
);
|
||||
}
|
||||
}
|
||||
return typeParameters;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AnnotationInstance getTypeDeterminingAnnotationInstance() {
|
||||
return JandexHelper.getSingleAnnotation(
|
||||
mappedAttribute.annotations(),
|
||||
HibernateDotNames.TYPE
|
||||
);
|
||||
}
|
||||
}
|
|
@ -37,9 +37,9 @@ import org.hibernate.internal.util.collections.CollectionHelper;
|
|||
*/
|
||||
public class CompositeAttributeTypeResolver implements AttributeTypeResolver {
|
||||
private List<AttributeTypeResolver> resolvers = new ArrayList<AttributeTypeResolver>();
|
||||
private final ExplicitAttributeTypeResolver explicitHibernateTypeResolver;
|
||||
private final AttributeTypeResolverImpl explicitHibernateTypeResolver;
|
||||
|
||||
public CompositeAttributeTypeResolver(ExplicitAttributeTypeResolver explicitHibernateTypeResolver) {
|
||||
public CompositeAttributeTypeResolver(AttributeTypeResolverImpl explicitHibernateTypeResolver) {
|
||||
if ( explicitHibernateTypeResolver == null ) {
|
||||
throw new AssertionFailure( "The Given AttributeTypeResolver is null." );
|
||||
}
|
||||
|
|
|
@ -34,7 +34,6 @@ import org.hibernate.AnnotationException;
|
|||
import org.hibernate.AssertionFailure;
|
||||
import org.hibernate.metamodel.source.annotations.JPADotNames;
|
||||
import org.hibernate.metamodel.source.annotations.JandexHelper;
|
||||
import org.hibernate.metamodel.source.annotations.attribute.AbstractAttributeTypeResolver;
|
||||
import org.hibernate.metamodel.source.annotations.attribute.MappedAttribute;
|
||||
import org.hibernate.type.EnumType;
|
||||
|
||||
|
@ -54,7 +53,7 @@ public class EnumeratedTypeResolver extends AbstractAttributeTypeResolver {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected AnnotationInstance getAnnotationInstance() {
|
||||
protected AnnotationInstance getTypeDeterminingAnnotationInstance() {
|
||||
return JandexHelper.getSingleAnnotation(
|
||||
mappedAttribute.annotations(),
|
||||
JPADotNames.ENUMERATED
|
||||
|
@ -98,25 +97,6 @@ public class EnumeratedTypeResolver extends AbstractAttributeTypeResolver {
|
|||
else {
|
||||
typeParameters.put( EnumType.TYPE, String.valueOf( Types.INTEGER ) );
|
||||
}
|
||||
//todo
|
||||
// Schema schema = mappedAttribute.getContext().getMetadataImplementor().getDatabase().getDefaultSchema();
|
||||
// Identifier schemaIdentifier = schema.getName().getSchema();
|
||||
// Identifier catalogIdentifier = schema.getName().getCatalog();
|
||||
// String schemaName = schemaIdentifier == null ? "" : schemaIdentifier.getName();
|
||||
// String catalogName = catalogIdentifier == null ? "" : catalogIdentifier.getName();
|
||||
// typeParameters.put( EnumType.SCHEMA, schemaName );
|
||||
// typeParameters.put( EnumType.CATALOG, catalogName );
|
||||
/**
|
||||
String schema = columns[0].getTable().getSchema();
|
||||
schema = schema == null ? "" : schema;
|
||||
String catalog = columns[0].getTable().getCatalog();
|
||||
catalog = catalog == null ? "" : catalog;
|
||||
typeParameters.setProperty( EnumType.SCHEMA, schema );
|
||||
typeParameters.setProperty( EnumType.CATALOG, catalog );
|
||||
typeParameters.setProperty( EnumType.TABLE, columns[0].getTable().getName() );
|
||||
typeParameters.setProperty( EnumType.COLUMN, columns[0].getName() );
|
||||
*/
|
||||
return typeParameters;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,86 +0,0 @@
|
|||
/*
|
||||
* 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.source.annotations.attribute.type;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.jboss.jandex.AnnotationInstance;
|
||||
import org.jboss.jandex.AnnotationValue;
|
||||
|
||||
import org.hibernate.metamodel.source.annotations.HibernateDotNames;
|
||||
import org.hibernate.metamodel.source.annotations.JandexHelper;
|
||||
import org.hibernate.metamodel.source.annotations.attribute.AbstractAttributeTypeResolver;
|
||||
import org.hibernate.metamodel.source.annotations.attribute.MappedAttribute;
|
||||
|
||||
/**
|
||||
* @author Strong Liu
|
||||
*/
|
||||
public class ExplicitAttributeTypeResolver extends AbstractAttributeTypeResolver {
|
||||
private final MappedAttribute mappedAttribute;
|
||||
|
||||
|
||||
public ExplicitAttributeTypeResolver(MappedAttribute mappedAttribute) {
|
||||
this.mappedAttribute = mappedAttribute;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String resolveHibernateTypeName(AnnotationInstance typeAnnotation) {
|
||||
String typeName = null;
|
||||
if ( typeAnnotation != null ) {
|
||||
typeName = JandexHelper.getValue( typeAnnotation, "type", String.class );
|
||||
}
|
||||
return typeName;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Map<String, String> resolveHibernateTypeParameters(AnnotationInstance typeAnnotation) {
|
||||
HashMap<String, String> typeParameters = new HashMap<String, String>();
|
||||
AnnotationValue parameterAnnotationValue = typeAnnotation.value( "parameters" );
|
||||
if ( parameterAnnotationValue != null ) {
|
||||
AnnotationInstance[] parameterAnnotations = parameterAnnotationValue.asNestedArray();
|
||||
for ( AnnotationInstance parameterAnnotationInstance : parameterAnnotations ) {
|
||||
typeParameters.put(
|
||||
JandexHelper.getValue( parameterAnnotationInstance, "name", String.class ),
|
||||
JandexHelper.getValue(
|
||||
parameterAnnotationInstance,
|
||||
"value",
|
||||
String.class
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
return typeParameters;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AnnotationInstance getAnnotationInstance() {
|
||||
return JandexHelper.getSingleAnnotation(
|
||||
mappedAttribute.annotations(),
|
||||
HibernateDotNames.TYPE
|
||||
);
|
||||
}
|
||||
|
||||
}
|
|
@ -35,7 +35,6 @@ import org.jboss.jandex.AnnotationInstance;
|
|||
import org.hibernate.AssertionFailure;
|
||||
import org.hibernate.metamodel.source.annotations.JPADotNames;
|
||||
import org.hibernate.metamodel.source.annotations.JandexHelper;
|
||||
import org.hibernate.metamodel.source.annotations.attribute.AbstractAttributeTypeResolver;
|
||||
import org.hibernate.metamodel.source.annotations.attribute.MappedAttribute;
|
||||
import org.hibernate.type.CharacterArrayClobType;
|
||||
import org.hibernate.type.PrimitiveCharacterArrayClobType;
|
||||
|
@ -49,7 +48,6 @@ import org.hibernate.type.WrappedMaterializedBlobType;
|
|||
public class LobTypeResolver extends AbstractAttributeTypeResolver {
|
||||
private final MappedAttribute mappedAttribute;
|
||||
|
||||
|
||||
public LobTypeResolver(MappedAttribute mappedAttribute) {
|
||||
if ( mappedAttribute == null ) {
|
||||
throw new AssertionFailure( "MappedAttribute is null" );
|
||||
|
@ -58,7 +56,7 @@ public class LobTypeResolver extends AbstractAttributeTypeResolver {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected AnnotationInstance getAnnotationInstance() {
|
||||
protected AnnotationInstance getTypeDeterminingAnnotationInstance() {
|
||||
return JandexHelper.getSingleAnnotation( mappedAttribute.annotations(), JPADotNames.LOB );
|
||||
}
|
||||
|
||||
|
|
|
@ -35,7 +35,6 @@ import org.hibernate.AssertionFailure;
|
|||
import org.hibernate.cfg.NotYetImplementedException;
|
||||
import org.hibernate.metamodel.source.annotations.JPADotNames;
|
||||
import org.hibernate.metamodel.source.annotations.JandexHelper;
|
||||
import org.hibernate.metamodel.source.annotations.attribute.AbstractAttributeTypeResolver;
|
||||
import org.hibernate.metamodel.source.annotations.attribute.MappedAttribute;
|
||||
import org.hibernate.type.StandardBasicTypes;
|
||||
|
||||
|
@ -64,7 +63,7 @@ public class TemporalTypeResolver extends AbstractAttributeTypeResolver {
|
|||
}
|
||||
TemporalType temporalType = JandexHelper.getEnumValue( temporalAnnotation, "value", TemporalType.class );
|
||||
boolean isDate = Date.class.isAssignableFrom( mappedAttribute.getAttributeType() );
|
||||
String type = null;
|
||||
String type;
|
||||
switch ( temporalType ) {
|
||||
case DATE:
|
||||
type = isDate ? StandardBasicTypes.DATE.getName() : StandardBasicTypes.CALENDAR_DATE.getName();
|
||||
|
@ -95,7 +94,7 @@ public class TemporalTypeResolver extends AbstractAttributeTypeResolver {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected AnnotationInstance getAnnotationInstance() {
|
||||
protected AnnotationInstance getTypeDeterminingAnnotationInstance() {
|
||||
return JandexHelper.getSingleAnnotation(
|
||||
mappedAttribute.annotations(),
|
||||
JPADotNames.TEMPORAL
|
||||
|
@ -105,5 +104,4 @@ public class TemporalTypeResolver extends AbstractAttributeTypeResolver {
|
|||
private static boolean isTemporalType(Class type) {
|
||||
return Date.class.isAssignableFrom( type ) || Calendar.class.isAssignableFrom( type );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
/*
|
||||
* 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.source.annotations.attribute.type;
|
||||
|
||||
/**
|
||||
* This package contains type binding code for basic attributes.
|
||||
*/
|
Loading…
Reference in New Issue