Package com.netflix.astyanax.model

Examples of com.netflix.astyanax.model.Composite


        this.keyspace = keyspace;
    }

    @Override
    public Composite mapToRowKey(Tuple tuple) {
        Composite keyName = new Composite();

        for (String rowKeyField : this.rowKeyFields){
            Object component = tuple.getValueByField(rowKeyField);
            if (component == null) {
                component = "[NULL]";
            }

            keyName.addComponent(component.toString(), StringSerializer.get());
        }

        return keyName;
    }
View Full Code Here


        MutationBatch mutation = this.keyspace.prepareMutationBatch();
        ColumnFamily<Composite, String> cf = new ColumnFamily<Composite, String>(this.options.columnFamily,
                CompositeSerializer.get(), StringSerializer.get());

        for (int i = 0; i < keys.size(); i++) {
            Composite keyName = toKeyName(keys.get(i));
            byte[] bytes = serializer.serialize(values.get(i));
            if (options.ttl != null && options.ttl > 0) {
                mutation.withRow(cf, keyName).putColumn(this.options.columnName, bytes, options.ttl);
            } else {
                mutation.withRow(cf, keyName).putColumn(this.options.columnName, bytes);
View Full Code Here

            }
        });
    }

    private Composite toKeyName(List<Object> key) {
        Composite keyName = new Composite();
        List<String> keyStrings = toKeyStrings(key);
        for (String componentString : keyStrings) {
            keyName.addComponent(componentString, StringSerializer.get());
        }
        return keyName;
    }
View Full Code Here

            Column<Composite> result = query.getKey("mykey").getColumn(makeStringComposite("foo", "bar")).execute()
                    .getResult();
            LOG.debug(result.getStringValue());

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

            // Composite end = new Composite();
            // end.addComponent("fyy", StringSerializer.get(),
            // ComponentEquality.GREATER_THAN_EQUAL);
            Composite end = makeStringEqualityComposite(new String[] { "fyy" },
                    new ComponentEquality[] { ComponentEquality.GREATER_THAN_EQUAL });

            ColumnList<Composite> results = query.getKey("mykey")
                    .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()));
                LOG.debug("Component(1): {}", columnKey.getComponent(1).getValue(StringSerializer.get()));
                LOG.debug("Value: {}", results.getValue(columnKey, StringSerializer.get(), ""));
View Full Code Here

            }

            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()));
//                LOG.debug("Component(1): {}", columnKey.getComponent(1).getValue(StringSerializer.get()));
//                LOG.debug("Component(2): {}", columnKey.getComponent(2).getValue(StringSerializer.get()));
View Full Code Here

        }
        assertFalse("unexpected result", fail);
    }

    public static Composite makeStringComposite(String... values) {
        Composite comp = new Composite();
        for (String value : values) {
            comp.addComponent(value, StringSerializer.get());
        }
        return comp;
    }
View Full Code Here

    public static Composite makeStringEqualityComposite(String[] values, ComponentEquality[] equalities) {
        if (values.length != equalities.length) {
            throw new IllegalArgumentException("Number of values and equalities must match.");
        }
        Composite comp = new Composite();
        for (int i = 0; i < values.length; i++) {
            comp.addComponent(values[i], StringSerializer.get(), equalities[i]);
        }
        return comp;
    }
View Full Code Here

  }

  public static class CmbAstyanaxComposite extends CmbComposite {
    private final Composite composite;
    public CmbAstyanaxComposite(List<?> l) {
      composite = new Composite(l);
    }
View Full Code Here

    private final Composite composite;
    public CmbAstyanaxComposite(List<?> l) {
      composite = new Composite(l);
    }
    public CmbAstyanaxComposite(Object... os) {
      composite = new Composite(os);
    }
View Full Code Here

        }
    }

    @Test
    public void testDeserializeOfSepecificSerializer() throws Exception {
        Composite composite1 = new Composite("abc", 123L);
        CompositeSerializer serializer = new SpecificCompositeSerializer(
                (CompositeType) TypeParser
                        .parse("CompositeType(UTF8Type,LongType)"));
        ByteBuffer byteBuffer = serializer.toByteBuffer(composite1);
        Composite composite2 = serializer.fromByteBuffer(byteBuffer);

        Assert.assertEquals(String.class, composite1.getComponent(0).getValue()
                .getClass());
        Assert.assertEquals(Long.class, composite1.getComponent(1).getValue()
                .getClass());

        Assert.assertEquals(composite1.getComponent(0).getValue().getClass(),
                composite2.getComponent(0).getValue().getClass());
        Assert.assertEquals(composite1.getComponent(1).getValue().getClass(),
                composite2.getComponent(1).getValue().getClass());

        Assert.assertEquals(composite1.getComponent(0).getValue(), composite2
                .getComponent(0).getValue());
        Assert.assertEquals(composite1.getComponent(1).getValue(), composite2
                .getComponent(1).getValue());
    }
View Full Code Here

TOP

Related Classes of com.netflix.astyanax.model.Composite

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.