Skip to content

Commit

Permalink
HHH-7452 mixin interface to simplify orm xml binding
Browse files Browse the repository at this point in the history
  • Loading branch information
stliu committed Jul 17, 2012
1 parent 6ed7e9e commit f0a49ad
Show file tree
Hide file tree
Showing 35 changed files with 354 additions and 666 deletions.
Expand Up @@ -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 ) {
Expand All @@ -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();
}
Expand Up @@ -59,21 +59,21 @@ 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;
}

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();
Expand All @@ -96,39 +96,26 @@ 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();

abstract protected JaxbIdClass getIdClass();

abstract protected JaxbEntityListeners getEntityListeners();

abstract protected JaxbAccessType getAccessType();

abstract protected String getClassName();

abstract protected JaxbPrePersist getPrePersist();

abstract protected JaxbPreRemove getPreRemove();
Expand All @@ -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;
Expand Down
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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 );
Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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(
Expand All @@ -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 ) {
Expand Down
Expand Up @@ -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
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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 );
}
Expand All @@ -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 );
Expand All @@ -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 ) ) {
Expand Down Expand Up @@ -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 );
}
Expand Down
Expand Up @@ -45,63 +45,28 @@
* @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 );
this.attributes = attributes;
}

@Override
List<JaxbBasic> getBasic() {
return attributes.getBasic();
protected AttributesContainer getAttributesContainer() {
return attributes;
}

@Override
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();
Expand Down
@@ -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();

}

0 comments on commit f0a49ad

Please sign in to comment.