Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MLIBZ-2647 Self-reference data model with an array #203

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -202,6 +202,33 @@ void finish() {
}
}

private static class DefaultKinveyClientArrayCallback implements KinveyClientCallback<PersonArray> {

private CountDownLatch latch;
PersonArray result;
Throwable error;

DefaultKinveyClientArrayCallback(CountDownLatch latch) {
this.latch = latch;
}

@Override
public void onSuccess(PersonArray result) {
this.result = result;
finish();
}

@Override
public void onFailure(Throwable error) {
this.error = error;
finish();
}

void finish() {
latch.countDown();
}
}

private static class DefaultKinveySyncCallback implements KinveySyncCallback {

private CountDownLatch latch;
Expand Down Expand Up @@ -697,6 +724,32 @@ public void run() {
return callback;
}

@Test
public void testUpdatePersonArray() throws InterruptedException, IOException {
DataStore<PersonArray> store = DataStore.collection(PersonArray.COLLECTION, PersonArray.class, StoreType.SYNC, client);
client.getSyncManager().clear(PersonArray.COLLECTION);
PersonArray person = new PersonArray();
DefaultKinveyClientArrayCallback callback = savePersonArray(store, person);
assertNotNull(callback.result);
KinveyReadResponse<PersonArray> callbackFind = store.find();
assertTrue(callbackFind.getResult().size() > 0);
}

private DefaultKinveyClientArrayCallback savePersonArray(final DataStore<PersonArray> store, final PersonArray person) throws InterruptedException {
final CountDownLatch latch = new CountDownLatch(1);
final DefaultKinveyClientArrayCallback callback = new DefaultKinveyClientArrayCallback(latch);
LooperThread looperThread = new LooperThread(new Runnable() {
@Override
public void run() {
store.save(person, callback);
}
});
looperThread.start();
latch.await();
looperThread.mHandler.sendMessage(new Message());
return callback;
}

@Test
public void testSaveItemLongCollectionNameLocally() throws InterruptedException {
DataStore<Person> store = DataStore.collection(Person.LONG_NAME, Person.class, StoreType.SYNC, client);
Expand Down
Expand Up @@ -380,7 +380,7 @@ private static RealmObjectSchema createSchemeFromClass(String name, DynamicRealm
if (fieldInfo == null){
continue;
}
if (fieldInfo.getType().isArray() || Collection.class.isAssignableFrom(fieldInfo.getType())){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yuliya-guseva Can you explain more why this condition was causing an exception?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This class works with Realm tables and contains a complicated logic.
This part of the condition was logically incorrect because we go into this part of the code only if the field is an array and the type of the array inherits GenericJson. In this case, the RealmObjectSchema.addRealmListField method is called and the field is created in the table in the form of ArrayList. But for the array this method should not be called.

if (Collection.class.isAssignableFrom(fieldInfo.getType())){
Class underlying = getUnderlying(f);
if (underlying != null && GenericJson.class.isAssignableFrom(underlying)){
if (!underlying.getSimpleName().equalsIgnoreCase(clazz.getSimpleName())) {
Expand Down