]> source.dussan.org Git - jackcess.git/commitdiff
rework public api for adding index/column, ditch TableModBuilder
authorJames Ahlborn <jtahlborn@yahoo.com>
Fri, 24 Jun 2016 00:23:14 +0000 (00:23 +0000)
committerJames Ahlborn <jtahlborn@yahoo.com>
Fri, 24 Jun 2016 00:23:14 +0000 (00:23 +0000)
git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/branches/mutateops@1000 f203690c-595d-4dc9-a70b-905162fa7fd2

src/main/java/com/healthmarketscience/jackcess/ColumnBuilder.java
src/main/java/com/healthmarketscience/jackcess/IndexBuilder.java
src/main/java/com/healthmarketscience/jackcess/TableModBuilder.java [deleted file]

index cb4b55400ccb1c4e3115d3fd8714ae15372e867f..69b4b330ce16617f6587f453ee063a9a2dd04714 100644 (file)
@@ -25,10 +25,13 @@ import com.healthmarketscience.jackcess.impl.ColumnImpl;
 import com.healthmarketscience.jackcess.impl.DatabaseImpl;
 import com.healthmarketscience.jackcess.impl.JetFormat;
 import com.healthmarketscience.jackcess.impl.PropertyMapImpl;
+import com.healthmarketscience.jackcess.impl.TableImpl;
+import com.healthmarketscience.jackcess.impl.TableMutator;
 
 /**
  * Builder style class for constructing a {@link Column}.  See {@link
- * TableBuilder} for example usage.
+ * TableBuilder} for example usage.  Additionally, a Column can be added to an
+ * existing Table using the {@link #addToTable(Table)} method.
  *
  * @author James Ahlborn
  * @usage _general_class_
@@ -472,6 +475,15 @@ public class ColumnBuilder {
     return this;
   }
 
+  /**
+   * Adds a new Column to the given Table with the currently configured
+   * attributes.
+   */
+  public Column addToTable(Table table) throws IOException
+  {
+      return new TableMutator((TableImpl)table).addColumn(this);
+  }
+
   private String withErrorContext(String msg) {
     return msg + "(Column=" + getName() + ")";
   }
index 52a4550acb128919049d3ec7f29735fd285d47d0..1f808d6252c745add2c079154302189e95d8ec8c 100644 (file)
@@ -16,6 +16,7 @@ limitations under the License.
 
 package com.healthmarketscience.jackcess;
 
+import java.io.IOException;
 import java.util.ArrayList;
 import java.util.HashSet;
 import java.util.List;
@@ -25,10 +26,13 @@ import com.healthmarketscience.jackcess.impl.DatabaseImpl;
 import com.healthmarketscience.jackcess.impl.IndexData;
 import com.healthmarketscience.jackcess.impl.IndexImpl;
 import com.healthmarketscience.jackcess.impl.JetFormat;
+import com.healthmarketscience.jackcess.impl.TableImpl;
+import com.healthmarketscience.jackcess.impl.TableMutator;
 
 /**
  * Builder style class for constructing an {@link Index}.  See {@link
- * TableBuilder} for example usage.
+ * TableBuilder} for example usage.  Additionally, an Index can be added to an
+ * existing Table using the {@link #addToTable(Table)} method.
  *
  * @author James Ahlborn
  * @usage _general_class_
@@ -185,6 +189,15 @@ public class IndexBuilder
     }
   }
 
+  /**
+   * Adds a new Index to the given Table with the currently configured
+   * attributes.
+   */
+  public Index addToTable(Table table) throws IOException
+  {
+      return new TableMutator((TableImpl)table).addIndex(this);
+  }
+
   private String withErrorContext(String msg) {
     return msg + "(Index=" + getName() + ")";
   }
diff --git a/src/main/java/com/healthmarketscience/jackcess/TableModBuilder.java b/src/main/java/com/healthmarketscience/jackcess/TableModBuilder.java
deleted file mode 100644 (file)
index e776c3c..0000000
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
-Copyright (c) 2016 James Ahlborn
-
-Licensed 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 com.healthmarketscience.jackcess;
-
-import java.io.IOException;
-
-import com.healthmarketscience.jackcess.impl.TableImpl;
-import com.healthmarketscience.jackcess.impl.TableMutator;
-
-/**
- *
- * @author James Ahlborn
- */
-public class TableModBuilder 
-{
-  private Table _table;
-
-  public TableModBuilder(Table table) {
-    _table = table;
-  }
-
-  public AddColumn addColumn(ColumnBuilder column) {
-    return new AddColumn(column);
-  }
-
-  public AddIndex addIndex(IndexBuilder index) {
-    return new AddIndex(index);
-  }
-
-  public class AddColumn
-  {
-    private ColumnBuilder _column;
-
-    private AddColumn(ColumnBuilder column) {
-      _column = column;
-    }
-
-    public Column add() throws IOException
-    {
-      return new TableMutator((TableImpl)_table).addColumn(_column);
-    }
-  }
-
-  public class AddIndex
-  {
-    private IndexBuilder _index;
-
-    private AddIndex(IndexBuilder index) {
-      _index = index;
-    }
-
-    public Index add() throws IOException
-    {
-      return new TableMutator((TableImpl)_table).addIndex(_index);
-    }
-  }
-}