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);
}
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;
}
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);
}
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);
}
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;
}
Aggregations