diff --git a/morf-core/src/main/java/org/alfasoftware/morf/dataset/TableLoader.java b/morf-core/src/main/java/org/alfasoftware/morf/dataset/TableLoader.java index 7396d0c8c..54a167b54 100755 --- a/morf-core/src/main/java/org/alfasoftware/morf/dataset/TableLoader.java +++ b/morf-core/src/main/java/org/alfasoftware/morf/dataset/TableLoader.java @@ -18,6 +18,7 @@ import java.sql.Connection; import java.sql.PreparedStatement; +import org.alfasoftware.morf.dataset.TableLoaderBuilder.TableLoaderBuilderImpl; import org.alfasoftware.morf.jdbc.RuntimeSqlException; import org.alfasoftware.morf.jdbc.SqlDialect; import org.alfasoftware.morf.jdbc.SqlScriptExecutor; diff --git a/morf-core/src/main/java/org/alfasoftware/morf/dataset/TableLoaderBuilder.java b/morf-core/src/main/java/org/alfasoftware/morf/dataset/TableLoaderBuilder.java index 11de4aedc..95bc8a851 100755 --- a/morf-core/src/main/java/org/alfasoftware/morf/dataset/TableLoaderBuilder.java +++ b/morf-core/src/main/java/org/alfasoftware/morf/dataset/TableLoaderBuilder.java @@ -17,10 +17,17 @@ import java.sql.Connection; +import org.alfasoftware.morf.dataset.TableLoaderBuilder.TableLoaderBuilderImpl; import org.alfasoftware.morf.jdbc.SqlDialect; import org.alfasoftware.morf.jdbc.SqlScriptExecutor; +import org.alfasoftware.morf.jdbc.SqlScriptExecutorProvider; import org.alfasoftware.morf.metadata.Table; +import com.google.inject.ImplementedBy; +import com.google.inject.Inject; +import com.google.inject.Provider; +import com.google.inject.util.Providers; + /** * Builds a {@link TableLoader}. * @@ -32,6 +39,7 @@ * * @author Copyright (c) Alfa Financial Software 2014 */ +@ImplementedBy(TableLoaderBuilderImpl.class) public interface TableLoaderBuilder { /** @@ -120,4 +128,109 @@ public interface TableLoaderBuilder { * @return A table loader. */ TableLoader forTable(Table table); -} \ No newline at end of file + + /** + * Internal implementation of {@link TableLoaderBuilder}. + */ + class TableLoaderBuilderImpl implements TableLoaderBuilder { + private Connection connection; + private final SqlScriptExecutorProvider sqlScriptExecutorProvider; + private SqlScriptExecutor sqlScriptExecutor; + private boolean explicitCommit; + private boolean truncateBeforeLoad; + private boolean insertingWithPresetAutonums; + private boolean insertingUnderAutonumLimit; + private Provider sqlDialect; + private int batchSize = 1000; + + TableLoaderBuilderImpl() { + super(); + // This will need to be provided in withSqlScriptExecutor + sqlScriptExecutorProvider = null; + } + + @Inject + TableLoaderBuilderImpl( + SqlScriptExecutorProvider sqlScriptExecutorProvider, + Provider sqlDialect) { + super(); + this.sqlScriptExecutorProvider = sqlScriptExecutorProvider; + this.sqlDialect = sqlDialect; + } + + @Override + public TableLoaderBuilder withDialect(SqlDialect sqlDialect) { + this.sqlDialect = Providers.of(sqlDialect); + return this; + } + + @Override + public TableLoaderBuilder withConnection(Connection connection) { + this.connection = connection; + return this; + } + + @Override + public TableLoaderBuilder withSqlScriptExecutor(SqlScriptExecutor sqlScriptExecutor) { + this.sqlScriptExecutor = sqlScriptExecutor; + return this; + } + + @Override + public TableLoaderBuilder explicitCommit() { + this.explicitCommit = true; + return this; + } + + @Override + public TableLoaderBuilder explicitCommit(boolean explicitCommit) { + this.explicitCommit = explicitCommit; + return this; + } + + @Override + public TableLoaderBuilder truncateBeforeLoad() { + this.truncateBeforeLoad = true; + return this; + } + + @Override + public TableLoaderBuilder insertingWithPresetAutonums() { + this.insertingWithPresetAutonums = true; + return this; + } + + @Override + public TableLoaderBuilder insertingUnderAutonumLimit() { + this.insertingUnderAutonumLimit = true; + return this; + } + + @Override + public TableLoaderBuilder withBatchSize(int recordsPerBatch) { + this.batchSize = recordsPerBatch; + return this; + } + + @Override + public TableLoader forTable(Table table) { + SqlScriptExecutor executor = sqlScriptExecutor; + if (executor == null) { + if (sqlScriptExecutorProvider == null) { + throw new IllegalArgumentException("No SqlScriptExecutor provided"); + } + executor = sqlScriptExecutorProvider.get(); + } + return new TableLoader( + connection, + executor, + sqlDialect.get(), + explicitCommit, + table, + insertingWithPresetAutonums, + insertingUnderAutonumLimit, + truncateBeforeLoad, + batchSize); + } + } +} diff --git a/morf-core/src/main/java/org/alfasoftware/morf/dataset/TableLoaderBuilderImpl.java b/morf-core/src/main/java/org/alfasoftware/morf/dataset/TableLoaderBuilderImpl.java deleted file mode 100644 index 6e749b59e..000000000 --- a/morf-core/src/main/java/org/alfasoftware/morf/dataset/TableLoaderBuilderImpl.java +++ /dev/null @@ -1,122 +0,0 @@ -/* Copyright 2017 Alfa Financial Software - * - * 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 org.alfasoftware.morf.dataset; - -import java.sql.Connection; - -import org.alfasoftware.morf.jdbc.SqlDialect; -import org.alfasoftware.morf.jdbc.SqlScriptExecutor; -import org.alfasoftware.morf.jdbc.SqlScriptExecutorProvider; -import org.alfasoftware.morf.metadata.Table; - -import com.google.inject.Provider; -import com.google.inject.util.Providers; - -/** - * Internal implementation of {@link TableLoaderBuilder}. - */ -class TableLoaderBuilderImpl implements TableLoaderBuilder { - private Connection connection; - private final SqlScriptExecutorProvider sqlScriptExecutorProvider; - private SqlScriptExecutor sqlScriptExecutor; - private boolean explicitCommit; - private boolean truncateBeforeLoad; - private boolean insertingWithPresetAutonums; - private boolean insertingUnderAutonumLimit; - private Provider sqlDialect; - private int batchSize = 1000; - - TableLoaderBuilderImpl() { - super(); - // This will need to be provided in withSqlScriptExecutor - sqlScriptExecutorProvider = null; - } - - @Override - public TableLoaderBuilder withDialect(SqlDialect sqlDialect) { - this.sqlDialect = Providers.of(sqlDialect); - return this; - } - - @Override - public TableLoaderBuilder withConnection(Connection connection) { - this.connection = connection; - return this; - } - - @Override - public TableLoaderBuilder withSqlScriptExecutor(SqlScriptExecutor sqlScriptExecutor) { - this.sqlScriptExecutor = sqlScriptExecutor; - return this; - } - - @Override - public TableLoaderBuilder explicitCommit() { - this.explicitCommit = true; - return this; - } - - @Override - public TableLoaderBuilder explicitCommit(boolean explicitCommit) { - this.explicitCommit = explicitCommit; - return this; - } - - @Override - public TableLoaderBuilder truncateBeforeLoad() { - this.truncateBeforeLoad = true; - return this; - } - - @Override - public TableLoaderBuilder insertingWithPresetAutonums() { - this.insertingWithPresetAutonums = true; - return this; - } - - @Override - public TableLoaderBuilder insertingUnderAutonumLimit() { - this.insertingUnderAutonumLimit = true; - return this; - } - - @Override - public TableLoaderBuilder withBatchSize(int recordsPerBatch) { - this.batchSize = recordsPerBatch; - return this; - } - - @Override - public TableLoader forTable(Table table) { - SqlScriptExecutor executor = sqlScriptExecutor; - if (executor == null) { - if (sqlScriptExecutorProvider == null) { - throw new IllegalArgumentException("No SqlScriptExecutor provided"); - } - executor = sqlScriptExecutorProvider.get(); - } - return new TableLoader( - connection, - executor, - sqlDialect.get(), - explicitCommit, - table, - insertingWithPresetAutonums, - insertingUnderAutonumLimit, - truncateBeforeLoad, - batchSize); - } -} \ No newline at end of file diff --git a/morf-core/src/main/java/org/alfasoftware/morf/guicesupport/MorfModule.java b/morf-core/src/main/java/org/alfasoftware/morf/guicesupport/MorfModule.java new file mode 100755 index 000000000..d1939e742 --- /dev/null +++ b/morf-core/src/main/java/org/alfasoftware/morf/guicesupport/MorfModule.java @@ -0,0 +1,41 @@ +/* Copyright 2017 Alfa Financial Software + * + * 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 org.alfasoftware.morf.guicesupport; + +import org.alfasoftware.morf.upgrade.TableContribution; +import org.alfasoftware.morf.upgrade.additions.UpgradeScriptAddition; +import org.alfasoftware.morf.upgrade.db.DatabaseUpgradeTableContribution; + +import com.google.inject.AbstractModule; +import com.google.inject.multibindings.Multibinder; + +/** + * Guice bindings for Morf module. + * + * @author Copyright (c) Alfa Financial Software 2017 + */ +public class MorfModule extends AbstractModule { + /** + * @see com.google.inject.AbstractModule#configure() + */ + @Override + protected void configure() { + Multibinder.newSetBinder(binder(), UpgradeScriptAddition.class); + + Multibinder tableMultibinder = Multibinder.newSetBinder(binder(), TableContribution.class); + tableMultibinder.addBinding().to(DatabaseUpgradeTableContribution.class); + } +} + diff --git a/morf-guicesupport/src/main/java/org/alfasoftware/morf/guicesupport/package-info.java b/morf-core/src/main/java/org/alfasoftware/morf/guicesupport/package-info.java similarity index 100% rename from morf-guicesupport/src/main/java/org/alfasoftware/morf/guicesupport/package-info.java rename to morf-core/src/main/java/org/alfasoftware/morf/guicesupport/package-info.java diff --git a/morf-core/src/main/java/org/alfasoftware/morf/jdbc/SqlScriptExecutorProvider.java b/morf-core/src/main/java/org/alfasoftware/morf/jdbc/SqlScriptExecutorProvider.java index a3f03593a..b676de716 100755 --- a/morf-core/src/main/java/org/alfasoftware/morf/jdbc/SqlScriptExecutorProvider.java +++ b/morf-core/src/main/java/org/alfasoftware/morf/jdbc/SqlScriptExecutorProvider.java @@ -19,6 +19,7 @@ import org.alfasoftware.morf.jdbc.SqlScriptExecutor.SqlScriptVisitor; +import com.google.inject.Inject; import com.google.inject.Provider; import com.google.inject.util.Providers; @@ -39,6 +40,7 @@ public class SqlScriptExecutorProvider implements Provider { * {@link SqlScriptExecutorProvider} for * @param sqlDialect The dialect to use */ + @Inject public SqlScriptExecutorProvider(final DataSource dataSource, Provider sqlDialect) { super(); this.dataSource = dataSource; diff --git a/morf-guicesupport/src/main/java/org/alfasoftware/morf/upgrade/DatabaseUpgradeModule.java b/morf-core/src/main/java/org/alfasoftware/morf/upgrade/DatabaseUpgradeModule.java similarity index 100% rename from morf-guicesupport/src/main/java/org/alfasoftware/morf/upgrade/DatabaseUpgradeModule.java rename to morf-core/src/main/java/org/alfasoftware/morf/upgrade/DatabaseUpgradeModule.java diff --git a/morf-guicesupport/src/main/java/org/alfasoftware/morf/upgrade/db/InfrastructuralTablesModule.java b/morf-core/src/main/java/org/alfasoftware/morf/upgrade/db/InfrastructuralTablesModule.java similarity index 100% rename from morf-guicesupport/src/main/java/org/alfasoftware/morf/upgrade/db/InfrastructuralTablesModule.java rename to morf-core/src/main/java/org/alfasoftware/morf/upgrade/db/InfrastructuralTablesModule.java diff --git a/morf-guicesupport/.gitignore b/morf-guicesupport/.gitignore deleted file mode 100644 index 3e71e2f91..000000000 --- a/morf-guicesupport/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/ivy.xml diff --git a/morf-guicesupport/pom.xml b/morf-guicesupport/pom.xml deleted file mode 100644 index 72185ce82..000000000 --- a/morf-guicesupport/pom.xml +++ /dev/null @@ -1,36 +0,0 @@ - - 4.0.0 - - - org.alfasoftware - morf-parent - 0.1.0-SNAPSHOT - - - Morf - Guice Support - morf-guicesupport - - - - - org.apache.maven.plugins - maven-source-plugin - - - org.apache.maven.plugins - maven-javadoc-plugin - - - org.apache.maven.plugins - maven-checkstyle-plugin - - - - - - - org.alfasoftware - morf-core - - - \ No newline at end of file diff --git a/morf-guicesupport/src/main/java/org/alfasoftware/morf/guicesupport/MorfModule.java b/morf-guicesupport/src/main/java/org/alfasoftware/morf/guicesupport/MorfModule.java deleted file mode 100755 index 500248de0..000000000 --- a/morf-guicesupport/src/main/java/org/alfasoftware/morf/guicesupport/MorfModule.java +++ /dev/null @@ -1,88 +0,0 @@ -/* Copyright 2017 Alfa Financial Software - * - * 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 org.alfasoftware.morf.guicesupport; - -import javax.sql.DataSource; - -import org.alfasoftware.morf.dataset.TableLoader; -import org.alfasoftware.morf.dataset.TableLoaderBuilder; -import org.alfasoftware.morf.jdbc.SqlDialect; -import org.alfasoftware.morf.jdbc.SqlScriptExecutorProvider; -import org.alfasoftware.morf.upgrade.TableContribution; -import org.alfasoftware.morf.upgrade.additions.UpgradeScriptAddition; -import org.alfasoftware.morf.upgrade.db.DatabaseUpgradeTableContribution; - -import com.google.common.base.Preconditions; -import com.google.inject.AbstractModule; -import com.google.inject.Inject; -import com.google.inject.Provides; -import com.google.inject.multibindings.Multibinder; - -/** - * Guice bindings for Morf module. - * - * @author Copyright (c) Alfa Financial Software 2017 - */ -public class MorfModule extends AbstractModule { - /** - * @see com.google.inject.AbstractModule#configure() - */ - @Override - protected void configure() { - Multibinder.newSetBinder(binder(), UpgradeScriptAddition.class); - - Multibinder tableMultibinder = Multibinder.newSetBinder(binder(), TableContribution.class); - tableMultibinder.addBinding().to(DatabaseUpgradeTableContribution.class); - } - - - /** - * Provides a {@link SqlScriptExecutorProvider}. - * - * @param param The optional bindings. - * @return The {@link SqlScriptExecutorProvider}. - */ - @Provides - public SqlScriptExecutorProvider sqlScriptExecutorProvider(SqlScriptExecutorProviderParam param) { - Preconditions.checkNotNull(param.sqlDialect, "Dialect is null"); - Preconditions.checkNotNull(param.dataSource, "Data source is null"); - return new SqlScriptExecutorProvider(param.dataSource, param.sqlDialect); - } - - private static final class SqlScriptExecutorProviderParam { - @Inject(optional = true) SqlDialect sqlDialect; - @Inject(optional = true) DataSource dataSource; - } - - - /** - * Provides a {@link TableLoaderBuilder}. - * - * @param param The optional bindings. - * @param sqlScriptExecutorProvider The SQL script executor. - * @return The {@link TableLoaderBuilder}. - */ - @Provides - public TableLoaderBuilder tableLoaderBuilder(TableLoaderBuilderParam param, SqlScriptExecutorProvider sqlScriptExecutorProvider) { - Preconditions.checkNotNull(param.sqlDialect, "Dialect is null"); - return TableLoader.builder() - .withDialect(param.sqlDialect) - .withSqlScriptExecutor(sqlScriptExecutorProvider.get()); - } - - private static final class TableLoaderBuilderParam { - @Inject(optional = true) SqlDialect sqlDialect; - } -} diff --git a/morf-integration-test/pom.xml b/morf-integration-test/pom.xml index a6fe43e3b..9f660c67a 100755 --- a/morf-integration-test/pom.xml +++ b/morf-integration-test/pom.xml @@ -36,11 +36,6 @@ morf-core runtime - - org.alfasoftware - morf-guicesupport - runtime - org.alfasoftware morf-excel diff --git a/morf-testsupport/pom.xml b/morf-testsupport/pom.xml index e2296563a..81f427804 100755 --- a/morf-testsupport/pom.xml +++ b/morf-testsupport/pom.xml @@ -32,10 +32,6 @@ org.alfasoftware morf-core - - org.alfasoftware - morf-guicesupport - org.hamcrest hamcrest-all diff --git a/morf-testsupport/src/main/java/org/alfasoftware/morf/testing/TestingDataSourceModule.java b/morf-testsupport/src/main/java/org/alfasoftware/morf/testing/TestingDataSourceModule.java index 1bfda0db3..91149b1bf 100755 --- a/morf-testsupport/src/main/java/org/alfasoftware/morf/testing/TestingDataSourceModule.java +++ b/morf-testsupport/src/main/java/org/alfasoftware/morf/testing/TestingDataSourceModule.java @@ -17,7 +17,7 @@ import javax.sql.DataSource; -import org.alfasoftware.morf.guicesupport.MorfModule; +import com.google.inject.Binder; import org.alfasoftware.morf.jdbc.ConnectionResources; import org.alfasoftware.morf.jdbc.ConnectionResourcesBean; import org.alfasoftware.morf.jdbc.SqlDialect; @@ -26,7 +26,6 @@ import com.google.common.io.Resources; import com.google.inject.AbstractModule; -import com.google.inject.Binder; import com.google.inject.Provides; /** @@ -46,7 +45,6 @@ public class TestingDataSourceModule extends AbstractModule { */ @Override public void configure() { - install(new MorfModule()); bind(ConnectionResources.class).toInstance(new ConnectionResourcesBean(Resources.getResource("morf.properties"))); } diff --git a/pom.xml b/pom.xml index ded7f54ae..d87a286c0 100755 --- a/pom.xml +++ b/pom.xml @@ -15,7 +15,6 @@ morf-core - morf-guicesupport morf-testsupport morf-excel morf-h2 @@ -185,11 +184,6 @@ morf-core ${project.version} - - org.alfasoftware - morf-guicesupport - ${project.version} - org.alfasoftware morf-testsupport @@ -394,4 +388,4 @@ - + \ No newline at end of file