mirror of
https://github.com/hibernate/hibernate-orm
synced 2025-02-17 16:44:57 +00:00
HHH-7452 mixin interface to simplify orm xml binding
This commit is contained in:
parent
6ed7e9ee7f
commit
f0a49ada75
@ -63,37 +63,37 @@ final void parser() {
|
||||
for ( JaxbId id : getId() ) {
|
||||
new IdMocker( indexBuilder, classInfo, defaults, id ).process();
|
||||
}
|
||||
for ( JaxbTransient transientObj : getTransient() ) {
|
||||
for ( JaxbTransient transientObj : getAttributesContainer().getTransient() ) {
|
||||
new TransientMocker( indexBuilder, classInfo, defaults, transientObj ).process();
|
||||
}
|
||||
for ( JaxbVersion version : getVersion() ) {
|
||||
new VersionMocker( indexBuilder, classInfo, defaults, version ).process();
|
||||
}
|
||||
|
||||
for ( JaxbBasic basic : getBasic() ) {
|
||||
for ( JaxbBasic basic : getAttributesContainer().getBasic() ) {
|
||||
new BasicMocker( indexBuilder, classInfo, defaults, basic ).process();
|
||||
}
|
||||
for ( JaxbElementCollection elementCollection : getElementCollection() ) {
|
||||
for ( JaxbElementCollection elementCollection : getAttributesContainer().getElementCollection() ) {
|
||||
new ElementCollectionMocker(
|
||||
indexBuilder, classInfo, defaults, elementCollection
|
||||
).process();
|
||||
}
|
||||
for ( JaxbEmbedded embedded : getEmbedded() ) {
|
||||
for ( JaxbEmbedded embedded : getAttributesContainer().getEmbedded() ) {
|
||||
new EmbeddedMocker( indexBuilder, classInfo, defaults, embedded ).process();
|
||||
}
|
||||
for ( JaxbManyToMany manyToMany : getManyToMany() ) {
|
||||
for ( JaxbManyToMany manyToMany : getAttributesContainer().getManyToMany() ) {
|
||||
new ManyToManyMocker( indexBuilder, classInfo, defaults, manyToMany ).process();
|
||||
}
|
||||
|
||||
for ( JaxbManyToOne manyToOne : getManyToOne() ) {
|
||||
for ( JaxbManyToOne manyToOne : getAttributesContainer().getManyToOne() ) {
|
||||
new ManyToOneMocker( indexBuilder, classInfo, defaults, manyToOne ).process();
|
||||
}
|
||||
for ( JaxbOneToMany oneToMany : getOneToMany() ) {
|
||||
for ( JaxbOneToMany oneToMany : getAttributesContainer().getOneToMany() ) {
|
||||
new OneToManyMocker(
|
||||
indexBuilder, classInfo, defaults, oneToMany
|
||||
).process();
|
||||
}
|
||||
for ( JaxbOneToOne oneToOne : getOneToOne() ) {
|
||||
for ( JaxbOneToOne oneToOne : getAttributesContainer().getOneToOne() ) {
|
||||
new OneToOneMocker( indexBuilder, classInfo, defaults, oneToOne ).process();
|
||||
}
|
||||
if ( getEmbeddedId() != null ) {
|
||||
@ -104,24 +104,7 @@ indexBuilder, classInfo, defaults, getEmbeddedId()
|
||||
}
|
||||
|
||||
abstract List<JaxbId> getId();
|
||||
|
||||
abstract List<JaxbTransient> getTransient();
|
||||
|
||||
abstract List<JaxbVersion> getVersion();
|
||||
|
||||
abstract List<JaxbBasic> getBasic();
|
||||
|
||||
abstract List<JaxbElementCollection> getElementCollection();
|
||||
|
||||
abstract List<JaxbEmbedded> getEmbedded();
|
||||
|
||||
abstract List<JaxbManyToMany> getManyToMany();
|
||||
|
||||
abstract List<JaxbManyToOne> getManyToOne();
|
||||
|
||||
abstract List<JaxbOneToMany> getOneToMany();
|
||||
|
||||
abstract List<JaxbOneToOne> getOneToOne();
|
||||
|
||||
abstract JaxbEmbeddedId getEmbeddedId();
|
||||
abstract protected AttributesContainer getAttributesContainer();
|
||||
}
|
@ -59,13 +59,13 @@ abstract class AbstractEntityObjectMocker extends AnnotationMocker {
|
||||
* Pre-process Entity Objects to find the default {@link javax.persistence.Access} for later attributes processing.
|
||||
*/
|
||||
final void preProcess() {
|
||||
applyDefaults();
|
||||
classInfo = indexBuilder.createClassInfo( getClassName() );
|
||||
DefaultConfigurationHelper.INSTANCE.applyDefaults( getEntityElement(), getDefaults() );
|
||||
classInfo = indexBuilder.createClassInfo( getEntityElement().getClazz() );
|
||||
DotName classDotName = classInfo.name();
|
||||
if ( isMetadataComplete() ) {
|
||||
if ( getEntityElement().isMetadataComplete() ) {
|
||||
indexBuilder.metadataComplete( classDotName );
|
||||
}
|
||||
parserAccessType( getAccessType(), getTarget() );
|
||||
parserAccessType( getEntityElement().getAccess(), getTarget() );
|
||||
isPreProcessCalled = true;
|
||||
}
|
||||
|
||||
@ -73,7 +73,7 @@ final void process() {
|
||||
if ( !isPreProcessCalled ) {
|
||||
throw new AssertionFailure( "preProcess should be called before process" );
|
||||
}
|
||||
if ( getAccessType() == null ) {
|
||||
if ( getEntityElement().getAccess() == null ) {
|
||||
JaxbAccessType accessType = AccessHelper.getEntityAccess( getTargetName(), indexBuilder );
|
||||
if ( accessType == null ) {
|
||||
accessType = getDefaults().getAccess();
|
||||
@ -96,27 +96,19 @@ final void process() {
|
||||
if ( getEntityListeners() != null ) {
|
||||
getListenerParser().parser( getEntityListeners() );
|
||||
}
|
||||
getListenerParser().parser( getPrePersist() );
|
||||
getListenerParser().parser( getPreRemove() );
|
||||
getListenerParser().parser( getPreUpdate() );
|
||||
getListenerParser().parser( getPostPersist() );
|
||||
getListenerParser().parser( getPostUpdate() );
|
||||
getListenerParser().parser( getPostRemove() );
|
||||
getListenerParser().parser( getPostLoad() );
|
||||
getListenerParser().parser( getPrePersist(), PRE_PERSIST );
|
||||
getListenerParser().parser( getPreRemove(), PRE_REMOVE );
|
||||
getListenerParser().parser( getPreUpdate(), PRE_UPDATE );
|
||||
getListenerParser().parser( getPostPersist(), POST_PERSIST );
|
||||
getListenerParser().parser( getPostUpdate(), POST_UPDATE );
|
||||
getListenerParser().parser( getPostRemove(), POST_REMOVE );
|
||||
getListenerParser().parser( getPostLoad(), POST_LOAD );
|
||||
|
||||
indexBuilder.finishEntityObject( getTargetName(), getDefaults() );
|
||||
}
|
||||
|
||||
|
||||
abstract protected EntityElement getEntityElement();
|
||||
abstract protected void processExtra();
|
||||
|
||||
/**
|
||||
* give a chance to the sub-classes to override defaults configuration
|
||||
*/
|
||||
abstract protected void applyDefaults();
|
||||
|
||||
abstract protected boolean isMetadataComplete();
|
||||
|
||||
abstract protected boolean isExcludeDefaultListeners();
|
||||
|
||||
abstract protected boolean isExcludeSuperclassListeners();
|
||||
@ -124,11 +116,6 @@ final void process() {
|
||||
abstract protected JaxbIdClass getIdClass();
|
||||
|
||||
abstract protected JaxbEntityListeners getEntityListeners();
|
||||
|
||||
abstract protected JaxbAccessType getAccessType();
|
||||
|
||||
abstract protected String getClassName();
|
||||
|
||||
abstract protected JaxbPrePersist getPrePersist();
|
||||
|
||||
abstract protected JaxbPreRemove getPreRemove();
|
||||
@ -155,7 +142,7 @@ protected ListenerMocker getListenerParser() {
|
||||
protected AbstractAttributesBuilder getAttributesBuilder() {
|
||||
if ( attributesBuilder == null ) {
|
||||
attributesBuilder = new AttributesBuilder(
|
||||
indexBuilder, classInfo, getAccessType(), getDefaults(), getAttributes()
|
||||
indexBuilder, classInfo, getEntityElement().getAccess(), getDefaults(), getAttributes()
|
||||
);
|
||||
}
|
||||
return attributesBuilder;
|
||||
|
@ -33,6 +33,7 @@
|
||||
|
||||
import org.hibernate.internal.jaxb.mapping.orm.JaxbAccessType;
|
||||
import org.hibernate.internal.jaxb.mapping.orm.JaxbUniqueConstraint;
|
||||
import org.hibernate.internal.util.collections.CollectionHelper;
|
||||
import org.hibernate.metamodel.internal.source.annotations.util.JPADotNames;
|
||||
|
||||
/**
|
||||
@ -76,7 +77,7 @@ protected AnnotationInstance parserAccessType(JaxbAccessType accessType, Annotat
|
||||
}
|
||||
|
||||
protected void nestedUniqueConstraintList(String name, List<JaxbUniqueConstraint> constraints, List<AnnotationValue> annotationValueList) {
|
||||
if ( MockHelper.isNotEmpty( constraints ) ) {
|
||||
if ( CollectionHelper.isNotEmpty( constraints ) ) {
|
||||
AnnotationValue[] values = new AnnotationValue[constraints.size()];
|
||||
for ( int i = 0; i < constraints.size(); i++ ) {
|
||||
AnnotationInstance annotationInstance = parserUniqueConstraint( constraints.get( i ), null );
|
||||
|
@ -37,6 +37,7 @@
|
||||
import org.hibernate.MappingException;
|
||||
import org.hibernate.internal.CoreMessageLogger;
|
||||
import org.hibernate.internal.jaxb.mapping.orm.JaxbAccessType;
|
||||
import org.hibernate.internal.util.collections.CollectionHelper;
|
||||
import org.hibernate.metamodel.internal.source.annotations.util.JPADotNames;
|
||||
import org.hibernate.metamodel.internal.source.annotations.util.JandexHelper;
|
||||
import org.hibernate.metamodel.internal.source.annotations.xml.PseudoJpaDotNames;
|
||||
@ -91,7 +92,7 @@ private static JaxbAccessType getAccessFromIdPosition(Map<DotName, List<Annotati
|
||||
return null;
|
||||
}
|
||||
List<AnnotationInstance> idAnnotationInstances = annotations.get( ID );
|
||||
if ( MockHelper.isNotEmpty( idAnnotationInstances ) ) {
|
||||
if ( CollectionHelper.isNotEmpty( idAnnotationInstances ) ) {
|
||||
return processIdAnnotations( idAnnotationInstances );
|
||||
}
|
||||
return null;
|
||||
@ -146,7 +147,7 @@ private static JaxbAccessType getAccess(Map<DotName, List<AnnotationInstance>> a
|
||||
return null;
|
||||
}
|
||||
List<AnnotationInstance> accessAnnotationInstances = annotations.get( JPADotNames.ACCESS );
|
||||
if ( MockHelper.isNotEmpty( accessAnnotationInstances ) ) {
|
||||
if ( CollectionHelper.isNotEmpty( accessAnnotationInstances ) ) {
|
||||
for ( AnnotationInstance annotationInstance : accessAnnotationInstances ) {
|
||||
if ( annotationInstance.target() != null && annotationInstance.target() instanceof ClassInfo ) {
|
||||
return JandexHelper.getEnumValue(
|
||||
@ -172,7 +173,7 @@ static JaxbAccessType getAccessFromAttributeAnnotation(DotName className, String
|
||||
Map<DotName, List<AnnotationInstance>> indexedAnnotations = indexBuilder.getIndexedAnnotations( className );
|
||||
if ( indexedAnnotations != null && indexedAnnotations.containsKey( ACCESS ) ) {
|
||||
List<AnnotationInstance> annotationInstances = indexedAnnotations.get( ACCESS );
|
||||
if ( MockHelper.isNotEmpty( annotationInstances ) ) {
|
||||
if ( CollectionHelper.isNotEmpty( annotationInstances ) ) {
|
||||
for ( AnnotationInstance annotationInstance : annotationInstances ) {
|
||||
AnnotationTarget indexedPropertyTarget = annotationInstance.target();
|
||||
if ( indexedPropertyTarget == null ) {
|
||||
|
@ -46,6 +46,7 @@
|
||||
import org.hibernate.internal.jaxb.mapping.orm.JaxbOrderColumn;
|
||||
import org.hibernate.internal.jaxb.mapping.orm.JaxbPrimaryKeyJoinColumn;
|
||||
import org.hibernate.internal.jaxb.mapping.orm.JaxbTemporalType;
|
||||
import org.hibernate.internal.util.collections.CollectionHelper;
|
||||
|
||||
/**
|
||||
* @author Strong Liu
|
||||
@ -112,7 +113,7 @@ private AnnotationInstance parserAssociationOverride(JaxbAssociationOverride ass
|
||||
}
|
||||
|
||||
private AnnotationValue[] nestedJoinColumnList(String name, List<JaxbJoinColumn> columns, List<AnnotationValue> annotationValueList) {
|
||||
if ( MockHelper.isNotEmpty( columns ) ) {
|
||||
if ( CollectionHelper.isNotEmpty( columns ) ) {
|
||||
AnnotationValue[] values = new AnnotationValue[columns.size()];
|
||||
for ( int i = 0; i < columns.size(); i++ ) {
|
||||
AnnotationInstance annotationInstance = parserJoinColumn( columns.get( i ), null );
|
||||
@ -246,7 +247,7 @@ protected AnnotationInstance parserPrimaryKeyJoinColumn(JaxbPrimaryKeyJoinColumn
|
||||
}
|
||||
|
||||
protected AnnotationInstance parserPrimaryKeyJoinColumnList(List<JaxbPrimaryKeyJoinColumn> primaryKeyJoinColumnList, AnnotationTarget target) {
|
||||
if ( MockHelper.isNotEmpty( primaryKeyJoinColumnList ) ) {
|
||||
if ( CollectionHelper.isNotEmpty( primaryKeyJoinColumnList ) ) {
|
||||
if ( primaryKeyJoinColumnList.size() == 1 ) {
|
||||
return parserPrimaryKeyJoinColumn( primaryKeyJoinColumnList.get( 0 ), target );
|
||||
}
|
||||
@ -264,7 +265,7 @@ protected AnnotationInstance parserPrimaryKeyJoinColumnList(List<JaxbPrimaryKeyJ
|
||||
}
|
||||
|
||||
protected AnnotationValue[] nestedPrimaryKeyJoinColumnList(String name, List<JaxbPrimaryKeyJoinColumn> constraints, List<AnnotationValue> annotationValueList) {
|
||||
if ( MockHelper.isNotEmpty( constraints ) ) {
|
||||
if ( CollectionHelper.isNotEmpty( constraints ) ) {
|
||||
AnnotationValue[] values = new AnnotationValue[constraints.size()];
|
||||
for ( int i = 0; i < constraints.size(); i++ ) {
|
||||
AnnotationInstance annotationInstance = parserPrimaryKeyJoinColumn( constraints.get( i ), null );
|
||||
@ -287,7 +288,7 @@ protected void getAnnotationInstanceByTarget(DotName annName, AnnotationTarget t
|
||||
return;
|
||||
}
|
||||
List<AnnotationInstance> annotationInstanceList = annotatedMap.get( annName );
|
||||
if ( MockHelper.isNotEmpty( annotationInstanceList ) ) {
|
||||
if ( CollectionHelper.isNotEmpty( annotationInstanceList ) ) {
|
||||
for ( AnnotationInstance annotationInstance : annotationInstanceList ) {
|
||||
AnnotationTarget annotationTarget = annotationInstance.target();
|
||||
if ( MockHelper.targetEquals( target, annotationTarget ) ) {
|
||||
@ -392,7 +393,7 @@ protected AnnotationInstance parserCollectionTable(JaxbCollectionTable collectio
|
||||
|
||||
|
||||
protected AnnotationInstance parserJoinColumnList(List<JaxbJoinColumn> joinColumnList, AnnotationTarget target) {
|
||||
if ( MockHelper.isNotEmpty( joinColumnList ) ) {
|
||||
if ( CollectionHelper.isNotEmpty( joinColumnList ) ) {
|
||||
if ( joinColumnList.size() == 1 ) {
|
||||
return parserJoinColumn( joinColumnList.get( 0 ), target );
|
||||
}
|
||||
|
@ -45,7 +45,7 @@
|
||||
* @author Strong Liu
|
||||
*/
|
||||
class AttributesBuilder extends AbstractAttributesBuilder {
|
||||
private JaxbAttributes attributes;
|
||||
private final JaxbAttributes attributes;
|
||||
|
||||
AttributesBuilder(IndexBuilder indexBuilder, ClassInfo classInfo, JaxbAccessType accessType, EntityMappingsMocker.Default defaults, JaxbAttributes attributes) {
|
||||
super( indexBuilder, classInfo, defaults );
|
||||
@ -53,8 +53,8 @@ class AttributesBuilder extends AbstractAttributesBuilder {
|
||||
}
|
||||
|
||||
@Override
|
||||
List<JaxbBasic> getBasic() {
|
||||
return attributes.getBasic();
|
||||
protected AttributesContainer getAttributesContainer() {
|
||||
return attributes;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -62,46 +62,11 @@ List<JaxbId> getId() {
|
||||
return attributes.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
List<JaxbTransient> getTransient() {
|
||||
return attributes.getTransient();
|
||||
}
|
||||
|
||||
@Override
|
||||
List<JaxbVersion> getVersion() {
|
||||
return attributes.getVersion();
|
||||
}
|
||||
|
||||
@Override
|
||||
List<JaxbElementCollection> getElementCollection() {
|
||||
return attributes.getElementCollection();
|
||||
}
|
||||
|
||||
@Override
|
||||
List<JaxbEmbedded> getEmbedded() {
|
||||
return attributes.getEmbedded();
|
||||
}
|
||||
|
||||
@Override
|
||||
List<JaxbManyToMany> getManyToMany() {
|
||||
return attributes.getManyToMany();
|
||||
}
|
||||
|
||||
@Override
|
||||
List<JaxbManyToOne> getManyToOne() {
|
||||
return attributes.getManyToOne();
|
||||
}
|
||||
|
||||
@Override
|
||||
List<JaxbOneToMany> getOneToMany() {
|
||||
return attributes.getOneToMany();
|
||||
}
|
||||
|
||||
@Override
|
||||
List<JaxbOneToOne> getOneToOne() {
|
||||
return attributes.getOneToOne();
|
||||
}
|
||||
|
||||
@Override
|
||||
JaxbEmbeddedId getEmbeddedId() {
|
||||
return attributes.getEmbeddedId();
|
||||
|
@ -0,0 +1,35 @@
|
||||
package org.hibernate.metamodel.internal.source.annotations.xml.mocker;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.hibernate.internal.jaxb.mapping.orm.JaxbBasic;
|
||||
import org.hibernate.internal.jaxb.mapping.orm.JaxbElementCollection;
|
||||
import org.hibernate.internal.jaxb.mapping.orm.JaxbEmbedded;
|
||||
import org.hibernate.internal.jaxb.mapping.orm.JaxbManyToMany;
|
||||
import org.hibernate.internal.jaxb.mapping.orm.JaxbManyToOne;
|
||||
import org.hibernate.internal.jaxb.mapping.orm.JaxbOneToMany;
|
||||
import org.hibernate.internal.jaxb.mapping.orm.JaxbOneToOne;
|
||||
import org.hibernate.internal.jaxb.mapping.orm.JaxbTransient;
|
||||
|
||||
/**
|
||||
* @author Strong Liu <stliu@hibernate.org>
|
||||
*/
|
||||
public interface AttributesContainer {
|
||||
|
||||
List<JaxbTransient> getTransient();
|
||||
|
||||
List<JaxbBasic> getBasic();
|
||||
|
||||
List<JaxbElementCollection> getElementCollection();
|
||||
|
||||
List<JaxbEmbedded> getEmbedded();
|
||||
|
||||
List<JaxbManyToMany> getManyToMany();
|
||||
|
||||
List<JaxbManyToOne> getManyToOne();
|
||||
|
||||
List<JaxbOneToMany> getOneToMany();
|
||||
|
||||
List<JaxbOneToOne> getOneToOne();
|
||||
|
||||
}
|
@ -36,7 +36,7 @@
|
||||
* @author Strong Liu
|
||||
*/
|
||||
class BasicMocker extends PropertyMocker {
|
||||
private JaxbBasic basic;
|
||||
private final JaxbBasic basic;
|
||||
|
||||
BasicMocker(IndexBuilder indexBuilder, ClassInfo classInfo, EntityMappingsMocker.Default defaults, JaxbBasic basic) {
|
||||
super( indexBuilder, classInfo, defaults );
|
||||
@ -44,10 +44,9 @@ class BasicMocker extends PropertyMocker {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getFieldName() {
|
||||
return basic.getName();
|
||||
protected PropertyElement getPropertyElement() {
|
||||
return basic;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void processExtra() {
|
||||
List<AnnotationValue> annotationValueList = new ArrayList<AnnotationValue>();
|
||||
@ -60,15 +59,4 @@ protected void processExtra() {
|
||||
parserTemporalType( basic.getTemporal(), getTarget() );
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected JaxbAccessType getAccessType() {
|
||||
return basic.getAccess();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setAccessType(JaxbAccessType accessType) {
|
||||
basic.setAccess( accessType );
|
||||
}
|
||||
}
|
||||
|
@ -100,20 +100,11 @@ void applyDefaults(Map<DotName, List<AnnotationInstance>> annotationsMap, Entity
|
||||
}
|
||||
}
|
||||
|
||||
void applyDefaults(JaxbMappedSuperclass mappedSuperclass, EntityMappingsMocker.Default defaults) {
|
||||
applyDefaultsToEntityObject( new MappedSuperClassEntityObject( mappedSuperclass ), defaults );
|
||||
void applyDefaults(EntityElement entityElement, EntityMappingsMocker.Default defaults) {
|
||||
applyDefaultsToEntityObject( entityElement , defaults );
|
||||
}
|
||||
|
||||
void applyDefaults(JaxbEmbeddable embeddable, EntityMappingsMocker.Default defaults) {
|
||||
applyDefaultsToEntityObject( new EmbeddableEntityObject( embeddable ), defaults );
|
||||
}
|
||||
|
||||
void applyDefaults(JaxbEntity entity, EntityMappingsMocker.Default defaults) {
|
||||
mockTableIfNonExist( entity, defaults );
|
||||
applyDefaultsToEntityObject( new EntityEntityObject( entity ), defaults );
|
||||
}
|
||||
|
||||
private void applyDefaultsToEntityObject(EntityObject entityObject, EntityMappingsMocker.Default defaults) {
|
||||
private void applyDefaultsToEntityObject(EntityElement entityObject, EntityMappingsMocker.Default defaults) {
|
||||
if ( defaults == null ) {
|
||||
return;
|
||||
}
|
||||
@ -162,16 +153,6 @@ private void mockTableIfNonExist(Map<DotName, List<AnnotationInstance>> annotati
|
||||
}
|
||||
}
|
||||
|
||||
private void mockTableIfNonExist(JaxbEntity entity, EntityMappingsMocker.Default defaults) {
|
||||
if ( hasSchemaOrCatalogDefined( defaults ) ) {
|
||||
JaxbTable table = entity.getTable();
|
||||
if ( table == null ) {
|
||||
table = new JaxbTable();
|
||||
entity.setTable( table );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void addCascadePersistIfNotExist(DotName annName, Map<DotName, List<AnnotationInstance>> indexedAnnotationMap) {
|
||||
List<AnnotationInstance> annotationInstanceList = indexedAnnotationMap.get( annName );
|
||||
if ( annotationInstanceList == null || annotationInstanceList.isEmpty() ) {
|
||||
@ -292,98 +273,6 @@ private AnnotationInstance overrideSchemaCatalogByDefault(AnnotationInstance ann
|
||||
);
|
||||
}
|
||||
|
||||
private static interface EntityObject {
|
||||
String getClazz();
|
||||
|
||||
void setClazz(String className);
|
||||
|
||||
Boolean isMetadataComplete();
|
||||
|
||||
void setMetadataComplete(Boolean isMetadataComplete);
|
||||
}
|
||||
|
||||
private static class EntityEntityObject implements EntityObject {
|
||||
private JaxbEntity entity;
|
||||
|
||||
private EntityEntityObject(JaxbEntity entity) {
|
||||
this.entity = entity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getClazz() {
|
||||
return entity.getClazz();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setClazz(String className) {
|
||||
entity.setClazz( className );
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean isMetadataComplete() {
|
||||
return entity.isMetadataComplete();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMetadataComplete(Boolean isMetadataComplete) {
|
||||
entity.setMetadataComplete( isMetadataComplete );
|
||||
}
|
||||
}
|
||||
|
||||
private static class EmbeddableEntityObject implements EntityObject {
|
||||
private JaxbEmbeddable entity;
|
||||
|
||||
private EmbeddableEntityObject(JaxbEmbeddable entity) {
|
||||
this.entity = entity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getClazz() {
|
||||
return entity.getClazz();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setClazz(String className) {
|
||||
entity.setClazz( className );
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean isMetadataComplete() {
|
||||
return entity.isMetadataComplete();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMetadataComplete(Boolean isMetadataComplete) {
|
||||
entity.setMetadataComplete( isMetadataComplete );
|
||||
}
|
||||
}
|
||||
|
||||
private static class MappedSuperClassEntityObject implements EntityObject {
|
||||
private JaxbMappedSuperclass entity;
|
||||
|
||||
private MappedSuperClassEntityObject(JaxbMappedSuperclass entity) {
|
||||
this.entity = entity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getClazz() {
|
||||
return entity.getClazz();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setClazz(String className) {
|
||||
entity.setClazz( className );
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean isMetadataComplete() {
|
||||
return entity.isMetadataComplete();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMetadataComplete(Boolean isMetadataComplete) {
|
||||
entity.setMetadataComplete( isMetadataComplete );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -36,13 +36,18 @@
|
||||
* @author Strong Liu
|
||||
*/
|
||||
class ElementCollectionMocker extends PropertyMocker {
|
||||
private JaxbElementCollection elementCollection;
|
||||
private final JaxbElementCollection elementCollection;
|
||||
|
||||
ElementCollectionMocker(IndexBuilder indexBuilder, ClassInfo classInfo, EntityMappingsMocker.Default defaults, JaxbElementCollection elementCollection) {
|
||||
super( indexBuilder, classInfo, defaults );
|
||||
this.elementCollection = elementCollection;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected PropertyElement getPropertyElement() {
|
||||
return elementCollection;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void processExtra() {
|
||||
List<AnnotationValue> annotationValueList = new ArrayList<AnnotationValue>();
|
||||
@ -72,19 +77,4 @@ protected void processExtra() {
|
||||
parserMapKeyEnumerated( elementCollection.getMapKeyEnumerated(), getTarget() );
|
||||
parserMapKeyTemporal( elementCollection.getMapKeyTemporal(), getTarget() );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getFieldName() {
|
||||
return elementCollection.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JaxbAccessType getAccessType() {
|
||||
return elementCollection.getAccess();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setAccessType(JaxbAccessType accessType) {
|
||||
elementCollection.setAccess( accessType );
|
||||
}
|
||||
}
|
||||
|
@ -46,7 +46,7 @@
|
||||
* @author Strong Liu
|
||||
*/
|
||||
class EmbeddableAttributesBuilder extends AbstractAttributesBuilder {
|
||||
private JaxbEmbeddableAttributes attributes;
|
||||
private final JaxbEmbeddableAttributes attributes;
|
||||
|
||||
EmbeddableAttributesBuilder(IndexBuilder indexBuilder, ClassInfo classInfo, JaxbAccessType accessType, EntityMappingsMocker.Default defaults, JaxbEmbeddableAttributes embeddableAttributes) {
|
||||
super( indexBuilder, classInfo, defaults );
|
||||
@ -54,55 +54,18 @@ class EmbeddableAttributesBuilder extends AbstractAttributesBuilder {
|
||||
}
|
||||
|
||||
@Override
|
||||
List<JaxbBasic> getBasic() {
|
||||
return attributes.getBasic();
|
||||
protected AttributesContainer getAttributesContainer() {
|
||||
return attributes;
|
||||
}
|
||||
|
||||
@Override
|
||||
List<JaxbId> getId() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
List<JaxbTransient> getTransient() {
|
||||
return attributes.getTransient();
|
||||
}
|
||||
|
||||
@Override
|
||||
List<JaxbVersion> getVersion() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
List<JaxbElementCollection> getElementCollection() {
|
||||
return attributes.getElementCollection();
|
||||
}
|
||||
|
||||
@Override
|
||||
List<JaxbEmbedded> getEmbedded() {
|
||||
return attributes.getEmbedded();
|
||||
}
|
||||
|
||||
@Override
|
||||
List<JaxbManyToMany> getManyToMany() {
|
||||
return attributes.getManyToMany();
|
||||
}
|
||||
|
||||
@Override
|
||||
List<JaxbManyToOne> getManyToOne() {
|
||||
return attributes.getManyToOne();
|
||||
}
|
||||
|
||||
@Override
|
||||
List<JaxbOneToMany> getOneToMany() {
|
||||
return attributes.getOneToMany();
|
||||
}
|
||||
|
||||
@Override
|
||||
List<JaxbOneToOne> getOneToOne() {
|
||||
return attributes.getOneToOne();
|
||||
}
|
||||
|
||||
@Override
|
||||
JaxbEmbeddedId getEmbeddedId() {
|
||||
return null;
|
||||
|
@ -45,11 +45,7 @@
|
||||
* @author Strong Liu
|
||||
*/
|
||||
class EmbeddableMocker extends AbstractEntityObjectMocker {
|
||||
private static final CoreMessageLogger LOG = Logger.getMessageLogger(
|
||||
CoreMessageLogger.class,
|
||||
EmbeddableMocker.class.getName()
|
||||
);
|
||||
private JaxbEmbeddable embeddable;
|
||||
private final JaxbEmbeddable embeddable;
|
||||
|
||||
EmbeddableMocker(IndexBuilder indexBuilder, JaxbEmbeddable embeddable, EntityMappingsMocker.Default defaults) {
|
||||
super( indexBuilder, defaults );
|
||||
@ -60,27 +56,22 @@ class EmbeddableMocker extends AbstractEntityObjectMocker {
|
||||
protected AbstractAttributesBuilder getAttributesBuilder() {
|
||||
if ( attributesBuilder == null ) {
|
||||
attributesBuilder = new EmbeddableAttributesBuilder(
|
||||
indexBuilder, classInfo, getAccessType(), getDefaults(), embeddable.getAttributes()
|
||||
indexBuilder, classInfo, embeddable.getAccess(), getDefaults(), embeddable.getAttributes()
|
||||
);
|
||||
}
|
||||
return attributesBuilder;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EntityElement getEntityElement() {
|
||||
return embeddable;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void processExtra() {
|
||||
create( EMBEDDABLE );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void applyDefaults() {
|
||||
DefaultConfigurationHelper.INSTANCE.applyDefaults( embeddable, getDefaults() );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isMetadataComplete() {
|
||||
return embeddable.isMetadataComplete() != null && embeddable.isMetadataComplete();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isExcludeDefaultListeners() {
|
||||
return false;
|
||||
@ -101,16 +92,6 @@ protected JaxbEntityListeners getEntityListeners() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JaxbAccessType getAccessType() {
|
||||
return embeddable.getAccess();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getClassName() {
|
||||
return embeddable.getClazz();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JaxbPrePersist getPrePersist() {
|
||||
return null;
|
||||
|
@ -32,7 +32,7 @@
|
||||
* @author Strong Liu
|
||||
*/
|
||||
class EmbeddedIdMocker extends PropertyMocker {
|
||||
private JaxbEmbeddedId embeddedId;
|
||||
private final JaxbEmbeddedId embeddedId;
|
||||
|
||||
EmbeddedIdMocker(IndexBuilder indexBuilder, ClassInfo classInfo, EntityMappingsMocker.Default defaults, JaxbEmbeddedId embeddedId) {
|
||||
super( indexBuilder, classInfo, defaults );
|
||||
@ -40,22 +40,12 @@ class EmbeddedIdMocker extends PropertyMocker {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getFieldName() {
|
||||
return embeddedId.getName();
|
||||
protected PropertyElement getPropertyElement() {
|
||||
return embeddedId;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void processExtra() {
|
||||
create( EMBEDDED_ID );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JaxbAccessType getAccessType() {
|
||||
return embeddedId.getAccess();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setAccessType(JaxbAccessType accessType) {
|
||||
embeddedId.setAccess( accessType );
|
||||
}
|
||||
}
|
||||
|
@ -32,7 +32,7 @@
|
||||
* @author Strong Liu
|
||||
*/
|
||||
class EmbeddedMocker extends PropertyMocker {
|
||||
private JaxbEmbedded embedded;
|
||||
private final JaxbEmbedded embedded;
|
||||
|
||||
EmbeddedMocker(IndexBuilder indexBuilder, ClassInfo classInfo, EntityMappingsMocker.Default defaults, JaxbEmbedded embedded) {
|
||||
super( indexBuilder, classInfo, defaults );
|
||||
@ -48,17 +48,7 @@ protected void processExtra() {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getFieldName() {
|
||||
return embedded.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JaxbAccessType getAccessType() {
|
||||
return embedded.getAccess();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setAccessType(JaxbAccessType accessType) {
|
||||
embedded.setAccess( accessType );
|
||||
protected PropertyElement getPropertyElement() {
|
||||
return embedded;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,17 @@
|
||||
package org.hibernate.metamodel.internal.source.annotations.xml.mocker;
|
||||
|
||||
import org.hibernate.internal.jaxb.mapping.orm.JaxbAccessType;
|
||||
|
||||
/**
|
||||
* @author Strong Liu <stliu@hibernate.org>
|
||||
*/
|
||||
public interface EntityElement {
|
||||
String getClazz();
|
||||
|
||||
void setClazz(String className);
|
||||
|
||||
Boolean isMetadataComplete();
|
||||
|
||||
void setMetadataComplete(Boolean isMetadataComplete);
|
||||
public JaxbAccessType getAccess();
|
||||
}
|
@ -65,7 +65,8 @@ public EntityMappingsMocker(List<JaxbEntityMappings> entityMappingsList, Index i
|
||||
}
|
||||
|
||||
/**
|
||||
* Create new {@link Index} with mocking JPA annotations from {@link org.hibernate.internal.jaxb.mapping.orm.JaxbEntityMappings} and merge them with existing {@link Index}
|
||||
* Create new {@link Index} with mocking JPA annotations from {@link org.hibernate.internal.jaxb.mapping.orm.JaxbEntityMappings}
|
||||
* and merge them with existing {@link Index}
|
||||
*
|
||||
* @return new {@link Index}
|
||||
*/
|
||||
|
@ -53,6 +53,7 @@
|
||||
import org.hibernate.internal.jaxb.mapping.orm.JaxbSecondaryTable;
|
||||
import org.hibernate.internal.jaxb.mapping.orm.JaxbTable;
|
||||
import org.hibernate.internal.util.StringHelper;
|
||||
import org.hibernate.internal.util.collections.CollectionHelper;
|
||||
|
||||
/**
|
||||
* Mock <entity> to {@link javax.persistence.Entity @Entity}
|
||||
@ -60,22 +61,13 @@
|
||||
* @author Strong Liu
|
||||
*/
|
||||
class EntityMocker extends AbstractEntityObjectMocker {
|
||||
private static final CoreMessageLogger LOG = Logger.getMessageLogger(
|
||||
CoreMessageLogger.class,
|
||||
EntityMocker.class.getName()
|
||||
);
|
||||
private JaxbEntity entity;
|
||||
private final JaxbEntity entity;
|
||||
|
||||
EntityMocker(IndexBuilder indexBuilder, JaxbEntity entity, EntityMappingsMocker.Default defaults) {
|
||||
super( indexBuilder, defaults );
|
||||
this.entity = entity;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getClassName() {
|
||||
return entity.getClazz();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void processExtra() {
|
||||
//@Entity
|
||||
@ -134,7 +126,7 @@ protected AccessType getDefaultAccess() {
|
||||
protected AccessType getAccessFromIndex(DotName className) {
|
||||
Map<DotName, List<AnnotationInstance>> indexedAnnotations = indexBuilder.getIndexedAnnotations( className );
|
||||
List<AnnotationInstance> accessAnnotationInstances = indexedAnnotations.get( ACCESS );
|
||||
if ( MockHelper.isNotEmpty( accessAnnotationInstances ) ) {
|
||||
if ( CollectionHelper.isNotEmpty( accessAnnotationInstances ) ) {
|
||||
for ( AnnotationInstance annotationInstance : accessAnnotationInstances ) {
|
||||
if ( annotationInstance.target() != null && annotationInstance.target() instanceof ClassInfo ) {
|
||||
ClassInfo ci = (ClassInfo) ( annotationInstance.target() );
|
||||
@ -149,8 +141,8 @@ protected AccessType getAccessFromIndex(DotName className) {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void applyDefaults() {
|
||||
DefaultConfigurationHelper.INSTANCE.applyDefaults( entity, getDefaults() );
|
||||
protected EntityElement getEntityElement() {
|
||||
return entity;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -193,10 +185,6 @@ protected JaxbAttributes getAttributes() {
|
||||
return entity.getAttributes();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isMetadataComplete() {
|
||||
return entity.isMetadataComplete() != null && entity.isMetadataComplete();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isExcludeDefaultListeners() {
|
||||
@ -218,11 +206,6 @@ protected JaxbEntityListeners getEntityListeners() {
|
||||
return entity.getEntityListeners();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JaxbAccessType getAccessType() {
|
||||
return entity.getAccess();
|
||||
}
|
||||
|
||||
//@Inheritance
|
||||
protected AnnotationInstance parserInheritance(JaxbInheritance inheritance) {
|
||||
if ( inheritance == null ) {
|
||||
@ -250,11 +233,7 @@ protected AnnotationInstance parserDiscriminatorColumn(JaxbDiscriminatorColumn d
|
||||
MockHelper.enumValue(
|
||||
"discriminatorType", DISCRIMINATOR_TYPE, discriminatorColumn.getDiscriminatorType(), annotationValueList
|
||||
);
|
||||
return
|
||||
create(
|
||||
DISCRIMINATOR_COLUMN, annotationValueList
|
||||
|
||||
);
|
||||
return create(DISCRIMINATOR_COLUMN, annotationValueList);
|
||||
|
||||
}
|
||||
|
||||
@ -282,7 +261,7 @@ protected AnnotationInstance parserSecondaryTable(JaxbSecondaryTable secondaryTa
|
||||
|
||||
|
||||
protected AnnotationInstance parserSecondaryTableList(List<JaxbSecondaryTable> primaryKeyJoinColumnList, AnnotationTarget target) {
|
||||
if ( MockHelper.isNotEmpty( primaryKeyJoinColumnList ) ) {
|
||||
if ( CollectionHelper.isNotEmpty( primaryKeyJoinColumnList ) ) {
|
||||
if ( primaryKeyJoinColumnList.size() == 1 ) {
|
||||
return parserSecondaryTable( primaryKeyJoinColumnList.get( 0 ), target );
|
||||
}
|
||||
@ -299,7 +278,7 @@ protected AnnotationInstance parserSecondaryTableList(List<JaxbSecondaryTable> p
|
||||
}
|
||||
|
||||
protected AnnotationValue[] nestedSecondaryTableList(String name, List<JaxbSecondaryTable> secondaryTableList, List<AnnotationValue> annotationValueList) {
|
||||
if ( MockHelper.isNotEmpty( secondaryTableList ) ) {
|
||||
if ( CollectionHelper.isNotEmpty( secondaryTableList ) ) {
|
||||
AnnotationValue[] values = new AnnotationValue[secondaryTableList.size()];
|
||||
for ( int i = 0; i < secondaryTableList.size(); i++ ) {
|
||||
AnnotationInstance annotationInstance = parserSecondaryTable( secondaryTableList.get( i ), null );
|
||||
|
@ -40,6 +40,7 @@
|
||||
import org.hibernate.internal.jaxb.mapping.orm.JaxbSequenceGenerator;
|
||||
import org.hibernate.internal.jaxb.mapping.orm.JaxbSqlResultSetMapping;
|
||||
import org.hibernate.internal.jaxb.mapping.orm.JaxbTableGenerator;
|
||||
import org.hibernate.internal.util.collections.CollectionHelper;
|
||||
|
||||
/**
|
||||
* @author Strong Liu
|
||||
@ -139,7 +140,7 @@ private AnnotationInstance parserEntityResult(JaxbEntityResult result) {
|
||||
}
|
||||
|
||||
private void nestedEntityResultList(String name, List<JaxbEntityResult> entityResults, List<AnnotationValue> annotationValueList) {
|
||||
if ( MockHelper.isNotEmpty( entityResults ) ) {
|
||||
if ( CollectionHelper.isNotEmpty( entityResults ) ) {
|
||||
AnnotationValue[] values = new AnnotationValue[entityResults.size()];
|
||||
for ( int i = 0; i < entityResults.size(); i++ ) {
|
||||
AnnotationInstance annotationInstance = parserEntityResult( entityResults.get( i ) );
|
||||
@ -159,7 +160,7 @@ private AnnotationInstance parserColumnResult(JaxbColumnResult result) {
|
||||
}
|
||||
|
||||
private void nestedColumnResultList(String name, List<JaxbColumnResult> columnResults, List<AnnotationValue> annotationValueList) {
|
||||
if ( MockHelper.isNotEmpty( columnResults ) ) {
|
||||
if ( CollectionHelper.isNotEmpty( columnResults ) ) {
|
||||
AnnotationValue[] values = new AnnotationValue[columnResults.size()];
|
||||
for ( int i = 0; i < columnResults.size(); i++ ) {
|
||||
AnnotationInstance annotationInstance = parserColumnResult( columnResults.get( i ) );
|
||||
@ -183,7 +184,7 @@ private AnnotationInstance parserFieldResult(JaxbFieldResult result) {
|
||||
|
||||
|
||||
private void nestedFieldResultList(String name, List<JaxbFieldResult> fieldResultList, List<AnnotationValue> annotationValueList) {
|
||||
if ( MockHelper.isNotEmpty( fieldResultList ) ) {
|
||||
if ( CollectionHelper.isNotEmpty( fieldResultList ) ) {
|
||||
AnnotationValue[] values = new AnnotationValue[fieldResultList.size()];
|
||||
for ( int i = 0; i < fieldResultList.size(); i++ ) {
|
||||
AnnotationInstance annotationInstance = parserFieldResult( fieldResultList.get( i ) );
|
||||
@ -270,7 +271,7 @@ private AnnotationInstance parserQueryHint(JaxbQueryHint queryHint) {
|
||||
}
|
||||
|
||||
private void nestedQueryHintList(String name, List<JaxbQueryHint> constraints, List<AnnotationValue> annotationValueList) {
|
||||
if ( MockHelper.isNotEmpty( constraints ) ) {
|
||||
if ( CollectionHelper.isNotEmpty( constraints ) ) {
|
||||
AnnotationValue[] values = new AnnotationValue[constraints.size()];
|
||||
for ( int i = 0; i < constraints.size(); i++ ) {
|
||||
AnnotationInstance annotationInstance = parserQueryHint( constraints.get( i ) );
|
||||
|
@ -46,6 +46,7 @@
|
||||
import org.hibernate.internal.jaxb.mapping.orm.JaxbSqlResultSetMapping;
|
||||
import org.hibernate.internal.jaxb.mapping.orm.JaxbTableGenerator;
|
||||
import org.hibernate.internal.util.StringHelper;
|
||||
import org.hibernate.internal.util.collections.CollectionHelper;
|
||||
import org.hibernate.metamodel.internal.source.annotations.util.JPADotNames;
|
||||
import org.hibernate.metamodel.spi.source.MappingException;
|
||||
|
||||
@ -57,18 +58,18 @@ class GlobalAnnotations implements JPADotNames {
|
||||
CoreMessageLogger.class,
|
||||
GlobalAnnotations.class.getName()
|
||||
);
|
||||
private Map<String, JaxbSequenceGenerator> sequenceGeneratorMap = new HashMap<String, JaxbSequenceGenerator>();
|
||||
private Map<String, JaxbTableGenerator> tableGeneratorMap = new HashMap<String, JaxbTableGenerator>();
|
||||
private Map<String, JaxbNamedQuery> namedQueryMap = new HashMap<String, JaxbNamedQuery>();
|
||||
private Map<String, JaxbNamedNativeQuery> namedNativeQueryMap = new HashMap<String, JaxbNamedNativeQuery>();
|
||||
private Map<String, JaxbSqlResultSetMapping> sqlResultSetMappingMap = new HashMap<String, JaxbSqlResultSetMapping>();
|
||||
private Map<DotName, List<AnnotationInstance>> annotationInstanceMap = new HashMap<DotName, List<AnnotationInstance>>();
|
||||
private List<AnnotationInstance> indexedAnnotationInstanceList = new ArrayList<AnnotationInstance>();
|
||||
private final Map<String, JaxbSequenceGenerator> sequenceGeneratorMap = new HashMap<String, JaxbSequenceGenerator>();
|
||||
private final Map<String, JaxbTableGenerator> tableGeneratorMap = new HashMap<String, JaxbTableGenerator>();
|
||||
private final Map<String, JaxbNamedQuery> namedQueryMap = new HashMap<String, JaxbNamedQuery>();
|
||||
private final Map<String, JaxbNamedNativeQuery> namedNativeQueryMap = new HashMap<String, JaxbNamedNativeQuery>();
|
||||
private final Map<String, JaxbSqlResultSetMapping> sqlResultSetMappingMap = new HashMap<String, JaxbSqlResultSetMapping>();
|
||||
private final Map<DotName, List<AnnotationInstance>> annotationInstanceMap = new HashMap<DotName, List<AnnotationInstance>>();
|
||||
private final List<AnnotationInstance> indexedAnnotationInstanceList = new ArrayList<AnnotationInstance>();
|
||||
//---------------------------
|
||||
private Set<String> defaultNamedNativeQueryNames = new HashSet<String>();
|
||||
private Set<String> defaultNamedQueryNames = new HashSet<String>();
|
||||
private Set<String> defaultNamedGenerators = new HashSet<String>();
|
||||
private Set<String> defaultSqlResultSetMappingNames = new HashSet<String>();
|
||||
private final Set<String> defaultNamedNativeQueryNames = new HashSet<String>();
|
||||
private final Set<String> defaultNamedQueryNames = new HashSet<String>();
|
||||
private final Set<String> defaultNamedGenerators = new HashSet<String>();
|
||||
private final Set<String> defaultSqlResultSetMappingNames = new HashSet<String>();
|
||||
|
||||
Map<DotName, List<AnnotationInstance>> getAnnotationInstanceMap() {
|
||||
return annotationInstanceMap;
|
||||
@ -89,7 +90,7 @@ AnnotationInstance push(DotName name, AnnotationInstance annotationInstance) {
|
||||
|
||||
|
||||
void addIndexedAnnotationInstance(List<AnnotationInstance> annotationInstanceList) {
|
||||
if ( MockHelper.isNotEmpty( annotationInstanceList ) ) {
|
||||
if ( CollectionHelper.isNotEmpty( annotationInstanceList ) ) {
|
||||
indexedAnnotationInstanceList.addAll( annotationInstanceList );
|
||||
}
|
||||
}
|
||||
@ -98,8 +99,11 @@ void addIndexedAnnotationInstance(List<AnnotationInstance> annotationInstanceLis
|
||||
* do the orm xmls define global configurations?
|
||||
*/
|
||||
boolean hasGlobalConfiguration() {
|
||||
return !( namedQueryMap.isEmpty() && namedNativeQueryMap.isEmpty() && sequenceGeneratorMap.isEmpty() && tableGeneratorMap
|
||||
.isEmpty() && sqlResultSetMappingMap.isEmpty() );
|
||||
return !( namedQueryMap.isEmpty()
|
||||
&& namedNativeQueryMap.isEmpty()
|
||||
&& sequenceGeneratorMap.isEmpty()
|
||||
&& tableGeneratorMap.isEmpty()
|
||||
&& sqlResultSetMappingMap.isEmpty() );
|
||||
}
|
||||
|
||||
Map<String, JaxbNamedNativeQuery> getNamedNativeQueryMap() {
|
||||
@ -227,34 +231,13 @@ void collectGlobalMappings(JaxbEntity entity, EntityMappingsMocker.Default defau
|
||||
/**
|
||||
* Override SequenceGenerator using info definded in EntityMappings/Persistence-Metadata-Unit
|
||||
*/
|
||||
private static JaxbSequenceGenerator overrideGenerator(JaxbSequenceGenerator generator, EntityMappingsMocker.Default defaults) {
|
||||
private static void overrideGenerator(SchemaAware generator, EntityMappingsMocker.Default defaults) {
|
||||
if ( StringHelper.isEmpty( generator.getSchema() ) && defaults != null ) {
|
||||
generator.setSchema( defaults.getSchema() );
|
||||
}
|
||||
if ( StringHelper.isEmpty( generator.getCatalog() ) && defaults != null ) {
|
||||
generator.setCatalog( defaults.getCatalog() );
|
||||
}
|
||||
return generator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Override TableGenerator using info definded in EntityMappings/Persistence-Metadata-Unit
|
||||
*/
|
||||
private static JaxbTableGenerator overrideGenerator(JaxbTableGenerator generator, EntityMappingsMocker.Default defaults) {
|
||||
if ( StringHelper.isEmpty( generator.getSchema() ) && defaults != null ) {
|
||||
generator.setSchema( defaults.getSchema() );
|
||||
}
|
||||
if ( StringHelper.isEmpty( generator.getCatalog() ) && defaults != null ) {
|
||||
generator.setCatalog( defaults.getCatalog() );
|
||||
}
|
||||
return generator;
|
||||
}
|
||||
|
||||
private void put(JaxbNamedNativeQuery query) {
|
||||
if ( query != null ) {
|
||||
checkQueryName( query.getName() );
|
||||
namedNativeQueryMap.put( query.getName(), query );
|
||||
}
|
||||
}
|
||||
|
||||
private void checkQueryName(String name) {
|
||||
@ -262,6 +245,11 @@ private void checkQueryName(String name) {
|
||||
throw new MappingException( "Duplicated query mapping " + name, null );
|
||||
}
|
||||
}
|
||||
private void checkDuplicated(Object old, String name){
|
||||
if ( old != null ) {
|
||||
LOG.duplicateGeneratorName( name );
|
||||
}
|
||||
}
|
||||
|
||||
private void put(JaxbNamedQuery query) {
|
||||
if ( query != null ) {
|
||||
@ -272,19 +260,23 @@ private void put(JaxbNamedQuery query) {
|
||||
|
||||
private void put(JaxbSequenceGenerator generator, EntityMappingsMocker.Default defaults) {
|
||||
if ( generator != null ) {
|
||||
Object old = sequenceGeneratorMap.put( generator.getName(), overrideGenerator( generator, defaults ) );
|
||||
if ( old != null ) {
|
||||
LOG.duplicateGeneratorName( generator.getName() );
|
||||
}
|
||||
overrideGenerator( generator, defaults );
|
||||
Object old = sequenceGeneratorMap.put( generator.getName(), generator );
|
||||
checkDuplicated( old, generator.getName() );
|
||||
}
|
||||
}
|
||||
|
||||
private void put(JaxbTableGenerator generator, EntityMappingsMocker.Default defaults) {
|
||||
if ( generator != null ) {
|
||||
Object old = tableGeneratorMap.put( generator.getName(), overrideGenerator( generator, defaults ) );
|
||||
if ( old != null ) {
|
||||
LOG.duplicateGeneratorName( generator.getName() );
|
||||
}
|
||||
overrideGenerator( generator, defaults );
|
||||
Object old = tableGeneratorMap.put( generator.getName(), generator );
|
||||
checkDuplicated( old, generator.getName() );
|
||||
}
|
||||
}
|
||||
private void put(JaxbNamedNativeQuery query) {
|
||||
if ( query != null ) {
|
||||
checkQueryName( query.getName() );
|
||||
namedNativeQueryMap.put( query.getName(), query );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -39,13 +39,18 @@
|
||||
* @author Strong Liu
|
||||
*/
|
||||
class IdMocker extends PropertyMocker {
|
||||
private JaxbId id;
|
||||
private final JaxbId id;
|
||||
|
||||
IdMocker(IndexBuilder indexBuilder, ClassInfo classInfo, EntityMappingsMocker.Default defaults, JaxbId id) {
|
||||
super( indexBuilder, classInfo, defaults );
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected PropertyElement getPropertyElement() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void processExtra() {
|
||||
create( ID );
|
||||
@ -66,19 +71,4 @@ private AnnotationInstance parserGeneratedValue(JaxbGeneratedValue generatedValu
|
||||
|
||||
return create( GENERATED_VALUE, target, annotationValueList );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getFieldName() {
|
||||
return id.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JaxbAccessType getAccessType() {
|
||||
return id.getAccess();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setAccessType(JaxbAccessType accessType) {
|
||||
id.setAccess( accessType );
|
||||
}
|
||||
}
|
||||
|
@ -38,6 +38,7 @@
|
||||
import org.hibernate.AssertionFailure;
|
||||
import org.hibernate.internal.CoreMessageLogger;
|
||||
import org.hibernate.internal.util.StringHelper;
|
||||
import org.hibernate.internal.util.collections.CollectionHelper;
|
||||
import org.hibernate.metamodel.internal.source.annotations.xml.filter.IndexedAnnotationFilter;
|
||||
import org.hibernate.service.ServiceRegistry;
|
||||
import org.hibernate.service.classloading.spi.ClassLoaderService;
|
||||
@ -50,14 +51,14 @@ public class IndexBuilder {
|
||||
CoreMessageLogger.class,
|
||||
IndexBuilder.class.getName()
|
||||
);
|
||||
private Map<DotName, List<AnnotationInstance>> annotations;
|
||||
private Map<DotName, List<ClassInfo>> subclasses;
|
||||
private Map<DotName, List<ClassInfo>> implementors;
|
||||
private Map<DotName, ClassInfo> classes;
|
||||
private final Map<DotName, List<AnnotationInstance>> annotations;
|
||||
private final Map<DotName, List<ClassInfo>> subclasses;
|
||||
private final Map<DotName, List<ClassInfo>> implementors;
|
||||
private final Map<DotName, ClassInfo> classes;
|
||||
private Index index;
|
||||
private Map<DotName, Map<DotName, List<AnnotationInstance>>> classInfoAnnotationsMap;
|
||||
private Map<DotName, Map<DotName, List<AnnotationInstance>>> indexedClassInfoAnnotationsMap;
|
||||
private ServiceRegistry serviceRegistry;
|
||||
private final Map<DotName, Map<DotName, List<AnnotationInstance>>> classInfoAnnotationsMap;
|
||||
private final Map<DotName, Map<DotName, List<AnnotationInstance>>> indexedClassInfoAnnotationsMap;
|
||||
private final ServiceRegistry serviceRegistry;
|
||||
|
||||
IndexBuilder(Index index, ServiceRegistry serviceRegistry) {
|
||||
this.index = index;
|
||||
@ -167,7 +168,7 @@ public ClassInfo getIndexedClassInfo(DotName name) {
|
||||
void collectGlobalConfigurationFromIndex(GlobalAnnotations globalAnnotations) {
|
||||
for ( DotName annName : DefaultConfigurationHelper.GLOBAL_ANNOTATIONS ) {
|
||||
List<AnnotationInstance> annotationInstanceList = index.getAnnotations( annName );
|
||||
if ( MockHelper.isNotEmpty( annotationInstanceList ) ) {
|
||||
if ( CollectionHelper.isNotEmpty( annotationInstanceList ) ) {
|
||||
globalAnnotations.addIndexedAnnotationInstance( annotationInstanceList );
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,8 @@
|
||||
package org.hibernate.metamodel.internal.source.annotations.xml.mocker;
|
||||
|
||||
/**
|
||||
* @author Strong Liu <stliu@hibernate.org>
|
||||
*/
|
||||
public interface Listener {
|
||||
public String getMethodName();
|
||||
}
|
@ -30,6 +30,7 @@
|
||||
import org.jboss.jandex.AnnotationTarget;
|
||||
import org.jboss.jandex.AnnotationValue;
|
||||
import org.jboss.jandex.ClassInfo;
|
||||
import org.jboss.jandex.DotName;
|
||||
|
||||
import org.hibernate.MappingException;
|
||||
import org.hibernate.internal.jaxb.mapping.orm.JaxbEntityListener;
|
||||
@ -73,76 +74,25 @@ private void parserEntityListener(JaxbEntityListener listener) {
|
||||
String clazz = listener.getClazz();
|
||||
ClassInfo tempClassInfo = indexBuilder.createClassInfo( clazz );
|
||||
ListenerMocker mocker = createListenerMocker( indexBuilder, tempClassInfo );
|
||||
mocker.parser( listener.getPostLoad() );
|
||||
mocker.parser( listener.getPostPersist() );
|
||||
mocker.parser( listener.getPostRemove() );
|
||||
mocker.parser( listener.getPostUpdate() );
|
||||
mocker.parser( listener.getPrePersist() );
|
||||
mocker.parser( listener.getPreRemove() );
|
||||
mocker.parser( listener.getPreUpdate() );
|
||||
mocker.parser( listener.getPostLoad(), POST_LOAD );
|
||||
mocker.parser( listener.getPostPersist(), POST_PERSIST );
|
||||
mocker.parser( listener.getPostRemove(), POST_REMOVE );
|
||||
mocker.parser( listener.getPostUpdate(), POST_UPDATE );
|
||||
mocker.parser( listener.getPrePersist(), PRE_PERSIST );
|
||||
mocker.parser( listener.getPreRemove(), PRE_REMOVE );
|
||||
mocker.parser( listener.getPreUpdate(), PRE_UPDATE );
|
||||
indexBuilder.finishEntityObject( tempClassInfo.name(), null );
|
||||
}
|
||||
|
||||
protected ListenerMocker createListenerMocker(IndexBuilder indexBuilder, ClassInfo classInfo) {
|
||||
return new ListenerMocker( indexBuilder, classInfo );
|
||||
}
|
||||
|
||||
//@PrePersist
|
||||
AnnotationInstance parser(JaxbPrePersist callback) {
|
||||
AnnotationInstance parser(Listener callback, DotName target) {
|
||||
if ( callback == null ) {
|
||||
return null;
|
||||
}
|
||||
return create( PRE_PERSIST, getListenerTarget( callback.getMethodName() ) );
|
||||
return create( target, getListenerTarget( callback.getMethodName() ) );
|
||||
}
|
||||
|
||||
//@PreRemove
|
||||
AnnotationInstance parser(JaxbPreRemove callback) {
|
||||
if ( callback == null ) {
|
||||
return null;
|
||||
}
|
||||
return create( PRE_REMOVE, getListenerTarget( callback.getMethodName() ) );
|
||||
}
|
||||
|
||||
//@PreUpdate
|
||||
AnnotationInstance parser(JaxbPreUpdate callback) {
|
||||
if ( callback == null ) {
|
||||
return null;
|
||||
}
|
||||
return create( PRE_UPDATE, getListenerTarget( callback.getMethodName() ) );
|
||||
}
|
||||
|
||||
//@PostPersist
|
||||
AnnotationInstance parser(JaxbPostPersist callback) {
|
||||
if ( callback == null ) {
|
||||
return null;
|
||||
}
|
||||
return create( POST_PERSIST, getListenerTarget( callback.getMethodName() ) );
|
||||
}
|
||||
|
||||
//@PostUpdate
|
||||
AnnotationInstance parser(JaxbPostUpdate callback) {
|
||||
if ( callback == null ) {
|
||||
return null;
|
||||
}
|
||||
return create( POST_UPDATE, getListenerTarget( callback.getMethodName() ) );
|
||||
}
|
||||
|
||||
//@PostRemove
|
||||
AnnotationInstance parser(JaxbPostRemove callback) {
|
||||
if ( callback == null ) {
|
||||
return null;
|
||||
}
|
||||
return create( POST_REMOVE, getListenerTarget( callback.getMethodName() ) );
|
||||
}
|
||||
|
||||
//@PostLoad
|
||||
AnnotationInstance parser(JaxbPostLoad callback) {
|
||||
if ( callback == null ) {
|
||||
return null;
|
||||
}
|
||||
return create( POST_LOAD, getListenerTarget( callback.getMethodName() ) );
|
||||
}
|
||||
|
||||
private AnnotationTarget getListenerTarget(String methodName) {
|
||||
return MockHelper.getTarget(
|
||||
indexBuilder.getServiceRegistry(), classInfo, methodName, MockHelper.TargetType.METHOD
|
||||
|
@ -36,19 +36,17 @@
|
||||
* @author Strong Liu
|
||||
*/
|
||||
class ManyToManyMocker extends PropertyMocker {
|
||||
private JaxbManyToMany manyToMany;
|
||||
private final JaxbManyToMany manyToMany;
|
||||
|
||||
ManyToManyMocker(IndexBuilder indexBuilder, ClassInfo classInfo, EntityMappingsMocker.Default defaults, JaxbManyToMany manyToMany) {
|
||||
super( indexBuilder, classInfo, defaults );
|
||||
this.manyToMany = manyToMany;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getFieldName() {
|
||||
return manyToMany.getName();
|
||||
protected PropertyElement getPropertyElement() {
|
||||
return manyToMany;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void processExtra() {
|
||||
List<AnnotationValue> annotationValueList = new ArrayList<AnnotationValue>();
|
||||
@ -71,14 +69,4 @@ protected void processExtra() {
|
||||
create( ORDER_BY, MockHelper.stringValueArray( "value", manyToMany.getOrderBy() ) );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JaxbAccessType getAccessType() {
|
||||
return manyToMany.getAccess();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setAccessType(JaxbAccessType accessType) {
|
||||
manyToMany.setAccess( accessType );
|
||||
}
|
||||
}
|
||||
|
@ -36,7 +36,7 @@
|
||||
* @author Strong Liu
|
||||
*/
|
||||
class ManyToOneMocker extends PropertyMocker {
|
||||
private JaxbManyToOne manyToOne;
|
||||
private final JaxbManyToOne manyToOne;
|
||||
|
||||
ManyToOneMocker(IndexBuilder indexBuilder, ClassInfo classInfo, EntityMappingsMocker.Default defaults, JaxbManyToOne manyToOne) {
|
||||
super( indexBuilder, classInfo, defaults );
|
||||
@ -44,8 +44,8 @@ class ManyToOneMocker extends PropertyMocker {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getFieldName() {
|
||||
return manyToOne.getName();
|
||||
protected PropertyElement getPropertyElement() {
|
||||
return manyToOne;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -67,14 +67,4 @@ protected void processExtra() {
|
||||
create( ID );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JaxbAccessType getAccessType() {
|
||||
return manyToOne.getAccess();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setAccessType(JaxbAccessType accessType) {
|
||||
manyToOne.setAccess( accessType );
|
||||
}
|
||||
}
|
||||
|
@ -57,8 +57,8 @@ class MappedSuperclassMocker extends AbstractEntityObjectMocker {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void applyDefaults() {
|
||||
DefaultConfigurationHelper.INSTANCE.applyDefaults( mappedSuperclass, getDefaults() );
|
||||
protected EntityElement getEntityElement() {
|
||||
return mappedSuperclass;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -70,17 +70,6 @@ protected void processExtra() {
|
||||
protected JaxbAttributes getAttributes() {
|
||||
return mappedSuperclass.getAttributes();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JaxbAccessType getAccessType() {
|
||||
return mappedSuperclass.getAccess();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isMetadataComplete() {
|
||||
return mappedSuperclass.isMetadataComplete() != null && mappedSuperclass.isMetadataComplete();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isExcludeDefaultListeners() {
|
||||
return mappedSuperclass.getExcludeDefaultListeners() != null;
|
||||
@ -101,10 +90,6 @@ protected JaxbEntityListeners getEntityListeners() {
|
||||
return mappedSuperclass.getEntityListeners();
|
||||
}
|
||||
|
||||
protected String getClassName() {
|
||||
return mappedSuperclass.getClazz();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JaxbPrePersist getPrePersist() {
|
||||
return mappedSuperclass.getPrePersist();
|
||||
|
@ -30,6 +30,8 @@
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import javax.persistence.CascadeType;
|
||||
|
||||
import org.jboss.jandex.AnnotationInstance;
|
||||
import org.jboss.jandex.AnnotationTarget;
|
||||
import org.jboss.jandex.AnnotationValue;
|
||||
@ -42,6 +44,7 @@
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.internal.jaxb.mapping.orm.JaxbCascadeType;
|
||||
import org.hibernate.internal.util.StringHelper;
|
||||
import org.hibernate.internal.util.collections.CollectionHelper;
|
||||
import org.hibernate.metamodel.internal.source.annotations.util.JPADotNames;
|
||||
import org.hibernate.service.ServiceRegistry;
|
||||
import org.hibernate.service.classloading.spi.ClassLoaderService;
|
||||
@ -62,7 +65,7 @@ public class MockHelper {
|
||||
* @param annotationValueList
|
||||
*/
|
||||
static void stringArrayValue(String name, List<String> values, List<AnnotationValue> annotationValueList) {
|
||||
if ( isNotEmpty( values ) ) {
|
||||
if ( CollectionHelper.isNotEmpty( values ) ) {
|
||||
AnnotationValue[] annotationValues = new AnnotationValue[values.size()];
|
||||
for ( int j = 0; j < values.size(); j++ ) {
|
||||
annotationValues[j] = stringValue( "", values.get( j ) );
|
||||
@ -149,13 +152,11 @@ static void nestedAnnotationValue(String name, AnnotationInstance value, List<An
|
||||
}
|
||||
|
||||
private static AnnotationValue[] nullSafe(AnnotationValue value) {
|
||||
return value == null ? EMPTY_ANNOTATION_VALUE_ARRAY : new AnnotationValue[] {
|
||||
value
|
||||
};
|
||||
return value == null ? EMPTY_ANNOTATION_VALUE_ARRAY : new AnnotationValue[] {value};
|
||||
}
|
||||
|
||||
static void classArrayValue(String name, List<String> classNameList, List<AnnotationValue> list, ServiceRegistry serviceRegistry) {
|
||||
if ( isNotEmpty( classNameList ) ) {
|
||||
if ( CollectionHelper.isNotEmpty( classNameList ) ) {
|
||||
|
||||
List<AnnotationValue> clazzValueList = new ArrayList<AnnotationValue>( classNameList.size() );
|
||||
for ( String clazz : classNameList ) {
|
||||
@ -172,7 +173,7 @@ name, toArray( clazzValueList )
|
||||
|
||||
public static AnnotationValue[] toArray(List<AnnotationValue> list) {
|
||||
AnnotationValue[] values = EMPTY_ANNOTATION_VALUE_ARRAY;
|
||||
if ( isNotEmpty( list ) ) {
|
||||
if ( CollectionHelper.isNotEmpty( list ) ) {
|
||||
values = list.toArray( new AnnotationValue[list.size()] );
|
||||
}
|
||||
return values;
|
||||
@ -191,32 +192,26 @@ static void cascadeValue(String name, JaxbCascadeType cascadeType, boolean isCas
|
||||
enumList.add( javax.persistence.CascadeType.PERSIST );
|
||||
}
|
||||
if ( cascadeType != null ) {
|
||||
if ( cascadeType.getCascadeAll() != null ) {
|
||||
enumList.add( javax.persistence.CascadeType.ALL );
|
||||
}
|
||||
if ( cascadeType.getCascadePersist() != null && !isCascadePersistDefault ) {
|
||||
enumList.add( javax.persistence.CascadeType.PERSIST );
|
||||
}
|
||||
if ( cascadeType.getCascadeMerge() != null ) {
|
||||
enumList.add( javax.persistence.CascadeType.MERGE );
|
||||
}
|
||||
if ( cascadeType.getCascadeRemove() != null ) {
|
||||
enumList.add( javax.persistence.CascadeType.REMOVE );
|
||||
}
|
||||
if ( cascadeType.getCascadeRefresh() != null ) {
|
||||
enumList.add( javax.persistence.CascadeType.REFRESH );
|
||||
}
|
||||
if ( cascadeType.getCascadeDetach() != null ) {
|
||||
enumList.add( javax.persistence.CascadeType.DETACH );
|
||||
}
|
||||
addIfNotNull( cascadeType.getCascadeAll(), enumList, CascadeType.ALL );
|
||||
addIfNotNull( cascadeType.getCascadePersist(), enumList, CascadeType.PERSIST );
|
||||
addIfNotNull( cascadeType.getCascadeMerge(), enumList, CascadeType.MERGE );
|
||||
addIfNotNull( cascadeType.getCascadeRemove(), enumList, CascadeType.REMOVE );
|
||||
addIfNotNull( cascadeType.getCascadeRefresh(), enumList, CascadeType.REFRESH );
|
||||
addIfNotNull( cascadeType.getCascadeDetach(), enumList , CascadeType.DETACH );
|
||||
}
|
||||
if ( !enumList.isEmpty() ) {
|
||||
MockHelper.enumArrayValue( name, JPADotNames.CASCADE_TYPE, enumList, annotationValueList );
|
||||
}
|
||||
}
|
||||
|
||||
private static void addIfNotNull(Object expect, List<Enum> enumList, CascadeType value) {
|
||||
if ( expect != null ) {
|
||||
enumList.add( value);
|
||||
}
|
||||
}
|
||||
|
||||
static void enumArrayValue(String name, DotName typeName, List<Enum> valueList, List<AnnotationValue> list) {
|
||||
if ( isNotEmpty( valueList ) ) {
|
||||
if ( CollectionHelper.isNotEmpty( valueList ) ) {
|
||||
|
||||
List<AnnotationValue> enumValueList = new ArrayList<AnnotationValue>( valueList.size() );
|
||||
for ( Enum e : valueList ) {
|
||||
@ -270,11 +265,6 @@ else if ( t1.getClass() == MethodInfo.class ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean isNotEmpty(Collection collection) {
|
||||
return collection != null && !collection.isEmpty();
|
||||
}
|
||||
|
||||
|
||||
static AnnotationInstance create(DotName name, AnnotationTarget target, List<AnnotationValue> annotationValueList) {
|
||||
return create(
|
||||
name, target, toArray( annotationValueList )
|
||||
|
@ -36,7 +36,7 @@
|
||||
* @author Strong Liu
|
||||
*/
|
||||
class OneToManyMocker extends PropertyMocker {
|
||||
private JaxbOneToMany oneToMany;
|
||||
private final JaxbOneToMany oneToMany;
|
||||
|
||||
OneToManyMocker(IndexBuilder indexBuilder, ClassInfo classInfo, EntityMappingsMocker.Default defaults, JaxbOneToMany oneToMany) {
|
||||
super( indexBuilder, classInfo, defaults );
|
||||
@ -44,10 +44,9 @@ class OneToManyMocker extends PropertyMocker {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getFieldName() {
|
||||
return oneToMany.getName();
|
||||
protected PropertyElement getPropertyElement() {
|
||||
return oneToMany;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void processExtra() {
|
||||
List<AnnotationValue> annotationValueList = new ArrayList<AnnotationValue>();
|
||||
@ -73,14 +72,4 @@ protected void processExtra() {
|
||||
create( ORDER_BY, getTarget(), MockHelper.stringValueArray( "value", oneToMany.getOrderBy() ) );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JaxbAccessType getAccessType() {
|
||||
return oneToMany.getAccess();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setAccessType(JaxbAccessType accessType) {
|
||||
oneToMany.setAccess( accessType );
|
||||
}
|
||||
}
|
||||
|
@ -44,8 +44,8 @@ class OneToOneMocker extends PropertyMocker {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getFieldName() {
|
||||
return oneToOne.getName();
|
||||
protected PropertyElement getPropertyElement() {
|
||||
return oneToOne;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -71,14 +71,4 @@ protected void processExtra() {
|
||||
create( ID );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JaxbAccessType getAccessType() {
|
||||
return oneToOne.getAccess();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setAccessType(JaxbAccessType accessType) {
|
||||
oneToOne.setAccess( accessType );
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,14 @@
|
||||
package org.hibernate.metamodel.internal.source.annotations.xml.mocker;
|
||||
|
||||
import org.hibernate.internal.jaxb.mapping.orm.JaxbAccessType;
|
||||
|
||||
/**
|
||||
* @author Strong Liu <stliu@hibernate.org>
|
||||
*/
|
||||
public interface PropertyElement {
|
||||
String getName();
|
||||
|
||||
JaxbAccessType getAccess();
|
||||
|
||||
void setAccess(JaxbAccessType accessType);
|
||||
}
|
@ -40,6 +40,7 @@
|
||||
import org.hibernate.internal.jaxb.mapping.orm.JaxbMapKeyColumn;
|
||||
import org.hibernate.internal.jaxb.mapping.orm.JaxbMapKeyJoinColumn;
|
||||
import org.hibernate.internal.jaxb.mapping.orm.JaxbTemporalType;
|
||||
import org.hibernate.internal.util.collections.CollectionHelper;
|
||||
|
||||
/**
|
||||
* @author Strong Liu
|
||||
@ -52,15 +53,9 @@ abstract class PropertyMocker extends AnnotationMocker {
|
||||
super( indexBuilder, defaults );
|
||||
this.classInfo = classInfo;
|
||||
}
|
||||
|
||||
protected abstract PropertyElement getPropertyElement();
|
||||
protected abstract void processExtra();
|
||||
|
||||
protected abstract String getFieldName();
|
||||
|
||||
protected abstract JaxbAccessType getAccessType();
|
||||
|
||||
protected abstract void setAccessType(JaxbAccessType accessType);
|
||||
|
||||
@Override
|
||||
protected DotName getTargetName() {
|
||||
return classInfo.name();
|
||||
@ -68,10 +63,10 @@ protected DotName getTargetName() {
|
||||
|
||||
protected void resolveTarget() {
|
||||
//attribute in orm.xml has access sub-element
|
||||
JaxbAccessType accessType = getAccessType();
|
||||
JaxbAccessType accessType = getPropertyElement().getAccess();
|
||||
if ( accessType == null ) {
|
||||
//attribute in the entity class has @Access
|
||||
accessType = AccessHelper.getAccessFromAttributeAnnotation( getTargetName(), getFieldName(), indexBuilder );
|
||||
accessType = AccessHelper.getAccessFromAttributeAnnotation( getTargetName(), getPropertyElement().getName(), indexBuilder );
|
||||
if ( accessType == null ) {
|
||||
accessType = AccessHelper.getEntityAccess( getTargetName(), indexBuilder );
|
||||
}
|
||||
@ -86,7 +81,7 @@ protected void resolveTarget() {
|
||||
accessType = JaxbAccessType.PROPERTY;
|
||||
|
||||
}
|
||||
setAccessType( accessType );
|
||||
getPropertyElement().setAccess( accessType );
|
||||
}
|
||||
|
||||
}
|
||||
@ -94,7 +89,7 @@ protected void resolveTarget() {
|
||||
@Override
|
||||
protected AnnotationTarget getTarget() {
|
||||
if ( target == null ) {
|
||||
target = getTargetFromAttributeAccessType( getAccessType() );
|
||||
target = getTargetFromAttributeAccessType( getPropertyElement().getAccess() );
|
||||
}
|
||||
return target;
|
||||
}
|
||||
@ -108,14 +103,14 @@ protected AnnotationTarget getTargetFromAttributeAccessType(JaxbAccessType acces
|
||||
return MockHelper.getTarget(
|
||||
indexBuilder.getServiceRegistry(),
|
||||
classInfo,
|
||||
getFieldName(),
|
||||
getPropertyElement().getName(),
|
||||
MockHelper.TargetType.FIELD
|
||||
);
|
||||
case PROPERTY:
|
||||
return MockHelper.getTarget(
|
||||
indexBuilder.getServiceRegistry(),
|
||||
classInfo,
|
||||
getFieldName(),
|
||||
getPropertyElement().getName(),
|
||||
MockHelper.TargetType.PROPERTY
|
||||
);
|
||||
default:
|
||||
@ -187,7 +182,7 @@ protected AnnotationInstance parserMapKey(JaxbMapKey mapKey, AnnotationTarget ta
|
||||
}
|
||||
|
||||
private AnnotationValue[] nestedMapKeyJoinColumnList(String name, List<JaxbMapKeyJoinColumn> columns, List<AnnotationValue> annotationValueList) {
|
||||
if ( MockHelper.isNotEmpty( columns ) ) {
|
||||
if ( CollectionHelper.isNotEmpty( columns ) ) {
|
||||
AnnotationValue[] values = new AnnotationValue[columns.size()];
|
||||
for ( int i = 0; i < columns.size(); i++ ) {
|
||||
AnnotationInstance annotationInstance = parserMapKeyJoinColumn( columns.get( i ), null );
|
||||
@ -204,7 +199,7 @@ private AnnotationValue[] nestedMapKeyJoinColumnList(String name, List<JaxbMapKe
|
||||
}
|
||||
|
||||
protected AnnotationInstance parserMapKeyJoinColumnList(List<JaxbMapKeyJoinColumn> joinColumnList, AnnotationTarget target) {
|
||||
if ( MockHelper.isNotEmpty( joinColumnList ) ) {
|
||||
if ( CollectionHelper.isNotEmpty( joinColumnList ) ) {
|
||||
if ( joinColumnList.size() == 1 ) {
|
||||
return parserMapKeyJoinColumn( joinColumnList.get( 0 ), target );
|
||||
}
|
||||
|
@ -32,11 +32,27 @@
|
||||
* @author Strong Liu
|
||||
*/
|
||||
class TransientMocker extends PropertyMocker {
|
||||
private JaxbTransient transientObj;
|
||||
private final JaxbTransient transientObj;
|
||||
private final PropertyElement wrapper;
|
||||
|
||||
TransientMocker(IndexBuilder indexBuilder, ClassInfo classInfo, EntityMappingsMocker.Default defaults, JaxbTransient transientObj) {
|
||||
TransientMocker(IndexBuilder indexBuilder, ClassInfo classInfo, EntityMappingsMocker.Default defaults, final JaxbTransient transientObj) {
|
||||
super( indexBuilder, classInfo, defaults );
|
||||
this.transientObj = transientObj;
|
||||
this.wrapper = new PropertyElement() {
|
||||
@Override
|
||||
public String getName() {
|
||||
return transientObj.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public JaxbAccessType getAccess() {
|
||||
return JaxbAccessType.FIELD;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAccess(JaxbAccessType accessType) {
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -45,17 +61,7 @@ protected void processExtra() {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getFieldName() {
|
||||
return transientObj.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JaxbAccessType getAccessType() {
|
||||
return JaxbAccessType.FIELD;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setAccessType(JaxbAccessType accessType) {
|
||||
//ignore
|
||||
protected PropertyElement getPropertyElement() {
|
||||
return wrapper;
|
||||
}
|
||||
}
|
||||
|
@ -32,7 +32,7 @@
|
||||
* @author Strong Liu
|
||||
*/
|
||||
class VersionMocker extends PropertyMocker {
|
||||
private JaxbVersion version;
|
||||
private final JaxbVersion version;
|
||||
|
||||
VersionMocker(IndexBuilder indexBuilder, ClassInfo classInfo, EntityMappingsMocker.Default defaults, JaxbVersion version) {
|
||||
super( indexBuilder, classInfo, defaults );
|
||||
@ -40,24 +40,13 @@ class VersionMocker extends PropertyMocker {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getFieldName() {
|
||||
return version.getName();
|
||||
protected PropertyElement getPropertyElement() {
|
||||
return version;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void processExtra() {
|
||||
create( VERSION );
|
||||
parserColumn( version.getColumn(), getTarget() );
|
||||
parserTemporalType( version.getTemporal(), getTarget() );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JaxbAccessType getAccessType() {
|
||||
return version.getAccess();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setAccessType(JaxbAccessType accessType) {
|
||||
version.setAccess( accessType );
|
||||
}
|
||||
}
|
||||
|
@ -459,30 +459,6 @@ protected List<AttributeSource> buildAttributeSources() {
|
||||
return attributeSources;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AttributeSource buildComponentAttributeSource(JaxbComponentElement attributeElement) {
|
||||
throw new UnsupportedOperationException( "Composite identifier cannot contain component attributes" );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AttributeSource buildOneToManyAttributeSource(JaxbOneToManyElement attributeElement) {
|
||||
throw new UnsupportedOperationException( "Composite identifier cannot contain one-to-many attributes" );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AttributeSource buildOneToOneAttributeSource(JaxbOneToOneElement attributeElement) {
|
||||
throw new UnsupportedOperationException( "Composite identifier cannot contain one-to-one attributes" );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AttributeSource buildAnyAttributeSource(JaxbAnyElement attributeElement) {
|
||||
throw new UnsupportedOperationException( "Composite identifier cannot contain ANY attributes" );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AttributeSource buildManyToManyAttributeSource(JaxbManyToManyElement attributeElement) {
|
||||
throw new UnsupportedOperationException( "Composite identifier cannot contain many-to-many attributes" );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getParentReferenceAttributeName() {
|
||||
|
@ -27,6 +27,79 @@
|
||||
<jaxb:bindings node="//xsd:complexType[@name='collection-table']">
|
||||
<inheritance:implements>org.hibernate.metamodel.internal.source.annotations.xml.mocker.SchemaAware</inheritance:implements>
|
||||
</jaxb:bindings>
|
||||
<jaxb:bindings node="//xsd:complexType[@name='table-generator']">
|
||||
<inheritance:implements>org.hibernate.metamodel.internal.source.annotations.xml.mocker.SchemaAware</inheritance:implements>
|
||||
</jaxb:bindings>
|
||||
<jaxb:bindings node="//xsd:complexType[@name='sequence-generator']">
|
||||
<inheritance:implements>org.hibernate.metamodel.internal.source.annotations.xml.mocker.SchemaAware</inheritance:implements>
|
||||
</jaxb:bindings>
|
||||
<jaxb:bindings node="//xsd:complexType[@name='entity']">
|
||||
<inheritance:implements>org.hibernate.metamodel.internal.source.annotations.xml.mocker.EntityElement</inheritance:implements>
|
||||
</jaxb:bindings>
|
||||
<jaxb:bindings node="//xsd:complexType[@name='embeddable']">
|
||||
<inheritance:implements>org.hibernate.metamodel.internal.source.annotations.xml.mocker.EntityElement</inheritance:implements>
|
||||
</jaxb:bindings>
|
||||
<jaxb:bindings node="//xsd:complexType[@name='mapped-superclass']">
|
||||
<inheritance:implements>org.hibernate.metamodel.internal.source.annotations.xml.mocker.EntityElement</inheritance:implements>
|
||||
</jaxb:bindings>
|
||||
<jaxb:bindings node="//xsd:complexType[@name='id']">
|
||||
<inheritance:implements>org.hibernate.metamodel.internal.source.annotations.xml.mocker.PropertyElement</inheritance:implements>
|
||||
</jaxb:bindings>
|
||||
<jaxb:bindings node="//xsd:complexType[@name='version']">
|
||||
<inheritance:implements>org.hibernate.metamodel.internal.source.annotations.xml.mocker.PropertyElement</inheritance:implements>
|
||||
</jaxb:bindings>
|
||||
<jaxb:bindings node="//xsd:complexType[@name='basic']">
|
||||
<inheritance:implements>org.hibernate.metamodel.internal.source.annotations.xml.mocker.PropertyElement</inheritance:implements>
|
||||
</jaxb:bindings>
|
||||
<jaxb:bindings node="//xsd:complexType[@name='many-to-one']">
|
||||
<inheritance:implements>org.hibernate.metamodel.internal.source.annotations.xml.mocker.PropertyElement</inheritance:implements>
|
||||
</jaxb:bindings>
|
||||
<jaxb:bindings node="//xsd:complexType[@name='one-to-many']">
|
||||
<inheritance:implements>org.hibernate.metamodel.internal.source.annotations.xml.mocker.PropertyElement</inheritance:implements>
|
||||
</jaxb:bindings>
|
||||
<jaxb:bindings node="//xsd:complexType[@name='one-to-one']">
|
||||
<inheritance:implements>org.hibernate.metamodel.internal.source.annotations.xml.mocker.PropertyElement</inheritance:implements>
|
||||
</jaxb:bindings>
|
||||
<jaxb:bindings node="//xsd:complexType[@name='embedded-id']">
|
||||
<inheritance:implements>org.hibernate.metamodel.internal.source.annotations.xml.mocker.PropertyElement</inheritance:implements>
|
||||
</jaxb:bindings>
|
||||
<jaxb:bindings node="//xsd:complexType[@name='embedded']">
|
||||
<inheritance:implements>org.hibernate.metamodel.internal.source.annotations.xml.mocker.PropertyElement</inheritance:implements>
|
||||
</jaxb:bindings>
|
||||
<jaxb:bindings node="//xsd:complexType[@name='many-to-many']">
|
||||
<inheritance:implements>org.hibernate.metamodel.internal.source.annotations.xml.mocker.PropertyElement</inheritance:implements>
|
||||
</jaxb:bindings>
|
||||
<jaxb:bindings node="//xsd:complexType[@name='element-collection']">
|
||||
<inheritance:implements>org.hibernate.metamodel.internal.source.annotations.xml.mocker.PropertyElement</inheritance:implements>
|
||||
</jaxb:bindings>
|
||||
<jaxb:bindings node="//xsd:complexType[@name='pre-persist']">
|
||||
<inheritance:implements>org.hibernate.metamodel.internal.source.annotations.xml.mocker.Listener</inheritance:implements>
|
||||
</jaxb:bindings>
|
||||
<jaxb:bindings node="//xsd:complexType[@name='pre-remove']">
|
||||
<inheritance:implements>org.hibernate.metamodel.internal.source.annotations.xml.mocker.Listener</inheritance:implements>
|
||||
</jaxb:bindings>
|
||||
<jaxb:bindings node="//xsd:complexType[@name='pre-update']">
|
||||
<inheritance:implements>org.hibernate.metamodel.internal.source.annotations.xml.mocker.Listener</inheritance:implements>
|
||||
</jaxb:bindings>
|
||||
<jaxb:bindings node="//xsd:complexType[@name='post-load']">
|
||||
<inheritance:implements>org.hibernate.metamodel.internal.source.annotations.xml.mocker.Listener</inheritance:implements>
|
||||
</jaxb:bindings>
|
||||
<jaxb:bindings node="//xsd:complexType[@name='post-remove']">
|
||||
<inheritance:implements>org.hibernate.metamodel.internal.source.annotations.xml.mocker.Listener</inheritance:implements>
|
||||
</jaxb:bindings>
|
||||
<jaxb:bindings node="//xsd:complexType[@name='post-update']">
|
||||
<inheritance:implements>org.hibernate.metamodel.internal.source.annotations.xml.mocker.Listener</inheritance:implements>
|
||||
</jaxb:bindings>
|
||||
<jaxb:bindings node="//xsd:complexType[@name='post-persist']">
|
||||
<inheritance:implements>org.hibernate.metamodel.internal.source.annotations.xml.mocker.Listener</inheritance:implements>
|
||||
</jaxb:bindings>
|
||||
|
||||
<jaxb:bindings node="//xsd:complexType[@name='attributes']">
|
||||
<inheritance:implements>org.hibernate.metamodel.internal.source.annotations.xml.mocker.AttributesContainer</inheritance:implements>
|
||||
</jaxb:bindings>
|
||||
<jaxb:bindings node="//xsd:complexType[@name='embeddable-attributes']">
|
||||
<inheritance:implements>org.hibernate.metamodel.internal.source.annotations.xml.mocker.AttributesContainer</inheritance:implements>
|
||||
</jaxb:bindings>
|
||||
</jaxb:bindings>
|
||||
|
||||
</jaxb:bindings>
|
Loading…
x
Reference in New Issue
Block a user