Java 类org.apache.cassandra.thrift.Compression 实例源码

项目:cassandra-maven-plugin    文件:AbstractCqlExecMojo.java   
private CqlResult executeStatement(Client client, String statement) throws ThriftApiExecutionException
{
    ByteBuffer buf = ByteBufferUtil.bytes(statement);
    try
    {
        if (cqlVersion.charAt(0) >= '3')
        {
            return client.execute_cql3_query(buf, Compression.NONE, ConsistencyLevel.ONE);
        } else
        {
            return client.execute_cql_query(buf, Compression.NONE);
        }
    } catch (Exception e)
    {
        getLog().debug(statement);
        throw new ThriftApiExecutionException(e);
    }
}
项目:openyu-commons    文件:CassandraThriftDMLTest.java   
/**
 * getByCql
 *
 * @throws Exception
 */
@Test
public void getByCql() throws Exception {
    String KEYSPACE = "mock";
    client.set_keyspace(KEYSPACE);
    //
    String CQL = "select * from student where KEY='Jack'";
    // query, compression
    CqlResult result = client.execute_cql_query(
            ByteBufferHelper.toByteBuffer(CQL), Compression.NONE);
    System.out.println(result);

    for (CqlRow cqlRow : result.getRows()) {
        for (Column column : cqlRow.getColumns()) {
            System.out.println(ByteHelper.toString(cqlRow.getKey()) + ", "
                    + ByteHelper.toString(column.getName()) + ": "
                    + ByteHelper.toString(column.getValue()) + ", "
                    + column.getTimestamp());
            // Jack, KEY: Jack, -1
            // Jack, art: 87, 1380933848350
            // Jack, grad: 5, 1380932164492000
            // Jack, math: 97, 1380933848305
        }
    }
}
项目:learning-hadoop    文件:CassandraOutputData.java   
/**
 * Send the batch insert.
 * 
 * @param batch
 *            the CQL batch insert statement
 * @param conn
 *            the connection to use
 * @param compressCQL
 *            true if the CQL should be compressed
 * @throws Exception
 *             if a problem occurs
 */
public static void commitCQLBatch(StringBuilder batch,
        CassandraConnection conn, boolean compressCQL) throws Exception {

    // compress the batch if necessary
    byte[] toSend = null;
    if (compressCQL) {
        toSend = compressQuery(batch.toString(), Compression.GZIP);
    } else {
        toSend = batch.toString().getBytes(
                Charset.forName(CassandraColumnMetaData.UTF8));
    }

    conn.getClient().execute_cql_query(ByteBuffer.wrap(toSend),
            compressCQL ? Compression.GZIP : Compression.NONE);
}
项目:learning-hadoop    文件:CassandraOutputData.java   
/**
 * Compress a CQL query
 * 
 * @param queryStr
 *            the CQL query
 * @param compression
 *            compression option (GZIP is the only option - so far)
 * @return an array of bytes containing the compressed query
 */
public static byte[] compressQuery(String queryStr, Compression compression) {
    byte[] data = queryStr.getBytes(Charset
            .forName(CassandraColumnMetaData.UTF8));

    Deflater compressor = new Deflater();
    compressor.setInput(data);
    compressor.finish();

    ByteArrayOutputStream byteArray = new ByteArrayOutputStream();
    byte[] buffer = new byte[1024];

    while (!compressor.finished()) {
        int size = compressor.deflate(buffer);
        byteArray.write(buffer, 0, size);
    }

    return byteArray.toByteArray();
}
项目:learning-hadoop    文件:CassandraInputData.java   
/**
 * Compress a CQL query
 * 
 * @param queryStr the CQL query
 * @param compression compression option (GZIP is the only option - so far)
 * @return an array of bytes containing the compressed query
 */
public static byte[] compressQuery(String queryStr, Compression compression) {
  byte[] data = queryStr.getBytes(Charset
      .forName(CassandraColumnMetaData.UTF8));

  Deflater compressor = new Deflater();
  compressor.setInput(data);
  compressor.finish();

  ByteArrayOutputStream byteArray = new ByteArrayOutputStream();
  byte[] buffer = new byte[1024];

  while (!compressor.finished()) {
    int size = compressor.deflate(buffer);
    byteArray.write(buffer, 0, size);
  }

  return byteArray.toByteArray();
}
项目:Rapture    文件:CassandraBase.java   
protected void executeCQL(String cql) throws InvalidRequestException, UnavailableException, TimedOutException, SchemaDisagreementException, TException {
    try {
        client.execute_cql_query(ByteBuffer.wrap(cql.getBytes("UTF-8")), Compression.NONE);
    } catch (UnsupportedEncodingException e) {
        throw new InvalidRequestException("Argument is not in UTF-8 character set");
    }
}
项目:emodb    文件:CassandraThriftFacade.java   
/** @deprecated Remove once Cassandra 1.1 support is no longer necessary. */
public void executeCql3Script_1_1(String script) {
    try {
        _client.set_cql_version(CQL_VERSION);
        for (String cqlStatement : toCqlStatements(script)) {
            if (StringUtils.isNotBlank(cqlStatement)) {
                cqlStatement += ";";
                _log.info("executing cql statement: " + cqlStatement);
                _client.execute_cql_query(ByteBuffer.wrap(cqlStatement.getBytes("UTF-8")), Compression.NONE);
            }
        }
    } catch (Exception e) {
        throw Throwables.propagate(e);
    }
}
项目:emodb    文件:CassandraThriftFacade.java   
public void executeCql3Script(String script) {
    try {
        for (String cqlStatement : toCqlStatements(script)) {
            if (StringUtils.isNotBlank(cqlStatement)) {
                cqlStatement += ";";
                _log.info("executing cql3 statement: " + cqlStatement);
                _client.execute_cql3_query(ByteBuffer.wrap(cqlStatement.getBytes("UTF-8")), Compression.NONE, ConsistencyLevel.LOCAL_QUORUM);
            }
        }
    } catch (Exception e) {
        throw Throwables.propagate(e);
    }
}
项目:cassandra-kmean    文件:CqlOperation.java   
@Override
public <V> V execute(String query, ByteBuffer key, List<Object> queryParams, ResultHandler<V> handler) throws TException
{
    String formattedQuery = formatCqlQuery(query, queryParams, true);
    return handler.simpleNativeHandler().apply(
            client.execute_cql3_query(formattedQuery, key, Compression.NONE, settings.command.consistencyLevel)
    );
}
项目:cassandra-kmean    文件:CqlOperation.java   
@Override
public <V> V execute(String query, ByteBuffer key, List<Object> queryParams, ResultHandler<V> handler) throws TException
{
    String formattedQuery = formatCqlQuery(query, queryParams, false);
    return handler.simpleNativeHandler().apply(
            client.execute_cql_query(formattedQuery, key, Compression.NONE)
    );
}
项目:ACaZoo    文件:CQLOperation.java   
public void run(final CassandraClient client) throws IOException
{
    run(new CQLQueryExecutor()
    {
        public boolean execute(String cqlQuery, List<String> queryParams) throws Exception
        {
            CqlResult result = null;
            if (session.usePreparedStatements())
            {
                Integer stmntId = getPreparedStatement(client, cqlQuery);
                if (session.cqlVersion.startsWith("3"))
                    result = client.execute_prepared_cql3_query(stmntId, queryParamsAsByteBuffer(queryParams), session.getConsistencyLevel());
                else
                    result = client.execute_prepared_cql_query(stmntId, queryParamsAsByteBuffer(queryParams));
            }
            else
            {
                String formattedQuery = formatCqlQuery(cqlQuery, queryParams);
                if (session.cqlVersion.startsWith("3"))
                    result = client.execute_cql3_query(ByteBuffer.wrap(formattedQuery.getBytes()), Compression.NONE, session.getConsistencyLevel());
                else
                    result = client.execute_cql_query(ByteBuffer.wrap(formattedQuery.getBytes()), Compression.NONE);
            }
            return validateThriftResult(result);
        }
    });
}
项目:ACaZoo    文件:Operation.java   
protected Integer getPreparedStatement(CassandraClient client, String cqlQuery) throws Exception
{
    Integer statementId = client.preparedStatements.get(cqlQuery.hashCode());
    if (statementId == null)
    {
        CqlPreparedResult response = session.cqlVersion.startsWith("3")
                                   ? client.prepare_cql3_query(ByteBufferUtil.bytes(cqlQuery), Compression.NONE)
                                   : client.prepare_cql_query(ByteBufferUtil.bytes(cqlQuery), Compression.NONE);
        statementId = response.itemId;
        client.preparedStatements.put(cqlQuery.hashCode(), statementId);
    }

    return statementId;
}
项目:openyu-commons    文件:CassandraThriftDMLTest.java   
/**
 * removeByCql
 *
 * @throws Exception
 */
@Test
public void removeByCql() throws Exception {
    String KEYSPACE = "mock";
    client.set_keyspace(KEYSPACE);
    //
    String CQL = "delete from student where KEY='Mary'";
    CqlResult result = client.execute_cql_query(
            ByteBufferHelper.toByteBuffer(CQL), Compression.NONE);
    System.out.println(result);
}
项目:scylla-tools-java    文件:CqlOperation.java   
@Override
public <V> V execute(String query, ByteBuffer key, List<Object> queryParams, ResultHandler<V> handler) throws TException
{
    String formattedQuery = formatCqlQuery(query, queryParams);
    return handler.simpleNativeHandler().apply(
            client.execute_cql3_query(formattedQuery, key, Compression.NONE, settings.command.consistencyLevel)
    );
}
项目:scylla-tools-java    文件:ValidatingSchemaQuery.java   
private static ValidatingStatement prepare(StressSettings settings, String cql, boolean incLb, boolean incUb)
{
    JavaDriverClient jclient = settings.getJavaDriverClient();
    ThriftClient tclient = settings.getThriftClient();
    PreparedStatement statement = jclient.prepare(cql);
    try
    {
        Integer thriftId = tclient.prepare_cql3_query(cql, Compression.NONE);
        return new ValidatingStatement(statement, thriftId, incLb, incUb);
    }
    catch (TException e)
    {
        throw new RuntimeException(e);
    }
}
项目:GraphTrek    文件:CqlOperation.java   
@Override
public <V> V execute(String query, ByteBuffer key, List<Object> queryParams, ResultHandler<V> handler) throws TException
{
    String formattedQuery = formatCqlQuery(query, queryParams);
    return handler.simpleNativeHandler().apply(
            client.execute_cql3_query(formattedQuery, key, Compression.NONE, settings.command.consistencyLevel)
    );
}
项目:Cassandra-Wasef    文件:CQLOperation.java   
public void run(final CassandraClient client) throws IOException
{
    run(new CQLQueryExecutor()
    {
        public boolean execute(String cqlQuery, List<String> queryParams) throws Exception
        {
            CqlResult result = null;
            if (session.usePreparedStatements())
            {
                Integer stmntId = getPreparedStatement(client, cqlQuery);
                if (session.cqlVersion.startsWith("3"))
                    result = client.execute_prepared_cql3_query(stmntId, queryParamsAsByteBuffer(queryParams), session.getConsistencyLevel());
                else
                    result = client.execute_prepared_cql_query(stmntId, queryParamsAsByteBuffer(queryParams));
            }
            else
            {
                String formattedQuery = formatCqlQuery(cqlQuery, queryParams);
                if (session.cqlVersion.startsWith("3"))
                    result = client.execute_cql3_query(ByteBuffer.wrap(formattedQuery.getBytes()), Compression.NONE, session.getConsistencyLevel());
                else
                    result = client.execute_cql_query(ByteBuffer.wrap(formattedQuery.getBytes()), Compression.NONE);
            }
            return validateThriftResult(result);
        }
    });
}
项目:Cassandra-Wasef    文件:Operation.java   
protected Integer getPreparedStatement(CassandraClient client, String cqlQuery) throws Exception
{
    Integer statementId = client.preparedStatements.get(cqlQuery.hashCode());
    if (statementId == null)
    {
        CqlPreparedResult response = session.cqlVersion.startsWith("3")
                                   ? client.prepare_cql3_query(ByteBufferUtil.bytes(cqlQuery), Compression.NONE)
                                   : client.prepare_cql_query(ByteBufferUtil.bytes(cqlQuery), Compression.NONE);
        statementId = response.itemId;
        client.preparedStatements.put(cqlQuery.hashCode(), statementId);
    }

    return statementId;
}
项目:stratio-cassandra    文件:CqlOperation.java   
@Override
public <V> V execute(String query, ByteBuffer key, List<Object> queryParams, ResultHandler<V> handler) throws TException
{
    String formattedQuery = formatCqlQuery(query, queryParams, true);
    return handler.simpleNativeHandler().apply(
            client.execute_cql3_query(formattedQuery, key, Compression.NONE, settings.command.consistencyLevel)
    );
}
项目:stratio-cassandra    文件:CqlOperation.java   
@Override
public <V> V execute(String query, ByteBuffer key, List<Object> queryParams, ResultHandler<V> handler) throws TException
{
    String formattedQuery = formatCqlQuery(query, queryParams, false);
    return handler.simpleNativeHandler().apply(
            client.execute_cql_query(formattedQuery, key, Compression.NONE)
    );
}
项目:cassandra-cqlMod    文件:CqlOperation.java   
@Override
public <V> V execute(String query, ByteBuffer key, List<ByteBuffer> queryParams, ResultHandler<V> handler) throws TException
{
    String formattedQuery = formatCqlQuery(query, queryParams, true);
    return handler.simpleNativeHandler().apply(
            client.execute_cql3_query(formattedQuery, key, Compression.NONE, state.settings.command.consistencyLevel)
    );
}
项目:cassandra-cqlMod    文件:CqlOperation.java   
@Override
public <V> V execute(String query, ByteBuffer key, List<ByteBuffer> queryParams, ResultHandler<V> handler) throws TException
{
    String formattedQuery = formatCqlQuery(query, queryParams, false);
    return handler.simpleNativeHandler().apply(
            client.execute_cql_query(formattedQuery, key, Compression.NONE)
    );
}
项目:wso2-cassandra    文件:CQLOperation.java   
public void run(final CassandraClient client) throws IOException
{
    run(new CQLQueryExecutor()
    {
        public boolean execute(String cqlQuery, List<String> queryParams) throws Exception
        {
            CqlResult result = null;
            if (session.usePreparedStatements())
            {
                Integer stmntId = getPreparedStatement(client, cqlQuery);
                if (session.cqlVersion.startsWith("3"))
                    result = client.execute_prepared_cql3_query(stmntId, queryParamsAsByteBuffer(queryParams), session.getConsistencyLevel());
                else
                    result = client.execute_prepared_cql_query(stmntId, queryParamsAsByteBuffer(queryParams));
            }
            else
            {
                String formattedQuery = formatCqlQuery(cqlQuery, queryParams);
                if (session.cqlVersion.startsWith("3"))
                    result = client.execute_cql3_query(ByteBuffer.wrap(formattedQuery.getBytes()), Compression.NONE, session.getConsistencyLevel());
                else
                    result = client.execute_cql_query(ByteBuffer.wrap(formattedQuery.getBytes()), Compression.NONE);
            }
            return validateThriftResult(result);
        }
    });
}
项目:wso2-cassandra    文件:Operation.java   
protected Integer getPreparedStatement(CassandraClient client, String cqlQuery) throws Exception
{
    Integer statementId = client.preparedStatements.get(cqlQuery.hashCode());
    if (statementId == null)
    {
        CqlPreparedResult response = session.cqlVersion.startsWith("3")
                                   ? client.prepare_cql3_query(ByteBufferUtil.bytes(cqlQuery), Compression.NONE)
                                   : client.prepare_cql_query(ByteBufferUtil.bytes(cqlQuery), Compression.NONE);
        statementId = response.itemId;
        client.preparedStatements.put(cqlQuery.hashCode(), statementId);
    }

    return statementId;
}
项目:cassandra-trunk    文件:CqlOperation.java   
@Override
public <V> V execute(String query, ByteBuffer key, List<Object> queryParams, ResultHandler<V> handler) throws TException
{
    String formattedQuery = formatCqlQuery(query, queryParams);
    return handler.simpleNativeHandler().apply(
            client.execute_cql3_query(formattedQuery, key, Compression.NONE, state.settings.command.consistencyLevel)
    );
}
项目:cassandra-1.2.16    文件:CQLOperation.java   
public void run(final CassandraClient client) throws IOException
{
    run(new CQLQueryExecutor()
    {
        public boolean execute(String cqlQuery, List<String> queryParams) throws Exception
        {
            CqlResult result = null;
            if (session.usePreparedStatements())
            {
                Integer stmntId = getPreparedStatement(client, cqlQuery);
                if (session.cqlVersion.startsWith("3"))
                    result = client.execute_prepared_cql3_query(stmntId, queryParamsAsByteBuffer(queryParams), session.getConsistencyLevel());
                else
                    result = client.execute_prepared_cql_query(stmntId, queryParamsAsByteBuffer(queryParams));
            }
            else
            {
                String formattedQuery = formatCqlQuery(cqlQuery, queryParams);
                if (session.cqlVersion.startsWith("3"))
                    result = client.execute_cql3_query(ByteBuffer.wrap(formattedQuery.getBytes()), Compression.NONE, session.getConsistencyLevel());
                else
                    result = client.execute_cql_query(ByteBuffer.wrap(formattedQuery.getBytes()), Compression.NONE);
            }
            return validateThriftResult(result);
        }
    });
}
项目:cassandra-1.2.16    文件:Operation.java   
protected Integer getPreparedStatement(CassandraClient client, String cqlQuery) throws Exception
{
    Integer statementId = client.preparedStatements.get(cqlQuery.hashCode());
    if (statementId == null)
    {
        CqlPreparedResult response = session.cqlVersion.startsWith("3")
                                   ? client.prepare_cql3_query(ByteBufferUtil.bytes(cqlQuery), Compression.NONE)
                                   : client.prepare_cql_query(ByteBufferUtil.bytes(cqlQuery), Compression.NONE);
        statementId = response.itemId;
        client.preparedStatements.put(cqlQuery.hashCode(), statementId);
    }

    return statementId;
}
项目:cassandra-kmean    文件:CqlOperation.java   
@Override
public Object createPreparedStatement(String cqlQuery) throws TException
{
    return client.prepare_cql3_query(cqlQuery, Compression.NONE);
}
项目:cassandra-kmean    文件:CqlOperation.java   
@Override
public Object createPreparedStatement(String cqlQuery) throws TException
{
    return client.prepare_cql_query(cqlQuery, Compression.NONE);
}
项目:ACaZoo    文件:Shuffle.java   
CqlResult execute_cql_query(ByteBuffer cqlQuery, Compression compression) throws Exception
{
    return client.execute_cql3_query(cqlQuery, compression, ConsistencyLevel.ONE);
}
项目:scylla-tools-java    文件:CqlOperation.java   
@Override
public Object createPreparedStatement(String cqlQuery) throws TException
{
    return client.prepare_cql3_query(cqlQuery, Compression.NONE);
}
项目:GraphTrek    文件:CqlOperation.java   
@Override
public Object createPreparedStatement(String cqlQuery) throws TException
{
    return client.prepare_cql3_query(cqlQuery, Compression.NONE);
}
项目:Cassandra-Wasef    文件:Shuffle.java   
CqlResult execute_cql_query(ByteBuffer cqlQuery, Compression compression) throws Exception
{
    return client.execute_cql3_query(cqlQuery, compression, ConsistencyLevel.ONE);
}
项目:stratio-cassandra    文件:CqlOperation.java   
@Override
public Object createPreparedStatement(String cqlQuery) throws TException
{
    return client.prepare_cql3_query(cqlQuery, Compression.NONE);
}
项目:stratio-cassandra    文件:CqlOperation.java   
@Override
public Object createPreparedStatement(String cqlQuery) throws TException
{
    return client.prepare_cql_query(cqlQuery, Compression.NONE);
}
项目:cassandra-cqlMod    文件:Shuffle.java   
CqlResult execute_cql_query(ByteBuffer cqlQuery, Compression compression) throws Exception
{
    return client.execute_cql3_query(cqlQuery, compression, ConsistencyLevel.ONE);
}
项目:cassandra-cqlMod    文件:CqlOperation.java   
@Override
public Object createPreparedStatement(String cqlQuery) throws TException
{
    return client.prepare_cql3_query(cqlQuery, Compression.NONE);
}
项目:cassandra-cqlMod    文件:CqlOperation.java   
@Override
public Object createPreparedStatement(String cqlQuery) throws TException
{
    return client.prepare_cql_query(cqlQuery, Compression.NONE);
}
项目:wso2-cassandra    文件:Shuffle.java   
CqlResult execute_cql_query(ByteBuffer cqlQuery, Compression compression) throws Exception
{
    return client.execute_cql3_query(cqlQuery, compression, ConsistencyLevel.ONE);
}
项目:cassandra-trunk    文件:Shuffle.java   
CqlResult execute_cql_query(ByteBuffer cqlQuery, Compression compression) throws Exception
{
    return client.execute_cql3_query(cqlQuery, compression, ConsistencyLevel.ONE);
}