Search in sources :

Example 6 with RealmAny

use of io.realm.RealmAny in project realm-java by realm.

the class JNIQueryTest method byteArrayQuery.

@Test
public void byteArrayQuery() throws Exception {
    final RealmAny binary1 = RealmAny.valueOf(new byte[] { 0x01, 0x02, 0x03, 0x04 });
    final RealmAny binary2 = RealmAny.valueOf(new byte[] { 0x05, 0x02, 0x03, 0x08 });
    final RealmAny binary3 = RealmAny.valueOf(new byte[] { 0x09, 0x0a, 0x0b, 0x04 });
    final RealmAny binary4 = RealmAny.valueOf(new byte[] { 0x05, 0x0a, 0x0b, 0x10 });
    final AtomicLong columnKey = new AtomicLong(-1);
    Table table = TestHelper.createTable(sharedRealm, "temp", new TestHelper.AdditionalTableSetup() {

        @Override
        public void execute(Table table) {
            columnKey.set(table.addColumn(RealmFieldType.BINARY, "binary"));
            TestHelper.addRowWithValues(table, new long[] { columnKey.get() }, new Object[] { (Object) binary1.asBinary() });
            TestHelper.addRowWithValues(table, new long[] { columnKey.get() }, new Object[] { (Object) binary2.asBinary() });
            TestHelper.addRowWithValues(table, new long[] { columnKey.get() }, new Object[] { (Object) binary3.asBinary() });
            TestHelper.addRowWithValues(table, new long[] { columnKey.get() }, new Object[] { (Object) binary4.asBinary() });
        }
    });
    // Equal to
    assertEquals(1L, table.where().equalTo(null, "binary", binary1).count());
    assertEquals(1L, table.where().equalTo(null, "binary", binary3).count());
    // Not equal to
    assertEquals(3L, table.where().notEqualTo(null, "binary", binary2).count());
    assertEquals(3L, table.where().notEqualTo(null, "binary", binary4).count());
}
Also used : TestHelper(io.realm.TestHelper) AtomicLong(java.util.concurrent.atomic.AtomicLong) RealmAny(io.realm.RealmAny) Test(org.junit.Test)

Example 7 with RealmAny

use of io.realm.RealmAny in project realm-java by realm.

the class JNIQueryTest method decimal128Query.

@Test
public void decimal128Query() throws Exception {
    final RealmAny one = RealmAny.valueOf(new Decimal128(1));
    final RealmAny two = RealmAny.valueOf(new Decimal128(2));
    final RealmAny three = RealmAny.valueOf(new Decimal128(3));
    final AtomicLong columnKey = new AtomicLong(-1);
    Table table = TestHelper.createTable(sharedRealm, "temp", new TestHelper.AdditionalTableSetup() {

        @Override
        public void execute(Table table) {
            columnKey.set(table.addColumn(RealmFieldType.DECIMAL128, "decimal128"));
            TestHelper.addRowWithValues(table, new long[] { columnKey.get() }, new Object[] { one.asDecimal128() });
            TestHelper.addRowWithValues(table, new long[] { columnKey.get() }, new Object[] { two.asDecimal128() });
            TestHelper.addRowWithValues(table, new long[] { columnKey.get() }, new Object[] { three.asDecimal128() });
        }
    });
    assertEquals(1L, table.where().equalTo(null, "decimal128", one).count());
    assertEquals(2L, table.where().notEqualTo(null, "decimal128", one).count());
    assertEquals(0L, table.where().lessThan(null, "decimal128", one).count());
    assertEquals(1L, table.where().lessThanOrEqual(null, "decimal128", one).count());
    assertEquals(2L, table.where().greaterThan(null, "decimal128", one).count());
    assertEquals(3L, table.where().greaterThanOrEqual(null, "decimal128", one).count());
    assertEquals(1L, table.where().equalTo(null, "decimal128", two).count());
    assertEquals(2L, table.where().notEqualTo(null, "decimal128", two).count());
    assertEquals(1L, table.where().lessThan(null, "decimal128", two).count());
    assertEquals(2L, table.where().lessThanOrEqual(null, "decimal128", two).count());
    assertEquals(1L, table.where().greaterThan(null, "decimal128", two).count());
    assertEquals(2L, table.where().greaterThanOrEqual(null, "decimal128", two).count());
    assertEquals(1L, table.where().equalTo(null, "decimal128", three).count());
    assertEquals(2L, table.where().notEqualTo(null, "decimal128", three).count());
    assertEquals(2L, table.where().lessThan(null, "decimal128", three).count());
    assertEquals(3L, table.where().lessThanOrEqual(null, "decimal128", three).count());
    assertEquals(0L, table.where().greaterThan(null, "decimal128", three).count());
    assertEquals(1L, table.where().greaterThanOrEqual(null, "decimal128", three).count());
}
Also used : TestHelper(io.realm.TestHelper) AtomicLong(java.util.concurrent.atomic.AtomicLong) Decimal128(org.bson.types.Decimal128) RealmAny(io.realm.RealmAny) Test(org.junit.Test)

Aggregations

RealmAny (io.realm.RealmAny)7 Test (org.junit.Test)5 TestHelper (io.realm.TestHelper)4 AtomicLong (java.util.concurrent.atomic.AtomicLong)4 Date (java.util.Date)3 NativeRealmAny (io.realm.internal.core.NativeRealmAny)2 Decimal128 (org.bson.types.Decimal128)1 ObjectId (org.bson.types.ObjectId)1