Package com.netflix.astyanax

Examples of com.netflix.astyanax.Keyspace


    @SuppressWarnings("unchecked")
    public void simpleReadWriteCompositeTest() {
        boolean fail = false;
        try {
            AstyanaxContext<Keyspace> context = newContext("localhost:9160", KEYSPACE);
            Keyspace ks = context.getEntity();
            ColumnFamily<String, Composite> cf = new ColumnFamily<String, Composite>("composite",
                    StringSerializer.get(), CompositeSerializer.get());

            MutationBatch mutation = ks.prepareMutationBatch();

            mutation.withRow(cf, "mykey").putColumn(makeStringComposite("foo", "bar"),
                    "Hello Composite Column Range Query");
            mutation.withRow(cf, "mykey").putColumn(makeStringComposite("foo", "baz"), "My dog has fleas");
            mutation.withRow(cf, "mykey").putColumn(makeStringComposite("fzz", "baz"), "It is snowing");

            mutation.execute();

            // simple column fetch
            ColumnFamilyQuery<String, Composite> query = ks.prepareQuery(cf);
            Column<Composite> result = query.getKey("mykey").getColumn(makeStringComposite("foo", "bar")).execute()
                    .getResult();
            LOG.debug(result.getStringValue());

            // build up a composite range query
View Full Code Here


    public void twoDimensionalCompositeRangeTest() {
        boolean fail = false;
        try {
            final String rowkey = "mykey2";
            AstyanaxContext<Keyspace> context = newContext("localhost:9160", KEYSPACE);
            Keyspace ks = context.getEntity();
            ColumnFamily<String, Composite> cf = new ColumnFamily<String, Composite>("composite2",
                    StringSerializer.get(), CompositeSerializer.get());

            MutationBatch mutation = ks.prepareMutationBatch();
           
            List<String> combinations = combinationsWithRepitition("abcdef", 3);
           
            for(String str : combinations){
                LOG.debug("Will insert '{}'", str);
                mutation.withRow(cf, rowkey).putColumn(makeStringComposite(str.substring(0,1), str.substring(1,2), str.substring(2,3)), str);
            }

            mutation.execute();

            // build up a composite range query
            Composite start = makeStringEqualityComposite(new String[] { "a", "a", "a"}, new ComponentEquality[] {
                    ComponentEquality.EQUAL,ComponentEquality.EQUAL, ComponentEquality.EQUAL });
            Composite end = makeStringEqualityComposite(new String[] { "a", "a", "b"}, new ComponentEquality[] {
                    ComponentEquality.EQUAL,ComponentEquality.EQUAL, ComponentEquality.EQUAL });

            ColumnFamilyQuery<String, Composite> query = ks.prepareQuery(cf);
            ColumnList<Composite> results = query.getKey(rowkey)
                    .withColumnRange(start.serialize(), end.serialize(), false, 100).execute().getResult();
            LOG.debug("Query matched {} results.", results.size());
            for (Composite columnKey : results.getColumnNames()) {
//                LOG.debug("Component(0): {}", columnKey.getComponent(0).getValue(StringSerializer.get()));
View Full Code Here

        // wait very briefly for the batch to complete
        Thread.sleep(250);

        AstyanaxContext<Keyspace> astyContext = newContext("localhost:9160", KEYSPACE);
        Keyspace ks = astyContext.getEntity();

        Column<String> result = ks
                .prepareQuery(new ColumnFamily<String, String>("users", StringSerializer.get(), StringSerializer.get()))
                .getKey("42").getColumn("VALUE").execute().getResult();
        assertEquals("42", result.getStringValue());

    }
View Full Code Here

        // wait very briefly for the batch to complete
        Thread.sleep(250);

        AstyanaxContext<Keyspace> astyContext = newContext("localhost:9160", KEYSPACE);
        Keyspace ks = astyContext.getEntity();

        Column<String> result = ks
                .prepareQuery(
                        new ColumnFamily<String, String>("Counts", StringSerializer.get(), StringSerializer.get()))
                .getKey("1").getColumn("MyCountColumn").execute().getResult();
        assertEquals(1L, result.getLongValue());
    }
View Full Code Here

        }
    }
   
    public static void createCounterColumnFamily(AstyanaxContext<Cluster> ctx,String ks, String cf) throws ConnectionException{
        Cluster cluster = ctx.getEntity();
        Keyspace keyspace = cluster.getKeyspace(ks);
        if(keyspace != null){
            LOG.warn("Keyspace {} already exists.", ks);
        }
        KeyspaceDefinition ksDef = cluster.makeKeyspaceDefinition();
View Full Code Here

        Tuple tuple = new MockTuple(fields, values);

        client.writeTuple(tuple, tupleMapper);

        AstyanaxContext<Keyspace> context = newContext("localhost:9160", KEYSPACE);
        Keyspace ks = context.getEntity();

        Column<String> result = ks
                .prepareQuery(
                        new ColumnFamily<SimpleComposite, String>("simple",
                                new AnnotatedCompositeSerializer<SimpleComposite>(SimpleComposite.class),
                                StringSerializer.get())).getKey(new SimpleComposite("key1val", "key2val"))
                .getColumn("foo").execute().getResult();
View Full Code Here

        }
       
       
       
        AstyanaxContext<Keyspace> context = newContext("localhost:9160", KEYSPACE);
        Keyspace ks = context.getEntity();
       
        AnnotatedCompositeSerializer<Composite2> acs = new AnnotatedCompositeSerializer<Composite2>(Composite2.class);
       
        ColumnFamily<String, Composite2> cf = new ColumnFamily<String, Composite2>("generic", StringSerializer.get(), acs);
       
        MutationBatch mutation = ks.prepareMutationBatch();
       
       
       
        mutation.withRow(cf, "foo").putColumn(c2, "Hello World");
       
View Full Code Here

    ColumnType type = info.getColumnType();
    if(type != ColumnType.ANY_EXCEPT_COMPOSITE) {
      throw new UnsupportedOperationException("Finding on composite type="+colFamily+" not allowed here, you should be using column slice as these rows are HUGE!!!!");
    }
   
    Keyspace keyspace = columnFamilies.getKeyspace();
    CursorKeysToRows2 cursor = new CursorKeysToRows2(rowKeys, batchSize, list, rowProvider);
    cursor.setupMore(keyspace, colFamily, info, cache);
    return cursor;
  }
View Full Code Here

    } catch (ConnectionException e) {
      throw new RuntimeException(e);
    }
  }
  public void sendChangesImpl(List<Action> actions, MetaLookup ormSession) throws ConnectionException {
    Keyspace keyspace = columnFamilies.getKeyspace();
    MutationBatch m = keyspace.prepareMutationBatch();
    //MutationBatch m = m1.setConsistencyLevel(ConsistencyLevel.CL_QUORUM);
   
    for(Action action : actions) {
      if(action instanceof Persist) {
        persist((Persist)action, ormSession, m);
View Full Code Here

  }
 
  private RowQuery createBasicRowQuery(byte[] rowKey, Info info1, ByteBufferRange range) {
    ColumnFamily cf = info1.getColumnFamilyObj();
   
    Keyspace keyspace = columnFamilies.getKeyspace();
    ColumnFamilyQuery query = keyspace.prepareQuery(cf);
    //ColumnFamilyQuery query = query1.setConsistencyLevel(ConsistencyLevel.CL_QUORUM);
    RowQuery rowQuery = query.getKey(rowKey)
              .autoPaginate(true)
              .withColumnRange(range);
    return rowQuery;
View Full Code Here

TOP

Related Classes of com.netflix.astyanax.Keyspace

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.