diff options
Diffstat (limited to 'tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibraryJoinTableNamingAction.java')
-rwxr-xr-x | tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibraryJoinTableNamingAction.java | 123 |
1 files changed, 123 insertions, 0 deletions
diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibraryJoinTableNamingAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibraryJoinTableNamingAction.java new file mode 100755 index 000000000..2d744b3fa --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibraryJoinTableNamingAction.java @@ -0,0 +1,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); + } + } + } + } +} |