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