当前位置: 首页>>代码示例>>Java>>正文


Java ClassTypeInformation类代码示例

本文整理汇总了Java中org.springframework.data.util.ClassTypeInformation的典型用法代码示例。如果您正苦于以下问题:Java ClassTypeInformation类的具体用法?Java ClassTypeInformation怎么用?Java ClassTypeInformation使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ClassTypeInformation类属于org.springframework.data.util包,在下文中一共展示了ClassTypeInformation类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: write

import org.springframework.data.util.ClassTypeInformation; //导入依赖的package包/类
@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 = conversions.hasCustomWriteTarget(entityType,
			SecretDocument.class);
	if (!handledByCustomConverter) {
		typeMapper.writeType(type, sink.getBody());
	}
}
 
开发者ID:spring-projects,项目名称:spring-vault,代码行数:17,代码来源:MappingVaultConverter.java

示例2: extractTypeInfo

import org.springframework.data.util.ClassTypeInformation; //导入依赖的package包/类
/**
 * 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()));
}
 
开发者ID:xiangxik,项目名称:java-platform,代码行数:27,代码来源:DefaultPredicateArgumentResolver.java

示例3: writeMap

import org.springframework.data.util.ClassTypeInformation; //导入依赖的package包/类
/**
 * @param keyspace
 * @param path
 * @param mapValueType
 * @param source
 * @param sink
 */
private void writeMap(String keyspace, String path, Class<?> mapValueType, Map<?, ?> source, RedisData sink) {
	if (CollectionUtils.isEmpty(source)) {
		return;
	}

	for (Map.Entry<?, ?> entry : source.entrySet()) {

		if (entry.getValue() == null || entry.getKey() == null) {
			continue;
		}

		String currentPath = path + ".[" + entry.getKey() + "]";

		if (conversionService.canConvert(entry.getValue().getClass(), byte[].class)) {
			sink.addDataEntry(toBytes(currentPath), toBytes(entry.getValue()));
		} else {
			writeInternal(keyspace, currentPath, entry.getValue(), ClassTypeInformation.from(mapValueType), sink);
		}
	}
}
 
开发者ID:christophstrobl,项目名称:spring-data-keyvalue-redis,代码行数:28,代码来源:MappingRedisConverter.java

示例4: write

import org.springframework.data.util.ClassTypeInformation; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public void write(Object source, @SuppressWarnings("rawtypes") Map target) {
	if (source == null) {
		return;
	}

	if (hasCustomWriteTarget(source.getClass(), SolrInputDocument.class)
			&& canConvert(source.getClass(), SolrInputDocument.class)) {
		SolrInputDocument convertedDocument = convert(source, SolrInputDocument.class);
		target.putAll(convertedDocument);
		return;

	}

	TypeInformation<? extends Object> type = ClassTypeInformation.from(source.getClass());
	write(type, source, target);
}
 
开发者ID:ramaava,项目名称:spring-data-solr,代码行数:19,代码来源:MappingSolrConverter.java

示例5: DefaultRepositoryExtensionMetadata

import org.springframework.data.util.ClassTypeInformation; //导入依赖的package包/类
/**
 * Creates a new {@link DefaultRepositoryExtensionMetadata} for the given repository extension interface.
 * 
 * @param repositoryInterface must not be {@literal null}.
 */
public DefaultRepositoryExtensionMetadata(Class<?> repositoryInterface) {

	super(repositoryInterface);
	Assert.isTrue(RepositoryExtension.class.isAssignableFrom(repositoryInterface), MUST_BE_A_REPOSITORY_EXTENSION);

	List<TypeInformation<?>> arguments = ClassTypeInformation.from(repositoryInterface) //
			.getRequiredSuperTypeInformation(RepositoryExtension.class)//
			.getTypeArguments();

	this.domainType = resolveTypeParameter(arguments, 0,
			() -> String.format("Could not resolve domain type of %s!", repositoryInterface));
	this.idType = resolveTypeParameter(arguments, 1,
			() -> String.format("Could not resolve id type of %s!", repositoryInterface));
}
 
开发者ID:snowdrop,项目名称:spring-data-snowdrop,代码行数:20,代码来源:DefaultRepositoryExtensionMetadata.java

示例6: should_return_the_attribute_name

import org.springframework.data.util.ClassTypeInformation; //导入依赖的package包/类
@Test public void
should_return_the_attribute_name(){
	
	MongoPersistentEntity<FieldWithoutAnnotation> entity = new BasicMongoPersistentEntity<FieldWithoutAnnotation>(ClassTypeInformation.from(FieldWithoutAnnotation.class));
	java.lang.reflect.Field field = ReflectionUtils.findField(FieldWithoutAnnotation.class, "name");
	
	BasicMongoPersistentProperty persistentProperty = new BasicMongoPersistentProperty(field, null, entity, new SimpleTypeHolder());		
	String fieldName = persistentProperty.getFieldName();
	
	assertEquals("Class attribute reading failed", field.getName(), fieldName);
}
 
开发者ID:wesley-ramos,项目名称:spring-multitenancy,代码行数:12,代码来源:BasicMongoPersistentPropertyTest.java

示例7: should_return_the_name_using_the_annotation

import org.springframework.data.util.ClassTypeInformation; //导入依赖的package包/类
@Test public void
should_return_the_name_using_the_annotation(){
	
	MongoPersistentEntity<AnnotatedField> entity = new BasicMongoPersistentEntity<AnnotatedField>(ClassTypeInformation.from(AnnotatedField.class));
	java.lang.reflect.Field field = ReflectionUtils.findField(AnnotatedField.class, "name");
	
	BasicMongoPersistentProperty persistentProperty = new BasicMongoPersistentProperty(field, null, entity, new SimpleTypeHolder());		
	String fieldName = persistentProperty.getFieldName();
	
	assertEquals("Class attribute reading failed","name_user", fieldName);
}
 
开发者ID:wesley-ramos,项目名称:spring-multitenancy,代码行数:12,代码来源:BasicMongoPersistentPropertyTest.java

示例8: createJpaQuery

import org.springframework.data.util.ClassTypeInformation; //导入依赖的package包/类
public Query createJpaQuery(String queryString) {
        Class<?> objectType = getQueryMethod().getReturnedObjectType();

        //get original proxy query.
        Query oriProxyQuery;

        //must be hibernate QueryImpl
        QueryImpl query;

        if (useJpaSpec && getQueryMethod().isQueryForEntity()) {
            oriProxyQuery = getEntityManager().createNativeQuery(queryString, objectType);

//            QueryImpl query = AopTargetUtils.getTarget(oriProxyQuery);
        } else {
            oriProxyQuery = getEntityManager().createNativeQuery(queryString);

			query = AopTargetUtils.getTarget(oriProxyQuery);
			//find generic type
			ClassTypeInformation<?> ctif = ClassTypeInformation.from(objectType);
			TypeInformation<?> actualType = ctif.getActualType();
			if (actualType == null){
			    actualType = ctif.getRawTypeInformation();
            }
			Class<?> genericType = actualType.getType();
			if (genericType != null && genericType != Void.class) {
				QueryBuilder.transform(query.getHibernateQuery(), genericType);
			}
		}
        //return the original proxy query, for a series of JPA actions, e.g.:close em.
        return oriProxyQuery;
    }
 
开发者ID:slyak,项目名称:spring-data-jpa-extra,代码行数:32,代码来源:FreemarkerTemplateQuery.java

示例9: read

import org.springframework.data.util.ClassTypeInformation; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private <S> S read(TypeInformation<S> type, Object source) {

	SecretDocument secretDocument = getSecretDocument(source);

	TypeInformation<? extends S> typeToUse = secretDocument != null ? typeMapper
			.readType(secretDocument.getBody(), type)
			: (TypeInformation) ClassTypeInformation.OBJECT;
	Class<? extends S> rawType = typeToUse.getType();

	if (conversions.hasCustomReadTarget(source.getClass(), rawType)) {
		return conversionService.convert(source, rawType);
	}

	if (SecretDocument.class.isAssignableFrom(rawType)) {
		return (S) source;
	}

	if (Map.class.isAssignableFrom(rawType) && secretDocument != null) {
		return (S) secretDocument.getBody();
	}

	if (typeToUse.isMap() && secretDocument != null) {
		return (S) readMap(typeToUse, secretDocument.getBody());
	}

	if (typeToUse.equals(ClassTypeInformation.OBJECT)) {
		return (S) source;
	}

	return read(
			(VaultPersistentEntity<S>) mappingContext
					.getRequiredPersistentEntity(typeToUse),
			secretDocument);
}
 
开发者ID:spring-projects,项目名称:spring-vault,代码行数:36,代码来源:MappingVaultConverter.java

示例10: readCollectionOrArray

import org.springframework.data.util.ClassTypeInformation; //导入依赖的package包/类
/**
 * 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());
}
 
开发者ID:spring-projects,项目名称:spring-vault,代码行数:46,代码来源:MappingVaultConverter.java

示例11: writeInternal

import org.springframework.data.util.ClassTypeInformation; //导入依赖的package包/类
/**
 * Internal write conversion method which should be used for nested invocations.
 *
 * @param obj
 * @param sink
 * @param typeHint
 */
@SuppressWarnings("unchecked")
protected void writeInternal(Object obj, SecretDocumentAccessor sink,
		@Nullable TypeInformation<?> typeHint) {

	Class<?> entityType = obj.getClass();
	Optional<Class<?>> customTarget = conversions.getCustomWriteTarget(entityType,
			SecretDocument.class);

	if (customTarget.isPresent()) {

		SecretDocument result = conversionService.convert(obj, SecretDocument.class);

		if (result.getId() != null) {
			sink.setId(result.getId());
		}

		sink.getBody().putAll(result.getBody());
		return;
	}

	if (Map.class.isAssignableFrom(entityType)) {
		writeMapInternal((Map<Object, Object>) obj, sink.getBody(),
				ClassTypeInformation.MAP);
		return;
	}

	VaultPersistentEntity<?> entity = mappingContext
			.getRequiredPersistentEntity(entityType);
	writeInternal(obj, sink, entity);
	addCustomTypeKeyIfNecessary(typeHint, obj, sink);
}
 
开发者ID:spring-projects,项目名称:spring-vault,代码行数:39,代码来源:MappingVaultConverter.java

示例12: writeMapInternal

import org.springframework.data.util.ClassTypeInformation; //导入依赖的package包/类
/**
 * Writes the given {@link Map} to the given {@link Map} considering the given
 * {@link TypeInformation}.
 *
 * @param obj must not be {@literal null}.
 * @param bson must not be {@literal null}.
 * @param propertyType must not be {@literal null}.
 * @return
 */
protected Map<String, Object> writeMapInternal(Map<Object, Object> obj,
		Map<String, Object> bson, TypeInformation<?> propertyType) {

	for (Entry<Object, Object> entry : obj.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())) {
				bson.put(simpleKey, val);
			}
			else if (val instanceof Collection || val.getClass().isArray()) {

				bson.put(
						simpleKey,
						writeCollectionInternal(asCollection(val),
								propertyType.getMapValueType(), new ArrayList<>()));
			}
			else {
				SecretDocumentAccessor nested = new SecretDocumentAccessor(
						new SecretDocument());
				TypeInformation<?> valueTypeInfo = propertyType.isMap() ? propertyType
						.getMapValueType() : ClassTypeInformation.OBJECT;
				writeInternal(val, nested, valueTypeInfo);
				bson.put(simpleKey, nested.getBody());
			}
		}
		else {
			throw new MappingException("Cannot use a complex object as a key value.");
		}
	}

	return bson;
}
 
开发者ID:spring-projects,项目名称:spring-vault,代码行数:47,代码来源:MappingVaultConverter.java

示例13: read

import org.springframework.data.util.ClassTypeInformation; //导入依赖的package包/类
@Override
public <S, R> List<R> read(SolrDocumentList source, Class<R> type) {
	if (source == null) {
		return Collections.emptyList();
	}

	List<R> resultList = new ArrayList<R>(source.size());
	TypeInformation<R> typeInformation = ClassTypeInformation.from(type);
	for (Map<String, ?> item : source) {
		resultList.add(read(typeInformation, item));
	}

	return resultList;
}
 
开发者ID:yiduwangkai,项目名称:dubbox-solr,代码行数:15,代码来源:MappingSolrConverter.java

示例14: afterPropertiesSet

import org.springframework.data.util.ClassTypeInformation; //导入依赖的package包/类
@Override
@SuppressWarnings({ CompilerWarnings.UNCHECKED })
public void afterPropertiesSet() {
    this.entityMetadata = this.entityManager.getEntityManagerFactory().unwrap(SessionFactory.class).getSessionFactoryOptions().getServiceRegistry()
        .getService(DbMetadataService.class).getEntityMetadatas().get((this.entityClass =
            ((Class<T>) ClassTypeInformation.from(this.repoInterface).getSuperTypeInformation(SdcctRepository.class).getTypeArguments().get(0).getType())));
    this.entityClasses =
        Stream.of(this.entityClass, (this.entityImplClass = ((Class<? extends T>) this.entityMetadata.getMappedClass()))).collect(Collectors.toSet());
    this.metamodel = this.entityManager.getMetamodel();

    super.afterPropertiesSet();
}
 
开发者ID:esacinc,项目名称:sdcct,代码行数:13,代码来源:SdcctRepositoryFactoryBean.java

示例15: testIdType

import org.springframework.data.util.ClassTypeInformation; //导入依赖的package包/类
@Test
public void testIdType() throws NoSuchFieldException, SecurityException {
	Mockito.when(persistentEntity.getTypeInformation()).thenReturn(ClassTypeInformation.from(ProductBean.class));
	SimpleSolrPersistentProperty property = new SimpleSolrPersistentProperty(ProductBean.class.getDeclaredField("id"),
			null, persistentEntity, new SimpleTypeHolder());
	Mockito.when(persistentEntity.getIdProperty()).thenReturn(property);

	SolrEntityInformation<ProductBean, String> entityInformation = new MappingSolrEntityInformation<ProductBean, String>(
			persistentEntity);
	Assert.assertEquals(String.class, entityInformation.getIdType());
}
 
开发者ID:ramaava,项目名称:spring-data-solr,代码行数:12,代码来源:MappingSolrEntityInformationTests.java


注:本文中的org.springframework.data.util.ClassTypeInformation类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。