@Override public ByteBuffer getRawKey() { return cf.getKeySerializer().toByteBuffer(rowKey); }
private K getAstyanaxRowKey(Row row, ColumnFamily<K,C> cf) { Serializer<K> keySerializer = cf.getKeySerializer(); return (K) CqlTypeMapping.getDynamicColumn(row, keySerializer, 0, cf); }
private Object getRowKey(com.datastax.driver.core.Row row, ColumnFamily<K, C> cf) { return CqlTypeMapping.getDynamicColumn(row, cf.getKeySerializer(), 0, cf); } }
public CqlRowListIterator(ResultSet rs, ColumnFamily<K,C> cf) { this.resultSet = rs; this.cf = cf; this.keySerializer = cf.getKeySerializer(); CqlColumnFamilyDefinitionImpl cfDef = (CqlColumnFamilyDefinitionImpl) cf.getColumnFamilyDefinition(); this.isClusteringKey = cfDef.getClusteringKeyColumnDefinitionList().size() > 0; }
@Override public IndexQuery<K, C> setStartKey(K key) { indexClause.setStart_key(columnFamily.getKeySerializer().toByteBuffer(key)); return this; }
@Override public IndexQuery<K, C> setStartKey(K key) { indexClause.setStart_key(columnFamily.getKeySerializer().toByteBuffer(key)); return this; }
public Object checkRowKey(K rKey) { if (rKey == null) { return null; } CqlColumnFamilyDefinitionImpl cfDef = (CqlColumnFamilyDefinitionImpl) columnFamily.getColumnFamilyDefinition(); if (cfDef.getKeyValidationClass().contains("BytesType")) { // Row key is of type bytes. Convert row key to bytebuffer if needed if (rKey instanceof ByteBuffer) { return rKey; } return columnFamily.getKeySerializer().toByteBuffer(rKey); } // else just return the row key as is return rKey; }
@Override public <K, C> ColumnListMutation<C> withRow(ColumnFamily<K, C> columnFamily, K rowKey) { Preconditions.checkNotNull(columnFamily, "columnFamily cannot be null"); Preconditions.checkNotNull(rowKey, "Row key cannot be null"); ByteBuffer bbKey = columnFamily.getKeySerializer().toByteBuffer(rowKey); if (!bbKey.hasRemaining()) { throw new RuntimeException("Row key cannot be empty"); } KeyAndColumnFamily kacf = new KeyAndColumnFamily(columnFamily.getName(), bbKey); ColumnListMutation<C> clm = (ColumnListMutation<C>) rowLookup.get(kacf); if (clm == null) { Map<String, ColumnListMutation<?>> innerMutationMap = mutationMap.get(bbKey); if (innerMutationMap == null) { innerMutationMap = Maps.newHashMap(); mutationMap.put(bbKey, innerMutationMap); } ColumnListMutation<?> innerMutationList = innerMutationMap.get(columnFamily.getName()); if (innerMutationList == null) { innerMutationList = createColumnListMutation(keyspace, columnFamily, rowKey); innerMutationMap.put(columnFamily.getName(), innerMutationList); } rowLookup.put(kacf, innerMutationList); clm = (ColumnListMutation<C>) innerMutationList; } return clm; }
this.cfDef = (CqlColumnFamilyDefinitionImpl) cf.getColumnFamilyDefinition(); Serializer<?> keySerializer = cf.getKeySerializer(); K prevKey = null; List<com.datastax.driver.core.Row> tempList = new ArrayList<com.datastax.driver.core.Row>();
@Override public <K, C> Rows<K, C> getRows(ColumnFamily<K, C> columnFamily) { if (!result.isSetRows()) throw new RuntimeException("CQL reponse doesn't contain rows"); return new ThriftCqlRowsImpl<K, C>(result.getRows(), columnFamily.getKeySerializer(), columnFamily.getColumnSerializer()); }
@Override public <K, C> Rows<K, C> getRows(ColumnFamily<K, C> columnFamily) { if (!result.isSetRows()) throw new RuntimeException("CQL reponse doesn't contain rows"); return new ThriftCqlRowsImpl<K, C>(result.getRows(), columnFamily.getKeySerializer(), columnFamily.getColumnSerializer()); }
timestamp = clock.getCurrentTime(); ByteBuffer bbKey = columnFamily.getKeySerializer().toByteBuffer(rowKey); if (!bbKey.hasRemaining()) { throw new RuntimeException("Row key cannot be empty");
timestamp = clock.getCurrentTime(); ByteBuffer bbKey = columnFamily.getKeySerializer().toByteBuffer(rowKey); if (!bbKey.hasRemaining()) { throw new RuntimeException("Row key cannot be empty");
/** * Convert a Map of options to an internal thrift column family definition * @param options */ private ThriftColumnFamilyDefinitionImpl toThriftColumnFamilyDefinition(Map<String, Object> options, ColumnFamily columnFamily) { ThriftColumnFamilyDefinitionImpl def = new ThriftColumnFamilyDefinitionImpl(); Map<String, Object> internalOptions = Maps.newHashMap(); if (options != null) internalOptions.putAll(options); internalOptions.put("keyspace", getKeyspaceName()); if (columnFamily != null) { internalOptions.put("name", columnFamily.getName()); if (!internalOptions.containsKey("comparator_type")) internalOptions.put("comparator_type", columnFamily.getColumnSerializer().getComparatorType().getTypeName()); if (!internalOptions.containsKey("key_validation_class")) internalOptions.put("key_validation_class", columnFamily.getKeySerializer().getComparatorType().getTypeName()); if (columnFamily.getDefaultValueSerializer() != null && !internalOptions.containsKey("default_validation_class")) internalOptions.put("default_validation_class", columnFamily.getDefaultValueSerializer().getComparatorType().getTypeName()); } def.setFields(internalOptions); return def; }
/** * Convert a Map of options to an internal thrift column family definition * @param options */ private ThriftColumnFamilyDefinitionImpl toThriftColumnFamilyDefinition(Map<String, Object> options, ColumnFamily columnFamily) { ThriftColumnFamilyDefinitionImpl def = new ThriftColumnFamilyDefinitionImpl(); Map<String, Object> internalOptions = Maps.newHashMap(); if (options != null) internalOptions.putAll(options); internalOptions.put("keyspace", getKeyspaceName()); if (columnFamily != null) { internalOptions.put("name", columnFamily.getName()); if (!internalOptions.containsKey("comparator_type")) internalOptions.put("comparator_type", columnFamily.getColumnSerializer().getComparatorType().getTypeName()); if (!internalOptions.containsKey("key_validation_class")) internalOptions.put("key_validation_class", columnFamily.getKeySerializer().getComparatorType().getTypeName()); if (columnFamily.getDefaultValueSerializer() != null && !internalOptions.containsKey("default_validation_class")) internalOptions.put("default_validation_class", columnFamily.getDefaultValueSerializer().getComparatorType().getTypeName()); } def.setFields(internalOptions); return def; }
@Override public Row<K, C> next() { org.apache.cassandra.thrift.KeySlice row = iter.next(); return new ThriftRowImpl<K, C>(columnFamily.getKeySerializer().fromBytes(row.getKey()), ByteBuffer.wrap(row.getKey()), new ThriftColumnOrSuperColumnListImpl<C>(row.getColumns(), columnFamily.getColumnSerializer())); }
@Override public Row<K, C> next() { org.apache.cassandra.thrift.KeySlice row = iter.next(); return new ThriftRowImpl<K, C>(columnFamily.getKeySerializer().fromBytes(row.getKey()), ByteBuffer.wrap(row.getKey()), new ThriftColumnOrSuperColumnListImpl<C>(row.getColumns(), columnFamily.getColumnSerializer())); }
public CqlColumnFamilyDefinitionImpl(Session session, String keyspace, ColumnFamily<?, ?> columnFamily, Map<String, Object> options) { this.session = session; Preconditions.checkArgument(columnFamily != null, "ColumnFamily cannot be null"); if (options == null) { options = new HashMap<String, Object>(); } keyspaceName = keyspace; cfName = columnFamily.getName(); optionsMap.put("key_validator", columnFamily.getKeySerializer().getComparatorType().getClassName()); optionsMap.put("comparator", columnFamily.getColumnSerializer().getComparatorType().getClassName()); optionsMap.put("default_validator", columnFamily.getDefaultValueSerializer().getComparatorType().getClassName()); if (columnFamily.getColumnSerializer() instanceof AnnotatedCompositeSerializer) { compositeSerializer = (AnnotatedCompositeSerializer<?>) columnFamily.getColumnSerializer(); } initFromMap(options); }
@Override public CqlResult<K, C> internalExecute(Client client, ConnectionContext context) throws Exception { org.apache.cassandra.thrift.CqlResult res = execute_cql_query(client); switch (res.getType()) { case ROWS: return new ThriftCqlResultImpl<K, C>(new ThriftCqlRowsImpl<K, C>(res.getRows(), cfQuery.columnFamily.getKeySerializer(), cfQuery.columnFamily.getColumnSerializer())); case INT: return new ThriftCqlResultImpl<K, C>(res.getNum()); default: return null; } } }, cfQuery.retry);
@Override public CqlResult<K, C> internalExecute(Client client, ConnectionContext context) throws Exception { org.apache.cassandra.thrift.CqlResult res = execute_cql_query(client); switch (res.getType()) { case ROWS: return new ThriftCqlResultImpl<K, C>(new ThriftCqlRowsImpl<K, C>(res.getRows(), cfQuery.columnFamily.getKeySerializer(), cfQuery.columnFamily.getColumnSerializer())); case INT: return new ThriftCqlResultImpl<K, C>(res.getNum()); default: return null; } } }, cfQuery.retry);