/** * Creates a new {@link PropertyPath} as subordinary of the given {@link PropertyPath}. * * @param source * @param base * @return */ private static PropertyPath create(String source, Stack<PropertyPath> base) { PropertyPath previous = base.peek(); PropertyPath propertyPath = create(source, previous.typeInformation.getRequiredActualType(), base); previous.next = propertyPath; return propertyPath; }
@Override public Class<?> getActualType() { return information.getRequiredActualType().getType(); }
private Object writeCollectionInternal(Collection<Object> source, TypeInformation<?> type) { Collection<Object> converted = CollectionFactory.createCollection(getCollectionType(type), source.size()); TypeInformation<?> actualType = type.getRequiredActualType(); for (Object element : source) { converted.add(convertToColumnType(element, actualType)); } return converted; }
@Nullable @Override public E getPersistentEntity(P persistentProperty) { Assert.notNull(persistentProperty, "PersistentProperty must not be null!"); if (!persistentProperty.isEntity()) { return null; } TypeInformation<?> typeInfo = persistentProperty.getTypeInformation(); return getPersistentEntity(typeInfo.getRequiredActualType()); }
@Nullable @Override public Predicate resolveArgument(MethodParameter parameter, @Nullable ModelAndViewContainer mavContainer, NativeWebRequest webRequest, @Nullable WebDataBinderFactory binderFactory) throws Exception { MultiValueMap<String, String> parameters = new LinkedMultiValueMap<>(); for (Entry<String, String[]> entry : webRequest.getParameterMap().entrySet()) { parameters.put(entry.getKey(), Arrays.asList(entry.getValue())); } Optional<QuerydslPredicate> annotation = Optional .ofNullable(parameter.getParameterAnnotation(QuerydslPredicate.class)); TypeInformation<?> domainType = extractTypeInfo(parameter).getRequiredActualType(); Optional<Class<? extends QuerydslBinderCustomizer<?>>> bindings = annotation// .map(QuerydslPredicate::bindings)// .map(CastUtils::cast); return predicateBuilder.getPredicate(domainType, parameters, bindings.map(it -> bindingsFactory.createBindingsFor(domainType, it)) .orElseGet(() -> bindingsFactory.createBindingsFor(domainType))); }
/** * Returns the type the given {@link PersistentProperty} ultimately refers to. In case it's of a unique identifier * type of an entity known it'll return the entity type. * * @param property must not be {@literal null}. * @return */ public TypeInformation<?> getTypeUltimatelyReferredToBy(PersistentProperty<?> property) { Assert.notNull(property, "PersistentProperty must not be null!"); PersistentEntity<?, ?> entity = getEntityUltimatelyReferredToBy(property); return entity == null // ? property.getTypeInformation().getRequiredActualType() // : entity.getTypeInformation(); }
@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); }
/** * Creates a leaf {@link PropertyPath} (no nested ones with the given name and owning type. * * @param name must not be {@literal null} or empty. * @param owningType must not be {@literal null}. * @param base the {@link PropertyPath} previously found. */ PropertyPath(String name, TypeInformation<?> owningType, List<PropertyPath> base) { Assert.hasText(name, "Name must not be null or empty!"); Assert.notNull(owningType, "Owning type must not be null!"); Assert.notNull(base, "Perviously found properties must not be null!"); String propertyName = Introspector.decapitalize(name); TypeInformation<?> propertyType = owningType.getProperty(propertyName); if (propertyType == null) { throw new PropertyReferenceException(propertyName, owningType, base); } this.owningType = owningType; this.typeInformation = propertyType; this.isCollection = propertyType.isCollectionLike(); this.name = propertyName; this.actualTypeInformation = propertyType.getActualType() == null ? propertyType : propertyType.getRequiredActualType(); }
@Nullable @Override public Object invoke(@SuppressWarnings("null") MethodInvocation invocation) throws Throwable { Method method = invocation.getMethod(); TypeInformation<Object> returnType = ClassTypeInformation.fromReturnTypeOf(method); ResolvableType type = ResolvableType.forMethodReturnType(method); boolean isCollectionResult = Collection.class.isAssignableFrom(type.getRawClass()); type = isCollectionResult ? type : ResolvableType.forClassWithGenerics(List.class, type); Iterable<String> jsonPaths = getJsonPaths(method); for (String jsonPath : jsonPaths) { try { if (returnType.getRequiredActualType().getType().isInterface()) { List<?> result = context.read(jsonPath); return result.isEmpty() ? null : result.get(0); } type = isCollectionResult && JsonPath.isPathDefinite(jsonPath) ? ResolvableType.forClassWithGenerics(List.class, type) : type; List<?> result = (List<?>) context.read(jsonPath, new ResolvableTypeRef(type)); if (isCollectionResult && JsonPath.isPathDefinite(jsonPath)) { result = (List<?>) result.get(0); } return isCollectionResult ? result : result.isEmpty() ? null : result.get(0); } catch (PathNotFoundException o_O) { // continue with next path } } return null; }
private Object getWriteValue(PersistentPropertyAccessor propertyAccessor, RelationalPersistentProperty property) { TypeInformation<?> type = property.getTypeInformation(); Object value = propertyAccessor.getProperty(property); if (type.isCollectionLike()) { RelationalPersistentEntity<?> nestedEntity = mappingContext .getPersistentEntity(type.getRequiredActualType().getType()); if (nestedEntity != null) { throw new InvalidDataAccessApiUsageException("Nested entities are not supported"); } ArrayColumns arrayColumns = dialect.getArraySupport(); if (!arrayColumns.isSupported()) { throw new InvalidDataAccessResourceUsageException( "Dialect " + dialect.getClass().getName() + " does not support array columns"); } return getArrayValue(arrayColumns, property, value); } return value; }
private Object getWriteValue(PersistentPropertyAccessor propertyAccessor, RelationalPersistentProperty property) { TypeInformation<?> type = property.getTypeInformation(); Object value = propertyAccessor.getProperty(property); if (type.isCollectionLike()) { RelationalPersistentEntity<?> nestedEntity = mappingContext .getPersistentEntity(type.getRequiredActualType().getType()); if (nestedEntity != null) { throw new InvalidDataAccessApiUsageException("Nested entities are not supported"); } ArrayColumns arrayColumns = dialect.getArraySupport(); if (!arrayColumns.isSupported()) { throw new InvalidDataAccessResourceUsageException( "Dialect " + dialect.getClass().getName() + " does not support array columns"); } return getArrayValue(arrayColumns, property, value); } return value; }
Supplier<DataType> fallback) { BasicCassandraPersistentEntity<?> persistentEntity = getPersistentEntity(typeInformation.getRequiredActualType()); .orElseGet(() -> { Class<?> propertyType = typeInformation.getRequiredActualType().getType();
@Nullable @SuppressWarnings("unchecked") private Object convertReadValue(Object value, TypeInformation<?> typeInformation) { if (typeInformation.isCollectionLike() && value instanceof Collection) { return readCollectionOrArrayInternal((Collection<?>) value, typeInformation); } if (typeInformation.isMap() && value instanceof Map) { return readMapInternal((Map<Object, Object>) value, typeInformation); } if (value instanceof TupleValue) { BasicCassandraPersistentEntity<?> tupleEntity = getMappingContext() .getPersistentEntity(typeInformation.getRequiredActualType()); if (tupleEntity != null) { return readEntityFromTuple(tupleEntity, (TupleValue) value); } } if (value instanceof UDTValue) { BasicCassandraPersistentEntity<?> udtEntity = getMappingContext() .getPersistentEntity(typeInformation.getRequiredActualType()); if (udtEntity != null && udtEntity.isUserDefinedType()) { return readEntityFromUdt(udtEntity, (UDTValue) value); } } return getPotentiallyConvertedSimpleRead(value, typeInformation.getType()); }
TypeInformation<?> actualType = type.getRequiredActualType();