Skip to content

Commit

Permalink
fixed bug on translation of nested collections, issue #7548
Browse files Browse the repository at this point in the history
  • Loading branch information
tglman committed Jul 17, 2017
1 parent 9fad56c commit 013e0c7
Show file tree
Hide file tree
Showing 4 changed files with 156 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1382,11 +1382,11 @@ else if (firstValue instanceof Map)

if (iMultiValue instanceof Set<?>) {
for (Object o : sourceValues) {
((Set<Object>) result).add(typeToStream(o, linkedType, db, null));
((Set<Object>) result).add(typeToStream(o, linkedType, db, iRecord));
}
} else if (iMultiValue instanceof List<?>) {
for (int i = 0; i < sourceValues.size(); i++) {
((List<Object>) result).add(typeToStream(((List<?>) sourceValues).get(i), linkedType, db, null));
((List<Object>) result).add(typeToStream(((List<?>) sourceValues).get(i), linkedType, db, iRecord));
}
} else {
if (iMultiValue instanceof OObjectLazyMap<?>) {
Expand All @@ -1399,7 +1399,7 @@ else if (iRecord != null && iType.equals(OType.EMBEDDEDMAP))
else
result = new ORecordLazyMap(iRecord);
for (Entry<Object, Object> entry : ((Map<Object, Object>) iMultiValue).entrySet()) {
((Map<Object, Object>) result).put(entry.getKey(), typeToStream(entry.getValue(), linkedType, db, null));
((Map<Object, Object>) result).put(entry.getKey(), typeToStream(entry.getValue(), linkedType, db, iRecord));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.orientechnologies.orient.object.db;

import com.orientechnologies.orient.core.db.document.ODatabaseDocument;
import com.orientechnologies.orient.core.db.object.ODatabaseObject;
import com.orientechnologies.orient.object.db.entity.NestedContainer;
import com.orientechnologies.orient.object.db.entity.NestedContent;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

/**
* Created by tglman on 17/07/17.
*/
public class NestedCollectionsTest {

private ODatabaseObject database;

@Before
public void before() {
database = new OObjectDatabaseTx("memory:" + NestedCollectionsTest.class.getSimpleName());
database.create();
database.getEntityManager().registerEntityClass(NestedContainer.class);
database.getEntityManager().registerEntityClass(NestedContent.class);
}

@Test
public void testNestedCollections() {

NestedContainer container = new NestedContainer("first");
NestedContainer saved = database.save(container);

assertEquals(1, saved.getFoo().size());
assertEquals(3, saved.getFoo().get("key-1").size());
}

@After
public void after() {
database.drop();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* Copyright 2017 dominik.kopczynski.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.orientechnologies.orient.object.db.entity;

import java.util.ArrayList;
import java.util.HashMap;

/**
* @author dominik.kopczynski
*/
public class NestedContainer {
private String name;
HashMap<String, ArrayList<NestedContent>> foo = new HashMap<String, ArrayList<NestedContent>>();

public NestedContainer() {

}

public void setFoo(HashMap<String, ArrayList<NestedContent>> foo) {
this.foo = foo;
}

public HashMap<String, ArrayList<NestedContent>> getFoo() {
return foo;
}

public NestedContainer(String name) {
this.name = name;
ArrayList<NestedContent> al = new ArrayList<NestedContent>();
NestedContent dd1 = new NestedContent("Jack / " + name);
NestedContent dd2 = new NestedContent("Maria / " + name);
NestedContent dd3 = new NestedContent("Micheal / " + name);
al.add(dd1);
al.add(dd2);
al.add(dd3);

foo.put("key-1", al);
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public void info() {
System.out.println("Name: " + getName());
for (String key : getFoo().keySet()) {
for (NestedContent cc2 : getFoo().get(key)) {
System.out.println(key + " " + cc2.getName());
}
}
System.out.println("============================");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright 2017 dominik.kopczynski.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.orientechnologies.orient.object.db.entity;

/**
* @author dominik.kopczynski
*/
public class NestedContent {
private String name;

public NestedContent() {

}

public NestedContent(String name) {
this.name = name;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}
}

0 comments on commit 013e0c7

Please sign in to comment.