@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))); }
@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)); }
public String localize(InternationalizedValue value, Language language) { return localizationMap.get( Pair.of( value, language ) ); } }
private void register(InternationalizedValue value, Language language, String translation) { localizationMap.put( Pair.of( value, language ), translation ); }
/** * 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); }
/** * 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; }
@Nullable private Pair<DefaultPersistentPropertyPath<P>, E> getPair(DefaultPersistentPropertyPath<P> path, Iterator<String> iterator, String segment, E entity) { P property = entity.getPersistentProperty(segment); if (property == null) { return null; } TypeInformation<?> type = property.getTypeInformation().getRequiredActualType(); return Pair.of(path.append(property), iterator.hasNext() ? context.getRequiredPersistentEntity(type) : entity); }
private List<PathNode> createNodes(PersistentPropertyPath<RelationalPersistentProperty> path, @Nullable PathNode parentNode, @Nullable Object value) { if (value == null) { return Collections.emptyList(); } List<PathNode> nodes = new ArrayList<>(); if (path.getRequiredLeafProperty().isQualified()) { if (path.getRequiredLeafProperty().isMap()) { ((Map<?, ?>) value).forEach((k, v) -> nodes.add(new PathNode(path, parentNode, Pair.of(k, v)))); } else { List listValue = (List) value; for (int k = 0; k < listValue.size(); k++) { nodes.add(new PathNode(path, parentNode, Pair.of(k, listValue.get(k)))); } } } else if (path.getRequiredLeafProperty().isCollectionLike()) { // collection value ((Collection<?>) value).forEach(v -> nodes.add(new PathNode(path, parentNode, v))); } else { // single entity value nodes.add(new PathNode(path, parentNode, value)); } return nodes; }
private List<PathNode> createNodes(PersistentPropertyPath<RelationalPersistentProperty> path, @Nullable PathNode parentNode, @Nullable Object value) { if (value == null) { return Collections.emptyList(); } List<PathNode> nodes = new ArrayList<>(); if (path.getRequiredLeafProperty().isQualified()) { if (path.getRequiredLeafProperty().isMap()) { ((Map<?, ?>) value).forEach((k, v) -> nodes.add(new PathNode(path, parentNode, Pair.of(k, v)))); } else { List listValue = (List) value; for (int k = 0; k < listValue.size(); k++) { nodes.add(new PathNode(path, parentNode, Pair.of(k, listValue.get(k)))); } } } else if (path.getRequiredLeafProperty().isCollectionLike()) { // collection value ((Collection<?>) value).forEach(v -> nodes.add(new PathNode(path, parentNode, v))); } else { // single entity value nodes.add(new PathNode(path, parentNode, value)); } return nodes; }
private List<PathNode> createNodes(PersistentPropertyPath<RelationalPersistentProperty> path, @Nullable PathNode parentNode, @Nullable Object value) { if (value == null) { return Collections.emptyList(); } List<PathNode> nodes = new ArrayList<>(); if (path.getRequiredLeafProperty().isEmbedded()) { nodes.add(new PathNode(path, parentNode, value)); } else if (path.getRequiredLeafProperty().isQualified()) { if (path.getRequiredLeafProperty().isMap()) { ((Map<?, ?>) value).forEach((k, v) -> nodes.add(new PathNode(path, parentNode, Pair.of(k, v)))); } else { List listValue = (List) value; for (int k = 0; k < listValue.size(); k++) { nodes.add(new PathNode(path, parentNode, Pair.of(k, listValue.get(k)))); } } } else if (path.getRequiredLeafProperty().isCollectionLike()) { // collection value ((Collection<?>) value).forEach(v -> nodes.add(new PathNode(path, parentNode, v))); } else { // single entity value nodes.add(new PathNode(path, parentNode, value)); } return nodes; }
private static Pair<String, List<String>> buildPartTreeSqlString(PartTree tree, SpannerMappingContext spannerMappingContext, Class type) { SpannerPersistentEntity<?> persistentEntity = spannerMappingContext .getPersistentEntity(type); List<String> tags = new ArrayList<>(); StringBuilder stringBuilder = new StringBuilder(); buildSelect(persistentEntity, tree, stringBuilder); buildFrom(persistentEntity, stringBuilder); buildWhere(tree, persistentEntity, tags, stringBuilder); applySort(tree.getSort(), stringBuilder, (o) -> persistentEntity .getPersistentProperty(o.getProperty()).getColumnName()); buildLimit(tree, stringBuilder); String selectSql = stringBuilder.toString(); String finalSql = selectSql; if (tree.isCountProjection()) { finalSql = "SELECT COUNT(1) FROM (" + selectSql + ")"; } else if (tree.isExistsProjection()) { finalSql = "SELECT EXISTS(" + selectSql + ")"; } return Pair.of(finalSql, tags); }
private static Pair<String, List<String>> buildPartTreeSqlString(PartTree tree, SpannerMappingContext spannerMappingContext, Class type) { SpannerPersistentEntity<?> persistentEntity = spannerMappingContext .getPersistentEntity(type); List<String> tags = new ArrayList<>(); StringBuilder stringBuilder = new StringBuilder(); buildSelect(persistentEntity, tree, stringBuilder); buildFrom(persistentEntity, stringBuilder); buildWhere(tree, persistentEntity, tags, stringBuilder); applySort(tree.getSort(), stringBuilder, (o) -> persistentEntity .getPersistentProperty(o.getProperty()).getColumnName()); buildLimit(tree, stringBuilder); String selectSql = stringBuilder.toString(); String finalSql = selectSql; if (tree.isCountProjection()) { finalSql = "SELECT COUNT(1) FROM (" + selectSql + ")"; } else if (tree.isExistsProjection()) { finalSql = "SELECT EXISTS(" + selectSql + ")"; } return Pair.of(finalSql, tags); }