org.springframework.data.util.TypeInformation Java Examples
The following examples show how to use
org.springframework.data.util.TypeInformation.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ReactiveNeo4jQueryMethod.java From sdn-rx with Apache License 2.0 | 6 votes |
/** * Creates a new {@link ReactiveNeo4jQueryMethod} from the given parameters. * * @param method must not be {@literal null}. * @param metadata must not be {@literal null}. * @param factory must not be {@literal null}. */ ReactiveNeo4jQueryMethod(Method method, RepositoryMetadata metadata, ProjectionFactory factory) { super(method, metadata, factory); if (hasParameterOfType(method, Pageable.class)) { TypeInformation<?> returnType = ClassTypeInformation.fromReturnTypeOf(method); boolean multiWrapper = ReactiveWrappers.isMultiValueType(returnType.getType()); boolean singleWrapperWithWrappedPageableResult = ReactiveWrappers.isSingleValueType(returnType.getType()) && (PAGE_TYPE.isAssignableFrom(returnType.getRequiredComponentType()) || SLICE_TYPE.isAssignableFrom(returnType.getRequiredComponentType())); if (singleWrapperWithWrappedPageableResult) { throw new InvalidDataAccessApiUsageException( String.format("'%s.%s' must not use sliced or paged execution. Please use Flux.buffer(size, skip).", ClassUtils.getShortName(method.getDeclaringClass()), method.getName())); } if (!multiWrapper) { throw new IllegalStateException(String.format( "Method has to use a multi-item reactive wrapper return type. Offending method: %s", method.toString())); } } }
Example #2
Source File: DefaultArangoConverter.java From spring-data with Apache License 2.0 | 6 votes |
private void writeArray( final String attribute, final Object source, final VPackBuilder sink, final TypeInformation<?> definedType) { if (byte[].class.equals(source.getClass())) { sink.add(attribute, Base64Utils.encodeToString((byte[]) source)); } else { sink.add(attribute, ValueType.ARRAY); for (int i = 0; i < Array.getLength(source); ++i) { final Object element = Array.get(source, i); writeInternal(null, element, sink, getNonNullComponentType(definedType)); } sink.close(); } }
Example #3
Source File: DefaultPredicateArgumentResolver.java From java-platform with Apache License 2.0 | 6 votes |
private static TypeInformation<?> detectDomainType(TypeInformation<?> source) { if (source.getTypeArguments().isEmpty()) { return source; } TypeInformation<?> actualType = source.getActualType(); if (source != actualType) { return detectDomainType(actualType); } if (source instanceof Iterable) { return source; } return detectDomainType(source.getComponentType()); }
Example #4
Source File: DefaultArangoConverter.java From spring-data with Apache License 2.0 | 6 votes |
private Object readArray(final TypeInformation<?> type, final VPackSlice source) { if (!source.isArray()) { throw new MappingException( String.format("Can't read array type %s from VPack type %s!", type, source.getType())); } final TypeInformation<?> componentType = getNonNullComponentType(type); final int length = source.getLength(); final Object array = Array.newInstance(componentType.getType(), length); for (int i = 0; i < length; ++i) { Array.set(array, i, readInternal(componentType, source.get(i))); } return array; }
Example #5
Source File: DefaultArangoConverter.java From spring-data with Apache License 2.0 | 6 votes |
private Object readCollection(final TypeInformation<?> type, final VPackSlice source) { if (!source.isArray()) { throw new MappingException( String.format("Can't read collection type %s from VPack type %s!", type, source.getType())); } final TypeInformation<?> componentType = getNonNullComponentType(type); final Class<?> collectionType = Iterable.class.equals(type.getType()) ? Collection.class : type.getType(); final Collection<Object> collection = CollectionFactory.createCollection(collectionType, componentType.getType(), source.getLength()); final Iterator<VPackSlice> iterator = source.arrayIterator(); while (iterator.hasNext()) { final VPackSlice elem = iterator.next(); collection.add(readInternal(componentType, elem)); } return collection; }
Example #6
Source File: DefaultArangoConverter.java From spring-data with Apache License 2.0 | 6 votes |
private Object readMap(final TypeInformation<?> type, final VPackSlice source) { if (!source.isObject()) { throw new MappingException( String.format("Can't read map type %s from VPack type %s!", type, source.getType())); } final Class<?> keyType = getNonNullComponentType(type).getType(); final TypeInformation<?> valueType = getNonNullMapValueType(type); final Map<Object, Object> map = CollectionFactory.createMap(type.getType(), keyType, source.size()); final Iterator<Entry<String, VPackSlice>> iterator = source.objectIterator(); while (iterator.hasNext()) { final Entry<String, VPackSlice> entry = iterator.next(); if (typeMapper.isTypeKey(entry.getKey())) { continue; } final Object key = convertIfNecessary(entry.getKey(), keyType); final VPackSlice value = entry.getValue(); map.put(key, readInternal(valueType, value)); } return map; }
Example #7
Source File: DefaultArangoPersistentEntity.java From spring-data with Apache License 2.0 | 6 votes |
public DefaultArangoPersistentEntity(final TypeInformation<T> information) { super(information); collection = StringUtils.uncapitalize(information.getType().getSimpleName()); context = new StandardEvaluationContext(); hashIndexedProperties = new ArrayList<>(); skiplistIndexedProperties = new ArrayList<>(); persistentIndexedProperties = new ArrayList<>(); geoIndexedProperties = new ArrayList<>(); fulltextIndexedProperties = new ArrayList<>(); repeatableAnnotationCache = new HashMap<>(); final Document document = findAnnotation(Document.class); final Edge edge = findAnnotation(Edge.class); if (edge != null) { collection = StringUtils.hasText(edge.value()) ? edge.value() : collection; collectionOptions = createCollectionOptions(edge); } else if (document != null) { collection = StringUtils.hasText(document.value()) ? document.value() : collection; collectionOptions = createCollectionOptions(document); } else { collectionOptions = new CollectionCreateOptions().type(CollectionType.DOCUMENT); } expression = PARSER.parseExpression(collection, ParserContext.TEMPLATE_EXPRESSION); }
Example #8
Source File: CrateDocumentConverter.java From spring-data-crate with Apache License 2.0 | 6 votes |
/** * Nesting Array or Collection types is not supported by crate. It is safe to assume that the payload * will contain either a Map or a primitive type. Map types will be converted to {@link CrateDocument} * while simple types will be added without any conversion * @param array {@link CrateArray} for adding either Map or Simple types * @param payload containing either a Map or primitive type. */ @SuppressWarnings("unchecked") private void toCrateArray(CrateArray array, Object payload) { Collection<Object> objects = (Collection<Object>)(payload.getClass().isArray() ? asList((Object[])payload) : payload); for(Object object : objects) { TypeInformation<?> type = getTypeInformation(object.getClass()); if(type.isMap()) { CrateDocument document = new CrateDocument(); toCrateDocument(document, object); array.add(document); }else { array.add(object); } } }
Example #9
Source File: EntityColumnMapper.java From spring-data-crate with Apache License 2.0 | 6 votes |
/** * @param properties properties of array/collection types, must not be {@literal null}. * @return list of columns of crate type array * @throws {@link InvalidCrateApiUsageException} */ public List<Column> mapColumns(Set<CratePersistentProperty> properties) { List<Column> columns = new LinkedList<>(); for(CratePersistentProperty property : properties) { TypeInformation<?> typeInformation = from(property.getComponentType()); // safety check if(property.isCollectionLike() && typeInformation.isMap()) { // could be a list or an array TypeInformation<?> actualType = property.getTypeInformation().getActualType(); // get the map's key type Class<?> componentType = actualType.getTypeArguments().get(0).getType(); checkMapKey(componentType); columns.add(createColumn(property)); } } return columns; }
Example #10
Source File: DefaultPredicateArgumentResolver.java From java-platform with Apache License 2.0 | 6 votes |
/** * Obtains the domain type information from the given method parameter. Will * favor an explicitly registered on through * {@link QuerydslPredicate#root()} but use the actual type of the method's * return type as fallback. * * @param parameter * must not be {@literal null}. * @return */ static TypeInformation<?> extractTypeInfo(MethodParameter parameter) { QuerydslPredicate annotation = parameter.getParameterAnnotation(QuerydslPredicate.class); if (annotation != null && !Object.class.equals(annotation.root())) { return ClassTypeInformation.from(annotation.root()); } Class<?> containingClass = parameter.getContainingClass(); if (ClassUtils.isAssignable(EntityController.class, containingClass)) { ResolvableType resolvableType = ResolvableType.forClass(containingClass); return ClassTypeInformation.from(resolvableType.as(EntityController.class).getGeneric(0).resolve()); } return detectDomainType(ClassTypeInformation.fromReturnTypeOf(parameter.getMethod())); }
Example #11
Source File: BasicVaultPersistentEntity.java From spring-vault with Apache License 2.0 | 6 votes |
/** * Creates new {@link BasicVaultPersistentEntity}. * @param information must not be {@literal null}. * @param fallbackKeySpaceResolver can be {@literal null}. */ public BasicVaultPersistentEntity(TypeInformation<T> information, KeySpaceResolver fallbackKeySpaceResolver) { super(information, fallbackKeySpaceResolver); Secret annotation = findAnnotation(Secret.class); if (annotation != null && StringUtils.hasText(annotation.backend())) { this.backend = annotation.backend(); this.backendExpression = detectExpression(this.backend); } else { this.backend = "secret"; this.backendExpression = null; } }
Example #12
Source File: DatastorePersistentEntityImpl.java From spring-cloud-gcp with Apache License 2.0 | 6 votes |
/** * Constructor. * @param information type information about the underlying entity type. * @param datastoreMappingContext a mapping context used to get metadata for related * persistent entities. */ public DatastorePersistentEntityImpl(TypeInformation<T> information, DatastoreMappingContext datastoreMappingContext) { super(information); Class<?> rawType = information.getType(); this.datastoreMappingContext = datastoreMappingContext; this.context = new StandardEvaluationContext(); this.kind = findAnnotation(Entity.class); this.discriminatorField = findAnnotation(DiscriminatorField.class); this.discriminatorValue = findAnnotation(DiscriminatorValue.class); this.classBasedKindName = this.hasTableName() ? this.kind.name() : StringUtils.uncapitalize(rawType.getSimpleName()); this.kindNameExpression = detectExpression(); }
Example #13
Source File: MybatisPersistentPropertyImpl.java From spring-data-mybatis with Apache License 2.0 | 6 votes |
@Nullable private TypeInformation<?> detectAssociationTargetType() { if (!isAssociation()) { return null; } for (Class<? extends Annotation> annotationType : ASSOCIATION_ANNOTATIONS) { Annotation annotation = findAnnotation(annotationType); if (annotation == null) { continue; } Object entityValue = AnnotationUtils.getValue(annotation, "targetEntity"); if (entityValue == null || entityValue.equals(void.class)) { continue; } return ClassTypeInformation.from((Class<?>) entityValue); } return null; }
Example #14
Source File: AbstractResolver.java From spring-data with Apache License 2.0 | 6 votes |
@SuppressWarnings({ "rawtypes", "unchecked" }) protected Object proxy( final String id, final TypeInformation<?> type, final A annotation, final ResolverCallback<A> callback) { final ProxyInterceptor interceptor = new ProxyInterceptor(id, type, annotation, callback, conversionService); if (type.getType().isInterface()) { final ProxyFactory proxyFactory = new ProxyFactory(new Class<?>[] { type.getType() }); for (final Class<?> interf : type.getType().getInterfaces()) { proxyFactory.addInterface(interf); } proxyFactory.addInterface(LazyLoadingProxy.class); proxyFactory.addAdvice(interceptor); return proxyFactory.getProxy(); } else { final Factory factory = (Factory) objenesis.newInstance(enhancedTypeFor(type.getType())); factory.setCallbacks(new Callback[] { interceptor }); return factory; } }
Example #15
Source File: MappingCrateConverter.java From spring-data-crate with Apache License 2.0 | 5 votes |
/** * Read a collection from the source object. * * @param targetType the target type. * @param source the list as source. * @param parent the optional parent. * @return the converted {@link Collection} or array, will never be {@literal null}. */ private Object readCollection(final TypeInformation<?> targetType, final CrateArray source, final Object parent) { notNull(targetType); Class<?> collectionType = targetType.getType(); if(source.isEmpty()) { return getPotentiallyConvertedSimpleRead(new HashSet<Object>(), collectionType); } collectionType = Collection.class.isAssignableFrom(collectionType) ? collectionType : List.class; Collection<Object> items = targetType.getType().isArray() ? new ArrayList<Object>(source.size()) : createCollection(collectionType, source.size()); TypeInformation<?> componentType = targetType.getComponentType(); Class<?> rawComponentType = componentType == null ? null : componentType.getType(); for(Object object : source) { if(object instanceof CrateDocument) { items.add(read(componentType, (CrateDocument) object, parent)); }else { items.add(getPotentiallyConvertedSimpleRead(object, rawComponentType)); } } return getPotentiallyConvertedSimpleRead(items, targetType.getType()); }
Example #16
Source File: SpannerMappingContext.java From spring-cloud-gcp with Apache License 2.0 | 5 votes |
@Override protected <T> SpannerPersistentEntity<T> createPersistentEntity( TypeInformation<T> typeInformation) { SpannerPersistentEntityImpl<T> persistentEntity = constructPersistentEntity(typeInformation); if (this.applicationContext != null) { persistentEntity.setApplicationContext(this.applicationContext); } return persistentEntity; }
Example #17
Source File: MappingCrateConverter.java From spring-data-crate with Apache License 2.0 | 5 votes |
@Override public void write(Object source, CrateDocument sink) { if(source == null) { return; } TypeInformation<?> type = from(source.getClass()); if(!conversions.hasCustomWriteTarget(source.getClass(), sink.getClass())) { typeMapper.writeType(type, sink); } writeInternal(source, sink, type); }
Example #18
Source File: DefaultArangoConverter.java From spring-data with Apache License 2.0 | 5 votes |
private void writeBaseEdgeDocument( final String attribute, final BaseEdgeDocument source, final VPackBuilder sink, final TypeInformation<?> definedType) { final VPackBuilder builder = new VPackBuilder(); writeMap(attribute, source.getProperties(), builder, definedType); builder.add(_ID, source.getId()); builder.add(_KEY, source.getKey()); builder.add(_REV, source.getRevision()); builder.add(_FROM, source.getFrom()); builder.add(_TO, source.getTo()); sink.add(attribute, builder.slice()); }
Example #19
Source File: MappingVaultConverter.java From spring-vault with Apache License 2.0 | 5 votes |
@Override public void write(Object source, SecretDocument sink) { Class<?> entityType = ClassUtils.getUserClass(source.getClass()); TypeInformation<? extends Object> type = ClassTypeInformation.from(entityType); SecretDocumentAccessor documentAccessor = new SecretDocumentAccessor(sink); writeInternal(source, documentAccessor, type); boolean handledByCustomConverter = this.conversions.hasCustomWriteTarget(entityType, SecretDocument.class); if (!handledByCustomConverter) { this.typeMapper.writeType(type, sink.getBody()); } }
Example #20
Source File: MappingCrateConverter.java From spring-data-crate with Apache License 2.0 | 5 votes |
/** * Helper method to write the map into the crate document. * * @param source the source object. * @param sink the target document. * @param type the type information for the document. * @return the written crate document. */ private CrateDocument writeMapInternal(final Map<Object, Object> source, final CrateDocument sink, final TypeInformation<?> type) { for(Map.Entry<Object, Object> entry : source.entrySet()) { Object key = entry.getKey(); Object val = entry.getValue(); if(conversions.isSimpleType(key.getClass())) { String simpleKey = key.toString(); if(val == null || (conversions.isSimpleType(val.getClass()) && !val.getClass().isArray())) { writeSimpleInternal(val, sink, simpleKey); }else if(val instanceof Collection || val.getClass().isArray()) { sink.put(simpleKey, writeCollectionInternal(asCollection(val), new CrateArray(), type.getMapValueType())); }else { CrateDocument document = new CrateDocument(); TypeInformation<?> valueTypeInfo = type.isMap() ? type.getMapValueType() : OBJECT; writeInternal(val, document, valueTypeInfo); sink.put(simpleKey, document); } } else { throw new MappingException("Cannot use a complex object as a key value."); } } return sink; }
Example #21
Source File: FirestorePersistentEntityImpl.java From spring-cloud-gcp with Apache License 2.0 | 5 votes |
private static <T> String getEntityCollectionName(TypeInformation<T> typeInformation) { Document document = AnnotationUtils.findAnnotation(typeInformation.getType(), Document.class); String collectionName = (String) AnnotationUtils.getValue(document, "collectionName"); if (StringUtils.isEmpty(collectionName)) { // Infer the collection name as the uncapitalized document name. return StringUtils.uncapitalize(typeInformation.getType().getSimpleName()); } else { return collectionName; } }
Example #22
Source File: DefaultArangoTypeMapper.java From spring-data with Apache License 2.0 | 5 votes |
public void writeType(final TypeInformation<?> info, final VPackBuilder sink) { Assert.notNull(info, "TypeInformation must not be null!"); final Alias alias = getAliasFor(info); if (alias.isPresent()) { accessor.writeTypeTo(sink, alias.getValue()); } }
Example #23
Source File: DefaultVaultTypeMapperUnitTests.java From spring-vault with Apache License 2.0 | 5 votes |
private void readsTypeFromField(Map<String, Object> document, @Nullable Class<?> type) { TypeInformation<?> typeInfo = this.typeMapper.readType(document); if (type != null) { assertThat(typeInfo).isNotNull(); assertThat(typeInfo.getType()).isAssignableFrom(type); } else { assertThat(typeInfo).isNull(); } }
Example #24
Source File: DefaultArangoTypeMapper.java From spring-data with Apache License 2.0 | 5 votes |
protected final Alias getAliasFor(final TypeInformation<?> info) { Assert.notNull(info, "TypeInformation must not be null!"); for (final TypeInformationMapper mapper : mappers) { final Alias alias = mapper.createAliasFor(info); if (alias.isPresent()) { return alias; } } return Alias.NONE; }
Example #25
Source File: MappingVaultConverter.java From spring-vault with Apache License 2.0 | 5 votes |
/** * Adds custom type information to the given {@link SecretDocument} if necessary. That * is if the value is not the same as the one given. This is usually the case if you * store a subtype of the actual declared type of the property. * @param type type hint. * @param value must not be {@literal null}. * @param accessor must not be {@literal null}. */ protected void addCustomTypeKeyIfNecessary(@Nullable TypeInformation<?> type, Object value, SecretDocumentAccessor accessor) { Class<?> reference = type != null ? type.getActualType().getType() : Object.class; Class<?> valueType = ClassUtils.getUserClass(value.getClass()); boolean notTheSameClass = !valueType.equals(reference); if (notTheSameClass) { this.typeMapper.writeType(valueType, accessor.getBody()); } }
Example #26
Source File: MappingCrateConverter.java From spring-data-crate with Apache License 2.0 | 5 votes |
/** * Adds custom type information to the given {@link CrateDocument} if necessary. * * @param type * @param value must not be {@literal null}. * @param document must not be {@literal null}. */ protected void addCustomTypeKeyIfNecessary(TypeInformation<?> type, Object value, CrateDocument document) { TypeInformation<?> actualType = type != null ? type.getActualType() : null; Class<?> reference = actualType == null ? Object.class : actualType.getType(); Class<?> valueType = getUserClass(value.getClass()); boolean notTheSameClass = !valueType.equals(reference); if(notTheSameClass) { typeMapper.writeType(valueType, document); } }
Example #27
Source File: TwoStepsConversions.java From spring-cloud-gcp with Apache License 2.0 | 5 votes |
private EntityValue convertOnWriteSingleEmbeddedMap(Object val, String kindName, TypeInformation valueTypeInformation) { return applyEntityValueBuilder(null, kindName, (builder) -> { Map map = (Map) val; for (Object key : map.keySet()) { String field = convertOnReadSingle(convertOnWriteSingle(key).get(), ClassTypeInformation.from(String.class)); builder.set(field, convertOnWrite(map.get(key), EmbeddedType.of(valueTypeInformation), field, valueTypeInformation)); } }, false); }
Example #28
Source File: SpannerMappingContextTests.java From spring-cloud-gcp with Apache License 2.0 | 5 votes |
private SpannerMappingContext createSpannerMappingContextWith( SpannerPersistentEntityImpl mockEntity) { return new SpannerMappingContext() { @Override @SuppressWarnings("unchecked") protected SpannerPersistentEntityImpl constructPersistentEntity( TypeInformation typeInformation) { return mockEntity; } }; }
Example #29
Source File: AbstractResolver.java From spring-data with Apache License 2.0 | 5 votes |
public ProxyInterceptor(final String id, final TypeInformation<?> type, final A annotation, final ResolverCallback<A> callback, final ConversionService conversionService) { super(); this.id = id; this.type = type; this.annotation = annotation; this.callback = callback; this.conversionService = conversionService; result = null; resolved = false; }
Example #30
Source File: MappingVaultConverter.java From spring-vault with Apache License 2.0 | 5 votes |
/** * Reads the given {@link List} into a collection of the given {@link TypeInformation} * . * @param targetType must not be {@literal null}. * @param sourceValue must not be {@literal null}. * @return the converted {@link Collection} or array, will never be {@literal null}. */ @Nullable @SuppressWarnings({ "rawtypes", "unchecked" }) private Object readCollectionOrArray(TypeInformation<?> targetType, List sourceValue) { Assert.notNull(targetType, "Target type must not be null"); Class<?> collectionType = targetType.getType(); TypeInformation<?> componentType = targetType.getComponentType() != null ? targetType.getComponentType() : ClassTypeInformation.OBJECT; Class<?> rawComponentType = componentType.getType(); collectionType = Collection.class.isAssignableFrom(collectionType) ? collectionType : List.class; Collection<Object> items = targetType.getType().isArray() ? new ArrayList<>(sourceValue.size()) : CollectionFactory.createCollection(collectionType, rawComponentType, sourceValue.size()); if (sourceValue.isEmpty()) { return getPotentiallyConvertedSimpleRead(items, collectionType); } for (Object obj : sourceValue) { if (obj instanceof Map) { items.add(read(componentType, (Map) obj)); } else if (obj instanceof List) { items.add(readCollectionOrArray(ClassTypeInformation.OBJECT, (List) obj)); } else { items.add(getPotentiallyConvertedSimpleRead(obj, rawComponentType)); } } return getPotentiallyConvertedSimpleRead(items, targetType.getType()); }