Search in sources :

Example 16 with EntityFieldMetaData

use of com.datastax.driver.mapping.meta.EntityFieldMetaData in project cassandra-driver-mapping by valchkou.

the class MappingBuilder method prepareDelete.

public static <T> BoundStatement prepareDelete(Object id, Class<T> clazz, String propertyName, String keyspace, Session session) {
    EntityTypeMetadata emeta = EntityTypeParser.getEntityMetadata(clazz);
    EntityFieldMetaData fmeta = emeta.getFieldMetadata(propertyName);
    Delete delete = QueryBuilder.delete(fmeta.getColumnName()).from(keyspace, emeta.getTableName());
    List<String> pkCols = emeta.getPkColumns();
    for (String col : pkCols) {
        delete.where(eq(col, QueryBuilder.bindMarker()));
    }
    return prepareBoundStatement(id, emeta, delete, pkCols, session);
}
Also used : EntityFieldMetaData(com.datastax.driver.mapping.meta.EntityFieldMetaData) EntityTypeMetadata(com.datastax.driver.mapping.meta.EntityTypeMetadata)

Example 17 with EntityFieldMetaData

use of com.datastax.driver.mapping.meta.EntityFieldMetaData in project cassandra-driver-mapping by valchkou.

the class MappingBuilder method getSelectCacheKey.

private static String getSelectCacheKey(String table, Session session, List<EntityFieldMetaData> fields) {
    StringBuilder sb = new StringBuilder();
    for (EntityFieldMetaData property : fields) {
        sb.append(property.getColumnName());
        sb.append('|');
    }
    return getCacheKey(table + sb.toString(), session);
}
Also used : EntityFieldMetaData(com.datastax.driver.mapping.meta.EntityFieldMetaData)

Example 18 with EntityFieldMetaData

use of com.datastax.driver.mapping.meta.EntityFieldMetaData in project cassandra-driver-mapping by valchkou.

the class CreateTable method getQueryString.

@Override
public String getQueryString() {
    StringBuilder columns = new StringBuilder();
    for (EntityFieldMetaData fd : entityMetadata.getFields()) {
        columns.append(fd.getColumnName());
        columns.append(" ");
        if (fd.isGenericType()) {
            columns.append(fd.getGenericDef());
        } else {
            columns.append(fd.getDataType().toString());
        }
        if (fd.isStatic()) {
            columns.append(" static");
        }
        columns.append(", ");
    }
    String pk = entityMetadata.getPkDefinition();
    String tableName = entityMetadata.getTableName();
    if (keyspace != null) {
        tableName = keyspace + "." + tableName;
    }
    StringBuilder sb = new StringBuilder();
    sb.append(String.format(CREATE_TABLE_TEMPLATE_CQL, tableName, columns.toString(), pk));
    if (entityMetadata.getProperties() != null) {
        Iterator<String> it = entityMetadata.getProperties().iterator();
        if (it.hasNext()) {
            sb.append(String.format(OPT_FIST, it.next()));
        }
        while (it.hasNext()) {
            sb.append(String.format(OPT_NEXT, it.next()));
        }
    }
    return sb.toString();
}
Also used : EntityFieldMetaData(com.datastax.driver.mapping.meta.EntityFieldMetaData)

Aggregations

EntityFieldMetaData (com.datastax.driver.mapping.meta.EntityFieldMetaData)18 EntityTypeMetadata (com.datastax.driver.mapping.meta.EntityTypeMetadata)13 PrimaryKeyMetadata (com.datastax.driver.mapping.meta.PrimaryKeyMetadata)2 ExecutionException (java.util.concurrent.ExecutionException)2 Test (org.junit.Test)2 Cluster (com.datastax.driver.core.Cluster)1 ColumnMetadata (com.datastax.driver.core.ColumnMetadata)1 DataType (com.datastax.driver.core.DataType)1 KeyspaceMetadata (com.datastax.driver.core.KeyspaceMetadata)1 RegularStatement (com.datastax.driver.core.RegularStatement)1 TableMetadata (com.datastax.driver.core.TableMetadata)1 Static (com.datastax.driver.mapping.annotation.Static)1 Field (java.lang.reflect.Field)1 Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1 Callable (java.util.concurrent.Callable)1 EmbeddedId (javax.persistence.EmbeddedId)1 GeneratedValue (javax.persistence.GeneratedValue)1 Transient (javax.persistence.Transient)1 Version (javax.persistence.Version)1