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;
import java.util.Collections;
@ -6,11 +30,12 @@ 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 AbstractHibernateTypeResolver implements HibernateTypeResolver {
public abstract class AbstractAttributeTypeResolver implements AttributeTypeResolver {
protected abstract AnnotationInstance getAnnotationInstance();
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.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.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).
@ -99,7 +105,7 @@ public class BasicAttribute extends MappedAttribute {
private final String customWriteFragment;
private final String customReadFragment;
private final String checkCondition;
private HibernateTypeResolver resolver;
private AttributeTypeResolver resolver;
public static BasicAttribute createSimpleAttribute(String name,
Class<?> attributeType,
@ -351,17 +357,17 @@ public class BasicAttribute extends MappedAttribute {
}
@Override
public HibernateTypeResolver getHibernateTypeResolver() {
public AttributeTypeResolver getHibernateTypeResolver() {
if ( resolver == null ) {
resolver = getDefaultHibernateTypeResolver();
}
return resolver;
}
protected HibernateTypeResolver getDefaultHibernateTypeResolver() {
protected AttributeTypeResolver getDefaultHibernateTypeResolver() {
CompositeHibernateTypeResolver resolver = new CompositeHibernateTypeResolver(
new ExplicitHibernateTypeResolver(
CompositeAttributeTypeResolver resolver = new CompositeAttributeTypeResolver(
new ExplicitAttributeTypeResolver(
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;
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;
import java.util.Map;
import org.hibernate.metamodel.source.annotations.attribute.type.AttributeTypeResolver;
import org.hibernate.metamodel.source.binder.ExplicitHibernateTypeSource;
/**
* @author Strong Liu
*/
public class ExplicitHibernateTypeSourceImpl implements ExplicitHibernateTypeSource {
private final HibernateTypeResolver typeResolver;
private final AttributeTypeResolver typeResolver;
public ExplicitHibernateTypeSourceImpl(HibernateTypeResolver typeResolver) {
public ExplicitHibernateTypeSourceImpl(AttributeTypeResolver 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;
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.Map;
import javax.persistence.TemporalType;
import org.jboss.jandex.AnnotationInstance;
import org.jboss.jandex.AnnotationValue;
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.HibernateDotNames;
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;
import org.hibernate.metamodel.source.annotations.attribute.type.AttributeTypeResolver;
/**
* Base class for the different types of mapped attributes
@ -106,7 +88,7 @@ public abstract class MappedAttribute implements Comparable<MappedAttribute> {
return context;
}
Map<DotName, List<AnnotationInstance>> annotations() {
public Map<DotName, List<AnnotationInstance>> annotations() {
return annotations;
}
@ -115,7 +97,7 @@ public abstract class MappedAttribute implements Comparable<MappedAttribute> {
return name.compareTo( mappedProperty.getName() );
}
public abstract HibernateTypeResolver getHibernateTypeResolver();
public abstract AttributeTypeResolver getHibernateTypeResolver();
@Override
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.util.HashMap;
@ -8,16 +32,16 @@ import org.jboss.jandex.AnnotationInstance;
import org.hibernate.AnnotationException;
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.JandexHelper;
import org.hibernate.metamodel.source.annotations.attribute.AbstractAttributeTypeResolver;
import org.hibernate.metamodel.source.annotations.attribute.MappedAttribute;
import org.hibernate.type.EnumType;
/**
* @author Strong Liu
*/
public class EnumeratedTypeResolver extends AbstractHibernateTypeResolver {
public class EnumeratedTypeResolver extends AbstractAttributeTypeResolver {
private final MappedAttribute mappedAttribute;
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.Map;
@ -8,15 +32,17 @@ 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 ExplicitHibernateTypeResolver extends AbstractHibernateTypeResolver {
public class ExplicitAttributeTypeResolver extends AbstractAttributeTypeResolver {
private final MappedAttribute mappedAttribute;
public ExplicitHibernateTypeResolver(MappedAttribute mappedAttribute) {
public ExplicitAttributeTypeResolver(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.sql.Blob;
@ -11,6 +35,8 @@ 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;
import org.hibernate.type.SerializableToBlobType;
@ -20,7 +46,7 @@ import org.hibernate.type.WrappedMaterializedBlobType;
/**
* @author Strong Liu
*/
public class LobTypeResolver extends AbstractHibernateTypeResolver {
public class LobTypeResolver extends AbstractAttributeTypeResolver {
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.Date;
@ -11,11 +35,14 @@ 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;
/**
* @author Strong Liu
*/
public class TemporalTypeResolver extends AbstractHibernateTypeResolver {
public class TemporalTypeResolver extends AbstractAttributeTypeResolver {
private final MappedAttribute mappedAttribute;
private final boolean isMapKey;
@ -40,16 +67,16 @@ public class TemporalTypeResolver extends AbstractHibernateTypeResolver {
String type = null;
switch ( temporalType ) {
case DATE:
type = isDate ? "date" : "calendar_date";
type = isDate ? StandardBasicTypes.DATE.getName() : StandardBasicTypes.CALENDAR_DATE.getName();
break;
case TIME:
type = "time";
type = StandardBasicTypes.TIME.getName();
if ( !isDate ) {
throw new NotYetImplementedException( "Calendar cannot persist TIME only" );
}
break;
case TIMESTAMP:
type = isDate ? "timestamp" : "calendar";
type = isDate ? StandardBasicTypes.TIMESTAMP.getName() : StandardBasicTypes.CALENDAR.getName();
break;
default:
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;
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;
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;
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;
import java.io.Serializable;
@ -23,8 +47,6 @@ import org.hibernate.type.StandardBasicTypes;
import org.hibernate.type.WrappedMaterializedBlobType;
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.assertTrue;
@ -55,92 +77,174 @@ public class LobBindingTests extends BaseAnnotationBindingTestCase {
String noLob;
}
class Thing implements Serializable{
class Thing implements Serializable {
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
@Resources(annotatedClasses = Item.class)
public void testLobTypeAttribute() {
EntityBinding binding = getEntityBinding( Item.class );
public void testClobWithLobAnnotation() {
ExpectedValue expectedValue = new ExpectedValue(
"clob",
Clob.class.getName(),
false,
ClobType.class,
false,
true
);
checkHibernateTypeDescriptor( expectedValue, "clob" );
}
AttributeBinding attributeBinding = binding.locateAttributeBinding( "clob" );
HibernateTypeDescriptor descriptor = attributeBinding.getHibernateTypeDescriptor();
assertEquals( "clob", descriptor.getExplicitTypeName() );
assertEquals( Clob.class.getName(), descriptor.getJavaTypeName() );
assertNotNull( descriptor.getResolvedTypeMapping() );
assertEquals( ClobType.class, descriptor.getResolvedTypeMapping().getClass() );
assertNotNull( descriptor.getTypeParameters() );
assertTrue( descriptor.getTypeParameters().isEmpty() );
@Test
@Resources(annotatedClasses = Item.class)
public void testBlobWithLobAnnotation() {
ExpectedValue expectedValue = new ExpectedValue(
"blob",
Blob.class.getName(),
false,
BlobType.class,
false,
true
);
checkHibernateTypeDescriptor( expectedValue, "blob" );
}
attributeBinding = binding.locateAttributeBinding( "blob" );
descriptor = attributeBinding.getHibernateTypeDescriptor();
assertEquals( "blob", descriptor.getExplicitTypeName() );
assertEquals( Blob.class.getName(), descriptor.getJavaTypeName() );
assertNotNull( descriptor.getResolvedTypeMapping() );
assertEquals( BlobType.class, descriptor.getResolvedTypeMapping().getClass() );
assertNotNull( descriptor.getTypeParameters() );
assertTrue( descriptor.getTypeParameters().isEmpty() );
@Test
@Resources(annotatedClasses = Item.class)
public void testStringWithLobAnnotation() {
ExpectedValue expectedValue = new ExpectedValue(
"materialized_clob",
String.class.getName(),
false,
MaterializedClobType.class,
false,
true
);
checkHibernateTypeDescriptor( expectedValue, "str" );
}
attributeBinding = binding.locateAttributeBinding( "str" );
descriptor = attributeBinding.getHibernateTypeDescriptor();
assertEquals( "materialized_clob", descriptor.getExplicitTypeName() );
assertEquals( String.class.getName(), descriptor.getJavaTypeName() );
assertNotNull( descriptor.getResolvedTypeMapping() );
assertEquals( MaterializedClobType.class, descriptor.getResolvedTypeMapping().getClass() );
assertNotNull( descriptor.getTypeParameters() );
assertTrue( descriptor.getTypeParameters().isEmpty() );
@Test
@Resources(annotatedClasses = Item.class)
public void testCharacterArrayWithLobAnnotation() {
ExpectedValue expectedValue = new ExpectedValue(
CharacterArrayClobType.class.getName(),
Character[].class.getName(),
false,
CharacterArrayClobType.class,
false,
true
);
checkHibernateTypeDescriptor( expectedValue, "characters" );
}
attributeBinding = binding.locateAttributeBinding( "characters" );
descriptor = attributeBinding.getHibernateTypeDescriptor();
assertEquals( CharacterArrayClobType.class.getName(), descriptor.getExplicitTypeName() );
assertEquals( Character[].class.getName(), descriptor.getJavaTypeName() );
assertNotNull( descriptor.getResolvedTypeMapping() );
assertEquals( CharacterArrayClobType.class, descriptor.getResolvedTypeMapping().getClass() );
assertNotNull( descriptor.getTypeParameters() );
assertTrue( descriptor.getTypeParameters().isEmpty() );
@Test
@Resources(annotatedClasses = Item.class)
public void testPrimitiveCharacterArrayWithLobAnnotation() {
ExpectedValue expectedValue = new ExpectedValue(
PrimitiveCharacterArrayClobType.class.getName(),
char[].class.getName(),
false,
PrimitiveCharacterArrayClobType.class,
false,
true
);
checkHibernateTypeDescriptor( expectedValue, "chars" );
}
attributeBinding = binding.locateAttributeBinding( "chars" );
descriptor = attributeBinding.getHibernateTypeDescriptor();
assertEquals( PrimitiveCharacterArrayClobType.class.getName(), descriptor.getExplicitTypeName() );
assertEquals( char[].class.getName(), descriptor.getJavaTypeName() );
assertNotNull( descriptor.getResolvedTypeMapping() );
assertEquals( PrimitiveCharacterArrayClobType.class, descriptor.getResolvedTypeMapping().getClass() );
assertNotNull( descriptor.getTypeParameters() );
assertTrue( descriptor.getTypeParameters().isEmpty() );
@Test
@Resources(annotatedClasses = Item.class)
public void testByteArrayWithLobAnnotation() {
ExpectedValue expectedValue = new ExpectedValue(
WrappedMaterializedBlobType.class.getName(),
Byte[].class.getName(),
false,
WrappedMaterializedBlobType.class,
false,
true
);
checkHibernateTypeDescriptor( expectedValue, "bytes" );
}
attributeBinding = binding.locateAttributeBinding( "bytes" );
descriptor = attributeBinding.getHibernateTypeDescriptor();
assertEquals( WrappedMaterializedBlobType.class.getName(), descriptor.getExplicitTypeName() );
assertEquals( Byte[].class.getName(), descriptor.getJavaTypeName() );
assertNotNull( descriptor.getResolvedTypeMapping() );
assertEquals( WrappedMaterializedBlobType.class, descriptor.getResolvedTypeMapping().getClass() );
assertNotNull( descriptor.getTypeParameters() );
assertTrue( descriptor.getTypeParameters().isEmpty() );
@Test
@Resources(annotatedClasses = Item.class)
public void testPrimitiveByteArrayWithLobAnnotation() {
ExpectedValue expectedValue = new ExpectedValue(
StandardBasicTypes.MATERIALIZED_BLOB.getName(),
byte[].class.getName(),
false,
MaterializedBlobType.class,
false,
true
);
checkHibernateTypeDescriptor( expectedValue, "bytes2" );
}
attributeBinding = binding.locateAttributeBinding( "bytes2" );
descriptor = attributeBinding.getHibernateTypeDescriptor();
assertEquals( StandardBasicTypes.MATERIALIZED_BLOB.getName(), descriptor.getExplicitTypeName() );
assertEquals( byte[].class.getName(), descriptor.getJavaTypeName() );
assertNotNull( descriptor.getResolvedTypeMapping() );
assertEquals( MaterializedBlobType.class, descriptor.getResolvedTypeMapping().getClass() );
assertNotNull( descriptor.getTypeParameters() );
assertTrue( descriptor.getTypeParameters().isEmpty() );
@Test
@Resources(annotatedClasses = Item.class)
public void testSerializableWithLobAnnotation() {
ExpectedValue expectedValue = new ExpectedValue(
SerializableToBlobType.class.getName(),
Thing.class.getName(),
false,
SerializableToBlobType.class,
false,
false
);
checkHibernateTypeDescriptor( expectedValue, "serializable" );
attributeBinding = binding.locateAttributeBinding( "serializable" );
descriptor = attributeBinding.getHibernateTypeDescriptor();
assertEquals( SerializableToBlobType.class.getName(), descriptor.getExplicitTypeName() );
assertEquals( Thing.class.getName(), descriptor.getJavaTypeName() );
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() ) );
assertTrue(
getTypeDescriptor( "serializable" ).getTypeParameters()
.get( SerializableToBlobType.CLASS_NAME )
.equals( Thing.class.getName() )
);
}
attributeBinding = binding.locateAttributeBinding( "noLob" );
descriptor = attributeBinding.getHibernateTypeDescriptor();
assertNull( descriptor.getExplicitTypeName() );
assertTrue( descriptor.getTypeParameters().isEmpty() );
@Test
@Resources(annotatedClasses = Item.class)
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;
import javax.persistence.Entity;
@ -33,6 +57,8 @@ public class QuotedIdentifierTest extends BaseAnnotationBindingTestCase {
assertIdentifierEquals( "`TABLE_ITEM4`", item );
}
//todo check if the column names are quoted
private void assertIdentifierEquals(String expected, EntityBinding realValue) {
org.hibernate.metamodel.relational.Table table = (org.hibernate.metamodel.relational.Table) realValue.getPrimaryTable();
assertEquals( Identifier.toIdentifier( expected ), table.getTableName() );