Java Code Examples for org.springframework.data.util.ReflectionUtils

The following examples show how to use org.springframework.data.util.ReflectionUtils. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
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");
    }
}
 
Example 2
/**
 * 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);
}
 
Example 3
@Override
public Optional<TemporalAccessor> getLastModifiedDate() {

	return getAsTemporalAccessor(
			metadata.getLastModifiedDateField().map(field -> {

				Object value = org.springframework.util.ReflectionUtils
						.getField(field, target);
				return value instanceof Optional
						? ((Optional<?>) value).orElse(null) : value;

			}), TemporalAccessor.class);
}
 
Example 4
/**
 * Sets the given field to the given value if the field is not {@literal null}.
 * @param field
 * @param value
 */
private TemporalAccessor setDateField(Optional<Field> field,
		TemporalAccessor value) {

	field.ifPresent(it -> ReflectionUtils.setField(it, target,
			getDateValueToSet(value, it.getType(), it)));

	return value;
}
 
Example 5
Source Project: HA-DB   Source File: SequenceOption.java    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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();
		}
	});
}
 
Example 6
private MongoAuth instantiateMongoAuth(String username, String password, String authDb) {
    Optional<Constructor<?>> constructor = ReflectionUtils.findConstructor(MongoAuth.class, username, password, authDb);
    if (constructor.isPresent()) {
        return (MongoAuth) BeanUtils.instantiateClass(constructor.get(), username, password, authDb);
    }

    constructor = ReflectionUtils.findConstructor(MongoAuth.class, username, password);
    if (constructor.isPresent()) {
        return (MongoAuth) BeanUtils.instantiateClass(constructor.get(), username, password);
    }

    throw new IllegalStateException("No suitable constructor found to instantiate MongoAuth. " +
            "Are you using a supported Mongeez version?");
}
 
Example 7
/**
 * Sets the given field to the given value if present.
 * @param field
 * @param value
 */
private <S> S setField(Optional<Field> field, S value) {

	field.ifPresent(it -> ReflectionUtils.setField(it, target, value));

	return value;
}