do { Callback callback = null; List<XMethod> methods = currentClazz.getDeclaredMethods(); for ( final XMethod xMethod : methods ) { if ( xMethod.isAnnotationPresent( callbackType.getCallbackAnnotation() ) ) { methodName, callbackType.getCallbackAnnotation().getSimpleName(), embeddableXClass.getName() ); throw new PersistenceException( "You can only annotate one callback method with " + callbackType.getCallbackAnnotation().getName() + " in bean class: " + embeddableXClass.getName() ); currentClazz = currentClazz.getSuperclass(); while ( currentClazz != null && !currentClazz.isAnnotationPresent( MappedSuperclass.class ) );
private AccessType determineDefaultAccessType() { for (XClass xclass = clazz; xclass != null; xclass = xclass.getSuperclass()) { if ( ( xclass.getSuperclass() == null || Object.class.getName().equals( xclass.getSuperclass().getName() ) ) && ( xclass.isAnnotationPresent( Entity.class ) || xclass.isAnnotationPresent( MappedSuperclass.class ) ) && xclass.isAnnotationPresent( Access.class ) ) { return AccessType.getAccessStrategy( xclass.getAnnotation( Access.class ).value() ); } } // Guess from identifier. // FIX: Shouldn't this be determined by the first attribute (i.e., field or property) with annotations, but without an // explicit Access annotation, according to JPA 2.0 spec 2.3.1: Default Access Type? for (XClass xclass = clazz; xclass != null && !Object.class.getName().equals(xclass.getName()); xclass = xclass.getSuperclass()) { if ( xclass.isAnnotationPresent( Entity.class ) || xclass.isAnnotationPresent( MappedSuperclass.class ) ) { for ( XProperty prop : xclass.getDeclaredProperties( AccessType.PROPERTY.getType() ) ) { final boolean isEmbeddedId = prop.isAnnotationPresent( EmbeddedId.class ); if ( prop.isAnnotationPresent( Id.class ) || isEmbeddedId ) { return AccessType.PROPERTY; } } for ( XProperty prop : xclass.getDeclaredProperties( AccessType.FIELD.getType() ) ) { final boolean isEmbeddedId = prop.isAnnotationPresent( EmbeddedId.class ); if ( prop.isAnnotationPresent( Id.class ) || isEmbeddedId ) { return AccessType.FIELD; } } } } throw new AnnotationException( "No identifier specified for entity: " + clazz ); }
/** * Checks whether one class is assignable from another. If not {@link MappingException} is thrown. * * @param child Subclass. * @param parent Superclass. */ private void checkSuperclass(XClass child, XClass parent) { if ( !parent.isAssignableFrom( child ) ) { throw new MappingException( "Class " + parent.getName() + " is not assignable from " + child.getName() + ". " + "Please revise Envers annotations applied to " + child.getName() + " type." ); } }
@Override public AnnotatedClassType addClassType(XClass clazz) { AnnotatedClassType type; if ( clazz.isAnnotationPresent( Entity.class ) ) { type = AnnotatedClassType.ENTITY; } else if ( clazz.isAnnotationPresent( Embeddable.class ) ) { type = AnnotatedClassType.EMBEDDABLE; } else if ( clazz.isAnnotationPresent( javax.persistence.MappedSuperclass.class ) ) { type = AnnotatedClassType.EMBEDDABLE_SUPERCLASS; } else { type = AnnotatedClassType.NONE; } annotatedClassTypeMap.put( clazz.getName(), type ); return type; }
public static InheritanceState getSuperclassInheritanceState(XClass clazz, Map<XClass, InheritanceState> states) { XClass superclass = clazz; do { superclass = superclass.getSuperclass(); InheritanceState currentState = states.get( superclass ); if ( currentState != null ) { return currentState; } } while ( superclass != null && !Object.class.getName().equals( superclass.getName() ) ); return null; }
public void bindEntity() { persistentClass.setAbstract( annotatedClass.isAbstract() ); persistentClass.setClassName( annotatedClass.getName() ); persistentClass.setJpaEntityName(name); persistentClass.setEntityName( annotatedClass.getName() ); bindDiscriminatorValue(); persistentClass.setProxyInterfaceName( proxyClass.getName() ); if ( annotatedClass.isAnnotationPresent( Immutable.class ) ) { mutable = false; annotatedClass.getAnnotation( org.hibernate.annotations.Entity.class ); if ( entityAnn != null ) { mutable = entityAnn.mutable(); LOG.entityAnnotationOnNonRoot(annotatedClass.getName()); if (annotatedClass.isAnnotationPresent(Immutable.class)) { LOG.immutableAnnotationOnNonRoot(annotatedClass.getName()); Persister persisterAnn = annotatedClass.getAnnotation( Persister.class ); Class persister = null; if ( persisterAnn != null ) { org.hibernate.annotations.Entity entityAnn = annotatedClass.getAnnotation( org.hibernate.annotations.Entity.class ); if ( entityAnn != null && !BinderHelper.isEmptyAnnotationValue( entityAnn.persister() ) ) { try {
.isAssignableFrom( returnedClassOrElement ) ) { type = SerializableToBlobType.class.getName(); typeParameters.setProperty( SerializableToBlobType.CLASS_NAME, returnedClassOrElement.getName() ); if ( returnedClassOrElement.isEnum() ) { type = EnumType.class.getName();
javax.persistence.DiscriminatorColumn discAnn = clazzToProcess.getAnnotation( javax.persistence.DiscriminatorColumn.class ); : DiscriminatorType.STRING; org.hibernate.annotations.DiscriminatorFormula discFormulaAnn = clazzToProcess.getAnnotation( org.hibernate.annotations.DiscriminatorFormula.class ); LOG.invalidDiscriminatorAnnotation( clazzToProcess.getName() ); final String discriminatorValue = clazzToProcess.isAnnotationPresent( DiscriminatorValue.class ) ? clazzToProcess.getAnnotation( DiscriminatorValue.class ).value() : null; entityBinder.setDiscriminatorValue( discriminatorValue ); DiscriminatorOptions discriminatorOptions = clazzToProcess.getAnnotation( DiscriminatorOptions.class ); if ( discriminatorOptions != null) { entityBinder.setForceDiscriminator( discriminatorOptions.force() );
/** * Recursively adds all audited properties of entity class and its superclasses. * * @param clazz Currently processed class. */ private void addPropertiesFromClass(XClass clazz) { final Audited allClassAudited = computeAuditConfiguration( clazz ); //look in the class addFromProperties( clazz.getDeclaredProperties( "field" ), it -> "field", fieldAccessedPersistentProperties, allClassAudited ); addFromProperties( clazz.getDeclaredProperties( "property" ), propertyAccessedPersistentProperties::get, propertyAccessedPersistentProperties.keySet(), allClassAudited ); if ( allClassAudited != null || !auditedPropertiesHolder.isEmpty() ) { final XClass superclazz = clazz.getSuperclass(); if ( !clazz.isInterface() && !"java.lang.Object".equals( superclazz.getName() ) ) { addPropertiesFromClass( superclazz ); } } }
XClass xClazz = parseContext.getCurrentClass(); Class<?> clazz = reflectionManager.toClass( xClazz ); if ( reflectionManager.toXClass( Coordinates.class ).isAssignableFrom( xClazz ) ) { spatialBridge = bridgeFactory.buildSpatialBridge( spatialAnnotation, clazz, null, null ); List<XProperty> fieldList = xClazz.getDeclaredProperties( XClass.ACCESS_FIELD ); .equals( spatialAnnotation.name() ) ) { if ( latitudeField != null ) { throw log.ambiguousLatitudeDefinition( xClazz.getName(), latitudeField, property.getName() ); if ( longitudeField != null ) { throw log.ambiguousLongitudeDefinition( xClazz.getName(), longitudeField, property.getName() List<XProperty> propertyList = xClazz.getDeclaredProperties( XClass.ACCESS_PROPERTY ); .equals( spatialAnnotation.name() ) ) { if ( latitudeField != null ) { throw log.ambiguousLatitudeDefinition( xClazz.getName(), latitudeField, property.getName() ); if ( longitudeField != null ) { throw log.ambiguousLongitudeDefinition( xClazz.getName(), longitudeField, property.getName()
final Audited allClassAudited = clazz.getAnnotation( Audited.class ); if ( allClassAudited != null && allClassAudited.auditParents().length > 0 ) { for ( Class c : allClassAudited.auditParents() ) { final XClass superclass = clazz.getSuperclass(); if ( !clazz.isInterface() && !Object.class.getName().equals( superclass.getName() ) ) { readAuditOverrides( superclass );
private static boolean hasAnnotationsOnIdClass(XClass idClass) { // if(idClass.getAnnotation(Embeddable.class) != null) // return true; List<XProperty> properties = idClass.getDeclaredProperties( XClass.ACCESS_FIELD ); for ( XProperty property : properties ) { if ( property.isAnnotationPresent( Column.class ) || property.isAnnotationPresent( OneToMany.class ) || property.isAnnotationPresent( ManyToOne.class ) || property.isAnnotationPresent( Id.class ) || property.isAnnotationPresent( GeneratedValue.class ) || property.isAnnotationPresent( OneToOne.class ) || property.isAnnotationPresent( ManyToMany.class ) ) { return true; } } List<XMethod> methods = idClass.getDeclaredMethods(); for ( XMethod method : methods ) { if ( method.isAnnotationPresent( Column.class ) || method.isAnnotationPresent( OneToMany.class ) || method.isAnnotationPresent( ManyToOne.class ) || method.isAnnotationPresent( Id.class ) || method.isAnnotationPresent( GeneratedValue.class ) || method.isAnnotationPresent( OneToOne.class ) || method.isAnnotationPresent( ManyToMany.class ) ) { return true; } } return false; }
final IndexedTypeIdentifier mappedClassIdentifier = new PojoIndexedTypeIdentifier( mappedClass ); if ( mappedXClass.isAnnotationPresent( Indexed.class ) ) { if ( mappedXClass.isAbstract() ) { log.abstractClassesCannotInsertDocuments( mappedXClass.getName() ); continue;
collectAttributeConversionInfo( infoMap, xClass.getSuperclass() ); final boolean canContainConvert = xClass.isAnnotationPresent( javax.persistence.Entity.class ) || xClass.isAnnotationPresent( javax.persistence.MappedSuperclass.class ) || xClass.isAnnotationPresent( javax.persistence.Embeddable.class ); if ( ! canContainConvert ) { return; final Convert convertAnnotation = xClass.getAnnotation( Convert.class ); if ( convertAnnotation != null ) { final AttributeConversionInfo info = new AttributeConversionInfo( convertAnnotation, xClass ); final Converts convertsAnnotation = xClass.getAnnotation( Converts.class ); if ( convertsAnnotation != null ) { for ( Convert convertAnnotation : convertsAnnotation.value() ) {
public String getTypeName() throws MappingException { return returnedClass == null ? null : returnedClass.getName(); }
private static void getListeners(XClass currentClazz, List<Class> orderedListeners) { EntityListeners entityListeners = currentClazz.getAnnotation( EntityListeners.class ); if ( entityListeners != null ) { Class[] classes = entityListeners.value(); int size = classes.length; for ( int index = size - 1; index >= 0; index-- ) { orderedListeners.add( classes[index] ); } } if ( useAnnotationAnnotatedByListener ) { Annotation[] annotations = currentClazz.getAnnotations(); for ( Annotation annot : annotations ) { entityListeners = annot.getClass().getAnnotation( EntityListeners.class ); if ( entityListeners != null ) { Class[] classes = entityListeners.value(); int size = classes.length; for ( int index = size - 1; index >= 0; index-- ) { orderedListeners.add( classes[index] ); } } } } } }
private void insertMappedSuperclasses(List<XClass> original, List<XClass> copy) { for ( XClass clazz : original ) { XClass superClass = clazz.getSuperclass(); while ( superClass != null && !reflectionManager.equals( superClass, Object.class ) && !copy.contains( superClass ) ) { if ( superClass.isAnnotationPresent( Entity.class ) || superClass.isAnnotationPresent( javax.persistence.MappedSuperclass.class ) ) { copy.add( superClass ); } superClass = superClass.getSuperclass(); } } }
/** * @param clazz Source class. * * @return List of @AuditOverride annotations applied at class level. */ private List<AuditOverride> computeAuditOverrides(XClass clazz) { final AuditOverrides auditOverrides = clazz.getAnnotation( AuditOverrides.class ); final AuditOverride auditOverride = clazz.getAnnotation( AuditOverride.class ); if ( auditOverrides == null && auditOverride != null ) { return Arrays.asList( auditOverride ); } else if ( auditOverrides != null && auditOverride == null ) { return Arrays.asList( auditOverrides.value() ); } else if ( auditOverrides != null && auditOverride != null ) { throw new MappingException( "@AuditOverrides annotation should encapsulate all @AuditOverride declarations. " + "Please revise Envers annotations applied to class " + clazz.getName() + "." ); } return Collections.emptyList(); }
private ModificationStore getDefaultAudited(XClass clazz) { final Audited defaultAudited = clazz.getAnnotation( Audited.class ); if ( defaultAudited != null ) { return defaultAudited.modStore(); } else { return null; } }
/** * @param clazz Source class. * @param propertyName Property name. * @param accessType Expected access type. Legal values are <i>field</i> and <i>property</i>. * * @return Property object or {@code null} if none with expected name and access type has been found. */ public static XProperty getProperty(XClass clazz, String propertyName, String accessType) { for ( XProperty property : clazz.getDeclaredProperties( accessType ) ) { if ( propertyName.equals( property.getName() ) ) { return property; } } return null; }