Package com.basho.riak.client.core.query.indexes

Examples of com.basho.riak.client.core.query.indexes.LongIntIndex


       
        StringBinIndex stringIndex = indexes.getIndex(new StringBinIndex.Name("foo"));
        assertEquals(stringIndex.size(), 1);
        assertTrue(stringIndex.hasValue("value"));
       
        LongIntIndex longIndex = indexes.getIndex(new LongIntIndex.Name("foo"));
        assertEquals(stringIndex.size(), 1);
        assertTrue(longIndex.hasValue(Long.MIN_VALUE));
    }
View Full Code Here


public class LongIntIndexTest
{
    @Test
    public void storeAndRetrieveLong()
    {
        LongIntIndex index = new LongIntIndex.Name("index_name").createIndex();
        Set<Long> longSet = new HashSet<Long>(Arrays.asList(Long.MAX_VALUE, Long.MIN_VALUE));
       
        index.add(longSet);
       
        assertEquals(index.size(), 2);
        assertTrue(index.hasValue(Long.MIN_VALUE));
        assertTrue(index.hasValue(Long.MAX_VALUE));
       
        Set<Long> longSet2 = index.values();
        assertTrue(longSet.containsAll(longSet2));
       
    }
View Full Code Here

   
    @Test
    public void createIndex()
    {
        assertTrue(indexes.isEmpty());
        LongIntIndex index = indexes.getIndex(new LongIntIndex.Name("foo"));
        assertFalse(indexes.isEmpty());
        assertEquals(indexes.size(), 1);
        assertTrue(indexes.hasIndex(new LongIntIndex.Name("foo")));
    }
View Full Code Here

       
        indexes.getIndex(new LongIntIndex.Name("my_index")).add(4L);
       
        assertTrue(indexes.hasIndex(new LongIntIndex.Name("my_index")));
       
        LongIntIndex lii = indexes.getIndex(new LongIntIndex.Name("my_index"));
        assertTrue(lii.hasValue(4L));
       
        RawIndex rri = indexes.getIndex(new RawIndex.Name("my_index", IndexType.INT));
        assertTrue(rri.hasValue(BinaryValue.unsafeCreate(String.valueOf(4L).getBytes())));
       
        assertEquals(indexes.size(), 1);
View Full Code Here

    @Test
    public void removeIndex()
    {
        assertTrue(indexes.isEmpty());
        StringBinIndex stringIndex = indexes.getIndex(new StringBinIndex.Name("bar"));
        LongIntIndex longIndex = indexes.getIndex(new LongIntIndex.Name("foo"));
       
        LongIntIndex removedLongIndex = indexes.removeIndex(new LongIntIndex.Name("foo"));
        assertEquals(longIndex, removedLongIndex);
        assertEquals(indexes.size(), 1);
    }
View Full Code Here

   
    @Test
    public void getIndex()
    {
        indexes.getIndex(new LongIntIndex.Name("foo")).add(Long.MIN_VALUE);
        LongIntIndex index = indexes.getIndex(new LongIntIndex.Name("foo"));
        assertEquals(index.getName(), "foo");
        assertTrue(index.hasValue(Long.MIN_VALUE));
    }
View Full Code Here

        List<RiakLink> links = new ArrayList<RiakLink>();
        links.add(new RiakLink("bucket", "key", "tag"));
        ro.getLinks().addLinks(links);

        RiakIndexes indexes = ro.getIndexes();
        LongIntIndex longIndex = indexes.getIndex(LongIntIndex.named("dave"));
        longIndex.add(42L);

        ro.setValue(BinaryValue.unsafeCreate(expectedValue));

        Location location = new Location(ns, key);
        StoreOperation operation =
View Full Code Here

            switch(f.getFieldType())
            {
                case SET_LONG:
                case LONG:
                    // We want to create the index regardless
                    LongIntIndex longIndex = container.getIndex(LongIntIndex.named(f.getIndexName()));
                    if (val != null)
                    {
                        if (f.getFieldType() == RiakIndexField.FieldType.SET_LONG)
                        {
                            longIndex.add((Set<Long>) val);
                        }
                        else
                        {
                            longIndex.add((Long) val);
                        }
                    }
                    break;
                case SET_STRING:
                case STRING:
                    // We want to create the index regardless
                    StringBinIndex stringBinIndex = container.getIndex(StringBinIndex.named(f.getIndexName()));
                    if (val != null)
                    {
                        if (f.getFieldType() == RiakIndexField.FieldType.SET_STRING)
                        {
                            stringBinIndex.add((Set<String>) val);
                        }
                        else
                        {
                            stringBinIndex.add((String) val);
                        }
                    }
                    break;
                case SET_BIG_INT:
                case BIG_INT:
                    BigIntIndex bigIntIndex = container.getIndex(BigIntIndex.named(f.getIndexName()));
                    if (val != null)
                    {
                        if (f.getFieldType() == RiakIndexField.FieldType.SET_BIG_INT)
                        {
                            bigIntIndex.add((Set<BigInteger>) val);
                        }
                        else
                        {
                            bigIntIndex.add((BigInteger) val);
                        }
                    }
                    break;
                case SET_RAW:
                case RAW:
                {
                    // We want to create the index regardless
                    IndexType iType = IndexType.typeFromFullname(f.getIndexName());
                    RawIndex rawIndex = container.getIndex(RawIndex.named(f.getIndexName(), iType));
                    if (val != null)
                    {
                        if (f.getFieldType() == RiakIndexField.FieldType.SET_RAW)
                        {
                            for (byte[] bytes : (Set<byte[]>) val)
                            {
                                rawIndex.add(BinaryValue.create(bytes));
                            }
                        }
                        else
                        {
                            rawIndex.add(BinaryValue.create((byte[])val));
                        }
                    }
                }
                default:
                    break;
            }
           
        }

        for (RiakIndexMethod m : indexMethods)
        {
            Object val;
           
            switch (m.getMethodType())
            {
                case SET_LONG_GETTER:
                case LONG_GETTER:
                    val = getMethodValue(m.getMethod(), obj);
                    // We want to create the index regardless
                    LongIntIndex index = container.getIndex(LongIntIndex.named(m.getIndexName()));
                    if (val != null)
                    {
                        if (m.getMethodType() == RiakIndexMethod.MethodType.SET_LONG_GETTER)
                        {
                            index.add((Set<Long>) val);
                        }
                        else
                        {
                            index.add((Long) val);
                        }
                    }
                    break;
                case SET_STRING_GETTER:
                case STRING_GETTER:
View Full Code Here

            Set<?> val = null;
            switch(f.getFieldType())
            {
                case SET_LONG:
                case LONG:
                    LongIntIndex longIndex = indexes.getIndex(LongIntIndex.named(f.getIndexName()));
                    val = longIndex.values();
                    break;
                case SET_STRING:
                case STRING:
                    StringBinIndex stringIndex = indexes.getIndex(StringBinIndex.named(f.getIndexName()));
                    val = stringIndex.values();
                    break;
                case SET_BIG_INT:
                case BIG_INT:
                    BigIntIndex bigIntIndex = indexes.getIndex(BigIntIndex.named(f.getIndexName()));
                    val = bigIntIndex.values();
                    break;
                case SET_RAW:
                case RAW:
                    IndexType iType = IndexType.typeFromFullname(f.getIndexName());
                    RawIndex rawIndex = indexes.getIndex((RawIndex.named(f.getIndexName(), iType)));
                    // Convert from BinaryValue to bytes
                    Set<byte[]> byteSet = new HashSet<byte[]>();
                    for (BinaryValue bv : rawIndex.values())
                    {
                        byteSet.add(bv.unsafeGetValue());
                    }
                    val = byteSet;
                    break;
                default:
                    break;
            }
           
            if (val != null)
            {
                if (f.getFieldType() == RiakIndexField.FieldType.LONG ||
                      f.getFieldType() == RiakIndexField.FieldType.STRING ||
                      f.getFieldType() == RiakIndexField.FieldType.BIG_INT ||
                      f.getFieldType() == RiakIndexField.FieldType.RAW)
                {
                    if (!val.isEmpty())
                    {
                        setFieldValue(f.getField(), obj, val.iterator().next()); // take the first value
                    }
                }
                else
                {
                    setFieldValue(f.getField(), obj, val);
                }
            }
        }

        for (RiakIndexMethod m : indexMethods)
        {
            Set<?> val = null;
           
            switch(m.getMethodType())
            {
                case SET_LONG_SETTER:
                case LONG_SETTER:
                    LongIntIndex longIndex = indexes.getIndex(LongIntIndex.named(m.getIndexName()));
                    val = longIndex.values();
                    break;
                case SET_STRING_SETTER:
                case STRING_SETTER:
                    StringBinIndex stringIndex = indexes.getIndex(StringBinIndex.named(m.getIndexName()));
                    val = stringIndex.values();
View Full Code Here

TOP

Related Classes of com.basho.riak.client.core.query.indexes.LongIntIndex

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.