Example usage for org.springframework.data.util TypeInformation getType

List of usage examples for org.springframework.data.util TypeInformation getType

Introduction

In this page you can find the example usage for org.springframework.data.util TypeInformation getType.

Prototype

Class<S> getType();

Source Link

Document

Returns the type of the property.

Usage

From source file:com.joyveb.dbpimpl.cass.prepare.mapping.CassandraSimpleTypes.java

public static DataType.Name[] convertPrimitiveTypeArguments(List<TypeInformation<?>> arguments) {
    DataType.Name[] result = new DataType.Name[arguments.size()];
    for (int i = 0; i != result.length; ++i) {
        TypeInformation<?> type = arguments.get(i);
        DataType dataType = autodetectPrimitive(type.getType());
        if (dataType == null) {
            throw new InvalidDataAccessApiUsageException(
                    "not found appropriate primitive DataType for type = '" + type.getType());
        }//from   w  w  w  .  j  a  v a  2  s  .c o  m
        result[i] = dataType.getName();
    }
    return result;
}

From source file:org.springframework.data.rest.webmvc.json.JsonSchema.java

/**
 * Returns whether the given {@link TypeInformation} represents a date.
 * //from  w w  w . j a  v a2s  .  c  o m
 * @param type must not be {@literal null}.
 * @return
 */
private static boolean isDate(TypeInformation<?> type) {

    Class<?> rawType = type.getType();

    if (Date.class.equals(rawType)) {
        return true;
    }

    for (String datePackage : Arrays.asList("java.time", "org.threeten.bp", "org.joda.time")) {
        if (rawType.getName().startsWith(datePackage)) {
            return true;
        }
    }

    return false;
}

From source file:org.springframework.data.rest.webmvc.json.JsonSchema.java

/**
 * Turns the given {@link TypeInformation} into a JSON Schema type string.
 * /*ww  w. jav a 2 s. com*/
 * @param typeInformation
 * @return
 * @see http://json-schema.org/latest/json-schema-core.html#anchor8
 */
private static String toJsonSchemaType(TypeInformation<?> typeInformation) {

    Class<?> type = typeInformation.getType();

    if (type == null) {
        return null;
    } else if (typeInformation.isCollectionLike()) {
        return "array";
    } else if (Boolean.class.equals(type) || boolean.class.equals(type)) {
        return "boolean";
    } else if (String.class.equals(type) || isDate(typeInformation) || type.isEnum()) {
        return "string";
    } else if (INTEGER_TYPES.contains(type)) {
        return "integer";
    } else if (ClassUtils.isAssignable(Number.class, type)) {
        return "number";
    } else {
        return "object";
    }
}

From source file:com.github.vanroy.springdata.jest.MappingBuilder.java

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());
}

From source file:org.develspot.data.orientdb.mapping.BasicOrientPersistentEntity.java

public BasicOrientPersistentEntity(TypeInformation<T> information) {
    super(information);

    Class<T> rawType = information.getType();
    //default/*from   w w  w. java  2 s.  c o m*/
    this.vertexType = rawType.getSimpleName();
    //check if annotation is present
    if (rawType.isAnnotationPresent(VertexType.class)) {
        VertexType annotation = rawType.getAnnotation(VertexType.class);
        if (!annotation.value().isEmpty()) {
            this.vertexType = annotation.value();
        }
    }
}

From source file:io.twipple.springframework.data.clusterpoint.convert.DefaultClusterpointTypeMapperTest.java

@Test
public void testReadType() throws Exception {
    ClusterpointDocument document = new ClusterpointDocument();
    mapper.writeType(MockEntity.class, document);

    TypeInformation<?> type = mapper.readType(document);
    assertNotNull(type);//from   ww w. ja  v a2  s  .com
    assertEquals(MockEntity.class, type.getType());
}

From source file:org.socialsignin.spring.data.dynamodb.mapping.DynamoDBMappingContext.java

@Override
protected boolean shouldCreatePersistentEntityFor(TypeInformation<?> type) {

    boolean hasHashKey = false;
    boolean hasRangeKey = false;
    for (Method method : type.getType().getMethods()) {
        if (method.isAnnotationPresent(DynamoDBHashKey.class))
            hasHashKey = true;/*from  w w  w . ja va  2s .com*/
        if (method.isAnnotationPresent(DynamoDBRangeKey.class))
            hasRangeKey = true;

    }
    for (Field field : type.getType().getFields()) {
        if (field.isAnnotationPresent(DynamoDBHashKey.class))
            hasHashKey = true;
        if (field.isAnnotationPresent(DynamoDBRangeKey.class))
            hasRangeKey = true;

    }
    return type.getType().isAnnotationPresent(DynamoDBTable.class) || (hasHashKey && hasRangeKey);
}

From source file:org.springdata.ehcache.mapping.BasicEhcachePersistentEntity.java

@SuppressWarnings("unchecked")
public BasicEhcachePersistentEntity(TypeInformation<T> typeInformation) {

    super(typeInformation);

    this.parser = new SpelExpressionParser();
    this.context = new StandardEvaluationContext();

    Class<T> rawType = typeInformation.getType();

    if (rawType.isAnnotationPresent(Entity.class)) {
        Entity annotation = rawType.getAnnotation(Entity.class);
        this.cacheName = StringUtils.hasText(annotation.cacheName()) ? annotation.cacheName() : null;
    } else {/* w  w w  .ja  va 2 s. com*/
        this.cacheName = null;
    }

    if (this.cacheName == null) {
        throw new BeanInitializationException(
                "entity class " + rawType + " does not specify cache name by Cache annotation");
    }

    if (DataSerializable.class.isAssignableFrom(rawType)) {
        serializer = new DataSerializer<T>();
        deserializer = new DataDeserializer<T>(rawType);
    } else {
        serializer = (Serializer<T>) new DefaultSerializer();
        deserializer = (Deserializer<T>) new DefaultDeserializer();
    }

}

From source file:com.joyveb.dbpimpl.cass.prepare.mapping.BasicCassandraPersistentEntity.java

/**
 * Creates a new {@link BasicCassandraPersistentEntity} with the given {@link TypeInformation}. Will default the table
 * name to the entities simple type name.
 * /*from  w  ww.jav a  2 s . c o m*/
 * @param typeInformation
 */
public BasicCassandraPersistentEntity(TypeInformation<T> typeInformation) {

    super(typeInformation, CassandraPersistentPropertyComparator.INSTANCE);

    this.parser = new SpelExpressionParser();
    this.context = new StandardEvaluationContext();

    Class<?> rawType = typeInformation.getType();
    String fallback = rawType.getSimpleName().toLowerCase();

    if (rawType.isAnnotationPresent(Table.class)) {
        Table d = rawType.getAnnotation(Table.class);
        this.table = StringUtils.hasText(d.name()) ? d.name() : fallback;
    } else {
        this.table = fallback;
    }
}

From source file:org.springframework.data.rest.webmvc.json.PersistentEntityToJsonSchemaConverter.java

/**
 * Creates a new {@link PersistentEntityToJsonSchemaConverter} for the given {@link PersistentEntities} and
 * {@link ResourceMappings}.//from  w  ww.j av  a 2s  .  com
 * 
 * @param entities must not be {@literal null}.
 * @param mappings must not be {@literal null}.
 * @param accessor must not be {@literal null}.
 * @param objectMapper must not be {@literal null}.
 * @param configuration must not be {@literal null}.
 */
public PersistentEntityToJsonSchemaConverter(PersistentEntities entities, Associations associations,
        MessageSourceAccessor accessor, ObjectMapper objectMapper, RepositoryRestConfiguration configuration,
        ValueTypeSchemaPropertyCustomizerFactory customizerFactory) {

    Assert.notNull(entities, "PersistentEntities must not be null!");
    Assert.notNull(associations, "AssociationLinks must not be null!");
    Assert.notNull(accessor, "MessageSourceAccessor must not be null!");
    Assert.notNull(objectMapper, "ObjectMapper must not be null!");
    Assert.notNull(configuration, "RepositoryRestConfiguration must not be null!");

    this.entities = entities;
    this.associations = associations;
    this.accessor = accessor;
    this.objectMapper = objectMapper;
    this.configuration = configuration;
    this.customizerFactory = customizerFactory;

    for (TypeInformation<?> domainType : entities.getManagedTypes()) {
        convertiblePairs.add(new ConvertiblePair(domainType.getType(), JsonSchema.class));
    }
}