cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject [2/2] cayenne git commit: partially fixing random ARTGROUP cleanup code..
Date Sun, 30 Nov 2014 16:29:24 GMT
partially fixing random ARTGROUP cleanup code..


Project: http://git-wip-us.apache.org/repos/asf/cayenne/repo
Commit: http://git-wip-us.apache.org/repos/asf/cayenne/commit/eefbc926
Tree: http://git-wip-us.apache.org/repos/asf/cayenne/tree/eefbc926
Diff: http://git-wip-us.apache.org/repos/asf/cayenne/diff/eefbc926

Branch: refs/heads/master
Commit: eefbc9264c869db5f04d073df908a5c640e1a1d8
Parents: 8094820
Author: aadamchik <aadamchik@apache.org>
Authored: Sun Nov 30 19:08:09 2014 +0300
Committer: aadamchik <aadamchik@apache.org>
Committed: Sun Nov 30 19:08:09 2014 +0300

----------------------------------------------------------------------
 .../CayenneDataObjectFlattenedRelIT.java        |   7 +
 .../access/DataContextDeleteRulesIT.java        | 424 +++++++++----------
 .../cayenne/access/DataContextOuterJoinsIT.java | 285 ++++++-------
 .../cayenne/access/FlattenedPrefetchIT.java     |   1 -
 .../cayenne/merge/AddColumnToModelIT.java       |  19 +-
 .../cayenne/merge/CreateTableToModelIT.java     | 144 +++----
 .../cayenne/merge/DropColumnToModelIT.java      | 407 +++++++++---------
 .../merge/DropRelationshipToModelIT.java        | 304 +++++++------
 .../cayenne/merge/DropTableToModelIT.java       | 131 +++---
 .../org/apache/cayenne/merge/MergeCase.java     | 349 +++++++--------
 .../apache/cayenne/merge/MergerFactoryIT.java   |  15 +-
 .../cayenne/merge/SetAllowNullToDbIT.java       |  64 ++-
 .../apache/cayenne/merge/SetNotNullToDbIT.java  |  57 ++-
 .../cayenne/merge/SetPrimaryKeyToDbIT.java      |  51 ++-
 .../apache/cayenne/merge/ValueForNullIT.java    | 182 ++++----
 .../cayenne/util/EntityMergeSupportIT.java      | 145 ++++---
 16 files changed, 1267 insertions(+), 1318 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cayenne/blob/eefbc926/cayenne-server/src/test/java/org/apache/cayenne/CayenneDataObjectFlattenedRelIT.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/CayenneDataObjectFlattenedRelIT.java b/cayenne-server/src/test/java/org/apache/cayenne/CayenneDataObjectFlattenedRelIT.java
index 9933066..6415505 100644
--- a/cayenne-server/src/test/java/org/apache/cayenne/CayenneDataObjectFlattenedRelIT.java
+++ b/cayenne-server/src/test/java/org/apache/cayenne/CayenneDataObjectFlattenedRelIT.java
@@ -36,6 +36,7 @@ import org.apache.cayenne.unit.di.server.UseServerRuntime;
 import org.junit.Before;
 import org.junit.Test;
 
+import java.sql.Types;
 import java.util.List;
 
 import static org.junit.Assert.assertEquals;
@@ -64,6 +65,12 @@ public class CayenneDataObjectFlattenedRelIT extends ServerCase {
     private TableHelper tArtGroup;
 
     private TableHelper tArtistGroup;
+    
+	@Override
+	public void cleanUpDB() throws Exception {
+		dbHelper.update("ARTGROUP").set("PARENT_GROUP_ID", null, Types.INTEGER).execute();
+		super.cleanUpDB();
+	}
 
     @Before
     public void setUp() throws Exception {

http://git-wip-us.apache.org/repos/asf/cayenne/blob/eefbc926/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextDeleteRulesIT.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextDeleteRulesIT.java b/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextDeleteRulesIT.java
index 7cf3c23..abc111b 100644
--- a/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextDeleteRulesIT.java
+++ b/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextDeleteRulesIT.java
@@ -19,6 +19,15 @@
 
 package org.apache.cayenne.access;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.sql.Types;
+import java.util.List;
+
 import org.apache.cayenne.PersistenceState;
 import org.apache.cayenne.di.Inject;
 import org.apache.cayenne.query.SQLTemplate;
@@ -33,226 +42,213 @@ import org.apache.cayenne.testdo.testmap.PaintingInfo;
 import org.apache.cayenne.unit.di.server.CayenneProjects;
 import org.apache.cayenne.unit.di.server.ServerCase;
 import org.apache.cayenne.unit.di.server.UseServerRuntime;
-import org.junit.Before;
 import org.junit.Test;
 
-import java.sql.Types;
-import java.util.List;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
 // TODO: redefine all test cases in terms of entities in "relationships" map
 // and merge this test case with DeleteRulesTst that inherits
 // from RelationshipTestCase.
 @UseServerRuntime(CayenneProjects.TESTMAP_PROJECT)
 public class DataContextDeleteRulesIT extends ServerCase {
 
-    @Inject
-    private DataContext context;
-
-    @Inject
-    private DBHelper dbHelper;
-
-    @Before
-    public void setUp() throws Exception {
-        dbHelper.update("ARTGROUP").set("PARENT_GROUP_ID", null, Types.INTEGER).execute();
-    }
-
-    @Test
-    public void testNullifyToOne() {
-        // ArtGroup toParentGroup
-        ArtGroup parentGroup = (ArtGroup) context.newObject("ArtGroup");
-        parentGroup.setName("Parent");
-
-        ArtGroup childGroup = (ArtGroup) context.newObject("ArtGroup");
-        childGroup.setName("Child");
-        parentGroup.addToChildGroupsArray(childGroup);
-
-        // Check to make sure that the relationships are both exactly correct
-        // before starting. We're not really testing this, but it is imperative
-        // that it is correct before testing the real details.
-        assertEquals(parentGroup, childGroup.getToParentGroup());
-        assertTrue(parentGroup.getChildGroupsArray().contains(childGroup));
-
-        // Always good to commit before deleting... bad things happen otherwise
-        context.commitChanges();
-
-        context.deleteObjects(childGroup);
-
-        // The things we are testing.
-        assertFalse(parentGroup.getChildGroupsArray().contains(childGroup));
-        // Although deleted, the property should be null (good cleanup policy)
-        // assertNull(childGroup.getToParentGroup());
-
-        // And be sure that the commit works afterwards, just for sanity
-        context.commitChanges();
-    }
-
-    /**
-     * Tests that deleting a source of a flattened relationship with CASCADE rule results
-     * in deleting a join and a target.
-     */
-    @Test
-    public void testCascadeToManyFlattened() {
-        // testing Artist.groupArray relationship
-        ArtGroup aGroup = context.newObject(ArtGroup.class);
-        aGroup.setName("Group Name");
-        Artist anArtist = context.newObject(Artist.class);
-        anArtist.setArtistName("A Name");
-        anArtist.addToGroupArray(aGroup);
-        assertTrue(anArtist.getGroupArray().contains(aGroup));
-
-        context.commitChanges();
-
-        SQLTemplate checkQuery = new SQLTemplate(
-                Artist.class,
-                "SELECT * FROM ARTIST_GROUP");
-        checkQuery.setFetchingDataRows(true);
-        List<?> joins1 = context.performQuery(checkQuery);
-        assertEquals(1, joins1.size());
-
-        context.deleteObjects(anArtist);
-
-        assertEquals(PersistenceState.DELETED, aGroup.getPersistenceState());
-        assertFalse(anArtist.getGroupArray().contains(aGroup));
-        context.commitChanges();
-
-        List<?> joins2 = context.performQuery(checkQuery);
-        assertEquals(0, joins2.size());
-    }
-
-    /**
-     * Tests that deleting a source of a flattened relationship with NULLIFY rule results
-     * in deleting a join together with the object deleted.
-     */
-    @Test
-    public void testNullifyToManyFlattened() {
-        // testing ArtGroup.artistArray relationship
-        ArtGroup aGroup = context.newObject(ArtGroup.class);
-        aGroup.setName("Group Name");
-        Artist anArtist = context.newObject(Artist.class);
-        anArtist.setArtistName("A Name");
-        aGroup.addToArtistArray(anArtist);
-
-        context.commitChanges();
-
-        // Preconditions
-        assertTrue(aGroup.getArtistArray().contains(anArtist));
-        assertTrue(anArtist.getGroupArray().contains(aGroup));
-
-        SQLTemplate checkQuery = new SQLTemplate(
-                Artist.class,
-                "SELECT * FROM ARTIST_GROUP");
-        checkQuery.setFetchingDataRows(true);
-        List<?> joins1 = context.performQuery(checkQuery);
-        assertEquals(1, joins1.size());
-
-        context.deleteObjects(aGroup);
-        assertFalse(anArtist.getGroupArray().contains(aGroup));
-        context.commitChanges();
-
-        List<?> joins2 = context.performQuery(checkQuery);
-        assertEquals(0, joins2.size());
-    }
-
-    @Test
-    public void testNullifyToMany() {
-        // ArtGroup childGroupsArray
-        ArtGroup parentGroup = (ArtGroup) context.newObject("ArtGroup");
-        parentGroup.setName("Parent");
-
-        ArtGroup childGroup = (ArtGroup) context.newObject("ArtGroup");
-        childGroup.setName("Child");
-        parentGroup.addToChildGroupsArray(childGroup);
-
-        // Preconditions - good to check to be sure
-        assertEquals(parentGroup, childGroup.getToParentGroup());
-        assertTrue(parentGroup.getChildGroupsArray().contains(childGroup));
-
-        context.commitChanges();
-
-        context.deleteObjects(parentGroup);
-
-        // The things we are testing.
-        assertNull(childGroup.getToParentGroup());
-
-        // Although deleted, the property should be null (good cleanup policy)
-        // assertFalse(parentGroup.getChildGroupsArray().contains(childGroup));
-        context.commitChanges();
-    }
-
-    @Test
-    public void testCascadeToOne() {
-        // Painting toPaintingInfo
-        Painting painting = (Painting) context.newObject("Painting");
-        painting.setPaintingTitle("A Title");
-
-        PaintingInfo info = (PaintingInfo) context.newObject("PaintingInfo");
-        painting.setToPaintingInfo(info);
-
-        // Must commit before deleting.. this relationship is dependent,
-        // and everything must be committed for certain things to work
-        context.commitChanges();
-
-        context.deleteObjects(painting);
-
-        // info must also be deleted
-        assertEquals(PersistenceState.DELETED, info.getPersistenceState());
-        assertNull(info.getPainting());
-        assertNull(painting.getToPaintingInfo());
-        context.commitChanges();
-    }
-
-    @Test
-    public void testCascadeToMany() {
-        // Artist artistExhibitArray
-        Artist anArtist = (Artist) context.newObject("Artist");
-        anArtist.setArtistName("A Name");
-        Exhibit anExhibit = (Exhibit) context.newObject("Exhibit");
-        anExhibit.setClosingDate(new java.sql.Timestamp(System.currentTimeMillis()));
-        anExhibit.setOpeningDate(new java.sql.Timestamp(System.currentTimeMillis()));
-
-        // Needs a gallery... required for data integrity
-        Gallery gallery = (Gallery) context.newObject("Gallery");
-        gallery.setGalleryName("A Name");
-
-        anExhibit.setToGallery(gallery);
-
-        ArtistExhibit artistExhibit = (ArtistExhibit) context.newObject("ArtistExhibit");
-
-        artistExhibit.setToArtist(anArtist);
-        artistExhibit.setToExhibit(anExhibit);
-        context.commitChanges();
-
-        context.deleteObjects(anArtist);
-
-        // Test that the link record was deleted, and removed from the relationship
-        assertEquals(PersistenceState.DELETED, artistExhibit.getPersistenceState());
-        assertFalse(anArtist.getArtistExhibitArray().contains(artistExhibit));
-        context.commitChanges();
-    }
-
-    @Test
-    public void testDenyToMany() {
-        // Gallery paintingArray
-        Gallery gallery = (Gallery) context.newObject("Gallery");
-        gallery.setGalleryName("A Name");
-        Painting painting = (Painting) context.newObject("Painting");
-        painting.setPaintingTitle("A Title");
-        gallery.addToPaintingArray(painting);
-        context.commitChanges();
-
-        try {
-            context.deleteObjects(gallery);
-            fail("Should have thrown an exception");
-        }
-        catch (Exception e) {
-            // GOOD!
-        }
-        context.commitChanges();
-    }
+	@Inject
+	private DataContext context;
+
+	@Inject
+	private DBHelper dbHelper;
+
+	@Override
+	public void cleanUpDB() throws Exception {
+		dbHelper.update("ARTGROUP").set("PARENT_GROUP_ID", null, Types.INTEGER).execute();
+		super.cleanUpDB();
+	}
+
+	@Test
+	public void testNullifyToOne() {
+		// ArtGroup toParentGroup
+		ArtGroup parentGroup = (ArtGroup) context.newObject("ArtGroup");
+		parentGroup.setName("Parent");
+
+		ArtGroup childGroup = (ArtGroup) context.newObject("ArtGroup");
+		childGroup.setName("Child");
+		parentGroup.addToChildGroupsArray(childGroup);
+
+		// Check to make sure that the relationships are both exactly correct
+		// before starting. We're not really testing this, but it is imperative
+		// that it is correct before testing the real details.
+		assertEquals(parentGroup, childGroup.getToParentGroup());
+		assertTrue(parentGroup.getChildGroupsArray().contains(childGroup));
+
+		// Always good to commit before deleting... bad things happen otherwise
+		context.commitChanges();
+
+		context.deleteObjects(childGroup);
+
+		// The things we are testing.
+		assertFalse(parentGroup.getChildGroupsArray().contains(childGroup));
+		// Although deleted, the property should be null (good cleanup policy)
+		// assertNull(childGroup.getToParentGroup());
+
+		// And be sure that the commit works afterwards, just for sanity
+		context.commitChanges();
+	}
+
+	/**
+	 * Tests that deleting a source of a flattened relationship with CASCADE
+	 * rule results in deleting a join and a target.
+	 */
+	@Test
+	public void testCascadeToManyFlattened() {
+		// testing Artist.groupArray relationship
+		ArtGroup aGroup = context.newObject(ArtGroup.class);
+		aGroup.setName("Group Name");
+		Artist anArtist = context.newObject(Artist.class);
+		anArtist.setArtistName("A Name");
+		anArtist.addToGroupArray(aGroup);
+		assertTrue(anArtist.getGroupArray().contains(aGroup));
+
+		context.commitChanges();
+
+		SQLTemplate checkQuery = new SQLTemplate(Artist.class, "SELECT * FROM ARTIST_GROUP");
+		checkQuery.setFetchingDataRows(true);
+		List<?> joins1 = context.performQuery(checkQuery);
+		assertEquals(1, joins1.size());
+
+		context.deleteObjects(anArtist);
+
+		assertEquals(PersistenceState.DELETED, aGroup.getPersistenceState());
+		assertFalse(anArtist.getGroupArray().contains(aGroup));
+		context.commitChanges();
+
+		List<?> joins2 = context.performQuery(checkQuery);
+		assertEquals(0, joins2.size());
+	}
+
+	/**
+	 * Tests that deleting a source of a flattened relationship with NULLIFY
+	 * rule results in deleting a join together with the object deleted.
+	 */
+	@Test
+	public void testNullifyToManyFlattened() {
+		// testing ArtGroup.artistArray relationship
+		ArtGroup aGroup = context.newObject(ArtGroup.class);
+		aGroup.setName("Group Name");
+		Artist anArtist = context.newObject(Artist.class);
+		anArtist.setArtistName("A Name");
+		aGroup.addToArtistArray(anArtist);
+
+		context.commitChanges();
+
+		// Preconditions
+		assertTrue(aGroup.getArtistArray().contains(anArtist));
+		assertTrue(anArtist.getGroupArray().contains(aGroup));
+
+		SQLTemplate checkQuery = new SQLTemplate(Artist.class, "SELECT * FROM ARTIST_GROUP");
+		checkQuery.setFetchingDataRows(true);
+		List<?> joins1 = context.performQuery(checkQuery);
+		assertEquals(1, joins1.size());
+
+		context.deleteObjects(aGroup);
+		assertFalse(anArtist.getGroupArray().contains(aGroup));
+		context.commitChanges();
+
+		List<?> joins2 = context.performQuery(checkQuery);
+		assertEquals(0, joins2.size());
+	}
+
+	@Test
+	public void testNullifyToMany() {
+		// ArtGroup childGroupsArray
+		ArtGroup parentGroup = (ArtGroup) context.newObject("ArtGroup");
+		parentGroup.setName("Parent");
+
+		ArtGroup childGroup = (ArtGroup) context.newObject("ArtGroup");
+		childGroup.setName("Child");
+		parentGroup.addToChildGroupsArray(childGroup);
+
+		// Preconditions - good to check to be sure
+		assertEquals(parentGroup, childGroup.getToParentGroup());
+		assertTrue(parentGroup.getChildGroupsArray().contains(childGroup));
+
+		context.commitChanges();
+
+		context.deleteObjects(parentGroup);
+
+		// The things we are testing.
+		assertNull(childGroup.getToParentGroup());
+
+		// Although deleted, the property should be null (good cleanup policy)
+		// assertFalse(parentGroup.getChildGroupsArray().contains(childGroup));
+		context.commitChanges();
+	}
+
+	@Test
+	public void testCascadeToOne() {
+		// Painting toPaintingInfo
+		Painting painting = (Painting) context.newObject("Painting");
+		painting.setPaintingTitle("A Title");
+
+		PaintingInfo info = (PaintingInfo) context.newObject("PaintingInfo");
+		painting.setToPaintingInfo(info);
+
+		// Must commit before deleting.. this relationship is dependent,
+		// and everything must be committed for certain things to work
+		context.commitChanges();
+
+		context.deleteObjects(painting);
+
+		// info must also be deleted
+		assertEquals(PersistenceState.DELETED, info.getPersistenceState());
+		assertNull(info.getPainting());
+		assertNull(painting.getToPaintingInfo());
+		context.commitChanges();
+	}
+
+	@Test
+	public void testCascadeToMany() {
+		// Artist artistExhibitArray
+		Artist anArtist = (Artist) context.newObject("Artist");
+		anArtist.setArtistName("A Name");
+		Exhibit anExhibit = (Exhibit) context.newObject("Exhibit");
+		anExhibit.setClosingDate(new java.sql.Timestamp(System.currentTimeMillis()));
+		anExhibit.setOpeningDate(new java.sql.Timestamp(System.currentTimeMillis()));
+
+		// Needs a gallery... required for data integrity
+		Gallery gallery = (Gallery) context.newObject("Gallery");
+		gallery.setGalleryName("A Name");
+
+		anExhibit.setToGallery(gallery);
+
+		ArtistExhibit artistExhibit = (ArtistExhibit) context.newObject("ArtistExhibit");
+
+		artistExhibit.setToArtist(anArtist);
+		artistExhibit.setToExhibit(anExhibit);
+		context.commitChanges();
+
+		context.deleteObjects(anArtist);
+
+		// Test that the link record was deleted, and removed from the
+		// relationship
+		assertEquals(PersistenceState.DELETED, artistExhibit.getPersistenceState());
+		assertFalse(anArtist.getArtistExhibitArray().contains(artistExhibit));
+		context.commitChanges();
+	}
+
+	@Test
+	public void testDenyToMany() {
+		// Gallery paintingArray
+		Gallery gallery = (Gallery) context.newObject("Gallery");
+		gallery.setGalleryName("A Name");
+		Painting painting = (Painting) context.newObject("Painting");
+		painting.setPaintingTitle("A Title");
+		gallery.addToPaintingArray(painting);
+		context.commitChanges();
+
+		try {
+			context.deleteObjects(gallery);
+			fail("Should have thrown an exception");
+		} catch (Exception e) {
+			// GOOD!
+		}
+		context.commitChanges();
+	}
 }

http://git-wip-us.apache.org/repos/asf/cayenne/blob/eefbc926/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextOuterJoinsIT.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextOuterJoinsIT.java b/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextOuterJoinsIT.java
index 719e79c..5c13490 100644
--- a/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextOuterJoinsIT.java
+++ b/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextOuterJoinsIT.java
@@ -43,156 +43,137 @@ import static org.junit.Assert.assertEquals;
 @UseServerRuntime(CayenneProjects.TESTMAP_PROJECT)
 public class DataContextOuterJoinsIT extends ServerCase {
 
-    @Inject
-    protected ObjectContext context;
-
-    @Inject
-    protected DBHelper dbHelper;
-
-    protected TableHelper artistHelper;
-    protected TableHelper paintingHelper;
-    protected TableHelper artgroupHelper;
-    protected TableHelper artistGroupHelper;
-
-    @Before
-    public void setUp() throws Exception {
-        artistHelper = new TableHelper(dbHelper, "ARTIST", "ARTIST_ID", "ARTIST_NAME");
-        paintingHelper = new TableHelper(
-                dbHelper,
-                "PAINTING",
-                "PAINTING_ID",
-                "ARTIST_ID",
-                "PAINTING_TITLE").setColumnTypes(
-                Types.INTEGER,
-                Types.BIGINT,
-                Types.VARCHAR);
-
-        artgroupHelper = new TableHelper(dbHelper, "ARTGROUP", "GROUP_ID", "NAME");
-        artistGroupHelper = new TableHelper(
-                dbHelper,
-                "ARTIST_GROUP",
-                "GROUP_ID",
-                "ARTIST_ID");
-
-        artistGroupHelper.deleteAll();
-        dbHelper.update("ARTGROUP").set("PARENT_GROUP_ID", null, Types.INTEGER).execute();
-        artgroupHelper.deleteAll();
-        paintingHelper.deleteAll();
-        artistHelper.deleteAll();
-    }
-
-    @Test
-    public void testSelectWithOuterJoinFlattened() throws Exception {
-
-        artistHelper.insert(33001, "AA1");
-        artistHelper.insert(33002, "AA2");
-        artistHelper.insert(33003, "BB1");
-        artistHelper.insert(33004, "BB2");
-
-        artgroupHelper.insert(1, "G1");
-
-        artistGroupHelper.insert(1, 33001);
-        artistGroupHelper.insert(1, 33002);
-        artistGroupHelper.insert(1, 33004);
-
-        SelectQuery missingToManyQuery = new SelectQuery(Artist.class);
-        missingToManyQuery.andQualifier(ExpressionFactory.matchExp(
-                Artist.GROUP_ARRAY_PROPERTY + Entity.OUTER_JOIN_INDICATOR,
-                null));
-        missingToManyQuery.addOrdering(Artist.ARTIST_NAME_PROPERTY, SortOrder.ASCENDING);
-
-        List<Artist> artists = context.performQuery(missingToManyQuery);
-        assertEquals(1, artists.size());
-        assertEquals("BB1", artists.get(0).getArtistName());
-    }
-
-    @Test
-    public void testSelectWithOuterJoin() throws Exception {
-
-        artistHelper.insert(33001, "AA1");
-        artistHelper.insert(33002, "AA2");
-        artistHelper.insert(33003, "BB1");
-        artistHelper.insert(33004, "BB2");
-
-        paintingHelper.insert(33001, 33001, "P1");
-        paintingHelper.insert(33002, 33002, "P2");
-
-        SelectQuery missingToManyQuery = new SelectQuery(Artist.class);
-        missingToManyQuery.andQualifier(ExpressionFactory.matchExp(
-                Artist.PAINTING_ARRAY_PROPERTY + Entity.OUTER_JOIN_INDICATOR,
-                null));
-        missingToManyQuery.addOrdering(Artist.ARTIST_NAME_PROPERTY, SortOrder.ASCENDING);
-
-        List<Artist> artists = context.performQuery(missingToManyQuery);
-        assertEquals(2, artists.size());
-        assertEquals("BB1", artists.get(0).getArtistName());
-
-        SelectQuery mixedConditionQuery = new SelectQuery(Artist.class);
-        mixedConditionQuery.andQualifier(ExpressionFactory.matchExp(
-                Artist.PAINTING_ARRAY_PROPERTY + Entity.OUTER_JOIN_INDICATOR,
-                null));
-        mixedConditionQuery.orQualifier(ExpressionFactory.matchExp(
-                Artist.ARTIST_NAME_PROPERTY,
-                "AA1"));
-        mixedConditionQuery.addOrdering(Artist.ARTIST_NAME_PROPERTY, SortOrder.ASCENDING);
-
-        artists = context.performQuery(mixedConditionQuery);
-        assertEquals(3, artists.size());
-        assertEquals("AA1", artists.get(0).getArtistName());
-        assertEquals("BB1", artists.get(1).getArtistName());
-        assertEquals("BB2", artists.get(2).getArtistName());
-    }
-
-    @Test
-    public void testSelectWithOuterJoinFromString() throws Exception {
-
-        artistHelper.insert(33001, "AA1");
-        artistHelper.insert(33002, "AA2");
-        artistHelper.insert(33003, "BB1");
-        artistHelper.insert(33004, "BB2");
-
-        paintingHelper.insert(33001, 33001, "P1");
-        paintingHelper.insert(33002, 33002, "P2");
-
-        SelectQuery missingToManyQuery = new SelectQuery(Artist.class);
-        missingToManyQuery.andQualifier(Expression.fromString("paintingArray+ = null"));
-        missingToManyQuery.addOrdering(Artist.ARTIST_NAME_PROPERTY, SortOrder.ASCENDING);
-
-        List<Artist> artists = context.performQuery(missingToManyQuery);
-        assertEquals(2, artists.size());
-        assertEquals("BB1", artists.get(0).getArtistName());
-
-        SelectQuery mixedConditionQuery = new SelectQuery(Artist.class);
-        mixedConditionQuery.andQualifier(ExpressionFactory.matchExp(
-                Artist.PAINTING_ARRAY_PROPERTY + Entity.OUTER_JOIN_INDICATOR,
-                null));
-        mixedConditionQuery.orQualifier(ExpressionFactory.matchExp(
-                Artist.ARTIST_NAME_PROPERTY,
-                "AA1"));
-        mixedConditionQuery.addOrdering(Artist.ARTIST_NAME_PROPERTY, SortOrder.ASCENDING);
-
-        artists = context.performQuery(mixedConditionQuery);
-        assertEquals(3, artists.size());
-        assertEquals("AA1", artists.get(0).getArtistName());
-        assertEquals("BB1", artists.get(1).getArtistName());
-        assertEquals("BB2", artists.get(2).getArtistName());
-    }
-
-    @Test
-    public void testSelectWithOuterOrdering() throws Exception {
-
-        artistHelper.insert(33001, "AA1");
-        artistHelper.insert(33002, "AA2");
-
-        paintingHelper.insert(33001, 33001, "P1");
-        paintingHelper.insert(33002, 33002, "P2");
-        paintingHelper.insert(33003, null, "P3");
-
-        SelectQuery query = new SelectQuery(Painting.class);
-
-        query.addOrdering("toArtist+.artistName", SortOrder.DESCENDING);
-
-        List<Artist> paintings = context.performQuery(query);
-        assertEquals(3, paintings.size());
-    }
+	@Inject
+	protected ObjectContext context;
+
+	@Inject
+	protected DBHelper dbHelper;
+
+	protected TableHelper artistHelper;
+	protected TableHelper paintingHelper;
+	protected TableHelper artgroupHelper;
+	protected TableHelper artistGroupHelper;
+
+	@Override
+	public void cleanUpDB() throws Exception {
+		dbHelper.update("ARTGROUP").set("PARENT_GROUP_ID", null, Types.INTEGER).execute();
+		super.cleanUpDB();
+	}
+
+	@Before
+	public void setUp() throws Exception {
+		artistHelper = new TableHelper(dbHelper, "ARTIST", "ARTIST_ID", "ARTIST_NAME");
+		paintingHelper = new TableHelper(dbHelper, "PAINTING", "PAINTING_ID", "ARTIST_ID", "PAINTING_TITLE")
+				.setColumnTypes(Types.INTEGER, Types.BIGINT, Types.VARCHAR);
+
+		artgroupHelper = new TableHelper(dbHelper, "ARTGROUP", "GROUP_ID", "NAME");
+		artistGroupHelper = new TableHelper(dbHelper, "ARTIST_GROUP", "GROUP_ID", "ARTIST_ID");
+	}
+
+	@Test
+	public void testSelectWithOuterJoinFlattened() throws Exception {
+
+		artistHelper.insert(33001, "AA1");
+		artistHelper.insert(33002, "AA2");
+		artistHelper.insert(33003, "BB1");
+		artistHelper.insert(33004, "BB2");
+
+		artgroupHelper.insert(1, "G1");
+
+		artistGroupHelper.insert(1, 33001);
+		artistGroupHelper.insert(1, 33002);
+		artistGroupHelper.insert(1, 33004);
+
+		SelectQuery missingToManyQuery = new SelectQuery(Artist.class);
+		missingToManyQuery.andQualifier(ExpressionFactory.matchExp(Artist.GROUP_ARRAY_PROPERTY
+				+ Entity.OUTER_JOIN_INDICATOR, null));
+		missingToManyQuery.addOrdering(Artist.ARTIST_NAME_PROPERTY, SortOrder.ASCENDING);
+
+		List<Artist> artists = context.performQuery(missingToManyQuery);
+		assertEquals(1, artists.size());
+		assertEquals("BB1", artists.get(0).getArtistName());
+	}
+
+	@Test
+	public void testSelectWithOuterJoin() throws Exception {
+
+		artistHelper.insert(33001, "AA1");
+		artistHelper.insert(33002, "AA2");
+		artistHelper.insert(33003, "BB1");
+		artistHelper.insert(33004, "BB2");
+
+		paintingHelper.insert(33001, 33001, "P1");
+		paintingHelper.insert(33002, 33002, "P2");
+
+		SelectQuery missingToManyQuery = new SelectQuery(Artist.class);
+		missingToManyQuery.andQualifier(ExpressionFactory.matchExp(Artist.PAINTING_ARRAY_PROPERTY
+				+ Entity.OUTER_JOIN_INDICATOR, null));
+		missingToManyQuery.addOrdering(Artist.ARTIST_NAME_PROPERTY, SortOrder.ASCENDING);
+
+		List<Artist> artists = context.performQuery(missingToManyQuery);
+		assertEquals(2, artists.size());
+		assertEquals("BB1", artists.get(0).getArtistName());
+
+		SelectQuery mixedConditionQuery = new SelectQuery(Artist.class);
+		mixedConditionQuery.andQualifier(ExpressionFactory.matchExp(Artist.PAINTING_ARRAY_PROPERTY
+				+ Entity.OUTER_JOIN_INDICATOR, null));
+		mixedConditionQuery.orQualifier(ExpressionFactory.matchExp(Artist.ARTIST_NAME_PROPERTY, "AA1"));
+		mixedConditionQuery.addOrdering(Artist.ARTIST_NAME_PROPERTY, SortOrder.ASCENDING);
+
+		artists = context.performQuery(mixedConditionQuery);
+		assertEquals(3, artists.size());
+		assertEquals("AA1", artists.get(0).getArtistName());
+		assertEquals("BB1", artists.get(1).getArtistName());
+		assertEquals("BB2", artists.get(2).getArtistName());
+	}
+
+	@Test
+	public void testSelectWithOuterJoinFromString() throws Exception {
+
+		artistHelper.insert(33001, "AA1");
+		artistHelper.insert(33002, "AA2");
+		artistHelper.insert(33003, "BB1");
+		artistHelper.insert(33004, "BB2");
+
+		paintingHelper.insert(33001, 33001, "P1");
+		paintingHelper.insert(33002, 33002, "P2");
+
+		SelectQuery missingToManyQuery = new SelectQuery(Artist.class);
+		missingToManyQuery.andQualifier(Expression.fromString("paintingArray+ = null"));
+		missingToManyQuery.addOrdering(Artist.ARTIST_NAME_PROPERTY, SortOrder.ASCENDING);
+
+		List<Artist> artists = context.performQuery(missingToManyQuery);
+		assertEquals(2, artists.size());
+		assertEquals("BB1", artists.get(0).getArtistName());
+
+		SelectQuery mixedConditionQuery = new SelectQuery(Artist.class);
+		mixedConditionQuery.andQualifier(ExpressionFactory.matchExp(Artist.PAINTING_ARRAY_PROPERTY
+				+ Entity.OUTER_JOIN_INDICATOR, null));
+		mixedConditionQuery.orQualifier(ExpressionFactory.matchExp(Artist.ARTIST_NAME_PROPERTY, "AA1"));
+		mixedConditionQuery.addOrdering(Artist.ARTIST_NAME_PROPERTY, SortOrder.ASCENDING);
+
+		artists = context.performQuery(mixedConditionQuery);
+		assertEquals(3, artists.size());
+		assertEquals("AA1", artists.get(0).getArtistName());
+		assertEquals("BB1", artists.get(1).getArtistName());
+		assertEquals("BB2", artists.get(2).getArtistName());
+	}
+
+	@Test
+	public void testSelectWithOuterOrdering() throws Exception {
+
+		artistHelper.insert(33001, "AA1");
+		artistHelper.insert(33002, "AA2");
+
+		paintingHelper.insert(33001, 33001, "P1");
+		paintingHelper.insert(33002, 33002, "P2");
+		paintingHelper.insert(33003, null, "P3");
+
+		SelectQuery query = new SelectQuery(Painting.class);
+
+		query.addOrdering("toArtist+.artistName", SortOrder.DESCENDING);
+
+		List<Artist> paintings = context.performQuery(query);
+		assertEquals(3, paintings.size());
+	}
 }

http://git-wip-us.apache.org/repos/asf/cayenne/blob/eefbc926/cayenne-server/src/test/java/org/apache/cayenne/access/FlattenedPrefetchIT.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/access/FlattenedPrefetchIT.java b/cayenne-server/src/test/java/org/apache/cayenne/access/FlattenedPrefetchIT.java
index f896877..99cfda4 100644
--- a/cayenne-server/src/test/java/org/apache/cayenne/access/FlattenedPrefetchIT.java
+++ b/cayenne-server/src/test/java/org/apache/cayenne/access/FlattenedPrefetchIT.java
@@ -67,7 +67,6 @@ public class FlattenedPrefetchIT extends ServerCase {
 
     @Before
     public void setUp() throws Exception {
-        dbHelper.update("ARTGROUP").set("PARENT_GROUP_ID", null, Types.INTEGER).execute();
 
         tArtist = new TableHelper(dbHelper, "ARTIST");
         tArtist.setColumns("ARTIST_ID", "ARTIST_NAME");

http://git-wip-us.apache.org/repos/asf/cayenne/blob/eefbc926/cayenne-server/src/test/java/org/apache/cayenne/merge/AddColumnToModelIT.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/merge/AddColumnToModelIT.java b/cayenne-server/src/test/java/org/apache/cayenne/merge/AddColumnToModelIT.java
index 583fd3a..db60769 100644
--- a/cayenne-server/src/test/java/org/apache/cayenne/merge/AddColumnToModelIT.java
+++ b/cayenne-server/src/test/java/org/apache/cayenne/merge/AddColumnToModelIT.java
@@ -18,23 +18,20 @@
  ****************************************************************/
 package org.apache.cayenne.merge;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import java.sql.Types;
+import java.util.List;
+
 import org.apache.cayenne.map.DbAttribute;
 import org.apache.cayenne.map.DbEntity;
 import org.apache.cayenne.map.ObjAttribute;
 import org.apache.cayenne.map.ObjEntity;
-import org.apache.cayenne.unit.di.server.CayenneProjects;
-import org.apache.cayenne.unit.di.server.UseServerRuntime;
 import org.junit.Test;
 
-import java.sql.Types;
-import java.util.List;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-
-@UseServerRuntime(CayenneProjects.TESTMAP_PROJECT)
 public class AddColumnToModelIT extends MergeCase {
 
     @Test

http://git-wip-us.apache.org/repos/asf/cayenne/blob/eefbc926/cayenne-server/src/test/java/org/apache/cayenne/merge/CreateTableToModelIT.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/merge/CreateTableToModelIT.java b/cayenne-server/src/test/java/org/apache/cayenne/merge/CreateTableToModelIT.java
index 7a5723a..3d14c1d 100644
--- a/cayenne-server/src/test/java/org/apache/cayenne/merge/CreateTableToModelIT.java
+++ b/cayenne-server/src/test/java/org/apache/cayenne/merge/CreateTableToModelIT.java
@@ -18,88 +18,80 @@
  ****************************************************************/
 package org.apache.cayenne.merge;
 
-import org.apache.cayenne.map.DbAttribute;
-import org.apache.cayenne.map.DbEntity;
-import org.apache.cayenne.map.ObjEntity;
-import org.apache.cayenne.unit.di.server.CayenneProjects;
-import org.apache.cayenne.unit.di.server.UseServerRuntime;
-import org.junit.Test;
-
-import java.sql.Types;
-import java.util.List;
-
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
 
-@UseServerRuntime(CayenneProjects.TESTMAP_PROJECT)
+import java.sql.Types;
+import java.util.List;
+
+import org.apache.cayenne.map.DbAttribute;
+import org.apache.cayenne.map.DbEntity;
+import org.apache.cayenne.map.ObjEntity;
+import org.junit.Test;
+
 public class CreateTableToModelIT extends MergeCase {
 
-    @Test
-    public void testAddTable() throws Exception {
-        dropTableIfPresent("NEW_TABLE");
-        assertTokensAndExecute(0, 0);
-
-        DbEntity dbEntity = new DbEntity("NEW_TABLE");
-
-        DbAttribute column1 = new DbAttribute("ID", Types.INTEGER, dbEntity);
-        column1.setMandatory(true);
-        column1.setPrimaryKey(true);
-        dbEntity.addAttribute(column1);
-
-        DbAttribute column2 = new DbAttribute("NAME", Types.VARCHAR, dbEntity);
-        column2.setMaxLength(10);
-        column2.setMandatory(false);
-        dbEntity.addAttribute(column2);
-
-        // for the new entity to the db
-        execute(mergerFactory().createCreateTableToDb(dbEntity));
-
-        List<MergerToken> tokens = createMergeTokens();
-        assertEquals(1, tokens.size());
-        MergerToken token = tokens.get(0);
-        if (token.getDirection().isToDb()) {
-            token = token.createReverse(mergerFactory());
-        }
-        assertTrue(token.getClass().getName(),
-                token instanceof CreateTableToModel);
-
-        execute(token);
-
-        ObjEntity objEntity = null;
-        for (ObjEntity candidate : map.getObjEntities()) {
-            if (dbEntity.getName().equalsIgnoreCase(candidate.getDbEntityName())) {
-                objEntity = candidate;
-                break;
-            }
-        }
-        assertNotNull(objEntity);
-
-        assertEquals(objEntity.getClassName(), map.getDefaultPackage() + "."
-                + objEntity.getName());
-        assertEquals(objEntity.getSuperClassName(), map.getDefaultSuperclass());
-        assertEquals(objEntity.getClientClassName(),
-                map.getDefaultClientPackage() + "." + objEntity.getName());
-        assertEquals(objEntity.getClientSuperClassName(),
-                map.getDefaultClientSuperclass());
-
-        assertEquals(1, objEntity.getAttributes().size());
-        assertEquals("java.lang.String", objEntity.getAttributes().iterator()
-                .next().getType());
-
-        // clear up
-        // fix psql case issue
-        map.removeDbEntity(objEntity.getDbEntity().getName(), true);
-        map.removeObjEntity(objEntity.getName(), true);
-        map.removeDbEntity(dbEntity.getName(), true);
-        resolver.refreshMappingCache();
-        assertNull(map.getObjEntity(objEntity.getName()));
-        assertNull(map.getDbEntity(dbEntity.getName()));
-        assertFalse(map.getDbEntities().contains(dbEntity));
-
-        assertTokensAndExecute(1, 0);
-        assertTokensAndExecute(0, 0);
-    }
+	@Test
+	public void testAddTable() throws Exception {
+		dropTableIfPresent("NEW_TABLE");
+		assertTokensAndExecute(0, 0);
+
+		DbEntity dbEntity = new DbEntity("NEW_TABLE");
+
+		DbAttribute column1 = new DbAttribute("ID", Types.INTEGER, dbEntity);
+		column1.setMandatory(true);
+		column1.setPrimaryKey(true);
+		dbEntity.addAttribute(column1);
+
+		DbAttribute column2 = new DbAttribute("NAME", Types.VARCHAR, dbEntity);
+		column2.setMaxLength(10);
+		column2.setMandatory(false);
+		dbEntity.addAttribute(column2);
+
+		// for the new entity to the db
+		execute(mergerFactory().createCreateTableToDb(dbEntity));
+
+		List<MergerToken> tokens = createMergeTokens();
+		assertEquals(1, tokens.size());
+		MergerToken token = tokens.get(0);
+		if (token.getDirection().isToDb()) {
+			token = token.createReverse(mergerFactory());
+		}
+		assertTrue(token.getClass().getName(), token instanceof CreateTableToModel);
+
+		execute(token);
+
+		ObjEntity objEntity = null;
+		for (ObjEntity candidate : map.getObjEntities()) {
+			if (dbEntity.getName().equalsIgnoreCase(candidate.getDbEntityName())) {
+				objEntity = candidate;
+				break;
+			}
+		}
+		assertNotNull(objEntity);
+
+		assertEquals(objEntity.getClassName(), map.getDefaultPackage() + "." + objEntity.getName());
+		assertEquals(objEntity.getSuperClassName(), map.getDefaultSuperclass());
+		assertEquals(objEntity.getClientClassName(), map.getDefaultClientPackage() + "." + objEntity.getName());
+		assertEquals(objEntity.getClientSuperClassName(), map.getDefaultClientSuperclass());
+
+		assertEquals(1, objEntity.getAttributes().size());
+		assertEquals("java.lang.String", objEntity.getAttributes().iterator().next().getType());
+
+		// clear up
+		// fix psql case issue
+		map.removeDbEntity(objEntity.getDbEntity().getName(), true);
+		map.removeObjEntity(objEntity.getName(), true);
+		map.removeDbEntity(dbEntity.getName(), true);
+		resolver.refreshMappingCache();
+		assertNull(map.getObjEntity(objEntity.getName()));
+		assertNull(map.getDbEntity(dbEntity.getName()));
+		assertFalse(map.getDbEntities().contains(dbEntity));
+
+		assertTokensAndExecute(1, 0);
+		assertTokensAndExecute(0, 0);
+	}
 }

http://git-wip-us.apache.org/repos/asf/cayenne/blob/eefbc926/cayenne-server/src/test/java/org/apache/cayenne/merge/DropColumnToModelIT.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/merge/DropColumnToModelIT.java b/cayenne-server/src/test/java/org/apache/cayenne/merge/DropColumnToModelIT.java
index 8fb2814..9bfee73 100644
--- a/cayenne-server/src/test/java/org/apache/cayenne/merge/DropColumnToModelIT.java
+++ b/cayenne-server/src/test/java/org/apache/cayenne/merge/DropColumnToModelIT.java
@@ -18,6 +18,16 @@
  ****************************************************************/
 package org.apache.cayenne.merge;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.sql.Types;
+import java.util.List;
+
 import org.apache.cayenne.map.DbAttribute;
 import org.apache.cayenne.map.DbEntity;
 import org.apache.cayenne.map.DbJoin;
@@ -25,212 +35,201 @@ import org.apache.cayenne.map.DbRelationship;
 import org.apache.cayenne.map.ObjAttribute;
 import org.apache.cayenne.map.ObjEntity;
 import org.apache.cayenne.map.ObjRelationship;
-import org.apache.cayenne.unit.di.server.CayenneProjects;
-import org.apache.cayenne.unit.di.server.UseServerRuntime;
 import org.junit.Test;
 
-import java.sql.Types;
-import java.util.List;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-@UseServerRuntime(CayenneProjects.TESTMAP_PROJECT)
 public class DropColumnToModelIT extends MergeCase {
 
-    @Test
-    public void testSimpleColumn() throws Exception {
-        dropTableIfPresent("NEW_TABLE");
-
-        assertTokensAndExecute(0, 0);
-
-        DbEntity dbEntity = new DbEntity("NEW_TABLE");
-
-        DbAttribute column1 = new DbAttribute("ID", Types.INTEGER, dbEntity);
-        column1.setMandatory(true);
-        column1.setPrimaryKey(true);
-        dbEntity.addAttribute(column1);
-
-        DbAttribute column2 = new DbAttribute("NAME", Types.VARCHAR, dbEntity);
-        column2.setMaxLength(10);
-        column2.setMandatory(false);
-        dbEntity.addAttribute(column2);
-
-        map.addDbEntity(dbEntity);
-
-        assertTokensAndExecute(1, 0);
-        assertTokensAndExecute(0, 0);
-
-        ObjEntity objEntity = new ObjEntity("NewTable");
-        objEntity.setDbEntity(dbEntity);
-        ObjAttribute oatr1 = new ObjAttribute("name");
-        oatr1.setDbAttributePath(column2.getName());
-        oatr1.setType("java.lang.String");
-        objEntity.addAttribute(oatr1);
-        map.addObjEntity(objEntity);
-
-        // force drop name column in db
-        MergerToken token = mergerFactory().createDropColumnToDb(dbEntity, column2);
-        execute(token);
-
-        List<MergerToken> tokens = createMergeTokens();
-        assertEquals(1, tokens.size());
-        token = tokens.get(0);
-        if (token.getDirection().isToDb()) {
-            token = token.createReverse(mergerFactory());
-        }
-        assertTrue(token instanceof DropColumnToModel);
-        execute(token);
-        assertNull(dbEntity.getAttribute(column2.getName()));
-        assertNull(objEntity.getAttribute(oatr1.getName()));
-
-        // clear up
-        map.removeObjEntity(objEntity.getName(), true);
-        map.removeDbEntity(dbEntity.getName(), true);
-        resolver.refreshMappingCache();
-        assertNull(map.getObjEntity(objEntity.getName()));
-        assertNull(map.getDbEntity(dbEntity.getName()));
-        assertFalse(map.getDbEntities().contains(dbEntity));
-
-        assertTokensAndExecute(1, 0);
-        assertTokensAndExecute(0, 0);
-    }
-
-    @Test
-    public void testRemoveFKColumnWithoutRelationshipInDb() throws Exception {
-        dropTableIfPresent("NEW_TABLE");
-        dropTableIfPresent("NEW_TABLE2");
-
-        assertTokensAndExecute(0, 0);
-
-        DbEntity dbEntity1 = new DbEntity("NEW_TABLE");
-
-        DbAttribute e1col1 = new DbAttribute("ID", Types.INTEGER, dbEntity1);
-        e1col1.setMandatory(true);
-        e1col1.setPrimaryKey(true);
-        dbEntity1.addAttribute(e1col1);
-
-        DbAttribute e1col2 = new DbAttribute("NAME", Types.VARCHAR, dbEntity1);
-        e1col2.setMaxLength(10);
-        e1col2.setMandatory(false);
-        dbEntity1.addAttribute(e1col2);
-
-        map.addDbEntity(dbEntity1);
-
-        DbEntity dbEntity2 = new DbEntity("NEW_TABLE2");
-        DbAttribute e2col1 = new DbAttribute("ID", Types.INTEGER, dbEntity2);
-        e2col1.setMandatory(true);
-        e2col1.setPrimaryKey(true);
-        dbEntity2.addAttribute(e2col1);
-        DbAttribute e2col2 = new DbAttribute("FK", Types.INTEGER, dbEntity2);
-        dbEntity2.addAttribute(e2col2);
-        DbAttribute e2col3 = new DbAttribute("NAME", Types.VARCHAR, dbEntity2);
-        e2col3.setMaxLength(10);
-        dbEntity2.addAttribute(e2col3);
-
-        map.addDbEntity(dbEntity2);
-
-        assertTokensAndExecute(2, 0);
-        assertTokensAndExecute(0, 0);
-
-        // force drop fk column in db
-        execute(mergerFactory().createDropColumnToDb(dbEntity2, e2col2));
-
-        // create db relationships, but do not sync them to db
-        DbRelationship rel1To2 = new DbRelationship("rel1To2");
-        rel1To2.setSourceEntity(dbEntity1);
-        rel1To2.setTargetEntity(dbEntity2);
-        rel1To2.setToMany(true);
-        rel1To2.addJoin(new DbJoin(rel1To2, e1col1.getName(), e2col2.getName()));
-        dbEntity1.addRelationship(rel1To2);
-        DbRelationship rel2To1 = new DbRelationship("rel2To1");
-        rel2To1.setSourceEntity(dbEntity2);
-        rel2To1.setTargetEntity(dbEntity1);
-        rel2To1.setToMany(false);
-        rel2To1.addJoin(new DbJoin(rel2To1, e2col2.getName(), e1col1.getName()));
-        dbEntity2.addRelationship(rel2To1);
-        assertSame(rel1To2, rel2To1.getReverseRelationship());
-        assertSame(rel2To1, rel1To2.getReverseRelationship());
-
-        // create ObjEntities
-        ObjEntity objEntity1 = new ObjEntity("NewTable");
-        objEntity1.setDbEntity(dbEntity1);
-        ObjAttribute oatr1 = new ObjAttribute("name");
-        oatr1.setDbAttributePath(e1col2.getName());
-        oatr1.setType("java.lang.String");
-        objEntity1.addAttribute(oatr1);
-        map.addObjEntity(objEntity1);
-        ObjEntity objEntity2 = new ObjEntity("NewTable2");
-        objEntity2.setDbEntity(dbEntity2);
-        ObjAttribute o2a1 = new ObjAttribute("name");
-        o2a1.setDbAttributePath(e2col3.getName());
-        o2a1.setType("java.lang.String");
-        objEntity2.addAttribute(o2a1);
-        map.addObjEntity(objEntity2);
-
-        // create ObjRelationships
-        assertEquals(0, objEntity1.getRelationships().size());
-        assertEquals(0, objEntity2.getRelationships().size());
-        ObjRelationship objRel1To2 = new ObjRelationship("objRel1To2");
-        objRel1To2.addDbRelationship(rel1To2);
-        objRel1To2.setSourceEntity(objEntity1);
-        objRel1To2.setTargetEntity(objEntity2);
-        objEntity1.addRelationship(objRel1To2);
-        ObjRelationship objRel2To1 = new ObjRelationship("objRel2To1");
-        objRel2To1.addDbRelationship(rel2To1);
-        objRel2To1.setSourceEntity(objEntity2);
-        objRel2To1.setTargetEntity(objEntity1);
-        objEntity2.addRelationship(objRel2To1);
-        assertEquals(1, objEntity1.getRelationships().size());
-        assertEquals(1, objEntity2.getRelationships().size());
-        assertSame(objRel1To2, objRel2To1.getReverseRelationship());
-        assertSame(objRel2To1, objRel1To2.getReverseRelationship());
-
-        // try do use the merger to remove the column and relationship in the model
-        List<MergerToken> tokens = createMergeTokens();
-        assertTokens(tokens, 2, 0);
-        // TODO: reversing the following two tokens should also reverse the order
-        MergerToken token0 = tokens.get(0).createReverse(mergerFactory());
-        MergerToken token1 = tokens.get(1).createReverse(mergerFactory());
-        if (!(token0 instanceof DropRelationshipToModel && token1 instanceof DropColumnToModel
-                || token1 instanceof DropRelationshipToModel && token0 instanceof DropColumnToModel)) {
-            fail();
-        }
-        // do not execute DropRelationshipToModel, only DropColumnToModel.
-        if (token1 instanceof DropColumnToModel) {
-            execute(token1);
-        } else {
-            execute(token0);
-        }
-
-        // check after merging
-        assertNull(dbEntity2.getAttribute(e2col2.getName()));
-        assertEquals(0, dbEntity1.getRelationships().size());
-        assertEquals(0, dbEntity2.getRelationships().size());
-        assertEquals(0, objEntity1.getRelationships().size());
-        assertEquals(0, objEntity2.getRelationships().size());
-
-        // clear up
-
-        dbEntity1.removeRelationship(rel1To2.getName());
-        dbEntity2.removeRelationship(rel2To1.getName());
-        map.removeObjEntity(objEntity1.getName(), true);
-        map.removeDbEntity(dbEntity1.getName(), true);
-        map.removeObjEntity(objEntity2.getName(), true);
-        map.removeDbEntity(dbEntity2.getName(), true);
-        resolver.refreshMappingCache();
-        assertNull(map.getObjEntity(objEntity1.getName()));
-        assertNull(map.getDbEntity(dbEntity1.getName()));
-        assertNull(map.getObjEntity(objEntity2.getName()));
-        assertNull(map.getDbEntity(dbEntity2.getName()));
-        assertFalse(map.getDbEntities().contains(dbEntity1));
-        assertFalse(map.getDbEntities().contains(dbEntity2));
-
-        assertTokensAndExecute(2, 0);
-        assertTokensAndExecute(0, 0);
-    }
+	@Test
+	public void testSimpleColumn() throws Exception {
+		dropTableIfPresent("NEW_TABLE");
+
+		assertTokensAndExecute(0, 0);
+
+		DbEntity dbEntity = new DbEntity("NEW_TABLE");
+
+		DbAttribute column1 = new DbAttribute("ID", Types.INTEGER, dbEntity);
+		column1.setMandatory(true);
+		column1.setPrimaryKey(true);
+		dbEntity.addAttribute(column1);
+
+		DbAttribute column2 = new DbAttribute("NAME", Types.VARCHAR, dbEntity);
+		column2.setMaxLength(10);
+		column2.setMandatory(false);
+		dbEntity.addAttribute(column2);
+
+		map.addDbEntity(dbEntity);
+
+		assertTokensAndExecute(1, 0);
+		assertTokensAndExecute(0, 0);
+
+		ObjEntity objEntity = new ObjEntity("NewTable");
+		objEntity.setDbEntity(dbEntity);
+		ObjAttribute oatr1 = new ObjAttribute("name");
+		oatr1.setDbAttributePath(column2.getName());
+		oatr1.setType("java.lang.String");
+		objEntity.addAttribute(oatr1);
+		map.addObjEntity(objEntity);
+
+		// force drop name column in db
+		MergerToken token = mergerFactory().createDropColumnToDb(dbEntity, column2);
+		execute(token);
+
+		List<MergerToken> tokens = createMergeTokens();
+		assertEquals(1, tokens.size());
+		token = tokens.get(0);
+		if (token.getDirection().isToDb()) {
+			token = token.createReverse(mergerFactory());
+		}
+		assertTrue(token instanceof DropColumnToModel);
+		execute(token);
+		assertNull(dbEntity.getAttribute(column2.getName()));
+		assertNull(objEntity.getAttribute(oatr1.getName()));
+
+		// clear up
+		map.removeObjEntity(objEntity.getName(), true);
+		map.removeDbEntity(dbEntity.getName(), true);
+		resolver.refreshMappingCache();
+		assertNull(map.getObjEntity(objEntity.getName()));
+		assertNull(map.getDbEntity(dbEntity.getName()));
+		assertFalse(map.getDbEntities().contains(dbEntity));
+
+		assertTokensAndExecute(1, 0);
+		assertTokensAndExecute(0, 0);
+	}
+
+	@Test
+	public void testRemoveFKColumnWithoutRelationshipInDb() throws Exception {
+		dropTableIfPresent("NEW_TABLE");
+		dropTableIfPresent("NEW_TABLE2");
+
+		assertTokensAndExecute(0, 0);
+
+		DbEntity dbEntity1 = new DbEntity("NEW_TABLE");
+
+		DbAttribute e1col1 = new DbAttribute("ID", Types.INTEGER, dbEntity1);
+		e1col1.setMandatory(true);
+		e1col1.setPrimaryKey(true);
+		dbEntity1.addAttribute(e1col1);
+
+		DbAttribute e1col2 = new DbAttribute("NAME", Types.VARCHAR, dbEntity1);
+		e1col2.setMaxLength(10);
+		e1col2.setMandatory(false);
+		dbEntity1.addAttribute(e1col2);
+
+		map.addDbEntity(dbEntity1);
+
+		DbEntity dbEntity2 = new DbEntity("NEW_TABLE2");
+		DbAttribute e2col1 = new DbAttribute("ID", Types.INTEGER, dbEntity2);
+		e2col1.setMandatory(true);
+		e2col1.setPrimaryKey(true);
+		dbEntity2.addAttribute(e2col1);
+		DbAttribute e2col2 = new DbAttribute("FK", Types.INTEGER, dbEntity2);
+		dbEntity2.addAttribute(e2col2);
+		DbAttribute e2col3 = new DbAttribute("NAME", Types.VARCHAR, dbEntity2);
+		e2col3.setMaxLength(10);
+		dbEntity2.addAttribute(e2col3);
+
+		map.addDbEntity(dbEntity2);
+
+		assertTokensAndExecute(2, 0);
+		assertTokensAndExecute(0, 0);
+
+		// force drop fk column in db
+		execute(mergerFactory().createDropColumnToDb(dbEntity2, e2col2));
+
+		// create db relationships, but do not sync them to db
+		DbRelationship rel1To2 = new DbRelationship("rel1To2");
+		rel1To2.setSourceEntity(dbEntity1);
+		rel1To2.setTargetEntity(dbEntity2);
+		rel1To2.setToMany(true);
+		rel1To2.addJoin(new DbJoin(rel1To2, e1col1.getName(), e2col2.getName()));
+		dbEntity1.addRelationship(rel1To2);
+		DbRelationship rel2To1 = new DbRelationship("rel2To1");
+		rel2To1.setSourceEntity(dbEntity2);
+		rel2To1.setTargetEntity(dbEntity1);
+		rel2To1.setToMany(false);
+		rel2To1.addJoin(new DbJoin(rel2To1, e2col2.getName(), e1col1.getName()));
+		dbEntity2.addRelationship(rel2To1);
+		assertSame(rel1To2, rel2To1.getReverseRelationship());
+		assertSame(rel2To1, rel1To2.getReverseRelationship());
+
+		// create ObjEntities
+		ObjEntity objEntity1 = new ObjEntity("NewTable");
+		objEntity1.setDbEntity(dbEntity1);
+		ObjAttribute oatr1 = new ObjAttribute("name");
+		oatr1.setDbAttributePath(e1col2.getName());
+		oatr1.setType("java.lang.String");
+		objEntity1.addAttribute(oatr1);
+		map.addObjEntity(objEntity1);
+		ObjEntity objEntity2 = new ObjEntity("NewTable2");
+		objEntity2.setDbEntity(dbEntity2);
+		ObjAttribute o2a1 = new ObjAttribute("name");
+		o2a1.setDbAttributePath(e2col3.getName());
+		o2a1.setType("java.lang.String");
+		objEntity2.addAttribute(o2a1);
+		map.addObjEntity(objEntity2);
+
+		// create ObjRelationships
+		assertEquals(0, objEntity1.getRelationships().size());
+		assertEquals(0, objEntity2.getRelationships().size());
+		ObjRelationship objRel1To2 = new ObjRelationship("objRel1To2");
+		objRel1To2.addDbRelationship(rel1To2);
+		objRel1To2.setSourceEntity(objEntity1);
+		objRel1To2.setTargetEntity(objEntity2);
+		objEntity1.addRelationship(objRel1To2);
+		ObjRelationship objRel2To1 = new ObjRelationship("objRel2To1");
+		objRel2To1.addDbRelationship(rel2To1);
+		objRel2To1.setSourceEntity(objEntity2);
+		objRel2To1.setTargetEntity(objEntity1);
+		objEntity2.addRelationship(objRel2To1);
+		assertEquals(1, objEntity1.getRelationships().size());
+		assertEquals(1, objEntity2.getRelationships().size());
+		assertSame(objRel1To2, objRel2To1.getReverseRelationship());
+		assertSame(objRel2To1, objRel1To2.getReverseRelationship());
+
+		// try do use the merger to remove the column and relationship in the
+		// model
+		List<MergerToken> tokens = createMergeTokens();
+		assertTokens(tokens, 2, 0);
+		// TODO: reversing the following two tokens should also reverse the
+		// order
+		MergerToken token0 = tokens.get(0).createReverse(mergerFactory());
+		MergerToken token1 = tokens.get(1).createReverse(mergerFactory());
+		if (!(token0 instanceof DropRelationshipToModel && token1 instanceof DropColumnToModel || token1 instanceof DropRelationshipToModel
+				&& token0 instanceof DropColumnToModel)) {
+			fail();
+		}
+		// do not execute DropRelationshipToModel, only DropColumnToModel.
+		if (token1 instanceof DropColumnToModel) {
+			execute(token1);
+		} else {
+			execute(token0);
+		}
+
+		// check after merging
+		assertNull(dbEntity2.getAttribute(e2col2.getName()));
+		assertEquals(0, dbEntity1.getRelationships().size());
+		assertEquals(0, dbEntity2.getRelationships().size());
+		assertEquals(0, objEntity1.getRelationships().size());
+		assertEquals(0, objEntity2.getRelationships().size());
+
+		// clear up
+
+		dbEntity1.removeRelationship(rel1To2.getName());
+		dbEntity2.removeRelationship(rel2To1.getName());
+		map.removeObjEntity(objEntity1.getName(), true);
+		map.removeDbEntity(dbEntity1.getName(), true);
+		map.removeObjEntity(objEntity2.getName(), true);
+		map.removeDbEntity(dbEntity2.getName(), true);
+		resolver.refreshMappingCache();
+		assertNull(map.getObjEntity(objEntity1.getName()));
+		assertNull(map.getDbEntity(dbEntity1.getName()));
+		assertNull(map.getObjEntity(objEntity2.getName()));
+		assertNull(map.getDbEntity(dbEntity2.getName()));
+		assertFalse(map.getDbEntities().contains(dbEntity1));
+		assertFalse(map.getDbEntities().contains(dbEntity2));
+
+		assertTokensAndExecute(2, 0);
+		assertTokensAndExecute(0, 0);
+	}
 }

http://git-wip-us.apache.org/repos/asf/cayenne/blob/eefbc926/cayenne-server/src/test/java/org/apache/cayenne/merge/DropRelationshipToModelIT.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/merge/DropRelationshipToModelIT.java b/cayenne-server/src/test/java/org/apache/cayenne/merge/DropRelationshipToModelIT.java
index 8799850..7f08a0e 100644
--- a/cayenne-server/src/test/java/org/apache/cayenne/merge/DropRelationshipToModelIT.java
+++ b/cayenne-server/src/test/java/org/apache/cayenne/merge/DropRelationshipToModelIT.java
@@ -18,6 +18,15 @@
  ****************************************************************/
 package org.apache.cayenne.merge;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.fail;
+
+import java.sql.Types;
+import java.util.List;
+
 import org.apache.cayenne.map.DbAttribute;
 import org.apache.cayenne.map.DbEntity;
 import org.apache.cayenne.map.DbJoin;
@@ -25,161 +34,150 @@ import org.apache.cayenne.map.DbRelationship;
 import org.apache.cayenne.map.ObjAttribute;
 import org.apache.cayenne.map.ObjEntity;
 import org.apache.cayenne.map.ObjRelationship;
-import org.apache.cayenne.unit.di.server.CayenneProjects;
-import org.apache.cayenne.unit.di.server.UseServerRuntime;
 import org.junit.Test;
 
-import java.sql.Types;
-import java.util.List;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.fail;
-
-@UseServerRuntime(CayenneProjects.TESTMAP_PROJECT)
 public class DropRelationshipToModelIT extends MergeCase {
 
-    @Test
-    public void testForeignKey() throws Exception {
-        dropTableIfPresent("NEW_TABLE");
-        dropTableIfPresent("NEW_TABLE2");
-
-        assertTokensAndExecute(0, 0);
-
-        DbEntity dbEntity1 = new DbEntity("NEW_TABLE");
-
-        DbAttribute e1col1 = new DbAttribute("ID", Types.INTEGER, dbEntity1);
-        e1col1.setMandatory(true);
-        e1col1.setPrimaryKey(true);
-        dbEntity1.addAttribute(e1col1);
-
-        DbAttribute e1col2 = new DbAttribute("NAME", Types.VARCHAR, dbEntity1);
-        e1col2.setMaxLength(10);
-        e1col2.setMandatory(false);
-        dbEntity1.addAttribute(e1col2);
-
-        map.addDbEntity(dbEntity1);
-
-        DbEntity dbEntity2 = new DbEntity("NEW_TABLE2");
-        DbAttribute e2col1 = new DbAttribute("ID", Types.INTEGER, dbEntity2);
-        e2col1.setMandatory(true);
-        e2col1.setPrimaryKey(true);
-        dbEntity2.addAttribute(e2col1);
-        DbAttribute e2col2 = new DbAttribute("FK", Types.INTEGER, dbEntity2);
-        dbEntity2.addAttribute(e2col2);
-        DbAttribute e2col3 = new DbAttribute("NAME", Types.VARCHAR, dbEntity2);
-        e2col3.setMaxLength(10);
-        dbEntity2.addAttribute(e2col3);
-
-        map.addDbEntity(dbEntity2);
-
-        // create db relationships
-        DbRelationship rel1To2 = new DbRelationship("rel1To2");
-        rel1To2.setSourceEntity(dbEntity1);
-        rel1To2.setTargetEntity(dbEntity2);
-        rel1To2.setToMany(true);
-        rel1To2.addJoin(new DbJoin(rel1To2, e1col1.getName(), e2col2.getName()));
-        dbEntity1.addRelationship(rel1To2);
-        DbRelationship rel2To1 = new DbRelationship("rel2To1");
-        rel2To1.setSourceEntity(dbEntity2);
-        rel2To1.setTargetEntity(dbEntity1);
-        rel2To1.setToMany(false);
-        rel2To1.addJoin(new DbJoin(rel2To1, e2col2.getName(), e1col1.getName()));
-        dbEntity2.addRelationship(rel2To1);
-        assertSame(rel1To2, rel2To1.getReverseRelationship());
-        assertSame(rel2To1, rel1To2.getReverseRelationship());
-
-        assertTokensAndExecute(4, 0);
-        assertTokensAndExecute(0, 0);
-
-        // create ObjEntities
-        ObjEntity objEntity1 = new ObjEntity("NewTable");
-        objEntity1.setDbEntity(dbEntity1);
-        ObjAttribute oatr1 = new ObjAttribute("name");
-        oatr1.setDbAttributePath(e1col2.getName());
-        oatr1.setType("java.lang.String");
-        objEntity1.addAttribute(oatr1);
-        map.addObjEntity(objEntity1);
-        ObjEntity objEntity2 = new ObjEntity("NewTable2");
-        objEntity2.setDbEntity(dbEntity2);
-        ObjAttribute o2a1 = new ObjAttribute("name");
-        o2a1.setDbAttributePath(e2col3.getName());
-        o2a1.setType("java.lang.String");
-        objEntity2.addAttribute(o2a1);
-        map.addObjEntity(objEntity2);
-
-        // create ObjRelationships
-        assertEquals(0, objEntity1.getRelationships().size());
-        assertEquals(0, objEntity2.getRelationships().size());
-        ObjRelationship objRel1To2 = new ObjRelationship("objRel1To2");
-        objRel1To2.addDbRelationship(rel1To2);
-        objRel1To2.setSourceEntity(objEntity1);
-        objRel1To2.setTargetEntity(objEntity2);
-        objEntity1.addRelationship(objRel1To2);
-        ObjRelationship objRel2To1 = new ObjRelationship("objRel2To1");
-        objRel2To1.addDbRelationship(rel2To1);
-        objRel2To1.setSourceEntity(objEntity2);
-        objRel2To1.setTargetEntity(objEntity1);
-        objEntity2.addRelationship(objRel2To1);
-        assertEquals(1, objEntity1.getRelationships().size());
-        assertEquals(1, objEntity2.getRelationships().size());
-        assertSame(objRel1To2, objRel2To1.getReverseRelationship());
-        assertSame(objRel2To1, objRel1To2.getReverseRelationship());
-
-        // remove relationship and fk from model, merge to db and read to model
-        dbEntity2.removeRelationship(rel2To1.getName());
-        dbEntity1.removeRelationship(rel1To2.getName());
-        dbEntity2.removeAttribute(e2col2.getName());
-        List<MergerToken> tokens = createMergeTokens();
-        assertTokens(tokens, 2, 1);
-        for (MergerToken token : tokens) {
-            if (token.getDirection().isToDb()) {
-                execute(token);
-            }
-        }
-        assertTokensAndExecute(0, 0);
-        dbEntity2.addRelationship(rel2To1);
-        dbEntity1.addRelationship(rel1To2);
-        dbEntity2.addAttribute(e2col2);
-
-        // try do use the merger to remove the relationship in the model
-        tokens = createMergeTokens();
-        assertTokens(tokens, 2, 0);
-        // TODO: reversing the following two tokens should also reverse the order
-        MergerToken token0 = tokens.get(0).createReverse(mergerFactory());
-        MergerToken token1 = tokens.get(1).createReverse(mergerFactory());
-        if (!(token0 instanceof DropRelationshipToModel && token1 instanceof DropColumnToModel
-            || token1 instanceof DropRelationshipToModel && token0 instanceof DropColumnToModel)) {
-            fail();
-        }
-        execute(token0);
-        execute(token1);
-
-        // check after merging
-        assertNull(dbEntity2.getAttribute(e2col2.getName()));
-        assertEquals(0, dbEntity1.getRelationships().size());
-        assertEquals(0, dbEntity2.getRelationships().size());
-        assertEquals(0, objEntity1.getRelationships().size());
-        assertEquals(0, objEntity2.getRelationships().size());
-
-        // clear up
-        dbEntity1.removeRelationship(rel1To2.getName());
-        dbEntity2.removeRelationship(rel2To1.getName());
-        map.removeObjEntity(objEntity1.getName(), true);
-        map.removeDbEntity(dbEntity1.getName(), true);
-        map.removeObjEntity(objEntity2.getName(), true);
-        map.removeDbEntity(dbEntity2.getName(), true);
-        resolver.refreshMappingCache();
-        assertNull(map.getObjEntity(objEntity1.getName()));
-        assertNull(map.getDbEntity(dbEntity1.getName()));
-        assertNull(map.getObjEntity(objEntity2.getName()));
-        assertNull(map.getDbEntity(dbEntity2.getName()));
-        assertFalse(map.getDbEntities().contains(dbEntity1));
-        assertFalse(map.getDbEntities().contains(dbEntity2));
-
-        assertTokensAndExecute(2, 0);
-        assertTokensAndExecute(0, 0);
-    }
+	@Test
+	public void testForeignKey() throws Exception {
+		dropTableIfPresent("NEW_TABLE");
+		dropTableIfPresent("NEW_TABLE2");
+
+		assertTokensAndExecute(0, 0);
+
+		DbEntity dbEntity1 = new DbEntity("NEW_TABLE");
+
+		DbAttribute e1col1 = new DbAttribute("ID", Types.INTEGER, dbEntity1);
+		e1col1.setMandatory(true);
+		e1col1.setPrimaryKey(true);
+		dbEntity1.addAttribute(e1col1);
+
+		DbAttribute e1col2 = new DbAttribute("NAME", Types.VARCHAR, dbEntity1);
+		e1col2.setMaxLength(10);
+		e1col2.setMandatory(false);
+		dbEntity1.addAttribute(e1col2);
+
+		map.addDbEntity(dbEntity1);
+
+		DbEntity dbEntity2 = new DbEntity("NEW_TABLE2");
+		DbAttribute e2col1 = new DbAttribute("ID", Types.INTEGER, dbEntity2);
+		e2col1.setMandatory(true);
+		e2col1.setPrimaryKey(true);
+		dbEntity2.addAttribute(e2col1);
+		DbAttribute e2col2 = new DbAttribute("FK", Types.INTEGER, dbEntity2);
+		dbEntity2.addAttribute(e2col2);
+		DbAttribute e2col3 = new DbAttribute("NAME", Types.VARCHAR, dbEntity2);
+		e2col3.setMaxLength(10);
+		dbEntity2.addAttribute(e2col3);
+
+		map.addDbEntity(dbEntity2);
+
+		// create db relationships
+		DbRelationship rel1To2 = new DbRelationship("rel1To2");
+		rel1To2.setSourceEntity(dbEntity1);
+		rel1To2.setTargetEntity(dbEntity2);
+		rel1To2.setToMany(true);
+		rel1To2.addJoin(new DbJoin(rel1To2, e1col1.getName(), e2col2.getName()));
+		dbEntity1.addRelationship(rel1To2);
+		DbRelationship rel2To1 = new DbRelationship("rel2To1");
+		rel2To1.setSourceEntity(dbEntity2);
+		rel2To1.setTargetEntity(dbEntity1);
+		rel2To1.setToMany(false);
+		rel2To1.addJoin(new DbJoin(rel2To1, e2col2.getName(), e1col1.getName()));
+		dbEntity2.addRelationship(rel2To1);
+		assertSame(rel1To2, rel2To1.getReverseRelationship());
+		assertSame(rel2To1, rel1To2.getReverseRelationship());
+
+		assertTokensAndExecute(4, 0);
+		assertTokensAndExecute(0, 0);
+
+		// create ObjEntities
+		ObjEntity objEntity1 = new ObjEntity("NewTable");
+		objEntity1.setDbEntity(dbEntity1);
+		ObjAttribute oatr1 = new ObjAttribute("name");
+		oatr1.setDbAttributePath(e1col2.getName());
+		oatr1.setType("java.lang.String");
+		objEntity1.addAttribute(oatr1);
+		map.addObjEntity(objEntity1);
+		ObjEntity objEntity2 = new ObjEntity("NewTable2");
+		objEntity2.setDbEntity(dbEntity2);
+		ObjAttribute o2a1 = new ObjAttribute("name");
+		o2a1.setDbAttributePath(e2col3.getName());
+		o2a1.setType("java.lang.String");
+		objEntity2.addAttribute(o2a1);
+		map.addObjEntity(objEntity2);
+
+		// create ObjRelationships
+		assertEquals(0, objEntity1.getRelationships().size());
+		assertEquals(0, objEntity2.getRelationships().size());
+		ObjRelationship objRel1To2 = new ObjRelationship("objRel1To2");
+		objRel1To2.addDbRelationship(rel1To2);
+		objRel1To2.setSourceEntity(objEntity1);
+		objRel1To2.setTargetEntity(objEntity2);
+		objEntity1.addRelationship(objRel1To2);
+		ObjRelationship objRel2To1 = new ObjRelationship("objRel2To1");
+		objRel2To1.addDbRelationship(rel2To1);
+		objRel2To1.setSourceEntity(objEntity2);
+		objRel2To1.setTargetEntity(objEntity1);
+		objEntity2.addRelationship(objRel2To1);
+		assertEquals(1, objEntity1.getRelationships().size());
+		assertEquals(1, objEntity2.getRelationships().size());
+		assertSame(objRel1To2, objRel2To1.getReverseRelationship());
+		assertSame(objRel2To1, objRel1To2.getReverseRelationship());
+
+		// remove relationship and fk from model, merge to db and read to model
+		dbEntity2.removeRelationship(rel2To1.getName());
+		dbEntity1.removeRelationship(rel1To2.getName());
+		dbEntity2.removeAttribute(e2col2.getName());
+		List<MergerToken> tokens = createMergeTokens();
+		assertTokens(tokens, 2, 1);
+		for (MergerToken token : tokens) {
+			if (token.getDirection().isToDb()) {
+				execute(token);
+			}
+		}
+		assertTokensAndExecute(0, 0);
+		dbEntity2.addRelationship(rel2To1);
+		dbEntity1.addRelationship(rel1To2);
+		dbEntity2.addAttribute(e2col2);
+
+		// try do use the merger to remove the relationship in the model
+		tokens = createMergeTokens();
+		assertTokens(tokens, 2, 0);
+		// TODO: reversing the following two tokens should also reverse the
+		// order
+		MergerToken token0 = tokens.get(0).createReverse(mergerFactory());
+		MergerToken token1 = tokens.get(1).createReverse(mergerFactory());
+		if (!(token0 instanceof DropRelationshipToModel && token1 instanceof DropColumnToModel || token1 instanceof DropRelationshipToModel
+				&& token0 instanceof DropColumnToModel)) {
+			fail();
+		}
+		execute(token0);
+		execute(token1);
+
+		// check after merging
+		assertNull(dbEntity2.getAttribute(e2col2.getName()));
+		assertEquals(0, dbEntity1.getRelationships().size());
+		assertEquals(0, dbEntity2.getRelationships().size());
+		assertEquals(0, objEntity1.getRelationships().size());
+		assertEquals(0, objEntity2.getRelationships().size());
+
+		// clear up
+		dbEntity1.removeRelationship(rel1To2.getName());
+		dbEntity2.removeRelationship(rel2To1.getName());
+		map.removeObjEntity(objEntity1.getName(), true);
+		map.removeDbEntity(dbEntity1.getName(), true);
+		map.removeObjEntity(objEntity2.getName(), true);
+		map.removeDbEntity(dbEntity2.getName(), true);
+		resolver.refreshMappingCache();
+		assertNull(map.getObjEntity(objEntity1.getName()));
+		assertNull(map.getDbEntity(dbEntity1.getName()));
+		assertNull(map.getObjEntity(objEntity2.getName()));
+		assertNull(map.getDbEntity(dbEntity2.getName()));
+		assertFalse(map.getDbEntities().contains(dbEntity1));
+		assertFalse(map.getDbEntities().contains(dbEntity2));
+
+		assertTokensAndExecute(2, 0);
+		assertTokensAndExecute(0, 0);
+	}
 }

http://git-wip-us.apache.org/repos/asf/cayenne/blob/eefbc926/cayenne-server/src/test/java/org/apache/cayenne/merge/DropTableToModelIT.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/merge/DropTableToModelIT.java b/cayenne-server/src/test/java/org/apache/cayenne/merge/DropTableToModelIT.java
index a0f4e3e..ddf5a49 100644
--- a/cayenne-server/src/test/java/org/apache/cayenne/merge/DropTableToModelIT.java
+++ b/cayenne-server/src/test/java/org/apache/cayenne/merge/DropTableToModelIT.java
@@ -18,80 +18,77 @@
  ****************************************************************/
 package org.apache.cayenne.merge;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import java.sql.Types;
+import java.util.List;
+
 import org.apache.cayenne.map.DbAttribute;
 import org.apache.cayenne.map.DbEntity;
 import org.apache.cayenne.map.ObjAttribute;
 import org.apache.cayenne.map.ObjEntity;
-import org.apache.cayenne.unit.di.server.CayenneProjects;
-import org.apache.cayenne.unit.di.server.UseServerRuntime;
 import org.junit.Test;
 
-import java.sql.Types;
-import java.util.List;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-
-@UseServerRuntime(CayenneProjects.TESTMAP_PROJECT)
 public class DropTableToModelIT extends MergeCase {
 
-    @Test
-    public void testDropTable() throws Exception {
-        dropTableIfPresent("NEW_TABLE");
-        assertTokensAndExecute(0, 0);
-
-        DbEntity dbEntity = new DbEntity("NEW_TABLE");
-
-        DbAttribute column1 = new DbAttribute("ID", Types.INTEGER, dbEntity);
-        column1.setMandatory(true);
-        column1.setPrimaryKey(true);
-        dbEntity.addAttribute(column1);
-
-        DbAttribute column2 = new DbAttribute("NAME", Types.VARCHAR, dbEntity);
-        column2.setMaxLength(10);
-        column2.setMandatory(false);
-        dbEntity.addAttribute(column2);
-
-        map.addDbEntity(dbEntity);
-
-        assertTokensAndExecute(1, 0);
-        assertTokensAndExecute(0, 0);
-
-        ObjEntity objEntity = new ObjEntity("NewTable");
-        objEntity.setDbEntity(dbEntity);
-        ObjAttribute oatr1 = new ObjAttribute("name");
-        oatr1.setDbAttributePath(column2.getName());
-        oatr1.setType("java.lang.String");
-        objEntity.addAttribute(oatr1);
-        map.addObjEntity(objEntity);
-
-        // force drop table in db
-        MergerToken token = mergerFactory().createDropTableToDb(dbEntity);
-        execute(token);
-
-        List<MergerToken> tokens = createMergeTokens();
-        assertEquals(1, tokens.size());
-        token = tokens.get(0);
-        if (token.getDirection().isToDb()) {
-            token = token.createReverse(mergerFactory());
-        }
-        assertTrue(token instanceof DropTableToModel);
-        execute(token);
-        resolver.refreshMappingCache();
-        assertNull(map.getDbEntity(dbEntity.getName()));
-        assertNull(map.getObjEntity(objEntity.getName()));
-
-        // clear up
-        map.removeObjEntity(objEntity.getName(), true);
-        map.removeDbEntity(dbEntity.getName(), true);
-        resolver.refreshMappingCache();
-        assertNull(map.getObjEntity(objEntity.getName()));
-        assertNull(map.getDbEntity(dbEntity.getName()));
-        assertFalse(map.getDbEntities().contains(dbEntity));
-
-        assertTokensAndExecute(0, 0);
-    }
+	@Test
+	public void testDropTable() throws Exception {
+		dropTableIfPresent("NEW_TABLE");
+		assertTokensAndExecute(0, 0);
+
+		DbEntity dbEntity = new DbEntity("NEW_TABLE");
+
+		DbAttribute column1 = new DbAttribute("ID", Types.INTEGER, dbEntity);
+		column1.setMandatory(true);
+		column1.setPrimaryKey(true);
+		dbEntity.addAttribute(column1);
+
+		DbAttribute column2 = new DbAttribute("NAME", Types.VARCHAR, dbEntity);
+		column2.setMaxLength(10);
+		column2.setMandatory(false);
+		dbEntity.addAttribute(column2);
+
+		map.addDbEntity(dbEntity);
+
+		assertTokensAndExecute(1, 0);
+		assertTokensAndExecute(0, 0);
+
+		ObjEntity objEntity = new ObjEntity("NewTable");
+		objEntity.setDbEntity(dbEntity);
+		ObjAttribute oatr1 = new ObjAttribute("name");
+		oatr1.setDbAttributePath(column2.getName());
+		oatr1.setType("java.lang.String");
+		objEntity.addAttribute(oatr1);
+		map.addObjEntity(objEntity);
+
+		// force drop table in db
+		MergerToken token = mergerFactory().createDropTableToDb(dbEntity);
+		execute(token);
+
+		List<MergerToken> tokens = createMergeTokens();
+		assertEquals(1, tokens.size());
+		token = tokens.get(0);
+		if (token.getDirection().isToDb()) {
+			token = token.createReverse(mergerFactory());
+		}
+		assertTrue(token instanceof DropTableToModel);
+		execute(token);
+		resolver.refreshMappingCache();
+		assertNull(map.getDbEntity(dbEntity.getName()));
+		assertNull(map.getObjEntity(objEntity.getName()));
+
+		// clear up
+		map.removeObjEntity(objEntity.getName(), true);
+		map.removeDbEntity(dbEntity.getName(), true);
+		resolver.refreshMappingCache();
+		assertNull(map.getObjEntity(objEntity.getName()));
+		assertNull(map.getDbEntity(dbEntity.getName()));
+		assertFalse(map.getDbEntities().contains(dbEntity));
+
+		assertTokensAndExecute(0, 0);
+	}
 
 }

http://git-wip-us.apache.org/repos/asf/cayenne/blob/eefbc926/cayenne-server/src/test/java/org/apache/cayenne/merge/MergeCase.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/merge/MergeCase.java b/cayenne-server/src/test/java/org/apache/cayenne/merge/MergeCase.java
index 0f4f130..8c999db 100644
--- a/cayenne-server/src/test/java/org/apache/cayenne/merge/MergeCase.java
+++ b/cayenne-server/src/test/java/org/apache/cayenne/merge/MergeCase.java
@@ -18,6 +18,15 @@
  ****************************************************************/
 package org.apache.cayenne.merge;
 
+import static org.junit.Assert.assertEquals;
+
+import java.sql.Connection;
+import java.sql.Statement;
+import java.sql.Types;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
 import org.apache.cayenne.access.DataNode;
 import org.apache.cayenne.access.loader.DbLoaderConfiguration;
 import org.apache.cayenne.configuration.server.ServerRuntime;
@@ -29,194 +38,188 @@ import org.apache.cayenne.map.DbEntity;
 import org.apache.cayenne.map.EntityResolver;
 import org.apache.cayenne.test.jdbc.DBHelper;
 import org.apache.cayenne.unit.UnitDbAdapter;
+import org.apache.cayenne.unit.di.server.CayenneProjects;
 import org.apache.cayenne.unit.di.server.ServerCase;
 import org.apache.cayenne.unit.di.server.ServerCaseDataSourceFactory;
+import org.apache.cayenne.unit.di.server.UseServerRuntime;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.junit.Before;
 
-import java.sql.Connection;
-import java.sql.Statement;
-import java.sql.Types;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-
-import static org.junit.Assert.assertEquals;
-
+@UseServerRuntime(CayenneProjects.TESTMAP_PROJECT)
 public abstract class MergeCase extends ServerCase {
 
-    private Log logger = LogFactory.getLog(MergeCase.class);
+	private Log logger = LogFactory.getLog(MergeCase.class);
+
+	@Inject
+	private DBHelper dbHelper;
 
-    @Inject
-    private DBHelper dbHelper;
+	@Inject
+	private ServerRuntime runtime;
 
-    @Inject
-    private ServerRuntime runtime;
+	@Inject
+	private UnitDbAdapter accessStackAdapter;
 
-    @Inject
-    private UnitDbAdapter accessStackAdapter;
+	@Inject
+	private ServerCaseDataSourceFactory dataSourceFactory;
 
-    @Inject
-    private ServerCaseDataSourceFactory dataSourceFactory;
+	@Inject
+	protected EntityResolver resolver;
 
-    @Inject
-    protected EntityResolver resolver;
+	@Inject
+	protected DataNode node;
 
-    @Inject
-    protected DataNode node;
+	protected DataMap map;
 
-    protected DataMap map;
+	private static List<String> TABLE_NAMES = Arrays.asList("ARTIST", "PAINTING", "NEW_TABLE", "NEW_TABLE2");
 
-    private static List<String> TABLE_NAMES = Arrays.asList("ARTIST",
-            "PAINTING", "NEW_TABLE", "NEW_TABLE2");
+	@Override
+	public void cleanUpDB() throws Exception {
+		dbHelper.update("ARTGROUP").set("PARENT_GROUP_ID", null, Types.INTEGER).execute();
+		super.cleanUpDB();
+	}
 
-    @Before
-    public void setUp() throws Exception {
-        dbHelper.update("ARTGROUP").set("PARENT_GROUP_ID", null, Types.INTEGER).execute();
-
-        // this map can't be safely modified in this test, as it is reset by DI
-        // container
-        // on every test
-        map = runtime.getDataDomain().getDataMap("testmap");
-
-        filterDataMap();
-
-        List<MergerToken> tokens = createMergeTokens();
-        execute(tokens);
-
-        assertTokensAndExecute(0, 0);
-    }
-
-    protected DbMerger createMerger(MergerFactory mergerFactory) {
-        return createMerger(mergerFactory, null);
-    }
-
-    protected DbMerger createMerger(MergerFactory mergerFactory, ValueForNullProvider valueForNullProvider) {
-        return new DbMerger(mergerFactory, valueForNullProvider) {
-
-            @Override
-            public boolean includeTableName(String tableName) {
-                return TABLE_NAMES.contains(tableName.toUpperCase());
-            }
-        };
-    }
-
-    protected List<MergerToken> createMergeTokens() {
-        return createMerger(node.getAdapter().mergerFactory()).createMergeTokens(node, map, new DbLoaderConfiguration());
-    }
-
-    /**
-     * Remote binary pk {@link DbEntity} for {@link DbAdapter} not supporting
-     * that and so on.
-     */
-    private void filterDataMap() {
-        // copied from AbstractAccessStack.dbEntitiesInInsertOrder
-        boolean excludeBinPK = accessStackAdapter.supportsBinaryPK();
-
-        if (!excludeBinPK) {
-            return;
-        }
-
-        List<DbEntity> entitiesToRemove = new ArrayList<DbEntity>();
-
-        for (DbEntity ent : map.getDbEntities()) {
-            for (DbAttribute attr : ent.getAttributes()) {
-                // check for BIN PK or FK to BIN Pk
-                if (attr.getType() == Types.BINARY
-                        || attr.getType() == Types.VARBINARY
-                        || attr.getType() == Types.LONGVARBINARY) {
-
-                    if (attr.isPrimaryKey() || attr.isForeignKey()) {
-                        entitiesToRemove.add(ent);
-                        break;
-                    }
-                }
-            }
-        }
-
-        for (DbEntity e : entitiesToRemove) {
-            map.removeDbEntity(e.getName(), true);
-        }
-    }
-
-    protected void execute(List<MergerToken> tokens) {
-        MergerContext mergerContext = new ExecutingMergerContext(map, node);
-        for (MergerToken tok : tokens) {
-            tok.execute(mergerContext);
-        }
-    }
-
-    protected void execute(MergerToken token) throws Exception {
-        MergerContext mergerContext = new ExecutingMergerContext(map, node);
-        token.execute(mergerContext);
-    }
-
-    private void executeSql(String sql) throws Exception {
-        Connection conn = dataSourceFactory.getSharedDataSource()
-                .getConnection();
-
-        try {
-            Statement st = conn.createStatement();
-
-            try {
-                st.execute(sql);
-            } finally {
-                st.close();
-            }
-        }
-
-        finally {
-            conn.close();
-        }
-    }
-
-    protected void assertTokens(List<MergerToken> tokens, int expectedToDb,
-            int expectedToModel) {
-        int actualToDb = 0;
-        int actualToModel = 0;
-        for (MergerToken token : tokens) {
-            if (token.getDirection().isToDb()) {
-                actualToDb++;
-            } else if (token.getDirection().isToModel()) {
-                actualToModel++;
-            }
-        }
-
-        assertEquals("tokens to db", expectedToDb, actualToDb);
-        assertEquals("tokens to model", expectedToModel, actualToModel);
-    }
-
-    protected void assertTokensAndExecute(int expectedToDb, int expectedToModel) {
-        List<MergerToken> tokens = createMergeTokens();
-        assertTokens(tokens, expectedToDb, expectedToModel);
-        execute(tokens);
-    }
-
-    protected MergerFactory mergerFactory() {
-        return node.getAdapter().mergerFactory();
-    }
-
-    protected void dropTableIfPresent(String tableName) throws Exception {
-
-        // must have a dummy datamap for the dummy table for the downstream code
-        // to work
-        DataMap map = new DataMap("dummy");
-        map.setQuotingSQLIdentifiers(map.isQuotingSQLIdentifiers());
-        DbEntity entity = new DbEntity(tableName);
-        map.addDbEntity(entity);
-
-        AbstractToDbToken t = (AbstractToDbToken) mergerFactory()
-                .createDropTableToDb(entity);
-
-        for (String sql : t.createSql(node.getAdapter())) {
-
-            try {
-                executeSql(sql);
-            } catch (Exception e) {
-                logger.info("Exception dropping table " + tableName
-                        + ", probably abscent..");
-            }
-        }
-    }
+	@Before
+	public void setUp() throws Exception {
+
+		// this map can't be safely modified in this test, as it is reset by DI
+		// container
+		// on every test
+		map = runtime.getDataDomain().getDataMap("testmap");
+
+		filterDataMap();
+
+		List<MergerToken> tokens = createMergeTokens();
+		execute(tokens);
+
+		assertTokensAndExecute(0, 0);
+	}
+
+	protected DbMerger createMerger(MergerFactory mergerFactory) {
+		return createMerger(mergerFactory, null);
+	}
+
+	protected DbMerger createMerger(MergerFactory mergerFactory, ValueForNullProvider valueForNullProvider) {
+		return new DbMerger(mergerFactory, valueForNullProvider) {
+
+			@Override
+			public boolean includeTableName(String tableName) {
+				return TABLE_NAMES.contains(tableName.toUpperCase());
+			}
+		};
+	}
+
+	protected List<MergerToken> createMergeTokens() {
+		return createMerger(node.getAdapter().mergerFactory())
+				.createMergeTokens(node, map, new DbLoaderConfiguration());
+	}
+
+	/**
+	 * Remote binary pk {@link DbEntity} for {@link DbAdapter} not supporting
+	 * that and so on.
+	 */
+	private void filterDataMap() {
+		// copied from AbstractAccessStack.dbEntitiesInInsertOrder
+		boolean excludeBinPK = accessStackAdapter.supportsBinaryPK();
+
+		if (!excludeBinPK) {
+			return;
+		}
+
+		List<DbEntity> entitiesToRemove = new ArrayList<DbEntity>();
+
+		for (DbEntity ent : map.getDbEntities()) {
+			for (DbAttribute attr : ent.getAttributes()) {
+				// check for BIN PK or FK to BIN Pk
+				if (attr.getType() == Types.BINARY || attr.getType() == Types.VARBINARY
+						|| attr.getType() == Types.LONGVARBINARY) {
+
+					if (attr.isPrimaryKey() || attr.isForeignKey()) {
+						entitiesToRemove.add(ent);
+						break;
+					}
+				}
+			}
+		}
+
+		for (DbEntity e : entitiesToRemove) {
+			map.removeDbEntity(e.getName(), true);
+		}
+	}
+
+	protected void execute(List<MergerToken> tokens) {
+		MergerContext mergerContext = new ExecutingMergerContext(map, node);
+		for (MergerToken tok : tokens) {
+			tok.execute(mergerContext);
+		}
+	}
+
+	protected void execute(MergerToken token) throws Exception {
+		MergerContext mergerContext = new ExecutingMergerContext(map, node);
+		token.execute(mergerContext);
+	}
+
+	private void executeSql(String sql) throws Exception {
+		Connection conn = dataSourceFactory.getSharedDataSource().getConnection();
+
+		try {
+			Statement st = conn.createStatement();
+
+			try {
+				st.execute(sql);
+			} finally {
+				st.close();
+			}
+		}
+
+		finally {
+			conn.close();
+		}
+	}
+
+	protected void assertTokens(List<MergerToken> tokens, int expectedToDb, int expectedToModel) {
+		int actualToDb = 0;
+		int actualToModel = 0;
+		for (MergerToken token : tokens) {
+			if (token.getDirection().isToDb()) {
+				actualToDb++;
+			} else if (token.getDirection().isToModel()) {
+				actualToModel++;
+			}
+		}
+
+		assertEquals("tokens to db", expectedToDb, actualToDb);
+		assertEquals("tokens to model", expectedToModel, actualToModel);
+	}
+
+	protected void assertTokensAndExecute(int expectedToDb, int expectedToModel) {
+		List<MergerToken> tokens = createMergeTokens();
+		assertTokens(tokens, expectedToDb, expectedToModel);
+		execute(tokens);
+	}
+
+	protected MergerFactory mergerFactory() {
+		return node.getAdapter().mergerFactory();
+	}
+
+	protected void dropTableIfPresent(String tableName) throws Exception {
+
+		// must have a dummy datamap for the dummy table for the downstream code
+		// to work
+		DataMap map = new DataMap("dummy");
+		map.setQuotingSQLIdentifiers(map.isQuotingSQLIdentifiers());
+		DbEntity entity = new DbEntity(tableName);
+		map.addDbEntity(entity);
+
+		AbstractToDbToken t = (AbstractToDbToken) mergerFactory().createDropTableToDb(entity);
+
+		for (String sql : t.createSql(node.getAdapter())) {
+
+			try {
+				executeSql(sql);
+			} catch (Exception e) {
+				logger.info("Exception dropping table " + tableName + ", probably abscent..");
+			}
+		}
+	}
 }


Mime
View raw message