cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject cayenne git commit: fix cdb import maven plugin
Date Thu, 27 Nov 2014 06:57:49 GMT
Repository: cayenne
Updated Branches:
  refs/heads/CAY-1946_1 949b84ff1 -> 67ac9ec0e


fix cdb import maven plugin


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

Branch: refs/heads/CAY-1946_1
Commit: 67ac9ec0e17f8723e72fe45e94bad5c60c33b5d2
Parents: 949b84f
Author: alexkolonitsky <Alex.Kolonitsky@gmail.com>
Authored: Wed Nov 26 16:00:58 2014 +0300
Committer: alexkolonitsky <Alex.Kolonitsky@gmail.com>
Committed: Wed Nov 26 16:00:58 2014 +0300

----------------------------------------------------------------------
 .../access/loader/filters/EntityFilters.java    | 46 ++++++++++----------
 .../loader/filters/IncludeFilterTest.java       | 37 ++++++++++++++++
 .../cayenne/tools/DbImporterMojoTest.java       | 11 +++++
 .../tools/dbimport/testViewsExclude-pom.xml     | 41 +++++++++++++++++
 .../dbimport/testViewsExclude.map.xml-result    | 43 ++++++++++++++++++
 .../cayenne/tools/dbimport/testViewsExclude.sql | 14 ++++++
 6 files changed, 170 insertions(+), 22 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cayenne/blob/67ac9ec0/cayenne-server/src/main/java/org/apache/cayenne/access/loader/filters/EntityFilters.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/main/java/org/apache/cayenne/access/loader/filters/EntityFilters.java
b/cayenne-server/src/main/java/org/apache/cayenne/access/loader/filters/EntityFilters.java
index 3c25196..acfa38c 100644
--- a/cayenne-server/src/main/java/org/apache/cayenne/access/loader/filters/EntityFilters.java
+++ b/cayenne-server/src/main/java/org/apache/cayenne/access/loader/filters/EntityFilters.java
@@ -326,10 +326,7 @@ public class EntityFilters {
                 return this;
             }
 
-            for (String pattern : tableFilters.split(",")) {
-                this.tableFilters = this.tableFilters.join(include(pattern));
-            }
-
+            this.tableFilters = includeFilter(tableFilters, this.tableFilters);
             return this;
         }
 
@@ -338,10 +335,7 @@ public class EntityFilters {
                 return this;
             }
 
-            for (String pattern : columnFilters.split(",")) {
-                this.columnFilters = this.columnFilters.join(include(pattern));
-            }
-
+            this.columnFilters = includeFilter(columnFilters, this.columnFilters);
             return this;
         }
 
@@ -350,11 +344,16 @@ public class EntityFilters {
                 return this;
             }
 
-            for (String pattern : proceduresFilters.split(",")) {
-                this.proceduresFilters = this.proceduresFilters.join(include(pattern));
+            this.proceduresFilters = includeFilter(proceduresFilters, this.proceduresFilters);
+            return this;
+        }
+
+        private Filter<String> includeFilter(String tableFilters, Filter<String>
filter) {
+            for (String pattern : tableFilters.split(",")) {
+                filter = filter.join(include(transform(pattern)));
             }
 
-            return this;
+            return filter;
         }
 
         public Builder excludeTables(String tableFilters) {
@@ -362,10 +361,7 @@ public class EntityFilters {
                 return this;
             }
 
-            for (String pattern : tableFilters.split(",")) {
-                this.tableFilters = this.tableFilters.join(exclude(pattern));
-            }
-
+            this.tableFilters = excludeFilter(tableFilters, this.tableFilters);
             return this;
         }
 
@@ -374,10 +370,7 @@ public class EntityFilters {
                 return this;
             }
 
-            for (String pattern : columnFilters.split(",")) {
-                this.columnFilters = this.columnFilters.join(exclude(pattern));
-            }
-
+            this.columnFilters = excludeFilter(columnFilters, this.columnFilters);
             return this;
         }
 
@@ -386,11 +379,20 @@ public class EntityFilters {
                 return this;
             }
 
-            for (String pattern : proceduresFilters.split(",")) {
-                this.proceduresFilters = this.proceduresFilters.join(exclude(pattern));
+            this.proceduresFilters = excludeFilter(proceduresFilters, this.proceduresFilters);
+            return this;
+        }
+
+        private Filter<String> excludeFilter(String tableFilters, Filter<String>
filter) {
+            for (String pattern : tableFilters.split(",")) {
+                filter = filter.join(exclude(transform(pattern)));
             }
 
-            return this;
+            return filter;
+        }
+
+        private static String transform(String pattern) {
+            return "^" + pattern.replaceAll("[*?]", ".$0") + "$";
         }
 
         public Filter<String> tableFilters() {

http://git-wip-us.apache.org/repos/asf/cayenne/blob/67ac9ec0/cayenne-server/src/test/java/org/apache/cayenne/access/loader/filters/IncludeFilterTest.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/access/loader/filters/IncludeFilterTest.java
b/cayenne-server/src/test/java/org/apache/cayenne/access/loader/filters/IncludeFilterTest.java
new file mode 100644
index 0000000..2208c5c
--- /dev/null
+++ b/cayenne-server/src/test/java/org/apache/cayenne/access/loader/filters/IncludeFilterTest.java
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cayenne.access.loader.filters;
+
+import org.junit.Test;
+
+import static org.apache.cayenne.access.loader.filters.FilterFactory.pattern;
+import static org.junit.Assert.*;
+
+public class IncludeFilterTest {
+
+    @Test
+    public void testIsInclude() throws Exception {
+        IncludeFilter filter = new IncludeFilter(pattern("^v_.*$"));
+        assertTrue(filter.isInclude("v_new_view"));
+        assertFalse(filter.isInclude("new_view"));
+        assertFalse(filter.isInclude("view"));
+        assertFalse(filter.isInclude("girl"));
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cayenne/blob/67ac9ec0/plugins/maven-cayenne-plugin/src/test/java/org/apache/cayenne/tools/DbImporterMojoTest.java
----------------------------------------------------------------------
diff --git a/plugins/maven-cayenne-plugin/src/test/java/org/apache/cayenne/tools/DbImporterMojoTest.java
b/plugins/maven-cayenne-plugin/src/test/java/org/apache/cayenne/tools/DbImporterMojoTest.java
index 682f180..ae9d308 100644
--- a/plugins/maven-cayenne-plugin/src/test/java/org/apache/cayenne/tools/DbImporterMojoTest.java
+++ b/plugins/maven-cayenne-plugin/src/test/java/org/apache/cayenne/tools/DbImporterMojoTest.java
@@ -102,6 +102,10 @@ public class DbImporterMojoTest extends AbstractMojoTestCase {
         test("testSchemasAndTableExclude");
     }
 
+    public void testViewsExclude() throws Exception {
+        test("testViewsExclude");
+    }
+
     private void test(String name) throws Exception {
         DbImporterMojo cdbImport = getCdbImport("dbimport/" + name + "-pom.xml");
         File mapFile = cdbImport.getMap();
@@ -129,6 +133,13 @@ public class DbImporterMojoTest extends AbstractMojoTestCase {
         Connection connection = DriverManager.getConnection(dbImportConfiguration.getUrl());
         Statement stmt = connection.createStatement();
 
+        ResultSet views = connection.getMetaData().getTables(null, null, null, new String[]{"VIEW"});
+        while (views.next()) {
+            String schema = views.getString("TABLE_SCHEM");
+            System.out.println("DROP VIEW " + (isBlank(schema) ? "" : schema + ".") + views.getString("TABLE_NAME"));
+            stmt.execute("DROP VIEW " + (isBlank(schema) ? "" : schema + ".") + views.getString("TABLE_NAME"));
+        }
+
         ResultSet tables = connection.getMetaData().getTables(null, null, null, new String[]{"TABLE"});
         while (tables.next()) {
             String schema = tables.getString("TABLE_SCHEM");

http://git-wip-us.apache.org/repos/asf/cayenne/blob/67ac9ec0/plugins/maven-cayenne-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testViewsExclude-pom.xml
----------------------------------------------------------------------
diff --git a/plugins/maven-cayenne-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testViewsExclude-pom.xml
b/plugins/maven-cayenne-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testViewsExclude-pom.xml
new file mode 100644
index 0000000..1f8f25d
--- /dev/null
+++ b/plugins/maven-cayenne-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testViewsExclude-pom.xml
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one
+  or more contributor license agreements.  See the NOTICE file
+  distributed with this work for additional information
+  regarding copyright ownership.  The ASF licenses this file
+  to you under the Apache License, Version 2.0 (the
+  "License"); you may not use this file except in compliance
+  with the License.  You may obtain a copy of the License at
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing,
+  software distributed under the License is distributed on an
+  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+  KIND, either express or implied.  See the License for the
+  specific language governing permissions and limitations
+  under the License.
+  -->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
+	http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+	<name>DbImporterMojo Test1</name>	
+
+	<build>
+		<plugins>
+			<plugin>
+				<artifactId>maven-cayenne-plugin</artifactId>
+				<configuration>
+					<map>target/test-classes/org/apache/cayenne/tools/dbimport/testViewsExclude.map.xml</map>
+                    <driver>org.apache.derby.jdbc.EmbeddedDriver</driver>
+                    <url>jdbc:derby:memory:DbImporterMojoTest;create=true</url>
+
+                    <excludeTables>v_*</excludeTables>
+				</configuration>
+			</plugin>
+		</plugins>
+	</build>
+
+</project>

http://git-wip-us.apache.org/repos/asf/cayenne/blob/67ac9ec0/plugins/maven-cayenne-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testViewsExclude.map.xml-result
----------------------------------------------------------------------
diff --git a/plugins/maven-cayenne-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testViewsExclude.map.xml-result
b/plugins/maven-cayenne-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testViewsExclude.map.xml-result
new file mode 100644
index 0000000..25bf598
--- /dev/null
+++ b/plugins/maven-cayenne-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testViewsExclude.map.xml-result
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+    Licensed to the Apache Software Foundation (ASF) under one
+    or more contributor license agreements.  See the NOTICE file
+    distributed with this work for additional information
+    regarding copyright ownership.  The ASF licenses this file
+    to you under the Apache License, Version 2.0 (the
+    "License"); you may not use this file except in compliance
+    with the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing,
+    software distributed under the License is distributed on an
+    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+    KIND, either express or implied.  See the License for the
+    specific language governing permissions and limitations
+    under the License.
+-->
+<data-map xmlns="http://cayenne.apache.org/schema/7/modelMap"
+          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+          xsi:schemaLocation="http://cayenne.apache.org/schema/7/modelMap http://cayenne.apache.org/schema/7/modelMap.xsd"
+          project-version="7">
+    <db-entity name="GIRL" schema="APP">
+        <db-attribute name="ID" type="INTEGER" isMandatory="true" length="10"/>
+    </db-entity>
+    <db-entity name="PERSON" schema="APP">
+        <db-attribute name="COL2" type="CHAR" length="25"/>
+        <db-attribute name="COL3" type="DECIMAL" length="10" scale="2"/>
+        <db-attribute name="COL4" type="VARCHAR" length="25"/>
+        <db-attribute name="COL5" type="DATE" length="10"/>
+        <db-attribute name="ID" type="INTEGER" isPrimaryKey="true" isMandatory="true"
length="10"/>
+    </db-entity>
+    <obj-entity name="Girl" className="Girl" dbEntityName="GIRL">
+        <obj-attribute name="id" type="java.lang.Integer" db-attribute-path="ID"/>
+    </obj-entity>
+    <obj-entity name="Person" className="Person" dbEntityName="PERSON">
+        <obj-attribute name="col2" type="java.lang.String" db-attribute-path="COL2"/>
+        <obj-attribute name="col3" type="java.math.BigDecimal" db-attribute-path="COL3"/>
+        <obj-attribute name="col4" type="java.lang.String" db-attribute-path="COL4"/>
+        <obj-attribute name="col5" type="java.util.Date" db-attribute-path="COL5"/>
+    </obj-entity>
+</data-map>

http://git-wip-us.apache.org/repos/asf/cayenne/blob/67ac9ec0/plugins/maven-cayenne-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testViewsExclude.sql
----------------------------------------------------------------------
diff --git a/plugins/maven-cayenne-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testViewsExclude.sql
b/plugins/maven-cayenne-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testViewsExclude.sql
new file mode 100644
index 0000000..5e32df5
--- /dev/null
+++ b/plugins/maven-cayenne-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testViewsExclude.sql
@@ -0,0 +1,14 @@
+
+CREATE TABLE Person (
+  id INTEGER NOT NULL,
+  COL2 CHAR(25),
+  COL3 DECIMAL(10,2),
+  COL4 VARCHAR(25),
+  COL5 DATE,
+
+  PRIMARY KEY (id),
+  UNIQUE (COL3)
+);
+
+CREATE VIEW girl (id) AS SELECT id FROM Person;
+CREATE VIEW v_vview (id) AS SELECT id FROM Person;
\ No newline at end of file


Mime
View raw message