@Override @SuppressWarnings("unchecked") public BulkOperations updateMulti(Query query, Update update) { Assert.notNull(query, "Query must not be null!"); Assert.notNull(update, "Update must not be null!"); return updateMulti(Collections.singletonList(Pair.of(query, update))); }
/** * Resolves the type variables to be used. Uses the parent's type variable map but overwrites variables locally * declared. * * @param type must not be {@literal null}. * @param parent must not be {@literal null}. * @return will never be {@literal null}. */ private static Map<TypeVariable<?>, Type> calculateTypeVariables(ParameterizedType type, TypeDiscoverer<?> parent) { Class<?> resolvedType = parent.resolveType(type); TypeVariable<?>[] typeParameters = resolvedType.getTypeParameters(); Type[] arguments = type.getActualTypeArguments(); Map<TypeVariable<?>, Type> localTypeVariables = new HashMap<>(parent.getTypeVariableMap()); IntStream.range(0, typeParameters.length) // .mapToObj(it -> Pair.of(typeParameters[it], flattenTypeVariable(arguments[it], localTypeVariables))) // .forEach(it -> localTypeVariables.put(it.getFirst(), it.getSecond())); return localTypeVariables; }
private Map<Method, RepositoryQuery> mapMethodsToQuery(RepositoryInformation repositoryInformation, QueryLookupStrategy lookupStrategy, ProjectionFactory projectionFactory) { return repositoryInformation.getQueryMethods().stream() // .map(method -> lookupQuery(method, repositoryInformation, lookupStrategy, projectionFactory)) // .peek(pair -> invokeListeners(pair.getSecond())) // .collect(Pair.toMap()); }
/** * Creates a new {@link Pair} for the given elements. * * @param first must not be {@literal null}. * @param second must not be {@literal null}. * @return */ public static <S, T> Pair<S, T> of(S first, T second) { return new Pair<>(first, second); }
/** * The most suitable delete method is selected as follows: We prefer * <ol> * <li>a {@link RepositoryMetadata#getDomainType()} as first parameter over</li> * <li>a {@link RepositoryMetadata#getIdType()} as first parameter over</li> * <li>a {@link Object} as first parameter over</li> * <li>an {@link Iterable} as first parameter.</li> * </ol> * * @param metadata must not be {@literal null}. * @return the most suitable method or {@literal null} if no method could be found. */ private static Optional<Method> selectMostSuitableDeleteMethod(RepositoryMetadata metadata) { Stream<Pair<String, Class<?>>> source = Stream.of(// Pair.of(DELETE, metadata.getDomainType()), // Pair.of(DELETE_BY_ID, metadata.getIdType()), // Pair.of(DELETE, Object.class), // Pair.of(DELETE_BY_ID, Object.class), // Pair.of(DELETE, Iterable.class)); Class<?> repositoryInterface = metadata.getRepositoryInterface(); return source// .flatMap(it -> toStream(findMethod(repositoryInterface, it.getFirst(), it.getSecond())))// .flatMap(it -> toStream(getMostSpecificMethod(it, repositoryInterface)))// .findFirst(); }
@Override @Nullable protected TypeInformation<?> doGetMapValueType() { if (Map.class.isAssignableFrom(getType())) { Type[] arguments = type.getActualTypeArguments(); if (arguments.length > 1) { return createInfo(arguments[1]); } } Class<?> rawType = getType(); Set<Type> supertypes = new HashSet<>(); Optional.ofNullable(rawType.getGenericSuperclass()).ifPresent(supertypes::add); supertypes.addAll(Arrays.asList(rawType.getGenericInterfaces())); Optional<TypeInformation<?>> result = supertypes.stream()// .map(it -> Pair.of(it, resolveType(it)))// .filter(it -> Map.class.isAssignableFrom(it.getSecond()))// .<TypeInformation<?>> map(it -> { ParameterizedType parameterizedSupertype = (ParameterizedType) it.getFirst(); Type[] arguments = parameterizedSupertype.getActualTypeArguments(); return createInfo(arguments[1]); }).findFirst(); return result.orElseGet(super::doGetMapValueType); }
@Override @SuppressWarnings("unchecked") public BulkOperations updateOne(Query query, Update update) { Assert.notNull(query, "Query must not be null!"); Assert.notNull(update, "Update must not be null!"); return updateOne(Collections.singletonList(Pair.of(query, update))); }
@Override @SuppressWarnings("unchecked") public BulkOperations updateMulti(Query query, Update update) { Assert.notNull(query, "Query must not be null!"); Assert.notNull(update, "Update must not be null!"); return updateMulti(Collections.singletonList(Pair.of(query, update))); }
@Override @SuppressWarnings("unchecked") public BulkOperations updateOne(Query query, Update update) { Assert.notNull(query, "Query must not be null!"); Assert.notNull(update, "Update must not be null!"); return updateOne(Collections.singletonList(Pair.of(query, update))); }
/** * Returns a {@link Pair} if both {@link Optional} instances have values or {@link Optional#empty()} if one or both * are missing. * * @param left * @param right * @return */ public static <T, S> Optional<Pair<T, S>> withBoth(Optional<T> left, Optional<S> right) { return left.flatMap(l -> right.map(r -> Pair.of(l, r))); }
private Pair<Method, RepositoryQuery> lookupQuery(Method method, RepositoryInformation information, QueryLookupStrategy strategy, ProjectionFactory projectionFactory) { return Pair.of(method, strategy.resolveQuery(method, information, projectionFactory, namedQueries)); }
/** * Creates a {@link PersistentPropertyPath} for the given parts and {@link TypeInformation}. * * @param propertyPath must not be {@literal null}. * @param type must not be {@literal null}. * @return */ private PersistentPropertyPath<P> createPersistentPropertyPath(String propertyPath, TypeInformation<?> type) { String trimmedPath = propertyPath.trim(); List<String> parts = trimmedPath.isEmpty() // ? Collections.emptyList() // : Arrays.asList(trimmedPath.split("\\.")); DefaultPersistentPropertyPath<P> path = DefaultPersistentPropertyPath.empty(); Iterator<String> iterator = parts.iterator(); E current = context.getRequiredPersistentEntity(type); while (iterator.hasNext()) { String segment = iterator.next(); final DefaultPersistentPropertyPath<P> currentPath = path; Pair<DefaultPersistentPropertyPath<P>, E> pair = getPair(path, iterator, segment, current); if (pair == null) { String source = StringUtils.collectionToDelimitedString(parts, "."); throw new InvalidPersistentPropertyPath(source, type, segment, currentPath); } path = pair.getFirst(); current = pair.getSecond(); } return path; }
public String localize(InternationalizedValue value, Language language) { return localizationMap.get( Pair.of( value, language ) ); } }
/** * Executes a PartTree-based query. * @param type the type of the underlying entity * @param tree the parsed metadata of the query * @param params the parameters of this specific query * @param spannerTemplate used to execute the query * @param spannerMappingContext used to get metadata about the entity type * @param <T> the type of the underlying entity * @return list of entities. */ public static <T> List<T> executeQuery(Class<T> type, PartTree tree, Object[] params, SpannerTemplate spannerTemplate, SpannerMappingContext spannerMappingContext) { Pair<String, List<String>> sqlAndTags = buildPartTreeSqlString(tree, spannerMappingContext, type); return spannerTemplate.query(type, buildStatementFromSqlWithArgs( sqlAndTags.getFirst(), sqlAndTags.getSecond(), null, spannerTemplate.getSpannerEntityProcessor().getWriteConverter(), params), null); }