blob: 1e69befc7e02680fc7245174cb68c14d0fbc1338 (
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
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
|
/**
* <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: OverrideSecondaryAction.java,v 1.2 2010/02/06 18:25:53 mtaal Exp $
*/
package org.eclipse.emf.teneo.test.emf.annotations;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import org.eclipse.emf.teneo.samples.emf.annotations.attroverridesecondarytable.Address;
import org.eclipse.emf.teneo.samples.emf.annotations.attroverridesecondarytable.AttroverridesecondarytableFactory;
import org.eclipse.emf.teneo.samples.emf.annotations.attroverridesecondarytable.AttroverridesecondarytablePackage;
import org.eclipse.emf.teneo.samples.emf.annotations.attroverridesecondarytable.Country;
import org.eclipse.emf.teneo.samples.emf.annotations.attroverridesecondarytable.Employee;
import org.eclipse.emf.teneo.samples.emf.annotations.attroverridesecondarytable.NonEmployee;
import org.eclipse.emf.teneo.test.AbstractTestAction;
import org.eclipse.emf.teneo.test.stores.TestStore;
/**
* See bugzilla 239800
*
* @author mtaal@elver.org
*/
public class OverrideSecondaryAction extends AbstractTestAction {
private static final String VERIFICATION_QUERY1 = "select count(*) from secondary_table where emp_num is not null";
private static final String VERIFICATION_QUERY2 =
"select count(*) from secondary_table where other_name is not null";
public OverrideSecondaryAction() {
super(AttroverridesecondarytablePackage.eINSTANCE);
}
@Override
public void doAction(TestStore store) {
{
store.beginTransaction();
final AttroverridesecondarytableFactory factory = AttroverridesecondarytableFactory.eINSTANCE;
final Employee e = factory.createEmployee();
String prefix = "abc";
e.setName(prefix + "_name");
e.setAddress(createAddress(prefix));
e.setEmployeeNumber(prefix);
store.store(e);
final NonEmployee ne = factory.createNonEmployee();
prefix = "def";
ne.setName(prefix + "_name");
ne.setAddress(createAddress(prefix));
store.store(ne);
store.commitTransaction();
}
{
store.beginTransaction();
final Employee e = store.getObject(Employee.class);
assertTrue(e.getName().startsWith("abc"));
assertTrue(e.getAddress().getCity().startsWith("abc"));
final NonEmployee ne = store.getObject(NonEmployee.class);
assertTrue(ne.getName().startsWith("def"));
assertTrue(ne.getAddress().getStreet().startsWith("def"));
store.commitTransaction();
}
testTable(store);
}
private Address createAddress(String prefix) {
final AttroverridesecondarytableFactory factory = AttroverridesecondarytableFactory.eINSTANCE;
final Address address = factory.createAddress();
address.setName(prefix + "_name");
address.setStreet(prefix + "_street");
address.setCity(prefix + "_city");
final Country c = factory.createCountry();
c.setName(prefix);
address.setCountry(c);
return address;
}
private void testTable(TestStore store) {
final Connection conn = store.getConnection();
Statement stmt = null;
ResultSet rs = null;
try {
stmt = conn.createStatement();
rs = stmt.executeQuery(VERIFICATION_QUERY1);
rs.next();
assertEquals(1, rs.getInt(1));
rs.close();
rs = stmt.executeQuery(VERIFICATION_QUERY2);
rs.next();
assertEquals(1, rs.getInt(1));
rs.close();
} catch (final SQLException e) {
assertTrue(e.getMessage(), false);
} finally {
try {
if (stmt != null) {
stmt.close();
}
} catch (final SQLException e) {
}
try {
if (rs != null) {
rs.close();
}
} catch (final SQLException e) {
}
}
}
}
|