/** * Creates a new {@link ReflectionRevisionEntityInformation} inspecting the given revision entity class. * * @param revisionEntityClass must not be {@literal null}. */ public ReflectionRevisionEntityInformation(Class<?> revisionEntityClass) { Assert.notNull(revisionEntityClass, "Revision entity type must not be null!"); AnnotationDetectionFieldCallback fieldCallback = new AnnotationDetectionFieldCallback(RevisionNumber.class); ReflectionUtils.doWithFields(revisionEntityClass, fieldCallback); this.revisionNumberType = fieldCallback.getRequiredType(); this.revisionEntityClass = revisionEntityClass; }
/** * Returns the type of the field or throws an {@link IllegalArgumentException} if no field could be found. * * @return * @throws IllegalStateException in case no field with the configured annotation was found. */ public Class<?> getRequiredType() { return getRequiredField().getType(); }
private static <T> Lazy<Optional<T>> detectAnnotation(Object entity, Class<? extends Annotation> annotationType) { return Lazy.of(() -> { AnnotationDetectionFieldCallback callback = new AnnotationDetectionFieldCallback(annotationType); ReflectionUtils.doWithFields(entity.getClass(), callback); return Optional.ofNullable(callback.getValue(entity)); }); }
/** * Creates a new {@link ReflectionEntityInformation} inspecting the given domain class for a field carrying the given * annotation. * * @param domainClass must not be {@literal null}. * @param annotation must not be {@literal null}. */ public ReflectionEntityInformation(Class<T> domainClass, final Class<? extends Annotation> annotation) { super(domainClass); Assert.notNull(annotation, "Annotation must not be null!"); AnnotationDetectionFieldCallback callback = new AnnotationDetectionFieldCallback(annotation); ReflectionUtils.doWithFields(domainClass, callback); try { this.field = callback.getRequiredField(); } catch (IllegalStateException o_O) { throw new IllegalArgumentException(String.format("Couldn't find field with annotation %s!", annotation), o_O); } ReflectionUtils.makeAccessible(this.field); }
/** * Creates a new {@link AnnotationRevisionMetadata} inspecing the given entity for the given annotations. If no * annotations will be provided these values will not be looked up from the entity and return {@literal null}. * * @param entity must not be {@literal null}. * @param revisionNumberAnnotation * @param revisionTimeStampAnnotation */ public AnnotationRevisionMetadata(final Object entity, Class<? extends Annotation> revisionNumberAnnotation, Class<? extends Annotation> revisionTimeStampAnnotation) { Assert.notNull(entity); this.entity = entity; if (revisionNumberAnnotation != null) { AnnotationDetectionFieldCallback numberCallback = new AnnotationDetectionFieldCallback(revisionNumberAnnotation); ReflectionUtils.doWithFields(entity.getClass(), numberCallback); this.revisionNumber = numberCallback.getValue(entity); } else { this.revisionNumber = null; } if (revisionTimeStampAnnotation != null) { AnnotationDetectionFieldCallback revisionCallback = new AnnotationDetectionFieldCallback( revisionTimeStampAnnotation); ReflectionUtils.doWithFields(entity.getClass(), revisionCallback); this.revisionDate = new DateTime(revisionCallback.getValue(entity)); } else { this.revisionDate = null; } }
public MybatisReflectionEntityInformation(Class<T> domainClass) { super(domainClass); IdClass idClass = domainClass.getAnnotation(IdClass.class); if (null != idClass) { this.idClass = idClass.value(); } else { for (Class<? extends Annotation> annotation : MybatisPersistentPropertyImpl.ID_ANNOTATIONS) { AnnotationDetectionFieldCallback callback = new AnnotationDetectionFieldCallback( annotation); ReflectionUtils.doWithFields(domainClass, callback); try { this.field = callback.getRequiredField(); } catch (IllegalStateException o_O) { } if (null != this.field) { ReflectionUtils.makeAccessible(this.field); break; } } } }