Search in sources :

Example 6 with Field

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);
}
Also used : Field(org.apache.gora.cassandra.bean.Field) ArrayList(java.util.ArrayList)

Example 7 with Field

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;
}
Also used : Field(org.apache.gora.cassandra.bean.Field)

Example 8 with 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);
}
Also used : Field(org.apache.gora.cassandra.bean.Field) ArrayList(java.util.ArrayList)

Example 9 with Field

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);
    }
}
Also used : Field(org.apache.gora.cassandra.bean.Field) IOException(java.io.IOException)

Example 10 with Field

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);
    }
}
Also used : Field(org.apache.gora.cassandra.bean.Field) PersistentBase(org.apache.gora.persistency.impl.PersistentBase) Schema(org.apache.avro.Schema) CassandraKey(org.apache.gora.cassandra.bean.CassandraKey)

Aggregations

Field (org.apache.gora.cassandra.bean.Field)19 ArrayList (java.util.ArrayList)7 ClusterKeyField (org.apache.gora.cassandra.bean.ClusterKeyField)6 PartitionKeyField (org.apache.gora.cassandra.bean.PartitionKeyField)6 Schema (org.apache.avro.Schema)5 CassandraKey (org.apache.gora.cassandra.bean.CassandraKey)5 GoraException (org.apache.gora.util.GoraException)3 SimpleStatement (com.datastax.driver.core.SimpleStatement)2 List (java.util.List)2 PersistentBase (org.apache.gora.persistency.impl.PersistentBase)2 AbstractGettableData (com.datastax.driver.core.AbstractGettableData)1 ColumnDefinitions (com.datastax.driver.core.ColumnDefinitions)1 ResultSet (com.datastax.driver.core.ResultSet)1 Row (com.datastax.driver.core.Row)1 UDTValue (com.datastax.driver.core.UDTValue)1 UserType (com.datastax.driver.core.UserType)1 Select (com.datastax.driver.core.querybuilder.Select)1 Update (com.datastax.driver.core.querybuilder.Update)1 DoubleArrayCodec (com.datastax.driver.extras.codecs.arrays.DoubleArrayCodec)1 FloatArrayCodec (com.datastax.driver.extras.codecs.arrays.FloatArrayCodec)1