mirror of
https://github.com/hibernate/hibernate-orm
synced 2025-02-13 06:34:50 +00:00
Attempt to match Hibernate code conventions
This commit is contained in:
parent
926c35a1b5
commit
9ae8e5f1d4
@ -484,7 +484,6 @@ private Annotation getTableGenerator(List<Element> elementsForProperty, XMLConte
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private Annotation getSequenceGenerator(List<Element> elementsForProperty, XMLContext.Default defaults) {
|
||||
for (Element element : elementsForProperty) {
|
||||
Element subelement = element != null ? element.element( annotationToXml.get( SequenceGenerator.class ) ) : null;
|
||||
@ -825,8 +824,7 @@ else if ( isJavaAnnotationPresent( CollectionOfElements.class ) ) { //legacy Hib
|
||||
}
|
||||
}
|
||||
|
||||
private void buildMapKeyJoinColumns(List<Annotation> annotationList,
|
||||
Element element) {
|
||||
private void buildMapKeyJoinColumns(List<Annotation> annotationList, Element element) {
|
||||
MapKeyJoinColumn[] joinColumns = getMapKeyJoinColumns( element );
|
||||
if ( joinColumns.length > 0 ) {
|
||||
AnnotationDescriptor ad = new AnnotationDescriptor( MapKeyJoinColumns.class );
|
||||
@ -836,9 +834,7 @@ private void buildMapKeyJoinColumns(List<Annotation> annotationList,
|
||||
}
|
||||
|
||||
private MapKeyJoinColumn[] getMapKeyJoinColumns(Element element) {
|
||||
List<Element> subelements = element != null ?
|
||||
element.elements( "map-key-join-column" ) :
|
||||
null;
|
||||
List<Element> subelements = element != null ? element.elements( "map-key-join-column" ) : null;
|
||||
List<MapKeyJoinColumn> joinColumns = new ArrayList<MapKeyJoinColumn>();
|
||||
if ( subelements != null ) {
|
||||
for (Element subelement : subelements) {
|
||||
@ -857,8 +853,7 @@ private MapKeyJoinColumn[] getMapKeyJoinColumns(Element element) {
|
||||
return joinColumns.toArray( new MapKeyJoinColumn[joinColumns.size()] );
|
||||
}
|
||||
|
||||
private Annotation getMapKeyAttributeOverrides(Element tree,
|
||||
Default defaults) {
|
||||
private Annotation getMapKeyAttributeOverrides(Element tree, Default defaults) {
|
||||
List<AttributeOverride> attributes = buildMapKeyAttributeOverrides( tree );
|
||||
return mergeAttributeOverrides( defaults, attributes );
|
||||
}
|
||||
@ -884,13 +879,11 @@ private List<AttributeOverride> buildMapKeyAttributeOverrides(List<Element> sube
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a @MapKeyEnumerated annotation to the specified annotationList if
|
||||
* the specified element contains a map-key-enumerated sub-element. This
|
||||
* should only be the case for element-collection, many-to-many, or
|
||||
* one-to-many associations.
|
||||
* Adds a @MapKeyEnumerated annotation to the specified annotationList if the specified element
|
||||
* contains a map-key-enumerated sub-element. This should only be the case for
|
||||
* element-collection, many-to-many, or one-to-many associations.
|
||||
*/
|
||||
private void getMapKeyEnumerated(List<Annotation> annotationList,
|
||||
Element element) {
|
||||
private void getMapKeyEnumerated(List<Annotation> annotationList, Element element) {
|
||||
Element subelement = element != null ? element.element( "map-key-enumerated" ) : null;
|
||||
if ( subelement != null ) {
|
||||
AnnotationDescriptor ad = new AnnotationDescriptor( MapKeyEnumerated.class );
|
||||
@ -902,13 +895,11 @@ private void getMapKeyEnumerated(List<Annotation> annotationList,
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a @MapKeyTemporal annotation to the specified annotationList if the
|
||||
* specified element contains a map-key-temporal sub-element. This should
|
||||
* only be the case for element-collection, many-to-many, or one-to-many
|
||||
* associations.
|
||||
* Adds a @MapKeyTemporal annotation to the specified annotationList if the specified element
|
||||
* contains a map-key-temporal sub-element. This should only be the case for element-collection,
|
||||
* many-to-many, or one-to-many associations.
|
||||
*/
|
||||
private void getMapKeyTemporal(List<Annotation> annotationList,
|
||||
Element element) {
|
||||
private void getMapKeyTemporal(List<Annotation> annotationList, Element element) {
|
||||
Element subelement = element != null ? element.element( "map-key-temporal" ) : null;
|
||||
if ( subelement != null ) {
|
||||
AnnotationDescriptor ad = new AnnotationDescriptor( MapKeyTemporal.class );
|
||||
@ -919,13 +910,11 @@ private void getMapKeyTemporal(List<Annotation> annotationList,
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an @OrderColumn annotation to the specified annotationList if the
|
||||
* specified element contains an order-column sub-element. This should only
|
||||
* be the case for element-collection, many-to-many, or one-to-many
|
||||
* associations.
|
||||
* Adds an @OrderColumn annotation to the specified annotationList if the specified element
|
||||
* contains an order-column sub-element. This should only be the case for element-collection,
|
||||
* many-to-many, or one-to-many associations.
|
||||
*/
|
||||
private void getOrderColumn(List<Annotation> annotationList,
|
||||
Element element) {
|
||||
private void getOrderColumn(List<Annotation> annotationList, Element element) {
|
||||
Element subelement = element != null ? element.element( "order-column" ) : null;
|
||||
if ( subelement != null ) {
|
||||
AnnotationDescriptor ad = new AnnotationDescriptor( OrderColumn.class );
|
||||
@ -939,9 +928,9 @@ private void getOrderColumn(List<Annotation> annotationList,
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a @MapsId annotation to the specified annotationList if the
|
||||
* specified element has the maps-id attribute set. This should only be the
|
||||
* case for many-to-one or one-to-one associations.
|
||||
* Adds a @MapsId annotation to the specified annotationList if the specified element has the
|
||||
* maps-id attribute set. This should only be the case for many-to-one or one-to-one
|
||||
* associations.
|
||||
*/
|
||||
private void getMapsId(List<Annotation> annotationList, Element element) {
|
||||
String attrVal = element.attributeValue( "maps-id" );
|
||||
@ -953,12 +942,11 @@ private void getMapsId(List<Annotation> annotationList, Element element) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an @Id annotation to the specified annotationList if the specified
|
||||
* element has the id attribute set to true. This should only be the case
|
||||
* for many-to-one or one-to-one associations.
|
||||
* Adds an @Id annotation to the specified annotationList if the specified element has the id
|
||||
* attribute set to true. This should only be the case for many-to-one or one-to-one
|
||||
* associations.
|
||||
*/
|
||||
private void getAssociationId(List<Annotation> annotationList,
|
||||
Element element) {
|
||||
private void getAssociationId(List<Annotation> annotationList, Element element) {
|
||||
String attrVal = element.attributeValue( "id" );
|
||||
if ( "true".equals( attrVal ) ) {
|
||||
AnnotationDescriptor ad = new AnnotationDescriptor( Id.class );
|
||||
@ -972,8 +960,7 @@ private void addTargetClass(Element element, AnnotationDescriptor ad, String nod
|
||||
Class clazz;
|
||||
try {
|
||||
clazz = ReflectHelper.classForName(
|
||||
XMLContext.buildSafeClassName( className, defaults ),
|
||||
this.getClass()
|
||||
XMLContext.buildSafeClassName( className, defaults ), this.getClass()
|
||||
);
|
||||
}
|
||||
catch (ClassNotFoundException e) {
|
||||
@ -1579,8 +1566,7 @@ private AttributeOverrides getAttributeOverrides(List<Element> elements, XMLCont
|
||||
return mergeAttributeOverrides( defaults, attributes );
|
||||
}
|
||||
|
||||
private AttributeOverrides mergeAttributeOverrides(XMLContext.Default defaults,
|
||||
List<AttributeOverride> attributes) {
|
||||
private AttributeOverrides mergeAttributeOverrides(XMLContext.Default defaults, List<AttributeOverride> attributes) {
|
||||
if ( defaults.canUseJavaAnnotations() ) {
|
||||
AttributeOverride annotation = getJavaAnnotation( AttributeOverride.class );
|
||||
addAttributeOverrideIfNeeded( annotation, attributes );
|
||||
|
@ -37,6 +37,7 @@
|
||||
import javax.persistence.UniqueConstraint;
|
||||
|
||||
public class Ejb3XmlManyToOneTest extends Ejb3XmlTestCase {
|
||||
|
||||
public void testNoJoins() throws Exception {
|
||||
reader = getReader( Entity1.class, "field1", "many-to-one.orm1.xml" );
|
||||
assertAnnotationPresent( ManyToOne.class );
|
||||
@ -165,7 +166,8 @@ public void testJoinTableAllChildren() throws Exception {
|
||||
assertTrue( inverseJoinColumns[1].unique() );
|
||||
|
||||
// UniqueConstraints
|
||||
UniqueConstraint[] uniqueConstraints = joinTableAnno.uniqueConstraints();
|
||||
UniqueConstraint[] uniqueConstraints = joinTableAnno
|
||||
.uniqueConstraints();
|
||||
assertEquals( 2, uniqueConstraints.length );
|
||||
assertEquals( 1, uniqueConstraints[0].columnNames().length );
|
||||
assertEquals( "col5", uniqueConstraints[0].columnNames()[0] );
|
||||
@ -189,8 +191,8 @@ public void testAllAttributes() throws Exception {
|
||||
assertFalse( relAnno.optional() );
|
||||
assertEquals( Entity3.class, relAnno.targetEntity() );
|
||||
assertEquals( "col1", reader.getAnnotation( MapsId.class ).value() );
|
||||
assertEquals(AccessType.PROPERTY,
|
||||
reader.getAnnotation(Access.class).value());
|
||||
assertEquals( AccessType.PROPERTY, reader.getAnnotation( Access.class )
|
||||
.value() );
|
||||
}
|
||||
|
||||
public void testCascadeAll() throws Exception {
|
||||
|
@ -65,7 +65,7 @@ public void testNoChildren() throws Exception {
|
||||
assertAnnotationNotPresent( JoinColumns.class );
|
||||
assertAnnotationNotPresent( JoinColumn.class );
|
||||
assertAnnotationNotPresent( Access.class );
|
||||
OneToMany relAnno = reader.getAnnotation(OneToMany.class);;
|
||||
OneToMany relAnno = reader.getAnnotation( OneToMany.class );
|
||||
assertEquals( 0, relAnno.cascade().length );
|
||||
assertEquals( FetchType.LAZY, relAnno.fetch() );
|
||||
assertEquals( "", relAnno.mappedBy() );
|
||||
@ -78,7 +78,8 @@ public void testOrderBy() throws Exception {
|
||||
assertAnnotationPresent( OneToMany.class );
|
||||
assertAnnotationPresent( OrderBy.class );
|
||||
assertAnnotationNotPresent( OrderColumn.class );
|
||||
assertEquals("col1 ASC, col2 DESC", reader.getAnnotation(OrderBy.class).value());
|
||||
assertEquals( "col1 ASC, col2 DESC", reader.getAnnotation( OrderBy.class )
|
||||
.value() );
|
||||
}
|
||||
|
||||
public void testOrderColumnNoAttributes() throws Exception {
|
||||
@ -143,7 +144,8 @@ public void testMapKeyClass() throws Exception {
|
||||
assertAnnotationNotPresent( MapKeyColumn.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumns.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumn.class );
|
||||
assertEquals(Entity2.class, reader.getAnnotation(MapKeyClass.class).value());
|
||||
assertEquals( Entity2.class, reader.getAnnotation( MapKeyClass.class )
|
||||
.value() );
|
||||
}
|
||||
|
||||
public void testMapKeyTemporal() throws Exception {
|
||||
@ -156,7 +158,8 @@ public void testMapKeyTemporal() throws Exception {
|
||||
assertAnnotationNotPresent( MapKeyColumn.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumns.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumn.class );
|
||||
assertEquals(TemporalType.DATE, reader.getAnnotation(MapKeyTemporal.class).value());
|
||||
assertEquals( TemporalType.DATE, reader.getAnnotation(
|
||||
MapKeyTemporal.class ).value() );
|
||||
}
|
||||
|
||||
public void testMapKeyEnumerated() throws Exception {
|
||||
@ -169,7 +172,8 @@ public void testMapKeyEnumerated() throws Exception {
|
||||
assertAnnotationNotPresent( MapKeyColumn.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumns.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumn.class );
|
||||
assertEquals(EnumType.STRING, reader.getAnnotation(MapKeyEnumerated.class).value());
|
||||
assertEquals( EnumType.STRING, reader.getAnnotation(
|
||||
MapKeyEnumerated.class ).value() );
|
||||
}
|
||||
|
||||
/**
|
||||
@ -188,7 +192,8 @@ public void testSingleMapKeyAttributeOverride() throws Exception {
|
||||
assertAnnotationNotPresent( MapKeyJoinColumn.class );
|
||||
assertAnnotationNotPresent( AttributeOverride.class );
|
||||
assertAnnotationPresent( AttributeOverrides.class );
|
||||
AttributeOverrides overridesAnno = reader.getAnnotation(AttributeOverrides.class);
|
||||
AttributeOverrides overridesAnno = reader
|
||||
.getAnnotation( AttributeOverrides.class );
|
||||
AttributeOverride[] overrides = overridesAnno.value();
|
||||
assertEquals( 1, overrides.length );
|
||||
assertEquals( "field1", overrides[0].name() );
|
||||
@ -207,7 +212,8 @@ public void testMultipleMapKeyAttributeOverrides() throws Exception {
|
||||
assertAnnotationNotPresent( MapKeyJoinColumn.class );
|
||||
assertAnnotationNotPresent( AttributeOverride.class );
|
||||
assertAnnotationPresent( AttributeOverrides.class );
|
||||
AttributeOverrides overridesAnno = reader.getAnnotation(AttributeOverrides.class);
|
||||
AttributeOverrides overridesAnno = reader
|
||||
.getAnnotation( AttributeOverrides.class );
|
||||
AttributeOverride[] overrides = overridesAnno.value();
|
||||
assertEquals( 2, overrides.length );
|
||||
assertEquals( "field1", overrides[0].name() );
|
||||
@ -294,7 +300,8 @@ public void testSingleMapKeyJoinColumn() throws Exception {
|
||||
assertAnnotationNotPresent( MapKeyColumn.class );
|
||||
assertAnnotationPresent( MapKeyJoinColumns.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumn.class );
|
||||
MapKeyJoinColumns joinColumnsAnno = reader.getAnnotation(MapKeyJoinColumns.class);
|
||||
MapKeyJoinColumns joinColumnsAnno = reader
|
||||
.getAnnotation( MapKeyJoinColumns.class );
|
||||
MapKeyJoinColumn[] joinColumns = joinColumnsAnno.value();
|
||||
assertEquals( 1, joinColumns.length );
|
||||
assertEquals( "col1", joinColumns[0].name() );
|
||||
@ -310,7 +317,8 @@ public void testMultipleMapKeyJoinColumns() throws Exception {
|
||||
assertAnnotationNotPresent( MapKeyColumn.class );
|
||||
assertAnnotationPresent( MapKeyJoinColumns.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumn.class );
|
||||
MapKeyJoinColumns joinColumnsAnno = reader.getAnnotation(MapKeyJoinColumns.class);
|
||||
MapKeyJoinColumns joinColumnsAnno = reader
|
||||
.getAnnotation( MapKeyJoinColumns.class );
|
||||
MapKeyJoinColumn[] joinColumns = joinColumnsAnno.value();
|
||||
assertEquals( 2, joinColumns.length );
|
||||
assertEquals( "", joinColumns[0].name() );
|
||||
@ -399,7 +407,8 @@ public void testJoinTableAllChildren() throws Exception {
|
||||
assertTrue( inverseJoinColumns[1].unique() );
|
||||
|
||||
// UniqueConstraints
|
||||
UniqueConstraint[] uniqueConstraints = joinTableAnno.uniqueConstraints();
|
||||
UniqueConstraint[] uniqueConstraints = joinTableAnno
|
||||
.uniqueConstraints();
|
||||
assertEquals( 2, uniqueConstraints.length );
|
||||
assertEquals( 1, uniqueConstraints[0].columnNames().length );
|
||||
assertEquals( "col5", uniqueConstraints[0].columnNames()[0] );
|
||||
@ -506,15 +515,14 @@ public void testAllAttributes() throws Exception {
|
||||
assertAnnotationNotPresent( JoinColumns.class );
|
||||
assertAnnotationNotPresent( JoinColumn.class );
|
||||
assertAnnotationPresent( Access.class );
|
||||
OneToMany relAnno = reader.getAnnotation(OneToMany.class);;
|
||||
OneToMany relAnno = reader.getAnnotation( OneToMany.class );
|
||||
assertEquals( 0, relAnno.cascade().length );
|
||||
assertEquals( FetchType.EAGER, relAnno.fetch() );
|
||||
assertEquals( "field2", relAnno.mappedBy() );
|
||||
assertTrue( relAnno.orphanRemoval() );
|
||||
assertEquals( Entity3.class, relAnno.targetEntity() );
|
||||
assertEquals(AccessType.PROPERTY,
|
||||
reader.getAnnotation(Access.class).value());
|
||||
|
||||
assertEquals( AccessType.PROPERTY, reader.getAnnotation( Access.class )
|
||||
.value() );
|
||||
}
|
||||
|
||||
//TODO: tests for merging/overriding
|
||||
|
@ -45,7 +45,8 @@ protected void assertAnnotationNotPresent(Class<? extends Annotation> annotation
|
||||
assertFalse( reader.isAnnotationPresent( annotationType ) );
|
||||
}
|
||||
|
||||
protected JPAOverridenAnnotationReader getReader(Class<?> entityClass, String fieldName, String ormResourceName) throws Exception {
|
||||
protected JPAOverridenAnnotationReader getReader(Class<?> entityClass, String fieldName, String ormResourceName)
|
||||
throws Exception {
|
||||
AnnotatedElement el = getAnnotatedElement( entityClass, fieldName );
|
||||
XMLContext xmlContext = getContext( ormResourceName );
|
||||
JPAOverridenAnnotationReader reader = new JPAOverridenAnnotationReader( el, xmlContext );
|
||||
|
Loading…
x
Reference in New Issue
Block a user