You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cayenne.apache.org by aa...@apache.org on 2014/10/29 19:40:37 UTC
[2/7] CAY-1946 CDbimport improvements
http://git-wip-us.apache.org/repos/asf/cayenne/blob/fde7761f/cayenne-tools/src/test/resources/org/apache/cayenne/tools/build-schema.xml
----------------------------------------------------------------------
diff --git a/cayenne-tools/src/test/resources/org/apache/cayenne/tools/build-schema.xml b/cayenne-tools/src/test/resources/org/apache/cayenne/tools/build-schema.xml
new file mode 100644
index 0000000..2d7bb6b
--- /dev/null
+++ b/cayenne-tools/src/test/resources/org/apache/cayenne/tools/build-schema.xml
@@ -0,0 +1,83 @@
+<!--
+ ~ 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 name="MyProject" default="dist" basedir=".">
+
+ <taskdef name="cdbimport" classname="org.apache.cayenne.tools.DbImporterTask" taskname="cdbimport"
+ classpath="${basedir}" />
+
+ <target name="dist">
+ <cdbimport map="${context.dir}/WEB-INF/DefaultMap.map.xml"
+ adapter="org.apache.cayenne.dba.hsqldb.HSQLDBAdapter"
+ driver="org.hsqldb.jdbcDriver"
+ url="jdbc:hsqldb:hsql://localhost/bookmarker"
+ username="sa">
+
+ <schema>schema-name-01</schema>
+
+ <schema>
+ <name>schema-name-02</name>
+ </schema>
+
+ <schema name="schema-name-03">
+ <includeTable>includeTable-01</includeTable>
+
+ <includeTable>
+ <pattern>includeTable-02</pattern>
+ </includeTable>
+
+ <includeTable pattern="includeTable-03">
+ <includeColumn pattern="includeColumn-01" />
+ <excludeColumn pattern="excludeColumn-01" />
+ </includeTable>
+
+ <excludeTable>excludeTable-01</excludeTable>
+ <excludeTable>
+ <pattern>excludeTable-02</pattern>
+ </excludeTable>
+ <excludeTable pattern="excludeTable-03" />
+
+ <includeColumn>includeColumn-01</includeColumn>
+ <includeColumn>
+ <pattern>includeColumn-02</pattern>
+ </includeColumn>
+ <includeColumn pattern="includeColumn-03" />
+ <excludeColumn>excludeColumn-01</excludeColumn>
+ <excludeColumn>
+ <pattern>excludeColumn-02</pattern>
+ </excludeColumn>
+ <excludeColumn pattern="excludeColumn-03" />
+
+ <includeProcedure>includeProcedure-01</includeProcedure>
+ <includeProcedure>
+ <pattern>includeProcedure-02</pattern>
+ </includeProcedure>
+ <includeProcedure pattern="includeProcedure-03" />
+ <excludeProcedure>excludeProcedure-01</excludeProcedure>
+ <excludeProcedure>
+ <pattern>excludeProcedure-02</pattern>
+ </excludeProcedure>
+ <excludeProcedure pattern="excludeProcedure-03" />
+ </schema>
+
+ </cdbimport>
+ </target>
+
+
+</project>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/cayenne/blob/fde7761f/cayenne-tools/src/test/resources/org/apache/cayenne/tools/dbimport/build-include-table.map.xml-result
----------------------------------------------------------------------
diff --git a/cayenne-tools/src/test/resources/org/apache/cayenne/tools/dbimport/build-include-table.map.xml-result b/cayenne-tools/src/test/resources/org/apache/cayenne/tools/dbimport/build-include-table.map.xml-result
new file mode 100644
index 0000000..8854a8b
--- /dev/null
+++ b/cayenne-tools/src/test/resources/org/apache/cayenne/tools/dbimport/build-include-table.map.xml-result
@@ -0,0 +1,37 @@
+<?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="PARENT" 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="Parent" className="Parent" dbEntityName="PARENT">
+ <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>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/cayenne/blob/fde7761f/cayenne-tools/src/test/resources/org/apache/cayenne/tools/dbimport/build-include-table.xml
----------------------------------------------------------------------
diff --git a/cayenne-tools/src/test/resources/org/apache/cayenne/tools/dbimport/build-include-table.xml b/cayenne-tools/src/test/resources/org/apache/cayenne/tools/dbimport/build-include-table.xml
new file mode 100644
index 0000000..897869d
--- /dev/null
+++ b/cayenne-tools/src/test/resources/org/apache/cayenne/tools/dbimport/build-include-table.xml
@@ -0,0 +1,35 @@
+<!--
+ ~ 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 name="MyProject" default="dist" basedir="../">
+
+ <taskdef name="cdbimport" classname="org.apache.cayenne.tools.DbImporterTask" taskname="cdbimport"
+ classpath="${basedir}" />
+
+ <target name="dist">
+ <cdbimport map="dbimport/build-include-table.map.xml"
+ driver="org.apache.derby.jdbc.EmbeddedDriver"
+ url="jdbc:derby:memory:DbImporterMojoTest;create=true">
+
+ <includeTable>Parent</includeTable>
+ </cdbimport>
+ </target>
+
+
+</project>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/cayenne/blob/fde7761f/cayenne-tools/src/test/resources/org/apache/cayenne/tools/dbimport/build-include-table.xml.sql
----------------------------------------------------------------------
diff --git a/cayenne-tools/src/test/resources/org/apache/cayenne/tools/dbimport/build-include-table.xml.sql b/cayenne-tools/src/test/resources/org/apache/cayenne/tools/dbimport/build-include-table.xml.sql
new file mode 100644
index 0000000..fb820b7
--- /dev/null
+++ b/cayenne-tools/src/test/resources/org/apache/cayenne/tools/dbimport/build-include-table.xml.sql
@@ -0,0 +1,20 @@
+CREATE TABLE Parent (
+ id INTEGER NOT NULL,
+ COL2 CHAR(25),
+ COL3 DECIMAL(10,2),
+ COL4 VARCHAR(25),
+ COL5 DATE,
+
+ PRIMARY KEY (id),
+ UNIQUE (COL3)
+);
+
+CREATE TABLE Child (
+ id INTEGER NOT NULL,
+ Parent_id CHAR(25),
+ COL3 DECIMAL(10,2),
+ COL4 VARCHAR(25),
+ COL5 DATE,
+
+ PRIMARY KEY (id)
+);
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/cayenne/blob/fde7761f/cayenne-tools/src/test/resources/org/apache/cayenne/tools/dbimport/config/reverseEngineering-ant-mapping.xml
----------------------------------------------------------------------
diff --git a/cayenne-tools/src/test/resources/org/apache/cayenne/tools/dbimport/config/reverseEngineering-ant-mapping.xml b/cayenne-tools/src/test/resources/org/apache/cayenne/tools/dbimport/config/reverseEngineering-ant-mapping.xml
new file mode 100644
index 0000000..4bdd44a
--- /dev/null
+++ b/cayenne-tools/src/test/resources/org/apache/cayenne/tools/dbimport/config/reverseEngineering-ant-mapping.xml
@@ -0,0 +1,31 @@
+<?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.
+ -->
+
+<reverseEngineering>
+
+ <typeMapper mapperClassName="class" usePrimitives="false">
+ <type java="my.personal.type" jdbc="varchar" />
+ <type java="java-01" jdbc="jdbc-01" />
+ <type java="java-02" jdbc="jdbc-02" length="21" notNull="true" />
+ <type java="java-03" jdbc="jdbc-03" precision="5" scale="2" />
+ <type java="java-03" jdbc="jdbc-03" precision="7" notNull="true" />
+ </typeMapper>
+
+</reverseEngineering>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/cayenne/blob/fde7761f/cayenne-tools/src/test/resources/org/apache/cayenne/tools/dbimport/config/reverseEngineering-catalog-and-schema.xml
----------------------------------------------------------------------
diff --git a/cayenne-tools/src/test/resources/org/apache/cayenne/tools/dbimport/config/reverseEngineering-catalog-and-schema.xml b/cayenne-tools/src/test/resources/org/apache/cayenne/tools/dbimport/config/reverseEngineering-catalog-and-schema.xml
new file mode 100644
index 0000000..46c26d0
--- /dev/null
+++ b/cayenne-tools/src/test/resources/org/apache/cayenne/tools/dbimport/config/reverseEngineering-catalog-and-schema.xml
@@ -0,0 +1,65 @@
+<?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.
+ -->
+
+<reverseEngineering>
+ <catalog name="catalog-name">
+ <schema name="schema-name">
+ <includeTable>includeTable-01</includeTable>
+
+ <includeTable>
+ <pattern>includeTable-02</pattern>
+ </includeTable>
+
+ <includeTable pattern="includeTable-03">
+ <includeColumn pattern="includeColumn-01" />
+ <excludeColumn pattern="excludeColumn-01" />
+ </includeTable>
+
+ <excludeTable>excludeTable-01</excludeTable>
+ <excludeTable>
+ <pattern>excludeTable-02</pattern>
+ </excludeTable>
+ <excludeTable pattern="excludeTable-03" />
+
+ <includeColumn>includeColumn-01</includeColumn>
+ <includeColumn>
+ <pattern>includeColumn-02</pattern>
+ </includeColumn>
+ <includeColumn pattern="includeColumn-03" />
+ <excludeColumn>excludeColumn-01</excludeColumn>
+ <excludeColumn>
+ <pattern>excludeColumn-02</pattern>
+ </excludeColumn>
+ <excludeColumn pattern="excludeColumn-03" />
+
+ <includeProcedure>includeProcedure-01</includeProcedure>
+ <includeProcedure>
+ <pattern>includeProcedure-02</pattern>
+ </includeProcedure>
+ <includeProcedure pattern="includeProcedure-03" />
+ <excludeProcedure>excludeProcedure-01</excludeProcedure>
+ <excludeProcedure>
+ <pattern>excludeProcedure-02</pattern>
+ </excludeProcedure>
+ <excludeProcedure pattern="excludeProcedure-03" />
+ </schema>
+ </catalog>
+
+</reverseEngineering>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/cayenne/blob/fde7761f/cayenne-tools/src/test/resources/org/apache/cayenne/tools/dbimport/config/reverseEngineering-catalog.xml
----------------------------------------------------------------------
diff --git a/cayenne-tools/src/test/resources/org/apache/cayenne/tools/dbimport/config/reverseEngineering-catalog.xml b/cayenne-tools/src/test/resources/org/apache/cayenne/tools/dbimport/config/reverseEngineering-catalog.xml
new file mode 100644
index 0000000..d820aa4
--- /dev/null
+++ b/cayenne-tools/src/test/resources/org/apache/cayenne/tools/dbimport/config/reverseEngineering-catalog.xml
@@ -0,0 +1,68 @@
+<?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.
+ -->
+
+<reverseEngineering>
+ <catalog>catalog-name-01</catalog>
+
+ <catalog>
+ <name>catalog-name-02</name>
+ </catalog>
+
+ <catalog name="catalog-name-03">
+ <includeTable>includeTable-01</includeTable>
+
+ <includeTable>
+ <pattern>includeTable-02</pattern>
+ </includeTable>
+
+ <includeTable pattern="includeTable-03">
+ <includeColumn pattern="includeColumn-01" />
+ <excludeColumn pattern="excludeColumn-01" />
+ </includeTable>
+
+ <excludeTable>excludeTable-01</excludeTable>
+ <excludeTable>
+ <pattern>excludeTable-02</pattern>
+ </excludeTable>
+ <excludeTable pattern="excludeTable-03" />
+
+ <includeColumn>includeColumn-01</includeColumn>
+ <includeColumn>
+ <pattern>includeColumn-02</pattern>
+ </includeColumn>
+ <includeColumn pattern="includeColumn-03" />
+ <excludeColumn>excludeColumn-01</excludeColumn>
+ <excludeColumn>
+ <pattern>excludeColumn-02</pattern>
+ </excludeColumn>
+ <excludeColumn pattern="excludeColumn-03" />
+
+ <includeProcedure>includeProcedure-01</includeProcedure>
+ <includeProcedure>
+ <pattern>includeProcedure-02</pattern>
+ </includeProcedure>
+ <includeProcedure pattern="includeProcedure-03" />
+ <excludeProcedure>excludeProcedure-01</excludeProcedure>
+ <excludeProcedure>
+ <pattern>excludeProcedure-02</pattern>
+ </excludeProcedure>
+ <excludeProcedure pattern="excludeProcedure-03" />
+ </catalog>
+</reverseEngineering>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/cayenne/blob/fde7761f/cayenne-tools/src/test/resources/org/apache/cayenne/tools/dbimport/config/reverseEngineering-flat.xml
----------------------------------------------------------------------
diff --git a/cayenne-tools/src/test/resources/org/apache/cayenne/tools/dbimport/config/reverseEngineering-flat.xml b/cayenne-tools/src/test/resources/org/apache/cayenne/tools/dbimport/config/reverseEngineering-flat.xml
new file mode 100644
index 0000000..5b785af
--- /dev/null
+++ b/cayenne-tools/src/test/resources/org/apache/cayenne/tools/dbimport/config/reverseEngineering-flat.xml
@@ -0,0 +1,61 @@
+<?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.
+ -->
+
+<reverseEngineering>
+ <includeTable>includeTable-01</includeTable>
+
+ <includeTable>
+ <pattern>includeTable-02</pattern>
+ </includeTable>
+
+ <includeTable pattern="includeTable-03">
+ <includeColumn pattern="includeColumn-01" />
+ <excludeColumn pattern="excludeColumn-01" />
+ </includeTable>
+
+ <excludeTable>excludeTable-01</excludeTable>
+ <excludeTable>
+ <pattern>excludeTable-02</pattern>
+ </excludeTable>
+ <excludeTable pattern="excludeTable-03" />
+
+ <includeColumn>includeColumn-01</includeColumn>
+ <includeColumn>
+ <pattern>includeColumn-02</pattern>
+ </includeColumn>
+ <includeColumn pattern="includeColumn-03" />
+ <excludeColumn>excludeColumn-01</excludeColumn>
+ <excludeColumn>
+ <pattern>excludeColumn-02</pattern>
+ </excludeColumn>
+ <excludeColumn pattern="excludeColumn-03" />
+
+ <includeProcedure>includeProcedure-01</includeProcedure>
+ <includeProcedure>
+ <pattern>includeProcedure-02</pattern>
+ </includeProcedure>
+ <includeProcedure pattern="includeProcedure-03" />
+ <excludeProcedure>excludeProcedure-01</excludeProcedure>
+ <excludeProcedure>
+ <pattern>excludeProcedure-02</pattern>
+ </excludeProcedure>
+ <excludeProcedure pattern="excludeProcedure-03" />
+
+</reverseEngineering>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/cayenne/blob/fde7761f/cayenne-tools/src/test/resources/org/apache/cayenne/tools/dbimport/config/reverseEngineering-maven-mapping.xml
----------------------------------------------------------------------
diff --git a/cayenne-tools/src/test/resources/org/apache/cayenne/tools/dbimport/config/reverseEngineering-maven-mapping.xml b/cayenne-tools/src/test/resources/org/apache/cayenne/tools/dbimport/config/reverseEngineering-maven-mapping.xml
new file mode 100644
index 0000000..c9d722e
--- /dev/null
+++ b/cayenne-tools/src/test/resources/org/apache/cayenne/tools/dbimport/config/reverseEngineering-maven-mapping.xml
@@ -0,0 +1,55 @@
+<?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.
+ -->
+
+<reverseEngineering>
+
+ <typeMapper >
+ <mapperClassName>class</mapperClassName>
+ <usePrimitives>false</usePrimitives>
+
+ <type>
+ <java>my.personal.type</java>
+ <jdbc>varchar</jdbc>
+ </type>
+ <type>
+ <java>java-01</java>
+ <jdbc>jdbc-01</jdbc>
+ </type>
+ <type>
+ <java>java-02</java>
+ <jdbc>jdbc-02</jdbc>
+ <length>21</length>
+ <notNull>true</notNull>
+ </type>
+ <type>
+ <java>java-03</java>
+ <jdbc>jdbc-03</jdbc>
+ <precision>5</precision>
+ <scale>2</scale>
+ </type>
+ <type>
+ <java>java-03</java>
+ <jdbc>jdbc-03</jdbc>
+ <precision>7</precision>
+ <notNull>true</notNull>
+ </type>
+ </typeMapper>
+
+</reverseEngineering>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/cayenne/blob/fde7761f/cayenne-tools/src/test/resources/org/apache/cayenne/tools/dbimport/config/reverseEngineering-mixed-mapping.xml
----------------------------------------------------------------------
diff --git a/cayenne-tools/src/test/resources/org/apache/cayenne/tools/dbimport/config/reverseEngineering-mixed-mapping.xml b/cayenne-tools/src/test/resources/org/apache/cayenne/tools/dbimport/config/reverseEngineering-mixed-mapping.xml
new file mode 100644
index 0000000..deb3dab
--- /dev/null
+++ b/cayenne-tools/src/test/resources/org/apache/cayenne/tools/dbimport/config/reverseEngineering-mixed-mapping.xml
@@ -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.
+ -->
+
+<reverseEngineering>
+
+ <typeMapper >
+ <mapperClassName>class</mapperClassName>
+ <usePrimitives>false</usePrimitives>
+
+ <type java="my.personal.type" jdbc="varchar" />
+ <type java="java-01" jdbc="jdbc-01" />
+ <type java="java-02" jdbc="jdbc-02">
+ <length>21</length>
+ <notNull>true</notNull>
+ </type>
+ <type java="java-03" jdbc="jdbc-03">
+ <precision>5</precision>
+ <scale>2</scale>
+ </type>
+ <type precision="7" notNull="true">
+ <java>java-03</java>
+ <jdbc>jdbc-03</jdbc>
+ </type>
+ </typeMapper>
+
+</reverseEngineering>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/cayenne/blob/fde7761f/cayenne-tools/src/test/resources/org/apache/cayenne/tools/dbimport/config/reverseEngineering-schema.xml
----------------------------------------------------------------------
diff --git a/cayenne-tools/src/test/resources/org/apache/cayenne/tools/dbimport/config/reverseEngineering-schema.xml b/cayenne-tools/src/test/resources/org/apache/cayenne/tools/dbimport/config/reverseEngineering-schema.xml
new file mode 100644
index 0000000..97c2c6f
--- /dev/null
+++ b/cayenne-tools/src/test/resources/org/apache/cayenne/tools/dbimport/config/reverseEngineering-schema.xml
@@ -0,0 +1,69 @@
+<?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.
+ -->
+
+<reverseEngineering>
+ <schema>schema-name-01</schema>
+
+ <schema>
+ <name>schema-name-02</name>
+ </schema>
+
+ <schema name="schema-name-03">
+ <includeTable>includeTable-01</includeTable>
+
+ <includeTable>
+ <pattern>includeTable-02</pattern>
+ </includeTable>
+
+ <includeTable pattern="includeTable-03">
+ <includeColumn pattern="includeColumn-01" />
+ <excludeColumn pattern="excludeColumn-01" />
+ </includeTable>
+
+ <excludeTable>excludeTable-01</excludeTable>
+ <excludeTable>
+ <pattern>excludeTable-02</pattern>
+ </excludeTable>
+ <excludeTable pattern="excludeTable-03" />
+
+ <includeColumn>includeColumn-01</includeColumn>
+ <includeColumn>
+ <pattern>includeColumn-02</pattern>
+ </includeColumn>
+ <includeColumn pattern="includeColumn-03" />
+ <excludeColumn>excludeColumn-01</excludeColumn>
+ <excludeColumn>
+ <pattern>excludeColumn-02</pattern>
+ </excludeColumn>
+ <excludeColumn pattern="excludeColumn-03" />
+
+ <includeProcedure>includeProcedure-01</includeProcedure>
+ <includeProcedure>
+ <pattern>includeProcedure-02</pattern>
+ </includeProcedure>
+ <includeProcedure pattern="includeProcedure-03" />
+ <excludeProcedure>excludeProcedure-01</excludeProcedure>
+ <excludeProcedure>
+ <pattern>excludeProcedure-02</pattern>
+ </excludeProcedure>
+ <excludeProcedure pattern="excludeProcedure-03" />
+ </schema>
+
+</reverseEngineering>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/cayenne/blob/fde7761f/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/CreateObjEntityAction.java
----------------------------------------------------------------------
diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/CreateObjEntityAction.java b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/CreateObjEntityAction.java
index 9a0fd41..7381886 100644
--- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/CreateObjEntityAction.java
+++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/CreateObjEntityAction.java
@@ -41,111 +41,106 @@ import org.apache.cayenne.util.EntityMergeSupport;
public class CreateObjEntityAction extends CayenneAction {
- public static String getActionName() {
- return "Create ObjEntity";
- }
-
- /**
- * Constructor for CreateObjEntityAction.
- */
- public CreateObjEntityAction(Application application) {
- super(getActionName(), application);
- }
-
- @Override
- public String getIconName() {
- return "icon-new_objentity.gif";
- }
-
- /**
- * @see org.apache.cayenne.modeler.util.CayenneAction#performAction(ActionEvent)
- */
- @Override
- public void performAction(ActionEvent e) {
- createObjEntity();
- }
-
- protected void createObjEntity() {
- ProjectController mediator = getProjectController();
-
- DataMap dataMap = mediator.getCurrentDataMap();
- ObjEntity entity = new ObjEntity(DefaultUniqueNameGenerator.generate(NameCheckers.objEntity, dataMap));
-
- // init defaults
- entity.setSuperClassName(dataMap.getDefaultSuperclass());
- entity.setDeclaredLockType(dataMap.getDefaultLockType());
-
- DbEntity dbEntity = mediator.getCurrentDbEntity();
- if (dbEntity != null) {
- entity.setDbEntity(dbEntity);
- String baseName = NameConverter.underscoredToJava(dbEntity.getName(), true);
- entity.setName(DefaultUniqueNameGenerator.generate(NameCheckers.objEntity, dbEntity.getDataMap(), baseName));
- }
-
- String pkg = dataMap.getDefaultPackage();
- if (pkg != null) {
- if (!pkg.endsWith(".")) {
- pkg = pkg + ".";
- }
-
- entity.setClassName(pkg + entity.getName());
- }
-
- if (dataMap.isClientSupported()) {
- String clientPkg = dataMap.getDefaultClientPackage();
- if (clientPkg != null) {
- if (!clientPkg.endsWith(".")) {
- clientPkg = clientPkg + ".";
- }
-
- entity.setClientClassName(clientPkg + entity.getName());
- }
-
- entity.setClientSuperClassName(dataMap.getDefaultClientSuperclass());
- }
-
- dataMap.addObjEntity(entity);
-
- // perform the merge
- EntityMergeSupport merger = new EntityMergeSupport(dataMap);
- merger.addEntityMergeListener(DeleteRuleUpdater.getEntityMergeListener());
- merger.synchronizeWithDbEntity(entity);
-
- fireObjEntityEvent(this, mediator, dataMap, entity);
-
- application.getUndoManager().addEdit(new CreateObjEntityUndoableEdit(dataMap, entity));
- }
-
- public void createObjEntity(DataMap dataMap, ObjEntity entity) {
- ProjectController mediator = getProjectController();
- dataMap.addObjEntity(entity);
- fireObjEntityEvent(this, mediator, dataMap, entity);
- }
-
- /**
- * Fires events when a obj entity was added
- */
- static void fireObjEntityEvent(Object src, ProjectController mediator, DataMap dataMap, ObjEntity entity) {
- mediator.fireObjEntityEvent(new EntityEvent(src, entity, MapEvent.ADD));
- EntityDisplayEvent displayEvent = new EntityDisplayEvent(src, entity, dataMap, mediator.getCurrentDataNode(),
- (DataChannelDescriptor) mediator.getProject().getRootNode());
- displayEvent.setMainTabFocus(true);
- mediator.fireObjEntityDisplayEvent(displayEvent);
- }
-
- /**
- * Returns <code>true</code> if path contains a DataMap object.
- */
- @Override
- public boolean enableForPath(ConfigurationNode object) {
- if (object == null) {
- return false;
- }
-
- if (object instanceof ObjEntity) {
- return ((ObjEntity) object).getParent() != null && ((ObjEntity) object).getParent() instanceof DataMap;
- }
-
- return false;
- }
+ public static String getActionName() {
+ return "Create ObjEntity";
+ }
+
+ /**
+ * Constructor for CreateObjEntityAction.
+ */
+ public CreateObjEntityAction(Application application) {
+ super(getActionName(), application);
+ }
+
+ @Override
+ public String getIconName() {
+ return "icon-new_objentity.gif";
+ }
+
+ /**
+ * @see org.apache.cayenne.modeler.util.CayenneAction#performAction(ActionEvent)
+ */
+ @Override
+ public void performAction(ActionEvent e) {
+ createObjEntity();
+ }
+
+ protected void createObjEntity() {
+ ProjectController mediator = getProjectController();
+
+ DataMap dataMap = mediator.getCurrentDataMap();
+ ObjEntity entity = new ObjEntity(DefaultUniqueNameGenerator.generate(NameCheckers.objEntity, dataMap));
+
+ // init defaults
+ entity.setSuperClassName(dataMap.getDefaultSuperclass());
+ entity.setDeclaredLockType(dataMap.getDefaultLockType());
+
+ DbEntity dbEntity = mediator.getCurrentDbEntity();
+ if (dbEntity != null) {
+ entity.setDbEntity(dbEntity);
+ String baseName = NameConverter.underscoredToJava(dbEntity.getName(), true);
+ entity.setName(DefaultUniqueNameGenerator.generate(NameCheckers.objEntity, dbEntity.getDataMap(), baseName));
+ }
+
+ entity.setClassName(dataMap.getNameWithDefaultPackage(entity.getName()));
+
+ if (dataMap.isClientSupported()) {
+ entity.setClientClassName(dataMap.getNameWithDefaultClientPackage(entity.getName()));
+ entity.setClientSuperClassName(dataMap.getDefaultClientSuperclass());
+ }
+
+ dataMap.addObjEntity(entity);
+
+ // perform the merge
+ EntityMergeSupport merger = new EntityMergeSupport(dataMap);
+ merger.addEntityMergeListener(DeleteRuleUpdater.getEntityMergeListener());
+ merger.synchronizeWithDbEntity(entity);
+
+ fireObjEntityEvent(this, mediator, dataMap, entity);
+
+ application.getUndoManager().addEdit(
+ new CreateObjEntityUndoableEdit(dataMap, entity));
+ }
+
+ public void createObjEntity(DataMap dataMap, ObjEntity entity) {
+ ProjectController mediator = getProjectController();
+ dataMap.addObjEntity(entity);
+ fireObjEntityEvent(this, mediator, dataMap, entity);
+ }
+
+ /**
+ * Fires events when a obj entity was added
+ */
+ static void fireObjEntityEvent(
+ Object src,
+ ProjectController mediator,
+ DataMap dataMap,
+ ObjEntity entity) {
+ mediator.fireObjEntityEvent(new EntityEvent(src, entity, MapEvent.ADD));
+ EntityDisplayEvent displayEvent = new EntityDisplayEvent(
+ src,
+ entity,
+ dataMap,
+ mediator.getCurrentDataNode(),
+ (DataChannelDescriptor) mediator.getProject().getRootNode());
+ displayEvent.setMainTabFocus(true);
+ mediator.fireObjEntityDisplayEvent(displayEvent);
+ }
+
+ /**
+ * Returns <code>true</code> if path contains a DataMap object.
+ */
+ @Override
+ public boolean enableForPath(ConfigurationNode object) {
+ if (object == null) {
+ return false;
+ }
+
+ if (object instanceof ObjEntity) {
+ return ((ObjEntity) object).getParent() != null
+ && ((ObjEntity) object).getParent() instanceof DataMap;
+ }
+
+ return false;
+ }
}
http://git-wip-us.apache.org/repos/asf/cayenne/blob/fde7761f/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/MigrateAction.java
----------------------------------------------------------------------
diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/MigrateAction.java b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/MigrateAction.java
index ddc7509..c5f3314 100644
--- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/MigrateAction.java
+++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/MigrateAction.java
@@ -20,8 +20,6 @@
package org.apache.cayenne.modeler.action;
import java.awt.event.ActionEvent;
-import java.sql.SQLException;
-import java.util.ArrayList;
import java.util.List;
import javax.sql.DataSource;
http://git-wip-us.apache.org/repos/asf/cayenne/blob/fde7761f/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/datamap/PackageUpdateController.java
----------------------------------------------------------------------
diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/datamap/PackageUpdateController.java b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/datamap/PackageUpdateController.java
index 1681b25..f1d6a8b 100644
--- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/datamap/PackageUpdateController.java
+++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/datamap/PackageUpdateController.java
@@ -94,13 +94,6 @@ public class PackageUpdateController extends DefaultsPreferencesController {
protected void updatePackage() {
boolean doAll = isAllEntities();
- String defaultPackage = getDefaultPackage();
- if (Util.isEmptyString(defaultPackage)) {
- defaultPackage = "";
- }
- else if (!defaultPackage.endsWith(".")) {
- defaultPackage = defaultPackage + '.';
- }
Map<String, String> oldNameEmbeddableToNewName = new HashMap<String,String>();
@@ -114,7 +107,7 @@ public class PackageUpdateController extends DefaultsPreferencesController {
if (doAll || Util.isEmptyString(oldName) || oldName.indexOf('.') < 0) {
EmbeddableEvent e = new EmbeddableEvent(this, embeddable, embeddable.getClassName());
- String newClassName = defaultPackage + className;
+ String newClassName = getNameWithDefaultPackage(className);
oldNameEmbeddableToNewName.put(oldName, newClassName);
embeddable.setClassName(newClassName);
mediator.fireEmbeddableEvent(e, mediator.getCurrentDataMap());
@@ -127,7 +120,7 @@ public class PackageUpdateController extends DefaultsPreferencesController {
if (doAll || Util.isEmptyString(oldName) || oldName.indexOf('.') < 0) {
String className = extractClassName(Util.isEmptyString(oldName) ? entity
.getName() : oldName);
- setClassName(entity, defaultPackage + className);
+ setClassName(entity, getNameWithDefaultPackage(className));
}
for(ObjAttribute attribute: entity.getAttributes()){
@@ -155,9 +148,12 @@ public class PackageUpdateController extends DefaultsPreferencesController {
: "";
}
- protected String getDefaultPackage() {
- return clientUpdate ? dataMap.getDefaultClientPackage() : dataMap
- .getDefaultPackage();
+ protected String getNameWithDefaultPackage(String name) {
+ if (clientUpdate) {
+ return dataMap.getNameWithDefaultClientPackage(name);
+ } else {
+ return dataMap.getNameWithDefaultPackage(name);
+ }
}
protected String getClassName(ObjEntity entity) {
http://git-wip-us.apache.org/repos/asf/cayenne/blob/fde7761f/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/DbLoaderHelper.java
----------------------------------------------------------------------
diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/DbLoaderHelper.java b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/DbLoaderHelper.java
index 9b604e1..c48c2b2 100644
--- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/DbLoaderHelper.java
+++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/DbLoaderHelper.java
@@ -1,21 +1,21 @@
-/*****************************************************************
- * 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
+/*
+ * 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
+ * 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.
- ****************************************************************/
+ * 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.modeler.dialog.db;
@@ -34,6 +34,10 @@ import org.apache.cayenne.CayenneException;
import org.apache.cayenne.CayenneRuntimeException;
import org.apache.cayenne.access.DbLoader;
import org.apache.cayenne.access.DbLoaderDelegate;
+import org.apache.cayenne.access.loader.DbLoaderConfiguration;
+import org.apache.cayenne.access.loader.filters.EntityFilters;
+import org.apache.cayenne.access.loader.filters.FilterFactory;
+import org.apache.cayenne.access.loader.filters.FiltersConfig;
import org.apache.cayenne.configuration.DataChannelDescriptor;
import org.apache.cayenne.configuration.event.DataMapEvent;
import org.apache.cayenne.dba.DbAdapter;
@@ -54,6 +58,8 @@ import org.apache.cayenne.util.Util;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import static org.apache.cayenne.access.loader.filters.FilterFactory.NULL;
+
/**
* Stateful helper class that encapsulates access to DbLoader.
*
@@ -78,13 +84,11 @@ public class DbLoaderHelper {
protected String dbUserName;
protected DbLoader loader;
protected DataMap dataMap;
- protected String schemaName;
- protected String tableNamePattern;
- protected boolean loadProcedures;
protected boolean meaningfulPk;
- protected String procedureNamePattern;
protected List<String> schemas;
+ private final EntityFilters.Builder filterBuilder = new EntityFilters.Builder();
+
protected String loadStatusNote;
/**
@@ -168,11 +172,12 @@ public class DbLoaderHelper {
return;
}
- this.schemaName = dialog.getSelectedSchema();
- this.tableNamePattern = dialog.getTableNamePattern();
- this.loadProcedures = dialog.isLoadingProcedures();
+ this.filterBuilder.schema(dialog.getSelectedSchema());
+ this.filterBuilder.includeTables(dialog.getTableNamePattern());
+ this.filterBuilder.setProceduresFilters(dialog.isLoadingProcedures() ? FilterFactory.TRUE : FilterFactory.NULL);
+ this.filterBuilder.includeProcedures(dialog.getProcedureNamePattern());
+
this.meaningfulPk = dialog.isMeaningfulPk();
- this.procedureNamePattern = dialog.getProcedureNamePattern();
this.addedObjEntities = new ArrayList<ObjEntity>();
this.loader.setNameGenerator(dialog.getNamingStrategy());
@@ -347,41 +352,15 @@ public class DbLoaderHelper {
if (!existingMap) {
dataMap = new DataMap(DefaultUniqueNameGenerator.generate(NameCheckers.dataMap));
dataMap.setName(DefaultUniqueNameGenerator.generate(NameCheckers.dataMap, mediator.getProject().getRootNode()));
- dataMap.setDefaultSchema(schemaName);
+ dataMap.setDefaultSchema(filterBuilder.schema());
}
if (isCanceled()) {
return;
}
- loadStatusNote = "Importing tables...";
-
- try {
- loader.setCreatingMeaningfulPK(meaningfulPk);
- loader.loadDataMapFromDB(schemaName, tableNamePattern, dataMap);
-
- /**
- * Update default rules for relationships
- */
- for (ObjEntity addedObjEntity : addedObjEntities) {
- DeleteRuleUpdater.updateObjEntity(addedObjEntity);
- }
- } catch (Throwable th) {
- if (!isCanceled()) {
- processException(th, "Error Reengineering Database");
- }
- }
-
- if (loadProcedures) {
- loadStatusNote = "Importing procedures...";
- try {
- loader.loadProceduresFromDB(schemaName, procedureNamePattern, dataMap);
- } catch (Throwable th) {
- if (!isCanceled()) {
- processException(th, "Error Reengineering Database");
- }
- }
- }
+ importingTables();
+ importingProcedures();
cleanup();
@@ -404,5 +383,49 @@ public class DbLoaderHelper {
mediator.addDataMap(Application.getFrame(), dataMap);
}
}
+
+ private void importingProcedures() {
+ if (!filterBuilder.proceduresFilters().equals(NULL)) {
+ return;
+ }
+
+ loadStatusNote = "Importing procedures...";
+ try {
+ DbLoaderConfiguration configuration = new DbLoaderConfiguration();
+ configuration.setFiltersConfig(new FiltersConfig(filterBuilder.build()));
+
+ loader.loadProcedures(dataMap, new DbLoaderConfiguration());
+ } catch (Throwable th) {
+ if (!isCanceled()) {
+ processException(th, "Error Reengineering Database");
+ }
+ }
+ }
+
+ private void importingTables() {
+ loadStatusNote = "Importing tables...";
+ try {
+ loader.setCreatingMeaningfulPK(meaningfulPk);
+ String[] types = loader.getDefaultTableTypes();
+ if (types.length == 0) {
+ throw new SQLException("No supported table types found.");
+ }
+
+ DbLoaderConfiguration configuration = new DbLoaderConfiguration();
+ configuration.setFiltersConfig(new FiltersConfig(filterBuilder.build()));
+ loader.load(dataMap, configuration, types);
+
+ /**
+ * Update default rules for relationships
+ */
+ for (ObjEntity addedObjEntity : addedObjEntities) {
+ DeleteRuleUpdater.updateObjEntity(addedObjEntity);
+ }
+ } catch (Throwable th) {
+ if (!isCanceled()) {
+ processException(th, "Error Reengineering Database");
+ }
+ }
+ }
}
}
http://git-wip-us.apache.org/repos/asf/cayenne/blob/fde7761f/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/MergerOptions.java
----------------------------------------------------------------------
diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/MergerOptions.java b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/MergerOptions.java
index 125a4fd..dc05932 100644
--- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/MergerOptions.java
+++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/MergerOptions.java
@@ -1,21 +1,21 @@
-/*****************************************************************
- * 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
+/*
+ * 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
+ * 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.
- ****************************************************************/
+ * 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.modeler.dialog.db;
@@ -34,6 +34,10 @@ import javax.swing.WindowConstants;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
+import org.apache.cayenne.access.loader.DbLoaderConfiguration;
+import org.apache.cayenne.access.loader.filters.DbPath;
+import org.apache.cayenne.access.loader.filters.EntityFilters;
+import org.apache.cayenne.access.loader.filters.FiltersConfig;
import org.apache.cayenne.configuration.DataChannelDescriptor;
import org.apache.cayenne.configuration.DataNodeDescriptor;
import org.apache.cayenne.dba.JdbcAdapter;
@@ -161,14 +165,18 @@ public class MergerOptions extends CayenneController {
*/
protected void prepareMigrator() {
try {
- adapter = (JdbcAdapter) connectionInfo.makeAdapter(getApplication()
- .getClassLoadingService());
+ adapter = (JdbcAdapter) connectionInfo.makeAdapter(getApplication().getClassLoadingService());
tokens.setMergerFactory(adapter.mergerFactory());
- merger = new DbMerger(adapter.mergerFactory(), defaultSchema);
+ merger = new DbMerger(adapter.mergerFactory());
+
+ DbLoaderConfiguration config = new DbLoaderConfiguration();
+ config.setFiltersConfig(new FiltersConfig(new EntityFilters(new DbPath(null, defaultSchema))));
+
List<MergerToken> mergerTokens = merger.createMergeTokens(
- connectionInfo.makeDataSource(getApplication()
- .getClassLoadingService()), adapter,
- dataMap);
+ connectionInfo.makeDataSource(getApplication().getClassLoadingService()),
+ adapter,
+ dataMap,
+ config);
tokens.setTokens(mergerTokens);
}
catch (Exception ex) {
@@ -181,15 +189,12 @@ public class MergerOptions extends CayenneController {
*/
protected void createSQL() {
// convert them to string representation for display
- final StringBuilder buf = new StringBuilder();
+ StringBuilder buf = new StringBuilder();
Iterator<MergerToken> it = tokens.getSelectedTokens().iterator();
String batchTerminator = adapter.getBatchTerminator();
- final String lineEnd = (batchTerminator != null) ? "\n"
- + batchTerminator
- + "\n\n" : "\n\n";
-
+ String lineEnd = batchTerminator != null ? "\n" + batchTerminator + "\n\n" : "\n\n";
while (it.hasNext()) {
MergerToken token = it.next();
@@ -267,7 +272,7 @@ public class MergerOptions extends CayenneController {
.getRootNode();
final DataNodeDescriptor node = getProjectController().getCurrentDataNode();
- final ModelMergeDelegate delegate = new ModelMergeDelegate() {
+ ModelMergeDelegate delegate = new ModelMergeDelegate() {
public void dbAttributeAdded(DbAttribute att) {
if (c.getCurrentDbEntity() == att.getEntity()) {
http://git-wip-us.apache.org/repos/asf/cayenne/blob/fde7761f/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/objentity/ClassNameUpdater.java
----------------------------------------------------------------------
diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/objentity/ClassNameUpdater.java b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/objentity/ClassNameUpdater.java
index a9fc623..449d10a 100644
--- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/objentity/ClassNameUpdater.java
+++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/objentity/ClassNameUpdater.java
@@ -24,6 +24,7 @@ import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
+import org.apache.cayenne.map.DataMap;
import org.apache.cayenne.map.ObjEntity;
import org.apache.cayenne.modeler.util.CayenneController;
@@ -120,9 +121,7 @@ public class ClassNameUpdater extends CayenneController {
}
private String suggestedServerClassName() {
- String pkg = entity.getDataMap() != null ? entity
- .getDataMap()
- .getDefaultPackage() : null;
+ String pkg = entity.getDataMap() == null ? null : entity.getDataMap().getDefaultPackage();
return suggestedClassName(entity.getName(), pkg, entity.getClassName());
}
@@ -132,21 +131,16 @@ public class ClassNameUpdater extends CayenneController {
return null;
}
- String pkg = entity.getDataMap() != null ? entity
- .getDataMap()
- .getDefaultClientPackage() : null;
+ String pkg = entity.getDataMap() == null ? null : entity.getDataMap().getDefaultClientPackage();
return suggestedClassName(entity.getName(), pkg, entity.getClientClassName());
}
/**
* Suggests a new class name based on new entity name and current selections.
*/
- private String suggestedClassName(
- String entityName,
- String suggestedPackage,
- String oldClassName) {
+ private static String suggestedClassName(String entityName, String suggestedPackage, String oldClassName) {
- if (entityName == null || entityName.trim().length() == 0) {
+ if (entityName == null || entityName.trim().isEmpty()) {
return null;
}
@@ -156,20 +150,13 @@ public class ClassNameUpdater extends CayenneController {
pkg = oldClassName.substring(0, oldClassName.lastIndexOf('.'));
}
- if (pkg == null) {
- pkg = "";
- }
- else {
- pkg = pkg + '.';
- }
-
// build suggested class name
- int dot = entityName.lastIndexOf('.');
- if (dot >= 0 && dot < entityName.length() - 1) {
- entityName = entityName.substring(dot + 1);
+ int lastDotIndex = entityName.lastIndexOf('.');
+ if (lastDotIndex >= 0 && lastDotIndex < entityName.length() - 1) {
+ entityName = entityName.substring(lastDotIndex + 1);
}
- return pkg + entityName;
+ return DataMap.getNameWithPackage(pkg, entityName);
}
protected void initBindings(
http://git-wip-us.apache.org/repos/asf/cayenne/blob/fde7761f/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/objentity/EntitySyncController.java
----------------------------------------------------------------------
diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/objentity/EntitySyncController.java b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/objentity/EntitySyncController.java
index cce0262..6e07559 100644
--- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/objentity/EntitySyncController.java
+++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/objentity/EntitySyncController.java
@@ -27,14 +27,17 @@ import java.util.Collections;
import org.apache.cayenne.map.DbEntity;
import org.apache.cayenne.map.ObjEntity;
+import org.apache.cayenne.map.naming.DefaultNameGenerator;
+import org.apache.cayenne.map.naming.ObjectNameGenerator;
import org.apache.cayenne.modeler.util.CayenneController;
+import org.apache.cayenne.modeler.util.NameGeneratorPreferences;
import org.apache.cayenne.util.EntityMergeSupport;
public class EntitySyncController extends CayenneController {
- protected DbEntity dbEntity;
- protected ObjEntity objEntity;
- protected EntitySyncDialog view;
+ private final DbEntity dbEntity;
+ private ObjEntity objEntity;
+ private EntitySyncDialog view;
/**
* Creates a controller for synchronizing all ObjEntities mapped to a given DbEntity.
@@ -58,18 +61,26 @@ public class EntitySyncController extends CayenneController {
return null;
}
- final EntityMergeSupport merger = new EntityMergeSupport(dbEntity.getDataMap());
+
+ ObjectNameGenerator namingStrategy;
+ try {
+ namingStrategy = NameGeneratorPreferences.getInstance().createNamingStrategy(application);
+ } catch (Throwable e) {
+ namingStrategy = NameGeneratorPreferences.defaultNameGenerator();
+
+ // TODO log exception
+ }
+
+ EntityMergeSupport merger = new EntityMergeSupport(dbEntity.getDataMap(), namingStrategy, true);
// see if we need to remove meaningful attributes...
- boolean showDialog = false;
for (ObjEntity entity : entities) {
if (!merger.getMeaningfulFKs(entity).isEmpty()) {
- showDialog = true;
- break;
+ return configureMerger(merger);
}
}
- return (showDialog) ? configureMerger(merger) : merger;
+ return merger;
}
/**
@@ -113,9 +124,8 @@ public class EntitySyncController extends CayenneController {
}
protected Collection<ObjEntity> getObjEntities() {
- return (objEntity != null) ? Collections.singleton(objEntity) : dbEntity
- .getDataMap()
- .getMappedEntities(dbEntity);
+ return objEntity == null ? dbEntity.getDataMap().getMappedEntities(dbEntity)
+ : Collections.singleton(objEntity);
}
}
http://git-wip-us.apache.org/repos/asf/cayenne/blob/fde7761f/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/util/NameGeneratorPreferences.java
----------------------------------------------------------------------
diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/util/NameGeneratorPreferences.java b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/util/NameGeneratorPreferences.java
index eef86f2..fa15083 100644
--- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/util/NameGeneratorPreferences.java
+++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/util/NameGeneratorPreferences.java
@@ -24,6 +24,7 @@ import java.util.prefs.Preferences;
import org.apache.cayenne.map.naming.LegacyNameGenerator;
import org.apache.cayenne.map.naming.DefaultNameGenerator;
+import org.apache.cayenne.map.naming.ObjectNameGenerator;
import org.apache.cayenne.modeler.Application;
/**
@@ -84,10 +85,21 @@ public class NameGeneratorPreferences {
for (String str : strategies) {
res.append(str).append(",");
}
- if (strategies.size() > 0) {
+ if (!strategies.isEmpty()) {
res.deleteCharAt(res.length() - 1);
}
getPreference().put(STRATEGIES_PREFERENCE, res.toString());
}
+
+ public ObjectNameGenerator createNamingStrategy(Application application)
+ throws ClassNotFoundException, IllegalAccessException, InstantiationException {
+
+ return application.getClassLoadingService()
+ .loadClass(ObjectNameGenerator.class, getLastUsedStrategies().get(0)).newInstance();
+ }
+
+ public static ObjectNameGenerator defaultNameGenerator() {
+ return new DefaultNameGenerator();
+ }
}
http://git-wip-us.apache.org/repos/asf/cayenne/blob/fde7761f/plugins/maven-cayenne-plugin/pom.xml
----------------------------------------------------------------------
diff --git a/plugins/maven-cayenne-plugin/pom.xml b/plugins/maven-cayenne-plugin/pom.xml
index 5401797..1458865 100644
--- a/plugins/maven-cayenne-plugin/pom.xml
+++ b/plugins/maven-cayenne-plugin/pom.xml
@@ -128,15 +128,37 @@
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.apache.cayenne</groupId>
+ <artifactId>cayenne-server</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ <type>test-jar</type>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.cayenne</groupId>
+ <artifactId>cayenne-tools</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ <type>test-jar</type>
+ </dependency>
</dependencies>
+ <reporting>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-plugin-plugin</artifactId>
+ <version>2.5.1</version>
+ </plugin>
+ </plugins>
+ </reporting>
+
<build>
<plugins>
<plugin>
<artifactId>maven-checkstyle-plugin</artifactId>
- <!--<configuration>
- <suppressionsLocation>${project.basedir}/cayenne-checkstyle-suppression.xml</suppressionsLocation>
- </configuration>-->
</plugin>
<plugin>
<artifactId>maven-pmd-plugin</artifactId>
http://git-wip-us.apache.org/repos/asf/cayenne/blob/fde7761f/plugins/maven-cayenne-plugin/src/main/java/org/apache/cayenne/tools/CayenneGeneratorMojo.java
----------------------------------------------------------------------
diff --git a/plugins/maven-cayenne-plugin/src/main/java/org/apache/cayenne/tools/CayenneGeneratorMojo.java b/plugins/maven-cayenne-plugin/src/main/java/org/apache/cayenne/tools/CayenneGeneratorMojo.java
index 12b4468..3c9d548 100644
--- a/plugins/maven-cayenne-plugin/src/main/java/org/apache/cayenne/tools/CayenneGeneratorMojo.java
+++ b/plugins/maven-cayenne-plugin/src/main/java/org/apache/cayenne/tools/CayenneGeneratorMojo.java
@@ -21,6 +21,7 @@ package org.apache.cayenne.tools;
import java.io.File;
+import org.apache.cayenne.access.loader.NamePatternMatcher;
import org.apache.cayenne.gen.ClassGenerationAction;
import org.apache.cayenne.gen.ClientClassGenerationAction;
import org.apache.cayenne.map.DataMap;
@@ -202,8 +203,7 @@ public class CayenneGeneratorMojo extends AbstractMojo {
CayenneGeneratorEntityFilterAction filterAction = new CayenneGeneratorEntityFilterAction();
filterAction.setClient(client);
- filterAction.setNameFilter(new NamePatternMatcher(logger,
- includeEntities, excludeEntities));
+ filterAction.setNameFilter(NamePatternMatcher.build(logger, includeEntities, excludeEntities));
try {
loaderAction.setAdditionalDataMapFiles(convertAdditionalDataMaps());
http://git-wip-us.apache.org/repos/asf/cayenne/blob/fde7761f/plugins/maven-cayenne-plugin/src/main/java/org/apache/cayenne/tools/DbImporterMojo.java
----------------------------------------------------------------------
diff --git a/plugins/maven-cayenne-plugin/src/main/java/org/apache/cayenne/tools/DbImporterMojo.java b/plugins/maven-cayenne-plugin/src/main/java/org/apache/cayenne/tools/DbImporterMojo.java
index d8ea086..1918106 100644
--- a/plugins/maven-cayenne-plugin/src/main/java/org/apache/cayenne/tools/DbImporterMojo.java
+++ b/plugins/maven-cayenne-plugin/src/main/java/org/apache/cayenne/tools/DbImporterMojo.java
@@ -16,11 +16,22 @@
* specific language governing permissions and limitations
* under the License.
****************************************************************/
-
package org.apache.cayenne.tools;
import java.io.File;
+import org.apache.cayenne.access.loader.filters.EntityFilters;
+import org.apache.cayenne.access.loader.filters.FilterFactory;
+import org.apache.cayenne.tools.dbimport.config.Catalog;
+import org.apache.cayenne.tools.dbimport.config.ExcludeColumn;
+import org.apache.cayenne.tools.dbimport.config.ExcludeProcedure;
+import org.apache.cayenne.tools.dbimport.config.ExcludeTable;
+import org.apache.cayenne.tools.dbimport.config.FiltersConfigBuilder;
+import org.apache.cayenne.tools.dbimport.config.IncludeColumn;
+import org.apache.cayenne.tools.dbimport.config.IncludeProcedure;
+import org.apache.cayenne.tools.dbimport.config.IncludeTable;
+import org.apache.cayenne.tools.dbimport.config.ReverseEngineering;
+import org.apache.cayenne.tools.dbimport.config.Schema;
import org.apache.cayenne.di.DIBootstrap;
import org.apache.cayenne.di.Injector;
import org.apache.cayenne.tools.configuration.ToolsModule;
@@ -71,86 +82,6 @@ public class DbImporterMojo extends AbstractMojo {
private boolean overwrite;
/**
- * DB schema to use for DB importing.
- *
- * @parameter expression="${cdbimport.schemaName}"
- * @deprecated since 3.2 renamed to "schema"
- */
- private String schemaName;
-
- /**
- * DB schema to use for DB importing.
- *
- * @parameter expression="${cdbimport.catalog}"
- * @since 3.2
- */
- private String catalog;
-
- /**
- * DB schema to use for DB importing.
- *
- * @parameter expression="${cdbimport.schema}"
- * @since 3.2
- */
- private String schema;
-
- /**
- * Pattern for tables to import from DB.
- *
- * The default is to match against all tables.
- *
- * @parameter expression="${cdbimport.tablePattern}"
- */
- private String tablePattern;
-
- /**
- * A comma-separated list of Perl5 regex that defines tables that should be
- * included in import.
- *
- * @parameter expression="${cdbimport.includeTables}"
- */
- private String includeTables;
-
- /**
- * A comma-separated list of Perl5 regex that defines tables that should be
- * skipped from import.
- *
- * @parameter expression="${cdbimport.excludeTables}"
- */
- private String excludeTables;
-
- /**
- * Indicates whether stored procedures should be imported.
- *
- * Default is <code>false</code>.
- *
- * @parameter expression="${cdbimport.importProcedures}"
- * default-value="false"
- */
- private boolean importProcedures;
-
- /**
- * Pattern for stored procedures to import from DB. This is only meaningful
- * if <code>importProcedures</code> is set to <code>true</code>.
- *
- * The default is to match against all stored procedures.
- *
- * @parameter expression="${cdbimport.procedurePattern}"
- */
- private String procedurePattern;
-
- /**
- * Indicates whether primary keys should be mapped as meaningful attributes
- * in the object entities.
- *
- * Default is <code>false</code>.
- *
- * @parameter expression="${cdbimport.meaningfulPk}" default-value="false"
- * @deprecated since 3.2 use meaningfulPkTables
- */
- private boolean meaningfulPk;
-
- /**
* @parameter expression="${cdbimport.meaningfulPkTables}"
* @since 3.2
*/
@@ -215,15 +146,101 @@ public class DbImporterMojo extends AbstractMojo {
*/
private boolean usePrimitives;
+ private final ReverseEngineering reverseEngineering = new ReverseEngineering();
+
+ private final EntityFilters.Builder filterBuilder = new EntityFilters.Builder();
+
+ /**
+ * DB schema to use for DB importing.
+ *
+ * @parameter expression="${cdbimport.schemaName}"
+ * @deprecated since 3.2 renamed to "schema"
+ */
+ private void setSchemaName(String schemaName) {
+ getLog().warn("'schemaName' property is deprecated. Use 'schema' instead");
+
+ filterBuilder.schema(schemaName);
+ }
+
+ /**
+ * DB schema to use for DB importing.
+ *
+ * @parameter expression="${cdbimport.catalog}"
+ * @since 3.2
+ */
+ private void setCatalog(String catalog) {
+ filterBuilder.catalog(catalog);
+ }
+
+ /**
+ * DB schema to use for DB importing.
+ *
+ * @parameter expression="${cdbimport.schema}"
+ * @since 3.2
+ */
+ private void setSchema(String schema) {
+ filterBuilder.schema(schema);
+ }
+
+ /**
+ * Pattern for tables to import from DB.
+ *
+ * The default is to match against all tables.
+ *
+ * @parameter expression="${cdbimport.tablePattern}"
+ */
+ private void setTablePattern(String tablePattern) {
+ filterBuilder.includeTables(tablePattern);
+ }
+
+ /**
+ * Indicates whether stored procedures should be imported.
+ *
+ * Default is <code>false</code>.
+ *
+ * @parameter expression="${cdbimport.importProcedures}"
+ * default-value="false"
+ */
+ private void setImportProcedures(boolean importProcedures) {
+ filterBuilder.setProceduresFilters(importProcedures ? FilterFactory.TRUE : FilterFactory.NULL);
+ }
+
+ /**
+ * Pattern for stored procedures to import from DB. This is only meaningful
+ * if <code>importProcedures</code> is set to <code>true</code>.
+ *
+ * The default is to match against all stored procedures.
+ *
+ * @parameter expression="${cdbimport.procedurePattern}"
+ */
+ private void setProcedurePattern(String procedurePattern) {
+ filterBuilder.includeProcedures(procedurePattern);
+ }
+
+ /**
+ * Indicates whether primary keys should be mapped as meaningful attributes
+ * in the object entities.
+ *
+ * Default is <code>false</code>.
+ *
+ * @parameter expression="${cdbimport.meaningfulPk}" default-value="false"
+ * @deprecated since 3.2 use meaningfulPkTables
+ */
+ public void setMeaningfulPk(boolean meaningfulPk) {
+ getLog().warn("'meaningfulPk' property is deprecated. Use 'meaningfulPkTables' pattern instead");
+
+ this.meaningfulPkTables = meaningfulPk ? "*" : null;
+ }
+
public void execute() throws MojoExecutionException, MojoFailureException {
Log logger = new MavenLogger(this);
- DbImportConfiguration parameters = toParameters();
+ DbImportConfiguration config = toParameters();
Injector injector = DIBootstrap.createInjector(new ToolsModule(logger), new DbImportModule());
try {
- injector.getInstance(DbImportAction.class).execute(parameters);
+ injector.getInstance(DbImportAction.class).execute(config);
} catch (Exception ex) {
Throwable th = Util.unwindException(ex);
@@ -239,46 +256,25 @@ public class DbImporterMojo extends AbstractMojo {
}
DbImportConfiguration toParameters() {
- DbImportConfiguration parameters = new DbImportConfiguration();
- parameters.setAdapter(adapter);
- parameters.setCatalog(catalog);
- parameters.setDefaultPackage(defaultPackage);
- parameters.setDriver(driver);
- parameters.setImportProcedures(importProcedures);
- parameters.setDataMapFile(map);
- parameters.setMeaningfulPkTables(getMeaningfulPkTables());
- parameters.setNamingStrategy(namingStrategy);
- parameters.setOverwrite(overwrite);
- parameters.setPassword(password);
- parameters.setProcedurePattern(procedurePattern);
- parameters.setSchema(getSchema());
- parameters.setTablePattern(tablePattern);
- parameters.setUrl(url);
- parameters.setUsername(username);
- parameters.setIncludeTables(includeTables);
- parameters.setExcludeTables(excludeTables);
- parameters.setUsePrimitives(usePrimitives);
- return parameters;
+ DbImportConfiguration config = new DbImportConfiguration();
+ config.setAdapter(adapter);
+ config.setDefaultPackage(defaultPackage);
+ config.setDriver(driver);
+ config.setDataMapFile(map);
+ config.setMeaningfulPkTables(meaningfulPkTables);
+ config.setNamingStrategy(namingStrategy);
+ config.setOverwrite(overwrite);
+ config.setPassword(password);
+ config.setUrl(url);
+ config.setUsername(username);
+ config.setUsePrimitives(usePrimitives);
+ config.setFiltersConfig(new FiltersConfigBuilder(reverseEngineering)
+ .add(filterBuilder.build()).filtersConfig());
+ return config;
}
private String getSchema() {
- if (schemaName != null) {
- getLog().warn("'schemaName' property is deprecated. Use 'schema' instead");
- }
-
- return schema != null ? schema : schemaName;
- }
-
- private String getMeaningfulPkTables() {
- if (meaningfulPk) {
- getLog().warn("'meaningfulPk' property is deprecated. Use 'meaningfulPkTables' pattern instead");
- }
-
- if (meaningfulPkTables != null) {
- return meaningfulPkTables;
- }
-
- return meaningfulPk ? "*" : null;
+ return filterBuilder.schema();
}
public File getMap() {
@@ -304,4 +300,40 @@ public class DbImporterMojo extends AbstractMojo {
public void setUrl(String url) {
this.url = url;
}
+
+ public void addIncludeColumn(IncludeColumn includeColumn) {
+ reverseEngineering.addIncludeColumn(includeColumn);
+ }
+
+ public void addExcludeColumn(ExcludeColumn excludeColumn) {
+ reverseEngineering.addExcludeColumn(excludeColumn);
+ }
+
+ public void addIncludeTable(IncludeTable includeTable) {
+ reverseEngineering.addIncludeTable(includeTable);
+ }
+
+ public void addExcludeTable(ExcludeTable excludeTable) {
+ reverseEngineering.addExcludeTable(excludeTable);
+ }
+
+ public void addIncludeProcedure(IncludeProcedure includeProcedure) {
+ reverseEngineering.addIncludeProcedure(includeProcedure);
+ }
+
+ public void addExcludeProcedure(ExcludeProcedure excludeProcedure) {
+ reverseEngineering.addExcludeProcedure(excludeProcedure);
+ }
+
+ public void addSchema(Schema schema) {
+ reverseEngineering.addSchema(schema);
+ }
+
+ public void addCatalog(Catalog catalog) {
+ reverseEngineering.addCatalog(catalog);
+ }
+
+ public ReverseEngineering getReverseEngineering() {
+ return reverseEngineering;
+ }
}
http://git-wip-us.apache.org/repos/asf/cayenne/blob/fde7761f/plugins/maven-cayenne-plugin/src/test/java/org/apache/cayenne/tools/DbImporterMojoConfigurationTest.java
----------------------------------------------------------------------
diff --git a/plugins/maven-cayenne-plugin/src/test/java/org/apache/cayenne/tools/DbImporterMojoConfigurationTest.java b/plugins/maven-cayenne-plugin/src/test/java/org/apache/cayenne/tools/DbImporterMojoConfigurationTest.java
new file mode 100644
index 0000000..e5a3a49
--- /dev/null
+++ b/plugins/maven-cayenne-plugin/src/test/java/org/apache/cayenne/tools/DbImporterMojoConfigurationTest.java
@@ -0,0 +1,56 @@
+/*****************************************************************
+ * 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.tools;
+
+import static org.apache.cayenne.tools.dbimport.config.DefaultReverseEngineeringLoaderTest.*;
+import org.apache.maven.plugin.testing.AbstractMojoTestCase;
+import org.junit.Test;
+
+/**
+ * @since 3.2.
+ */
+public class DbImporterMojoConfigurationTest extends AbstractMojoTestCase {
+
+ @Test
+ public void testLoadCatalog() throws Exception {
+ assertCatalog(getCdbImport("pom-catalog.xml").getReverseEngineering());
+ }
+
+ @Test
+ public void testLoadSchema() throws Exception {
+ assertSchema(getCdbImport("pom-schema.xml").getReverseEngineering());
+ }
+
+ @Test
+ public void testLoadCatalogAndSchema() throws Exception {
+ assertCatalogAndSchema(getCdbImport("pom-catalog-and-schema.xml").getReverseEngineering());
+ }
+
+ @Test
+ public void testLoadFlat() throws Exception {
+ assertFlat(getCdbImport("pom-flat.xml").getReverseEngineering());
+
+ }
+
+ private DbImporterMojo getCdbImport(String pomFileName) throws Exception {
+ return (DbImporterMojo) lookupMojo("cdbimport",
+ getTestFile("src/test/resources/org/apache/cayenne/tools/config/" + pomFileName));
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/cayenne/blob/fde7761f/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 a255a9c..682f180 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
@@ -27,15 +27,20 @@ import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
+import java.util.Iterator;
+import org.apache.cayenne.tools.dbimport.config.Catalog;
+import org.apache.cayenne.tools.dbimport.config.IncludeTable;
+import org.apache.cayenne.tools.dbimport.config.Schema;
import org.apache.cayenne.tools.dbimport.DbImportConfiguration;
import org.apache.maven.plugin.testing.AbstractMojoTestCase;
import org.codehaus.plexus.util.FileUtils;
+import org.custommonkey.xmlunit.DetailedDiff;
+import org.custommonkey.xmlunit.Diff;
import org.custommonkey.xmlunit.XMLUnit;
import org.xml.sax.SAXException;
-import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual;
-import static org.junit.Assert.assertNotNull;
+import static org.apache.commons.lang.StringUtils.isBlank;
public class DbImporterMojoTest extends AbstractMojoTestCase {
@@ -85,6 +90,18 @@ public class DbImporterMojoTest extends AbstractMojoTestCase {
test("testImportAddTableAndColumn");
}
+ public void testSimpleFiltering() throws Exception {
+ test("testSimpleFiltering");
+ }
+
+ public void testFilteringWithSchema() throws Exception {
+ test("testFilteringWithSchema");
+ }
+
+ public void testSchemasAndTableExclude() throws Exception {
+ test("testSchemasAndTableExclude");
+ }
+
private void test(String name) throws Exception {
DbImporterMojo cdbImport = getCdbImport("dbimport/" + name + "-pom.xml");
File mapFile = cdbImport.getMap();
@@ -114,14 +131,33 @@ public class DbImporterMojoTest extends AbstractMojoTestCase {
ResultSet tables = connection.getMetaData().getTables(null, null, null, new String[]{"TABLE"});
while (tables.next()) {
- System.out.println("DROP TABLE " + tables.getString("TABLE_NAME"));
- stmt.execute("DROP TABLE " + tables.getString("TABLE_NAME"));
+ String schema = tables.getString("TABLE_SCHEM");
+ System.out.println("DROP TABLE " + (isBlank(schema) ? "" : schema + ".") + tables.getString("TABLE_NAME"));
+ stmt.execute("DROP TABLE " + (isBlank(schema) ? "" : schema + ".") + tables.getString("TABLE_NAME"));
+ }
+
+ ResultSet schemas = connection.getMetaData().getSchemas();
+ while (schemas.next()) {
+ String schem = schemas.getString("TABLE_SCHEM");
+ if (schem.startsWith("SCHEMA")) {
+ System.out.println("DROP SCHEMA " + schem);
+ stmt.execute("DROP SCHEMA " + schem + " RESTRICT");
+ }
}
}
private void verifyResult(File map, File mapFileCopy) {
try {
- assertXMLEqual(new FileReader(map.getAbsolutePath() + "-result"), new FileReader(mapFileCopy));
+ FileReader control = new FileReader(map.getAbsolutePath() + "-result");
+ FileReader test = new FileReader(mapFileCopy);
+
+ DetailedDiff diff = new DetailedDiff(new Diff(control, test));
+ if (!diff.similar()) {
+ System.out.println(" >>>> " + map.getAbsolutePath() + "-result");
+ System.out.println(" >>>> " + mapFileCopy);
+ fail(diff.toString());
+ }
+
} catch (SAXException e) {
e.printStackTrace();
fail();
@@ -131,6 +167,59 @@ public class DbImporterMojoTest extends AbstractMojoTestCase {
}
}
+ public void testFilteringConfig() throws Exception {
+ DbImporterMojo cdbImport = getCdbImport("config/pom-01.xml");
+
+ assertEquals(2, cdbImport.getReverseEngineering().getCatalogs().size());
+ Iterator<Catalog> iterator = cdbImport.getReverseEngineering().getCatalogs().iterator();
+ assertEquals("catalog-name-01", iterator.next().getName());
+
+ Catalog catalog = iterator.next();
+ assertEquals("catalog-name-02", catalog.getName());
+ Iterator<Schema> schemaIterator = catalog.getSchemas().iterator();
+
+ assertEquals("schema-name-01", schemaIterator.next().getName());
+
+ Schema schema = schemaIterator.next();
+ assertEquals("schema-name-02", schema.getName());
+
+ Iterator<IncludeTable> includeTableIterator = schema.getIncludeTables().iterator();
+ assertEquals("incTable-01", includeTableIterator.next().getPattern());
+
+ IncludeTable includeTable = includeTableIterator.next();
+ assertEquals("incTable-02", includeTable.getPattern());
+ assertEquals("includeColumn-01", includeTable.getIncludeColumns().iterator().next().getPattern());
+ assertEquals("excludeColumn-01", includeTable.getExcludeColumns().iterator().next().getPattern());
+
+ assertEquals("includeColumn-02", schema.getIncludeColumns().iterator().next().getPattern());
+ assertEquals("excludeColumn-02", schema.getExcludeColumns().iterator().next().getPattern());
+
+ assertEquals("includeColumn-03", catalog.getIncludeColumns().iterator().next().getPattern());
+ assertEquals("excludeColumn-03", catalog.getExcludeColumns().iterator().next().getPattern());
+
+ schemaIterator = cdbImport.getReverseEngineering().getSchemas().iterator();
+ schema = schemaIterator.next();
+ assertEquals("schema-name-03", schema.getName());
+
+ schema = schemaIterator.next();
+ assertEquals("schema-name-04", schema.getName());
+
+ includeTableIterator = schema.getIncludeTables().iterator();
+ assertEquals("incTable-04", includeTableIterator.next().getPattern());
+ assertEquals("excTable-04", schema.getExcludeTables().iterator().next().getPattern());
+
+ includeTable = includeTableIterator.next();
+ assertEquals("incTable-05", includeTable.getPattern());
+ assertEquals("includeColumn-04", includeTable.getIncludeColumns().iterator().next().getPattern());
+ assertEquals("excludeColumn-04", includeTable.getExcludeColumns().iterator().next().getPattern());
+
+ assertEquals("includeColumn-04", schema.getIncludeColumns().iterator().next().getPattern());
+ assertEquals("excludeColumn-04", schema.getExcludeColumns().iterator().next().getPattern());
+
+ assertEquals("includeColumn-03", catalog.getIncludeColumns().iterator().next().getPattern());
+ assertEquals("excludeColumn-03", catalog.getExcludeColumns().iterator().next().getPattern());
+ }
+
private void prepareDatabase(String sqlFile, DbImportConfiguration dbImportConfiguration) throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException, IOException, URISyntaxException {
Class.forName(dbImportConfiguration.getDriver()).newInstance();
// Get a connection