HHH-8893 HBM transform/mock

This commit is contained in:
Brett Meyer 2014-04-04 11:05:53 -04:00
parent 87a4b56bd2
commit 95d66ed252
39 changed files with 882 additions and 638 deletions

View File

@ -610,7 +610,7 @@ public final class StringHelper {
}
public static String toUpperCase(String str) {
return str==null ? null : str.toUpperCase();
return str == null ? null : str.toUpperCase(Locale.ENGLISH);
}
public static String toLowerCase(String str) {

View File

@ -25,6 +25,7 @@ package org.hibernate.metamodel.source.internal.annotations.global;
import java.util.Collection;
import java.util.HashMap;
import javax.persistence.LockModeType;
import javax.persistence.ParameterMode;
@ -41,7 +42,6 @@ import org.hibernate.annotations.QueryHints;
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.engine.query.spi.sql.NativeSQLQueryRootReturn;
import org.hibernate.engine.spi.NamedQueryDefinitionBuilder;
import org.hibernate.engine.spi.NamedSQLQueryDefinition;
import org.hibernate.engine.spi.NamedSQLQueryDefinitionBuilder;
import org.hibernate.internal.CoreLogging;
import org.hibernate.internal.CoreMessageLogger;
@ -52,7 +52,6 @@ import org.hibernate.metamodel.source.internal.annotations.AnnotationBindingCont
import org.hibernate.metamodel.source.internal.annotations.util.HibernateDotNames;
import org.hibernate.metamodel.source.internal.annotations.util.JPADotNames;
import org.hibernate.metamodel.source.internal.annotations.util.JandexHelper;
import org.jboss.jandex.AnnotationInstance;
import org.jboss.jandex.AnnotationValue;
@ -113,7 +112,7 @@ public class QueryProcessor {
JPADotNames.NAMED_NATIVE_QUERIES
);
for ( AnnotationInstance query : annotations ) {
bindNamedNativeQuery( query, bindingContext );
bindNamedNativeQuery( bindingContext, query );
}
annotations = JandexHelper.collectionAnnotations(
@ -122,7 +121,7 @@ public class QueryProcessor {
JPADotNames.NAMED_STORED_PROCEDURE_QUERIES
);
for ( AnnotationInstance query : annotations ) {
bindNamedStoredProcedureQuery( query, bindingContext );
bindNamedStoredProcedureQuery( bindingContext, query );
}
annotations = JandexHelper.collectionAnnotations(
@ -140,7 +139,7 @@ public class QueryProcessor {
HibernateDotNames.NAMED_NATIVE_QUERIES
);
for ( AnnotationInstance query : annotations ) {
bindNamedNativeQuery( query, bindingContext );
bindNamedNativeQuery( bindingContext, query );
}
}
@ -161,8 +160,7 @@ public class QueryProcessor {
if ( annotation.name().equals( JPADotNames.NAMED_QUERY ) ) {
bindJPANamedQuery( annotation, builder, name, query, bindingContext );
} else {
builder.setFlushMode(
getFlushMode( JandexHelper.getEnumValue( annotation, "flushMode", FlushModeType.class, classLoaderService ) ) )
builder.setFlushMode( getFlushMode( JandexHelper.getEnumValue( annotation, "flushMode", FlushModeType.class, classLoaderService ) ) )
.setCacheable( JandexHelper.getValue( annotation, "cacheable", Boolean.class, classLoaderService ) )
.setCacheRegion( defaultToNull( JandexHelper.getValue( annotation, "cacheRegion", String.class, classLoaderService ) ) )
.setFetchSize( defaultToNull( JandexHelper.getValue( annotation, "fetchSize", Integer.class, classLoaderService ) ) )
@ -172,52 +170,10 @@ public class QueryProcessor {
.setReadOnly( JandexHelper.getValue( annotation, "readOnly", Boolean.class, classLoaderService ) );
}
bindingContext.getMetadataCollector().addNamedQuery(builder.createNamedQueryDefinition());
LOG.debugf( "Binding named query: %s => %s", name, query );
}
public static FlushMode getFlushMode(FlushModeType flushModeType) {
FlushMode flushMode;
switch ( flushModeType ) {
case ALWAYS:
flushMode = FlushMode.ALWAYS;
break;
case AUTO:
flushMode = FlushMode.AUTO;
break;
case COMMIT:
flushMode = FlushMode.COMMIT;
break;
case MANUAL:
flushMode = FlushMode.MANUAL;
break;
case PERSISTENCE_CONTEXT:
flushMode = null;
break;
default:
throw new AssertionFailure( "Unknown flushModeType: " + flushModeType );
}
return flushMode;
}
private static CacheMode getCacheMode(CacheModeType cacheModeType) {
switch ( cacheModeType ) {
case GET:
return CacheMode.GET;
case IGNORE:
return CacheMode.IGNORE;
case NORMAL:
return CacheMode.NORMAL;
case PUT:
return CacheMode.PUT;
case REFRESH:
return CacheMode.REFRESH;
default:
throw new AssertionFailure( "Unknown cacheModeType: " + cacheModeType );
}
}
private static void bindJPANamedQuery(
AnnotationInstance annotation,
NamedQueryDefinitionBuilder builder,
@ -263,21 +219,84 @@ public class QueryProcessor {
.setComment( defaultToNull( getString( hints, QueryHints.COMMENT, bindingContext ) ) )
.setParameterTypes( null );
}
private static void bindNamedNativeQuery(AnnotationInstance annotation, AnnotationBindingContext bindingContext) {
private static void bindNamedNativeQuery(AnnotationBindingContext bindingContext, AnnotationInstance annotation) {
final ClassLoaderService classLoaderService = bindingContext.getBuildingOptions().getServiceRegistry().getService( ClassLoaderService.class );
String name = JandexHelper.getValue( annotation, "name", String.class, classLoaderService );
final String name = JandexHelper.getValue( annotation, "name", String.class, classLoaderService );
if ( StringHelper.isEmpty( name ) ) {
throw new AnnotationException( "A named native query must have a name when used in class or package level" );
}
NamedSQLQueryDefinitionBuilder builder = new NamedSQLQueryDefinitionBuilder();
builder.setName( name );
String query = JandexHelper.getValue( annotation, "query", String.class, classLoaderService );
final String query = JandexHelper.getValue( annotation, "query", String.class, classLoaderService );
builder.setQuery( query );
if ( annotation.name().equals( JPADotNames.NAMED_NATIVE_QUERY ) ) {
bindJPANamedNativeQuery( annotation, builder, name, query, bindingContext );
final String resultSetMapping = JandexHelper.getValue(
annotation, "resultSetMapping", String.class, classLoaderService );
if ( StringHelper.isNotEmpty( resultSetMapping ) ) {
boolean resultSetMappingExists = bindingContext.getMetadataCollector().getResultSetMappingDefinitions().containsKey( resultSetMapping );
if ( !resultSetMappingExists ) {
throw new MappingException(
String.format(
"Named SQL Query [%s] referenced an non-existent result set mapping [%s] ",
name,
resultSetMapping
)
);
}
builder.setResultSetRef( resultSetMapping );
}
else {
AnnotationValue annotationValue = annotation.value( "resultClass" );
NativeSQLQueryRootReturn[] queryRoots;
if ( annotationValue == null ) {
// pure native scalar query
queryRoots = new NativeSQLQueryRootReturn[0];
}
else {
queryRoots = new NativeSQLQueryRootReturn[] {
new NativeSQLQueryRootReturn(
"alias1",
annotationValue.asString(),
new HashMap<String, String[]>(),
LockMode.READ
)
};
}
builder.setQueryReturns( queryRoots );
}
}
else {
builder.setFlushMode( getFlushMode( JandexHelper.getEnumValue( annotation, "flushMode", FlushModeType.class, classLoaderService ) ) )
.setCacheable( JandexHelper.getValue( annotation, "cacheable", Boolean.class, classLoaderService ) )
.setCacheRegion( defaultToNull( JandexHelper.getValue( annotation, "cacheRegion", String.class, classLoaderService ) ) )
.setFetchSize( defaultToNull( JandexHelper.getValue( annotation, "fetchSize", Integer.class, classLoaderService ) ) )
.setTimeout( defaultToNull( JandexHelper.getValue( annotation, "timeout", Integer.class, classLoaderService ) ) )
.setComment( JandexHelper.getValue( annotation, "comment", String.class, classLoaderService ) )
.setCacheMode( getCacheMode( JandexHelper.getValue( annotation, "cacheMode", CacheModeType.class, classLoaderService ) ) )
.setReadOnly( JandexHelper.getValue( annotation, "readOnly", Boolean.class, classLoaderService ) )
.setCallable( JandexHelper.getValue( annotation, "callable", Boolean.class, classLoaderService ) )
.setQueryReturns( new NativeSQLQueryRootReturn[0] );
}
String resultSetMapping = JandexHelper.getValue( annotation, "resultSetMapping", String.class, classLoaderService );
bindingContext.getMetadataCollector().addNamedNativeQuery(builder.createNamedQueryDefinition());
LOG.debugf( "Binding named query: %s => %s", name, query );
}
AnnotationInstance[] hints = JandexHelper.getValue( annotation, "hints", AnnotationInstance[].class, classLoaderService );
private static void bindJPANamedNativeQuery(
AnnotationInstance annotation,
NamedSQLQueryDefinitionBuilder builder,
String name,
String query,
AnnotationBindingContext bindingContext){
final ClassLoaderService classLoaderService = bindingContext.getBuildingOptions().getServiceRegistry().getService( ClassLoaderService.class );
AnnotationInstance[] hints = JandexHelper.getValue( annotation, "hints", AnnotationInstance[].class,
classLoaderService );
boolean cacheable = getBoolean( hints, "org.hibernate.cacheable", name, bindingContext );
String cacheRegion = getString( hints, QueryHints.CACHE_REGION, bindingContext );
if ( StringHelper.isEmpty( cacheRegion ) ) {
cacheRegion = null;
@ -287,93 +306,63 @@ public class QueryProcessor {
if ( timeout != null && timeout < 0 ) {
timeout = null;
}
builder.setCacheable( getBoolean( hints, QueryHints.CACHEABLE, name, bindingContext ) )
.setCacheRegion( cacheRegion )
.setTimeout( timeout )
.setFetchSize( defaultToNull( getInteger( hints, QueryHints.FETCH_SIZE, name, bindingContext ) ) )
.setFlushMode( getFlushMode( hints, QueryHints.FLUSH_MODE, name, bindingContext ) )
.setCacheMode( getCacheMode( hints, QueryHints.CACHE_MODE, name, bindingContext ) )
.setReadOnly( getBoolean( hints, QueryHints.READ_ONLY, name, bindingContext ) )
.setComment( defaultToNull( getString( hints, QueryHints.COMMENT, bindingContext ) ) )
.setParameterTypes( null )
.setCallable( getBoolean( hints, QueryHints.CALLABLE, name, bindingContext ) );
}
Integer fetchSize = getInteger( hints, QueryHints.FETCH_SIZE, name, bindingContext );
if ( fetchSize != null && fetchSize < 0 ) {
fetchSize = null;
public static FlushMode getFlushMode(FlushModeType flushModeType) {
FlushMode flushMode;
switch ( flushModeType ) {
case ALWAYS:
flushMode = FlushMode.ALWAYS;
break;
case AUTO:
flushMode = FlushMode.AUTO;
break;
case COMMIT:
flushMode = FlushMode.COMMIT;
break;
case MANUAL:
flushMode = FlushMode.MANUAL;
break;
case PERSISTENCE_CONTEXT:
flushMode = null;
break;
default:
throw new AssertionFailure( "Unknown flushModeType: " + flushModeType );
}
FlushMode flushMode = getFlushMode( hints, QueryHints.FLUSH_MODE, name, bindingContext );
CacheMode cacheMode = getCacheMode( hints, QueryHints.CACHE_MODE, name, bindingContext );
boolean readOnly = getBoolean( hints, QueryHints.READ_ONLY, name, bindingContext );
String comment = getString( hints, QueryHints.COMMENT, bindingContext );
if ( StringHelper.isEmpty( comment ) ) {
comment = null;
return flushMode;
}
private static CacheMode getCacheMode(CacheModeType cacheModeType) {
switch ( cacheModeType ) {
case GET:
return CacheMode.GET;
case IGNORE:
return CacheMode.IGNORE;
case NORMAL:
return CacheMode.NORMAL;
case PUT:
return CacheMode.PUT;
case REFRESH:
return CacheMode.REFRESH;
default:
throw new AssertionFailure( "Unknown cacheModeType: " + cacheModeType );
}
boolean callable = getBoolean( hints, QueryHints.CALLABLE, name, bindingContext );
NamedSQLQueryDefinition def;
if ( StringHelper.isNotEmpty( resultSetMapping ) ) {
boolean resultSetMappingExists = bindingContext.getMetadataCollector().getResultSetMappingDefinitions().containsKey( resultSetMapping );
if ( !resultSetMappingExists ) {
throw new MappingException(
String.format(
"Named SQL Query [%s] referenced an non-existent result set mapping [%s] ",
name,
resultSetMapping
)
);
}
def = new NamedSQLQueryDefinitionBuilder().setName( name )
.setQuery( query )
.setResultSetRef(
resultSetMapping
)
.setQuerySpaces( null )
.setCacheable( cacheable )
.setCacheRegion( cacheRegion )
.setTimeout( timeout )
.setFetchSize( fetchSize )
.setFlushMode( flushMode )
.setCacheMode( cacheMode )
.setReadOnly( readOnly )
.setComment( comment )
.setParameterTypes( null )
.setCallable( callable )
.createNamedQueryDefinition();
}
else {
AnnotationValue annotationValue = annotation.value( "resultClass" );
NativeSQLQueryRootReturn[] queryRoots;
if ( annotationValue == null ) {
// pure native scalar query
queryRoots = new NativeSQLQueryRootReturn[0];
}
else {
queryRoots = new NativeSQLQueryRootReturn[] {
new NativeSQLQueryRootReturn(
"alias1",
annotationValue.asString(),
new HashMap<String, String[]>(),
LockMode.READ
)
};
}
def = new NamedSQLQueryDefinitionBuilder().setName( name )
.setQuery( query )
.setQueryReturns( queryRoots )
.setQuerySpaces( null )
.setCacheable( cacheable )
.setCacheRegion( cacheRegion )
.setTimeout( timeout )
.setFetchSize( fetchSize )
.setFlushMode( flushMode )
.setCacheMode( cacheMode )
.setReadOnly( readOnly )
.setComment( comment )
.setParameterTypes( null )
.setCallable( callable )
.createNamedQueryDefinition();
}
bindingContext.getMetadataCollector().addNamedNativeQuery( def );
LOG.debugf( "Binding named native query: %s => %s", name, query );
}
private static void bindNamedStoredProcedureQuery(
AnnotationInstance query,
AnnotationBindingContext bindingContext) {
AnnotationBindingContext bindingContext,
AnnotationInstance query) {
final String name = query.value( "name" ).asString();
final String procedureName = query.value( "procedureName" ).asString();
LOG.debugf( "Starting binding of @NamedStoredProcedureQuery(name=%s, procedureName=%s)", name, procedureName );

View File

@ -50,17 +50,17 @@ import org.jboss.jandex.ClassInfo;
*/
public abstract class AbstractAttributesBuilder {
private ClassInfo classInfo;
private EntityMappingsMocker.Default defaults;
private IndexBuilder indexBuilder;
protected ClassInfo classInfo;
protected Default defaults;
protected IndexBuilder indexBuilder;
AbstractAttributesBuilder(IndexBuilder indexBuilder, ClassInfo classInfo, EntityMappingsMocker.Default defaults) {
AbstractAttributesBuilder(IndexBuilder indexBuilder, ClassInfo classInfo, Default defaults) {
this.indexBuilder = indexBuilder;
this.classInfo = classInfo;
this.defaults = defaults;
}
final void parse() {
protected void parse() {
for ( JaxbId id : getId() ) {
new IdMocker( indexBuilder, classInfo, defaults, id ).process();
}

View File

@ -51,7 +51,7 @@ public abstract class AbstractEntityObjectMocker extends AnnotationMocker {
protected AbstractAttributesBuilder attributesBuilder;
protected ClassInfo classInfo;
AbstractEntityObjectMocker(IndexBuilder indexBuilder, EntityMappingsMocker.Default defaults) {
AbstractEntityObjectMocker(IndexBuilder indexBuilder, Default defaults) {
super( indexBuilder, defaults );
}
@ -82,7 +82,7 @@ public abstract class AbstractEntityObjectMocker extends AnnotationMocker {
}
parseAccessType( accessType, getTarget() );
}
processExtra();
doProcess();
if ( isExcludeDefaultListeners() ) {
create( EXCLUDE_DEFAULT_LISTENERS );
}
@ -91,10 +91,8 @@ public abstract class AbstractEntityObjectMocker extends AnnotationMocker {
}
parseIdClass( getIdClass() );
if ( getAttributes() != null ) {
getAttributesBuilder().parse();
}
getAttributesBuilder().parse();
if ( getEntityListeners() != null ) {
getListenerparse().parse( getEntityListeners() );
}
@ -110,7 +108,7 @@ public abstract class AbstractEntityObjectMocker extends AnnotationMocker {
}
abstract protected ManagedType getEntityElement();
abstract protected void processExtra();
abstract protected void doProcess();
abstract protected boolean isExcludeDefaultListeners();
abstract protected boolean isExcludeSuperclassListeners();
@ -132,11 +130,13 @@ public abstract class AbstractEntityObjectMocker extends AnnotationMocker {
abstract protected JaxbPostLoad getPostLoad();
// TODO: Re-think this. EmbeddableAttributesBuilder#attributes is a JaxbEmbeddableAttributes, so it instead
// has to override #getAttributesBuilder().
abstract protected JaxbAttributes getAttributes();
protected ListenerMocker getListenerparse() {
if ( listenerparse == null ) {
listenerparse = new ListenerMocker( indexBuilder, classInfo );
listenerparse = new ListenerMocker( indexBuilder, classInfo, getDefaults() );
}
return listenerparse;
}
@ -155,11 +155,8 @@ public abstract class AbstractEntityObjectMocker extends AnnotationMocker {
return null;
}
String className = MockHelper.buildSafeClassName( idClass.getClazz(), getDefaults().getPackageName() );
return create(
ID_CLASS, MockHelper.classValueArray(
"value", className, indexBuilder.getServiceRegistry()
)
);
return create( ID_CLASS, MockHelper.classValueArray( "value", className, getDefaults(),
indexBuilder.getServiceRegistry() ) );
}

View File

@ -44,11 +44,16 @@ import org.jboss.jandex.DotName;
*/
public abstract class AbstractMocker implements JPADotNames {
final protected IndexBuilder indexBuilder;
final private Default defaults;
AbstractMocker(IndexBuilder indexBuilder) {
AbstractMocker(IndexBuilder indexBuilder, Default defaults) {
this.indexBuilder = indexBuilder;
this.defaults = defaults;
}
protected Default getDefaults() {
return defaults;
}
abstract protected AnnotationInstance push(AnnotationInstance annotationInstance);

View File

@ -55,21 +55,15 @@ import org.jboss.jandex.DotName;
* @author Strong Liu
*/
public abstract class AnnotationMocker extends AbstractMocker {
private EntityMappingsMocker.Default defaults;
AnnotationMocker(IndexBuilder indexBuilder, EntityMappingsMocker.Default defaults) {
super( indexBuilder );
this.defaults = defaults;
AnnotationMocker(IndexBuilder indexBuilder, Default defaults) {
super( indexBuilder, defaults );
}
abstract void process();
protected EntityMappingsMocker.Default getDefaults() {
return defaults;
}
protected boolean isDefaultCascadePersist() {
return defaults.isCascadePersist()!=null && defaults.isCascadePersist();
return getDefaults().isCascadePersist() != null && getDefaults().isCascadePersist();
}
//@JoinTable

View File

@ -24,18 +24,25 @@
package org.hibernate.metamodel.source.internal.jandex;
import java.util.List;
import javax.persistence.AccessType;
import org.hibernate.annotations.NaturalIdCache;
import org.hibernate.metamodel.source.internal.jaxb.AttributesContainer;
import org.hibernate.metamodel.source.internal.jaxb.JaxbAny;
import org.hibernate.metamodel.source.internal.jaxb.JaxbAttributes;
import org.hibernate.metamodel.source.internal.jaxb.JaxbBasic;
import org.hibernate.metamodel.source.internal.jaxb.JaxbEmbedded;
import org.hibernate.metamodel.source.internal.jaxb.JaxbEmbeddedId;
import org.hibernate.metamodel.source.internal.jaxb.JaxbId;
import org.hibernate.metamodel.source.internal.jaxb.JaxbManyToOne;
import org.hibernate.metamodel.source.internal.jaxb.JaxbNaturalId;
import org.hibernate.metamodel.source.internal.jaxb.JaxbVersion;
import org.jboss.jandex.ClassInfo;
/**
* @author Strong Liu
* @author Brett Meyer
*/
public class AttributesBuilder extends AbstractAttributesBuilder {
private final JaxbAttributes attributes;
@ -44,11 +51,35 @@ public class AttributesBuilder extends AbstractAttributesBuilder {
IndexBuilder indexBuilder,
ClassInfo classInfo,
AccessType accessType,
EntityMappingsMocker.Default defaults,
Default defaults,
JaxbAttributes attributes) {
super( indexBuilder, classInfo, defaults );
this.attributes = attributes;
}
@Override
protected void parse() {
super.parse();
if ( attributes.getNaturalId() != null ) {
final JaxbNaturalId naturalId = attributes.getNaturalId();
// TODO: This is stupid. Pieces of AbstractAttributesBuilder#parse should be pulled somewhere and
// reused.
for ( JaxbAny any : naturalId.getAny() ) {
// TODO
}
for ( JaxbBasic basic : naturalId.getBasic() ) {
new NaturalIdMocker( indexBuilder, classInfo, defaults, basic, naturalId.isMutable() ).process();
}
for ( JaxbEmbedded embedded : getAttributesContainer().getEmbedded() ) {
new NaturalIdMocker( indexBuilder, classInfo, defaults, embedded, naturalId.isMutable() ).process();
}
for ( JaxbManyToOne manyToOne : getAttributesContainer().getManyToOne() ) {
new NaturalIdMocker( indexBuilder, classInfo, defaults, manyToOne, naturalId.isMutable() ).process();
}
// TODO: @NaturalIdCache?
}
}
@Override
protected AttributesContainer getAttributesContainer() {

View File

@ -38,7 +38,7 @@ import org.jboss.jandex.ClassInfo;
public class BasicMocker extends PropertyMocker {
private final JaxbBasic basic;
BasicMocker(IndexBuilder indexBuilder, ClassInfo classInfo, EntityMappingsMocker.Default defaults, JaxbBasic basic) {
BasicMocker(IndexBuilder indexBuilder, ClassInfo classInfo, Default defaults, JaxbBasic basic) {
super( indexBuilder, classInfo, defaults );
this.basic = basic;
}
@ -49,7 +49,7 @@ public class BasicMocker extends PropertyMocker {
}
@Override
protected void processExtra() {
protected void doProcess() {
List<AnnotationValue> annotationValueList = new ArrayList<AnnotationValue>();
MockHelper.booleanValue( "optional", basic.isOptional(), annotationValueList );
MockHelper.enumValue( "fetch", FETCH_TYPE, basic.getFetch(), annotationValueList );

View File

@ -0,0 +1,106 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* JBoss, Home of Professional Open Source
* Copyright 2014 Red Hat Inc. and/or its affiliates and other contributors
* as indicated by the @authors tag. All rights reserved.
* See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* 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, v. 2.1.
* This program is distributed in the hope that it will be useful, but WITHOUT A
* 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,
* v.2.1 along with this distribution; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*/
package org.hibernate.metamodel.source.internal.jandex;
import java.io.Serializable;
import javax.persistence.AccessType;
public class Default implements Serializable {
private AccessType access;
private String packageName;
private String schema;
private String catalog;
private Boolean metadataComplete;
private Boolean cascadePersist;
public AccessType getAccess() {
return access;
}
public void setAccess(AccessType access) {
this.access = access;
}
public String getCatalog() {
return catalog;
}
public void setCatalog(String catalog) {
this.catalog = catalog;
}
public String getPackageName() {
return packageName;
}
public void setPackageName(String packageName) {
this.packageName = packageName;
}
public String getSchema() {
return schema;
}
public void setSchema(String schema) {
this.schema = schema;
}
public Boolean isMetadataComplete() {
return metadataComplete;
}
public void setMetadataComplete(Boolean metadataComplete) {
this.metadataComplete = metadataComplete;
}
public Boolean isCascadePersist() {
return cascadePersist;
}
public void setCascadePersist(Boolean cascadePersist) {
this.cascadePersist = cascadePersist;
}
void override(Default globalDefault) {
if ( globalDefault != null ) {
if ( globalDefault.getAccess() != null ) {
access = globalDefault.getAccess();
}
if ( globalDefault.getPackageName() != null ) {
packageName = globalDefault.getPackageName();
}
if ( globalDefault.getSchema() != null ) {
schema = globalDefault.getSchema();
}
if ( globalDefault.getCatalog() != null ) {
catalog = globalDefault.getCatalog();
}
if ( globalDefault.isCascadePersist() != null ) {
cascadePersist = globalDefault.isCascadePersist();
}
if ( globalDefault.isMetadataComplete() != null ) {
metadataComplete = globalDefault.isMetadataComplete();
}
}
}
}

View File

@ -77,7 +77,7 @@ public class DefaultConfigurationHelper {
private DefaultConfigurationHelper() {
}
public void applyDefaults(SchemaAware schemaAware, EntityMappingsMocker.Default defaults) {
public void applyDefaults(SchemaAware schemaAware, Default defaults) {
if ( hasSchemaOrCatalogDefined( defaults ) ) {
if ( StringHelper.isEmpty( schemaAware.getSchema() ) ) {
schemaAware.setSchema( defaults.getSchema() );
@ -88,7 +88,7 @@ public class DefaultConfigurationHelper {
}
}
public void applyDefaults(Map<DotName, List<AnnotationInstance>> annotationsMap, EntityMappingsMocker.Default defaults) {
public void applyDefaults(Map<DotName, List<AnnotationInstance>> annotationsMap, Default defaults) {
if ( annotationsMap.isEmpty() || defaults == null ) {
return;
}
@ -100,13 +100,13 @@ public class DefaultConfigurationHelper {
}
}
public void applyDefaults(ManagedType entityElement, EntityMappingsMocker.Default defaults) {
public void applyDefaults(ManagedType entityElement, Default defaults) {
if(JaxbEntity.class.isInstance( entityElement ))
mockTableIfNonExist( JaxbEntity.class.cast( entityElement ), defaults );
applyDefaultsToEntityObject( entityElement , defaults );
}
private void mockTableIfNonExist(JaxbEntity entity, EntityMappingsMocker.Default defaults) {
private void mockTableIfNonExist(JaxbEntity entity, Default defaults) {
if ( hasSchemaOrCatalogDefined( defaults ) ) {
JaxbTable table = entity.getTable();
if ( table == null ) {
@ -116,7 +116,7 @@ public class DefaultConfigurationHelper {
}
}
private void applyDefaultsToEntityObject(ManagedType entityObject, EntityMappingsMocker.Default defaults) {
private void applyDefaultsToEntityObject(ManagedType entityObject, Default defaults) {
if ( defaults == null ) {
return;
}
@ -128,7 +128,7 @@ public class DefaultConfigurationHelper {
LOG.debugf( "Adding XML overriding information for %s", className );
}
private boolean hasSchemaOrCatalogDefined(EntityMappingsMocker.Default defaults) {
private boolean hasSchemaOrCatalogDefined(Default defaults) {
return ( defaults != null ) && ( StringHelper.isNotEmpty( defaults.getSchema() ) || StringHelper.isNotEmpty(
defaults.getCatalog()
) );
@ -142,7 +142,7 @@ public class DefaultConfigurationHelper {
}
}
private void applyDefaultSchemaAndCatalog(Map<DotName, List<AnnotationInstance>> annotationsMap, EntityMappingsMocker.Default defaults) {
private void applyDefaultSchemaAndCatalog(Map<DotName, List<AnnotationInstance>> annotationsMap, Default defaults) {
for ( DotName annName : SCHEMA_AWARE_ANNOTATIONS ) {
mockTableIfNonExist( annotationsMap, annName );
if ( annotationsMap.containsKey( annName ) ) {
@ -216,7 +216,7 @@ public class DefaultConfigurationHelper {
}
//@Table, @CollectionTable, @JoinTable, @SecondaryTable
private void overrideSchemaCatalogByDefault(DotName annName, Map<DotName, List<AnnotationInstance>> indexedAnnotationMap, EntityMappingsMocker.Default defaults) {
private void overrideSchemaCatalogByDefault(DotName annName, Map<DotName, List<AnnotationInstance>> indexedAnnotationMap, Default defaults) {
List<AnnotationInstance> annotationInstanceList = indexedAnnotationMap.get( annName );
if ( annotationInstanceList == null || annotationInstanceList.isEmpty() ) {
return;
@ -250,7 +250,7 @@ public class DefaultConfigurationHelper {
indexedAnnotationMap.put( annName, newAnnotationInstanceList );
}
private AnnotationInstance overrideSchemaCatalogByDefault(AnnotationInstance annotationInstance, EntityMappingsMocker.Default defaults) {
private AnnotationInstance overrideSchemaCatalogByDefault(AnnotationInstance annotationInstance, Default defaults) {
List<AnnotationValue> newAnnotationValueList = new ArrayList<AnnotationValue>();
newAnnotationValueList.addAll( annotationInstance.values() );
boolean schemaDefined = false;

View File

@ -38,7 +38,7 @@ import org.jboss.jandex.ClassInfo;
public class ElementCollectionMocker extends PropertyMocker {
private final JaxbElementCollection elementCollection;
ElementCollectionMocker(IndexBuilder indexBuilder, ClassInfo classInfo, EntityMappingsMocker.Default defaults, JaxbElementCollection elementCollection) {
ElementCollectionMocker(IndexBuilder indexBuilder, ClassInfo classInfo, Default defaults, JaxbElementCollection elementCollection) {
super( indexBuilder, classInfo, defaults );
this.elementCollection = elementCollection;
}
@ -49,12 +49,13 @@ public class ElementCollectionMocker extends PropertyMocker {
}
@Override
protected void processExtra() {
protected void doProcess() {
List<AnnotationValue> annotationValueList = new ArrayList<AnnotationValue>();
MockHelper.classValue(
"targetClass",
elementCollection.getTargetClass(),
annotationValueList,
getDefaults(),
indexBuilder.getServiceRegistry()
);
MockHelper.enumValue( "fetch", FETCH_TYPE, elementCollection.getFetch(), annotationValueList );

View File

@ -45,7 +45,7 @@ public class EmbeddableAttributesBuilder extends AbstractAttributesBuilder {
IndexBuilder indexBuilder,
ClassInfo classInfo,
AccessType accessType,
EntityMappingsMocker.Default defaults,
Default defaults,
JaxbEmbeddableAttributes embeddableAttributes) {
super( indexBuilder, classInfo, defaults );
this.attributes = embeddableAttributes;

View File

@ -44,7 +44,7 @@ import org.hibernate.metamodel.source.internal.jaxb.ManagedType;
public class EmbeddableMocker extends AbstractEntityObjectMocker {
private final JaxbEmbeddable embeddable;
EmbeddableMocker(IndexBuilder indexBuilder, JaxbEmbeddable embeddable, EntityMappingsMocker.Default defaults) {
EmbeddableMocker(IndexBuilder indexBuilder, JaxbEmbeddable embeddable, Default defaults) {
super( indexBuilder, defaults );
this.embeddable = embeddable;
}
@ -65,7 +65,7 @@ public class EmbeddableMocker extends AbstractEntityObjectMocker {
}
@Override
protected void processExtra() {
protected void doProcess() {
create( EMBEDDABLE );
}

View File

@ -34,7 +34,7 @@ import org.jboss.jandex.ClassInfo;
public class EmbeddedIdMocker extends PropertyMocker {
private final JaxbEmbeddedId embeddedId;
EmbeddedIdMocker(IndexBuilder indexBuilder, ClassInfo classInfo, EntityMappingsMocker.Default defaults, JaxbEmbeddedId embeddedId) {
EmbeddedIdMocker(IndexBuilder indexBuilder, ClassInfo classInfo, Default defaults, JaxbEmbeddedId embeddedId) {
super( indexBuilder, classInfo, defaults );
this.embeddedId = embeddedId;
}
@ -45,7 +45,7 @@ public class EmbeddedIdMocker extends PropertyMocker {
}
@Override
protected void processExtra() {
protected void doProcess() {
create( EMBEDDED_ID );
}
}

View File

@ -34,13 +34,13 @@ import org.jboss.jandex.ClassInfo;
public class EmbeddedMocker extends PropertyMocker {
private final JaxbEmbedded embedded;
EmbeddedMocker(IndexBuilder indexBuilder, ClassInfo classInfo, EntityMappingsMocker.Default defaults, JaxbEmbedded embedded) {
EmbeddedMocker(IndexBuilder indexBuilder, ClassInfo classInfo, Default defaults, JaxbEmbedded embedded) {
super( indexBuilder, classInfo, defaults );
this.embedded = embedded;
}
@Override
protected void processExtra() {
protected void doProcess() {
create( EMBEDDED );
parseAttributeOverrides( embedded.getAttributeOverride(), getTarget() );
parseAssociationOverrides( embedded.getAssociationOverride(), getTarget() );

View File

@ -23,13 +23,14 @@
*/
package org.hibernate.metamodel.source.internal.jandex;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.AccessType;
import org.hibernate.internal.CoreLogging;
import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.internal.util.StringHelper;
import org.hibernate.metamodel.source.internal.jaxb.JaxbEmbeddable;
import org.hibernate.metamodel.source.internal.jaxb.JaxbEntity;
import org.hibernate.metamodel.source.internal.jaxb.JaxbEntityMappings;
@ -40,7 +41,6 @@ import org.hibernate.service.ServiceRegistry;
import org.hibernate.xml.spi.BindResult;
import org.hibernate.xml.spi.Origin;
import org.hibernate.xml.spi.SourceType;
import org.jboss.jandex.Index;
import org.jboss.jandex.IndexView;
@ -132,7 +132,7 @@ public class EntityMappingsMocker {
globalDefaults.setCatalog( pud.getCatalog() );
//globalDefaults.setAccess( pud.getAccess() );
globalDefaults.setCascadePersist( pud.getCascadePersist() != null );
new PersistenceMetadataMocker( indexBuilder, pud ).process();
new PersistenceMetadataMocker( indexBuilder, pud, globalDefaults ).process();
}
}
@ -170,9 +170,7 @@ public class EntityMappingsMocker {
private void processGlobalAnnotations() {
if ( globalAnnotations.hasGlobalConfiguration() ) {
indexBuilder.collectGlobalConfigurationFromIndex( globalAnnotations );
new GlobalAnnotationMocker(
indexBuilder, globalAnnotations
).process();
new GlobalAnnotationMocker( indexBuilder, globalAnnotations, globalDefaults ).process();
}
}
@ -181,92 +179,19 @@ public class EntityMappingsMocker {
entityMappingDefault.setPackageName( entityMappings.getPackage() );
entityMappingDefault.setSchema( entityMappings.getSchema() );
entityMappingDefault.setCatalog( entityMappings.getCatalog() );
entityMappingDefault.setAccess( entityMappings.getAccess() );
AccessType accessType = entityMappings.getAccess();
if (accessType == null) {
try {
accessType = AccessType.valueOf( StringHelper.toUpperCase( entityMappings.getAttributeAccessor() ) );
}
catch (Exception e) {
// ignore
}
}
entityMappingDefault.setAccess( accessType );
final Default defaults = new Default();
defaults.override( globalDefaults );
defaults.override( entityMappingDefault );
return defaults;
}
public static class Default implements Serializable {
private AccessType access;
private String packageName;
private String schema;
private String catalog;
private Boolean metadataComplete;
private Boolean cascadePersist;
public AccessType getAccess() {
return access;
}
public void setAccess(AccessType access) {
this.access = access;
}
public String getCatalog() {
return catalog;
}
public void setCatalog(String catalog) {
this.catalog = catalog;
}
public String getPackageName() {
return packageName;
}
public void setPackageName(String packageName) {
this.packageName = packageName;
}
public String getSchema() {
return schema;
}
public void setSchema(String schema) {
this.schema = schema;
}
public Boolean isMetadataComplete() {
return metadataComplete;
}
public void setMetadataComplete(Boolean metadataComplete) {
this.metadataComplete = metadataComplete;
}
public Boolean isCascadePersist() {
return cascadePersist;
}
public void setCascadePersist(Boolean cascadePersist) {
this.cascadePersist = cascadePersist;
}
void override(Default globalDefault) {
if ( globalDefault != null ) {
if ( globalDefault.getAccess() != null ) {
access = globalDefault.getAccess();
}
if ( globalDefault.getPackageName() != null ) {
packageName = globalDefault.getPackageName();
}
if ( globalDefault.getSchema() != null ) {
schema = globalDefault.getSchema();
}
if ( globalDefault.getCatalog() != null ) {
catalog = globalDefault.getCatalog();
}
if ( globalDefault.isCascadePersist() != null ) {
cascadePersist = globalDefault.isCascadePersist();
}
if ( globalDefault.isMetadataComplete() != null ) {
metadataComplete = globalDefault.isMetadataComplete();
}
}
}
}
}

View File

@ -29,19 +29,14 @@ import java.util.Map;
import javax.persistence.AccessType;
import org.hibernate.annotations.CacheModeType;
import org.hibernate.annotations.FlushModeType;
import org.hibernate.internal.util.StringHelper;
import org.hibernate.internal.util.collections.CollectionHelper;
import org.hibernate.metamodel.source.internal.annotations.util.HibernateDotNames;
import org.hibernate.metamodel.source.internal.jaxb.JaxbAttributes;
import org.hibernate.metamodel.source.internal.jaxb.JaxbDiscriminatorColumn;
import org.hibernate.metamodel.source.internal.jaxb.JaxbEntity;
import org.hibernate.metamodel.source.internal.jaxb.JaxbEntityListeners;
import org.hibernate.metamodel.source.internal.jaxb.JaxbIdClass;
import org.hibernate.metamodel.source.internal.jaxb.JaxbInheritance;
import org.hibernate.metamodel.source.internal.jaxb.JaxbNamedNativeQuery;
import org.hibernate.metamodel.source.internal.jaxb.JaxbNamedQuery;
import org.hibernate.metamodel.source.internal.jaxb.JaxbPostLoad;
import org.hibernate.metamodel.source.internal.jaxb.JaxbPostPersist;
import org.hibernate.metamodel.source.internal.jaxb.JaxbPostRemove;
@ -67,13 +62,13 @@ import org.jboss.jandex.DotName;
public class EntityMocker extends AbstractEntityObjectMocker {
private final JaxbEntity entity;
public EntityMocker(IndexBuilder indexBuilder, JaxbEntity entity, EntityMappingsMocker.Default defaults) {
public EntityMocker(IndexBuilder indexBuilder, JaxbEntity entity, Default defaults) {
super( indexBuilder, defaults );
this.entity = entity;
}
@Override
protected void processExtra() {
protected void doProcess() {
//@Entity
create( ENTITY, MockHelper.stringValueArray( "name", entity.getName() ) );
@ -102,11 +97,6 @@ public class EntityMocker extends AbstractEntityObjectMocker {
parseAssociationOverrides( entity.getAssociationOverride(), getTarget() );
parsePrimaryKeyJoinColumnList( entity.getPrimaryKeyJoinColumn(), getTarget() );
parseSecondaryTableList( entity.getSecondaryTable(), getTarget() );
// @NamedQuery
parseNamedQueries( entity.getNamedQuery() );
// @NamedNativeQuery
parseNamedNativeQueries( entity.getNamedNativeQuery() );
}
//@Table (entity only)
@ -297,75 +287,4 @@ public class EntityMocker extends AbstractEntityObjectMocker {
return MockHelper.EMPTY_ANNOTATION_VALUE_ARRAY;
}
private void parseNamedQueries( List<JaxbNamedQuery> namedQueries ) {
if (! namedQueries.isEmpty() ) {
AnnotationValue[] namedQueryAnnotations = new AnnotationValue[namedQueries.size()];
for ( int i = 0; i < namedQueries.size(); i++ ) {
JaxbNamedQuery namedQuery = namedQueries.get( i );
List<AnnotationValue> annotationValueList = new ArrayList<AnnotationValue>();
MockHelper.stringValue( "name", namedQuery.getName(), annotationValueList );
MockHelper.stringValue( "query", namedQuery.getQuery(), annotationValueList );
MockHelper.stringValue( "cacheRegion", namedQuery.getCacheRegion(), annotationValueList );
MockHelper.stringValue( "comment", namedQuery.getComment(), annotationValueList );
MockHelper.booleanValue( "cacheable", namedQuery.isCacheable(), annotationValueList );
MockHelper.booleanValue( "readOnly", namedQuery.isReadOnly(), annotationValueList );
MockHelper.integerValue( "fetchSize", namedQuery.getFetchSize(), annotationValueList );
MockHelper.integerValue( "timeout", namedQuery.getTimeout(), annotationValueList );
MockHelper.enumValue( "cacheMode", HibernateDotNames.CACHE_MODE_TYPE,
MockHelper.convert( namedQuery.getCacheMode() ), annotationValueList );
MockHelper.enumValue( "flushMode", HibernateDotNames.FLUSH_MODE_TYPE,
MockHelper.convert( namedQuery.getFlushMode() ), annotationValueList );
AnnotationInstance annotationInstance = create(
HibernateDotNames.NAMED_QUERY, null, annotationValueList );
namedQueryAnnotations[i] = MockHelper.nestedAnnotationValue( "", annotationInstance );
}
List<AnnotationValue> annotationValueList = new ArrayList<AnnotationValue>();
MockHelper.addToCollectionIfNotNull( annotationValueList,
AnnotationValue.createArrayValue( "value", namedQueryAnnotations ) );
create( HibernateDotNames.NAMED_QUERIES, getTarget(), annotationValueList );
}
}
private void parseNamedNativeQueries( List<JaxbNamedNativeQuery> namedQueries ) {
if (! namedQueries.isEmpty() ) {
AnnotationValue[] namedQueryAnnotations = new AnnotationValue[namedQueries.size()];
for ( int i = 0; i < namedQueries.size(); i++ ) {
JaxbNamedNativeQuery namedQuery = namedQueries.get( i );
List<AnnotationValue> annotationValueList = new ArrayList<AnnotationValue>();
MockHelper.stringValue( "name", namedQuery.getName(), annotationValueList );
MockHelper.stringValue( "query", namedQuery.getQuery(), annotationValueList );
MockHelper.stringValue( "cacheRegion", namedQuery.getCacheRegion(), annotationValueList );
MockHelper.stringValue( "comment", namedQuery.getComment(), annotationValueList );
MockHelper.stringValue( "resultSetMapping", namedQuery.getResultSetMapping(), annotationValueList );
MockHelper.booleanValue( "cacheable", namedQuery.isCacheable(), annotationValueList );
MockHelper.booleanValue( "readOnly", namedQuery.isReadOnly(), annotationValueList );
// TODO: add #callable to the schema?
// MockHelper.booleanValue( "callable", namedQuery.isCallable(), annotationValueList );
MockHelper.integerValue( "fetchSize", namedQuery.getFetchSize(), annotationValueList );
MockHelper.integerValue( "timeout", namedQuery.getTimeout(), annotationValueList );
MockHelper.enumValue( "cacheMode", HibernateDotNames.CACHE_MODE_TYPE,
MockHelper.convert( namedQuery.getCacheMode() ), annotationValueList );
MockHelper.enumValue( "flushMode", HibernateDotNames.FLUSH_MODE_TYPE,
MockHelper.convert( namedQuery.getFlushMode() ), annotationValueList );
MockHelper.classValue( "resultClass", namedQuery.getResultClass(), annotationValueList,
indexBuilder.getServiceRegistry() );
AnnotationInstance annotationInstance = create(
HibernateDotNames.NAMED_NATIVE_QUERY, null, annotationValueList );
namedQueryAnnotations[i] = MockHelper.nestedAnnotationValue( "", annotationInstance );
}
List<AnnotationValue> annotationValueList = new ArrayList<AnnotationValue>();
MockHelper.addToCollectionIfNotNull( annotationValueList,
AnnotationValue.createArrayValue( "value", namedQueryAnnotations ) );
create( HibernateDotNames.NAMED_NATIVE_QUERIES, getTarget(), annotationValueList );
}
}
}

View File

@ -28,6 +28,7 @@ import java.util.Collection;
import java.util.List;
import org.hibernate.internal.util.collections.CollectionHelper;
import org.hibernate.metamodel.source.internal.annotations.util.HibernateDotNames;
import org.hibernate.metamodel.source.internal.jaxb.JaxbNamedNativeQuery;
import org.hibernate.metamodel.source.internal.jaxb.JaxbNamedQuery;
import org.hibernate.metamodel.source.internal.jaxb.JaxbQueryHint;
@ -37,7 +38,6 @@ import org.hibernate.metamodel.source.internal.jaxb.JaxbSqlResultSetMappingColum
import org.hibernate.metamodel.source.internal.jaxb.JaxbSqlResultSetMappingEntityResult;
import org.hibernate.metamodel.source.internal.jaxb.JaxbSqlResultSetMappingFieldResult;
import org.hibernate.metamodel.source.internal.jaxb.JaxbTableGenerator;
import org.jboss.jandex.AnnotationInstance;
import org.jboss.jandex.AnnotationValue;
@ -47,8 +47,8 @@ import org.jboss.jandex.AnnotationValue;
public class GlobalAnnotationMocker extends AbstractMocker {
private GlobalAnnotations globalAnnotations;
GlobalAnnotationMocker(IndexBuilder indexBuilder, GlobalAnnotations globalAnnotations) {
super( indexBuilder );
GlobalAnnotationMocker(IndexBuilder indexBuilder, GlobalAnnotations globalAnnotations, Default defaults) {
super( indexBuilder, defaults );
this.globalAnnotations = globalAnnotations;
}
@ -65,22 +65,10 @@ public class GlobalAnnotationMocker extends AbstractMocker {
}
}
if ( !globalAnnotations.getNamedQueryMap().isEmpty() ) {
Collection<JaxbNamedQuery> namedQueries = globalAnnotations.getNamedQueryMap().values();
if ( namedQueries.size() > 1 ) {
parseNamedQueries( namedQueries );
}
else {
parseNamedQuery( namedQueries.iterator().next() );
}
parseNamedQueries( globalAnnotations.getNamedQueryMap().values() );
}
if ( !globalAnnotations.getNamedNativeQueryMap().isEmpty() ) {
Collection<JaxbNamedNativeQuery> namedQueries = globalAnnotations.getNamedNativeQueryMap().values();
if ( namedQueries.size() > 1 ) {
parseNamedNativeQueries( namedQueries );
}
else {
parseNamedNativeQuery( namedQueries.iterator().next() );
}
parseNamedNativeQueries( globalAnnotations.getNamedNativeQueryMap().values() );
}
if ( !globalAnnotations.getSqlResultSetMappingMap().isEmpty() ) {
parseSqlResultSetMappings( globalAnnotations.getSqlResultSetMappingMap().values() );
@ -123,9 +111,8 @@ public class GlobalAnnotationMocker extends AbstractMocker {
"discriminatorColumn", result.getDiscriminatorColumn(), annotationValueList
);
nestedFieldResultList( "fields", result.getFieldResult(), annotationValueList );
MockHelper.classValue(
"entityClass", result.getEntityClass(), annotationValueList, indexBuilder.getServiceRegistry()
);
MockHelper.classValue( "entityClass", result.getEntityClass(), annotationValueList, getDefaults(),
indexBuilder.getServiceRegistry() );
return
create(
ENTITY_RESULT, null, annotationValueList
@ -192,67 +179,73 @@ public class GlobalAnnotationMocker extends AbstractMocker {
}
}
private AnnotationInstance parseNamedNativeQueries(Collection<JaxbNamedNativeQuery> namedQueries) {
AnnotationValue[] values = new AnnotationValue[namedQueries.size()];
int i = 0;
for ( JaxbNamedNativeQuery namedQuery : namedQueries ) {
AnnotationInstance annotationInstance = parseNamedNativeQuery( namedQuery );
values[i++] = MockHelper.nestedAnnotationValue(
"", annotationInstance
);
private void parseNamedQueries( Collection<JaxbNamedQuery> namedQueries ) {
if (! namedQueries.isEmpty() ) {
AnnotationValue[] namedQueryAnnotations = new AnnotationValue[namedQueries.size()];
int i = 0;
for ( JaxbNamedQuery namedQuery : namedQueries ) {
List<AnnotationValue> annotationValueList = new ArrayList<AnnotationValue>();
MockHelper.stringValue( "name", namedQuery.getName(), annotationValueList );
MockHelper.stringValue( "query", namedQuery.getQuery(), annotationValueList );
MockHelper.stringValue( "cacheRegion", namedQuery.getCacheRegion(), annotationValueList );
MockHelper.stringValue( "comment", namedQuery.getComment(), annotationValueList );
MockHelper.booleanValue( "cacheable", namedQuery.isCacheable(), annotationValueList );
MockHelper.booleanValue( "readOnly", namedQuery.isReadOnly(), annotationValueList );
MockHelper.integerValue( "fetchSize", namedQuery.getFetchSize(), annotationValueList );
MockHelper.integerValue( "timeout", namedQuery.getTimeout(), annotationValueList );
MockHelper.enumValue( "cacheMode", HibernateDotNames.CACHE_MODE_TYPE,
MockHelper.convert( namedQuery.getCacheMode() ), annotationValueList );
MockHelper.enumValue( "flushMode", HibernateDotNames.FLUSH_MODE_TYPE,
MockHelper.convert( namedQuery.getFlushMode() ), annotationValueList );
AnnotationInstance annotationInstance = create(
HibernateDotNames.NAMED_QUERY, null, annotationValueList );
namedQueryAnnotations[i++] = MockHelper.nestedAnnotationValue( "", annotationInstance );
}
List<AnnotationValue> annotationValueList = new ArrayList<AnnotationValue>();
MockHelper.addToCollectionIfNotNull( annotationValueList,
AnnotationValue.createArrayValue( "value", namedQueryAnnotations ) );
create( HibernateDotNames.NAMED_QUERIES, null, annotationValueList );
}
return create(
NAMED_NATIVE_QUERIES, null,
new AnnotationValue[] { AnnotationValue.createArrayValue( "value", values ) }
);
}
//@NamedNativeQuery
private AnnotationInstance parseNamedNativeQuery(JaxbNamedNativeQuery namedNativeQuery) {
List<AnnotationValue> annotationValueList = new ArrayList<AnnotationValue>();
MockHelper.stringValue( "name", namedNativeQuery.getName(), annotationValueList );
MockHelper.stringValue( "query", namedNativeQuery.getQuery(), annotationValueList );
MockHelper.stringValue(
"resultSetMapping", namedNativeQuery.getResultSetMapping(), annotationValueList
);
MockHelper.classValue(
"resultClass", namedNativeQuery.getResultClass(), annotationValueList, indexBuilder.getServiceRegistry()
);
nestedQueryHintList( "hints", namedNativeQuery.getHint(), annotationValueList );
return
create(
NAMED_NATIVE_QUERY, null, annotationValueList
);
}
private AnnotationInstance parseNamedQueries(Collection<JaxbNamedQuery> namedQueries) {
AnnotationValue[] values = new AnnotationValue[namedQueries.size()];
int i = 0;
for ( JaxbNamedQuery namedQuery : namedQueries ) {
AnnotationInstance annotationInstance = parseNamedQuery( namedQuery );
values[i++] = MockHelper.nestedAnnotationValue(
"", annotationInstance
);
private void parseNamedNativeQueries( Collection<JaxbNamedNativeQuery> namedQueries ) {
if (! namedQueries.isEmpty() ) {
AnnotationValue[] namedQueryAnnotations = new AnnotationValue[namedQueries.size()];
int i = 0;
for ( JaxbNamedNativeQuery namedQuery : namedQueries ) {
List<AnnotationValue> annotationValueList = new ArrayList<AnnotationValue>();
MockHelper.stringValue( "name", namedQuery.getName(), annotationValueList );
MockHelper.stringValue( "query", namedQuery.getQuery(), annotationValueList );
MockHelper.stringValue( "cacheRegion", namedQuery.getCacheRegion(), annotationValueList );
MockHelper.stringValue( "comment", namedQuery.getComment(), annotationValueList );
MockHelper.stringValue( "resultSetMapping", namedQuery.getResultSetMapping(), annotationValueList );
MockHelper.booleanValue( "cacheable", namedQuery.isCacheable(), annotationValueList );
MockHelper.booleanValue( "readOnly", namedQuery.isReadOnly(), annotationValueList );
// TODO: add #callable to the schema?
// MockHelper.booleanValue( "callable", namedQuery.isCallable(), annotationValueList );
MockHelper.integerValue( "fetchSize", namedQuery.getFetchSize(), annotationValueList );
MockHelper.integerValue( "timeout", namedQuery.getTimeout(), annotationValueList );
MockHelper.enumValue( "cacheMode", HibernateDotNames.CACHE_MODE_TYPE,
MockHelper.convert( namedQuery.getCacheMode() ), annotationValueList );
MockHelper.enumValue( "flushMode", HibernateDotNames.FLUSH_MODE_TYPE,
MockHelper.convert( namedQuery.getFlushMode() ), annotationValueList );
MockHelper.classValue( "resultClass", namedQuery.getResultClass(), annotationValueList, getDefaults(),
indexBuilder.getServiceRegistry() );
AnnotationInstance annotationInstance = create(
HibernateDotNames.NAMED_NATIVE_QUERY, null, annotationValueList );
namedQueryAnnotations[i++] = MockHelper.nestedAnnotationValue( "", annotationInstance );
}
List<AnnotationValue> annotationValueList = new ArrayList<AnnotationValue>();
MockHelper.addToCollectionIfNotNull( annotationValueList,
AnnotationValue.createArrayValue( "value", namedQueryAnnotations ) );
create( HibernateDotNames.NAMED_NATIVE_QUERIES, null, annotationValueList );
}
return create(
NAMED_QUERIES, null,
new AnnotationValue[] { AnnotationValue.createArrayValue( "value", values ) }
);
}
//@NamedQuery
private AnnotationInstance parseNamedQuery(JaxbNamedQuery namedQuery) {
List<AnnotationValue> annotationValueList = new ArrayList<AnnotationValue>();
MockHelper.stringValue( "name", namedQuery.getName(), annotationValueList );
MockHelper.stringValue( "query", namedQuery.getQuery(), annotationValueList );
MockHelper.enumValue( "lockMode", LOCK_MODE_TYPE, namedQuery.getLockMode(), annotationValueList );
nestedQueryHintList( "hints", namedQuery.getHint(), annotationValueList );
return create( NAMED_QUERY, null, annotationValueList );
}
//@QueryHint

View File

@ -158,7 +158,7 @@ public class GlobalAnnotations implements JPADotNames {
}
}
void collectGlobalMappings(JaxbEntityMappings entityMappings, EntityMappingsMocker.Default defaults) {
void collectGlobalMappings(JaxbEntityMappings entityMappings, Default defaults) {
for ( JaxbSequenceGenerator generator : entityMappings.getSequenceGenerator() ) {
put( generator, defaults );
defaultNamedGenerators.add( generator.getName() );
@ -181,7 +181,7 @@ public class GlobalAnnotations implements JPADotNames {
}
}
void collectGlobalMappings(JaxbEntity entity, EntityMappingsMocker.Default defaults) {
void collectGlobalMappings(JaxbEntity entity, Default defaults) {
for ( JaxbNamedQuery namedQuery : entity.getNamedQuery() ) {
if ( !defaultNamedQueryNames.contains( namedQuery.getName() ) ) {
put( namedQuery );
@ -233,7 +233,7 @@ public class GlobalAnnotations implements JPADotNames {
/**
* Override SequenceGenerator using info definded in EntityMappings/Persistence-Metadata-Unit
*/
private static void overrideGenerator(SchemaAware generator, EntityMappingsMocker.Default defaults) {
private static void overrideGenerator(SchemaAware generator, Default defaults) {
if ( StringHelper.isEmpty( generator.getSchema() ) && defaults != null ) {
generator.setSchema( defaults.getSchema() );
}
@ -260,7 +260,7 @@ public class GlobalAnnotations implements JPADotNames {
}
}
private void put(JaxbSequenceGenerator generator, EntityMappingsMocker.Default defaults) {
private void put(JaxbSequenceGenerator generator, Default defaults) {
if ( generator != null ) {
overrideGenerator( generator, defaults );
Object old = sequenceGeneratorMap.put( generator.getName(), generator );
@ -268,7 +268,7 @@ public class GlobalAnnotations implements JPADotNames {
}
}
private void put(JaxbTableGenerator generator, EntityMappingsMocker.Default defaults) {
private void put(JaxbTableGenerator generator, Default defaults) {
if ( generator != null ) {
overrideGenerator( generator, defaults );
Object old = tableGeneratorMap.put( generator.getName(), generator );

View File

@ -26,11 +26,11 @@ package org.hibernate.metamodel.source.internal.jandex;
import java.util.ArrayList;
import java.util.List;
import org.hibernate.annotations.common.util.StringHelper;
import org.hibernate.metamodel.source.internal.annotations.util.HibernateDotNames;
import org.hibernate.metamodel.source.internal.jaxb.JaxbGeneratedValue;
import org.hibernate.metamodel.source.internal.jaxb.JaxbId;
import org.hibernate.metamodel.source.internal.jaxb.PersistentAttribute;
import org.jboss.jandex.AnnotationInstance;
import org.jboss.jandex.AnnotationTarget;
import org.jboss.jandex.AnnotationValue;
import org.jboss.jandex.ClassInfo;
@ -41,7 +41,7 @@ import org.jboss.jandex.ClassInfo;
public class IdMocker extends PropertyMocker {
private final JaxbId id;
IdMocker(IndexBuilder indexBuilder, ClassInfo classInfo, EntityMappingsMocker.Default defaults, JaxbId id) {
IdMocker(IndexBuilder indexBuilder, ClassInfo classInfo, Default defaults, JaxbId id) {
super( indexBuilder, classInfo, defaults );
this.id = id;
}
@ -52,23 +52,31 @@ public class IdMocker extends PropertyMocker {
}
@Override
protected void processExtra() {
protected void doProcess() {
create( ID );
parseColumn( id.getColumn(), getTarget() );
parseGeneratedValue( id.getGeneratedValue(), getTarget() );
parseTemporalType( id.getTemporal(), getTarget() );
}
private AnnotationInstance parseGeneratedValue(JaxbGeneratedValue generatedValue, AnnotationTarget target) {
private void parseGeneratedValue(JaxbGeneratedValue generatedValue, AnnotationTarget target) {
if ( generatedValue == null ) {
return null;
return;
}
// @GeneratedValue(generator = "...")
List<AnnotationValue> annotationValueList = new ArrayList<AnnotationValue>();
MockHelper.enumValue( "strategy", GENERATION_TYPE, generatedValue.getStrategy(), annotationValueList );
MockHelper.stringValue( "generator", generatedValue.getGenerator(), annotationValueList );
MockHelper.enumValue(
"strategy", GENERATION_TYPE, generatedValue.getStrategy(), annotationValueList
);
return create( GENERATED_VALUE, target, annotationValueList );
create( GENERATED_VALUE, target, annotationValueList );
// TODO: Assumes all generators are generic. How to check to see if it's custom?
if (! StringHelper.isEmpty( generatedValue.getGenerator() )) {
// @GenericGenerator(name = "...", strategy = "...")
annotationValueList = new ArrayList<AnnotationValue>();
MockHelper.stringValue( "name", generatedValue.getGenerator(), annotationValueList );
MockHelper.stringValue( "strategy", generatedValue.getGenerator(), annotationValueList );
create( HibernateDotNames.GENERIC_GENERATOR, target, annotationValueList );
}
}
}

View File

@ -81,7 +81,7 @@ public class IndexBuilder {
*
* @return Index.
*/
public Index build(EntityMappingsMocker.Default globalDefaults) {
public Index build(Default globalDefaults) {
//merge annotations that not overrided by xml into the new Index
for ( ClassInfo ci : index.getKnownClasses() ) {
DotName name = ci.name();
@ -183,7 +183,7 @@ public class IndexBuilder {
annotations.putAll( globalAnnotations.getAnnotationInstanceMap() );
}
void finishEntityObject(final DotName name, final EntityMappingsMocker.Default defaults) {
void finishEntityObject(final DotName name, final Default defaults) {
Map<DotName, List<AnnotationInstance>> map = classInfoAnnotationsMap.get( name );
if ( map == null ) {
throw new AssertionFailure( "Calling finish entity object " + name + " before create it." );

View File

@ -31,7 +31,6 @@ import org.hibernate.internal.util.StringHelper;
import org.hibernate.metamodel.source.internal.jaxb.JaxbEntityListener;
import org.hibernate.metamodel.source.internal.jaxb.JaxbEntityListeners;
import org.hibernate.metamodel.source.internal.jaxb.LifecycleCallback;
import org.jboss.jandex.AnnotationInstance;
import org.jboss.jandex.AnnotationTarget;
import org.jboss.jandex.AnnotationValue;
@ -46,8 +45,8 @@ import org.jboss.jandex.DotName;
public class ListenerMocker extends AbstractMocker {
private final ClassInfo classInfo;
ListenerMocker(IndexBuilder indexBuilder, ClassInfo classInfo) {
super( indexBuilder );
ListenerMocker(IndexBuilder indexBuilder, ClassInfo classInfo, Default defaults) {
super( indexBuilder, defaults );
this.classInfo = classInfo;
}
@ -61,7 +60,8 @@ public class ListenerMocker extends AbstractMocker {
MockHelper.addToCollectionIfNotNull( clazzNameList, listener.getClazz() );
parseEntityListener( listener, clazzNameList );
}
MockHelper.classArrayValue( "value", clazzNameList, annotationValueList, indexBuilder.getServiceRegistry() );
MockHelper.classArrayValue( "value", clazzNameList, annotationValueList, getDefaults(),
indexBuilder.getServiceRegistry() );
return create( ENTITY_LISTENERS, classInfo, annotationValueList );
}
@ -85,7 +85,7 @@ public class ListenerMocker extends AbstractMocker {
}
protected ListenerMocker createListenerMocker(IndexBuilder indexBuilder, ClassInfo classInfo) {
return new ListenerMocker( indexBuilder, classInfo );
return new ListenerMocker( indexBuilder, classInfo, getDefaults() );
}
AnnotationInstance parse(LifecycleCallback callback, DotName target) {
if ( callback == null ) {

View File

@ -38,7 +38,7 @@ import org.jboss.jandex.ClassInfo;
public class ManyToManyMocker extends PropertyMocker {
private final JaxbManyToMany manyToMany;
ManyToManyMocker(IndexBuilder indexBuilder, ClassInfo classInfo, EntityMappingsMocker.Default defaults, JaxbManyToMany manyToMany) {
ManyToManyMocker(IndexBuilder indexBuilder, ClassInfo classInfo, Default defaults, JaxbManyToMany manyToMany) {
super( indexBuilder, classInfo, defaults );
this.manyToMany = manyToMany;
}
@ -49,11 +49,10 @@ public class ManyToManyMocker extends PropertyMocker {
}
@Override
protected void processExtra() {
protected void doProcess() {
List<AnnotationValue> annotationValueList = new ArrayList<AnnotationValue>();
MockHelper.classValue(
"targetEntity", manyToMany.getTargetEntity(), annotationValueList, indexBuilder.getServiceRegistry()
);
MockHelper.classValue( "targetEntity", manyToMany.getTargetEntity(), annotationValueList, getDefaults(),
indexBuilder.getServiceRegistry() );
MockHelper.enumValue( "fetch", FETCH_TYPE, manyToMany.getFetch(), annotationValueList );
MockHelper.stringValue( "mappedBy", manyToMany.getMappedBy(), annotationValueList );
MockHelper.cascadeValue( "cascade", manyToMany.getCascade(), isDefaultCascadePersist(), annotationValueList );

View File

@ -38,7 +38,7 @@ import org.jboss.jandex.ClassInfo;
public class ManyToOneMocker extends PropertyMocker {
private final JaxbManyToOne manyToOne;
ManyToOneMocker(IndexBuilder indexBuilder, ClassInfo classInfo, EntityMappingsMocker.Default defaults, JaxbManyToOne manyToOne) {
ManyToOneMocker(IndexBuilder indexBuilder, ClassInfo classInfo, Default defaults, JaxbManyToOne manyToOne) {
super( indexBuilder, classInfo, defaults );
this.manyToOne = manyToOne;
}
@ -49,11 +49,10 @@ public class ManyToOneMocker extends PropertyMocker {
}
@Override
protected void processExtra() {
protected void doProcess() {
List<AnnotationValue> annotationValueList = new ArrayList<AnnotationValue>();
MockHelper.classValue(
"targetEntity", manyToOne.getTargetEntity(), annotationValueList, indexBuilder.getServiceRegistry()
);
MockHelper.classValue( "targetEntity", manyToOne.getTargetEntity(), annotationValueList, getDefaults(),
indexBuilder.getServiceRegistry() );
MockHelper.enumValue( "fetch", FETCH_TYPE, manyToOne.getFetch(), annotationValueList );
MockHelper.booleanValue( "optional", manyToOne.isOptional(), annotationValueList );
MockHelper.cascadeValue( "cascade", manyToOne.getCascade(), isDefaultCascadePersist(), annotationValueList );

View File

@ -44,7 +44,7 @@ import org.hibernate.metamodel.source.internal.jaxb.ManagedType;
public class MappedSuperclassMocker extends AbstractEntityObjectMocker {
private JaxbMappedSuperclass mappedSuperclass;
MappedSuperclassMocker(IndexBuilder indexBuilder, JaxbMappedSuperclass mappedSuperclass, EntityMappingsMocker.Default defaults) {
MappedSuperclassMocker(IndexBuilder indexBuilder, JaxbMappedSuperclass mappedSuperclass, Default defaults) {
super( indexBuilder, defaults );
this.mappedSuperclass = mappedSuperclass;
}
@ -55,7 +55,7 @@ public class MappedSuperclassMocker extends AbstractEntityObjectMocker {
}
@Override
protected void processExtra() {
protected void doProcess() {
create( MAPPED_SUPERCLASS );
}

View File

@ -126,20 +126,25 @@ public class MockHelper {
return AnnotationValue.createBooleanValue( name, value );
}
private static AnnotationValue classValue(String name, String className, ServiceRegistry serviceRegistry) {
private static AnnotationValue classValue(String name, String className, Default defaults,
ServiceRegistry serviceRegistry) {
if ( StringHelper.isNotEmpty( className ) ) {
className = buildSafeClassName( className, defaults.getPackageName() );
return AnnotationValue.createClassValue( name, getType( className, serviceRegistry ) );
}
return null;
}
static void classValue(String name, String className, List<AnnotationValue> list, ServiceRegistry serviceRegistry) {
addToCollectionIfNotNull( list, classValue( name, className, serviceRegistry ) );
static void classValue(String name, String className, List<AnnotationValue> list, Default defaults,
ServiceRegistry serviceRegistry) {
addToCollectionIfNotNull( list, classValue( name, className, defaults, serviceRegistry ) );
}
static AnnotationValue[] classValueArray(String name, String className, ServiceRegistry serviceRegistry) {
return nullSafe( classValue( name, className, serviceRegistry ) );
static AnnotationValue[] classValueArray(String name, String className, Default defaults,
ServiceRegistry serviceRegistry) {
return nullSafe( classValue( name, className, defaults, serviceRegistry ) );
}
static AnnotationValue nestedAnnotationValue(String name, AnnotationInstance value) {
@ -159,12 +164,13 @@ public class MockHelper {
return value == null ? EMPTY_ANNOTATION_VALUE_ARRAY : new AnnotationValue[] {value};
}
static void classArrayValue(String name, List<String> classNameList, List<AnnotationValue> list, ServiceRegistry serviceRegistry) {
static void classArrayValue(String name, List<String> classNameList, List<AnnotationValue> list, Default defaults,
ServiceRegistry serviceRegistry) {
if ( CollectionHelper.isNotEmpty( classNameList ) ) {
List<AnnotationValue> clazzValueList = new ArrayList<AnnotationValue>( classNameList.size() );
for ( String clazz : classNameList ) {
addToCollectionIfNotNull( clazzValueList, classValue( "", clazz, serviceRegistry ) );
addToCollectionIfNotNull( clazzValueList, classValue( "", clazz, defaults, serviceRegistry ) );
}
list.add(
@ -277,7 +283,7 @@ public class MockHelper {
}
static String buildSafeClassName(String className, String defaultPackageName) {
if ( className!= null && className.indexOf( '.' ) < 0 && StringHelper.isNotEmpty( defaultPackageName ) ) {
if ( StringHelper.isNotEmpty( className ) && className.indexOf( '.' ) < 0 && StringHelper.isNotEmpty( defaultPackageName ) ) {
className = StringHelper.qualify( defaultPackageName, className );
}
return className;

View File

@ -0,0 +1,59 @@
/*
* 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.internal.jandex;
import java.util.ArrayList;
import java.util.List;
import org.hibernate.metamodel.source.internal.annotations.util.HibernateDotNames;
import org.hibernate.metamodel.source.internal.jaxb.PersistentAttribute;
import org.jboss.jandex.AnnotationValue;
import org.jboss.jandex.ClassInfo;
/**
* @author Brett Meyer
*/
public class NaturalIdMocker extends PropertyMocker {
private final PersistentAttribute attribute;
private final boolean mutable;
NaturalIdMocker(IndexBuilder indexBuilder, ClassInfo classInfo, Default defaults,
PersistentAttribute attribute, boolean mutable) {
super( indexBuilder, classInfo, defaults );
this.attribute = attribute;
this.mutable = mutable;
}
@Override
protected void doProcess() {
List<AnnotationValue> annotationValueList = new ArrayList<AnnotationValue>();
MockHelper.booleanValue( "mutable", mutable, annotationValueList );
create( HibernateDotNames.NATURAL_ID, annotationValueList );
}
@Override
protected PersistentAttribute getPersistentAttribute() {
return attribute;
}
}

View File

@ -38,7 +38,7 @@ import org.jboss.jandex.ClassInfo;
public class OneToManyMocker extends PropertyMocker {
private final JaxbOneToMany oneToMany;
OneToManyMocker(IndexBuilder indexBuilder, ClassInfo classInfo, EntityMappingsMocker.Default defaults, JaxbOneToMany oneToMany) {
OneToManyMocker(IndexBuilder indexBuilder, ClassInfo classInfo, Default defaults, JaxbOneToMany oneToMany) {
super( indexBuilder, classInfo, defaults );
this.oneToMany = oneToMany;
}
@ -49,11 +49,10 @@ public class OneToManyMocker extends PropertyMocker {
}
@Override
protected void processExtra() {
protected void doProcess() {
List<AnnotationValue> annotationValueList = new ArrayList<AnnotationValue>();
MockHelper.classValue(
"targetEntity", MockHelper.buildSafeClassName( oneToMany.getTargetEntity(), getDefaults().getPackageName() ), annotationValueList, indexBuilder.getServiceRegistry()
);
MockHelper.classValue( "targetEntity", oneToMany.getTargetEntity(), annotationValueList, getDefaults(),
indexBuilder.getServiceRegistry() );
MockHelper.enumValue( "fetch", FETCH_TYPE, oneToMany.getFetch(), annotationValueList );
MockHelper.stringValue( "mappedBy", oneToMany.getMappedBy(), annotationValueList );
MockHelper.booleanValue( "orphanRemoval", oneToMany.isOrphanRemoval(), annotationValueList );

View File

@ -39,7 +39,7 @@ import org.jboss.jandex.ClassInfo;
public class OneToOneMocker extends PropertyMocker {
private JaxbOneToOne oneToOne;
OneToOneMocker(IndexBuilder indexBuilder, ClassInfo classInfo, EntityMappingsMocker.Default defaults, JaxbOneToOne oneToOne) {
OneToOneMocker(IndexBuilder indexBuilder, ClassInfo classInfo, Default defaults, JaxbOneToOne oneToOne) {
super( indexBuilder, classInfo, defaults );
this.oneToOne = oneToOne;
}
@ -50,14 +50,11 @@ public class OneToOneMocker extends PropertyMocker {
}
@Override
protected void processExtra() {
protected void doProcess() {
List<AnnotationValue> annotationValueList = new ArrayList<AnnotationValue>();
MockHelper.classValue(
"targetEntity",
MockHelper.classValue( "targetEntity",
StringHelper.qualifyIfNot( getDefaults().getPackageName(), oneToOne.getTargetEntity() ),
annotationValueList,
indexBuilder.getServiceRegistry()
);
annotationValueList, getDefaults(), indexBuilder.getServiceRegistry() );
MockHelper.enumValue( "fetch", FETCH_TYPE, oneToOne.getFetch(), annotationValueList );
MockHelper.booleanValue( "optional", oneToOne.isOptional(), annotationValueList );
MockHelper.booleanValue( "orphanRemoval", oneToOne.isOrphanRemoval(), annotationValueList );

View File

@ -38,8 +38,9 @@ public class PersistenceMetadataMocker extends AbstractMocker {
);
}
PersistenceMetadataMocker(IndexBuilder indexBuilder, JaxbPersistenceUnitDefaults persistenceUnitDefaults) {
super( indexBuilder );
PersistenceMetadataMocker(IndexBuilder indexBuilder, JaxbPersistenceUnitDefaults persistenceUnitDefaults,
Default defaults) {
super( indexBuilder, defaults );
this.persistenceUnitDefaults = persistenceUnitDefaults;
}
@ -54,7 +55,7 @@ public class PersistenceMetadataMocker extends AbstractMocker {
}
if ( persistenceUnitDefaults.getEntityListeners() != null ) {
new DefaultListenerMocker( indexBuilder, null ).parse( persistenceUnitDefaults.getEntityListeners() );
new DefaultListenerMocker( indexBuilder, null, getDefaults() ).parse( persistenceUnitDefaults.getEntityListeners() );
}
indexBuilder.finishGlobalConfigurationMocking( globalAnnotations );
}
@ -78,8 +79,8 @@ public class PersistenceMetadataMocker extends AbstractMocker {
}
private class DefaultListenerMocker extends ListenerMocker {
DefaultListenerMocker(IndexBuilder indexBuilder, ClassInfo classInfo) {
super( indexBuilder, classInfo );
DefaultListenerMocker(IndexBuilder indexBuilder, ClassInfo classInfo, Default defaults) {
super( indexBuilder, classInfo, defaults );
}
@Override
@ -94,7 +95,7 @@ public class PersistenceMetadataMocker extends AbstractMocker {
@Override
protected ListenerMocker createListenerMocker(IndexBuilder indexBuilder, ClassInfo classInfo) {
return new DefaultListenerMocker( indexBuilder, classInfo );
return new DefaultListenerMocker( indexBuilder, classInfo, getDefaults() );
}
}
}

View File

@ -25,6 +25,7 @@ package org.hibernate.metamodel.source.internal.jandex;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.AccessType;
import javax.persistence.EnumType;
import javax.persistence.TemporalType;
@ -36,7 +37,6 @@ import org.hibernate.metamodel.source.internal.jaxb.JaxbMapKeyClass;
import org.hibernate.metamodel.source.internal.jaxb.JaxbMapKeyColumn;
import org.hibernate.metamodel.source.internal.jaxb.JaxbMapKeyJoinColumn;
import org.hibernate.metamodel.source.internal.jaxb.PersistentAttribute;
import org.jboss.jandex.AnnotationInstance;
import org.jboss.jandex.AnnotationTarget;
import org.jboss.jandex.AnnotationValue;
@ -50,13 +50,13 @@ public abstract class PropertyMocker extends AnnotationMocker {
protected ClassInfo classInfo;
private AnnotationTarget target;
PropertyMocker(IndexBuilder indexBuilder, ClassInfo classInfo, EntityMappingsMocker.Default defaults) {
PropertyMocker(IndexBuilder indexBuilder, ClassInfo classInfo, Default defaults) {
super( indexBuilder, defaults );
this.classInfo = classInfo;
}
protected abstract PersistentAttribute getPersistentAttribute();
protected abstract void processExtra();
protected abstract void doProcess();
@Override
protected DotName getTargetName() {
@ -97,6 +97,7 @@ public abstract class PropertyMocker extends AnnotationMocker {
}
else {
// attribute in orm.xml did define access
getPersistentAttribute().setAccess( xmlDefinedAccessType );
List<AnnotationValue> accessTypeValueList = new ArrayList<AnnotationValue>();
MockHelper.enumValue( "value", ACCESS_TYPE, xmlDefinedAccessType, accessTypeValueList );
create( ACCESS, accessTypeValueList );
@ -139,7 +140,7 @@ public abstract class PropertyMocker extends AnnotationMocker {
@Override
final void process() {
resolveTarget();
processExtra();
doProcess();
}
protected AnnotationInstance parseMapKeyColumn(JaxbMapKeyColumn mapKeyColumn, AnnotationTarget target) {
@ -164,11 +165,8 @@ public abstract class PropertyMocker extends AnnotationMocker {
if ( mapKeyClass == null ) {
return null;
}
return create(
MAP_KEY_CLASS, target, MockHelper.classValueArray(
"value", mapKeyClass.getClazz(), indexBuilder.getServiceRegistry()
)
);
return create( MAP_KEY_CLASS, target, MockHelper.classValueArray( "value", mapKeyClass.getClazz(),
getDefaults(), indexBuilder.getServiceRegistry() ) );
}
protected AnnotationInstance parseMapKeyTemporal(TemporalType temporalType, AnnotationTarget target) {

View File

@ -37,7 +37,7 @@ public class TransientMocker extends PropertyMocker {
private final JaxbTransient transientObj;
private final PersistentAttribute wrapper;
TransientMocker(IndexBuilder indexBuilder, ClassInfo classInfo, EntityMappingsMocker.Default defaults, final JaxbTransient transientObj) {
TransientMocker(IndexBuilder indexBuilder, ClassInfo classInfo, Default defaults, final JaxbTransient transientObj) {
super( indexBuilder, classInfo, defaults );
this.transientObj = transientObj;
this.wrapper = new PersistentAttribute() {
@ -56,19 +56,19 @@ public class TransientMocker extends PropertyMocker {
}
@Override
public String getCustomAccess() {
public String getAttributeAccessor() {
return null;
}
@Override
public void setCustomAccess(String customAccess) {
public void setAttributeAccessor(String customAccess) {
}
};
}
@Override
protected void processExtra() {
protected void doProcess() {
create( TRANSIENT );
}

View File

@ -34,7 +34,7 @@ import org.jboss.jandex.ClassInfo;
public class VersionMocker extends PropertyMocker {
private final JaxbVersion version;
VersionMocker(IndexBuilder indexBuilder, ClassInfo classInfo, EntityMappingsMocker.Default defaults, JaxbVersion version) {
VersionMocker(IndexBuilder indexBuilder, ClassInfo classInfo, Default defaults, JaxbVersion version) {
super( indexBuilder, classInfo, defaults );
this.version = version;
}
@ -45,7 +45,7 @@ public class VersionMocker extends PropertyMocker {
}
@Override
protected void processExtra() {
protected void doProcess() {
create( VERSION );
parseColumn( version.getColumn(), getTarget() );
parseTemporalType( version.getTemporal(), getTarget() );

View File

@ -37,6 +37,6 @@ public interface PersistentAttribute {
AccessType getAccess();
void setAccess(AccessType accessType);
String getCustomAccess();
void setCustomAccess(String customAccess);
String getAttributeAccessor();
void setAttributeAccessor(String customAccess);
}

View File

@ -26,13 +26,53 @@ package org.hibernate.metamodel.source.internal.jaxb.hbm;
import java.util.Date;
import javax.persistence.FetchType;
import javax.xml.bind.JAXBElement;
import org.hibernate.FlushMode;
import org.hibernate.internal.util.StringHelper;
import org.hibernate.metamodel.source.internal.jaxb.*;
import org.hibernate.metamodel.source.internal.jandex.MockHelper;
import org.hibernate.metamodel.source.internal.jaxb.JaxbAny;
import org.hibernate.metamodel.source.internal.jaxb.JaxbAttributes;
import org.hibernate.metamodel.source.internal.jaxb.JaxbBasic;
import org.hibernate.metamodel.source.internal.jaxb.JaxbCacheElement;
import org.hibernate.metamodel.source.internal.jaxb.JaxbCacheModeType;
import org.hibernate.metamodel.source.internal.jaxb.JaxbCascadeType;
import org.hibernate.metamodel.source.internal.jaxb.JaxbColumn;
import org.hibernate.metamodel.source.internal.jaxb.JaxbDiscriminatorColumn;
import org.hibernate.metamodel.source.internal.jaxb.JaxbEmbeddable;
import org.hibernate.metamodel.source.internal.jaxb.JaxbEmbeddableAttributes;
import org.hibernate.metamodel.source.internal.jaxb.JaxbEmbedded;
import org.hibernate.metamodel.source.internal.jaxb.JaxbEmbeddedId;
import org.hibernate.metamodel.source.internal.jaxb.JaxbEmptyType;
import org.hibernate.metamodel.source.internal.jaxb.JaxbEntity;
import org.hibernate.metamodel.source.internal.jaxb.JaxbEntityMappings;
import org.hibernate.metamodel.source.internal.jaxb.JaxbForeignKey;
import org.hibernate.metamodel.source.internal.jaxb.JaxbGeneratedValue;
import org.hibernate.metamodel.source.internal.jaxb.JaxbHbmCustomSql;
import org.hibernate.metamodel.source.internal.jaxb.JaxbHbmCustomSqlCheckEnum;
import org.hibernate.metamodel.source.internal.jaxb.JaxbHbmFetchProfile;
import org.hibernate.metamodel.source.internal.jaxb.JaxbHbmFilterDef;
import org.hibernate.metamodel.source.internal.jaxb.JaxbHbmIdGeneratorDef;
import org.hibernate.metamodel.source.internal.jaxb.JaxbHbmLoader;
import org.hibernate.metamodel.source.internal.jaxb.JaxbHbmMultiTenancy;
import org.hibernate.metamodel.source.internal.jaxb.JaxbHbmParam;
import org.hibernate.metamodel.source.internal.jaxb.JaxbHbmToolingHint;
import org.hibernate.metamodel.source.internal.jaxb.JaxbHbmType;
import org.hibernate.metamodel.source.internal.jaxb.JaxbHbmTypeDef;
import org.hibernate.metamodel.source.internal.jaxb.JaxbId;
import org.hibernate.metamodel.source.internal.jaxb.JaxbIdClass;
import org.hibernate.metamodel.source.internal.jaxb.JaxbJoinColumn;
import org.hibernate.metamodel.source.internal.jaxb.JaxbJoinTable;
import org.hibernate.metamodel.source.internal.jaxb.JaxbManyToOne;
import org.hibernate.metamodel.source.internal.jaxb.JaxbNamedNativeQuery;
import org.hibernate.metamodel.source.internal.jaxb.JaxbNamedQuery;
import org.hibernate.metamodel.source.internal.jaxb.JaxbNaturalId;
import org.hibernate.metamodel.source.internal.jaxb.JaxbOneToOne;
import org.hibernate.metamodel.source.internal.jaxb.JaxbPersistenceUnitMetadata;
import org.hibernate.metamodel.source.internal.jaxb.JaxbQueryParamType;
import org.hibernate.metamodel.source.internal.jaxb.JaxbSynchronizeType;
import org.hibernate.metamodel.source.internal.jaxb.JaxbTable;
import org.hibernate.xml.spi.Origin;
import org.jboss.logging.Logger;
/**
@ -73,7 +113,7 @@ public class HbmXmlTransformer {
ormRoot.setPackage( hbmXmlMapping.getPackage() );
ormRoot.setSchema( hbmXmlMapping.getSchema() );
ormRoot.setCatalog( hbmXmlMapping.getCatalog() );
ormRoot.setCustomAccess( hbmXmlMapping.getDefaultAccess() );
ormRoot.setAttributeAccessor( hbmXmlMapping.getDefaultAccess() );
ormRoot.setDefaultCascade( hbmXmlMapping.getDefaultCascade() );
ormRoot.setAutoImport( hbmXmlMapping.isAutoImport() );
ormRoot.setDefaultLazy( hbmXmlMapping.isDefaultLazy() );
@ -148,7 +188,7 @@ public class HbmXmlTransformer {
filterDef.setCondition( (String) content );
}
else {
JaxbFilterParamElement hbmFilterParam = (JaxbFilterParamElement) content;
JaxbFilterParamElement hbmFilterParam = ( (JAXBElement<JaxbFilterParamElement>) content ).getValue();
JaxbHbmFilterDef.JaxbFilterParam param = new JaxbHbmFilterDef.JaxbFilterParam();
filterDef.getFilterParam().add( param );
param.setName( hbmFilterParam.getParameterName() );
@ -501,14 +541,14 @@ public class HbmXmlTransformer {
JaxbColumn column,
JaxbColumnElement hbmColumn,
String tableName,
boolean insertable,
boolean updateable) {
Boolean insertable,
Boolean updateable) {
column.setTable( tableName );
column.setName( hbmColumn.getName() );
column.setComment( hbmColumn.getComment() );
column.setCheck( hbmColumn.getCheck() );
column.setDefault( hbmColumn.getDefault() );
column.setNullable( !hbmColumn.isNotNull() );
column.setNullable( hbmColumn.isNotNull() == null ? null : !hbmColumn.isNotNull() );
column.setColumnDefinition( hbmColumn.getSqlType() );
column.setInsertable( insertable );
column.setUpdatable( updateable );
@ -526,15 +566,17 @@ public class HbmXmlTransformer {
}
if ( StringHelper.isNotEmpty( hbmClass.getDiscriminator().getColumnAttribute() ) ) {
entity.setDiscriminatorColumn( new JaxbDiscriminatorColumn() );
entity.getDiscriminatorColumn().setName( hbmClass.getDiscriminator().getColumnAttribute() );
}
else if ( StringHelper.isEmpty( hbmClass.getDiscriminator().getFormulaAttribute() ) ) {
entity.setDiscriminatorFormula( hbmClass.getDiscriminator().getFormulaAttribute() );
}
else if ( StringHelper.isEmpty( hbmClass.getDiscriminator().getFormula().trim() ) ) {
else if ( StringHelper.isEmpty( hbmClass.getDiscriminator().getFormula() ) ) {
entity.setDiscriminatorFormula( hbmClass.getDiscriminator().getFormulaAttribute().trim() );
}
else {
entity.setDiscriminatorColumn( new JaxbDiscriminatorColumn() );
entity.getDiscriminatorColumn().setName( hbmClass.getDiscriminator().getColumn().getName() );
entity.getDiscriminatorColumn().setColumnDefinition( hbmClass.getDiscriminator().getColumn().getSqlType() );
entity.getDiscriminatorColumn().setLength( hbmClass.getDiscriminator().getColumn().getLength() );
@ -555,6 +597,7 @@ public class HbmXmlTransformer {
transferManyToAnyAttributes( entity, hbmClass );
transferPrimitiveArrayAttributes( entity, hbmClass );
transferPropertiesGrouping( entity, hbmClass );
transferNaturalIdentifiers( entity, hbmClass );
}
private void transferIdentifier(JaxbEntity entity, JaxbClassElement hbmClass) {
@ -563,8 +606,16 @@ public class HbmXmlTransformer {
// simple id
final JaxbId id = new JaxbId();
id.setName( hbmId.getName() );
id.setCustomAccess( hbmId.getAccess() );
id.setAttributeAccessor( hbmId.getAccess() );
if (hbmId.getGenerator() != null) {
final JaxbGeneratedValue generator = new JaxbGeneratedValue();
generator.setGenerator( hbmId.getGenerator().getClazz() );
id.setGeneratedValue( generator );
}
if ( StringHelper.isNotEmpty( hbmId.getTypeAttribute() ) ) {
id.setType( new JaxbHbmType() );
id.getType().setName( hbmId.getTypeAttribute() );
}
else {
@ -583,11 +634,13 @@ public class HbmXmlTransformer {
}
id.setUnsavedValue( hbmId.getUnsavedValue() );
if ( StringHelper.isNotEmpty( hbmId.getColumnAttribute() ) ) {
id.setColumn( new JaxbColumn() );
id.getColumn().setName( hbmId.getColumnAttribute() );
}
else {
if ( hbmId.column != null ) {
assert hbmId.column.size() == 1;
id.setColumn( new JaxbColumn() );
transferColumn( id.getColumn(), hbmId.getColumn().get( 0 ), null, true, false );
}
}
@ -616,17 +669,19 @@ public class HbmXmlTransformer {
}
if ( isAggregate ) {
entity.getAttributes().setEmbeddedId( new JaxbEmbeddedId() );
entity.getAttributes().getEmbeddedId().setName( hbmCompositeId.getName() );
entity.getAttributes().getEmbeddedId().setCustomAccess( hbmCompositeId.getAccess() );
entity.getAttributes().getEmbeddedId().setAttributeAccessor( hbmCompositeId.getAccess() );
final JaxbEmbeddable embeddable = new JaxbEmbeddable();
embeddable.setClazz( hbmCompositeId.getClazz() );
embeddable.setAttributes( new JaxbEmbeddableAttributes() );
for ( Object hbmCompositeAttribute : hbmCompositeId.getKeyPropertyOrKeyManyToOne() ) {
if ( JaxbKeyPropertyElement.class.isInstance( hbmCompositeAttribute ) ) {
final JaxbKeyPropertyElement keyProp = (JaxbKeyPropertyElement) hbmCompositeAttribute;
final JaxbBasic basic = new JaxbBasic();
basic.setName( keyProp.getName() );
basic.setCustomAccess( keyProp.getAccess() );
basic.setAttributeAccessor( keyProp.getAccess() );
if ( StringHelper.isNotEmpty( keyProp.getColumnAttribute() ) ) {
final JaxbColumn column = new JaxbColumn();
column.setName( keyProp.getColumnAttribute() );
@ -645,7 +700,7 @@ public class HbmXmlTransformer {
final JaxbKeyManyToOneElement keyManyToOne = (JaxbKeyManyToOneElement) hbmCompositeAttribute;
final JaxbManyToOne manyToOne = new JaxbManyToOne();
manyToOne.setName( keyManyToOne.getName() );
manyToOne.setCustomAccess( keyManyToOne.getAccess() );
manyToOne.setAttributeAccessor( keyManyToOne.getAccess() );
if ( StringHelper.isNotEmpty( keyManyToOne.getEntityName() ) ) {
manyToOne.setTargetEntity( keyManyToOne.getEntityName() );
}
@ -653,9 +708,11 @@ public class HbmXmlTransformer {
manyToOne.setTargetEntity( keyManyToOne.getClazz() );
}
// todo : cascade
if ( "true".equals( keyManyToOne.getLazy().value() ) ) {
// TODO: should this check "proxy" instead?
if ( keyManyToOne.getLazy() != null && "true".equals( keyManyToOne.getLazy().value() ) ) {
manyToOne.setFetch( FetchType.LAZY );
}
manyToOne.setForeignKey( new JaxbForeignKey() );
manyToOne.getForeignKey().setName( keyManyToOne.getForeignKey() );
if ( StringHelper.isNotEmpty( keyManyToOne.getColumnAttribute() ) ) {
final JaxbJoinColumn joinColumn = new JaxbJoinColumn();
@ -677,19 +734,24 @@ public class HbmXmlTransformer {
ormRoot.getEmbeddable().add( embeddable );
}
else {
entity.getIdClass().setClazz( hbmCompositeId.getClazz() );
final JaxbIdClass idClass = new JaxbIdClass();
idClass.setClazz( hbmCompositeId.getClazz() );
entity.setIdClass( idClass );
for ( Object hbmCompositeAttribute : hbmCompositeId.getKeyPropertyOrKeyManyToOne() ) {
if ( JaxbKeyPropertyElement.class.isInstance( hbmCompositeAttribute ) ) {
final JaxbKeyPropertyElement keyProp = (JaxbKeyPropertyElement) hbmCompositeAttribute;
final JaxbId id = new JaxbId();
id.setName( keyProp.getName() );
id.setCustomAccess( keyProp.getAccess() );
id.setAttributeAccessor( keyProp.getAccess() );
if ( StringHelper.isNotEmpty( keyProp.getColumnAttribute() ) ) {
id.getColumn().setName( keyProp.getColumnAttribute() );
final JaxbColumn column = new JaxbColumn();
column.setName( keyProp.getColumnAttribute() );
id.setColumn( column );
}
else {
if ( keyProp.column != null ) {
assert keyProp.column.size() == 1;
id.setColumn( new JaxbColumn() );
transferColumn( id.getColumn(), keyProp.getColumn().get( 0 ), null, true, false );
}
}
@ -700,7 +762,7 @@ public class HbmXmlTransformer {
final JaxbManyToOne manyToOne = new JaxbManyToOne();
manyToOne.setName( keyManyToOne.getName() );
manyToOne.setId( true );
manyToOne.setCustomAccess( keyManyToOne.getAccess() );
manyToOne.setAttributeAccessor( keyManyToOne.getAccess() );
if ( StringHelper.isNotEmpty( keyManyToOne.getEntityName() ) ) {
manyToOne.setTargetEntity( keyManyToOne.getEntityName() );
}
@ -708,9 +770,11 @@ public class HbmXmlTransformer {
manyToOne.setTargetEntity( keyManyToOne.getClazz() );
}
// todo : cascade
if ( "true".equals( keyManyToOne.getLazy().value() ) ) {
// TODO: should this be "proxy", instead of "true"?
if ( keyManyToOne.getLazy() != null && "true".equals( keyManyToOne.getLazy().value() ) ) {
manyToOne.setFetch( FetchType.LAZY );
}
manyToOne.setForeignKey( new JaxbForeignKey() );
manyToOne.getForeignKey().setName( keyManyToOne.getForeignKey() );
if ( StringHelper.isNotEmpty( keyManyToOne.getColumnAttribute() ) ) {
final JaxbJoinColumn joinColumn = new JaxbJoinColumn();
@ -734,63 +798,169 @@ public class HbmXmlTransformer {
private void transferBasicAttributes(JaxbEntity entity, JaxbClassElement hbmClass) {
for ( JaxbPropertyElement hbmProp : hbmClass.getProperty() ) {
final JaxbBasic basic = new JaxbBasic();
basic.setName( hbmProp.getName() );
basic.setOptional( hbmProp.isNotNull() != null && !hbmProp.isNotNull() );
basic.setFetch( FetchType.EAGER );
basic.setCustomAccess( hbmProp.getAccess() );
basic.setOptimisticLock( hbmProp.isOptimisticLock() );
if ( StringHelper.isNotEmpty( hbmProp.getTypeAttribute() ) ) {
basic.getType().setName( hbmProp.getTypeAttribute() );
}
else {
if ( hbmProp.getType() != null ) {
basic.setType( new JaxbHbmType() );
basic.getType().setName( hbmProp.getType().getName() );
for ( JaxbParamElement hbmParam : hbmProp.getType().getParam() ) {
final JaxbHbmParam param = new JaxbHbmParam();
param.setName( hbmParam.getName() );
param.setValue( hbmParam.getValue() );
basic.getType().getParam().add( param );
}
}
}
if ( StringHelper.isNotEmpty( hbmProp.getFormulaAttribute() ) ) {
basic.getColumnOrFormula().add( hbmProp.getFormulaAttribute() );
}
else if ( StringHelper.isNotEmpty( hbmProp.getColumnAttribute() ) ) {
final JaxbColumn column = new JaxbColumn();
column.setName( hbmProp.getColumnAttribute() );
basic.getColumnOrFormula().add( column );
}
else if ( !hbmProp.getFormula().isEmpty() ) {
for ( String formula : hbmProp.getFormula() ) {
basic.getColumnOrFormula().add( formula );
}
}
else {
for ( JaxbColumnElement hbmColumn : hbmProp.getColumn() ) {
final JaxbColumn column = new JaxbColumn();
transferColumn( column, hbmColumn, null, hbmProp.isInsert(), hbmProp.isUpdate() );
basic.getColumnOrFormula().add( column );
}
}
entity.getAttributes().getBasic().add( basic );
entity.getAttributes().getBasic().add( transferBasicAttribute( hbmProp ) );
}
}
private void transferEmbeddedAttributes(JaxbEntity entity, JaxbClassElement hbmClass) {
private void transferNaturalIdentifiers(JaxbEntity entity, JaxbClassElement hbmClass) {
if (hbmClass.getNaturalId() == null) {
return;
}
JaxbNaturalId naturalId = new JaxbNaturalId();
for ( JaxbPropertyElement hbmProp : hbmClass.getNaturalId().getProperty() ) {
naturalId.getBasic().add( transferBasicAttribute( hbmProp ) );
}
for ( JaxbManyToOneElement hbmM2O : hbmClass.getNaturalId().getManyToOne() ) {
naturalId.getManyToOne().add( transferManyToOneAttribute( hbmM2O ) );
}
for ( JaxbComponentElement hbmComponent : hbmClass.getNaturalId().getComponent() ) {
naturalId.getEmbedded().add( transferEmbeddedAttribute( hbmComponent ) );
}
for ( JaxbAnyElement hbmAny : hbmClass.getNaturalId().getAny() ) {
naturalId.getAny().add( transferAnyAttribute( hbmAny ) );
}
// TODO: hbmClass.getNaturalId().getDynamicComponent?
naturalId.setMutable( hbmClass.getNaturalId().isMutable() );
entity.getAttributes().setNaturalId( naturalId );
}
private JaxbBasic transferBasicAttribute(JaxbPropertyElement hbmProp) {
final JaxbBasic basic = new JaxbBasic();
basic.setName( hbmProp.getName() );
basic.setOptional( hbmProp.isNotNull() == null ? true : !hbmProp.isNotNull() );
basic.setFetch( FetchType.EAGER );
basic.setAttributeAccessor( hbmProp.getAccess() );
basic.setOptimisticLock( hbmProp.isOptimisticLock() );
if ( StringHelper.isNotEmpty( hbmProp.getTypeAttribute() ) ) {
basic.setType( new JaxbHbmType() );
basic.getType().setName( hbmProp.getTypeAttribute() );
}
else {
if ( hbmProp.getType() != null ) {
basic.setType( new JaxbHbmType() );
basic.getType().setName( hbmProp.getType().getName() );
for ( JaxbParamElement hbmParam : hbmProp.getType().getParam() ) {
final JaxbHbmParam param = new JaxbHbmParam();
param.setName( hbmParam.getName() );
param.setValue( hbmParam.getValue() );
basic.getType().getParam().add( param );
}
}
}
// TODO: If hbmProp isUnique or notNull is set, bind the column?
if ( StringHelper.isNotEmpty( hbmProp.getFormulaAttribute() ) ) {
basic.getColumnOrFormula().add( hbmProp.getFormulaAttribute() );
}
else if ( StringHelper.isNotEmpty( hbmProp.getColumnAttribute() ) ) {
final JaxbColumn column = new JaxbColumn();
column.setName( hbmProp.getColumnAttribute() );
basic.getColumnOrFormula().add( column );
}
else if ( !hbmProp.getFormula().isEmpty() ) {
for ( String formula : hbmProp.getFormula() ) {
basic.getColumnOrFormula().add( formula );
}
}
else {
for ( JaxbColumnElement hbmColumn : hbmProp.getColumn() ) {
final JaxbColumn column = new JaxbColumn();
transferColumn( column, hbmColumn, null, hbmProp.isInsert(), hbmProp.isUpdate() );
basic.getColumnOrFormula().add( column );
}
}
return basic;
}
private void transferEmbeddedAttributes(JaxbEntity entity, JaxbClassElement hbmClass) {
for (JaxbComponentElement hbmComponent : hbmClass.getComponent()) {
entity.getAttributes().getEmbedded().add( transferEmbeddedAttribute( hbmComponent ) );
ormRoot.getEmbeddable().add( transferEmbeddable( hbmComponent ) );
}
}
private JaxbEmbeddable transferEmbeddable(JaxbComponentElement hbmComponent) {
final JaxbEmbeddable embeddable = new JaxbEmbeddable();
embeddable.setClazz( hbmComponent.getClazz() );
embeddable.setAttributes( new JaxbEmbeddableAttributes() );
for (JaxbPropertyElement property : hbmComponent.getProperty()) {
embeddable.getAttributes().getBasic().add( transferBasicAttribute( property ) );
}
for (JaxbManyToOneElement manyToOne : hbmComponent.getManyToOne()) {
embeddable.getAttributes().getManyToOne().add( transferManyToOneAttribute( manyToOne ) );
}
for (JaxbOneToOneElement oneToOne : hbmComponent.getOneToOne()) {
embeddable.getAttributes().getOneToOne().add( transferOneToOneAttribute( oneToOne ) );
}
for (JaxbComponentElement component : hbmComponent.getComponent()) {
// TODO
}
return embeddable;
}
private JaxbEmbedded transferEmbeddedAttribute(JaxbComponentElement hbmComponent) {
final JaxbEmbedded embedded = new JaxbEmbedded();
embedded.setAttributeAccessor( hbmComponent.getAccess() );
embedded.setName( hbmComponent.getName() );
return embedded;
}
private void transferOneToOneAttributes(JaxbEntity entity, JaxbClassElement hbmClass) {
for (JaxbOneToOneElement hbmO2O : hbmClass.getOneToOne()) {
entity.getAttributes().getOneToOne().add( transferOneToOneAttribute( hbmO2O ) );
}
}
private JaxbOneToOne transferOneToOneAttribute(JaxbOneToOneElement hbmO2O) {
final JaxbOneToOne o2o = new JaxbOneToOne();
o2o.setAttributeAccessor( hbmO2O.getAccess() );
o2o.setCascade( convertCascadeType( hbmO2O.getCascade() ) );
o2o.setFetch( convert( hbmO2O.getFetch() ) );
o2o.setForeignKey( new JaxbForeignKey() );
o2o.getForeignKey().setName( hbmO2O.getForeignKey() );
if (! StringHelper.isEmpty( hbmO2O.getPropertyRef() )) {
final JaxbJoinColumn joinColumn = new JaxbJoinColumn();
joinColumn.setReferencedColumnName( hbmO2O.getPropertyRef() );
o2o.getJoinColumn().add( joinColumn );
}
o2o.setName( hbmO2O.getName() );
o2o.setTargetEntity( hbmO2O.getEntityName() );
return o2o;
}
private void transferManyToOneAttributes(JaxbEntity entity, JaxbClassElement hbmClass) {
for (JaxbManyToOneElement hbmM2O : hbmClass.getManyToOne()) {
entity.getAttributes().getManyToOne().add( transferManyToOneAttribute( hbmM2O ) );
}
}
private JaxbManyToOne transferManyToOneAttribute(JaxbManyToOneElement hbmM2O) {
final JaxbManyToOne m2o = new JaxbManyToOne();
m2o.setAttributeAccessor( hbmM2O.getAccess() );
m2o.setCascade( convertCascadeType( hbmM2O.getCascade() ) );
m2o.setFetch( convert( hbmM2O.getFetch() ) );
m2o.setForeignKey( new JaxbForeignKey() );
m2o.getForeignKey().setName( hbmM2O.getForeignKey() );
final JaxbJoinColumn joinColumn = new JaxbJoinColumn();
if (StringHelper.isEmpty( hbmM2O.getColumnAttribute() )) {
// AbstractBasicBindingTests seems to imply this was the case
joinColumn.setName( hbmM2O.getName() );
}
else {
joinColumn.setName( hbmM2O.getColumnAttribute() );
}
if (! StringHelper.isEmpty( hbmM2O.getPropertyRef() )) {
joinColumn.setReferencedColumnName( hbmM2O.getPropertyRef() );
}
m2o.getJoinColumn().add( joinColumn );
m2o.setName( hbmM2O.getName() );
m2o.setOptional( hbmM2O.isNotNull() == null ? true : !hbmM2O.isNotNull() );
m2o.setTargetEntity( hbmM2O.getEntityName() );
return m2o;
}
private void transferManyToManyAttributes(JaxbEntity entity, JaxbClassElement hbmClass) {
@ -801,6 +971,11 @@ public class HbmXmlTransformer {
}
private JaxbAny transferAnyAttribute(JaxbAnyElement hbmAny) {
// TODO
return new JaxbAny();
}
private void transferManyToAnyAttributes(JaxbEntity entity, JaxbClassElement hbmClass) {
}
@ -840,5 +1015,53 @@ public class HbmXmlTransformer {
private void transferUnionSubclass(JaxbUnionSubclassElement hbmSubclass, JaxbEntity entity) {
// todo : implement
}
private JaxbCascadeType convertCascadeType(String s) {
final JaxbCascadeType cascadeType = new JaxbCascadeType();
if (! StringHelper.isEmpty( s )) {
s = s.replaceAll( " ", "" );
final String[] split = s.split( "," );
for (String hbmCascade : split) {
if (hbmCascade.equalsIgnoreCase( "all" )) {
cascadeType.setCascadeAll( new JaxbEmptyType() );
}
else if (hbmCascade.equalsIgnoreCase( "persist" )) {
cascadeType.setCascadePersist( new JaxbEmptyType() );
}
else if (hbmCascade.equalsIgnoreCase( "merge" )) {
cascadeType.setCascadeMerge( new JaxbEmptyType() );
}
else if (hbmCascade.equalsIgnoreCase( "refresh" )) {
cascadeType.setCascadeRefresh( new JaxbEmptyType() );
}
else if (hbmCascade.equalsIgnoreCase( "save-update" )) {
// TODO
}
else if (hbmCascade.equalsIgnoreCase( "evict" )) {
// TODO
}
else if (hbmCascade.equalsIgnoreCase( "replicate" )) {
// TODO
}
else if (hbmCascade.equalsIgnoreCase( "lock" )) {
// TODO
}
}
}
return cascadeType;
}
private FetchType convert(JaxbFetchStyleAttribute hbmFetch) {
if (hbmFetch != null) {
switch (hbmFetch) {
case JOIN:
return FetchType.EAGER;
case SELECT:
return FetchType.LAZY;
}
}
// TODO: EAGER or LAZY?
return FetchType.LAZY;
}
}

View File

@ -82,7 +82,7 @@
<!-- The JPA declaration is the discrete set (property|field) -->
<xsd:element name="access" type="orm:access-type" />
<!-- Hibernate allows pluggable contracts, so its declaration is open-ended -->
<xsd:element name="custom-access" type="xsd:string" />
<xsd:element name="attribute-accessor" type="xsd:string" />
</xsd:choice>
<xsd:element name="auto-import" type="xsd:boolean" minOccurs="0" />
@ -272,7 +272,7 @@
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string"/>
<xsd:attribute name="access" type="orm:access-type"/>
<xsd:attribute name="custom-access" type="xsd:string" />
<xsd:attribute name="attribute-accessor" type="xsd:string" />
</xsd:complexType>
<xsd:complexType name="any-discriminator-value-mapping">
@ -402,7 +402,7 @@
<xsd:attribute name="fetch" type="orm:fetch-type"/>
<xsd:attribute name="optional" type="xsd:boolean"/>
<xsd:attribute name="access" type="orm:access-type"/>
<xsd:attribute name="custom-access" type="xsd:string" />
<xsd:attribute name="attribute-accessor" type="xsd:string" />
<xsd:attribute name="natural-id" type="xsd:boolean" />
</xsd:complexType>
@ -680,7 +680,7 @@
<xsd:attribute name="target-class" type="xsd:string"/>
<xsd:attribute name="fetch" type="orm:fetch-type"/>
<xsd:attribute name="access" type="orm:access-type"/>
<xsd:attribute name="custom-access" type="xsd:string" />
<xsd:attribute name="attribute-accessor" type="xsd:string" />
</xsd:complexType>
@ -741,7 +741,7 @@
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required"/>
<xsd:attribute name="access" type="orm:access-type"/>
<xsd:attribute name="custom-access" type="xsd:string" />
<xsd:attribute name="attribute-accessor" type="xsd:string" />
<xsd:attribute name="natural-id" type="xsd:boolean" />
</xsd:complexType>
@ -758,7 +758,7 @@
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required"/>
<xsd:attribute name="access" type="orm:access-type"/>
<xsd:attribute name="custom-access" type="xsd:string" />
<xsd:attribute name="attribute-accessor" type="xsd:string" />
</xsd:complexType>
@ -914,7 +914,7 @@
-->
<xsd:attribute name="class" type="xsd:string" />
<xsd:attribute name="access" type="orm:access-type"/>
<xsd:attribute name="custom-access" type="xsd:string" />
<xsd:attribute name="attribute-accessor" type="xsd:string" />
<xsd:attribute name="cacheable" type="xsd:boolean"/>
<xsd:attribute name="metadata-complete" type="xsd:boolean"/>
</xsd:complexType>
@ -1103,7 +1103,7 @@
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required"/>
<xsd:attribute name="access" type="orm:access-type"/>
<xsd:attribute name="custom-access" type="xsd:string" />
<xsd:attribute name="attribute-accessor" type="xsd:string" />
</xsd:complexType>
@ -1284,7 +1284,7 @@
<xsd:attribute name="name" use="required" type="xsd:string"/>
<xsd:attribute name="access" type="orm:access-type"/>
<xsd:attribute name="custom-access" type="xsd:string" />
<xsd:attribute name="attribute-accessor" type="xsd:string" />
</xsd:complexType>
@ -1333,7 +1333,7 @@
<xsd:attribute name="target-entity" type="xsd:string"/>
<xsd:attribute name="fetch" type="orm:fetch-type"/>
<xsd:attribute name="access" type="orm:access-type"/>
<xsd:attribute name="custom-access" type="xsd:string" />
<xsd:attribute name="attribute-accessor" type="xsd:string" />
<xsd:attribute name="mapped-by" type="xsd:string"/>
</xsd:complexType>
@ -1365,7 +1365,7 @@
<xsd:attribute name="fetch" type="orm:fetch-type"/>
<xsd:attribute name="optional" type="xsd:boolean"/>
<xsd:attribute name="access" type="orm:access-type"/>
<xsd:attribute name="custom-access" type="xsd:string" />
<xsd:attribute name="attribute-accessor" type="xsd:string" />
<xsd:attribute name="maps-id" type="xsd:string"/>
<xsd:attribute name="id" type="xsd:boolean"/>
<xsd:attribute name="natural-id" type="xsd:boolean" />
@ -1475,7 +1475,7 @@
<xsd:attribute name="class" type="xsd:string" use="required"/>
<xsd:attribute name="access" type="orm:access-type"/>
<xsd:attribute name="custom-access" type="xsd:string" />
<xsd:attribute name="attribute-accessor" type="xsd:string" />
<xsd:attribute name="metadata-complete" type="xsd:boolean"/>
</xsd:complexType>
@ -1713,7 +1713,7 @@
<xsd:attribute name="target-entity" type="xsd:string"/>
<xsd:attribute name="fetch" type="orm:fetch-type"/>
<xsd:attribute name="access" type="orm:access-type"/>
<xsd:attribute name="custom-access" type="xsd:string" />
<xsd:attribute name="attribute-accessor" type="xsd:string" />
<xsd:attribute name="mapped-by" type="xsd:string"/>
<xsd:attribute name="orphan-removal" type="xsd:boolean"/>
</xsd:complexType>
@ -1748,7 +1748,7 @@
<xsd:attribute name="fetch" type="orm:fetch-type"/>
<xsd:attribute name="optional" type="xsd:boolean"/>
<xsd:attribute name="access" type="orm:access-type"/>
<xsd:attribute name="custom-access" type="xsd:string" />
<xsd:attribute name="attribute-accessor" type="xsd:string" />
<xsd:attribute name="mapped-by" type="xsd:string"/>
<xsd:attribute name="orphan-removal" type="xsd:boolean"/>
<xsd:attribute name="maps-id" type="xsd:string"/>
@ -2211,7 +2211,7 @@
<xsd:attribute name="name" type="xsd:string" use="required"/>
<xsd:attribute name="access" type="orm:access-type"/>
<xsd:attribute name="custom-access" type="xsd:string" />
<xsd:attribute name="attribute-accessor" type="xsd:string" />
</xsd:complexType>

View File

@ -23,23 +23,21 @@
*/
package org.hibernate.metamodel.internal.source.annotations.xml.mocker;
import static org.junit.Assert.assertEquals;
import org.hibernate.metamodel.source.internal.annotations.util.JPADotNames;
import org.hibernate.metamodel.source.internal.jandex.EntityMappingsMocker;
import org.hibernate.metamodel.source.internal.jandex.Default;
import org.hibernate.metamodel.source.internal.jandex.EntityMocker;
import org.hibernate.metamodel.source.internal.jandex.IndexBuilder;
import org.hibernate.metamodel.source.internal.jaxb.JaxbAttributes;
import org.hibernate.metamodel.source.internal.jaxb.JaxbEntity;
import org.hibernate.metamodel.source.internal.jaxb.JaxbGeneratedValue;
import org.hibernate.metamodel.source.internal.jaxb.JaxbId;
import org.junit.Test;
import org.jboss.jandex.AnnotationInstance;
import org.jboss.jandex.AnnotationValue;
import org.jboss.jandex.DotName;
import org.jboss.jandex.Index;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
/**
* @author Strong Liu
@ -49,11 +47,11 @@ public class BasicMockerTest extends AbstractMockerTest {
public void testEntity() {
JaxbEntity entity = createEntity();
IndexBuilder indexBuilder = getIndexBuilder();
EntityMocker entityMocker = new EntityMocker( indexBuilder, entity, new EntityMappingsMocker.Default() );
EntityMocker entityMocker = new EntityMocker( indexBuilder, entity, new Default() );
entityMocker.preProcess();
entityMocker.process();
Index index = indexBuilder.build( new EntityMappingsMocker.Default() );
Index index = indexBuilder.build( new Default() );
assertEquals( 1, index.getKnownClasses().size() );
DotName itemName = DotName.createSimple( Item.class.getName() );
assertHasAnnotation( index, itemName, JPADotNames.ENTITY );
@ -67,7 +65,7 @@ public class BasicMockerTest extends AbstractMockerTest {
entity.setName( "Item" );
entity.setClazz( "Item" );
IndexBuilder indexBuilder = getIndexBuilder();
EntityMappingsMocker.Default defaults = new EntityMappingsMocker.Default();
Default defaults = new Default();
defaults.setPackageName( getClass().getPackage().getName() );
defaults.setSchema( "HIBERNATE_SCHEMA" );
defaults.setCatalog( "HIBERNATE_CATALOG" );
@ -75,7 +73,7 @@ public class BasicMockerTest extends AbstractMockerTest {
entityMocker.preProcess();
entityMocker.process();
Index index = indexBuilder.build( new EntityMappingsMocker.Default() );
Index index = indexBuilder.build( new Default() );
assertEquals( 1, index.getKnownClasses().size() );
DotName itemName = DotName.createSimple( Item.class.getName() );
assertHasAnnotation( index, itemName, JPADotNames.ENTITY );

View File

@ -1,10 +1,17 @@
package org.hibernate.metamodel.internal.source.annotations.xml.mocker;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.Id;
@ -14,21 +21,13 @@ import javax.persistence.SecondaryTable;
import javax.persistence.SecondaryTables;
import org.hibernate.metamodel.source.internal.annotations.util.JPADotNames;
import org.hibernate.metamodel.source.internal.jandex.Default;
import org.hibernate.metamodel.source.internal.jandex.DefaultConfigurationHelper;
import org.hibernate.metamodel.source.internal.jandex.EntityMappingsMocker;
import org.hibernate.metamodel.source.internal.jaxb.JaxbEntity;
import org.junit.Test;
import org.jboss.jandex.AnnotationInstance;
import org.jboss.jandex.DotName;
import org.jboss.jandex.Index;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
/**
* @author Strong Liu
@ -45,7 +44,7 @@ public class DefaultConfigurationHelperTest extends AbstractMockerTest {
@Test
public void applyDefaultToEntity() {
EntityMappingsMocker.Default defaults = new EntityMappingsMocker.Default();
Default defaults = new Default();
defaults.setPackageName( "org.test" );
defaults.setSchema( "schema" );
defaults.setMetadataComplete( true );
@ -64,7 +63,7 @@ public class DefaultConfigurationHelperTest extends AbstractMockerTest {
@Test
public void testDefaultCascadePersist() {
EntityMappingsMocker.Default defaults = new EntityMappingsMocker.Default();
Default defaults = new Default();
defaults.setCascadePersist( true );
Index index = getIndex();
Map<DotName, List<AnnotationInstance>> annotations = new HashMap<DotName, List<AnnotationInstance>>();
@ -110,7 +109,7 @@ public class DefaultConfigurationHelperTest extends AbstractMockerTest {
@Test
public void testDefaultSchemaToAnnotationInstance() {
EntityMappingsMocker.Default defaults = new EntityMappingsMocker.Default();
Default defaults = new Default();
defaults.setSchema( "hib_schema" );
defaults.setCatalog( "hib_catalog" );
Index index = getIndex();

View File

@ -23,28 +23,26 @@
*/
package org.hibernate.metamodel.internal.source.annotations.xml.mocker;
import java.util.List;
import org.hibernate.metamodel.source.internal.annotations.util.JPADotNames;
import org.hibernate.metamodel.source.internal.jandex.EntityMappingsMocker;
import org.hibernate.metamodel.source.internal.jandex.EntityMocker;
import org.hibernate.metamodel.source.internal.jandex.IndexBuilder;
import org.hibernate.metamodel.source.internal.jaxb.JaxbEntity;
import org.junit.Test;
import org.jboss.jandex.AnnotationInstance;
import org.jboss.jandex.AnnotationValue;
import org.jboss.jandex.ClassInfo;
import org.jboss.jandex.DotName;
import org.jboss.jandex.Index;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.fail;
import java.util.List;
import org.hibernate.metamodel.source.internal.annotations.util.JPADotNames;
import org.hibernate.metamodel.source.internal.jandex.Default;
import org.hibernate.metamodel.source.internal.jandex.EntityMocker;
import org.hibernate.metamodel.source.internal.jandex.IndexBuilder;
import org.hibernate.metamodel.source.internal.jaxb.JaxbEntity;
import org.jboss.jandex.AnnotationInstance;
import org.jboss.jandex.AnnotationValue;
import org.jboss.jandex.ClassInfo;
import org.jboss.jandex.DotName;
import org.jboss.jandex.Index;
import org.junit.Test;
/**
* @author Strong Liu
*/
@ -63,12 +61,12 @@ public class OverrideTest extends AbstractMockerTest {
JaxbEntity author = new JaxbEntity();
author.setClazz( Author.class.getName() );
IndexBuilder indexBuilder = getIndexBuilder();
EntityMappingsMocker.Default defaults = new EntityMappingsMocker.Default();
Default defaults = new Default();
defaults.setMetadataComplete( true );
EntityMocker entityMocker = new EntityMocker( indexBuilder, author, defaults );
entityMocker.preProcess();
entityMocker.process();
Index index = indexBuilder.build( new EntityMappingsMocker.Default() );
Index index = indexBuilder.build( new Default() );
DotName className = DotName.createSimple( Author.class.getName() );
ClassInfo classInfo = index.getClassByName( className );
assertEquals( 1, classInfo.annotations().size() );
@ -105,12 +103,12 @@ public class OverrideTest extends AbstractMockerTest {
JaxbEntity author = new JaxbEntity();
author.setClazz( Author.class.getName() );
IndexBuilder indexBuilder = getIndexBuilder();
EntityMappingsMocker.Default defaults = new EntityMappingsMocker.Default();
Default defaults = new Default();
defaults.setCascadePersist( true );
EntityMocker entityMocker = new EntityMocker( indexBuilder, author, defaults );
entityMocker.preProcess();
entityMocker.process();
Index index = indexBuilder.build( new EntityMappingsMocker.Default() );
Index index = indexBuilder.build( new Default() );
DotName className = DotName.createSimple( Author.class.getName() );
assertAnnotationValue(
index, className, JPADotNames.ONE_TO_MANY, new CascadeAnnotationValueChecker( "PERSIST", "MERGE" )