private static boolean discoverTypeWithoutReflection(XProperty p) { if ( p.isAnnotationPresent( OneToOne.class ) && !p.getAnnotation( OneToOne.class ) .targetEntity() .equals( void.class ) ) { return true; } else if ( p.isAnnotationPresent( OneToMany.class ) && !p.getAnnotation( OneToMany.class ) .targetEntity() .equals( void.class ) ) { return true; } else if ( p.isAnnotationPresent( ManyToOne.class ) && !p.getAnnotation( ManyToOne.class ) .targetEntity() .equals( void.class ) ) { return true; } else if ( p.isAnnotationPresent( ManyToMany.class ) && !p.getAnnotation( ManyToMany.class ) .targetEntity() .equals( void.class ) ) { return true; } else if ( p.isAnnotationPresent( org.hibernate.annotations.Any.class ) ) { return true; } else if ( p.isAnnotationPresent( ManyToAny.class ) ) { if ( !p.isCollection() && !p.isArray() ) { throw new AnnotationException( "@ManyToAny used on a non collection non array property: " + p.getName() ); } return true; } else if ( p.isAnnotationPresent( Type.class ) ) { return true; } else if ( p.isAnnotationPresent( Target.class ) ) { return true; } return false; }
MappingInformation(final AttributeAccessor attribute) { final OneToOne oneToOne = attribute.getAnnotation(OneToOne.class); final NotNull notNull = attribute.getAnnotation(NotNull.class); if (oneToOne != null) { this.optional = oneToOne.optional() && notNull == null; this.mappedBy = oneToOne.mappedBy(); this.anyMetaColumn = null; } else { this.mappedBy = ""; final ManyToOne manyToOne = attribute.getAnnotation(ManyToOne.class); if (manyToOne != null) { this.optional = manyToOne.optional() && notNull == null; this.anyMetaColumn = null; } else { final Any any = attribute.getAnnotation(Any.class); if (any != null) { this.optional = any.optional() && notNull == null; this.anyMetaColumn = any.metaColumn().name(); } else { final ManyToAny manyToAny = attribute.getAnnotation(ManyToAny.class); if (manyToAny == null) { throw new IllegalArgumentException( attribute + " is neither declared as OneToOne nor ManyToOne"); } this.optional = notNull == null; this.anyMetaColumn = manyToAny.metaColumn().name(); } } } }
public void prepare(XProperty collectionProperty) { // fugly if ( prepared ) { return; } if ( collectionProperty == null ) { return; } prepared = true; if ( collection.isMap() ) { if ( collectionProperty.isAnnotationPresent( MapKeyEnumerated.class ) ) { canKeyBeConverted = false; } else if ( collectionProperty.isAnnotationPresent( MapKeyTemporal.class ) ) { canKeyBeConverted = false; } else if ( collectionProperty.isAnnotationPresent( MapKeyClass.class ) ) { canKeyBeConverted = false; } else if ( collectionProperty.isAnnotationPresent( MapKeyType.class ) ) { canKeyBeConverted = false; } } else { canKeyBeConverted = false; } if ( collectionProperty.isAnnotationPresent( ManyToAny.class ) ) { canElementBeConverted = false; } else if ( collectionProperty.isAnnotationPresent( OneToMany.class ) ) { canElementBeConverted = false; } else if ( collectionProperty.isAnnotationPresent( ManyToMany.class ) ) { canElementBeConverted = false; } else if ( collectionProperty.isAnnotationPresent( Enumerated.class ) ) { canElementBeConverted = false; } else if ( collectionProperty.isAnnotationPresent( Temporal.class ) ) { canElementBeConverted = false; } else if ( collectionProperty.isAnnotationPresent( CollectionType.class ) ) { canElementBeConverted = false; } // Is it valid to reference a collection attribute in a @Convert attached to the owner (entity) by path? // if so we should pass in 'clazzToProcess' also if ( canKeyBeConverted || canElementBeConverted ) { buildAttributeConversionInfoMaps( collectionProperty, elementAttributeConversionInfoMap, keyAttributeConversionInfoMap ); } }
private void defineFetchingStrategy() { LazyCollection lazy = property.getAnnotation( LazyCollection.class ); Fetch fetch = property.getAnnotation( Fetch.class ); OneToMany oneToMany = property.getAnnotation( OneToMany.class ); ManyToMany manyToMany = property.getAnnotation( ManyToMany.class ); ElementCollection elementCollection = property.getAnnotation( ElementCollection.class ); //jpa 2 ManyToAny manyToAny = property.getAnnotation( ManyToAny.class ); FetchType fetchType; if ( oneToMany != null ) { fetchType = oneToMany.fetch(); } else if ( manyToMany != null ) { fetchType = manyToMany.fetch(); } else if ( elementCollection != null ) { fetchType = elementCollection.fetch(); } else if ( manyToAny != null ) { fetchType = FetchType.LAZY; } else { throw new AssertionFailure( "Define fetch strategy on a property not annotated with @ManyToOne nor @OneToMany nor @CollectionOfElements" ); } if ( lazy != null ) { collection.setLazy( !( lazy.value() == LazyCollectionOption.FALSE ) ); collection.setExtraLazy( lazy.value() == LazyCollectionOption.EXTRA ); } else { collection.setLazy( fetchType == FetchType.LAZY ); collection.setExtraLazy( false ); } if ( fetch != null ) { if ( fetch.value() == org.hibernate.annotations.FetchMode.JOIN ) { collection.setFetchMode( FetchMode.JOIN ); collection.setLazy( false ); } else if ( fetch.value() == org.hibernate.annotations.FetchMode.SELECT ) { collection.setFetchMode( FetchMode.SELECT ); } else if ( fetch.value() == org.hibernate.annotations.FetchMode.SUBSELECT ) { collection.setFetchMode( FetchMode.SELECT ); collection.setSubselectLoadable( true ); collection.getOwner().setSubselectLoadableCollections( true ); } else { throw new AssertionFailure( "Unknown FetchMode: " + fetch.value() ); } } else { collection.setFetchMode( AnnotationBinder.getFetchMode( fetchType ) ); } }
/** * Indicates that the given attribute references an entity and may be used by an {@link EntityProperty}. * * @param attribute * accessor of the attribute to check * @return {@code true} if an {@link EntityProperty} may be created for the given attribute */ static boolean isEntityProperty(final AttributeAccessor attribute) { return attribute.isAnnotationPresent(OneToOne.class) || attribute.isAnnotationPresent(ManyToOne.class) || attribute.isAnnotationPresent(Any.class) || attribute.isAnnotationPresent(ManyToAny.class); }