daily pastebin goal
3%
SHARE
TWEET

Untitled

a guest Feb 19th, 2019 63 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.apigee.apix.cassandra.test;
  2.  
  3. import me.prettyprint.cassandra.serializers.CompositeSerializer;
  4. import me.prettyprint.cassandra.serializers.StringSerializer;
  5. import me.prettyprint.hector.api.beans.AbstractComposite;
  6. import me.prettyprint.hector.api.beans.ColumnSlice;
  7. import me.prettyprint.hector.api.beans.Composite;
  8. import me.prettyprint.hector.api.factory.HFactory;
  9. import me.prettyprint.hector.api.query.QueryResult;
  10. import me.prettyprint.hector.api.query.SliceQuery;
  11.  
  12. /**
  13.  * Created with IntelliJ IDEA.
  14.  * User: thameema
  15.  * Date: 10/19/12
  16.  * Time: 10:25 AM
  17.  * To change this template use File | Settings | File Templates.
  18.  */
  19. public class CassTest extends Base {
  20.  
  21.     public static void main(String args[]){
  22.         init();
  23.         CassTest ct = new CassTest();
  24.         long input = 168430082;
  25.         String s = ct.query(input);
  26.         System.out.println("Value is:"+s);
  27.     }
  28.  
  29.     private String cf = "operator_ips2";
  30.  
  31.     public String query(long inputValue) {
  32.         SliceQuery<String, Composite, String> sq = HFactory.createSliceQuery(tutorialKeyspace, StringSerializer.get(), new CompositeSerializer(), StringSerializer.get());
  33.  
  34.         sq.setColumnFamily(cf);
  35.         sq.setKey("ip");
  36.  
  37.         /**
  38.         Composite startRange = new Composite();
  39.         startRange.addComponent(0, inputValue, AbstractComposite.ComponentEquality.EQUAL);
  40.         startRange.addComponent(1, inputValue, AbstractComposite.ComponentEquality.GREATER_THAN_EQUAL);
  41.  
  42.         Composite endRange = new Composite();
  43.         endRange.addComponent(0, inputValue, AbstractComposite.ComponentEquality.EQUAL);
  44.         endRange.addComponent(1, inputValue, AbstractComposite.ComponentEquality.LESS_THAN_EQUAL);
  45.         */
  46.  
  47.         Composite startRange = new Composite();
  48.         startRange.addComponent(0, "last", AbstractComposite.ComponentEquality.EQUAL);
  49.         startRange.addComponent(1, inputValue, AbstractComposite.ComponentEquality.EQUAL);
  50.         startRange.addComponent(2, 0, AbstractComposite.ComponentEquality.EQUAL);
  51.  
  52.         Composite endRange = new Composite();
  53.         endRange.addComponent(0, "last", AbstractComposite.ComponentEquality.EQUAL);
  54.         endRange.addComponent(1, inputValue, AbstractComposite.ComponentEquality.EQUAL);
  55.         endRange.addComponent(2, Integer.MAX_VALUE, AbstractComposite.ComponentEquality.LESS_THAN_EQUAL);
  56.  
  57.         sq.setRange(startRange, endRange, false, 10);
  58.  
  59.         QueryResult<ColumnSlice<Composite,String>> result = sq.execute();
  60.         ColumnSlice<Composite, String> slice = result.get();
  61.  
  62.         return slice.getColumns().get(0).getValue();
  63.     }
  64.  
  65. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top