Search in sources :

Example 36 with EntityTypeMetadata

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

the class MappingBuilder method prepareUpdateValue.

public static BoundStatement prepareUpdateValue(Object id, Class<?> clazz, String propertyName, Object value, WriteOptions options, String keyspace, Session session) {
    EntityTypeMetadata emeta = EntityTypeParser.getEntityMetadata(clazz);
    Update update = QueryBuilder.update(keyspace, emeta.getTableName());
    setValueToUpdateStatement(emeta, update, propertyName, value);
    applyOptions(options, update, null);
    return prepareUpdate(id, emeta, update, session);
}
Also used : EntityTypeMetadata(com.datastax.driver.mapping.meta.EntityTypeMetadata)

Example 37 with EntityTypeMetadata

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

the class MappingBuilder method prepareSave.

public static <E> BuiltStatement prepareSave(E entity, WriteOptions options, String keyspace) {
    Class<?> clazz = entity.getClass();
    EntityTypeMetadata entityMetadata = EntityTypeParser.getEntityMetadata(clazz);
    long version = Long.MIN_VALUE;
    if (entityMetadata.hasVersion()) {
        EntityFieldMetaData verField = entityMetadata.getVersionField();
        version = ((Long) verField.getValue(entity)).longValue();
    }
    BuiltStatement stmt = null;
    if (version > 0) {
        stmt = buildUpdate(entity, options, keyspace);
    } else {
        stmt = buildInsert(entity, options, keyspace);
    }
    return stmt;
}
Also used : EntityFieldMetaData(com.datastax.driver.mapping.meta.EntityFieldMetaData) EntityTypeMetadata(com.datastax.driver.mapping.meta.EntityTypeMetadata)

Example 38 with EntityTypeMetadata

use of com.datastax.driver.mapping.meta.EntityTypeMetadata 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 39 with EntityTypeMetadata

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

the class MappingBuilder method prepareUpdateValues.

public static BoundStatement prepareUpdateValues(Object id, Class<?> clazz, String[] propertyNames, Object[] values, WriteOptions options, String keyspace, Session session) {
    EntityTypeMetadata emeta = EntityTypeParser.getEntityMetadata(clazz);
    Update update = QueryBuilder.update(keyspace, emeta.getTableName());
    for (int i = 0; i < propertyNames.length; i++) {
        setValueToUpdateStatement(emeta, update, propertyNames[i], values[i]);
    }
    applyOptions(options, update, null);
    return prepareUpdate(id, emeta, update, session);
}
Also used : EntityTypeMetadata(com.datastax.driver.mapping.meta.EntityTypeMetadata)

Example 40 with EntityTypeMetadata

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

the class EntityTypeParser method parseEntityClass.

/**
     * use reflection to iterate entity properties and collect fields to be
     * persisted
     */
private static <T> EntityTypeMetadata parseEntityClass(Class<T> clazz) {
    EntityTypeMetadata result = parseEntityLevelMetadata(clazz);
    parsePropertyLevelMetadata(result.getEntityClass(), result, null, false);
    return result;
}
Also used : EntityTypeMetadata(com.datastax.driver.mapping.meta.EntityTypeMetadata)

Aggregations

EntityTypeMetadata (com.datastax.driver.mapping.meta.EntityTypeMetadata)40 Test (org.junit.Test)18 EntityFieldMetaData (com.datastax.driver.mapping.meta.EntityFieldMetaData)13 TableMetadata (com.datastax.driver.core.TableMetadata)8 ColumnMetadata (com.datastax.driver.core.ColumnMetadata)6 PrimaryKeyMetadata (com.datastax.driver.mapping.meta.PrimaryKeyMetadata)4 RegularStatement (com.datastax.driver.core.RegularStatement)3 EntityWithCompositeKey (com.datastax.driver.mapping.entity.EntityWithCompositeKey)2 SimpleKey (com.datastax.driver.mapping.entity.SimpleKey)2 ExecutionException (java.util.concurrent.ExecutionException)2 BoundStatement (com.datastax.driver.core.BoundStatement)1 Cluster (com.datastax.driver.core.Cluster)1 KeyspaceMetadata (com.datastax.driver.core.KeyspaceMetadata)1 PreparedStatement (com.datastax.driver.core.PreparedStatement)1 ResultSet (com.datastax.driver.core.ResultSet)1 Row (com.datastax.driver.core.Row)1 Statement (com.datastax.driver.core.Statement)1 BuiltStatement (com.datastax.driver.core.querybuilder.BuiltStatement)1 TableProperties (com.datastax.driver.mapping.annotation.TableProperties)1 TableProperty (com.datastax.driver.mapping.annotation.TableProperty)1