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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
|
/**
* <copyright>
*
* Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others
* 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:
* Martin Taal
* </copyright>
*
* $Id: LibraryJoinTableNamingAction.java,v 1.5 2008/02/28 07:08:14 mtaal Exp $
*/
package org.eclipse.emf.teneo.test.emf.sample;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Properties;
import org.eclipse.emf.teneo.PersistenceOptions;
import org.eclipse.emf.teneo.samples.emf.sample.library.Book;
import org.eclipse.emf.teneo.samples.emf.sample.library.BookCategory;
import org.eclipse.emf.teneo.samples.emf.sample.library.Library;
import org.eclipse.emf.teneo.samples.emf.sample.library.LibraryFactory;
import org.eclipse.emf.teneo.samples.emf.sample.library.LibraryPackage;
import org.eclipse.emf.teneo.samples.emf.sample.library.Writer;
import org.eclipse.emf.teneo.test.AbstractTestAction;
import org.eclipse.emf.teneo.test.StoreTestException;
import org.eclipse.emf.teneo.test.stores.TestStore;
/**
* Tests the library example of emf/xsd.
*
* @author <a href="mailto:mtaal@elver.org">Martin Taal</a>
* @version $Revision: 1.5 $
*/
public class LibraryJoinTableNamingAction extends AbstractTestAction {
/**
* Constructor for ClassHierarchyParsing.
*
* @param arg0
*/
public LibraryJoinTableNamingAction() {
super(LibraryPackage.eINSTANCE);
}
@Override
public Properties getExtraConfigurationProperties() {
final Properties props = new Properties();
props.setProperty(PersistenceOptions.DEFAULT_CACHE_STRATEGY, "READ_WRITE");
props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONTAINED_ASSOCIATIONS, "true");
props.setProperty(PersistenceOptions.JOIN_TABLE_NAMING_STRATEGY, "unique");
props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
props.setProperty(PersistenceOptions.SQL_CASE_STRATEGY, "uppercase");
return props;
}
/** Creates an item, an address and links them to a po. */
@Override
@SuppressWarnings("unchecked")
public void doAction(TestStore store) {
final LibraryFactory factory = LibraryFactory.eINSTANCE;
// create a book, writer and library
{
store.beginTransaction();
final Writer writer = factory.createWriter();
writer.setName("JRR Tolkien");
final Book book = factory.createBook();
book.setAuthor(writer);
book.setPages(5);
book.setTitle("The Hobbit");
book.setCategory(BookCategory.SCIENCE_FICTION_LITERAL);
final Book book2 = factory.createBook();
book2.setAuthor(writer);
book2.setPages(5);
book2.setTitle("The fellowship of the ring");
book2.setCategory(BookCategory.SCIENCE_FICTION_LITERAL);
final Library library = factory.createLibrary();
library.getBooks().add(book);
library.setName("Science Fiction Library");
library.getBooks().add(book2);
library.getWriters().add(writer);
store.store(library);
store.commitTransaction();
assertEquals(2, writer.getBooks().size());
}
if (true) {
Connection conn = null;
Statement stmt = null;
try {
conn = store.getConnection();
stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM WRITER_BOOKS");
assertTrue(rs.next());
} catch (SQLException s) {
throw new StoreTestException("SQL Exception", s);
} finally {
try {
if (stmt != null) {
stmt.close();
}
if (conn != null) {
conn.close();
}
} catch (SQLException s) {
throw new StoreTestException("SQL Exception", s);
}
}
}
}
}
|