当前位置: 首页>>代码示例>>Java>>正文


Java Compression类代码示例

本文整理汇总了Java中org.apache.cassandra.thrift.Compression的典型用法代码示例。如果您正苦于以下问题:Java Compression类的具体用法?Java Compression怎么用?Java Compression使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Compression类属于org.apache.cassandra.thrift包,在下文中一共展示了Compression类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: executeStatement

import org.apache.cassandra.thrift.Compression; //导入依赖的package包/类
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);
    }
}
 
开发者ID:mojohaus,项目名称:cassandra-maven-plugin,代码行数:19,代码来源:AbstractCqlExecMojo.java

示例2: getByCql

import org.apache.cassandra.thrift.Compression; //导入依赖的package包/类
/**
 * 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
		}
	}
}
 
开发者ID:mixaceh,项目名称:openyu-commons,代码行数:30,代码来源:CassandraThriftDMLTest.java

示例3: commitCQLBatch

import org.apache.cassandra.thrift.Compression; //导入依赖的package包/类
/**
 * 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);
}
 
开发者ID:javachen,项目名称:learning-hadoop,代码行数:28,代码来源:CassandraOutputData.java

示例4: compressQuery

import org.apache.cassandra.thrift.Compression; //导入依赖的package包/类
/**
 * 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();
}
 
开发者ID:javachen,项目名称:learning-hadoop,代码行数:28,代码来源:CassandraOutputData.java

示例5: compressQuery

import org.apache.cassandra.thrift.Compression; //导入依赖的package包/类
/**
 * 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();
}
 
开发者ID:javachen,项目名称:learning-hadoop,代码行数:26,代码来源:CassandraInputData.java

示例6: executeCQL

import org.apache.cassandra.thrift.Compression; //导入依赖的package包/类
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");
    }
}
 
开发者ID:RapturePlatform,项目名称:Rapture,代码行数:8,代码来源:CassandraBase.java

示例7: executeCql3Script_1_1

import org.apache.cassandra.thrift.Compression; //导入依赖的package包/类
/** @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);
    }
}
 
开发者ID:bazaarvoice,项目名称:emodb,代码行数:16,代码来源:CassandraThriftFacade.java

示例8: executeCql3Script

import org.apache.cassandra.thrift.Compression; //导入依赖的package包/类
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);
    }
}
 
开发者ID:bazaarvoice,项目名称:emodb,代码行数:14,代码来源:CassandraThriftFacade.java

示例9: execute

import org.apache.cassandra.thrift.Compression; //导入依赖的package包/类
@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)
    );
}
 
开发者ID:vcostet,项目名称:cassandra-kmean,代码行数:9,代码来源:CqlOperation.java

示例10: run

import org.apache.cassandra.thrift.Compression; //导入依赖的package包/类
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);
        }
    });
}
 
开发者ID:pgaref,项目名称:ACaZoo,代码行数:28,代码来源:CQLOperation.java

示例11: getPreparedStatement

import org.apache.cassandra.thrift.Compression; //导入依赖的package包/类
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;
}
 
开发者ID:pgaref,项目名称:ACaZoo,代码行数:15,代码来源:Operation.java

示例12: removeByCql

import org.apache.cassandra.thrift.Compression; //导入依赖的package包/类
/**
 * 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);
}
 
开发者ID:mixaceh,项目名称:openyu-commons,代码行数:16,代码来源:CassandraThriftDMLTest.java

示例13: execute

import org.apache.cassandra.thrift.Compression; //导入依赖的package包/类
@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)
    );
}
 
开发者ID:scylladb,项目名称:scylla-tools-java,代码行数:9,代码来源:CqlOperation.java

示例14: prepare

import org.apache.cassandra.thrift.Compression; //导入依赖的package包/类
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);
    }
}
 
开发者ID:scylladb,项目名称:scylla-tools-java,代码行数:16,代码来源:ValidatingSchemaQuery.java

示例15: execute

import org.apache.cassandra.thrift.Compression; //导入依赖的package包/类
@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)
    );
}
 
开发者ID:mafernandez-stratio,项目名称:cassandra-cqlMod,代码行数:9,代码来源:CqlOperation.java


注:本文中的org.apache.cassandra.thrift.Compression类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。