Mercurial > hg > Members > shoshi > TreeCMS > TreeCMSPrototype1
view src/treecms/proto/cassandra/test/CassGetSliceTest.java @ 41:1214cf906f1e
commit
author | shoshi |
---|---|
date | Tue, 18 Jan 2011 19:04:28 +0900 |
parents | |
children | 7392f7ed45d2 |
line wrap: on
line source
package treecms.proto.cassandra.test; import java.util.List; import org.apache.cassandra.thrift.Cassandra; import org.apache.cassandra.thrift.ColumnOrSuperColumn; import org.apache.cassandra.thrift.ColumnParent; import org.apache.cassandra.thrift.ColumnPath; import org.apache.cassandra.thrift.ConsistencyLevel; import org.apache.cassandra.thrift.InvalidRequestException; import org.apache.cassandra.thrift.KeySlice; import org.apache.cassandra.thrift.NotFoundException; import org.apache.cassandra.thrift.SlicePredicate; import org.apache.cassandra.thrift.SliceRange; import org.apache.cassandra.thrift.TimedOutException; import org.apache.cassandra.thrift.UnavailableException; import org.apache.thrift.TException; import org.apache.thrift.protocol.TBinaryProtocol; import org.apache.thrift.protocol.TProtocol; import org.apache.thrift.transport.TSocket; import org.apache.thrift.transport.TTransport; public class CassGetSliceTest { public static void main(String _args[])throws Exception { Cassandra.Client client; String host = "localhost"; int port = 9160; TTransport tr = new TSocket(host,port); TProtocol proto = new TBinaryProtocol(tr); client = new Cassandra.Client(proto); tr.open(); System.out.println("ClusterName = "+client.describe_cluster_name()); testGetRangeSlice(client); tr.close(); } public static void testGet(Cassandra.Client _client) throws InvalidRequestException, NotFoundException, UnavailableException, TimedOutException, TException { ColumnPath path = new ColumnPath(); path.column_family = "TreeCMSCF01"; path.column = "value".getBytes(); ColumnOrSuperColumn value = _client.get("TreeCMSKS","uuid@01",path,ConsistencyLevel.ONE); System.out.println(new String(value.column.getValue())); } public static void testGetSlice(Cassandra.Client _client) throws InvalidRequestException, NotFoundException, UnavailableException, TimedOutException, TException { SliceRange sliceRange = new SliceRange(); sliceRange.setStart(new byte[0]); sliceRange.setFinish(new byte[0]); SlicePredicate slicePredicate = new SlicePredicate(); slicePredicate.setSlice_range(sliceRange); List<ColumnOrSuperColumn> values = _client.get_slice("TreeCMSKS","uuid@01",new ColumnParent("TreeCMSCF01"),slicePredicate,ConsistencyLevel.ONE); for(ColumnOrSuperColumn value : values){ System.out.println(new String(value.column.getName())+":"+new String(value.column.getValue())); } } public static void testGetRangeSlice(Cassandra.Client _client) throws InvalidRequestException, NotFoundException, UnavailableException, TimedOutException, TException { SliceRange sliceRange = new SliceRange(); sliceRange.setStart(new byte[0]); sliceRange.setFinish(new byte[0]); SlicePredicate slicePredicate = new SlicePredicate(); slicePredicate.setSlice_range(sliceRange); List<KeySlice> values = _client.get_range_slice("TreeCMSKS",new ColumnParent("TreeCMSCF02"),slicePredicate,"hogehoge","hogehogea",100,ConsistencyLevel.ONE); for(KeySlice key : values){ System.out.println(new String(key.getKey())); for(ColumnOrSuperColumn column : key.getColumns()){ System.out.println("\t"+new String(column.column.getName())+":"+new String(column.column.getValue())); } } } }