-
Notifications
You must be signed in to change notification settings - Fork 872
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixed bug on translation of nested collections, issue #7548
- Loading branch information
Showing
4 changed files
with
156 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
object/src/test/java/com/orientechnologies/orient/object/db/NestedCollectionsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
|
||
} |
70 changes: 70 additions & 0 deletions
70
object/src/test/java/com/orientechnologies/orient/object/db/entity/NestedContainer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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("============================"); | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
object/src/test/java/com/orientechnologies/orient/object/db/entity/NestedContent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |