use of com.datastax.driver.mapping.annotation.Static in project cassandra-driver-mapping by valchkou.
the class EntityTypeParser method parsePropertyLevelMetadata.
private static EntityTypeMetadata parsePropertyLevelMetadata(Class<?> clazz, EntityTypeMetadata result, PrimaryKeyMetadata pkmeta, boolean isPartitionKey) {
Field[] fields = clazz.getDeclaredFields();
Method[] methods = clazz.getDeclaredMethods();
for (Field f : fields) {
boolean isOwnField = false;
PrimaryKeyMetadata pkm = null;
// for embedded key go recursive
if (f.getAnnotation(EmbeddedId.class) != null || f.getAnnotation(Id.class) != null) {
isOwnField = true;
pkm = new PrimaryKeyMetadata();
pkm.setPartition(isPartitionKey);
if (isPartitionKey) {
pkmeta.setPartitionKey(pkm);
} else {
result.setPrimaryKeyMetadata(pkm);
}
parsePropertyLevelMetadata(f.getType(), result, pkm, true);
}
if ((f.getAnnotation(Transient.class) == null && javaTypeToDataType.get(f.getType()) != null) || isOwnField || f.getType().isEnum()) {
Method getter = null;
Method setter = null;
for (Method m : methods) {
// setter are defined
if (isGetterFor(m, f.getName())) {
getter = m;
} else if (isSetterFor(m, f)) {
setter = m;
}
if (setter != null && getter != null) {
String columnName = getColumnName(f);
DataType.Name dataType = getColumnDataType(f);
EntityFieldMetaData fd = new EntityFieldMetaData(f, dataType, getter, setter, columnName);
if (pkmeta != null && !isOwnField) {
fd.setPartition(pkmeta.isPartition());
fd.setPrimary(true);
pkmeta.addField(fd);
} else if (isOwnField) {
pkm.setOwnField(fd);
}
if (f.getAnnotation(EmbeddedId.class) != null) {
break;
}
if (f.getAnnotation(Version.class) != null) {
result.setVersionField(fd);
}
setCollections(f, fd);
if (f.getAnnotation(Static.class) != null) {
fd.setStatic(true);
}
if (f.getAnnotation(GeneratedValue.class) != null) {
fd.setAutoGenerate(true);
}
result.addField(fd);
// exit inner loop on filed's methods and go to
break;
// the next field
}
}
}
}
return result;
}
Aggregations