Refine search
/** * 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 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 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()); }
/** * Returns a {@link Lazy} for the unique bean of the given type from the given {@link BeanFactory} (which needs to be * a {@link ListableBeanFactory}). The lookup will produce a {@link NoUniqueBeanDefinitionException} in case multiple * beans of the given type are available in the given {@link BeanFactory}. * * @param type must not be {@literal null}. * @param beanFactory the {@link BeanFactory} to lookup the bean from. * @return a {@link Lazy} for the unique bean of the given type or the instance provided by the fallback in case no * bean of the given type can be found. */ public static <T> Lazy<T> lazyIfAvailable(Class<T> type, BeanFactory beanFactory) { Assert.notNull(type, "Type must not be null!"); Assert.isInstanceOf(ListableBeanFactory.class, beanFactory); return Lazy.of(() -> lookupBean(type, (ListableBeanFactory) beanFactory)); }
/** * 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 CustomRepositoryImplementationDetector} with the given {@link Environment} and * {@link ResourceLoader}. Calls to {@link #detectCustomImplementation(ImplementationLookupConfiguration)} will issue * scans for * * @param environment must not be {@literal null}. * @param resourceLoader must not be {@literal null}. */ public CustomRepositoryImplementationDetector(Environment environment, ResourceLoader resourceLoader) { Assert.notNull(environment, "Environment must not be null!"); Assert.notNull(resourceLoader, "ResourceLoader must not be null!"); this.environment = environment; this.resourceLoader = resourceLoader; this.implementationCandidates = Lazy.empty(); }
/** * Returns the value of the lazy computation or the value produced by the given {@link Supplier} in case the original * value is {@literal null}. * * @param supplier must not be {@literal null}. * @return */ @Nullable private T orElseGet(Supplier<? extends T> supplier) { Assert.notNull(supplier, "Default value supplier must not be null!"); T value = getNullable(); return value == null ? supplier.get() : value; }
@Override public boolean isEntity() { return isEntity.get(); }
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); } }); }
public void afterPropertiesSet() { this.factory = createRepositoryFactory(); this.factory.setQueryLookupStrategyKey(queryLookupStrategyKey); this.factory.setNamedQueries(namedQueries); this.factory.setEvaluationContextProvider( evaluationContextProvider.orElseGet(() -> QueryMethodEvaluationContextProvider.DEFAULT)); this.factory.setBeanClassLoader(classLoader); this.factory.setBeanFactory(beanFactory); if (publisher != null) { this.factory.addRepositoryProxyPostProcessor(new EventPublishingRepositoryProxyPostProcessor(publisher)); } repositoryBaseClass.ifPresent(this.factory::setRepositoryBaseClass); RepositoryFragments customImplementationFragment = customImplementation // .map(RepositoryFragments::just) // .orElseGet(RepositoryFragments::empty); RepositoryFragments repositoryFragmentsToUse = this.repositoryFragments // .orElseGet(RepositoryFragments::empty) // .append(customImplementationFragment); this.repositoryMetadata = this.factory.getRepositoryMetadata(repositoryInterface); // Make sure the aggregate root type is present in the MappingContext (e.g. for auditing) this.mappingContext.ifPresent(it -> it.getPersistentEntity(repositoryMetadata.getDomainType())); this.repository = Lazy.of(() -> this.factory.getRepository(repositoryInterface, repositoryFragmentsToUse)); if (!lazyInit) { this.repository.get(); } }
/** * Returns the {@link Optional} value created by the configured {@link Supplier}, allowing the absence of values in * contrast to {@link #get()}. Will return the calculated instance for subsequent lookups. * * @return */ public Optional<T> getOptional() { return Optional.ofNullable(getNullable()); }
/** * Creates a new {@link Lazy} to produce an object lazily. * * @param <T> the type of which to produce an object of eventually. * @param supplier the {@link Supplier} to create the object lazily. * @return */ public static <T> Lazy<T> of(Supplier<? extends T> supplier) { return new Lazy<>(supplier); }
private Property(TypeInformation<?> type, Optional<Field> field, Optional<PropertyDescriptor> descriptor) { Assert.notNull(type, "Type must not be null!"); Assert.isTrue(Optionals.isAnyPresent(field, descriptor), "Either field or descriptor has to be given!"); this.field = field; this.descriptor = descriptor; this.rawType = withFieldOrDescriptor( // it -> type.getRequiredProperty(it.getName()).getType(), // it -> type.getRequiredProperty(it.getName()).getType() // ); this.hashCode = Lazy.of(() -> withFieldOrDescriptor(Object::hashCode)); this.name = Lazy.of(() -> withFieldOrDescriptor(Field::getName, FeatureDescriptor::getName)); this.toString = Lazy.of(() -> withFieldOrDescriptor(Object::toString, it -> String.format("%s.%s", type.getType().getName(), it.getDisplayName()))); this.getter = descriptor.map(PropertyDescriptor::getReadMethod)// .filter(it -> getType() != null)// .filter(it -> getType().isAssignableFrom(type.getReturnType(it).getType())); this.setter = descriptor.map(PropertyDescriptor::getWriteMethod)// .filter(it -> getType() != null)// .filter(it -> type.getParameterTypes(it).get(0).getType().isAssignableFrom(getType())); this.wither = Lazy.of(() -> findWither(type, getName(), getType())); }
/** * 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())); }
@Override public boolean isIdProperty() { return isIdProperty.get(); }
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; }); }
/** * Returns the value created by the configured {@link Supplier}. Will return the calculated instance for subsequent * lookups. * * @return */ public T get() { T value = getNullable(); if (value == null) { throw new IllegalStateException("Expected lazy evaluation to yield a non-null value but got null!"); } return value; }