use of io.realm.internal.RealmProxyMediator in project realm-java by realm.
the class RealmProxyMediatorTests method validateTable_noDuplicateIndexInIndicesMap.
@Test
public void validateTable_noDuplicateIndexInIndicesMap() {
RealmProxyMediator mediator = realm.getConfiguration().getSchemaMediator();
CatRealmProxy.CatColumnInfo columnInfo;
columnInfo = (CatRealmProxy.CatColumnInfo) mediator.validateTable(Cat.class, realm.sharedRealm, false);
final Set<Long> indexSet = new HashSet<Long>();
int indexCount = 0;
// Gets index for each field and then put into set.
for (Field field : Cat.class.getDeclaredFields()) {
if (Modifier.isStatic(field.getModifiers())) {
continue;
}
indexSet.add(columnInfo.getIndicesMap().get(field.getName()));
indexCount++;
}
assertEquals("if no duplicates, size of set equals to field count.", indexCount, indexSet.size());
}
use of io.realm.internal.RealmProxyMediator in project realm-java by realm.
the class CompositeMediator method insertOrUpdate.
@Override
public void insertOrUpdate(Realm realm, Collection<? extends RealmModel> objects) {
RealmProxyMediator mediator = getMediator(Util.getOriginalModelClass(Util.getOriginalModelClass(objects.iterator().next().getClass())));
mediator.insertOrUpdate(realm, objects);
}
use of io.realm.internal.RealmProxyMediator in project realm-java by realm.
the class CompositeMediator method insert.
@Override
public void insert(Realm realm, Collection<? extends RealmModel> objects) {
RealmProxyMediator mediator = getMediator(Util.getOriginalModelClass(Util.getOriginalModelClass(objects.iterator().next().getClass())));
mediator.insert(realm, objects);
}
use of io.realm.internal.RealmProxyMediator in project realm-java by realm.
the class CompositeMediator method insert.
@Override
public void insert(Realm realm, RealmModel object, Map<RealmModel, Long> cache) {
RealmProxyMediator mediator = getMediator(Util.getOriginalModelClass(object.getClass()));
mediator.insert(realm, object, cache);
}
use of io.realm.internal.RealmProxyMediator in project realm-java by realm.
the class Realm method initializeRealm.
private static void initializeRealm(Realm realm) {
// Everything in this method needs to be behind a transaction lock to prevent multi-process interaction while
// the Realm is initialized.
boolean commitChanges = false;
try {
realm.beginTransaction();
long currentVersion = realm.getVersion();
boolean unversioned = currentVersion == UNVERSIONED;
commitChanges = unversioned;
if (unversioned) {
realm.setVersion(realm.configuration.getSchemaVersion());
}
final RealmProxyMediator mediator = realm.configuration.getSchemaMediator();
final Set<Class<? extends RealmModel>> modelClasses = mediator.getModelClasses();
final Map<Class<? extends RealmModel>, ColumnInfo> columnInfoMap = new HashMap<>(modelClasses.size());
if (unversioned) {
// Create all of the tables.
for (Class<? extends RealmModel> modelClass : modelClasses) {
mediator.createTable(modelClass, realm.sharedRealm);
}
}
for (Class<? extends RealmModel> modelClass : modelClasses) {
// Now that they have all been created, validate them.
columnInfoMap.put(modelClass, mediator.validateTable(modelClass, realm.sharedRealm, false));
}
realm.schema.columnIndices = new ColumnIndices((unversioned) ? realm.configuration.getSchemaVersion() : currentVersion, columnInfoMap);
if (unversioned) {
final Transaction transaction = realm.configuration.getInitialDataTransaction();
if (transaction != null) {
transaction.execute(realm);
}
}
} catch (Exception e) {
commitChanges = false;
throw e;
} finally {
if (commitChanges) {
realm.commitTransaction();
} else {
realm.cancelTransaction();
}
}
}
Aggregations