private AnnotationBusinessKeyMetadata(final Class<?> type) { Assert.notNull(type, "Given Type must not be null"); businessKeyField = ReflectionUtils.findField(type, BUSINESSKEY_FILTER); }
/** * Finds the field matching the given {@link DescribedFieldFilter}. Will make sure there's only one field matching the * filter. * * @see #findField(Class, DescribedFieldFilter, boolean) * @param type must not be {@literal null}. * @param filter must not be {@literal null}. * @return the field matching the given {@link DescribedFieldFilter} or {@literal null} if none found. * @throws IllegalStateException in case more than one matching field is found */ @Nullable public static Field findField(Class<?> type, DescribedFieldFilter filter) { return findField(type, filter, true); }
/** * Finds the first field on the given class matching the given {@link FieldFilter}. * * @param type must not be {@literal null}. * @param filter must not be {@literal null}. * @return the field matching the filter or {@literal null} in case no field could be found. */ @Nullable public static Field findField(Class<?> type, FieldFilter filter) { return findField(type, new DescribedFieldFilter() { public boolean matches(Field field) { return filter.matches(field); } public String getDescription() { return String.format("FieldFilter %s", filter.toString()); } }, false); }
/** * Creates a new {@link AnnotationAuditingMetadata} instance for the given type. * * @param type must not be {@literal null}. */ private AnnotationAuditingMetadata(Class<?> type) { Assert.notNull(type, "Given type must not be null!"); this.createdByField = Optional.ofNullable(ReflectionUtils.findField(type, CREATED_BY_FILTER)); this.createdDateField = Optional.ofNullable(ReflectionUtils.findField(type, CREATED_DATE_FILTER)); this.lastModifiedByField = Optional.ofNullable(ReflectionUtils.findField(type, LAST_MODIFIED_BY_FILTER)); this.lastModifiedDateField = Optional.ofNullable(ReflectionUtils.findField(type, LAST_MODIFIED_DATE_FILTER)); assertValidDateFieldType(createdDateField); assertValidDateFieldType(lastModifiedDateField); }
/** * Creates a new {@link AnnotationAuditingMetadata} instance for the given type. * @param type must not be {@literal null}. */ private AnnotationAuditingMetadata(Class<?> type) { Assert.notNull(type, "Given type must not be null!"); this.createdByField = Optional .ofNullable(ReflectionUtils.findField(type, CREATED_BY_FILTER)); this.createdDateField = Optional .ofNullable(ReflectionUtils.findField(type, CREATED_DATE_FILTER)); this.lastModifiedByField = Optional .ofNullable(ReflectionUtils.findField(type, LAST_MODIFIED_BY_FILTER)); this.lastModifiedDateField = Optional .ofNullable(ReflectionUtils.findField(type, LAST_MODIFIED_DATE_FILTER)); assertValidDateFieldType(createdDateField); assertValidDateFieldType(lastModifiedDateField); }
public void purperSequence(MongoTemplate template, String collectionName, Object entity) { Optional<Field> noField = Optional.ofNullable(ReflectionUtils.findField(entity.getClass(), IDNO_FILTER)); noField.ifPresent(f -> { try { String fieldName = noField.get().getName(); Long increment = generate(template, collectionName, fieldName, 1l); f.setAccessible(true); f.set(entity, increment); } catch (Exception e) { e.printStackTrace(); } }); }
private Object invokeWithIntecept(MethodInvocation invocation) throws Throwable { Object entity = invocation.getArguments()[0]; Field idField = ReflectionUtils.findField(entity.getClass(), ID_FILTER); if (idField == null) { idField = ReflectionUtils.findField(entity.getClass(), DATA_ID_FILTER); } if (idField == null) { return invocation.proceed(); } org.springframework.util.ReflectionUtils.makeAccessible(idField); Object id = org.springframework.util.ReflectionUtils.getField(idField, entity); if (locker.lockOwner(id) == null || locker.isLockOwner(id, auth.getAuthentication())) { return invocation.proceed(); } else { throw new LockOwnerException("Not lock owner"); } } }