Search in sources :

Example 56 with Decimal128

use of org.bson.types.Decimal128 in project realm-java by realm.

the class JNITableInsertTest method parameters.

@Parameterized.Parameters
public static Collection<Object[]> parameters() {
    List<Object> value = new ArrayList<>();
    value.add(0, true);
    value.add(1, "abc");
    value.add(2, 123L);
    value.add(3, 987.123f);
    value.add(4, 1234567.898d);
    value.add(5, new Date(645342));
    value.add(6, new byte[] { 1, 2, 3, 4, 5 });
    value.add(7, new Decimal128(1));
    value.add(8, new ObjectId());
    return Arrays.asList(new Object[] { value }, new Object[] { value });
}
Also used : ObjectId(org.bson.types.ObjectId) ArrayList(java.util.ArrayList) Decimal128(org.bson.types.Decimal128) Date(java.util.Date)

Example 57 with Decimal128

use of org.bson.types.Decimal128 in project realm-java by realm.

the class DynamicRealmObject method setValueSet.

@SuppressWarnings("unchecked")
private <E> void setValueSet(String fieldName, RealmSet<E> sourceSet, RealmFieldType primitiveType) {
    long columnKey = proxyState.getRow$realm().getColumnKey(fieldName);
    OsSet osSet = proxyState.getRow$realm().getValueSet(columnKey, primitiveType);
    Class<E> elementClass;
    switch(primitiveType) {
        case INTEGER_SET:
            elementClass = (Class<E>) Number.class;
            break;
        case BOOLEAN_SET:
            elementClass = (Class<E>) Boolean.class;
            break;
        case STRING_SET:
            elementClass = (Class<E>) String.class;
            break;
        case BINARY_SET:
            elementClass = (Class<E>) byte[].class;
            break;
        case DATE_SET:
            elementClass = (Class<E>) Date.class;
            break;
        case FLOAT_SET:
            elementClass = (Class<E>) Float.class;
            break;
        case DOUBLE_SET:
            elementClass = (Class<E>) Double.class;
            break;
        case DECIMAL128_SET:
            elementClass = (Class<E>) Decimal128.class;
            break;
        case OBJECT_ID_SET:
            elementClass = (Class<E>) ObjectId.class;
            break;
        case UUID_SET:
            elementClass = (Class<E>) UUID.class;
            break;
        case MIXED_SET:
            elementClass = (Class<E>) RealmAny.class;
            break;
        default:
            throw new IllegalArgumentException("Unsupported type: " + primitiveType);
    }
    // Set in the RealmObject
    RealmSet<E> targetSet = new RealmSet<>(proxyState.getRealm$realm(), osSet, elementClass);
    // We move the data in a auxiliary set to prevent removing the values when the input and out sets are
    // the same.
    RealmSet<E> auxiliarySet = new RealmSet<>();
    auxiliarySet.addAll(sourceSet);
    // Now we can safely clear the target set
    osSet.clear();
    // And now we move the data back in
    targetSet.addAll(auxiliarySet);
}
Also used : ObjectId(org.bson.types.ObjectId) Decimal128(org.bson.types.Decimal128) Date(java.util.Date) OsSet(io.realm.internal.OsSet) UUID(java.util.UUID) NativeRealmAny(io.realm.internal.core.NativeRealmAny)

Example 58 with Decimal128

use of org.bson.types.Decimal128 in project realm-java by realm.

the class DynamicRealmObject method setValueList.

@SuppressWarnings("unchecked")
private <E> void setValueList(String fieldName, RealmList<E> list, RealmFieldType primitiveType) {
    long columnKey = proxyState.getRow$realm().getColumnKey(fieldName);
    OsList osList = proxyState.getRow$realm().getValueList(columnKey, primitiveType);
    Class<E> elementClass;
    switch(primitiveType) {
        case INTEGER_LIST:
            elementClass = (Class<E>) Long.class;
            break;
        case BOOLEAN_LIST:
            elementClass = (Class<E>) Boolean.class;
            break;
        case STRING_LIST:
            elementClass = (Class<E>) String.class;
            break;
        case BINARY_LIST:
            elementClass = (Class<E>) byte[].class;
            break;
        case DATE_LIST:
            elementClass = (Class<E>) Date.class;
            break;
        case FLOAT_LIST:
            elementClass = (Class<E>) Float.class;
            break;
        case DOUBLE_LIST:
            elementClass = (Class<E>) Double.class;
            break;
        case DECIMAL128_LIST:
            elementClass = (Class<E>) Decimal128.class;
            break;
        case OBJECT_ID_LIST:
            elementClass = (Class<E>) ObjectId.class;
            break;
        case UUID_LIST:
            elementClass = (Class<E>) UUID.class;
            break;
        case MIXED_LIST:
            elementClass = (Class<E>) RealmAny.class;
            break;
        default:
            throw new IllegalArgumentException("Unsupported type: " + primitiveType);
    }
    final ManagedListOperator<?> operator = getOperator(proxyState.getRealm$realm(), osList, primitiveType, elementClass);
    if (list.isManaged() && osList.size() == list.size()) {
        // There is a chance that the source list and the target list are the same list in the same object.
        // In this case, we can't use removeAll().
        final int size = list.size();
        final Iterator<?> iterator = list.iterator();
        for (int i = 0; i < size; i++) {
            @Nullable final Object value = iterator.next();
            operator.set(i, value);
        }
    } else {
        osList.removeAll();
        for (Object value : list) {
            operator.append(value);
        }
    }
}
Also used : OsList(io.realm.internal.OsList) ObjectId(org.bson.types.ObjectId) Decimal128(org.bson.types.Decimal128) Date(java.util.Date) UUID(java.util.UUID) NativeRealmAny(io.realm.internal.core.NativeRealmAny) Nullable(javax.annotation.Nullable)

Example 59 with Decimal128

use of org.bson.types.Decimal128 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)

Example 60 with Decimal128

use of org.bson.types.Decimal128 in project realm-java by realm.

the class JNIQueryTest method queryTestForNoMatches.

@Test
public void queryTestForNoMatches() {
    Table t = TestHelper.createTableWithAllColumnTypes(sharedRealm);
    long columnKey1 = t.getColumnKey("binary");
    long columnKey2 = t.getColumnKey("boolean");
    long columnKey3 = t.getColumnKey("date");
    long columnKey4 = t.getColumnKey("double");
    long columnKey5 = t.getColumnKey("float");
    long columnKey6 = t.getColumnKey("long");
    long columnKey7 = t.getColumnKey("string");
    long columnKey8 = t.getColumnKey("decimal128");
    long columnKey9 = t.getColumnKey("object_id");
    sharedRealm.beginTransaction();
    TestHelper.addRowWithValues(t, new long[] { columnKey1, columnKey2, columnKey3, columnKey4, columnKey5, columnKey6, columnKey7, columnKey8, columnKey9 }, new Object[] { new byte[] { 1, 2, 3 }, true, new Date(1384423149761L), 4.5d, 5.7f, 100, "string", new Decimal128(0), new ObjectId() });
    sharedRealm.commitTransaction();
    // No matches
    TableQuery q = t.where().greaterThan(null, "long", RealmAny.valueOf(1000));
    assertEquals(-1, q.find());
}
Also used : ObjectId(org.bson.types.ObjectId) Decimal128(org.bson.types.Decimal128) Date(java.util.Date) Test(org.junit.Test)

Aggregations

Decimal128 (org.bson.types.Decimal128)80 ObjectId (org.bson.types.ObjectId)50 Date (java.util.Date)46 Test (org.junit.Test)46 AllTypes (io.realm.entities.AllTypes)22 BigDecimal (java.math.BigDecimal)20 UUID (java.util.UUID)17 UiThreadTest (androidx.test.annotation.UiThreadTest)12 PrimaryKeyAsString (io.realm.entities.PrimaryKeyAsString)11 AllJavaTypes (io.realm.entities.AllJavaTypes)10 DictionaryAllTypes (io.realm.entities.DictionaryAllTypes)10 Dog (io.realm.entities.Dog)9 PrimaryKeyAsObjectId (io.realm.entities.PrimaryKeyAsObjectId)8 JSONObject (org.json.JSONObject)8 MappedAllJavaTypes (io.realm.entities.MappedAllJavaTypes)7 NonLatinFieldNames (io.realm.entities.NonLatinFieldNames)6 PrimaryKeyAsLong (io.realm.entities.PrimaryKeyAsLong)6 SimpleDateFormat (java.text.SimpleDateFormat)6 Calendar (java.util.Calendar)6 DefaultValueOfField (io.realm.entities.DefaultValueOfField)5