/** * Get a HColumn<Long, byte[]> with a given key in a given row in a given column Family * * @param rowName name of the row * @param columnFamily column Family name * @param key long type key of the column we are looking for * @param keyspace cassandra keySpace instance * @return query result as a cassandra column * @throws CassandraDataAccessException in case of an Error when accessing data */ public static HColumn<Long, byte[]> getLongByteArrayColumnInARow( String rowName, String columnFamily, long key, Keyspace keyspace) throws CassandraDataAccessException { if (keyspace == null) { throw new CassandraDataAccessException("Can't access Data , no keyspace provided "); } if (columnFamily == null || rowName == null) { throw new CassandraDataAccessException( "Can't access data with columnFamily = " + columnFamily + " and rowName=" + rowName); } try { ColumnQuery columnQuery = HFactory.createColumnQuery( keyspace, stringSerializer, longSerializer, bytesArraySerializer); columnQuery.setColumnFamily(columnFamily); columnQuery.setKey(rowName); columnQuery.setName(key); QueryResult<HColumn<Long, byte[]>> result = columnQuery.execute(); HColumn<Long, byte[]> column = result.get(); return column; } catch (Exception e) { throw new CassandraDataAccessException( "Error while executing quary for HColumn<Long, byte[]> with key =" + key + " in column Family = " + columnFamily, e); } }
public <V> HColumn<N, V> querySingleColumn(K key, N columnName, Serializer<V> valueSerializer) { ColumnQuery<K, N, V> query = HFactory.createColumnQuery(keyspace, keySerializer, topSerializer, valueSerializer); query.setColumnFamily(columnFamily); query.setKey(key); query.setName(columnName); QueryResult<HColumn<N, V>> result = query.execute(); return result != null ? result.get() : null; }
/** * Get the position in the queue for the given appId, consumer and queu * * @param queueId The queueId * @param consumerId The consumerId * @return */ protected UUID getConsumerQueuePosition(UUID queueId, UUID consumerId) { HColumn<UUID, UUID> result = HFactory.createColumnQuery(ko, ue, ue, ue) .setKey(consumerId) .setName(queueId) .setColumnFamily(CONSUMERS.getColumnFamily()) .execute() .get(); if (result != null) { return result.getValue(); } return null; }
public byte[] get(String columnFamilyName, String key) { ColumnQuery<String, String, byte[]> columnQuery = HFactory.createColumnQuery( this._keyspace, StringSerializer.get(), StringSerializer.get(), BytesArraySerializer.get()); columnQuery.setColumnFamily(columnFamilyName).setKey(key).setName(DEFAULT_COLUMN_NAME); QueryResult<HColumn<String, byte[]>> result = columnQuery.execute(); HColumn<String, byte[]> res = result.get(); if (res != null) { // System.out.println( "Get success" ); byte[] value = res.getValue(); /* if( this._debug ) { if( this._failMap.containsKey( key ) ) System.out.println( "Successful get for previously failed key: " + key ); }*/ return value; } else { /* if( this._debug ) { // Track the keys that fail and check whether we ever see a key for a value that failed before if( this._failMap.containsKey( key ) ) { int count = this._failMap.get( key ); count++; this._failMap.put( key, count ); } else this._failMap.put( key, 1 ); }*/ // System.out.println( "Get failure" ); return null; } }
public V getValue(K key, N name) { this.policy.loadConsistencyLevelForRead(columnFamily); V result = null; HColumn<N, V> column; try { column = HFactory.createColumnQuery(keyspace, keySerializer, columnNameSerializer, valueSerializer) .setColumnFamily(columnFamily) .setKey(key) .setName(name) .execute() .get(); } catch (Throwable throwable) { throw new RuntimeException(throwable); } finally { this.policy.reinitDefaultConsistencyLevel(); } if (column != null) { result = column.getValue(); } return result; }