Search in sources :

Example 1 with TableProperties

use of com.datastax.driver.mapping.annotation.TableProperties in project cassandra-driver-mapping by valchkou.

the class EntityTypeParser method parseEntityLevelMetadata.

/**
 * Parses class level annotations and initializes EntityMetadata object for
 * given entity class
 *
 * @param clazz
 * @return EntityMetadata
 */
private static <T> EntityTypeMetadata parseEntityLevelMetadata(Class<T> clazz) {
    EntityTypeMetadata result = null;
    Annotation annotation = clazz.getAnnotation(Table.class);
    if (annotation instanceof Table) {
        Table tableAntn = (Table) annotation;
        String tableName = tableAntn.name();
        if (tableName != null && tableName.length() > 0) {
            result = new EntityTypeMetadata(clazz, tableName);
        } else {
            result = new EntityTypeMetadata(clazz);
        }
        Index[] indexes = tableAntn.indexes();
        if (indexes != null && indexes.length > 0) {
            for (Index index : indexes) {
                result.addindex(index.name(), index.columnList());
            }
        }
    } else {
        result = new EntityTypeMetadata(clazz);
    }
    // parse properties
    annotation = clazz.getAnnotation(TableProperties.class);
    if (annotation instanceof TableProperties) {
        TableProperty[] props = ((TableProperties) annotation).values();
        for (TableProperty prop : props) {
            result.addProperty(prop.value());
        }
    }
    // parse ttl
    annotation = clazz.getAnnotation(Ttl.class);
    if (annotation instanceof Ttl) {
        result.setTtl(((Ttl) annotation).value());
    }
    return result;
}
Also used : EntityTypeMetadata(com.datastax.driver.mapping.meta.EntityTypeMetadata) Table(javax.persistence.Table) Index(javax.persistence.Index) TableProperties(com.datastax.driver.mapping.annotation.TableProperties) Ttl(com.datastax.driver.mapping.annotation.Ttl) Annotation(java.lang.annotation.Annotation) TableProperty(com.datastax.driver.mapping.annotation.TableProperty)

Aggregations

TableProperties (com.datastax.driver.mapping.annotation.TableProperties)1 TableProperty (com.datastax.driver.mapping.annotation.TableProperty)1 Ttl (com.datastax.driver.mapping.annotation.Ttl)1 EntityTypeMetadata (com.datastax.driver.mapping.meta.EntityTypeMetadata)1 Annotation (java.lang.annotation.Annotation)1 Index (javax.persistence.Index)1 Table (javax.persistence.Table)1