Search in sources :

Example 66 with AllJavaTypes

use of io.realm.entities.AllJavaTypes in project realm-java by realm.

the class RealmQueryTests method createBinaryOnlyDataSet.

private void createBinaryOnlyDataSet() {
    realm.beginTransaction();
    for (int i = 0; i < binaries.length; i++) {
        AllJavaTypes binaryOnly = new AllJavaTypes((long) i);
        binaryOnly.setFieldBinary(binaries[i]);
        realm.copyToRealm(binaryOnly);
    }
    realm.commitTransaction();
}
Also used : AllJavaTypes(io.realm.entities.AllJavaTypes)

Example 67 with AllJavaTypes

use of io.realm.entities.AllJavaTypes in project realm-java by realm.

the class RealmQueryTests method populateForDistinctInvalidTypesLinked.

private void populateForDistinctInvalidTypesLinked(Realm realm) {
    realm.beginTransaction();
    AllJavaTypes notEmpty = new AllJavaTypes();
    notEmpty.setFieldBinary(new byte[] { 1, 2, 3 });
    notEmpty.setFieldObject(notEmpty);
    notEmpty.setFieldList(new RealmList<AllJavaTypes>(notEmpty));
    realm.copyToRealm(notEmpty);
    realm.commitTransaction();
}
Also used : AllJavaTypes(io.realm.entities.AllJavaTypes)

Example 68 with AllJavaTypes

use of io.realm.entities.AllJavaTypes in project realm-java by realm.

the class BulkInsertTests method insert_duplicatedPrimaryKeyFails.

@Test
public void insert_duplicatedPrimaryKeyFails() {
    // Single object with 2 references to two objects with the same ID
    AllJavaTypes obj = new AllJavaTypes(2);
    obj.setFieldList(new RealmList<AllJavaTypes>(new AllJavaTypes(1), new AllJavaTypes(1)));
    realm.beginTransaction();
    try {
        realm.insert(obj);
        fail();
    } catch (RealmPrimaryKeyConstraintException ignored) {
    } finally {
        realm.cancelTransaction();
    }
    // Two objects with the same ID in a list
    realm.beginTransaction();
    try {
        realm.insert(Arrays.asList(new AllJavaTypes(1), new AllJavaTypes(1)));
        fail();
    } catch (RealmPrimaryKeyConstraintException ignored) {
    } finally {
        realm.cancelTransaction();
    }
}
Also used : RealmPrimaryKeyConstraintException(io.realm.exceptions.RealmPrimaryKeyConstraintException) AllJavaTypes(io.realm.entities.AllJavaTypes) Test(org.junit.Test)

Example 69 with AllJavaTypes

use of io.realm.entities.AllJavaTypes in project realm-java by realm.

the class BulkInsertTests method insertOrUpdate_linkingManagedToUnmanagedObject.

@Test
public void insertOrUpdate_linkingManagedToUnmanagedObject() {
    realm.beginTransaction();
    AllJavaTypes managedAllJavaTypes = realm.createObject(AllJavaTypes.class, 42);
    realm.commitTransaction();
    AllJavaTypes unmanagedObject = new AllJavaTypes(8);
    //Linking managed object to unmanaged object
    unmanagedObject.setFieldObject(managedAllJavaTypes);
    realm.beginTransaction();
    realm.insertOrUpdate(unmanagedObject);
    realm.commitTransaction();
    AllJavaTypes first = realm.where(AllJavaTypes.class).equalTo(AllJavaTypes.FIELD_ID, 8).findFirst();
    assertNotNull(first);
    assertEquals(8, first.getFieldId(), 0);
    assertNotNull(first.getFieldObject());
    assertEquals(42, first.getFieldObject().getFieldId());
    assertEquals(2, realm.where(AllJavaTypes.class).count());
}
Also used : AllJavaTypes(io.realm.entities.AllJavaTypes) Test(org.junit.Test)

Example 70 with AllJavaTypes

use of io.realm.entities.AllJavaTypes in project realm-java by realm.

the class LinkingObjectsUnmanagedTests method copyToAndFromRealm.

// Test round-trip
@Test
public void copyToAndFromRealm() {
    AllJavaTypes unmanagedChild = new AllJavaTypes(1);
    realm.beginTransaction();
    AllJavaTypes parent = realm.createObject(AllJavaTypes.class, 2);
    realm.commitTransaction();
    assertEquals(new AllJavaTypes().getObjectParents(), unmanagedChild.getObjectParents());
    realm.beginTransaction();
    AllJavaTypes child = realm.copyToRealm(unmanagedChild);
    parent.setFieldObject(child);
    realm.commitTransaction();
    RealmResults<AllJavaTypes> parents = child.getObjectParents();
    assertNotNull(parents);
    assertEquals(1, parents.size());
    assertEquals(parent, parents.first());
    unmanagedChild = realm.copyFromRealm(child);
    assertEquals(unmanagedChild.getFieldId(), 1);
    assertEquals(new AllJavaTypes().getObjectParents(), unmanagedChild.getObjectParents());
    RealmResults<AllJavaTypes> queryResults = realm.where(AllJavaTypes.class).equalTo("fieldId", 1).findAll();
    assertEquals(1, queryResults.size());
    child = queryResults.first();
    parents = child.getObjectParents();
    assertNotNull(parents);
    assertEquals(1, parents.size());
    assertEquals(parent, parents.first());
}
Also used : AllJavaTypes(io.realm.entities.AllJavaTypes) Test(org.junit.Test)

Aggregations

AllJavaTypes (io.realm.entities.AllJavaTypes)90 Test (org.junit.Test)78 UiThreadTest (android.support.test.annotation.UiThreadTest)24 RunTestInLooperThread (io.realm.rule.RunTestInLooperThread)10 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)6 Date (java.util.Date)5 RealmException (io.realm.exceptions.RealmException)4 Ignore (org.junit.Ignore)3 CountDownLatch (java.util.concurrent.CountDownLatch)2 ExecutionException (java.util.concurrent.ExecutionException)2 ExecutorService (java.util.concurrent.ExecutorService)2 ExpectedException (org.junit.rules.ExpectedException)2 Pair (android.util.Pair)1 CyclicType (io.realm.entities.CyclicType)1 Dog (io.realm.entities.Dog)1 NonLatinFieldNames (io.realm.entities.NonLatinFieldNames)1 PrimaryKeyAsString (io.realm.entities.PrimaryKeyAsString)1 RealmPrimaryKeyConstraintException (io.realm.exceptions.RealmPrimaryKeyConstraintException)1 RunInLooperThread (io.realm.rule.RunInLooperThread)1 Field (java.lang.reflect.Field)1