use of com.datastax.driver.mapping.annotation.Ttl 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;
}
Aggregations