improve DBCleaner with filtering
Project: http://git-wip-us.apache.org/repos/asf/cayenne/repo Commit: http://git-wip-us.apache.org/repos/asf/cayenne/commit/62d137cf Tree: http://git-wip-us.apache.org/repos/asf/cayenne/tree/62d137cf Diff: http://git-wip-us.apache.org/repos/asf/cayenne/diff/62d137cf Branch: refs/heads/CAY-1946_1 Commit: 62d137cf71ca740a852007f90a5631618866f81d Parents: a5559d7 Author: Savva Kolbechev <s.kolbac...@gmail.com> Authored: Wed Nov 19 18:44:00 2014 +0300 Committer: Savva Kolbechev <s.kolbac...@gmail.com> Committed: Wed Nov 19 18:44:00 2014 +0300 ---------------------------------------------------------------------- .../cayenne/unit/di/server/DBCleaner.java | 55 +++++--------------- .../unit/di/server/DBCleanerProvider.java | 5 +- .../cayenne/unit/di/server/SchemaBuilder.java | 24 ++++++--- 3 files changed, 30 insertions(+), 54 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cayenne/blob/62d137cf/cayenne-server/src/test/java/org/apache/cayenne/unit/di/server/DBCleaner.java ---------------------------------------------------------------------- diff --git a/cayenne-server/src/test/java/org/apache/cayenne/unit/di/server/DBCleaner.java b/cayenne-server/src/test/java/org/apache/cayenne/unit/di/server/DBCleaner.java index e28525b..2bd5cc3 100644 --- a/cayenne-server/src/test/java/org/apache/cayenne/unit/di/server/DBCleaner.java +++ b/cayenne-server/src/test/java/org/apache/cayenne/unit/di/server/DBCleaner.java @@ -19,7 +19,6 @@ package org.apache.cayenne.unit.di.server; -import org.apache.cayenne.access.DataDomain; import org.apache.cayenne.configuration.ConfigurationTree; import org.apache.cayenne.configuration.DataChannelDescriptor; import org.apache.cayenne.configuration.XMLDataChannelDescriptorLoader; @@ -32,70 +31,40 @@ import org.apache.cayenne.unit.UnitDbAdapter; import java.net.URL; import java.sql.SQLException; -import java.util.ArrayList; import java.util.List; public class DBCleaner { private FlavoredDBHelper dbHelper; private String location; - private DataDomain domain; private XMLDataChannelDescriptorLoader loader; @Inject + private SchemaBuilder schemaBuilder; + + @Inject private UnitDbAdapter accessStackAdapter; @Inject private Injector injector; - public DBCleaner(FlavoredDBHelper dbHelper, DataDomain dataDomain, String location) { + public DBCleaner(FlavoredDBHelper dbHelper, String location) { this.dbHelper = dbHelper; this.location = location; - this.domain = dataDomain; } public void clean() throws SQLException { - if (location.equals(CayenneProjects.BINARY_PK_PROJECT)) { - if (accessStackAdapter.supportsBinaryPK()) { - dbHelper.deleteAll("BINARY_PK_TEST2"); - dbHelper.deleteAll("BINARY_PK_TEST1"); - } - } else if (location.equals(CayenneProjects.EMPTY_PROJECT)) { - return; - } else if (location.equals(CayenneProjects.LOB_PROJECT)) { - dbHelper.deleteAll("CLOB_TEST_RELATION"); - if (accessStackAdapter.supportsLobs()) { - dbHelper.deleteAll("BLOB_TEST"); - dbHelper.deleteAll("CLOB_TEST"); - } - dbHelper.deleteAll("TEST"); - } else if (location.equals(CayenneProjects.MISC_TYPES_PROJECT)) { - if (accessStackAdapter.supportsLobs()) { - dbHelper.deleteAll("SERIALIZABLE_ENTITY"); - } - dbHelper.deleteAll("ARRAYS_ENTITY"); - dbHelper.deleteAll("CHARACTER_ENTITY"); - } else if (location.equals(CayenneProjects.RETURN_TYPES_PROJECT)) { - if (accessStackAdapter.supportsLobs()) { - dbHelper.deleteAll("TYPES_MAPPING_LOBS_TEST1"); - dbHelper.deleteAll("TYPES_MAPPING_TEST2"); - } - dbHelper.deleteAll("TYPES_MAPPING_TEST1"); - } else { - loader = new XMLDataChannelDescriptorLoader(); - injector.injectMembers(loader); + loader = new XMLDataChannelDescriptorLoader(); + injector.injectMembers(loader); - URL url = getClass().getClassLoader().getResource(location); - ConfigurationTree<DataChannelDescriptor> tree = loader.load(new URLResource(url)); + URL url = getClass().getClassLoader().getResource(location); + ConfigurationTree<DataChannelDescriptor> tree = loader.load(new URLResource(url)); - for (DataMap map : tree.getRootNode().getDataMaps()) { - DataMap dataMap = domain.getDataMap(map.getName()); - List<DbEntity> entities = new ArrayList<DbEntity>(dataMap.getDbEntities()); - domain.getEntitySorter().sortDbEntities(entities, true); + for (DataMap map : tree.getRootNode().getDataMaps()) { + List<DbEntity> entities = schemaBuilder.dbEntitiesInDeleteOrder(map); - for (DbEntity entity : entities) { - dbHelper.deleteAll(entity.getName()); - } + for (DbEntity entity : entities) { + dbHelper.deleteAll(entity.getName()); } } } http://git-wip-us.apache.org/repos/asf/cayenne/blob/62d137cf/cayenne-server/src/test/java/org/apache/cayenne/unit/di/server/DBCleanerProvider.java ---------------------------------------------------------------------- diff --git a/cayenne-server/src/test/java/org/apache/cayenne/unit/di/server/DBCleanerProvider.java b/cayenne-server/src/test/java/org/apache/cayenne/unit/di/server/DBCleanerProvider.java index ff579b4..86b5e86 100644 --- a/cayenne-server/src/test/java/org/apache/cayenne/unit/di/server/DBCleanerProvider.java +++ b/cayenne-server/src/test/java/org/apache/cayenne/unit/di/server/DBCleanerProvider.java @@ -32,12 +32,9 @@ public class DBCleanerProvider implements Provider<DBCleaner> { @Inject protected Provider<ServerCaseProperties> propertiesProvider; - @Inject - private SchemaBuilder schemaBuilder; - @Override public DBCleaner get() throws ConfigurationException { - return new DBCleaner((FlavoredDBHelper) dbHelper, schemaBuilder.getDomain(), propertiesProvider.get().getConfigurationLocation()); + return new DBCleaner((FlavoredDBHelper) dbHelper, propertiesProvider.get().getConfigurationLocation()); } } http://git-wip-us.apache.org/repos/asf/cayenne/blob/62d137cf/cayenne-server/src/test/java/org/apache/cayenne/unit/di/server/SchemaBuilder.java ---------------------------------------------------------------------- diff --git a/cayenne-server/src/test/java/org/apache/cayenne/unit/di/server/SchemaBuilder.java b/cayenne-server/src/test/java/org/apache/cayenne/unit/di/server/SchemaBuilder.java index 02bd5fe..880f697 100644 --- a/cayenne-server/src/test/java/org/apache/cayenne/unit/di/server/SchemaBuilder.java +++ b/cayenne-server/src/test/java/org/apache/cayenne/unit/di/server/SchemaBuilder.java @@ -203,6 +203,23 @@ public class SchemaBuilder { private List<DbEntity> dbEntitiesInInsertOrder(DataNode node, DataMap map) { List<DbEntity> entities = new ArrayList<DbEntity>(map.getDbEntities()); + dbEntitiesFilter(entities); + + domain.getEntitySorter().sortDbEntities(entities, false); + return entities; + } + + protected List<DbEntity> dbEntitiesInDeleteOrder(DataMap dataMap) { + DataMap map = domain.getDataMap(dataMap.getName()); + List<DbEntity> entities = new ArrayList<DbEntity>(map.getDbEntities()); + + dbEntitiesFilter(entities); + + domain.getEntitySorter().sortDbEntities(entities, true); + return entities; + } + + private void dbEntitiesFilter(List<DbEntity> entities) { // filter various unsupported tests... // LOBs @@ -258,9 +275,6 @@ public class SchemaBuilder { entities = filtered; } - - domain.getEntitySorter().sortDbEntities(entities, false); - return entities; } private void dropSchema(DataNode node, DataMap map) throws Exception { @@ -367,8 +381,4 @@ public class SchemaBuilder { return queries; } - protected DataDomain getDomain() { - return domain; - } - }