本文整理汇总了Java中org.springframework.data.util.ClassTypeInformation.from方法的典型用法代码示例。如果您正苦于以下问题:Java ClassTypeInformation.from方法的具体用法?Java ClassTypeInformation.from怎么用?Java ClassTypeInformation.from使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.data.util.ClassTypeInformation
的用法示例。
在下文中一共展示了ClassTypeInformation.from方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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());
}
}
示例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()));
}
示例3: 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);
}
示例4: 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);
}
示例5: 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);
}
示例6: 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;
}
示例7: 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;
}
示例8: testGetCollection
import org.springframework.data.util.ClassTypeInformation; //导入方法依赖的package包/类
@Test
public void testGetCollection() {
final BasicDocumentDbPersistentEntity entity = new BasicDocumentDbPersistentEntity<Person>(
ClassTypeInformation.from(Person.class));
assertThat(entity.getCollection()).isEqualTo("");
}
开发者ID:Microsoft,项目名称:spring-data-documentdb,代码行数:7,代码来源:BasicDocumentDbPersistentEntityUnitTest.java
示例9: testGetLanguage
import org.springframework.data.util.ClassTypeInformation; //导入方法依赖的package包/类
@Test
public void testGetLanguage() {
final BasicDocumentDbPersistentEntity entity = new BasicDocumentDbPersistentEntity<Person>(
ClassTypeInformation.from(Person.class));
assertThat(entity.getLanguage()).isEqualTo("");
}
开发者ID:Microsoft,项目名称:spring-data-documentdb,代码行数:7,代码来源:BasicDocumentDbPersistentEntityUnitTest.java
示例10: should_generate_the_name_of_the_collection_by_adding_the_tenant_at_startup
import org.springframework.data.util.ClassTypeInformation; //导入方法依赖的package包/类
@Test public void
should_generate_the_name_of_the_collection_by_adding_the_tenant_at_startup() throws ClassNotFoundException{
MultitenancyConfigLoader config = Mockito.mock(MultitenancyConfigLoader.class);
MongoConfigLoader mongoConfig = new MongoConfigLoader();
mongoConfig.setStrategy(MultitenancyStrategyEnum.COLLECTION);
when(config.getMongodb()).thenReturn(mongoConfig);
CurrentTenant.set("tenant");
MongoPersistentEntity<MyEntity> entity = new BasicMongoPersistentEntity<MyEntity>(ClassTypeInformation.from(MyEntity.class));
MappingMongoEntityInformation<MyEntity, Integer> entityInformation = new MappingMongoEntityInformation<MyEntity, Integer>(entity, config);
assertEquals("Class attribute reading failed","tenant_my_entity", entityInformation.getCollectionName());
}
示例11: isEntity
import org.springframework.data.util.ClassTypeInformation; //导入方法依赖的package包/类
protected static boolean isEntity(java.lang.reflect.Field field) {
TypeInformation typeInformation = ClassTypeInformation.from(field.getType());
Class<?> clazz = getFieldType(field);
boolean isComplexType = !SIMPLE_TYPE_HOLDER.isSimpleType(clazz);
return isComplexType && !Map.class.isAssignableFrom(typeInformation.getType());
}
示例12: writePropertyInternal
import org.springframework.data.util.ClassTypeInformation; //导入方法依赖的package包/类
@SuppressWarnings({ "unchecked" })
protected void writePropertyInternal(@Nullable Object obj,
SecretDocumentAccessor accessor, VaultPersistentProperty prop) {
if (obj == null) {
return;
}
TypeInformation<?> valueType = ClassTypeInformation.from(obj.getClass());
TypeInformation<?> type = prop.getTypeInformation();
if (valueType.isCollectionLike()) {
List<Object> collectionInternal = createCollection(asCollection(obj), prop);
accessor.put(prop, collectionInternal);
return;
}
if (valueType.isMap()) {
Map<String, Object> mapDbObj = createMap((Map<Object, Object>) obj, prop);
accessor.put(prop, mapDbObj);
return;
}
// Lookup potential custom target type
Optional<Class<?>> basicTargetType = conversions.getCustomWriteTarget(obj
.getClass());
if (basicTargetType.isPresent()) {
accessor.put(prop, conversionService.convert(obj, basicTargetType.get()));
return;
}
VaultPersistentEntity<?> entity = isSubtype(prop.getType(), obj.getClass()) ? mappingContext
.getRequiredPersistentEntity(obj.getClass()) : mappingContext
.getRequiredPersistentEntity(type);
SecretDocumentAccessor nested = accessor.writeNested(prop);
writeInternal(obj, nested, entity);
addCustomTypeKeyIfNecessary(ClassTypeInformation.from(prop.getRawType()), obj,
nested);
}
示例13: should_generate_the_collection_name_using_the_class_name
import org.springframework.data.util.ClassTypeInformation; //导入方法依赖的package包/类
@Test public void
should_generate_the_collection_name_using_the_class_name(){
ClassTypeInformation<?> info = ClassTypeInformation.from(ClassWithoutTheDocumentAnnotation.class);
TypeInformation<?> type = info.specialize(info);
BasicMongoPersistentEntity<?> persistentEntity = new BasicMongoPersistentEntity<>(type);
String expected = StringUtils.uncapitalize(ClassWithoutTheDocumentAnnotation.class.getSimpleName());
String collectionName = persistentEntity.getCollection();
assertEquals("Failed to Generate Collection Name", expected, collectionName);
}
示例14: should_generate_the_collection_name_by_using_the_annotation
import org.springframework.data.util.ClassTypeInformation; //导入方法依赖的package包/类
@Test public void
should_generate_the_collection_name_by_using_the_annotation(){
ClassTypeInformation<?> info = ClassTypeInformation.from(ClassWithTheDocumentAnnotation.class);
TypeInformation<?> type = info.specialize(info);
BasicMongoPersistentEntity<?> persistentEntity = new BasicMongoPersistentEntity<>(type);
Document annotation = ClassWithTheDocumentAnnotation.class.getAnnotation(Document.class);
String collectionName = persistentEntity.getCollection();
assertEquals("Failed to Generate Collection Name", annotation.name(), collectionName);
}