本文整理汇总了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);
}
}
示例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
}
}
}
示例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);
}
示例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();
}
示例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();
}
示例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");
}
}
示例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);
}
}
示例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);
}
}
示例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)
);
}
示例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);
}
});
}
示例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;
}
示例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);
}
示例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)
);
}
示例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);
}
}
示例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)
);
}