Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 4c6f4a9c5bdd779de996eedc378fefd5623a6b52 (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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/**
 * <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: MappedSuperClassAction.java,v 1.8 2008/04/06 13:44:01 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 java.util.Properties;

import org.eclipse.emf.teneo.PersistenceOptions;
import org.eclipse.emf.teneo.samples.emf.annotations.mappedsuperclass.MappedsuperclassFactory;
import org.eclipse.emf.teneo.samples.emf.annotations.mappedsuperclass.MappedsuperclassPackage;
import org.eclipse.emf.teneo.samples.emf.annotations.mappedsuperclass.SpecificDocument;
import org.eclipse.emf.teneo.test.AbstractTestAction;
import org.eclipse.emf.teneo.test.StoreTestException;
import org.eclipse.emf.teneo.test.stores.TestStore;

/**
 * Testcase
 * 
 * @author <a href="mailto:mtaal@elver.org">Martin Taal</a>
 * @version $Revision: 1.8 $
 */
public class MappedSuperClassAction extends AbstractTestAction {
	/**
	 * Constructor
	 */
	public MappedSuperClassAction() {
		super(MappedsuperclassPackage.eINSTANCE);
	}

	@Override
	public Properties getExtraConfigurationProperties() {
		final Properties props = new Properties();
		props.setProperty(PersistenceOptions.DEFAULT_CACHE_STRATEGY, "READ_WRITE");
		props.setProperty(PersistenceOptions.SET_ENTITY_AUTOMATICALLY, "false");
		return props;
	}

	/** Creates an item, an address and links them to a po. */
	@Override
	public void doAction(TestStore store) {
		final MappedsuperclassFactory factory = MappedsuperclassFactory.eINSTANCE;
		{
			store.beginTransaction();
			final SpecificDocument sd = factory.createSpecificDocument();
			sd.setMyName("TEST IT");
			sd.setMyGenericInfo("GENERIC INFO");
			sd.setMySpecificInfo("SPECIFIC INFO");
			store.store(sd);
			store.commitTransaction();
		}

		// query for the specific table
		{
			Connection conn = null;
			try {
				conn = store.getConnection();
				final Statement stmt = conn.createStatement();
				// the following should not fail for all inheritance strategies
				final ResultSet rs = stmt.executeQuery("SELECT * FROM specificdocument");
				assertTrue(rs.next());
			} catch (final SQLException s) {
				throw new StoreTestException("SQLException while checking existence of table", s);
			} finally {
				try {
					if (conn != null) {
						conn.close();
					}
				} catch (final SQLException s) {
					throw new StoreTestException("SQLException while checking existence of table", s);
				}
			}
		}

		// query for the mapped superclass table, should always fail!
		{
			Connection conn = null;
			try {
				conn = store.getConnection();
				final Statement stmt = conn.createStatement();
				// the following should not fail for all inheritance strategies
				final ResultSet rs = stmt.executeQuery("SELECT * FROM document");
				assertTrue(rs != null); // dummy test to get rid of warning
				fail("The DOCUMENT table should not exist as it is a mapped superclass");
			} catch (final SQLException s) {
				// this is correct
			} catch (final Exception e) {
				throw new StoreTestException("Exception while checking existence of table", e);
			} finally {
				try {
					if (conn != null) {
						conn.close();
					}
				} catch (final SQLException s) {
					throw new StoreTestException("SQLException while checking existence of table", s);
				}
			}
		}

		{
			Connection conn = null;
			try {
				conn = store.getConnection();
				final Statement stmt = conn.createStatement();
				// the following should not fail for all inheritance strategies
				final ResultSet rs = stmt.executeQuery("SELECT * FROM parentdocument");
				assertTrue(rs != null); // dummy to get rid of warning
				fail("The PARENTDOCUMENT table should not exist as it is a mapped superclass");
			} catch (final SQLException s) {
				// this is correct
			} catch (final Exception e) {
				throw new StoreTestException("Exception while checking existence of table", e);
			} finally {
				try {
					if (conn != null) {
						conn.close();
					}
				} catch (final SQLException s) {
					throw new StoreTestException("SQLException while checking existence of table", s);
				}
			}
		}
		{
			store.beginTransaction();
			final SpecificDocument sd = store.getObject(SpecificDocument.class);
			assertEquals(sd.getMyName(), "TEST IT");
			assertEquals(sd.getMyGenericInfo(), "GENERIC INFO");
			assertEquals(sd.getMySpecificInfo(), "SPECIFIC INFO");
			store.commitTransaction();
		}

	}
}

Back to the top