blob: 6660d78a824277bec407d128ded9e75d5edc437f (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
/*******************************************************************************
* Copyright (c) 2008 Oracle and Geensys.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Oracle and Geensys - initial API and implementation
*******************************************************************************/
package org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests.resource;
import java.io.IOException;
import java.util.Collections;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.emf.teneo.eclipselink.examples.library.Address;
import org.eclipse.emf.teneo.eclipselink.examples.library.Book;
import org.eclipse.emf.teneo.eclipselink.examples.library.Library;
import org.eclipse.emf.teneo.eclipselink.examples.library.LibraryFactory;
import org.eclipse.emf.teneo.eclipselink.examples.library.Translator;
import org.eclipse.emf.teneo.eclipselink.examples.library.Writer;
import org.eclipse.emf.teneo.eclipselink.resource.EclipseLinkURIUtil;
public class CreateSampleLibrariesWithEclipseLinkResourceTest extends BasicEclipseLinkTest {
private URI uri;
private Resource resource;
private Library library1, library2, library3;
public void testEclipseLinkResource() throws IOException {
// create and populate first library model instance
library1 = LibraryFactory.eINSTANCE.createLibrary();
library1.setName("EclipseCon Library");
Writer writer1 = LibraryFactory.eINSTANCE.createWriter();
writer1.setName("The True Eclipse Expert");
library1.getWriters().add(writer1);
Address address1 = LibraryFactory.eINSTANCE.createAddress();
address1.setTown("Sin City");
writer1.setAddress(address1);
Book book1 = LibraryFactory.eINSTANCE.createBook();
book1.setTitle("Eclipse Tips & Tricks");
library1.getBooks().put(book1.getTitle(), book1);
Translator translator1 = LibraryFactory.eINSTANCE.createTranslator();
translator1.setName("Mr. Babelfish");
book1.setTranslator(translator1);
Address address2 = LibraryFactory.eINSTANCE.createAddress();
address2.setTown("Foo City");
// TODO add this relationship to mapping
translator1.setAddress(address2);
// create and populate second library model instance
library2 = LibraryFactory.eINSTANCE.createLibrary();
library2.setName("IBM Library");
// create and populate third library model instance
library3 = LibraryFactory.eINSTANCE.createLibrary();
library3.setName("ORACLE Library");
// create EclipseLink URI for saving/loading all library models in/from
// database
uri = EclipseLinkURIUtil.createEclipseLinkURI(TEST_PERSISTENCE_UNIT_NAME, Library.class.getName());
// save all library model instances in database
ResourceSet resourceSet = new ResourceSetImpl();
resourceSet.getLoadOptions().putAll(getTestPersistenceUnitProperties());
resource = resourceSet.createResource(uri);
resource.getContents().add(library1);
resource.getContents().add(library2);
resource.getContents().add(library3);
resource.save(Collections.EMPTY_MAP);
// unload resource of library model instances
resource.unload();
}
}
|