Search in sources :

Example 1 with Static

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;
}
Also used : EntityFieldMetaData(com.datastax.driver.mapping.meta.EntityFieldMetaData) PrimaryKeyMetadata(com.datastax.driver.mapping.meta.PrimaryKeyMetadata) EmbeddedId(javax.persistence.EmbeddedId) Method(java.lang.reflect.Method) GeneratedValue(javax.persistence.GeneratedValue) Field(java.lang.reflect.Field) Version(javax.persistence.Version) DataType(com.datastax.driver.core.DataType) Transient(javax.persistence.Transient) Static(com.datastax.driver.mapping.annotation.Static)

Aggregations

DataType (com.datastax.driver.core.DataType)1 Static (com.datastax.driver.mapping.annotation.Static)1 EntityFieldMetaData (com.datastax.driver.mapping.meta.EntityFieldMetaData)1 PrimaryKeyMetadata (com.datastax.driver.mapping.meta.PrimaryKeyMetadata)1 Field (java.lang.reflect.Field)1 Method (java.lang.reflect.Method)1 EmbeddedId (javax.persistence.EmbeddedId)1 GeneratedValue (javax.persistence.GeneratedValue)1 Transient (javax.persistence.Transient)1 Version (javax.persistence.Version)1