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:38 UTC

[3/7] CAY-1946 CDbimport improvements

http://git-wip-us.apache.org/repos/asf/cayenne/blob/fde7761f/cayenne-tools/src/main/java/org/apache/cayenne/tools/dbimport/config/IncludeColumn.java
----------------------------------------------------------------------
diff --git a/cayenne-tools/src/main/java/org/apache/cayenne/tools/dbimport/config/IncludeColumn.java b/cayenne-tools/src/main/java/org/apache/cayenne/tools/dbimport/config/IncludeColumn.java
new file mode 100644
index 0000000..46b5672
--- /dev/null
+++ b/cayenne-tools/src/main/java/org/apache/cayenne/tools/dbimport/config/IncludeColumn.java
@@ -0,0 +1,31 @@
+/*****************************************************************
+ *   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.dbimport.config;
+
+/**
+ * @since 3.2.
+ */
+public class IncludeColumn extends PatternParam {
+    public IncludeColumn() {
+    }
+
+    public IncludeColumn(String pattern) {
+        super(pattern);
+    }
+}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/fde7761f/cayenne-tools/src/main/java/org/apache/cayenne/tools/dbimport/config/IncludeProcedure.java
----------------------------------------------------------------------
diff --git a/cayenne-tools/src/main/java/org/apache/cayenne/tools/dbimport/config/IncludeProcedure.java b/cayenne-tools/src/main/java/org/apache/cayenne/tools/dbimport/config/IncludeProcedure.java
new file mode 100644
index 0000000..a5c8ea2
--- /dev/null
+++ b/cayenne-tools/src/main/java/org/apache/cayenne/tools/dbimport/config/IncludeProcedure.java
@@ -0,0 +1,31 @@
+/*****************************************************************
+ *   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.dbimport.config;
+
+/**
+ * @since 3.2.
+ */
+public class IncludeProcedure extends PatternParam {
+    public IncludeProcedure() {
+    }
+
+    public IncludeProcedure(String pattern) {
+        super(pattern);
+    }
+}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/fde7761f/cayenne-tools/src/main/java/org/apache/cayenne/tools/dbimport/config/IncludeTable.java
----------------------------------------------------------------------
diff --git a/cayenne-tools/src/main/java/org/apache/cayenne/tools/dbimport/config/IncludeTable.java b/cayenne-tools/src/main/java/org/apache/cayenne/tools/dbimport/config/IncludeTable.java
new file mode 100644
index 0000000..e627eea
--- /dev/null
+++ b/cayenne-tools/src/main/java/org/apache/cayenne/tools/dbimport/config/IncludeTable.java
@@ -0,0 +1,77 @@
+/*****************************************************************
+ *   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.dbimport.config;
+
+import java.util.Collection;
+import java.util.LinkedList;
+
+import static org.apache.commons.lang.StringUtils.join;
+
+/**
+ * @since 3.2.
+ */
+public class IncludeTable extends PatternParam {
+
+    private Collection<IncludeColumn> includeColumns = new LinkedList<IncludeColumn>();
+    private Collection<ExcludeColumn> excludeColumns = new LinkedList<ExcludeColumn>();
+
+    public IncludeTable() {
+    }
+
+    public IncludeTable(String pattern) {
+        super(pattern);
+    }
+
+    public Collection<IncludeColumn> getIncludeColumns() {
+        return includeColumns;
+    }
+
+    public void setIncludeColumns(Collection<IncludeColumn> includeColumns) {
+        this.includeColumns = includeColumns;
+    }
+
+    public Collection<ExcludeColumn> getExcludeColumns() {
+        return excludeColumns;
+    }
+
+    public void setExcludeColumns(Collection<ExcludeColumn> excludeColumns) {
+        this.excludeColumns = excludeColumns;
+    }
+
+    public void addIncludeColumn(IncludeColumn includeColumn) {
+        this.includeColumns.add(includeColumn);
+    }
+
+    public void addExcludeColumn(ExcludeColumn excludeColumn) {
+        this.excludeColumns.add(excludeColumn);
+    }
+
+    @Override
+    public String toString() {
+        String str = "+(" + getPattern() + ") ";
+        if (includeColumns != null && !includeColumns.isEmpty()) {
+            str += "+Columns(" + join(includeColumns, ", ") + ") ";
+        }
+
+        if (excludeColumns != null && !excludeColumns.isEmpty()) {
+            str += "-Columns(" + join(excludeColumns, ", ") + ") ";
+        }
+        return str;
+    }
+}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/fde7761f/cayenne-tools/src/main/java/org/apache/cayenne/tools/dbimport/config/PatternParam.java
----------------------------------------------------------------------
diff --git a/cayenne-tools/src/main/java/org/apache/cayenne/tools/dbimport/config/PatternParam.java b/cayenne-tools/src/main/java/org/apache/cayenne/tools/dbimport/config/PatternParam.java
new file mode 100644
index 0000000..3d8297c
--- /dev/null
+++ b/cayenne-tools/src/main/java/org/apache/cayenne/tools/dbimport/config/PatternParam.java
@@ -0,0 +1,74 @@
+/*****************************************************************
+ *   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.dbimport.config;
+
+/**
+ * @since 3.2.
+ */
+public class PatternParam {
+
+    private String pattern;
+
+    public PatternParam() {
+    }
+
+    public PatternParam(String pattern) {
+        this.pattern = pattern;
+    }
+
+    public String getPattern() {
+        return pattern;
+    }
+
+    public void setPattern(String pattern) {
+        this.pattern = pattern;
+    }
+
+    /**
+     * used my maven
+     *
+     * @param pattern
+     */
+    public void set(String pattern) {
+        setPattern(pattern);
+    }
+
+
+    /**
+     * used my ant
+     *
+     * @param pattern
+     */
+    public void addText(String pattern) {
+        if (pattern.trim().isEmpty()) {
+            return;
+        }
+
+        setPattern(pattern);
+    }
+
+    public void addConfiguredPattern(AntNestedElement pattern) {
+        set(pattern.getName());
+    }
+
+    @Override
+    public String toString() {
+        return "RegExp(" + pattern + ")";
+    }
+}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/fde7761f/cayenne-tools/src/main/java/org/apache/cayenne/tools/dbimport/config/ReverseEngineering.java
----------------------------------------------------------------------
diff --git a/cayenne-tools/src/main/java/org/apache/cayenne/tools/dbimport/config/ReverseEngineering.java b/cayenne-tools/src/main/java/org/apache/cayenne/tools/dbimport/config/ReverseEngineering.java
new file mode 100644
index 0000000..8f4277b
--- /dev/null
+++ b/cayenne-tools/src/main/java/org/apache/cayenne/tools/dbimport/config/ReverseEngineering.java
@@ -0,0 +1,60 @@
+/*****************************************************************
+ *   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.dbimport.config;
+
+
+import java.util.Collection;
+import java.util.LinkedList;
+
+/**
+ * @since 3.2.
+ */
+public class ReverseEngineering extends FilterContainer {
+
+    private Collection<Catalog> catalogs = new LinkedList<Catalog>();
+    private Collection<Schema> schemas = new LinkedList<Schema>();
+
+    public ReverseEngineering() {
+    }
+
+    public Collection<Catalog> getCatalogs() {
+        return catalogs;
+    }
+
+    public void setCatalogs(Collection<Catalog> catalogs) {
+        this.catalogs = catalogs;
+    }
+
+    public Collection<Schema> getSchemas() {
+        return schemas;
+    }
+
+    public void setSchemas(Collection<Schema> schemas) {
+        this.schemas = schemas;
+    }
+
+    public void addSchema(Schema schema) {
+        this.schemas.add(schema);
+    }
+
+    public void addCatalog(Catalog catalog) {
+        this.catalogs.add(catalog);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/fde7761f/cayenne-tools/src/main/java/org/apache/cayenne/tools/dbimport/config/ReverseEngineeringLoader.java
----------------------------------------------------------------------
diff --git a/cayenne-tools/src/main/java/org/apache/cayenne/tools/dbimport/config/ReverseEngineeringLoader.java b/cayenne-tools/src/main/java/org/apache/cayenne/tools/dbimport/config/ReverseEngineeringLoader.java
new file mode 100644
index 0000000..8e663b6
--- /dev/null
+++ b/cayenne-tools/src/main/java/org/apache/cayenne/tools/dbimport/config/ReverseEngineeringLoader.java
@@ -0,0 +1,31 @@
+/*****************************************************************
+ *   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.dbimport.config;
+
+import org.apache.cayenne.CayenneRuntimeException;
+import org.apache.cayenne.resource.Resource;
+
+/**
+ * @since 3.2.
+ */
+public interface ReverseEngineeringLoader {
+
+    ReverseEngineering load(Resource configurationResource) throws CayenneRuntimeException;
+
+}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/fde7761f/cayenne-tools/src/main/java/org/apache/cayenne/tools/dbimport/config/Schema.java
----------------------------------------------------------------------
diff --git a/cayenne-tools/src/main/java/org/apache/cayenne/tools/dbimport/config/Schema.java b/cayenne-tools/src/main/java/org/apache/cayenne/tools/dbimport/config/Schema.java
new file mode 100644
index 0000000..1a399f0
--- /dev/null
+++ b/cayenne-tools/src/main/java/org/apache/cayenne/tools/dbimport/config/Schema.java
@@ -0,0 +1,58 @@
+/*****************************************************************
+ *   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.dbimport.config;
+
+/**
+ * @since 3.2.
+ */
+public class Schema extends FilterContainer {
+
+    private String name;
+
+    public Schema() {
+    }
+
+    public Schema(String name) {
+        this.name = name;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public void set(String name) {
+        setName(name);
+    }
+
+    public void addConfiguredName(AntNestedElement name) {
+        setName(name.getName());
+    }
+
+    public void addText(String name) {
+        if (name.trim().isEmpty()) {
+            return;
+        }
+
+        setName(name);
+    }
+}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/fde7761f/cayenne-tools/src/main/java/org/apache/cayenne/tools/dbimport/config/Type.java
----------------------------------------------------------------------
diff --git a/cayenne-tools/src/main/java/org/apache/cayenne/tools/dbimport/config/Type.java b/cayenne-tools/src/main/java/org/apache/cayenne/tools/dbimport/config/Type.java
new file mode 100644
index 0000000..bbd1039
--- /dev/null
+++ b/cayenne-tools/src/main/java/org/apache/cayenne/tools/dbimport/config/Type.java
@@ -0,0 +1,136 @@
+/*****************************************************************
+ *   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.dbimport.config;
+
+import org.apache.cayenne.util.ToStringBuilder;
+
+/**
+ * @since 3.2.
+ */
+public class Type {
+
+    private String jdbc;
+    private String java;
+
+    private Integer length;
+    private Integer precision;
+    private Integer scale;
+    private Boolean notNull;
+
+    public String getJdbc() {
+        return jdbc;
+    }
+
+    public void setJdbc(String jdbc) {
+        this.jdbc = jdbc;
+    }
+
+    public String getJava() {
+        return java;
+    }
+
+    public void setJava(String java) {
+        this.java = java;
+    }
+
+    public Integer getLength() {
+        return length;
+    }
+
+    public void setLength(Integer length) {
+        this.length = length;
+    }
+
+    public Integer getPrecision() {
+        return precision;
+    }
+
+    public void setPrecision(Integer precision) {
+        this.precision = precision;
+    }
+
+    public Integer getScale() {
+        return scale;
+    }
+
+    public void setScale(Integer scale) {
+        this.scale = scale;
+    }
+
+    public Boolean getNotNull() {
+        return notNull;
+    }
+
+    public void setNotNull(Boolean notNull) {
+        this.notNull = notNull;
+    }
+
+    @Override
+    public boolean equals(Object o) {
+        if (this == o) {
+            return true;
+        }
+        if (o == null || getClass() != o.getClass()) {
+            return false;
+        }
+
+        Type type = (Type) o;
+
+        if (jdbc != null ? !jdbc.equals(type.jdbc) : type.jdbc != null) {
+            return false;
+        }
+        if (!length.equals(type.length)) {
+            return false;
+        }
+        if (!notNull.equals(type.notNull)) {
+            return false;
+        }
+        if (!precision.equals(type.precision)) {
+            return false;
+        }
+        if (!scale.equals(type.scale)) {
+            return false;
+        }
+
+        return true;
+    }
+
+    @Override
+    public int hashCode() {
+        int result = jdbc != null ? jdbc.hashCode() : 0;
+        result = 31 * result + length.hashCode();
+        result = 31 * result + precision.hashCode();
+        result = 31 * result + scale.hashCode();
+        result = 31 * result + notNull.hashCode();
+        return result;
+    }
+
+
+    @Override
+    public String toString() {
+        return new ToStringBuilder(this)
+                .append("jdbc", jdbc)
+                .append("java", java)
+                .append("length", length)
+                .append("precision", precision)
+                .append("scale", scale)
+                .append("notNull", notNull)
+                .toString();
+    }
+}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/fde7761f/cayenne-tools/src/main/java/org/apache/cayenne/tools/dbimport/config/TypeMapper.java
----------------------------------------------------------------------
diff --git a/cayenne-tools/src/main/java/org/apache/cayenne/tools/dbimport/config/TypeMapper.java b/cayenne-tools/src/main/java/org/apache/cayenne/tools/dbimport/config/TypeMapper.java
new file mode 100644
index 0000000..ed84fff
--- /dev/null
+++ b/cayenne-tools/src/main/java/org/apache/cayenne/tools/dbimport/config/TypeMapper.java
@@ -0,0 +1,95 @@
+/*****************************************************************
+ *   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.dbimport.config;
+
+import org.apache.cayenne.util.EqualsBuilder;
+import org.apache.cayenne.util.HashCodeBuilder;
+
+import java.util.Collection;
+import java.util.LinkedList;
+
+/**
+ * @since 3.2.
+ */
+public class TypeMapper {
+
+    private String mapperClassName;
+
+    private Boolean usePrimitives;
+
+    private Collection<Type> types = new LinkedList<Type>();
+
+    public String getMapperClassName() {
+        return mapperClassName;
+    }
+
+    public void setMapperClassName(String mapperClassName) {
+        this.mapperClassName = mapperClassName;
+    }
+
+    public Boolean getUsePrimitives() {
+        return usePrimitives;
+    }
+
+    public void setUsePrimitives(Boolean usePrimitives) {
+        this.usePrimitives = usePrimitives;
+    }
+
+    public Collection<Type> getTypes() {
+        return types;
+    }
+
+    public void setTypes(Collection<Type> types) {
+        this.types = types;
+    }
+
+    public void addType(Type type) {
+        this.types.add(type);
+    }
+
+
+    @Override
+    public boolean equals(Object obj) {
+        if (obj == null) {
+            return false;
+        }
+        if (obj == this) {
+            return true;
+        }
+        if (obj.getClass() != getClass()) {
+            return false;
+        }
+        TypeMapper rhs = (TypeMapper) obj;
+        return new EqualsBuilder()
+                .append(this.mapperClassName, rhs.mapperClassName)
+                .append(this.usePrimitives, rhs.usePrimitives)
+                .append(this.types, rhs.types)
+                .isEquals();
+    }
+
+    @Override
+    public int hashCode() {
+        return new HashCodeBuilder().append(mapperClassName).append(usePrimitives).append(types).toHashCode();
+    }
+
+    @Override
+    public String toString() {
+        return "TypeMapper {mapperClassName=" + mapperClassName + ", usePrimitives=" + usePrimitives + ", types=" + types + '}';
+    }
+}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/fde7761f/cayenne-tools/src/test/java/org/apache/cayenne/tools/DbImporterTaskTest.java
----------------------------------------------------------------------
diff --git a/cayenne-tools/src/test/java/org/apache/cayenne/tools/DbImporterTaskTest.java b/cayenne-tools/src/test/java/org/apache/cayenne/tools/DbImporterTaskTest.java
new file mode 100644
index 0000000..647b66d
--- /dev/null
+++ b/cayenne-tools/src/test/java/org/apache/cayenne/tools/DbImporterTaskTest.java
@@ -0,0 +1,168 @@
+/*
+ * 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 org.apache.cayenne.tools.dbimport.DbImportConfiguration;
+import org.apache.tools.ant.Project;
+import org.apache.tools.ant.ProjectHelper;
+import org.apache.tools.ant.UnknownElement;
+import org.apache.tools.ant.util.FileUtils;
+import org.custommonkey.xmlunit.DetailedDiff;
+import org.custommonkey.xmlunit.Diff;
+import org.custommonkey.xmlunit.XMLUnit;
+import org.junit.Test;
+import org.xml.sax.SAXException;
+
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+import java.net.URISyntaxException;
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import static org.apache.cayenne.tools.dbimport.config.DefaultReverseEngineeringLoaderTest.*;
+import static org.apache.commons.lang.StringUtils.isBlank;
+import static org.junit.Assert.fail;
+
+public class DbImporterTaskTest {
+
+    static {
+        XMLUnit.setIgnoreWhitespace(true);
+    }
+
+    @Test
+    public void testLoadCatalog() throws Exception {
+        assertCatalog(getCdbImport("build-catalog.xml").getReverseEngineering());
+    }
+
+    @Test
+    public void testLoadSchema() throws Exception {
+        assertSchema(getCdbImport("build-schema.xml").getReverseEngineering());
+    }
+
+    @Test
+    public void testLoadCatalogAndSchema() throws Exception {
+        assertCatalogAndSchema(getCdbImport("build-catalog-and-schema.xml").getReverseEngineering());
+    }
+
+    @Test
+    public void testLoadFlat() throws Exception {
+        assertFlat(getCdbImport("build-flat.xml").getReverseEngineering());
+    }
+
+    @Test
+    public void testIncludeTable() throws Exception {
+        test("build-include-table.xml");
+    }
+
+
+    private DbImporterTask getCdbImport(String buildFile) {
+        Project project = new Project();
+        ProjectHelper.configureProject(project, new File(getPackagePath() + "/" + buildFile));
+
+        UnknownElement task = (UnknownElement) project.getTargets().get("dist").getTasks()[0];
+        task.maybeConfigure();
+
+        return (DbImporterTask) task.getRealThing();
+    }
+
+    private String getPackagePath() {
+        return getClass().getClassLoader().getResource(getClass().getPackage().getName().replace('.', '/')).getPath();
+    }
+
+    private void test(String name) throws Exception {
+        DbImporterTask cdbImport = getCdbImport("dbimport/" + name);
+        File mapFile = cdbImport.getMap();
+        File mapFileCopy = new File(mapFile.getParentFile(), "copy-" + mapFile.getName());
+        if (mapFile.exists()) {
+            FileUtils.getFileUtils().copyFile(mapFile, mapFileCopy);
+            cdbImport.setMap(mapFileCopy);
+        } else {
+            mapFileCopy = mapFile;
+        }
+
+        prepareDatabase(name, cdbImport.toParameters());
+
+        try {
+            cdbImport.execute();
+            verifyResult(mapFile, mapFileCopy);
+        } finally {
+            cleanDb(cdbImport.toParameters());
+        }
+    }
+
+    private void cleanDb(DbImportConfiguration dbImportConfiguration) throws ClassNotFoundException, IllegalAccessException, InstantiationException, SQLException {
+        Class.forName(dbImportConfiguration.getDriver()).newInstance();
+        // Get a connection
+        Connection connection = DriverManager.getConnection(dbImportConfiguration.getUrl());
+        Statement stmt = connection.createStatement();
+
+        ResultSet tables = connection.getMetaData().getTables(null, null, null, new String[]{"TABLE"});
+        while (tables.next()) {
+            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 {
+            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();
+        } catch (IOException e) {
+            e.printStackTrace();
+            fail();
+        }
+    }
+
+    private void prepareDatabase(String sqlFile, DbImportConfiguration dbImportConfiguration) throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException, IOException, URISyntaxException {
+        Class.forName(dbImportConfiguration.getDriver()).newInstance();
+        // Get a connection
+        Statement stmt = DriverManager.getConnection(dbImportConfiguration.getUrl()).createStatement();
+
+        for (String sql : FileUtils.readFully(new FileReader(getPackagePath() + "/dbimport/" + sqlFile + ".sql")).split(";")) {
+            stmt.execute(sql);
+        }
+    }
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cayenne/blob/fde7761f/cayenne-tools/src/test/java/org/apache/cayenne/tools/NamePatternMatcherTest.java
----------------------------------------------------------------------
diff --git a/cayenne-tools/src/test/java/org/apache/cayenne/tools/NamePatternMatcherTest.java b/cayenne-tools/src/test/java/org/apache/cayenne/tools/NamePatternMatcherTest.java
index 143a473..a67e85b 100644
--- a/cayenne-tools/src/test/java/org/apache/cayenne/tools/NamePatternMatcherTest.java
+++ b/cayenne-tools/src/test/java/org/apache/cayenne/tools/NamePatternMatcherTest.java
@@ -21,40 +21,25 @@ package org.apache.cayenne.tools;
 
 import junit.framework.TestCase;
 
+import org.apache.cayenne.access.loader.NamePatternMatcher;
 import org.apache.tools.ant.Task;
 
+import static org.apache.cayenne.access.loader.NamePatternMatcher.replaceWildcardInStringWithString;
+
 public class NamePatternMatcherTest extends TestCase {
 
     /**
      * Test pattern expansion.
      */
     public void testReplaceWildcardInStringWithString() throws Exception {
-        assertEquals(null, NamePatternMatcher.replaceWildcardInStringWithString(
-                "*",
-                null,
-                "Entity"));
-        assertEquals("*.java", NamePatternMatcher.replaceWildcardInStringWithString(
-                null,
-                "*.java",
-                "Entity"));
-        assertEquals("Entity.java", NamePatternMatcher.replaceWildcardInStringWithString(
-                "*",
-                "*.java",
-                "Entity"));
-        assertEquals("java.Entity", NamePatternMatcher.replaceWildcardInStringWithString(
-                "*",
-                "java.*",
-                "Entity"));
-        assertEquals("Entity.Entity", NamePatternMatcher
-                .replaceWildcardInStringWithString("*", "*.*", "Entity"));
-        assertEquals("EntityEntity", NamePatternMatcher
-                .replaceWildcardInStringWithString("*", "**", "Entity"));
-        assertEquals("EditEntityReport.vm", NamePatternMatcher
-                .replaceWildcardInStringWithString("*", "Edit*Report.vm", "Entity"));
-        assertEquals("Entity", NamePatternMatcher.replaceWildcardInStringWithString(
-                "*",
-                "*",
-                "Entity"));
+        assertEquals(null, replaceWildcardInStringWithString("*", null, "Entity"));
+        assertEquals("*.java", replaceWildcardInStringWithString(null, "*.java", "Entity"));
+        assertEquals("Entity.java", replaceWildcardInStringWithString("*", "*.java", "Entity"));
+        assertEquals("java.Entity", replaceWildcardInStringWithString("*", "java.*", "Entity"));
+        assertEquals("Entity.Entity", replaceWildcardInStringWithString("*", "*.*", "Entity"));
+        assertEquals("EntityEntity", replaceWildcardInStringWithString("*", "**", "Entity"));
+        assertEquals("EditEntityReport.vm", replaceWildcardInStringWithString("*", "Edit*Report.vm", "Entity"));
+        assertEquals("Entity", replaceWildcardInStringWithString("*", "*", "Entity"));
     }
 
     /**
@@ -71,10 +56,8 @@ public class NamePatternMatcherTest extends TestCase {
 
         String includePattern = "billing_*,user?";
         String excludePattern = null;
-        NamePatternMatcher namePatternMatcher = new NamePatternMatcher(
-                new AntLogger(parentTask),
-                includePattern,
-                excludePattern);
+        NamePatternMatcher namePatternMatcher = NamePatternMatcher.build(
+                new AntLogger(parentTask), includePattern, excludePattern);
 
         String[] nullFilters = namePatternMatcher.tokenizePattern(null);
         assertEquals(0, nullFilters.length);
@@ -99,10 +82,8 @@ public class NamePatternMatcherTest extends TestCase {
 
         String includePattern = "Organization,SecGroup,SecIndividual";
         String excludePattern = null;
-        NamePatternMatcher namePatternMatcher = new NamePatternMatcher(
-                new AntLogger(parentTask),
-                includePattern,
-                excludePattern);
+        NamePatternMatcher namePatternMatcher = NamePatternMatcher.build(
+                new AntLogger(parentTask), includePattern, excludePattern);
 
         String[] filters = namePatternMatcher.tokenizePattern(includePattern);
         assertEquals(3, filters.length);

http://git-wip-us.apache.org/repos/asf/cayenne/blob/fde7761f/cayenne-tools/src/test/java/org/apache/cayenne/tools/dbimport/DbImportActionTest.java
----------------------------------------------------------------------
diff --git a/cayenne-tools/src/test/java/org/apache/cayenne/tools/dbimport/DbImportActionTest.java b/cayenne-tools/src/test/java/org/apache/cayenne/tools/dbimport/DbImportActionTest.java
index 2977576..72d1df4 100644
--- a/cayenne-tools/src/test/java/org/apache/cayenne/tools/dbimport/DbImportActionTest.java
+++ b/cayenne-tools/src/test/java/org/apache/cayenne/tools/dbimport/DbImportActionTest.java
@@ -1,25 +1,26 @@
-/*****************************************************************
- *   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.tools.dbimport;
 
 import org.apache.cayenne.CayenneRuntimeException;
 import org.apache.cayenne.access.DbLoader;
+import org.apache.cayenne.access.loader.DbLoaderConfiguration;
 import org.apache.cayenne.access.DbLoaderDelegate;
 import org.apache.cayenne.configuration.DataNodeDescriptor;
 import org.apache.cayenne.configuration.server.DataSourceFactory;
@@ -69,16 +70,10 @@ public class DbImportActionTest {
     @Test
     public void testNewDataMapImport() throws Exception {
 
-        final boolean[] haveWeTriedToLoadProcedures = {false};
         DbLoader dbLoader = new DbLoader(null, null, null) {
             @Override
-            public void load(DataMap dataMap, String catalogPattern, String schemaPattern, String tablePattern, String... tableTypes) throws SQLException {
-                new DataMapBuilder(dataMap).withDbEntities(2);
-            }
-
-            @Override
-            public void loadProcedures(DataMap dataMap, String catalogPattern, String schemaPattern, String namePattern) throws SQLException {
-                haveWeTriedToLoadProcedures[0] = true;
+            public DataMap load(DbLoaderConfiguration config) throws SQLException {
+                return new DataMapBuilder(new DataMap()).withDbEntities(2).build();
             }
 
             @Override
@@ -93,7 +88,10 @@ public class DbImportActionTest {
 
         when(params.createDataMap()).thenReturn(new DataMap("testImport"));
         when(params.createMergeDelegate()).thenReturn(new DefaultModelMergeDelegate());
-        when(params.isImportProcedures()).thenReturn(true);
+        when(params.getDbLoaderConfig()).thenReturn(new DbLoaderConfiguration());
+
+        final DataMap DATA_MAP = new DataMap();
+        when(params.initializeDataMap(any(DataMap.class))).thenReturn(DATA_MAP);
 
         final boolean[] haveWeTriedToSave = {false};
         DbImportAction action = buildDbImportAction(new FileProjectSaver() {
@@ -102,14 +100,12 @@ public class DbImportActionTest {
                 haveWeTriedToSave[0] = true;
 
                 // Validation phase
-                DataMap rootNode = (DataMap) project.getRootNode();
-                assertEquals(2, rootNode.getDbEntityMap().size());
+                assertEquals(DATA_MAP, project.getRootNode());
             }
         }, null);
 
         action.execute(params);
 
-        assertTrue("We should try to load procedures.", haveWeTriedToLoadProcedures[0]);
         assertTrue("We should try to save.", haveWeTriedToSave[0]);
     }
 
@@ -117,7 +113,8 @@ public class DbImportActionTest {
     public void testImportWithFieldChanged() throws Exception {
         DbLoader dbLoader = new DbLoader(null, null, null) {
             @Override
-            public void load(DataMap dataMap, String catalogPattern, String schemaPattern, String tablePattern, String... tableTypes) throws SQLException {
+            public DataMap load(DbLoaderConfiguration config) throws SQLException {
+                DataMap dataMap = new DataMap("dataMap");
                 new DataMapBuilder(dataMap).with(
                         dbEntity("ARTGROUP").attributes(
                                 dbAttr("GROUP_ID").typeInt().primaryKey(),
@@ -128,6 +125,8 @@ public class DbImportActionTest {
                         objEntity("org.apache.cayenne.testdo.testmap", "ArtGroup", "ARTGROUP").attributes(
                                 objAttr("name").type(String.class).dbPath("NAME")
                 ));
+
+                return dataMap;
             }
 
             @Override
@@ -143,6 +142,7 @@ public class DbImportActionTest {
         when(params.createDataMap()).thenReturn(new DataMap("testImport"));
         when(params.getDataMapFile()).thenReturn(FILE_STUB);
         when(params.createMergeDelegate()).thenReturn(new DefaultModelMergeDelegate());
+        when(params.getDbLoaderConfig()).thenReturn(new DbLoaderConfiguration());
 
         final boolean[] haveWeTriedToSave = {false};
         DbImportAction action = buildDbImportAction(new FileProjectSaver() {
@@ -185,11 +185,13 @@ public class DbImportActionTest {
     public void testImportWithoutChanges() throws Exception {
         DbLoader dbLoader = new DbLoader(null, null, null) {
             @Override
-            public void load(DataMap dataMap, String catalogPattern, String schemaPattern, String tablePattern, String... tableTypes) throws SQLException {
+            public DataMap load(DbLoaderConfiguration config) throws SQLException {
+                DataMap dataMap = new DataMap("dataMap");
                 new DataMapBuilder(dataMap).with(
                         dbEntity("ARTGROUP").attributes(
                                 dbAttr("NAME").typeVarchar(100).mandatory()
                         ));
+                return dataMap;
             }
 
             @Override
@@ -205,6 +207,7 @@ public class DbImportActionTest {
         when(params.createDataMap()).thenReturn(new DataMap("testImport"));
         when(params.getDataMapFile()).thenReturn(FILE_STUB);
         when(params.createMergeDelegate()).thenReturn(new DefaultModelMergeDelegate());
+        when(params.getDbLoaderConfig()).thenReturn(new DbLoaderConfiguration());
 
         Log log = mock(Log.class);
         when(log.isDebugEnabled()).thenReturn(false);
@@ -231,7 +234,7 @@ public class DbImportActionTest {
     public void testImportWithDbError() throws Exception {
         DbLoader dbLoader = mock(DbLoader.class);
         when(dbLoader.getDefaultTableTypes()).thenReturn(null);
-        doThrow(new SQLException()).when(dbLoader).load(any(DataMap.class), anyString(), anyString(), anyString());
+        doThrow(new SQLException()).when(dbLoader).load(any(DataMap.class), any(DbLoaderConfiguration.class));
 
         DbImportConfiguration params = mock(DbImportConfiguration.class);
         when(params.createLoader(any(DbAdapter.class), any(Connection.class), any(DbLoaderDelegate.class)))

http://git-wip-us.apache.org/repos/asf/cayenne/blob/fde7761f/cayenne-tools/src/test/java/org/apache/cayenne/tools/dbimport/DbImportConfigurationTest.java
----------------------------------------------------------------------
diff --git a/cayenne-tools/src/test/java/org/apache/cayenne/tools/dbimport/DbImportConfigurationTest.java b/cayenne-tools/src/test/java/org/apache/cayenne/tools/dbimport/DbImportConfigurationTest.java
index 18aeeb4..e8f03d0 100644
--- a/cayenne-tools/src/test/java/org/apache/cayenne/tools/dbimport/DbImportConfigurationTest.java
+++ b/cayenne-tools/src/test/java/org/apache/cayenne/tools/dbimport/DbImportConfigurationTest.java
@@ -18,214 +18,21 @@
  ****************************************************************/
 package org.apache.cayenne.tools.dbimport;
 
-import org.apache.cayenne.access.DbLoader;
-import org.apache.cayenne.access.DbLoaderDelegate;
-import org.apache.cayenne.dba.DbAdapter;
 import org.apache.cayenne.map.DataMap;
-import org.apache.cayenne.map.DbAttribute;
 import org.apache.cayenne.map.DbEntity;
-import org.apache.cayenne.map.ObjAttribute;
-import org.apache.cayenne.map.ObjEntity;
 import org.apache.cayenne.util.XMLEncoder;
 import org.junit.Test;
 
 import java.io.File;
 import java.io.PrintWriter;
-import java.lang.reflect.Field;
 import java.net.MalformedURLException;
 import java.net.URL;
-import java.sql.Connection;
-import java.sql.Types;
-import java.util.List;
 
 import static org.junit.Assert.*;
-import static org.junit.Assert.assertEquals;
-import static org.mockito.Mockito.mock;
 
 public class DbImportConfigurationTest {
 
     @Test
-    public void testCreateLoader() throws Exception {
-        DbImportConfiguration parameters = new DbImportConfiguration();
-
-        Connection connection = mock(Connection.class);
-
-        DbLoader loader = parameters.createLoader(mock(DbAdapter.class), connection,
-                mock(DbLoaderDelegate.class));
-        assertNotNull(loader);
-        assertSame(connection, loader.getConnection());
-        assertTrue(loader.includeTableName("dummy"));
-    }
-
-    @Test
-    public void testCreateLoader_IncludeExclude() throws Exception {
-        DbImportConfiguration parameters = new DbImportConfiguration();
-        parameters.setIncludeTables("a,b,c*");
-
-        DbLoader loader1 = parameters.createLoader(mock(DbAdapter.class), mock(Connection.class),
-                mock(DbLoaderDelegate.class));
-
-        assertFalse(loader1.includeTableName("dummy"));
-        assertFalse(loader1.includeTableName("ab"));
-        assertTrue(loader1.includeTableName("a"));
-        assertTrue(loader1.includeTableName("b"));
-        assertTrue(loader1.includeTableName("cd"));
-
-        parameters.setExcludeTables("cd");
-
-        DbLoader loader2 = parameters.createLoader(mock(DbAdapter.class), mock(Connection.class),
-                mock(DbLoaderDelegate.class));
-
-        assertFalse(loader2.includeTableName("dummy"));
-        assertFalse(loader2.includeTableName("ab"));
-        assertTrue(loader2.includeTableName("a"));
-        assertTrue(loader2.includeTableName("b"));
-        assertFalse(loader2.includeTableName("cd"));
-        assertTrue(loader2.includeTableName("cx"));
-    }
-
-
-    @Test
-    public void testCreateLoader_MeaningfulPk_Default() throws Exception {
-        DbImportConfiguration parameters = new DbImportConfiguration();
-        assertNull(parameters.getMeaningfulPkTables());
-
-        DbLoader loader1 = parameters.createLoader(mock(DbAdapter.class), mock(Connection.class),
-                mock(DbLoaderDelegate.class));
-
-        DataMap map = new DataMap();
-
-        DbEntity e1 = new DbEntity("e1");
-        DbAttribute pk = new DbAttribute("pk", Types.INTEGER, e1);
-        pk.setPrimaryKey(true);
-        e1.addAttribute(pk);
-        DbAttribute nonPk = new DbAttribute("nonPk", Types.INTEGER, e1);
-        e1.addAttribute(nonPk);
-
-        map.addDbEntity(e1);
-
-        // DbLoader is so ugly and hard to test..
-        Field dbEntityList = DbLoader.class.getDeclaredField("dbEntityList");
-        dbEntityList.setAccessible(true);
-        List<DbEntity> entities = (List<DbEntity>) dbEntityList.get(loader1);
-        entities.add(e1);
-
-        loader1.loadObjEntities(map);
-
-        ObjEntity oe1 = map.getObjEntity("E1");
-        assertEquals(1, oe1.getAttributes().size());
-        assertNotNull(oe1.getAttribute("nonPk"));
-    }
-
-    @Test
-    public void testCreateLoader_MeaningfulPk_Specified() throws Exception {
-        DbImportConfiguration parameters = new DbImportConfiguration();
-        parameters.setMeaningfulPkTables("a*");
-
-        DbLoader loader1 = parameters.createLoader(mock(DbAdapter.class), mock(Connection.class),
-                mock(DbLoaderDelegate.class));
-
-        // DbLoader is so ugly and hard to test..
-        Field dbEntityList = DbLoader.class.getDeclaredField("dbEntityList");
-        dbEntityList.setAccessible(true);
-        List<DbEntity> entities = (List<DbEntity>) dbEntityList.get(loader1);
-
-        DataMap map = new DataMap();
-
-        DbEntity e1 = new DbEntity("e1");
-        DbAttribute pk = new DbAttribute("pk", Types.INTEGER, e1);
-        pk.setPrimaryKey(true);
-        e1.addAttribute(pk);
-        DbAttribute nonPk = new DbAttribute("nonPk", Types.INTEGER, e1);
-        e1.addAttribute(nonPk);
-
-        map.addDbEntity(e1);
-        entities.add(e1);
-
-        DbEntity a1 = new DbEntity("a1");
-        DbAttribute apk = new DbAttribute("pk", Types.INTEGER, a1);
-        apk.setPrimaryKey(true);
-        a1.addAttribute(apk);
-        DbAttribute anonPk = new DbAttribute("nonPk", Types.INTEGER, a1);
-        a1.addAttribute(anonPk);
-
-        map.addDbEntity(a1);
-        entities.add(a1);
-
-        loader1.loadObjEntities(map);
-
-        ObjEntity oe1 = map.getObjEntity("E1");
-        assertEquals(1, oe1.getAttributes().size());
-        assertNotNull(oe1.getAttribute("nonPk"));
-
-        ObjEntity oe2 = map.getObjEntity("A1");
-        assertEquals(2, oe2.getAttributes().size());
-        assertNotNull(oe2.getAttribute("nonPk"));
-        assertNotNull(oe2.getAttribute("pk"));
-    }
-
-    @Test
-    public void testCreateLoader_UsePrimitives_False() throws Exception {
-        DbImportConfiguration parameters = new DbImportConfiguration();
-        parameters.setUsePrimitives(false);
-
-        DbLoader loader1 = parameters.createLoader(mock(DbAdapter.class), mock(Connection.class),
-                mock(DbLoaderDelegate.class));
-
-        DataMap map = new DataMap();
-
-        DbEntity e1 = new DbEntity("e1");
-        DbAttribute nonPk = new DbAttribute("nonPk", Types.INTEGER, e1);
-        e1.addAttribute(nonPk);
-
-        map.addDbEntity(e1);
-
-        // DbLoader is so ugly and hard to test..
-        Field dbEntityList = DbLoader.class.getDeclaredField("dbEntityList");
-        dbEntityList.setAccessible(true);
-        List<DbEntity> entities = (List<DbEntity>) dbEntityList.get(loader1);
-        entities.add(e1);
-
-        loader1.loadObjEntities(map);
-
-        ObjEntity oe1 = map.getObjEntity("E1");
-
-        ObjAttribute oa1 = oe1.getAttribute("nonPk");
-        assertEquals("java.lang.Integer", oa1.getType());
-    }
-
-    @Test
-    public void testCreateLoader_UsePrimitives_True() throws Exception {
-        DbImportConfiguration parameters = new DbImportConfiguration();
-        parameters.setUsePrimitives(true);
-
-        DbLoader loader1 = parameters.createLoader(mock(DbAdapter.class), mock(Connection.class),
-                mock(DbLoaderDelegate.class));
-
-        DataMap map = new DataMap();
-
-        DbEntity e1 = new DbEntity("e1");
-        DbAttribute nonPk = new DbAttribute("nonPk", Types.INTEGER, e1);
-        e1.addAttribute(nonPk);
-
-        map.addDbEntity(e1);
-
-        // DbLoader is so ugly and hard to test..
-        Field dbEntityList = DbLoader.class.getDeclaredField("dbEntityList");
-        dbEntityList.setAccessible(true);
-        List<DbEntity> entities = (List<DbEntity>) dbEntityList.get(loader1);
-        entities.add(e1);
-
-        loader1.loadObjEntities(map);
-
-        ObjEntity oe1 = map.getObjEntity("E1");
-
-        ObjAttribute oa1 = oe1.getAttribute("nonPk");
-        assertEquals("int", oa1.getType());
-    }
-
-
-    @Test
     public void testCreateDataMap_New() throws Exception {
         URL outUrl = dataMapUrl("testCreateDataMap1.map.xml");
 

http://git-wip-us.apache.org/repos/asf/cayenne/blob/fde7761f/cayenne-tools/src/test/java/org/apache/cayenne/tools/dbimport/config/DefaultReverseEngineeringLoaderTest.java
----------------------------------------------------------------------
diff --git a/cayenne-tools/src/test/java/org/apache/cayenne/tools/dbimport/config/DefaultReverseEngineeringLoaderTest.java b/cayenne-tools/src/test/java/org/apache/cayenne/tools/dbimport/config/DefaultReverseEngineeringLoaderTest.java
new file mode 100644
index 0000000..16c9735
--- /dev/null
+++ b/cayenne-tools/src/test/java/org/apache/cayenne/tools/dbimport/config/DefaultReverseEngineeringLoaderTest.java
@@ -0,0 +1,203 @@
+/*
+ * 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.dbimport.config;
+
+import org.apache.cayenne.resource.URLResource;
+import org.junit.Test;
+
+import java.io.File;
+import java.net.MalformedURLException;
+import java.util.Iterator;
+
+import static org.junit.Assert.assertEquals;
+
+public class DefaultReverseEngineeringLoaderTest {
+
+    @Test
+    public void testLoadCatalog() throws Exception {
+        ReverseEngineering engineering = new DefaultReverseEngineeringLoader()
+                .load(getResource("/reverseEngineering-catalog.xml"));
+
+        assertCatalog(engineering);
+    }
+
+    public static void assertCatalog(ReverseEngineering engineering) {
+        Iterator<Catalog> catalogs = engineering.getCatalogs().iterator();
+        assertEquals("catalog-name-01", catalogs.next().getName());
+        assertEquals("catalog-name-02", catalogs.next().getName());
+
+        Catalog catalog = catalogs.next();
+        assertEquals("catalog-name-03", catalog.getName());
+
+        Iterator<IncludeTable> includeTables = catalog.getIncludeTables().iterator();
+        assertEquals("includeTable-01", includeTables.next().getPattern());
+        assertEquals("includeTable-02", includeTables.next().getPattern());
+
+        IncludeTable includeTable = includeTables.next();
+        assertEquals("includeTable-03", includeTable.getPattern());
+        assertEquals("includeColumn-01", includeTable.getIncludeColumns().iterator().next().getPattern());
+        assertEquals("excludeColumn-01", includeTable.getExcludeColumns().iterator().next().getPattern());
+
+        Iterator<ExcludeTable> excludeTables = catalog.getExcludeTables().iterator();
+        assertEquals("excludeTable-01", excludeTables.next().getPattern());
+        assertEquals("excludeTable-02", excludeTables.next().getPattern());
+        assertEquals("excludeTable-03", excludeTables.next().getPattern());
+
+        Iterator<ExcludeColumn> excludeColumns = catalog.getExcludeColumns().iterator();
+        assertEquals("excludeColumn-01", excludeColumns.next().getPattern());
+        assertEquals("excludeColumn-02", excludeColumns.next().getPattern());
+        assertEquals("excludeColumn-03", excludeColumns.next().getPattern());
+        Iterator<IncludeColumn> includeColumns = catalog.getIncludeColumns().iterator();
+        assertEquals("includeColumn-01", includeColumns.next().getPattern());
+        assertEquals("includeColumn-02", includeColumns.next().getPattern());
+        assertEquals("includeColumn-03", includeColumns.next().getPattern());
+
+        Iterator<ExcludeProcedure> excludeProcedures = catalog.getExcludeProcedures().iterator();
+        assertEquals("excludeProcedure-01", excludeProcedures.next().getPattern());
+        assertEquals("excludeProcedure-02", excludeProcedures.next().getPattern());
+        assertEquals("excludeProcedure-03", excludeProcedures.next().getPattern());
+        Iterator<IncludeProcedure> includeProcedures = catalog.getIncludeProcedures().iterator();
+        assertEquals("includeProcedure-01", includeProcedures.next().getPattern());
+        assertEquals("includeProcedure-02", includeProcedures.next().getPattern());
+        assertEquals("includeProcedure-03", includeProcedures.next().getPattern());
+    }
+
+    @Test
+    public void testLoadSchema() throws Exception {
+        ReverseEngineering engineering = new DefaultReverseEngineeringLoader()
+                .load(getResource("/reverseEngineering-schema.xml"));
+
+        assertSchema(engineering);
+    }
+
+    public static void assertSchema(ReverseEngineering engineering) {
+        Iterator<Schema> schemas = engineering.getSchemas().iterator();
+        assertEquals("schema-name-01", schemas.next().getName());
+        assertEquals("schema-name-02", schemas.next().getName());
+
+        Schema schema = schemas.next();
+        assertEquals("schema-name-03", schema.getName());
+
+        assertSchemaContent(schema);
+    }
+
+    public static void assertSchemaContent(Schema schema) {
+        Iterator<IncludeTable> includeTables = schema.getIncludeTables().iterator();
+        assertEquals("includeTable-01", includeTables.next().getPattern());
+        assertEquals("includeTable-02", includeTables.next().getPattern());
+
+        IncludeTable includeTable = includeTables.next();
+        assertEquals("includeTable-03", includeTable.getPattern());
+        assertEquals("includeColumn-01", includeTable.getIncludeColumns().iterator().next().getPattern());
+        assertEquals("excludeColumn-01", includeTable.getExcludeColumns().iterator().next().getPattern());
+
+        Iterator<ExcludeTable> excludeTables = schema.getExcludeTables().iterator();
+        assertEquals("excludeTable-01", excludeTables.next().getPattern());
+        assertEquals("excludeTable-02", excludeTables.next().getPattern());
+        assertEquals("excludeTable-03", excludeTables.next().getPattern());
+
+        Iterator<ExcludeColumn> excludeColumns = schema.getExcludeColumns().iterator();
+        assertEquals("excludeColumn-01", excludeColumns.next().getPattern());
+        assertEquals("excludeColumn-02", excludeColumns.next().getPattern());
+        assertEquals("excludeColumn-03", excludeColumns.next().getPattern());
+        Iterator<IncludeColumn> includeColumns = schema.getIncludeColumns().iterator();
+        assertEquals("includeColumn-01", includeColumns.next().getPattern());
+        assertEquals("includeColumn-02", includeColumns.next().getPattern());
+        assertEquals("includeColumn-03", includeColumns.next().getPattern());
+
+        Iterator<ExcludeProcedure> excludeProcedures = schema.getExcludeProcedures().iterator();
+        assertEquals("excludeProcedure-01", excludeProcedures.next().getPattern());
+        assertEquals("excludeProcedure-02", excludeProcedures.next().getPattern());
+        assertEquals("excludeProcedure-03", excludeProcedures.next().getPattern());
+        Iterator<IncludeProcedure> includeProcedures = schema.getIncludeProcedures().iterator();
+        assertEquals("includeProcedure-01", includeProcedures.next().getPattern());
+        assertEquals("includeProcedure-02", includeProcedures.next().getPattern());
+        assertEquals("includeProcedure-03", includeProcedures.next().getPattern());
+    }
+
+    @Test
+    public void testLoadCatalogAndSchema() throws Exception {
+        ReverseEngineering engineering = new DefaultReverseEngineeringLoader()
+                .load(getResource("/reverseEngineering-catalog-and-schema.xml"));
+
+        assertCatalogAndSchema(engineering);
+    }
+
+    public static void assertCatalogAndSchema(ReverseEngineering engineering) {
+        Catalog catalog = engineering.getCatalogs().iterator().next();
+        assertEquals("catalog-name", catalog.getName());
+
+        Schema schema = catalog.getSchemas().iterator().next();
+        assertEquals("schema-name", schema.getName());
+
+        assertSchemaContent(schema);
+    }
+
+    @Test
+    public void testLoadFlat() throws Exception {
+        ReverseEngineering engineering = new DefaultReverseEngineeringLoader()
+                .load(getResource("/reverseEngineering-flat.xml"));
+
+        assertFlat(engineering);
+    }
+
+    public static void assertFlat(ReverseEngineering engineering) {
+        Iterator<IncludeTable> includeTables = engineering.getIncludeTables().iterator();
+        assertEquals("includeTable-01", includeTables.next().getPattern());
+        assertEquals("includeTable-02", includeTables.next().getPattern());
+
+        IncludeTable includeTable = includeTables.next();
+        assertEquals("includeTable-03", includeTable.getPattern());
+        assertEquals("includeColumn-01", includeTable.getIncludeColumns().iterator().next().getPattern());
+        assertEquals("excludeColumn-01", includeTable.getExcludeColumns().iterator().next().getPattern());
+
+        Iterator<ExcludeTable> excludeTables = engineering.getExcludeTables().iterator();
+        assertEquals("excludeTable-01", excludeTables.next().getPattern());
+        assertEquals("excludeTable-02", excludeTables.next().getPattern());
+        assertEquals("excludeTable-03", excludeTables.next().getPattern());
+
+        Iterator<ExcludeColumn> excludeColumns = engineering.getExcludeColumns().iterator();
+        assertEquals("excludeColumn-01", excludeColumns.next().getPattern());
+        assertEquals("excludeColumn-02", excludeColumns.next().getPattern());
+        assertEquals("excludeColumn-03", excludeColumns.next().getPattern());
+        Iterator<IncludeColumn> includeColumns = engineering.getIncludeColumns().iterator();
+        assertEquals("includeColumn-01", includeColumns.next().getPattern());
+        assertEquals("includeColumn-02", includeColumns.next().getPattern());
+        assertEquals("includeColumn-03", includeColumns.next().getPattern());
+
+        Iterator<ExcludeProcedure> excludeProcedures = engineering.getExcludeProcedures().iterator();
+        assertEquals("excludeProcedure-01", excludeProcedures.next().getPattern());
+        assertEquals("excludeProcedure-02", excludeProcedures.next().getPattern());
+        assertEquals("excludeProcedure-03", excludeProcedures.next().getPattern());
+        Iterator<IncludeProcedure> includeProcedures = engineering.getIncludeProcedures().iterator();
+        assertEquals("includeProcedure-01", includeProcedures.next().getPattern());
+        assertEquals("includeProcedure-02", includeProcedures.next().getPattern());
+        assertEquals("includeProcedure-03", includeProcedures.next().getPattern());
+    }
+
+    protected URLResource getResource(String file) throws MalformedURLException {
+        return new URLResource(new File(getPackagePath() + file).toURI().toURL());
+    }
+
+    private String getPackagePath() {
+        return getClass().getClassLoader().getResource(getClass().getPackage().getName().replace('.', '/')).getPath();
+    }
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cayenne/blob/fde7761f/cayenne-tools/src/test/java/org/apache/cayenne/tools/dbimport/config/FiltersConfigBuilderTest.java
----------------------------------------------------------------------
diff --git a/cayenne-tools/src/test/java/org/apache/cayenne/tools/dbimport/config/FiltersConfigBuilderTest.java b/cayenne-tools/src/test/java/org/apache/cayenne/tools/dbimport/config/FiltersConfigBuilderTest.java
new file mode 100644
index 0000000..54fb4c0
--- /dev/null
+++ b/cayenne-tools/src/test/java/org/apache/cayenne/tools/dbimport/config/FiltersConfigBuilderTest.java
@@ -0,0 +1,153 @@
+/*
+ * 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.dbimport.config;
+
+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.junit.Test;
+
+import static org.apache.cayenne.access.loader.filters.FilterFactory.*;
+import static org.apache.cayenne.access.loader.filters.FiltersFactory.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+
+public class FiltersConfigBuilderTest {
+
+    @Test
+    public void testEmptyDbEntitiesFilters() throws Exception {
+        ReverseEngineering engineering = new ReverseEngineering();
+        FiltersConfig executions = new FiltersConfigBuilder(engineering).filtersConfig();
+
+        assertEquals("If nothing was configured we have to import everything. Filter %/%/% true/true/true",
+                new FiltersConfig(eFilters(path(), TRUE, TRUE, NULL)),
+                executions);
+    }
+
+    @Test
+    public void testOnlyOneCatalogDbEntitiesFilters() throws Exception {
+        ReverseEngineering engineering = new ReverseEngineering();
+        engineering.addCatalog(new Catalog("catalog_01"));
+        FiltersConfig executions = new FiltersConfigBuilder(engineering).filtersConfig();
+
+
+        assertEquals(new FiltersConfig(eFilters(path("catalog_01", null), TRUE, TRUE, NULL)),
+                executions);
+    }
+
+    @Test
+    public void testCatalogDbEntitiesFilters() throws Exception {
+        ReverseEngineering engineering = new ReverseEngineering();
+        engineering.addCatalog(new Catalog("catalog_01"));
+        engineering.addCatalog(new Catalog("catalog_02").schema(new Schema("schema_01")));
+        engineering.addCatalog(new Catalog("catalog_02").schema(new Schema("schema_02")));
+        engineering.addCatalog(new Catalog("catalog_02").schema(new Schema("schema_03")));
+        engineering.addCatalog(new Catalog("catalog_03").schema(new Schema("schema_01")));
+        engineering.addCatalog(new Catalog("catalog_03").schema(new Schema("schema_01")));
+        engineering.addCatalog(new Catalog("catalog_03").schema(new Schema("schema_01")));
+        engineering.addCatalog(new Catalog("catalog_03").schema(new Schema("schema_01")));
+        FiltersConfig executions = new FiltersConfigBuilder(engineering).filtersConfig();
+
+
+        assertEquals(new FiltersConfig(
+                        eFilters(path("catalog_01", null), TRUE, TRUE, NULL),
+                        eFilters(path("catalog_02", "schema_01"), TRUE, TRUE, NULL),
+                        eFilters(path("catalog_02", "schema_02"), TRUE, TRUE, NULL),
+                        eFilters(path("catalog_02", "schema_03"), TRUE, TRUE, NULL),
+                        eFilters(path("catalog_03", "schema_01"), TRUE, TRUE, NULL)
+                ),
+                executions);
+    }
+
+    @Test
+    public void testSchemaDbEntitiesFilters() throws Exception {
+        ReverseEngineering engineering = new ReverseEngineering();
+        engineering.addSchema(new Schema("schema_01"));
+        engineering.addSchema(new Schema("schema_02"));
+        engineering.addSchema(new Schema("schema_03"));
+        FiltersConfig executions = new FiltersConfigBuilder(engineering).filtersConfig();
+
+
+        assertEquals(new FiltersConfig(
+                        eFilters(path(null, "schema_01"), TRUE, TRUE, NULL),
+                        eFilters(path(null, "schema_02"), TRUE, TRUE, NULL),
+                        eFilters(path(null, "schema_03"), TRUE, TRUE, NULL)
+                ),
+                executions);
+    }
+
+    @Test
+    public void testFiltersDbEntitiesFilters() throws Exception {
+        ReverseEngineering engineering = new ReverseEngineering();
+        engineering.addIncludeTable(new IncludeTable("IncludeTable"));
+        engineering.addIncludeColumn(new IncludeColumn("IncludeColumn"));
+        engineering.addIncludeProcedure(new IncludeProcedure("IncludeProcedure"));
+        engineering.addExcludeTable(new ExcludeTable("ExcludeTable"));
+        engineering.addExcludeColumn(new ExcludeColumn("ExcludeColumn"));
+        engineering.addExcludeProcedure(new ExcludeProcedure("ExcludeProcedure"));
+
+        FiltersConfig executions = new FiltersConfigBuilder(engineering).filtersConfig();
+
+        assertEquals(new FiltersConfig(
+                        eFilters(path(),
+                            list(include("IncludeTable"), exclude("ExcludeTable")),
+                            list(include("IncludeColumn"), exclude("ExcludeColumn")),
+                            list(include("IncludeProcedure"), exclude("ExcludeProcedure"))),
+                        eFilters(path(null, null, "IncludeTable"), NULL, TRUE, NULL)
+                ),
+                executions);
+    }
+
+    @Test
+    public void testComplexConfiguration() throws Exception {
+        IncludeTable table = new IncludeTable("table");
+        table.addIncludeColumn(new IncludeColumn("column"));
+
+        Schema schema = new Schema("schema");
+        schema.addIncludeTable(table);
+
+        Catalog catalog = new Catalog("catalog");
+        catalog.addSchema(schema);
+
+        ReverseEngineering engineering = new ReverseEngineering();
+        engineering.addCatalog(catalog);
+
+        FiltersConfig executions = new FiltersConfigBuilder(engineering).filtersConfig();
+
+        assertEquals(new FiltersConfig(
+                        eFilters(path("catalog", "schema"), include("table"), NULL, NULL),
+                        eFilters(path("catalog", "schema", "table"), NULL, include("column"), NULL)
+                        ),
+                executions);
+    }
+
+    @Test
+    public void testAddNull() throws Exception {
+        FiltersConfigBuilder builder = new FiltersConfigBuilder(new ReverseEngineering());
+        DbPath path = new DbPath();
+        builder.add(new EntityFilters(path, NULL, NULL, NULL));
+        builder.add(new EntityFilters(path, NULL, NULL, NULL));
+        builder.add(new EntityFilters(path, NULL, NULL, NULL));
+        builder.add(new EntityFilters(path, NULL, NULL, NULL));
+
+        EntityFilters filter = builder.filtersConfig().filter(path);
+        assertFalse(filter.isEmpty());
+    }
+}
\ 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/build-catalog-and-schema.xml
----------------------------------------------------------------------
diff --git a/cayenne-tools/src/test/resources/org/apache/cayenne/tools/build-catalog-and-schema.xml b/cayenne-tools/src/test/resources/org/apache/cayenne/tools/build-catalog-and-schema.xml
new file mode 100644
index 0000000..64ee1bc
--- /dev/null
+++ b/cayenne-tools/src/test/resources/org/apache/cayenne/tools/build-catalog-and-schema.xml
@@ -0,0 +1,78 @@
+<!--
+  ~ 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">
+
+            <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>
+        </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/build-catalog.xml
----------------------------------------------------------------------
diff --git a/cayenne-tools/src/test/resources/org/apache/cayenne/tools/build-catalog.xml b/cayenne-tools/src/test/resources/org/apache/cayenne/tools/build-catalog.xml
new file mode 100644
index 0000000..32d7c7a
--- /dev/null
+++ b/cayenne-tools/src/test/resources/org/apache/cayenne/tools/build-catalog.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">
+
+            <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>
+
+        </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/build-flat.xml
----------------------------------------------------------------------
diff --git a/cayenne-tools/src/test/resources/org/apache/cayenne/tools/build-flat.xml b/cayenne-tools/src/test/resources/org/apache/cayenne/tools/build-flat.xml
new file mode 100644
index 0000000..29f9e72
--- /dev/null
+++ b/cayenne-tools/src/test/resources/org/apache/cayenne/tools/build-flat.xml
@@ -0,0 +1,75 @@
+<!--
+  ~ 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">
+
+            <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" />
+
+        </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/build-mapping.xml
----------------------------------------------------------------------
diff --git a/cayenne-tools/src/test/resources/org/apache/cayenne/tools/build-mapping.xml b/cayenne-tools/src/test/resources/org/apache/cayenne/tools/build-mapping.xml
new file mode 100644
index 0000000..90d6116
--- /dev/null
+++ b/cayenne-tools/src/test/resources/org/apache/cayenne/tools/build-mapping.xml
@@ -0,0 +1,44 @@
+<!--
+  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">
+
+            <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>
+
+        </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/build-reverse-engineering-in-external-file.xml
----------------------------------------------------------------------
diff --git a/cayenne-tools/src/test/resources/org/apache/cayenne/tools/build-reverse-engineering-in-external-file.xml b/cayenne-tools/src/test/resources/org/apache/cayenne/tools/build-reverse-engineering-in-external-file.xml
new file mode 100644
index 0000000..8cd89e8
--- /dev/null
+++ b/cayenne-tools/src/test/resources/org/apache/cayenne/tools/build-reverse-engineering-in-external-file.xml
@@ -0,0 +1,33 @@
+<!--
+  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"
+                   reverseEngineeringFile="dbimport/config/reverseEngineering-catalog-and-schema.xml" />
+    </target>
+
+
+</project>
\ No newline at end of file