Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

HHH-7969 mock orm xml

  • Loading branch information...
commit 0e3b01f1e40f1faa72d32b37bf664032cf5c4ad6 1 parent 7c9eae9
@stliu authored
View
41 hibernate-core/src/main/java/org/hibernate/cfg/annotations/reflection/JPAOverriddenAnnotationReader.java
@@ -65,10 +65,12 @@
import javax.persistence.ExcludeSuperclassListeners;
import javax.persistence.FetchType;
import javax.persistence.FieldResult;
+import javax.persistence.ForeignKey;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.IdClass;
+import javax.persistence.Index;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.JoinColumn;
@@ -132,6 +134,7 @@
import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.internal.util.ReflectHelper;
import org.hibernate.internal.util.StringHelper;
+import org.hibernate.internal.util.collections.CollectionHelper;
/**
* Encapsulates the overriding of Java annotations from an EJB 3.0 descriptor.
@@ -227,6 +230,8 @@ public boolean returnTransient() {
annotationToXml.put( MapKeyJoinColumns.class, "map-key-join-column" );
annotationToXml.put( OrderColumn.class, "order-column" );
annotationToXml.put( Cacheable.class, "cacheable" );
+ annotationToXml.put( Index.class, "index" );
+ annotationToXml.put( ForeignKey.class, "foreign-key" );
}
private XMLContext xmlContext;
@@ -612,6 +617,7 @@ private JoinTable overridesDefaultsInJoinTable(Annotation annotation, XMLContext
ad.setValue( "uniqueConstraints", table.uniqueConstraints() );
ad.setValue( "joinColumns", table.joinColumns() );
ad.setValue( "inverseJoinColumns", table.inverseJoinColumns() );
+ ad.setValue( "indexes", table.indexes() );
}
}
if ( StringHelper.isEmpty( (String) ad.valueOf( "schema" ) )
@@ -661,6 +667,7 @@ private JoinTable buildJoinTable(Element tree, XMLContext.Default defaults) {
buildUniqueConstraints( annotation, subelement );
annotation.setValue( "joinColumns", getJoinColumns( subelement, false ) );
annotation.setValue( "inverseJoinColumns", getJoinColumns( subelement, true ) );
+ annotation.setValue( "indexes", getIndexes( subelement ) );
return AnnotationFactory.create( annotation );
}
@@ -1068,6 +1075,7 @@ private void getCollectionTable(List<Annotation> annotationList, Element element
annotation.setValue( "joinColumns", joinColumns );
}
buildUniqueConstraints( annotation, subelement );
+ annotation.setValue( "indexes", getIndexes( subelement ) );
annotationList.add( AnnotationFactory.create( annotation ) );
}
}
@@ -1525,6 +1533,35 @@ private AssociationOverrides getAssociationOverrides(Element tree, XMLContext.De
return overrides;
}
+ private ForeignKey getForeignKey(Element element) {
+ Element fkElement = element != null ? element.element( "foreign-key" ) : null;
+ AnnotationDescriptor fk = new AnnotationDescriptor( ForeignKey.class );
+ if ( fkElement != null ) {
+ copyStringAttribute( fk, fkElement, "name", false );
+ copyStringAttribute( fk, fkElement, "foreignKeyDefinition", false );
+ copyBooleanAttribute( fk, fkElement, "disableForeignKey" );
+ }
+ return (ForeignKey) AnnotationFactory.create( fk );
+ }
+
+ private static Index[] getIndexes(Element element) {
+ List<Element> subelements = element != null ?
+ element.elements( "indexes" ) :
+ null;
+ if ( CollectionHelper.isNotEmpty( subelements ) ) {
+ Index[] indexes = new Index[subelements.size()];
+ for(int i=0;i<indexes.length;i++){
+ AnnotationDescriptor index = new AnnotationDescriptor( Index.class );
+ Element subElement = subelements.get( i );
+ copyStringAttribute( index, subElement, "name", false );
+ copyStringAttribute( index, subElement, "columnList", true );
+ copyBooleanAttribute( index, subElement, "unique" );
+ indexes[i] = (Index)AnnotationFactory.create( index );
+ }
+ }
+ return new Index[0];
+ }
+
private JoinColumn[] getJoinColumns(Element element, boolean isInverse) {
List<Element> subelements = element != null ?
element.elements( isInverse ? "inverse-join-column" : "join-column" ) :
@@ -2011,6 +2048,7 @@ public static TableGenerator buildTableGeneratorAnnotation(Element element, XMLC
copyIntegerAttribute( ad, element, "initial-value" );
copyIntegerAttribute( ad, element, "allocation-size" );
buildUniqueConstraints( ad, element );
+ ad.setValue( "indexes", getIndexes( element ) );
if ( StringHelper.isEmpty( (String) ad.valueOf( "schema" ) )
&& StringHelper.isNotEmpty( defaults.getSchema() ) ) {
ad.setValue( "schema", defaults.getSchema() );
@@ -2297,6 +2335,7 @@ else if ( defaults.canUseJavaAnnotations() ) {
annotation.setValue( "schema", defaults.getSchema() );
}
buildUniqueConstraints( annotation, subelement );
+ annotation.setValue( "indexes", getIndexes( subelement ) );
return AnnotationFactory.create( annotation );
}
}
@@ -2321,6 +2360,7 @@ private SecondaryTables getSecondaryTables(Element tree, XMLContext.Default defa
}
buildUniqueConstraints( annotation, element );
annotation.setValue( "pkJoinColumns", buildPrimaryKeyJoinColumns( element ) );
+ annotation.setValue( "indexes", getIndexes( element ) );
secondaryTables.add( (SecondaryTable) AnnotationFactory.create( annotation ) );
}
/*
@@ -2360,6 +2400,7 @@ private void overridesDefaultInSecondaryTable(
annotation.setValue( "catalog", secTableAnn.catalog() );
annotation.setValue( "uniqueConstraints", secTableAnn.uniqueConstraints() );
annotation.setValue( "pkJoinColumns", secTableAnn.pkJoinColumns() );
+ annotation.setValue( "indexes", secTableAnn.indexes() );
if ( StringHelper.isEmpty( (String) annotation.valueOf( "schema" ) )
&& StringHelper.isNotEmpty( defaults.getSchema() ) ) {
annotation.setValue( "schema", defaults.getSchema() );
Please sign in to comment.
Something went wrong with that request. Please try again.