@Override public T getResult() { return operation.getResult(); }
@Override public int getCount(final ByteBuffer key, final ColumnParent columnParent, final SlicePredicate predicate) throws HectorException { Operation<Integer> op = new Operation<Integer>(OperationType.READ, failoverPolicy, keyspaceName, credentials) { @Override public Integer execute(Cassandra.Client cassandra) throws HectorException { try { return cassandra.get_count(key, columnParent, predicate, getThriftCl(OperationType.READ)); } catch (Exception e) { throw xtrans.translate(e); } } }; operateWithFailover(op); return op.getResult(); }
@Override public Map<ByteBuffer, Integer> multigetCount(final List<ByteBuffer> keys, final ColumnParent columnParent, final SlicePredicate slicePredicate) throws HectorException { Operation<Map<ByteBuffer,Integer>> op = new Operation<Map<ByteBuffer,Integer>>(OperationType.READ, failoverPolicy, keyspaceName, credentials) { @Override public Map<ByteBuffer, Integer> execute(Cassandra.Client cassandra) throws HectorException { try { return cassandra.multiget_count(keys, columnParent, slicePredicate, getThriftCl(OperationType.READ)); } catch (Exception e) { throw xtrans.translate(e); } } }; operateWithFailover(op); return op.getResult(); }
@Override public Map<ByteBuffer, List<CounterColumn>> multigetCounterSlice(final List<ByteBuffer> keys, final ColumnParent columnParent, final SlicePredicate predicate) throws HectorException { Operation<Map<ByteBuffer, List<CounterColumn>>> getCount = new Operation<Map<ByteBuffer, List<CounterColumn>>>( OperationType.READ, failoverPolicy, keyspaceName, credentials) { @Override public Map<ByteBuffer, List<CounterColumn>> execute(Cassandra.Client cassandra) throws HectorException { try { Map<ByteBuffer, List<ColumnOrSuperColumn>> cfmap = cassandra.multiget_slice( keys, columnParent, predicate, getThriftCl(OperationType.READ)); Map<ByteBuffer, List<CounterColumn>> result = new HashMap<ByteBuffer, List<CounterColumn>>(); for (Map.Entry<ByteBuffer, List<ColumnOrSuperColumn>> entry : cfmap.entrySet()) { result.put(entry.getKey(), getCounterColumnList(entry.getValue())); } return result; } catch (Exception e) { throw xtrans.translate(e); } } }; operateWithFailover(getCount); return getCount.getResult(); }
@Override public Map<ByteBuffer, List<Column>> multigetSlice(final List<ByteBuffer> keys, final ColumnParent columnParent, final SlicePredicate predicate) throws HectorException { Operation<Map<ByteBuffer, List<Column>>> getCount = new Operation<Map<ByteBuffer, List<Column>>>( OperationType.READ, failoverPolicy, keyspaceName, credentials) { @Override public Map<ByteBuffer, List<Column>> execute(Cassandra.Client cassandra) throws HectorException { try { Map<ByteBuffer, List<ColumnOrSuperColumn>> cfmap = cassandra.multiget_slice( keys, columnParent, predicate, getThriftCl(OperationType.READ)); Map<ByteBuffer, List<Column>> result = new HashMap<ByteBuffer, List<Column>>(); for (Map.Entry<ByteBuffer, List<ColumnOrSuperColumn>> entry : cfmap.entrySet()) { result.put(entry.getKey(), getColumnList(entry.getValue())); } return result; } catch (Exception e) { throw xtrans.translate(e); } } }; operateWithFailover(getCount); return getCount.getResult(); }
public Map<String,List<String>> describeSchemaVersions() throws HectorException { Operation<Map<String,List<String>>> op = new Operation<Map<String,List<String>>>(OperationType.META_READ, getCredentials()) { @Override public Map<String,List<String>> execute(Cassandra.Client cassandra) throws HectorException { try { return cassandra.describe_schema_versions(); } catch (Exception e) { throw xtrans.translate(e); } } }; connectionManager.operateWithFailover(op); return op.getResult(); }
public List<TokenRange> describeRing(final String keyspace) throws HectorException { Operation<List<TokenRange>> op = new Operation<List<TokenRange>>(OperationType.META_READ, getCredentials()) { @Override public List<TokenRange> execute(Cassandra.Client cassandra) throws HectorException { try { return cassandra.describe_ring(keyspace); } catch (Exception e) { throw xtrans.translate(e); } } }; connectionManager.operateWithFailover(op); return op.getResult(); }
@Override public String describeClusterName() throws HectorException { Operation<String> op = new Operation<String>(OperationType.META_READ, getCredentials()) { @Override public String execute(Cassandra.Client cassandra) throws HectorException { try { return cassandra.describe_cluster_name(); } catch (Exception e) { throw xtrans.translate(e); } } }; connectionManager.operateWithFailover(op); return op.getResult(); }
@Override public List<KeyspaceDefinition> describeKeyspaces() throws HectorException { Operation<List<KeyspaceDefinition>> op = new Operation<List<KeyspaceDefinition>>(OperationType.META_READ, getCredentials()) { @Override public List<KeyspaceDefinition> execute(Cassandra.Client cassandra) throws HectorException { try { return ThriftKsDef.fromThriftList(cassandra.describe_keyspaces()); } catch (Exception e) { throw xtrans.translate(e); } } }; connectionManager.operateWithFailover(op); return op.getResult(); }
@Override public String describeThriftVersion() throws HectorException { Operation<String> op = new Operation<String>(OperationType.META_READ, getCredentials()) { @Override public String execute(Cassandra.Client cassandra) throws HectorException { try { return cassandra.describe_version(); } catch (Exception e) { throw xtrans.translate(e); } } }; connectionManager.operateWithFailover(op); return op.getResult(); }
@Override public String describePartitioner() throws HectorException { Operation<String> op = new Operation<String>(OperationType.META_READ, getCredentials()) { @Override public String execute(Cassandra.Client cassandra) throws HectorException { try { if ( log.isInfoEnabled() ) { log.info("in execute with client {}", cassandra); } return cassandra.describe_partitioner(); } catch (Exception e) { throw xtrans.translate(e); } } }; connectionManager.operateWithFailover(op); return op.getResult(); }
public String updateKeyspace(final KeyspaceDefinition ksdef, final boolean waitForSchemaAgreement) throws HectorException { Operation<String> op = new Operation<String>(OperationType.META_WRITE, FailoverPolicy.FAIL_FAST, getCredentials()) { @Override public String execute(Cassandra.Client cassandra) throws HectorException { try { if (waitForSchemaAgreement) { waitForSchemaAgreement(cassandra); } String schemaId = cassandra.system_update_keyspace(toThriftImplementation(ksdef).toThrift()); if (waitForSchemaAgreement) { waitForSchemaAgreement(cassandra); } return schemaId; } catch (Exception e) { throw xtrans.translate(e); } } }; connectionManager.operateWithFailover(op); return op.getResult(); }
@Override public KeyspaceDefinition describeKeyspace(final String keyspace) throws HectorException { Operation<KeyspaceDefinition> op = new Operation<KeyspaceDefinition>( OperationType.META_READ, getCredentials()) { @Override public KeyspaceDefinition execute(Cassandra.Client cassandra) throws HectorException { try { return new ThriftKsDef(cassandra.describe_keyspace(keyspace)); } catch (org.apache.cassandra.thrift.NotFoundException nfe) { setException(xtrans.translate(nfe)); return null; } catch (Exception e) { throw xtrans.translate(e); } } }; connectionManager.operateWithFailover(op); return op.getResult(); }
@Override public String dropKeyspace(final String keyspace, final boolean waitForSchemaAgreement) throws HectorException { Operation<String> op = new Operation<String>(OperationType.META_WRITE, FailoverPolicy.FAIL_FAST, getCredentials()) { @Override public String execute(Cassandra.Client cassandra) throws HectorException { try { if (waitForSchemaAgreement) { waitForSchemaAgreement(cassandra); } String schemaId = cassandra.system_drop_keyspace(keyspace); if (waitForSchemaAgreement) { waitForSchemaAgreement(cassandra); } return schemaId; } catch (Exception e) { throw xtrans.translate(e); } } }; connectionManager.operateWithFailover(op); return op.getResult(); }
@Override public String addKeyspace(final KeyspaceDefinition ksdef, final boolean waitForSchemaAgreement) throws HectorException { Operation<String> op = new Operation<String>(OperationType.META_WRITE, FailoverPolicy.FAIL_FAST, getCredentials()) { @Override public String execute(Cassandra.Client cassandra) throws HectorException { try { if (waitForSchemaAgreement) { waitForSchemaAgreement(cassandra); } String schemaId = cassandra.system_add_keyspace(toThriftImplementation(ksdef).toThrift()); if (waitForSchemaAgreement) { waitForSchemaAgreement(cassandra); } return schemaId; } catch (Exception e) { throw xtrans.translate(e); } } }; connectionManager.operateWithFailover(op); return op.getResult(); }
@Override public String dropColumnFamily(final String keyspaceName, final String columnFamily, final boolean waitForSchemaAgreement) throws HectorException { Operation<String> op = new Operation<String>(OperationType.META_WRITE, FailoverPolicy.FAIL_FAST, keyspaceName, getCredentials()) { @Override public String execute(Cassandra.Client cassandra) throws HectorException { try { if (waitForSchemaAgreement) { waitForSchemaAgreement(cassandra); } String schemaId = cassandra.system_drop_column_family(columnFamily); if (waitForSchemaAgreement) { waitForSchemaAgreement(cassandra); } return schemaId; } catch (Exception e) { throw xtrans.translate(e); } } }; connectionManager.operateWithFailover(op); return op.getResult(); }
@Override public SuperColumn getSuperColumn(final ByteBuffer key, final ColumnPath columnPath) throws HectorException { Operation<SuperColumn> op = new Operation<SuperColumn>(OperationType.READ, failoverPolicy, keyspaceName, credentials) { @Override public SuperColumn execute(Cassandra.Client cassandra) throws HectorException { ColumnOrSuperColumn cosc; try { cosc = cassandra.get(key, columnPath, getThriftCl(OperationType.READ)); } catch (NotFoundException e) { setException(xtrans.translate(e)); return null; } catch (Exception e) { throw xtrans.translate(e); } return cosc == null ? null : cosc.getSuper_column(); } }; operateWithFailover(op); if (op.hasException()) { throw op.getException(); } return op.getResult(); }
@Override public CounterColumn getCounter(final ByteBuffer key, final ColumnPath columnPath) throws HectorException { Operation<CounterColumn> op = new Operation<CounterColumn>(OperationType.READ, failoverPolicy, keyspaceName, credentials) { @Override public CounterColumn execute(Cassandra.Client cassandra) throws HectorException { ColumnOrSuperColumn cosc; try { cosc = cassandra.get(key, columnPath, getThriftCl(OperationType.READ)); } catch (NotFoundException e) { setException(xtrans.translate(e)); return null; } catch (Exception e) { throw xtrans.translate(e); } return cosc.getCounter_column(); } }; operateWithFailover(op); if (op.hasException()) { throw op.getException(); } return op.getResult(); }
@Override public Column getColumn(final ByteBuffer key, final ColumnPath columnPath) throws HectorException { // valideColumnPath(columnPath); Operation<Column> op = new Operation<Column>(OperationType.READ, failoverPolicy, keyspaceName, credentials) { @Override public Column execute(Cassandra.Client cassandra) throws HectorException { ColumnOrSuperColumn cosc; try { cosc = cassandra.get(key, columnPath, getThriftCl(OperationType.READ)); } catch (NotFoundException e) { setException(xtrans.translate(e)); return null; } catch (Exception e) { throw xtrans.translate(e); } return cosc == null ? null : cosc.getColumn(); } }; operateWithFailover(op); if (op.hasException()) { throw op.getException(); } return op.getResult(); }
@Override public String updateColumnFamily(final ColumnFamilyDefinition cfdef, final boolean waitForSchemaAgreement) throws HectorException { Operation<String> op = new Operation<String>(OperationType.META_WRITE, FailoverPolicy.FAIL_FAST, cfdef.getKeyspaceName(), getCredentials()) { @Override public String execute(Cassandra.Client cassandra) throws HectorException { try { if (waitForSchemaAgreement) { waitForSchemaAgreement(cassandra); } String schemaId = cassandra.system_update_column_family(toThriftImplementation(cfdef).toThrift()); if (waitForSchemaAgreement) { waitForSchemaAgreement(cassandra); } return schemaId; } catch (Exception e) { throw xtrans.translate(e); } } }; connectionManager.operateWithFailover(op); return op.getResult(); }