Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormtaal2007-01-30 05:51:50 -0500
committermtaal2007-01-30 05:51:50 -0500
commit2879ac71a8598d21a6fb0027b048df3933224a0e (patch)
treedf79c8f4cfc4c8e4d63daca17ad0e08f6f06d820
parenta70014ec327c62798631a145a36505cd90080fc9 (diff)
downloadorg.eclipse.emf.teneo-2879ac71a8598d21a6fb0027b048df3933224a0e.tar.gz
org.eclipse.emf.teneo-2879ac71a8598d21a6fb0027b048df3933224a0e.tar.xz
org.eclipse.emf.teneo-2879ac71a8598d21a6fb0027b048df3933224a0e.zip
Re-organized imports in various locations
-rw-r--r--tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/InheritanceAnnotationTablePerClassAction.java233
-rw-r--r--tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/InheritanceAnnotationTablePerClassAction.persistence.xml32
-rw-r--r--tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/GMFNotationAction.java6
-rw-r--r--tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibraryResourceAction.java12
-rw-r--r--tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LobjAction.java5
5 files changed, 271 insertions, 17 deletions
diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/InheritanceAnnotationTablePerClassAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/InheritanceAnnotationTablePerClassAction.java
new file mode 100644
index 000000000..f3936070f
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/InheritanceAnnotationTablePerClassAction.java
@@ -0,0 +1,233 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2006 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: InheritanceAnnotationTablePerClassAction.java,v 1.1 2007/01/30 10:51:50 mtaal Exp $
+ */
+
+package org.eclipse.emf.teneo.test.emf.annotations;
+
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.emf.teneo.annotations.pannotation.InheritanceType;
+import org.eclipse.emf.teneo.samples.emf.annotations.inheritancemapping.Address;
+import org.eclipse.emf.teneo.samples.emf.annotations.inheritancemapping.ContentList;
+import org.eclipse.emf.teneo.samples.emf.annotations.inheritancemapping.DistrictUKAddress;
+import org.eclipse.emf.teneo.samples.emf.annotations.inheritancemapping.InheritancemappingFactory;
+import org.eclipse.emf.teneo.samples.emf.annotations.inheritancemapping.InheritancemappingPackage;
+import org.eclipse.emf.teneo.samples.emf.annotations.inheritancemapping.InternationalPrice;
+import org.eclipse.emf.teneo.samples.emf.annotations.inheritancemapping.Price;
+import org.eclipse.emf.teneo.samples.emf.annotations.inheritancemapping.UKAddress;
+import org.eclipse.emf.teneo.samples.emf.annotations.inheritancemapping.USAddress;
+import org.eclipse.emf.teneo.samples.emf.annotations.inheritancemapping.USState;
+import org.eclipse.emf.teneo.samples.emf.annotations.inheritancemapping.impl.DistrictUKAddressImpl;
+import org.eclipse.emf.teneo.samples.emf.annotations.inheritancemapping.impl.InternationalPriceImpl;
+import org.eclipse.emf.teneo.samples.emf.annotations.inheritancemapping.impl.UKAddressImpl;
+import org.eclipse.emf.teneo.samples.emf.annotations.inheritancemapping.impl.USAddressImpl;
+import org.eclipse.emf.teneo.test.AbstractTestAction;
+import org.eclipse.emf.teneo.test.StoreTestException;
+import org.eclipse.emf.teneo.test.stores.TestStore;
+
+/**
+ * Tests annotations to direct the inheritance mapping.
+ *
+ * @author <a href="mailto:mtaal@elver.org">Martin Taal</a>
+ * @version $Revision: 1.1 $
+ */
+public class InheritanceAnnotationTablePerClassAction extends AbstractTestAction {
+
+ /** UGLY, at least ensure that at least one of the three tests is run */
+ private static int ignored_tests = 0;
+
+ /**
+ * Constructor for ClassHierarchyParsing.
+ *
+ * @param arg0
+ */
+ public InheritanceAnnotationTablePerClassAction() {
+ super(InheritancemappingPackage.eINSTANCE);
+ }
+
+ /** Creates simple types and tests against */
+ public void doAction(TestStore store) {
+ if (store.isInheritanceStrategy(InternationalPriceImpl.class.getName(),
+ InheritanceType.SINGLE_TABLE_LITERAL)) {
+ ignored_tests++;
+ assertTrue(ignored_tests < 3);
+ return; // not the correct test, should only run xml tests, need to change the whole test framework to do this
+ }
+
+ // test a simple type
+ final InheritancemappingFactory factory = InheritancemappingFactory.eINSTANCE;
+ {
+ store.beginTransaction();
+ USAddress usaddress = factory.createUSAddress();
+ usaddress.setName("Montgomery");
+ usaddress.setCity("Montgomery");
+ usaddress.setState(USState.AL_LITERAL);
+ usaddress.setZip(new BigInteger("36101"));
+ usaddress.setStreet("Montgomery street");
+ store.store(usaddress);
+
+ // test nullable fields
+ USAddress emptyaddress = factory.createUSAddress();
+ emptyaddress.setName("empty");
+ emptyaddress.setCity("empty");
+ emptyaddress.setStreet("empty");
+ if (emptyaddress.isSetState()) {
+ emptyaddress.unsetState();
+ }
+ if (emptyaddress.isSetZip()) {
+ emptyaddress.unsetZip();
+ }
+
+ store.store(usaddress);
+ store.store(emptyaddress);
+
+ // create a uk address and a uk district address
+ UKAddress ukaddress = factory.createUKAddress();
+ ukaddress.setCity("London");
+ ukaddress.setStreet("Downingstreet 10");
+ ukaddress.setName("Primeminister");
+ ukaddress.setPostcode("0000");
+ store.store(ukaddress);
+
+ DistrictUKAddress districtaddress = factory.createDistrictUKAddress();
+ districtaddress.setCity("district");
+ districtaddress.setDistrict("district1");
+ districtaddress.setName("My districtaddress");
+ districtaddress.setPostcode("postcode1");
+ districtaddress.setStreet("street1");
+ store.store(districtaddress);
+ ContentList contentlist = factory.createContentList();
+ contentlist.setName("testme");
+ contentlist.getAddress().add(usaddress);
+ contentlist.getAddress().add(emptyaddress);
+ contentlist.getAddress().add(ukaddress);
+ contentlist.getAddress().add(districtaddress);
+ store.store(contentlist);
+
+ InternationalPrice intprice = factory.createInternationalPrice();
+ intprice.setName("euro");
+ intprice.setCurrency("EUR");
+ intprice.setValue(new BigDecimal("100.50"));
+
+
+ Price price = factory.createPrice();
+ price.setName("mycurrency");
+ price.setValue(new BigDecimal("99.30"));
+ store.store(price);
+ store.store(intprice);
+
+ store.store(contentlist);
+ store.commitTransaction();
+ }
+
+ {
+ store.beginTransaction();
+ ContentList contentList = (ContentList) store.getObject(ContentList.class);
+ checkAddressList(contentList.getAddress().iterator());
+
+ List prices = store.getObjects(Price.class);
+ assertEquals(2, prices.size());
+ InternationalPrice ip;
+ Price p;
+ if (prices.get(0) instanceof InternationalPrice) {
+ ip = (InternationalPrice)prices.get(0);
+ p = (Price)prices.get(1);
+ } else {
+ ip = (InternationalPrice)prices.get(1);
+ p = (Price)prices.get(0);
+ }
+ assertTrue(ip.getName().compareTo("euro") == 0);
+ assertTrue(p.getName().compareTo("mycurrency") == 0);
+
+ store.commitTransaction();
+ }
+
+ // eventhough at global level one inheritance strategy is used this should differ for individual
+ // class hierarchies as enforced by the annotations
+ assertTrue(store.isInheritanceStrategy(InternationalPriceImpl.class.getName(),
+ InheritanceType.TABLE_PER_CLASS_LITERAL));
+ assertTrue(store.isInheritanceStrategy(UKAddressImpl.class.getName(), InheritanceType.JOINED_LITERAL));
+ assertTrue(store.isInheritanceStrategy(USAddressImpl.class.getName(), InheritanceType.JOINED_LITERAL));
+ assertTrue(store.isInheritanceStrategy(DistrictUKAddressImpl.class.getName(), InheritanceType.JOINED_LITERAL));
+
+ // do some sql queries to check if the name column is present in the subclass
+ Connection conn = null;
+ Statement stmt = null;
+ try {
+ try {
+ conn = store.getConnection();
+ stmt = conn.createStatement();
+ ResultSet rs = stmt.executeQuery("select * from internationalprice where name='euro'");
+ int cnt = 0;
+ while (rs.next()) {
+ cnt++;
+ }
+ rs.close();
+
+ assertEquals(1, cnt);
+ rs = stmt.executeQuery("select * from myprice where name='mycurrency'");
+ cnt = 0;
+ while (rs.next()) {
+ cnt++;
+ }
+ rs.close();
+ assertEquals(1, cnt);
+ } finally {
+ if (stmt != null) stmt.close();
+ if (conn != null) conn.close();
+ }
+ } catch (SQLException e) {
+ throw new StoreTestException("Sql exception when retrieving objects based on discriminator values", e);
+ }
+ }
+
+ /** Checks that the address types occur in the passed list */
+ private void checkAddressList(Iterator it) {
+ int cntus = 0;
+ int cntuk = 0;
+ int cntdistrict = 0;
+ while (it.hasNext()) {
+ Address address = (Address) it.next();
+ if (address instanceof DistrictUKAddress) {
+ cntdistrict++;
+ } else if (address instanceof UKAddress) {
+ cntuk++;
+ if (address.getName().compareTo("Primeminister") == 0) {
+ assertTrue(address instanceof UKAddress);
+ }
+ } else if (address instanceof USAddress) {
+ cntus++;
+
+ if (address.getName().compareTo("empty") == 0) {
+ assertFalse(((USAddress) address).isSetState());
+ assertFalse(((USAddress) address).isSetZip());
+ } else {
+ assertTrue(((USAddress) address).isSetState());
+ assertTrue(((USAddress) address).isSetZip());
+ }
+ }
+ }
+ assertTrue(cntus == 2);
+ assertTrue(cntuk == 1);
+ assertTrue(cntdistrict == 1);
+ }
+} \ No newline at end of file
diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/InheritanceAnnotationTablePerClassAction.persistence.xml b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/InheritanceAnnotationTablePerClassAction.persistence.xml
new file mode 100644
index 000000000..01451cbe4
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/InheritanceAnnotationTablePerClassAction.persistence.xml
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="utf-8"?>
+<persistence-mapping xmlns="http://www.eclipse.org/emft/teneo"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+
+ <!-- Template for TestAction persistence mapping. -->
+
+ <epackage namespace-uri="http://www.eclipse.org/emf/teneo/samples/emf/annotations/inheritancemapping">
+
+ <eclass name="ContentList">
+ <property name="name">
+ <id />
+ </property>
+ </eclass>
+
+ <eclass name="Price">
+ <table name="myprice" />
+ <inheritance>TABLE_PER_CLASS</inheritance>
+ <property name="name">
+ <id />
+ </property>
+ </eclass>
+
+ <eclass name="Address">
+ <inheritance>JOINED</inheritance>
+ <property name="name">
+ <id />
+ </property>
+ </eclass>
+
+ </epackage>
+
+</persistence-mapping> \ No newline at end of file
diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/GMFNotationAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/GMFNotationAction.java
index bf4097265..99bb36426 100644
--- a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/GMFNotationAction.java
+++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/GMFNotationAction.java
@@ -11,7 +11,7 @@
* Martin Taal
* </copyright>
*
- * $Id: GMFNotationAction.java,v 1.2 2006/11/23 06:12:19 mtaal Exp $
+ * $Id: GMFNotationAction.java,v 1.3 2007/01/30 10:51:50 mtaal Exp $
*/
package org.eclipse.emf.teneo.test.emf.sample;
@@ -28,9 +28,7 @@ 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.ecore.xmi.XMIResource;
-import org.eclipse.emf.ecore.xmi.XMLResource;
import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
-import org.eclipse.emf.teneo.PersistenceOptions;
import org.eclipse.emf.teneo.test.AbstractTestAction;
import org.eclipse.emf.teneo.test.StoreTestException;
import org.eclipse.emf.teneo.test.stores.TestStore;
@@ -41,7 +39,7 @@ import org.example.mindmap.MindmapPackage;
* Tests persisting of gmf diagram.
*
* @author <a href="mailto:mtaal@elver.org">Martin Taal</a>
- * @version $Revision: 1.2 $
+ * @version $Revision: 1.3 $
*/
public class GMFNotationAction extends AbstractTestAction {
diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibraryResourceAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibraryResourceAction.java
index 1a4950e3e..e6ba49f39 100644
--- a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibraryResourceAction.java
+++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibraryResourceAction.java
@@ -11,22 +11,14 @@
* Martin Taal
* </copyright>
*
- * $Id: LibraryResourceAction.java,v 1.5 2006/11/14 10:56:13 mtaal Exp $
+ * $Id: LibraryResourceAction.java,v 1.6 2007/01/30 10:51:50 mtaal Exp $
*/
package org.eclipse.emf.teneo.test.emf.sample;
-import java.io.FileOutputStream;
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.ecore.util.EcoreUtil;
-import org.eclipse.emf.ecore.xmi.impl.XMLResourceFactoryImpl;
-import org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl;
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;
@@ -42,7 +34,7 @@ import org.eclipse.emf.teneo.test.stores.TestStore;
* of resources are handled in the Catalog example.
*
* @author <a href="mailto:mtaal@elver.org">Martin Taal</a>
- * @version $Revision: 1.5 $
+ * @version $Revision: 1.6 $
*/
public class LibraryResourceAction extends AbstractTestAction {
/**
diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LobjAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LobjAction.java
index 90baa36f4..7e73fff79 100644
--- a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LobjAction.java
+++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LobjAction.java
@@ -11,13 +11,12 @@
* Martin Taal
* </copyright>
*
- * $Id: LobjAction.java,v 1.1 2006/11/20 08:18:12 mtaal Exp $
+ * $Id: LobjAction.java,v 1.2 2007/01/30 10:51:50 mtaal Exp $
*/
package org.eclipse.emf.teneo.test.emf.sample;
import java.io.IOException;
-import java.net.URL;
import java.util.Collections;
import java.util.Iterator;
@@ -37,7 +36,7 @@ import org.eclipse.emf.teneo.test.stores.TestStore;
* Tests the capa, detach and update
*
* @author <a href="mailto:mtaal@elver.org">Martin Taal</a>
- * @version $Revision: 1.1 $
+ * @version $Revision: 1.2 $
*/
public class LobjAction extends AbstractTestAction {

Back to the top