public <N, V> ColumnSlice<N, V> getColumns( Keyspace ko, Object columnFamily, Object key, N[] columns, Serializer<N> nameSerializer, Serializer<V> valueSerializer ) throws Exception { if ( db_logger.isTraceEnabled() ) { db_logger.trace( "getColumn cf={} key={} column={}", columnFamily, key, columns ); } /* * ByteBuffer column_bytes = null; if (column instanceof List) { * column_bytes = Composite.serializeToByteBuffer((List<?>) column); } else * { column_bytes = bytebuffer(column); } */ SliceQuery<ByteBuffer, N, V> q = HFactory.createSliceQuery( ko, be, nameSerializer, valueSerializer ); QueryResult<ColumnSlice<N, V>> r = q.setKey( bytebuffer( key ) ).setColumnNames( columns ).setColumnFamily( columnFamily.toString() ) .execute(); ColumnSlice<N, V> result = r.get(); if ( db_logger.isTraceEnabled() ) { if ( result == null ) { db_logger.trace( "getColumn returned null" ); } } return result; }
q.setKey( bytebuffer( key ) ); q.setColumnNames( ( N[] ) nameSerializer.fromBytesSet( se.toBytesSet( new ArrayList<String>( columnNames ) ) ) .toArray() );
/** * Get the bounds for the queue * * @return The bounds for the queue */ public QueueBounds getQueueBounds( UUID queueId ) { try { ColumnSlice<String, UUID> result = HFactory.createSliceQuery( ko, ue, se, ue ).setKey( queueId ) .setColumnNames( QUEUE_NEWEST, QUEUE_OLDEST ) .setColumnFamily( QUEUE_PROPERTIES.getColumnFamily() ).execute() .get(); if ( result != null && result.getColumnByName( QUEUE_OLDEST ) != null && result.getColumnByName( QUEUE_NEWEST ) != null ) { return new QueueBounds( result.getColumnByName( QUEUE_OLDEST ).getValue(), result.getColumnByName( QUEUE_NEWEST ).getValue() ); } } catch ( Exception e ) { logger.error( "Error getting oldest queue message ID", e ); } return null; }
q.setColumnFamily( CONSUMER_QUEUE_TIMEOUTS.getColumnFamily() ); q.setKey( key ); q.setColumnNames( transactionId );
/** * Reads all existing locks for this lock path * * @param lockPath * a lock path * @return a list of locks waiting on this lockpath */ private Map<String, String> readExistingLocks(HLock lock, String lockName) { // logger.debug("Started reading existing columns"); SliceQuery<String, String, String> sliceQuery = HFactory .createSliceQuery(keyspace, StringSerializer.get(), StringSerializer.get(), StringSerializer.get()) .setColumnFamily(lockManagerConfigurator.getLockManagerCF()).setKey(lock.getPath()); sliceQuery.setColumnNames(lockName); QueryResult<ColumnSlice<String, String>> queryResult = sliceQuery.execute(); // logger.debug("Finished reading existing columns"); return getResults(queryResult); }
q.setColumnNames(cfMapDef.getSliceColumnNameArr()); } else { q.setRange("", "", false, maxNumColumns);
q.setKey("testSliceQuery0"); q.setColumnNames("testSliceQuery1", "testSliceQuery2", "testSliceQuery3"); QueryResult<ColumnSlice<String, String>> r = q.execute(); assertNotNull(r);
public static SliceQuery<ByteBuffer, String, ByteBuffer> buildSliceQuery(ByteBuffer key, List<String> columns, String cfName, Keyspace keyspace) { SliceQuery<ByteBuffer, String, ByteBuffer> query = HFactory.createSliceQuery(keyspace, ByteBufferSerializer.get(), StringSerializer.get(), ByteBufferSerializer.get()); String[] colArray = new String[columns.size()]; columns.toArray(colArray); query.setColumnNames(colArray); query.setKey(key); query.setColumnFamily(cfName); return query; }
@Override public QueryResult<ColumnSlice<String,String>> execute() { SliceQuery<String, String, String> sliceQuery = HFactory.createSliceQuery(keyspace, stringSerializer, stringSerializer, stringSerializer); sliceQuery.setColumnFamily("Npanxx"); sliceQuery.setKey("512202"); // We only ever have these four columns on Npanxx sliceQuery.setColumnNames("city","state","lat","lng"); // The following would do the exact same as the above // accept here we say get the first 4 columns according to comparator order // sliceQuery.setRange("", "", false, 4); QueryResult<ColumnSlice<String, String>> result = sliceQuery.execute(); return result; } }
/** * Loads a lazy property's value * * @param metadata the entity metadata * @param self the entity instance * @param proceed the method being intercepted * @param m * @param args the method arguments */ @Override protected <T> void loadLazyPropertyIfNecessary(ClassMetadata<T> metadata, Object self, Method proceed, Method m, Object[] args) throws Exception { Object value = proceed.invoke(self, args); String key = getKey(self); if (key != null) { //key may be null if this is just a regular access to the property before the entity has been persisted and no key has been assigned SliceQuery<String, String, Object> query = getSliceQuery(metadata); query.setColumnFamily(metadata.getColumnFamily()); query.setKey(key); String column = metadata.getLazyProperty(m); query.setColumnNames(column); List<HColumn<String, Object>> columns = query.execute().get().getColumns(); HColumn<String, Object> mappedColumnValue = columns.size() == 1 ? columns.get(0) : null; if (mappedColumnValue != null && isEmptyContainerValue(value)) { //todo once a load attempt has been made we should not attempt again but we have no sessions...perhaps a weakreference map? Object propertyValue = loadProperty(metadata, column, mappedColumnValue); PropertyUtils.setProperty(self, column, propertyValue); } } }
/** * Reads all existing locks for this lock path * * @param lockPath * a lock path * @return a list of locks waiting on this lockpath */ private Map<String, String> readExistingLocks(HLock lock, String lockName) { // logger.debug("Started reading existing columns"); SliceQuery<String, String, String> sliceQuery = HFactory .createSliceQuery(keyspace, StringSerializer.get(), StringSerializer.get(), StringSerializer.get()) .setColumnFamily(lockManagerConfigurator.getLockManagerCF()).setKey(lock.getPath()); sliceQuery.setColumnNames(lockName); QueryResult<ColumnSlice<String, String>> queryResult = sliceQuery.execute(); // logger.debug("Finished reading existing columns"); return getResults(queryResult); }