HHH-6490 Support @javax.persistence.Lob

HHH-6492 Support @javax.persistence.Enumerated
refact HHH-6489 Support @javax.persistence.Temporal
refact test
add license header
This commit is contained in:
Strong Liu 2011-08-01 19:47:15 +08:00
parent 67e8f311db
commit 37a8f83d2e
18 changed files with 602 additions and 187 deletions

View File

@ -1,3 +1,27 @@
/*
* 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; package org.hibernate.metamodel.source.annotations.attribute;
import java.util.Collections; import java.util.Collections;
@ -6,11 +30,12 @@ import java.util.Map;
import org.jboss.jandex.AnnotationInstance; import org.jboss.jandex.AnnotationInstance;
import org.hibernate.internal.util.StringHelper; import org.hibernate.internal.util.StringHelper;
import org.hibernate.metamodel.source.annotations.attribute.type.AttributeTypeResolver;
/** /**
* @author Strong Liu * @author Strong Liu
*/ */
public abstract class AbstractHibernateTypeResolver implements HibernateTypeResolver { public abstract class AbstractAttributeTypeResolver implements AttributeTypeResolver {
protected abstract AnnotationInstance getAnnotationInstance(); protected abstract AnnotationInstance getAnnotationInstance();
protected abstract String resolveHibernateTypeName(AnnotationInstance annotationInstance); protected abstract String resolveHibernateTypeName(AnnotationInstance annotationInstance);

View File

@ -45,6 +45,12 @@ import org.hibernate.metamodel.source.annotations.HibernateDotNames;
import org.hibernate.metamodel.source.annotations.JPADotNames; import org.hibernate.metamodel.source.annotations.JPADotNames;
import org.hibernate.metamodel.source.annotations.JandexHelper; import org.hibernate.metamodel.source.annotations.JandexHelper;
import org.hibernate.metamodel.source.annotations.TypeEnumConversionHelper; import org.hibernate.metamodel.source.annotations.TypeEnumConversionHelper;
import org.hibernate.metamodel.source.annotations.attribute.type.AttributeTypeResolver;
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;
/** /**
* Represent a mapped attribute (explicitly or implicitly mapped). * Represent a mapped attribute (explicitly or implicitly mapped).
@ -99,7 +105,7 @@ public class BasicAttribute extends MappedAttribute {
private final String customWriteFragment; private final String customWriteFragment;
private final String customReadFragment; private final String customReadFragment;
private final String checkCondition; private final String checkCondition;
private HibernateTypeResolver resolver; private AttributeTypeResolver resolver;
public static BasicAttribute createSimpleAttribute(String name, public static BasicAttribute createSimpleAttribute(String name,
Class<?> attributeType, Class<?> attributeType,
@ -351,17 +357,17 @@ public class BasicAttribute extends MappedAttribute {
} }
@Override @Override
public HibernateTypeResolver getHibernateTypeResolver() { public AttributeTypeResolver getHibernateTypeResolver() {
if ( resolver == null ) { if ( resolver == null ) {
resolver = getDefaultHibernateTypeResolver(); resolver = getDefaultHibernateTypeResolver();
} }
return resolver; return resolver;
} }
protected HibernateTypeResolver getDefaultHibernateTypeResolver() { protected AttributeTypeResolver getDefaultHibernateTypeResolver() {
CompositeHibernateTypeResolver resolver = new CompositeHibernateTypeResolver( CompositeAttributeTypeResolver resolver = new CompositeAttributeTypeResolver(
new ExplicitHibernateTypeResolver( new ExplicitAttributeTypeResolver(
this this
) )
); );

View File

@ -1,59 +0,0 @@
package org.hibernate.metamodel.source.annotations.attribute;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.hibernate.AssertionFailure;
import org.hibernate.internal.util.StringHelper;
import org.hibernate.internal.util.collections.CollectionHelper;
/**
* @author Strong Liu
*/
public class CompositeHibernateTypeResolver implements HibernateTypeResolver {
private List<HibernateTypeResolver> resolvers = new ArrayList<HibernateTypeResolver>();
private final ExplicitHibernateTypeResolver explicitHibernateTypeResolver;
public CompositeHibernateTypeResolver(ExplicitHibernateTypeResolver explicitHibernateTypeResolver) {
if ( explicitHibernateTypeResolver == null ) {
throw new AssertionFailure( "The Given HibernateTypeResolver is null." );
}
this.explicitHibernateTypeResolver = explicitHibernateTypeResolver;
}
public void addHibernateTypeResolver(HibernateTypeResolver resolver) {
if ( resolver == null ) {
throw new AssertionFailure( "The Given HibernateTypeResolver is null." );
}
resolvers.add( resolver );
}
@Override
public String getExplicitHibernateTypeName() {
String type = explicitHibernateTypeResolver.getExplicitHibernateTypeName();
if ( StringHelper.isEmpty( type ) ) {
for ( HibernateTypeResolver resolver : resolvers ) {
type = resolver.getExplicitHibernateTypeName();
if ( StringHelper.isNotEmpty( type ) ) {
break;
}
}
}
return type;
}
@Override
public Map<String, String> getExplicitHibernateTypeParameters() {
Map<String, String> parameters = explicitHibernateTypeResolver.getExplicitHibernateTypeParameters();
if ( CollectionHelper.isEmpty( parameters ) ) {
for ( HibernateTypeResolver resolver : resolvers ) {
parameters = resolver.getExplicitHibernateTypeParameters();
if ( CollectionHelper.isNotEmpty( parameters ) ) {
break;
}
}
}
return parameters;
}
}

View File

@ -1,3 +1,27 @@
/*
* 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; package org.hibernate.metamodel.source.annotations.attribute;
import org.hibernate.metamodel.source.binder.DerivedValueSource; import org.hibernate.metamodel.source.binder.DerivedValueSource;

View File

@ -1,16 +1,41 @@
/*
* 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; package org.hibernate.metamodel.source.annotations.attribute;
import java.util.Map; import java.util.Map;
import org.hibernate.metamodel.source.annotations.attribute.type.AttributeTypeResolver;
import org.hibernate.metamodel.source.binder.ExplicitHibernateTypeSource; import org.hibernate.metamodel.source.binder.ExplicitHibernateTypeSource;
/** /**
* @author Strong Liu * @author Strong Liu
*/ */
public class ExplicitHibernateTypeSourceImpl implements ExplicitHibernateTypeSource { public class ExplicitHibernateTypeSourceImpl implements ExplicitHibernateTypeSource {
private final HibernateTypeResolver typeResolver; private final AttributeTypeResolver typeResolver;
public ExplicitHibernateTypeSourceImpl(HibernateTypeResolver typeResolver) { public ExplicitHibernateTypeSourceImpl(AttributeTypeResolver typeResolver) {
this.typeResolver = typeResolver; this.typeResolver = typeResolver;
} }

View File

@ -1,11 +0,0 @@
package org.hibernate.metamodel.source.annotations.attribute;
import java.util.Map;
/**
* @author Strong Liu
*/
public interface HibernateTypeResolver {
String getExplicitHibernateTypeName();
Map<String, String> getExplicitHibernateTypeParameters();
}

View File

@ -23,32 +23,14 @@
*/ */
package org.hibernate.metamodel.source.annotations.attribute; package org.hibernate.metamodel.source.annotations.attribute;
import java.io.Serializable;
import java.sql.Blob;
import java.sql.Clob;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import javax.persistence.TemporalType;
import org.jboss.jandex.AnnotationInstance; import org.jboss.jandex.AnnotationInstance;
import org.jboss.jandex.AnnotationValue;
import org.jboss.jandex.DotName; import org.jboss.jandex.DotName;
import org.hibernate.AnnotationException;
import org.hibernate.AssertionFailure;
import org.hibernate.cfg.NotYetImplementedException;
import org.hibernate.metamodel.source.annotations.AnnotationBindingContext; import org.hibernate.metamodel.source.annotations.AnnotationBindingContext;
import org.hibernate.metamodel.source.annotations.HibernateDotNames; import org.hibernate.metamodel.source.annotations.attribute.type.AttributeTypeResolver;
import org.hibernate.metamodel.source.annotations.JPADotNames;
import org.hibernate.metamodel.source.annotations.JandexHelper;
import org.hibernate.type.CharacterArrayClobType;
import org.hibernate.type.PrimitiveCharacterArrayClobType;
import org.hibernate.type.SerializableToBlobType;
import org.hibernate.type.StandardBasicTypes;
import org.hibernate.type.WrappedMaterializedBlobType;
/** /**
* Base class for the different types of mapped attributes * Base class for the different types of mapped attributes
@ -106,7 +88,7 @@ public abstract class MappedAttribute implements Comparable<MappedAttribute> {
return context; return context;
} }
Map<DotName, List<AnnotationInstance>> annotations() { public Map<DotName, List<AnnotationInstance>> annotations() {
return annotations; return annotations;
} }
@ -115,7 +97,7 @@ public abstract class MappedAttribute implements Comparable<MappedAttribute> {
return name.compareTo( mappedProperty.getName() ); return name.compareTo( mappedProperty.getName() );
} }
public abstract HibernateTypeResolver getHibernateTypeResolver(); public abstract AttributeTypeResolver getHibernateTypeResolver();
@Override @Override
public String toString() { public String toString() {

View File

@ -0,0 +1,35 @@
/*
* 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.Map;
/**
* @author Strong Liu
*/
public interface AttributeTypeResolver {
String getExplicitHibernateTypeName();
Map<String, String> getExplicitHibernateTypeParameters();
}

View File

@ -0,0 +1,83 @@
/*
* 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.ArrayList;
import java.util.List;
import java.util.Map;
import org.hibernate.AssertionFailure;
import org.hibernate.internal.util.StringHelper;
import org.hibernate.internal.util.collections.CollectionHelper;
/**
* @author Strong Liu
*/
public class CompositeAttributeTypeResolver implements AttributeTypeResolver {
private List<AttributeTypeResolver> resolvers = new ArrayList<AttributeTypeResolver>();
private final ExplicitAttributeTypeResolver explicitHibernateTypeResolver;
public CompositeAttributeTypeResolver(ExplicitAttributeTypeResolver explicitHibernateTypeResolver) {
if ( explicitHibernateTypeResolver == null ) {
throw new AssertionFailure( "The Given AttributeTypeResolver is null." );
}
this.explicitHibernateTypeResolver = explicitHibernateTypeResolver;
}
public void addHibernateTypeResolver(AttributeTypeResolver resolver) {
if ( resolver == null ) {
throw new AssertionFailure( "The Given AttributeTypeResolver is null." );
}
resolvers.add( resolver );
}
@Override
public String getExplicitHibernateTypeName() {
String type = explicitHibernateTypeResolver.getExplicitHibernateTypeName();
if ( StringHelper.isEmpty( type ) ) {
for ( AttributeTypeResolver resolver : resolvers ) {
type = resolver.getExplicitHibernateTypeName();
if ( StringHelper.isNotEmpty( type ) ) {
break;
}
}
}
return type;
}
@Override
public Map<String, String> getExplicitHibernateTypeParameters() {
Map<String, String> parameters = explicitHibernateTypeResolver.getExplicitHibernateTypeParameters();
if ( CollectionHelper.isEmpty( parameters ) ) {
for ( AttributeTypeResolver resolver : resolvers ) {
parameters = resolver.getExplicitHibernateTypeParameters();
if ( CollectionHelper.isNotEmpty( parameters ) ) {
break;
}
}
}
return parameters;
}
}

View File

@ -1,4 +1,28 @@
package org.hibernate.metamodel.source.annotations.attribute; /*
* 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.sql.Types; import java.sql.Types;
import java.util.HashMap; import java.util.HashMap;
@ -8,16 +32,16 @@ import org.jboss.jandex.AnnotationInstance;
import org.hibernate.AnnotationException; import org.hibernate.AnnotationException;
import org.hibernate.AssertionFailure; import org.hibernate.AssertionFailure;
import org.hibernate.metamodel.relational.Identifier;
import org.hibernate.metamodel.relational.Schema;
import org.hibernate.metamodel.source.annotations.JPADotNames; import org.hibernate.metamodel.source.annotations.JPADotNames;
import org.hibernate.metamodel.source.annotations.JandexHelper; 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; import org.hibernate.type.EnumType;
/** /**
* @author Strong Liu * @author Strong Liu
*/ */
public class EnumeratedTypeResolver extends AbstractHibernateTypeResolver { public class EnumeratedTypeResolver extends AbstractAttributeTypeResolver {
private final MappedAttribute mappedAttribute; private final MappedAttribute mappedAttribute;
private final boolean isMapKey; private final boolean isMapKey;

View File

@ -1,4 +1,28 @@
package org.hibernate.metamodel.source.annotations.attribute; /*
* 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.HashMap;
import java.util.Map; import java.util.Map;
@ -8,15 +32,17 @@ import org.jboss.jandex.AnnotationValue;
import org.hibernate.metamodel.source.annotations.HibernateDotNames; import org.hibernate.metamodel.source.annotations.HibernateDotNames;
import org.hibernate.metamodel.source.annotations.JandexHelper; 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 * @author Strong Liu
*/ */
public class ExplicitHibernateTypeResolver extends AbstractHibernateTypeResolver { public class ExplicitAttributeTypeResolver extends AbstractAttributeTypeResolver {
private final MappedAttribute mappedAttribute; private final MappedAttribute mappedAttribute;
public ExplicitHibernateTypeResolver(MappedAttribute mappedAttribute) { public ExplicitAttributeTypeResolver(MappedAttribute mappedAttribute) {
this.mappedAttribute = mappedAttribute; this.mappedAttribute = mappedAttribute;
} }

View File

@ -1,4 +1,28 @@
package org.hibernate.metamodel.source.annotations.attribute; /*
* 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.io.Serializable; import java.io.Serializable;
import java.sql.Blob; import java.sql.Blob;
@ -11,6 +35,8 @@ import org.jboss.jandex.AnnotationInstance;
import org.hibernate.AssertionFailure; import org.hibernate.AssertionFailure;
import org.hibernate.metamodel.source.annotations.JPADotNames; import org.hibernate.metamodel.source.annotations.JPADotNames;
import org.hibernate.metamodel.source.annotations.JandexHelper; 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.CharacterArrayClobType;
import org.hibernate.type.PrimitiveCharacterArrayClobType; import org.hibernate.type.PrimitiveCharacterArrayClobType;
import org.hibernate.type.SerializableToBlobType; import org.hibernate.type.SerializableToBlobType;
@ -20,7 +46,7 @@ import org.hibernate.type.WrappedMaterializedBlobType;
/** /**
* @author Strong Liu * @author Strong Liu
*/ */
public class LobTypeResolver extends AbstractHibernateTypeResolver { public class LobTypeResolver extends AbstractAttributeTypeResolver {
private final MappedAttribute mappedAttribute; private final MappedAttribute mappedAttribute;

View File

@ -1,4 +1,28 @@
package org.hibernate.metamodel.source.annotations.attribute; /*
* 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.Calendar; import java.util.Calendar;
import java.util.Date; import java.util.Date;
@ -11,11 +35,14 @@ import org.hibernate.AssertionFailure;
import org.hibernate.cfg.NotYetImplementedException; import org.hibernate.cfg.NotYetImplementedException;
import org.hibernate.metamodel.source.annotations.JPADotNames; import org.hibernate.metamodel.source.annotations.JPADotNames;
import org.hibernate.metamodel.source.annotations.JandexHelper; 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;
/** /**
* @author Strong Liu * @author Strong Liu
*/ */
public class TemporalTypeResolver extends AbstractHibernateTypeResolver { public class TemporalTypeResolver extends AbstractAttributeTypeResolver {
private final MappedAttribute mappedAttribute; private final MappedAttribute mappedAttribute;
private final boolean isMapKey; private final boolean isMapKey;
@ -40,16 +67,16 @@ public class TemporalTypeResolver extends AbstractHibernateTypeResolver {
String type = null; String type = null;
switch ( temporalType ) { switch ( temporalType ) {
case DATE: case DATE:
type = isDate ? "date" : "calendar_date"; type = isDate ? StandardBasicTypes.DATE.getName() : StandardBasicTypes.CALENDAR_DATE.getName();
break; break;
case TIME: case TIME:
type = "time"; type = StandardBasicTypes.TIME.getName();
if ( !isDate ) { if ( !isDate ) {
throw new NotYetImplementedException( "Calendar cannot persist TIME only" ); throw new NotYetImplementedException( "Calendar cannot persist TIME only" );
} }
break; break;
case TIMESTAMP: case TIMESTAMP:
type = isDate ? "timestamp" : "calendar"; type = isDate ? StandardBasicTypes.TIMESTAMP.getName() : StandardBasicTypes.CALENDAR.getName();
break; break;
default: default:
throw new AssertionFailure( "Unknown temporal type: " + temporalType ); throw new AssertionFailure( "Unknown temporal type: " + temporalType );

View File

@ -1,3 +1,27 @@
/*
* 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.entity; package org.hibernate.metamodel.source.annotations.entity;
import javax.persistence.Access; import javax.persistence.Access;

View File

@ -1,3 +1,27 @@
/*
* 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.entity; package org.hibernate.metamodel.source.annotations.entity;
import java.sql.Types; import java.sql.Types;

View File

@ -1,3 +1,27 @@
/*
* 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.entity; package org.hibernate.metamodel.source.annotations.entity;
import javax.persistence.Entity; import javax.persistence.Entity;

View File

@ -1,3 +1,27 @@
/*
* 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.entity; package org.hibernate.metamodel.source.annotations.entity;
import java.io.Serializable; import java.io.Serializable;
@ -23,8 +47,6 @@ import org.hibernate.type.StandardBasicTypes;
import org.hibernate.type.WrappedMaterializedBlobType; import org.hibernate.type.WrappedMaterializedBlobType;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull; import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
@ -55,92 +77,174 @@ public class LobBindingTests extends BaseAnnotationBindingTestCase {
String noLob; String noLob;
} }
class Thing implements Serializable{ class Thing implements Serializable {
int size; int size;
} }
private HibernateTypeDescriptor getTypeDescriptor(String attributeName) {
EntityBinding binding = getEntityBinding( Item.class );
AttributeBinding attributeBinding = binding.locateAttributeBinding( attributeName );
return attributeBinding.getHibernateTypeDescriptor();
}
private class ExpectedValue {
String explicitTypeName;
String javaTypeName;
boolean isResolvedTypeMappingNull;
Class resolvedTypeMappingClass;
boolean isTypeParametersNull;
boolean isTypeParametersEmpty;
private ExpectedValue(String explicitTypeName,
String javaTypeName,
boolean resolvedTypeMappingNull,
Class resolvedTypeMappingClass,
boolean typeParametersNull,
boolean typeParametersEmpty
) {
this.explicitTypeName = explicitTypeName;
this.isResolvedTypeMappingNull = resolvedTypeMappingNull;
this.isTypeParametersEmpty = typeParametersEmpty;
this.isTypeParametersNull = typeParametersNull;
this.javaTypeName = javaTypeName;
this.resolvedTypeMappingClass = resolvedTypeMappingClass;
}
}
private void checkHibernateTypeDescriptor(ExpectedValue expectedValue, String attributeName) {
HibernateTypeDescriptor descriptor = getTypeDescriptor( attributeName );
assertEquals( expectedValue.explicitTypeName, descriptor.getExplicitTypeName() );
assertEquals( expectedValue.javaTypeName, descriptor.getJavaTypeName() );
assertEquals( expectedValue.isResolvedTypeMappingNull, descriptor.getResolvedTypeMapping() == null );
assertEquals( expectedValue.resolvedTypeMappingClass, descriptor.getResolvedTypeMapping().getClass() );
assertEquals( expectedValue.isTypeParametersNull, descriptor.getTypeParameters() == null );
assertEquals( expectedValue.isTypeParametersEmpty, descriptor.getTypeParameters().isEmpty() );
}
@Test @Test
@Resources(annotatedClasses = Item.class) @Resources(annotatedClasses = Item.class)
public void testLobTypeAttribute() { public void testClobWithLobAnnotation() {
EntityBinding binding = getEntityBinding( Item.class ); ExpectedValue expectedValue = new ExpectedValue(
"clob",
Clob.class.getName(),
false,
ClobType.class,
false,
true
);
checkHibernateTypeDescriptor( expectedValue, "clob" );
}
AttributeBinding attributeBinding = binding.locateAttributeBinding( "clob" ); @Test
HibernateTypeDescriptor descriptor = attributeBinding.getHibernateTypeDescriptor(); @Resources(annotatedClasses = Item.class)
assertEquals( "clob", descriptor.getExplicitTypeName() ); public void testBlobWithLobAnnotation() {
assertEquals( Clob.class.getName(), descriptor.getJavaTypeName() ); ExpectedValue expectedValue = new ExpectedValue(
assertNotNull( descriptor.getResolvedTypeMapping() ); "blob",
assertEquals( ClobType.class, descriptor.getResolvedTypeMapping().getClass() ); Blob.class.getName(),
assertNotNull( descriptor.getTypeParameters() ); false,
assertTrue( descriptor.getTypeParameters().isEmpty() ); BlobType.class,
false,
true
);
checkHibernateTypeDescriptor( expectedValue, "blob" );
}
attributeBinding = binding.locateAttributeBinding( "blob" ); @Test
descriptor = attributeBinding.getHibernateTypeDescriptor(); @Resources(annotatedClasses = Item.class)
assertEquals( "blob", descriptor.getExplicitTypeName() ); public void testStringWithLobAnnotation() {
assertEquals( Blob.class.getName(), descriptor.getJavaTypeName() ); ExpectedValue expectedValue = new ExpectedValue(
assertNotNull( descriptor.getResolvedTypeMapping() ); "materialized_clob",
assertEquals( BlobType.class, descriptor.getResolvedTypeMapping().getClass() ); String.class.getName(),
assertNotNull( descriptor.getTypeParameters() ); false,
assertTrue( descriptor.getTypeParameters().isEmpty() ); MaterializedClobType.class,
false,
true
);
checkHibernateTypeDescriptor( expectedValue, "str" );
}
attributeBinding = binding.locateAttributeBinding( "str" ); @Test
descriptor = attributeBinding.getHibernateTypeDescriptor(); @Resources(annotatedClasses = Item.class)
assertEquals( "materialized_clob", descriptor.getExplicitTypeName() ); public void testCharacterArrayWithLobAnnotation() {
assertEquals( String.class.getName(), descriptor.getJavaTypeName() ); ExpectedValue expectedValue = new ExpectedValue(
assertNotNull( descriptor.getResolvedTypeMapping() ); CharacterArrayClobType.class.getName(),
assertEquals( MaterializedClobType.class, descriptor.getResolvedTypeMapping().getClass() ); Character[].class.getName(),
assertNotNull( descriptor.getTypeParameters() ); false,
assertTrue( descriptor.getTypeParameters().isEmpty() ); CharacterArrayClobType.class,
false,
true
);
checkHibernateTypeDescriptor( expectedValue, "characters" );
}
attributeBinding = binding.locateAttributeBinding( "characters" ); @Test
descriptor = attributeBinding.getHibernateTypeDescriptor(); @Resources(annotatedClasses = Item.class)
assertEquals( CharacterArrayClobType.class.getName(), descriptor.getExplicitTypeName() ); public void testPrimitiveCharacterArrayWithLobAnnotation() {
assertEquals( Character[].class.getName(), descriptor.getJavaTypeName() ); ExpectedValue expectedValue = new ExpectedValue(
assertNotNull( descriptor.getResolvedTypeMapping() ); PrimitiveCharacterArrayClobType.class.getName(),
assertEquals( CharacterArrayClobType.class, descriptor.getResolvedTypeMapping().getClass() ); char[].class.getName(),
assertNotNull( descriptor.getTypeParameters() ); false,
assertTrue( descriptor.getTypeParameters().isEmpty() ); PrimitiveCharacterArrayClobType.class,
false,
true
);
checkHibernateTypeDescriptor( expectedValue, "chars" );
}
attributeBinding = binding.locateAttributeBinding( "chars" ); @Test
descriptor = attributeBinding.getHibernateTypeDescriptor(); @Resources(annotatedClasses = Item.class)
assertEquals( PrimitiveCharacterArrayClobType.class.getName(), descriptor.getExplicitTypeName() ); public void testByteArrayWithLobAnnotation() {
assertEquals( char[].class.getName(), descriptor.getJavaTypeName() ); ExpectedValue expectedValue = new ExpectedValue(
assertNotNull( descriptor.getResolvedTypeMapping() ); WrappedMaterializedBlobType.class.getName(),
assertEquals( PrimitiveCharacterArrayClobType.class, descriptor.getResolvedTypeMapping().getClass() ); Byte[].class.getName(),
assertNotNull( descriptor.getTypeParameters() ); false,
assertTrue( descriptor.getTypeParameters().isEmpty() ); WrappedMaterializedBlobType.class,
false,
true
);
checkHibernateTypeDescriptor( expectedValue, "bytes" );
}
attributeBinding = binding.locateAttributeBinding( "bytes" ); @Test
descriptor = attributeBinding.getHibernateTypeDescriptor(); @Resources(annotatedClasses = Item.class)
assertEquals( WrappedMaterializedBlobType.class.getName(), descriptor.getExplicitTypeName() ); public void testPrimitiveByteArrayWithLobAnnotation() {
assertEquals( Byte[].class.getName(), descriptor.getJavaTypeName() ); ExpectedValue expectedValue = new ExpectedValue(
assertNotNull( descriptor.getResolvedTypeMapping() ); StandardBasicTypes.MATERIALIZED_BLOB.getName(),
assertEquals( WrappedMaterializedBlobType.class, descriptor.getResolvedTypeMapping().getClass() ); byte[].class.getName(),
assertNotNull( descriptor.getTypeParameters() ); false,
assertTrue( descriptor.getTypeParameters().isEmpty() ); MaterializedBlobType.class,
false,
true
);
checkHibernateTypeDescriptor( expectedValue, "bytes2" );
}
attributeBinding = binding.locateAttributeBinding( "bytes2" ); @Test
descriptor = attributeBinding.getHibernateTypeDescriptor(); @Resources(annotatedClasses = Item.class)
assertEquals( StandardBasicTypes.MATERIALIZED_BLOB.getName(), descriptor.getExplicitTypeName() ); public void testSerializableWithLobAnnotation() {
assertEquals( byte[].class.getName(), descriptor.getJavaTypeName() ); ExpectedValue expectedValue = new ExpectedValue(
assertNotNull( descriptor.getResolvedTypeMapping() ); SerializableToBlobType.class.getName(),
assertEquals( MaterializedBlobType.class, descriptor.getResolvedTypeMapping().getClass() ); Thing.class.getName(),
assertNotNull( descriptor.getTypeParameters() ); false,
assertTrue( descriptor.getTypeParameters().isEmpty() ); SerializableToBlobType.class,
false,
false
);
checkHibernateTypeDescriptor( expectedValue, "serializable" );
attributeBinding = binding.locateAttributeBinding( "serializable" ); assertTrue(
descriptor = attributeBinding.getHibernateTypeDescriptor(); getTypeDescriptor( "serializable" ).getTypeParameters()
assertEquals( SerializableToBlobType.class.getName(), descriptor.getExplicitTypeName() ); .get( SerializableToBlobType.CLASS_NAME )
assertEquals( Thing.class.getName(), descriptor.getJavaTypeName() ); .equals( Thing.class.getName() )
assertNotNull( descriptor.getResolvedTypeMapping() ); );
assertEquals( SerializableToBlobType.class, descriptor.getResolvedTypeMapping().getClass() ); }
assertNotNull( descriptor.getTypeParameters() );
assertEquals( 1,descriptor.getTypeParameters().size() );
assertTrue( descriptor.getTypeParameters().get( SerializableToBlobType.CLASS_NAME ).equals( Thing.class.getName() ) );
attributeBinding = binding.locateAttributeBinding( "noLob" );
descriptor = attributeBinding.getHibernateTypeDescriptor(); @Test
assertNull( descriptor.getExplicitTypeName() ); @Resources(annotatedClasses = Item.class)
assertTrue( descriptor.getTypeParameters().isEmpty() ); public void testNoLobAttribute() {
assertNull( getTypeDescriptor( "noLob" ).getExplicitTypeName() );
assertTrue( getTypeDescriptor( "noLob" ).getTypeParameters().isEmpty() );
} }
} }

View File

@ -1,3 +1,27 @@
/*
* 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.entity; package org.hibernate.metamodel.source.annotations.entity;
import javax.persistence.Entity; import javax.persistence.Entity;
@ -33,6 +57,8 @@ public class QuotedIdentifierTest extends BaseAnnotationBindingTestCase {
assertIdentifierEquals( "`TABLE_ITEM4`", item ); assertIdentifierEquals( "`TABLE_ITEM4`", item );
} }
//todo check if the column names are quoted
private void assertIdentifierEquals(String expected, EntityBinding realValue) { private void assertIdentifierEquals(String expected, EntityBinding realValue) {
org.hibernate.metamodel.relational.Table table = (org.hibernate.metamodel.relational.Table) realValue.getPrimaryTable(); org.hibernate.metamodel.relational.Table table = (org.hibernate.metamodel.relational.Table) realValue.getPrimaryTable();
assertEquals( Identifier.toIdentifier( expected ), table.getTableName() ); assertEquals( Identifier.toIdentifier( expected ), table.getTableName() );