# HG changeset patch
# User Augusto Mauch <augusto.mauch@openbravo.com>
# Date 1449676515 -3600
#      Wed Dec 09 16:55:15 2015 +0100
# Node ID 59d5fc9fb9cf719394db9437d53593ca23643bf5
# Parent  06fa38a1654c2937a529b0d0a6e6b3dace012a21
Fixes issue 29800: It is supported to exclude sequences from the database model

It is possible to exclude sequences from the model by declaring the exclusions in the exclude filter like this:

<?xml version="1.0"?>
  <vector>
    <excludedSequence name="EXCLUDED_SEQUENCE"/>
  </vector>

diff --git a/src/mapping.xml b/src/mapping.xml
--- a/src/mapping.xml
+++ b/src/mapping.xml
@@ -277,4 +277,10 @@
     </element>
   </class>
   
+  <class name="org.apache.ddlutils.platform.modelexclusion.ExcludedSequence">
+    <element name="excludedSequence">
+      <attribute name="name" property="name"/>
+    </element>
+  </class>  
+  
 </betwixt-config>
diff --git a/src/org/apache/ddlutils/platform/ExcludeFilter.java b/src/org/apache/ddlutils/platform/ExcludeFilter.java
--- a/src/org/apache/ddlutils/platform/ExcludeFilter.java
+++ b/src/org/apache/ddlutils/platform/ExcludeFilter.java
@@ -18,6 +18,7 @@
 
 import org.apache.ddlutils.io.DatabaseIO;
 import org.apache.ddlutils.platform.modelexclusion.ExcludedFunction;
+import org.apache.ddlutils.platform.modelexclusion.ExcludedSequence;
 import org.apache.ddlutils.platform.modelexclusion.ExcludedTable;
 import org.apache.ddlutils.platform.modelexclusion.ExcludedTrigger;
 import org.apache.ddlutils.platform.modelexclusion.ExcludedView;
@@ -45,6 +46,7 @@
   Vector<String> excludedFunctions = new Vector<String>();
   Vector<String> excludedTriggers = new Vector<String>();
   Vector<String> excludedViews = new Vector<String>();
+  Vector<String> excludedSequences = new Vector<String>();
 
   private Logger log4j = Logger.getLogger(getClass());
 
@@ -66,6 +68,10 @@
     for (String s : excludedFunctions) {
       sb.append("  -" + s + "\n");
     }
+    sb.append("***Filtered sequences: " + "\n");
+    for (String s : excludedSequences) {
+      sb.append("  -" + s + "\n");
+    }
     return sb.toString();
   }
 
@@ -87,6 +93,7 @@
     filter.excludedViews.addAll(excludedViews);
     filter.excludedTriggers.addAll(excludedTriggers);
     filter.excludedFunctions.addAll(excludedFunctions);
+    filter.excludedSequences.addAll(excludedSequences);
 
     for (ExceptionRow row : exceptions) {
       filter.exceptions.add((ExceptionRow) row.clone());
@@ -112,6 +119,8 @@
           excludedFunctions.add(((ExcludedFunction) obj).getName());
         } else if (obj instanceof ExcludedTrigger) {
           excludedTriggers.add(((ExcludedTrigger) obj).getName());
+        } else if (obj instanceof ExcludedSequence) {
+          excludedSequences.add(((ExcludedSequence) obj).getName());
         }
       }
     } catch (Exception e) {
@@ -144,6 +153,11 @@
         v.add(new ExcludedTrigger(trigger));
       }
 
+      String[] sequences = getExcludedSequences();
+      for (String sequence : sequences) {
+        v.add(new ExcludedSequence(sequence));
+      }
+
       DatabaseIO dbIO = new DatabaseIO();
       dbIO.writeExcludedObjects(file, v);
     } catch (Exception e) {
@@ -160,7 +174,7 @@
   }
 
   public String[] getExcludedSequences() {
-    return new String[0];
+    return excludedSequences.toArray(new String[0]);
   }
 
   public String[] getExcludedFunctions() {
@@ -209,7 +223,7 @@
   }
 
   private boolean hasPrefix(String name, String prefix) {
-    if(prefix.equalsIgnoreCase(name)){
+    if (prefix.equalsIgnoreCase(name)) {
       return true;
     }
     return name.toUpperCase().startsWith(prefix.toUpperCase() + "_");
diff --git a/src/org/apache/ddlutils/platform/modelexclusion/ExcludedSequence.java b/src/org/apache/ddlutils/platform/modelexclusion/ExcludedSequence.java
new file mode 100644
--- /dev/null
+++ b/src/org/apache/ddlutils/platform/modelexclusion/ExcludedSequence.java
@@ -0,0 +1,35 @@
+/*
+ ************************************************************************************
+ * Copyright (C) 2015 Openbravo S.L.U.
+ * Licensed under the Apache Software License version 2.0
+ * 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.ddlutils.platform.modelexclusion;
+
+public class ExcludedSequence {
+
+  private String name;
+
+  public ExcludedSequence() {
+    name = "";
+  }
+
+  public ExcludedSequence(String name) {
+    this.name = name;
+  }
+
+  public void setName(String name) {
+    this.name = name;
+  }
+
+  public String getName() {
+    return name;
+  }
+
+}
# HG changeset patch
# User Augusto Mauch <augusto.mauch@openbravo.com>
# Date 1449676567 -3600
#      Wed Dec 09 16:56:07 2015 +0100
# Node ID e3b7eb7d542c49ed95afd1635ae94569cfa86749
# Parent  59d5fc9fb9cf719394db9437d53593ca23643bf5
Related with issue 29800: Adds tests to check excluded sequences

diff --git a/src-test/model/excludeFilter/BASE_MODEL_WITH_SEQUENCE.xml b/src-test/model/excludeFilter/BASE_MODEL_WITH_SEQUENCE.xml
new file mode 100644
--- /dev/null
+++ b/src-test/model/excludeFilter/BASE_MODEL_WITH_SEQUENCE.xml
@@ -0,0 +1,5 @@
+<?xml version="1.0"?>
+  <database name="EXCLUDED SEQUENCE TEST">
+    <sequence name="NOT_EXCLUDED_SEQUENCE" start="10" increment="1"/>
+    <sequence name="EXCLUDED_SEQUENCE" start="10" increment="1"/>
+  </database>
\ No newline at end of file
diff --git a/src-test/model/excludeFilter/excludeSequence.xml b/src-test/model/excludeFilter/excludeSequence.xml
new file mode 100644
--- /dev/null
+++ b/src-test/model/excludeFilter/excludeSequence.xml
@@ -0,0 +1,5 @@
+<?xml version="1.0"?>
+  <vector>
+    <excludedSequence name="EXCLUDED_SEQUENCE"/>
+  </vector>
+  
\ No newline at end of file
diff --git a/src-test/src/org/openbravo/dbsm/test/model/CheckExcludeFilter.java b/src-test/src/org/openbravo/dbsm/test/model/CheckExcludeFilter.java
--- a/src-test/src/org/openbravo/dbsm/test/model/CheckExcludeFilter.java
+++ b/src-test/src/org/openbravo/dbsm/test/model/CheckExcludeFilter.java
@@ -22,6 +22,7 @@
 import org.apache.ddlutils.Platform;
 import org.apache.ddlutils.model.Database;
 import org.apache.ddlutils.model.Function;
+import org.apache.ddlutils.model.Sequence;
 import org.apache.ddlutils.model.Table;
 import org.apache.ddlutils.model.Trigger;
 import org.apache.ddlutils.model.View;
@@ -111,6 +112,22 @@
     assertThat(excludedFile.exists(), equalTo(false));
   }
 
+  @Test
+  // Tests that tables in the exclude filter are not exported
+  public void sequenceIsExcluded() throws IOException {
+    resetDB();
+    updateDatabase("excludeFilter/BASE_MODEL_WITH_SEQUENCE.xml");
+    ExcludeFilter excludeFilter = new ExcludeFilter();
+    excludeFilter.fillFromFile(new File("model/excludeFilter/excludeSequence.xml"));
+    setExcludeFilter(excludeFilter);
+    exportDatabase(EXPORT_DIR);
+    File notExcludedFile = new File(EXPORT_DIR + "/sequences/NOT_EXCLUDED_SEQUENCE.xml");
+    File excludedFile = new File(EXPORT_DIR + "/sequences/EXCLUDED_SEQUENCE.xml");
+    assertThat(excludedSequenceExistsInDb(), equalTo(true));
+    assertThat(notExcludedFile.exists(), equalTo(true));
+    assertThat(excludedFile.exists(), equalTo(false));
+  }
+
   private boolean excludedFunctionExistsInDb() {
     Platform platform = getPlatform();
     Database database = platform.loadModelFromDatabase(new ExcludeFilter());
@@ -138,4 +155,11 @@
     Trigger trigger = database.findTrigger("EXCLUDED_TRIGGER");
     return (trigger != null);
   }
+
+  private boolean excludedSequenceExistsInDb() {
+    Platform platform = getPlatform();
+    Database database = platform.loadModelFromDatabase(new ExcludeFilter());
+    Sequence sequence = database.findSequence("EXCLUDED_SEQUENCE");
+    return (sequence != null);
+  }
 }
