From: James Ahlborn Date: Fri, 24 Jun 2016 00:23:14 +0000 (+0000) Subject: rework public api for adding index/column, ditch TableModBuilder X-Git-Tag: jackcess-2.1.5~7^2~28 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=7e0838c282354251e664577c817af4efd8b484b2;p=jackcess.git rework public api for adding index/column, ditch TableModBuilder git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/branches/mutateops@1000 f203690c-595d-4dc9-a70b-905162fa7fd2 --- diff --git a/src/main/java/com/healthmarketscience/jackcess/ColumnBuilder.java b/src/main/java/com/healthmarketscience/jackcess/ColumnBuilder.java index cb4b554..69b4b33 100644 --- a/src/main/java/com/healthmarketscience/jackcess/ColumnBuilder.java +++ b/src/main/java/com/healthmarketscience/jackcess/ColumnBuilder.java @@ -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() + ")"; } diff --git a/src/main/java/com/healthmarketscience/jackcess/IndexBuilder.java b/src/main/java/com/healthmarketscience/jackcess/IndexBuilder.java index 52a4550..1f808d6 100644 --- a/src/main/java/com/healthmarketscience/jackcess/IndexBuilder.java +++ b/src/main/java/com/healthmarketscience/jackcess/IndexBuilder.java @@ -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 index e776c3c..0000000 --- a/src/main/java/com/healthmarketscience/jackcess/TableModBuilder.java +++ /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); - } - } -}