/** * Creates a new {@link JpaMetamodel} for the given JPA {@link Metamodel}. * * @param metamodel must not be {@literal null}. */ private JpaMetamodel(Metamodel metamodel) { Assert.notNull(metamodel, "Metamodel must not be null!"); this.metamodel = metamodel; this.managedTypes = Lazy.of(() -> metamodel.getManagedTypes().stream() // .map(ManagedType::getJavaType) // .filter(it -> it != null) // .collect(StreamUtils.toUnmodifiableSet())); }
private Lazy<String> bodyExtractor(Request request) { return Lazy.of(() -> { try { return EntityUtils.toString(request.getEntity()); } catch (IOException e) { throw new RequestBodyEncodingException("Error encoding request", e); } }); }
/** * Creates a new {@link JpaPersistentPropertyImpl} * * @param metamodel must not be {@literal null}. * @param property must not be {@literal null}. * @param owner must not be {@literal null}. * @param simpleTypeHolder must not be {@literal null}. */ public JpaPersistentPropertyImpl(JpaMetamodel metamodel, Property property, PersistentEntity<?, JpaPersistentProperty> owner, SimpleTypeHolder simpleTypeHolder) { super(property, owner, simpleTypeHolder); Assert.notNull(metamodel, "Metamodel must not be null!"); this.isAssociation = Lazy.of(() -> ASSOCIATION_ANNOTATIONS.stream().anyMatch(this::isAnnotationPresent)); this.usePropertyAccess = detectPropertyAccess(); this.associationTargetType = detectAssociationTargetType(); this.updateable = detectUpdatability(); this.isIdProperty = Lazy.of(() -> ID_ANNOTATIONS.stream().anyMatch(it -> isAnnotationPresent(it)) // || metamodel.isSingleIdAttribute(getOwner().getType(), getName(), getType())); this.isEntity = Lazy.of(() -> metamodel.isJpaManaged(getActualType())); }
DefaultExposureAwareCrudMethods(CrudMethods crudMethods, boolean exportedDefault) { Assert.notNull(crudMethods, "CrudMethods must not be null!"); this.exposesSave = Lazy.of(() -> exposes(crudMethods.getSaveMethod())); this.exposesDelete = Lazy.of(() -> exposes(crudMethods.getDeleteMethod()) && crudMethods.hasFindOneMethod()); this.exposesFindOne = Lazy.of(() -> exposes(crudMethods.getFindOneMethod())); this.exposesFindAll = Lazy.of(() -> exposes(crudMethods.getFindAllMethod())); this.exportedDefault = exportedDefault; }
public RepositoryRestMvcConfiguration(ApplicationContext context, @Qualifier("mvcConversionService") ObjectFactory<ConversionService> conversionService) { super(context, conversionService); this.mapper = Lazy.of(() -> { Jdk8Module jdk8Module = new Jdk8Module(); jdk8Module.configureAbsentsAsNulls(true); ObjectMapper mapper = basicObjectMapper(); mapper.registerModule(persistentEntityJackson2Module()); mapper.registerModule(jdk8Module); return mapper; }); }
/** * Creates a new {@link RelationalPersistentEntityImpl} for the given {@link TypeInformation}. * * @param information must not be {@literal null}. */ RelationalPersistentEntityImpl(TypeInformation<T> information, NamingStrategy namingStrategy) { super(information); this.namingStrategy = namingStrategy; this.tableName = Lazy.of(() -> Optional.ofNullable(findAnnotation(Table.class)).map(Table::value)); }
/** * Returns a new Lazy that will return the given value in case the current one does not yield in a result. * * @param supplier must not be {@literal null}. * @return */ public Lazy<T> or(T value) { Assert.notNull(value, "Value must not be null!"); return Lazy.of(() -> orElse(value)); }
/** * Creates a new {@link RelationalPersistentEntityImpl} for the given {@link TypeInformation}. * * @param information must not be {@literal null}. */ RelationalPersistentEntityImpl(TypeInformation<T> information, NamingStrategy namingStrategy) { super(information); this.namingStrategy = namingStrategy; this.tableName = Lazy.of(() -> Optional.ofNullable(findAnnotation(Table.class)).map(Table::value)); }
/** * Creates a new {@link RelationalPersistentEntityImpl} for the given {@link TypeInformation}. * * @param information must not be {@literal null}. */ RelationalPersistentEntityImpl(TypeInformation<T> information, NamingStrategy namingStrategy) { super(information); this.namingStrategy = namingStrategy; this.tableName = Lazy.of(() -> Optional.ofNullable( // findAnnotation(Table.class)) // .map(Table::value) // .filter(StringUtils::hasText) // ); }
/** * Returns a new Lazy that will consume the given supplier in case the current one does not yield in a result. * * @param supplier must not be {@literal null}. * @return */ public Lazy<T> or(Supplier<? extends T> supplier) { Assert.notNull(supplier, "Supplier must not be null!"); return Lazy.of(() -> orElseGet(supplier)); }
/** * Creates a new {@link Lazy} with the given {@link Function} lazily applied to the current one. * * @param function must not be {@literal null}. * @return */ public <S> Lazy<S> map(Function<? super T, ? extends S> function) { Assert.notNull(function, "Function must not be null!"); return Lazy.of(() -> function.apply(get())); }
/** * Creates a new {@link ExtensionAwareQueryMethodEvaluationContextProvider} using the given * {@link EvaluationContextExtension}s. * * @param extensions must not be {@literal null}. */ public ExtensionAwareQueryMethodEvaluationContextProvider(List<? extends EvaluationContextExtension> extensions) { Assert.notNull(extensions, "EvaluationContextExtensions must not be null!"); this.delegate = Lazy.of(new org.springframework.data.spel.ExtensionAwareEvaluationContextProvider(extensions)); }
/** * Creates a new {@link AnnotationNamingMethodParameter} for the given {@link Method}'s parameter with the given * index. * * @param method must not be {@literal null}. * @param parameterIndex * @param attribute can be {@literal null} */ public AnnotationNamingMethodParameter(Method method, int parameterIndex, Optional<AnnotationAttribute> attribute) { super(method, parameterIndex); this.attribute = attribute; this.name = Lazy.of(() -> this.attribute.// flatMap(it -> it.getValueFrom(this).map(Object::toString)).// orElseGet(super::getParameterName)); }
/** * Creates a new {@link JpaMetamodel} for the given JPA {@link Metamodel}. * * @param metamodel must not be {@literal null}. */ private JpaMetamodel(Metamodel metamodel) { Assert.notNull(metamodel, "Metamodel must not be null!"); this.metamodel = metamodel; this.managedTypes = Lazy.of(() -> metamodel.getManagedTypes().stream() // .map(ManagedType::getJavaType) // .filter(it -> it != null) // .collect(StreamUtils.toUnmodifiableSet())); }
/** * Creates a new {@link Lazy} with the given {@link Function} lazily applied to the current one. * * @param function must not be {@literal null}. * @return */ public <S> Lazy<S> flatMap(Function<? super T, Lazy<? extends S>> function) { Assert.notNull(function, "Function must not be null!"); return Lazy.of(() -> function.apply(get()).get()); }
/** * Creates a new {@link AbstractRepositoryMetadata}. * * @param repositoryInterface must not be {@literal null} and must be an interface. */ public AbstractRepositoryMetadata(Class<?> repositoryInterface) { Assert.notNull(repositoryInterface, "Given type must not be null!"); Assert.isTrue(repositoryInterface.isInterface(), "Given type must be an interface!"); this.repositoryInterface = repositoryInterface; this.typeInformation = ClassTypeInformation.from(repositoryInterface); this.crudMethods = Lazy.of(() -> new DefaultCrudMethods(this)); }
/** * Creates a new {@link BasicCassandraPersistentTupleEntity} given {@link TypeInformation} and * {@link TupleTypeFactory}. * * @param information must not be {@literal null}. * @param tupleTypeFactory must not be {@literal null}. */ public BasicCassandraPersistentTupleEntity(TypeInformation<T> information, TupleTypeFactory tupleTypeFactory) { super(information, CassandraPersistentTupleMetadataVerifier.INSTANCE, TuplePropertyComparator.INSTANCE); Assert.notNull(tupleTypeFactory, "TupleTypeFactory must not be null"); this.tupleType = Lazy.of(() -> tupleTypeFactory.create(getTupleFieldDataTypes())); }
/** * Creates a new {@link ParameterizedTypeInformation} for the given {@link Type} and parent {@link TypeDiscoverer}. * * @param type must not be {@literal null} * @param parent must not be {@literal null} */ public ParameterizedTypeInformation(ParameterizedType type, TypeDiscoverer<?> parent) { super(type, parent, calculateTypeVariables(type, parent)); this.type = type; this.resolved = Lazy.of(() -> isResolvedCompletely()); }
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)); }); }
public RepositoryRestMvcConfiguration(ApplicationContext context, @Qualifier("mvcConversionService") ObjectFactory<ConversionService> conversionService) { super(context, conversionService); this.mapper = Lazy.of(() -> { Jdk8Module jdk8Module = new Jdk8Module(); jdk8Module.configureAbsentsAsNulls(true); ObjectMapper mapper = basicObjectMapper(); mapper.registerModule(persistentEntityJackson2Module()); mapper.registerModule(jdk8Module); return mapper; }); }