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 });
}
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);
}
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);
}
}
}
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());
}
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());
}
Aggregations