use of org.apache.gora.cassandra.bean.Field in project gora by apache.
the class CassandraMapping method getFieldNames.
/**
* This method returns the Field Names
*
* @return array of Field Names
*/
public String[] getFieldNames() {
List<String> fieldNames = new ArrayList<>(fieldList.size());
for (Field field : fieldList) {
fieldNames.add(field.getFieldName());
}
String[] fieldNameArray = new String[fieldNames.size()];
return fieldNames.toArray(fieldNameArray);
}
use of org.apache.gora.cassandra.bean.Field in project gora by apache.
the class CassandraMapping method getDefaultCassandraKey.
private Field getDefaultCassandraKey() {
Field field = new Field();
field.setFieldName("defaultId");
field.setColumnName("defaultId");
field.setType("varchar");
field.addProperty("primarykey", "true");
return field;
}
use of org.apache.gora.cassandra.bean.Field in project gora by apache.
the class CassandraMapping method getAllFieldsIncludingKeys.
/**
* This method returns partition keys
*
* @return partitionKeys
*/
public String[] getAllFieldsIncludingKeys() {
List<String> fieldNames = new ArrayList<>(fieldList.size());
for (Field field : fieldList) {
fieldNames.add(field.getFieldName());
}
if (cassandraKey != null) {
for (Field field : cassandraKey.getFieldList()) {
fieldNames.add(field.getFieldName());
}
}
String[] fieldNameArray = new String[fieldNames.size()];
return fieldNames.toArray(fieldNameArray);
}
use of org.apache.gora.cassandra.bean.Field in project gora by apache.
the class GoraCassandraNativeCompiler method compile.
/**
* Method in charge of compiling a specific table using a key schema and a set
* of attributes
*
* @param mapping Cassandra Mapping
*/
private void compile(CassandraMapping mapping) {
String fullQualifiedName = mapping.getProperty("name");
String tableName = mapping.getCoreName();
String packageName = fullQualifiedName.substring(0, fullQualifiedName.lastIndexOf("."));
String className = fullQualifiedName.substring(packageName.length() + 1, fullQualifiedName.length());
String keySpace = mapping.getKeySpace().getName();
try {
startFile(className, packageName);
setHeaders(packageName);
line(0, "");
line(0, "@Table(keyspace = \"" + keySpace + "\", name = \"" + tableName + "\"," + "readConsistency = \"QUORUM\"," + "writeConsistency = \"QUORUM\"," + "caseSensitiveKeyspace = false," + "caseSensitiveTable = false)");
line(0, "public class " + className + " implements Persistent {");
for (Field field : mapping.getFieldList()) {
processFields(field);
processGetterAndSetters(field);
line(2, "");
}
setDefaultMethods(2, className);
line(0, "}");
out.flush();
out.close();
} catch (IOException e) {
log.error("Error while compiling table {}", className, e.getMessage());
throw new RuntimeException(e);
}
}
use of org.apache.gora.cassandra.bean.Field in project gora by apache.
the class AvroCassandraUtils method processKeys.
static void processKeys(CassandraMapping cassandraMapping, Object key, List<String> keys, List<Object> values) {
CassandraKey cassandraKey = cassandraMapping.getCassandraKey();
if (cassandraKey != null) {
if (key instanceof PersistentBase) {
PersistentBase keyBase = (PersistentBase) key;
for (Schema.Field field : keyBase.getSchema().getFields()) {
Field mappedField = cassandraKey.getFieldFromFieldName(field.name());
if (mappedField != null) {
keys.add(field.name());
Object value = keyBase.get(field.pos());
value = getFieldValueFromAvroBean(field.schema(), field.schema().getType(), value, mappedField);
values.add(value);
} else {
LOG.debug("Ignoring field {}, Since field couldn't find in the {} mapping", new Object[] { field.name(), cassandraMapping.getPersistentClass() });
}
}
} else {
LOG.error("Key bean isn't extended by {} .", new Object[] { cassandraMapping.getKeyClass(), PersistentBase.class });
}
} else {
keys.add(cassandraMapping.getInlinedDefinedPartitionKey().getFieldName());
values.add(key);
}
}
Aggregations