cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject [2/4] cayenne git commit: improve DBCleaner without filtering
Date Sat, 22 Nov 2014 10:44:42 GMT
improve DBCleaner without filtering


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

Branch: refs/heads/master
Commit: a5559d7d4b7e55725e15b64068f2b41596060075
Parents: df3494b
Author: Savva Kolbechev <s.kolbachev@gmail.com>
Authored: Wed Nov 19 18:03:30 2014 +0300
Committer: Savva Kolbechev <s.kolbachev@gmail.com>
Committed: Wed Nov 19 18:03:30 2014 +0300

----------------------------------------------------------------------
 .../cayenne/unit/di/server/DBCleaner.java       | 225 +++----------------
 .../unit/di/server/DBCleanerProvider.java       |   5 +-
 .../cayenne/unit/di/server/SchemaBuilder.java   |   5 +
 .../unit/di/server/ServerCaseModule.java        |   6 +
 4 files changed, 50 insertions(+), 191 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cayenne/blob/a5559d7d/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 3bd680c..e28525b 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,109 +19,49 @@
 
 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;
 import org.apache.cayenne.di.Inject;
+import org.apache.cayenne.di.Injector;
+import org.apache.cayenne.map.DataMap;
+import org.apache.cayenne.map.DbEntity;
+import org.apache.cayenne.resource.URLResource;
 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 UnitDbAdapter accessStackAdapter;
 
-    public DBCleaner(FlavoredDBHelper dbHelper, String location) {
+    @Inject
+    private Injector injector;
+
+    public DBCleaner(FlavoredDBHelper dbHelper, DataDomain dataDomain, String location) {
         this.dbHelper = dbHelper;
         this.location = location;
+        this.domain = dataDomain;
     }
 
     public void clean() throws SQLException {
-        if (location.equals(CayenneProjects.TESTMAP_PROJECT)) {
-            dbHelper.deleteAll("PAINTING_INFO");
-            dbHelper.deleteAll("PAINTING");
-            dbHelper.deleteAll("PAINTING1");
-            dbHelper.deleteAll("ARTIST_EXHIBIT");
-            dbHelper.deleteAll("ARTIST_GROUP");
-            dbHelper.deleteAll("ARTIST");
-            dbHelper.deleteAll("ARTGROUP");
-            dbHelper.deleteAll("EXHIBIT");
-            dbHelper.deleteAll("GALLERY");
-            dbHelper.deleteAll("ARTIST_CT");
-            dbHelper.deleteAll("GENERATED_COLUMN");
-            dbHelper.deleteAll("NULL_TEST");
-        } else if (location.equals(CayenneProjects.MULTI_TIER_PROJECT)) {
-            dbHelper.deleteAll("MT_TABLE2");
-            dbHelper.deleteAll("MT_TABLE1");
-            dbHelper.deleteAll("MT_JOIN45");
-            dbHelper.deleteAll("MT_TABLE4");
-            dbHelper.deleteAll("MT_TABLE5");
-        } else if (location.equals(CayenneProjects.COMPOUND_PROJECT)) {
-            dbHelper.deleteAll("CHAR_FK_TEST");
-            dbHelper.deleteAll("CHAR_PK_TEST");
-            dbHelper.deleteAll("COMPOUND_FK_TEST");
-            dbHelper.deleteAll("COMPOUND_PK_TEST");
-        } else if (location.equals(CayenneProjects.PEOPLE_PROJECT)) {
-            dbHelper.deleteAll("ADDRESS");
-            dbHelper.deleteAll("DEPARTMENT");
-            dbHelper.deleteAll("PERSON_NOTES");
-            dbHelper.deleteAll("PERSON");
-            dbHelper.deleteAll("CLIENT_COMPANY");
-        } else if (location.equals(CayenneProjects.BINARY_PK_PROJECT)) {
+        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.DATE_TIME_PROJECT)) {
-            dbHelper.deleteAll("CALENDAR_TEST");
-            dbHelper.deleteAll("DATE_TEST");
-        } else if (location.equals(CayenneProjects.DELETE_RULES_PROJECT)) {
-            dbHelper.deleteAll("DELETE_CASCADE");
-            dbHelper.deleteAll("DELETE_DENY");
-            dbHelper.deleteAll("DELETE_NULLIFY");
-            dbHelper.deleteAll("DELETE_RULE");
-        } else if (location.equals(CayenneProjects.EMBEDDABLE_PROJECT)) {
-            dbHelper.deleteAll("EMBED_ENTITY1");
         } else if (location.equals(CayenneProjects.EMPTY_PROJECT)) {
             return;
-        } else if (location.equals(CayenneProjects.ENUM_PROJECT)) {
-            dbHelper.deleteAll("ENUM_ENTITY");
-        } else if (location.equals(CayenneProjects.EXTENDED_TYPE_PROJECT)) {
-            dbHelper.deleteAll("EXTENDED_TYPE_TEST");
-        } else if (location.equals(CayenneProjects.GENERATED_PROJECT)) {
-            dbHelper.deleteAll("GENERATED_JOIN");
-            dbHelper.deleteAll("GENERATED_F1");
-            dbHelper.deleteAll("GENERATED_F2");
-            dbHelper.deleteAll("GENERATED_COLUMN_DEP");
-            dbHelper.deleteAll("GENERATED_COLUMN_TEST");
-            dbHelper.deleteAll("GENERATED_COLUMN_TEST2");
-            dbHelper.deleteAll("GENERATED_COLUMN_COMP_KEY");
-            dbHelper.deleteAll("GENERATED_COLUMN_COMP_M");
-        } else if (location.equals(CayenneProjects.GENERIC_PROJECT)) {
-            dbHelper.deleteAll("GENERIC2");
-            dbHelper.deleteAll("GENERIC1");
-        } else if (location.equals(CayenneProjects.INHERITANCE_PROJECT)) {
-            dbHelper.deleteAll("BASE_ENTITY");
-            dbHelper.deleteAll("DIRECT_TO_SUB_ENTITY");
-            dbHelper.deleteAll("RELATED_ENTITY");
-        } else if (location.equals(CayenneProjects.INHERITANCE_SINGLE_TABLE1_PROJECT)) {
-            dbHelper.deleteAll("GROUP_MEMBERS");
-            dbHelper.deleteAll("USER_PROPERTIES");
-            dbHelper.deleteAll("GROUP_PROPERTIES");
-            dbHelper.deleteAll("ROLES");
-        } else if (location.equals(CayenneProjects.INHERITANCE_VERTICAL_PROJECT)) {
-            dbHelper.deleteAll("IV_SUB1_SUB1");
-            dbHelper.deleteAll("IV_SUB1");
-            dbHelper.deleteAll("IV_SUB2");
-            dbHelper.deleteAll("IV_ROOT");
-            dbHelper.deleteAll("IV1_SUB1");
-            dbHelper.deleteAll("IV1_ROOT");
-            dbHelper.deleteAll("IV2_SUB1");
-            dbHelper.deleteAll("IV2_ROOT");
-            dbHelper.deleteAll("IV2_X");
-        } else if (location.equals(CayenneProjects.LIFECYCLES_PROJECT)) {
-            dbHelper.deleteAll("LIFECYCLES");
         } else if (location.equals(CayenneProjects.LOB_PROJECT)) {
             dbHelper.deleteAll("CLOB_TEST_RELATION");
             if (accessStackAdapter.supportsLobs()) {
@@ -129,129 +69,34 @@ public class DBCleaner {
                 dbHelper.deleteAll("CLOB_TEST");
             }
             dbHelper.deleteAll("TEST");
-        } else if (location.equals(CayenneProjects.LOCKING_PROJECT)) {
-            dbHelper.deleteAll("LOCKING_HELPER");
-            dbHelper.deleteAll("REL_LOCKING_TEST");
-            dbHelper.deleteAll("SIMPLE_LOCKING_TEST");
-        } else if (location.equals(CayenneProjects.MAP_TO_MANY_PROJECT)) {
-            dbHelper.deleteAll("ID_MAP_TO_MANY_TARGET");
-            dbHelper.deleteAll("ID_MAP_TO_MANY");
-            dbHelper.deleteAll("MAP_TO_MANY_TARGET");
-            dbHelper.deleteAll("MAP_TO_MANY");
-        } else if (location.equals(CayenneProjects.MEANINGFUL_PK_PROJECT)) {
-            dbHelper.deleteAll("MEANINGFUL_PK");
-            dbHelper.deleteAll("MEANINGFUL_PK_DEP");
-            dbHelper.deleteAll("MEANINGFUL_PK_TEST1");
         } 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.MIXED_PERSISTENCE_STRATEGY_PROJECT)) {
-            dbHelper.deleteAll("MIXED_PERSISTENCE_STRATEGY2");
-            dbHelper.deleteAll("MIXED_PERSISTENCE_STRATEGY");
-        } else if (location.equals(CayenneProjects.MULTINODE_PROJECT)) {
-            dbHelper.deleteAll("CROSSDB_M1E1");
-            dbHelper.deleteAll("CROSSDB_M2E1");
-            dbHelper.deleteAll("CROSSDB_M2E2");
-        } else if (location.equals(CayenneProjects.NO_PK_PROJECT)) {
-            dbHelper.deleteAll("NO_PK_TEST");
-        } else if (location.equals(CayenneProjects.NUMERIC_TYPES_PROJECT)) {
-            dbHelper.deleteAll("BIGDECIMAL_ENTITY");
-            dbHelper.deleteAll("BIGINTEGER_ENTITY");
-            dbHelper.deleteAll("BOOLEAN_TEST");
-            dbHelper.deleteAll("BIT_TEST");
-            dbHelper.deleteAll("SMALLINT_TEST");
-            dbHelper.deleteAll("TINYINT_TEST");
-            dbHelper.deleteAll("DECIMAL_PK_TST");
-            dbHelper.deleteAll("FLOAT_TEST");
-            dbHelper.deleteAll("LONG_ENTITY");
-        } else if (location.equals(CayenneProjects.ONEWAY_PROJECT)) {
-            dbHelper.deleteAll("oneway_table2");
-            dbHelper.deleteAll("oneway_table1");
-            dbHelper.deleteAll("oneway_table4");
-            dbHelper.deleteAll("oneway_table3");
-        } else if (location.equals(CayenneProjects.PERSISTENT_PROJECT)) {
-            dbHelper.deleteAll("CONTINENT");
-            dbHelper.deleteAll("COUNTRY");
-        } else if (location.equals(CayenneProjects.PRIMITIVE_PROJECT)) {
-            dbHelper.deleteAll("PRIMITIVES_TEST");
-        } else if (location.equals(CayenneProjects.QUALIFIED_PROJECT)) {
-            dbHelper.deleteAll("TEST_QUALIFIED2");
-            dbHelper.deleteAll("TEST_QUALIFIED1");
-        } else if (location.equals(CayenneProjects.QUOTED_IDENTIFIERS_PROJECT)) {
-            dbHelper.deleteAll("quote Person");
-            dbHelper.deleteAll("QUOTED_ADDRESS");
-        } else if (location.equals(CayenneProjects.REFLEXIVE_PROJECT)) {
-            dbHelper.deleteAll("REFLEXIVE");
-        } else if (location.equals(CayenneProjects.RELATIONSHIPS_PROJECT)) {
-            dbHelper.deleteAll("FK_OF_DIFFERENT_TYPE");
-            dbHelper.deleteAll("REFLEXIVE_AND_TO_ONE");
-            dbHelper.deleteAll("RELATIONSHIP_HELPER");
-            dbHelper.deleteAll("MEANINGFUL_FK");
-        } else if (location.equals(CayenneProjects.RELATIONSHIPS_ACTIVITY_PROJECT)) {
-            dbHelper.deleteAll("ACTIVITY");
-            dbHelper.deleteAll("RESULT");
-        } else if (location.equals(CayenneProjects.RELATIONSHIPS_CHILD_MASTER_PROJECT)) {
-            dbHelper.deleteAll("CHILD");
-            dbHelper.deleteAll("MASTER");
-        } else if (location.equals(CayenneProjects.RELATIONSHIPS_CLOB_PROJECT)) {
-            dbHelper.deleteAll("CLOB_DETAIL");
-            dbHelper.deleteAll("CLOB_MASTER");
-        } else if (location.equals(CayenneProjects.RELATIONSHIPS_COLLECTION_TO_MANY_PROJECT))
{
-            dbHelper.deleteAll("COLLECTION_TO_MANY_TARGET");
-            dbHelper.deleteAll("COLLECTION_TO_MANY");
-        } else if (location.equals(CayenneProjects.RELATIONSHIPS_DELETE_RULES_PROJECT)) {
-            dbHelper.deleteAll("DELETE_RULE_TEST3");
-            dbHelper.deleteAll("DELETE_RULE_TEST1");
-            dbHelper.deleteAll("DELETE_RULE_TEST2");
-            dbHelper.deleteAll("DELETE_RULE_JOIN");
-            dbHelper.deleteAll("DELETE_RULE_FLATB");
-            dbHelper.deleteAll("DELETE_RULE_FLATA");
-        } else if (location.equals(CayenneProjects.RELATIONSHIPS_FLATTENED_PROJECT)) {
-            dbHelper.deleteAll("COMPLEX_JOIN");
-            dbHelper.deleteAll("FLATTENED_TEST_4");
-            dbHelper.deleteAll("FLATTENED_TEST_3");
-            dbHelper.deleteAll("FLATTENED_TEST_2");
-            dbHelper.deleteAll("FLATTENED_TEST_1");
-            dbHelper.deleteAll("FLATTENED_CIRCULAR_JOIN");
-            dbHelper.deleteAll("FLATTENED_CIRCULAR");
-        } else if (location.equals(CayenneProjects.RELATIONSHIPS_SET_TO_MANY_PROJECT)) {
-            dbHelper.deleteAll("SET_TO_MANY_TARGET");
-            dbHelper.deleteAll("SET_TO_MANY");
-        } else if (location.equals(CayenneProjects.RELATIONSHIPS_TO_MANY_FK_PROJECT)) {
-            dbHelper.deleteAll("TO_MANY_FKDEP");
-            dbHelper.deleteAll("TO_MANY_FKROOT");
-            dbHelper.deleteAll("TO_MANY_ROOT2");
-        } else if (location.equals(CayenneProjects.RELATIONSHIPS_TO_ONE_FK_PROJECT)) {
-            dbHelper.deleteAll("TO_ONE_FK1");
-            dbHelper.deleteAll("TO_ONE_FK2");
         } 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 if (location.equals(CayenneProjects.SOFT_DELETE_PROJECT)) {
-            dbHelper.deleteAll("SOFT_DELETE");
-        } else if (location.equals(CayenneProjects.SUS_PROJECT)) {
-            return;
-        } else if (location.equals(CayenneProjects.TABLE_PRIMITIVES_PROJECT)) {
-            dbHelper.deleteAll("TABLE_PRIMITIVES");
-        } else if (location.equals(CayenneProjects.THINGS_PROJECT)) {
-            dbHelper.deleteAll("BALL");
-            dbHelper.deleteAll("BOX_THING");
-            dbHelper.deleteAll("THING");
-            dbHelper.deleteAll("BOX_INFO");
-            dbHelper.deleteAll("BOX");
-            dbHelper.deleteAll("BAG");
-        } else if (location.equals(CayenneProjects.TOONE_PROJECT)) {
-            dbHelper.deleteAll("TOONE_DEP");
-            dbHelper.deleteAll("TOONE_MASTER");
-        } else if (location.equals(CayenneProjects.UUID_PROJECT)) {
-            dbHelper.deleteAll("UUID_TEST");
-            dbHelper.deleteAll("UUID_PK_ENTITY");
+        } else {
+            loader = new XMLDataChannelDescriptorLoader();
+            injector.injectMembers(loader);
+
+            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 (DbEntity entity : entities) {
+                    dbHelper.deleteAll(entity.getName());
+                }
+            }
         }
     }
 }

http://git-wip-us.apache.org/repos/asf/cayenne/blob/a5559d7d/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 86b5e86..ff579b4 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,9 +32,12 @@ 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, propertiesProvider.get().getConfigurationLocation());
+        return new DBCleaner((FlavoredDBHelper) dbHelper, schemaBuilder.getDomain(), propertiesProvider.get().getConfigurationLocation());
     }
 
 }

http://git-wip-us.apache.org/repos/asf/cayenne/blob/a5559d7d/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 a497e0d..02bd5fe 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
@@ -366,4 +366,9 @@ public class SchemaBuilder {
 
         return queries;
     }
+
+    protected DataDomain getDomain() {
+        return domain;
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/cayenne/blob/a5559d7d/cayenne-server/src/test/java/org/apache/cayenne/unit/di/server/ServerCaseModule.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/unit/di/server/ServerCaseModule.java
b/cayenne-server/src/test/java/org/apache/cayenne/unit/di/server/ServerCaseModule.java
index 4bf0bbb..b24aef9 100644
--- a/cayenne-server/src/test/java/org/apache/cayenne/unit/di/server/ServerCaseModule.java
+++ b/cayenne-server/src/test/java/org/apache/cayenne/unit/di/server/ServerCaseModule.java
@@ -42,11 +42,15 @@ import org.apache.cayenne.access.types.TimestampType;
 import org.apache.cayenne.access.types.UUIDType;
 import org.apache.cayenne.access.types.UtilDateType;
 import org.apache.cayenne.access.types.VoidType;
+import org.apache.cayenne.configuration.ConfigurationNameMapper;
 import org.apache.cayenne.configuration.Constants;
+import org.apache.cayenne.configuration.DataMapLoader;
+import org.apache.cayenne.configuration.DefaultConfigurationNameMapper;
 import org.apache.cayenne.configuration.DefaultObjectStoreFactory;
 import org.apache.cayenne.configuration.DefaultRuntimeProperties;
 import org.apache.cayenne.configuration.ObjectStoreFactory;
 import org.apache.cayenne.configuration.RuntimeProperties;
+import org.apache.cayenne.configuration.XMLDataMapLoader;
 import org.apache.cayenne.configuration.server.DataSourceFactory;
 import org.apache.cayenne.configuration.server.ServerRuntime;
 import org.apache.cayenne.conn.DataSourceInfo;
@@ -208,6 +212,8 @@ public class ServerCaseModule implements Module {
         binder.bind(AdhocObjectFactory.class).to(DefaultAdhocObjectFactory.class);
         binder.bind(ResourceLocator.class).to(ClassLoaderResourceLocator.class);
         binder.bind(ObjectStoreFactory.class).to(DefaultObjectStoreFactory.class);
+        binder.bind(DataMapLoader.class).to(XMLDataMapLoader.class);
+        binder.bind(ConfigurationNameMapper.class).to(DefaultConfigurationNameMapper.class);
 
         // test-scoped objects
         binder.bind(EntityResolver.class).toProvider(


Mime
View raw message