Skip to content

Commit

Permalink
Revert "Merge pull request #48 from badgerwithagun/guice".
Browse files Browse the repository at this point in the history
This needs more work to sustain compatibility with existing code.

This reverts commit c2ccb99, reversing
changes made to 8bedf83.
  • Loading branch information
badgerwithagun committed Mar 14, 2018
1 parent f2d9ed9 commit 1f47ae6
Show file tree
Hide file tree
Showing 15 changed files with 160 additions and 267 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}.
*
Expand All @@ -32,6 +39,7 @@
*
* @author Copyright (c) Alfa Financial Software 2014
*/
@ImplementedBy(TableLoaderBuilderImpl.class)
public interface TableLoaderBuilder {

/**
Expand Down Expand Up @@ -120,4 +128,109 @@ public interface TableLoaderBuilder {
* @return A table loader.
*/
TableLoader forTable(Table table);
}

/**
* 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> sqlDialect;
private int batchSize = 1000;

TableLoaderBuilderImpl() {
super();
// This will need to be provided in withSqlScriptExecutor
sqlScriptExecutorProvider = null;
}

@Inject
TableLoaderBuilderImpl(
SqlScriptExecutorProvider sqlScriptExecutorProvider,
Provider<SqlDialect> 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);
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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<TableContribution> tableMultibinder = Multibinder.newSetBinder(binder(), TableContribution.class);
tableMultibinder.addBinding().to(DatabaseUpgradeTableContribution.class);
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -39,6 +40,7 @@ public class SqlScriptExecutorProvider implements Provider<SqlScriptExecutor> {
* {@link SqlScriptExecutorProvider} for
* @param sqlDialect The dialect to use
*/
@Inject
public SqlScriptExecutorProvider(final DataSource dataSource, Provider<SqlDialect> sqlDialect) {
super();
this.dataSource = dataSource;
Expand Down
1 change: 0 additions & 1 deletion morf-guicesupport/.gitignore

This file was deleted.

36 changes: 0 additions & 36 deletions morf-guicesupport/pom.xml

This file was deleted.

Loading

0 comments on commit 1f47ae6

Please sign in to comment.