This is an automated email from the git hooks/post-receive script. New commit to branch feature/3860_introduce_topiasqlbatchsupport in repository topia. See http://git.nuiton.org/topia.git commit 6ae53987dc835876e4e556f61e913184f719537e Author: Tony CHEMIT <chemit@codelutin.com> Date: Tue Jan 5 08:26:11 2016 +0100 Add Sql action abstract classes --- .../sql/batch/actions/AbstractSchemaAction.java | 60 ++++++ .../sql/batch/actions/AbstractSchemaRequest.java | 106 ++++++++++ .../sql/batch/actions/AbstractSqlAction.java | 231 +++++++++++++++++++++ .../sql/batch/actions/AbstractSqlRequest.java | 114 ++++++++++ .../sql/batch/actions/AbstractTablesAction.java | 214 +++++++++++++++++++ .../sql/batch/actions/AbstractTablesRequest.java | 105 ++++++++++ .../batch/actions/TopiaSqlTableSelectArgument.java | 53 +++++ .../src/test/resources/log4j.properties | 34 +++ 8 files changed, 917 insertions(+) diff --git a/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/actions/AbstractSchemaAction.java b/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/actions/AbstractSchemaAction.java new file mode 100644 index 0000000..60c9ffa --- /dev/null +++ b/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/actions/AbstractSchemaAction.java @@ -0,0 +1,60 @@ +package org.nuiton.topia.service.sql.batch.actions; + +/* + * #%L + * ToPIA :: Service Sql batch + * %% + * Copyright (C) 2004 - 2016 CodeLutin, Tony Chemit + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + +import org.hibernate.dialect.Dialect; + +import java.io.IOException; +import java.nio.file.Path; +import java.sql.SQLException; + +/** + * Created on 01/01/16. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 3.0.1 + */ +public abstract class AbstractSchemaAction<R extends AbstractSchemaRequest> extends AbstractSqlAction<R> { + + protected AbstractSchemaAction(R request) { + super(request); + } + + protected abstract String produceSql(Class<? extends Dialect> dialectType, Path temporaryDirectory) throws IOException; + + @Override + protected final void execute() throws IOException, SQLException { + + String sqlStatements = produceSql(request.getDialect(), request.getTemporaryPath()); + + if (useOutputDb()) { + targetConnection.createStatement().execute(sqlStatements); + } + + if (useOutputWriter()) { + writer.append(sqlStatements); + } + + } + +} diff --git a/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/actions/AbstractSchemaRequest.java b/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/actions/AbstractSchemaRequest.java new file mode 100644 index 0000000..5d035e3 --- /dev/null +++ b/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/actions/AbstractSchemaRequest.java @@ -0,0 +1,106 @@ +package org.nuiton.topia.service.sql.batch.actions; + +/* + * #%L + * ToPIA :: Service Sql batch + * %% + * Copyright (C) 2004 - 2016 CodeLutin, Tony Chemit + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + +import com.google.common.base.Preconditions; +import org.hibernate.dialect.Dialect; +import org.hibernate.dialect.H2Dialect; +import org.hibernate.dialect.PostgreSQL9Dialect; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; + +/** + * Created on 01/01/16. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 3.0.1 + */ +public abstract class AbstractSchemaRequest extends AbstractSqlRequest { + + protected Class<? extends Dialect> dialect; + + protected Path temporaryPath; + + public Class<? extends Dialect> getDialect() { + return dialect; + } + + protected void setDialect(Class<? extends Dialect> dialect) { + this.dialect = dialect; + } + + public Path getTemporaryPath() { + return temporaryPath; + } + + protected void setTemporaryPath(Path temporaryPath) { + this.temporaryPath = temporaryPath; + } + + public abstract static class AbstractSchemaRequestBuilder<R extends AbstractSchemaRequest, B extends AbstractSchemaRequestBuilder<R, B>> extends AbstractSqlRequestBuilder<B, R> { + + protected AbstractSchemaRequestBuilder(R request) { + super(request); + } + + public B forH2() { + setDialect(H2Dialect.class); + return returnThis(); + } + + public B forPostgres() { + setDialect(PostgreSQL9Dialect.class); + return returnThis(); + } + + public B setDialect(Class<? extends Dialect> dialectType) { + request.setDialect(dialectType); + return returnThis(); + } + + public B setTemporaryPath(Path temporaryPath) { + request.setTemporaryPath(temporaryPath); + return returnThis(); + } + + @Override + protected void checkParams() { + super.checkParams(); + Preconditions.checkState(request.getDialect() != null, "No dialect defined"); + + if (request.getTemporaryPath() == null) { + + try { + Path tempDirectory = Files.createTempDirectory(getClass().getSimpleName()); + setTemporaryPath(tempDirectory); + } catch (IOException e) { + throw new RuntimeException("Could not create teomporary path"); + } + + } + } + + } +} diff --git a/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/actions/AbstractSqlAction.java b/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/actions/AbstractSqlAction.java new file mode 100644 index 0000000..984b54a --- /dev/null +++ b/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/actions/AbstractSqlAction.java @@ -0,0 +1,231 @@ +package org.nuiton.topia.service.sql.batch.actions; + +/* + * #%L + * ToPIA :: Service Replication + * %% + * Copyright (C) 2004 - 2015 CodeLutin, Tony Chemit + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + +import com.google.common.collect.ImmutableSet; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.nuiton.topia.persistence.TopiaApplicationContext; +import org.nuiton.topia.persistence.TopiaException; +import org.nuiton.topia.persistence.TopiaPersistenceContext; +import org.nuiton.topia.persistence.internal.AbstractTopiaPersistenceContext; +import org.nuiton.topia.persistence.jdbc.JdbcConfiguration; +import org.nuiton.topia.persistence.jdbc.JdbcHelper; +import org.nuiton.topia.persistence.support.TopiaSqlWork; +import org.nuiton.util.TimeLog; + +import java.io.Closeable; +import java.io.IOException; +import java.io.Writer; +import java.sql.Connection; +import java.sql.SQLException; + +/** + * Support to create action. + * <p> + * Created on 29/12/15. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 3.0.1 + */ +public abstract class AbstractSqlAction<R extends AbstractSqlRequest> implements Runnable, Closeable { + + protected static final TimeLog TIME_LOG = new TimeLog(AbstractSqlAction.class, 50L, 100L); + /** + * Logger. + */ + private static final Log log = LogFactory.getLog(AbstractSqlAction.class); + protected final R request; + + protected final ImmutableSet<Closeable> closeables; + + protected TopiaPersistenceContext sourcePersistenceContext; + + protected Connection targetConnection; + + protected Writer writer; + + protected long startTime; + + protected long endTime; + + protected AbstractSqlAction(R request) { + this.request = request; + + ImmutableSet.Builder<Closeable> closeableBuilder = ImmutableSet.builder(); + closeableBuilder.add(new Closeable() { + @Override + public void close() throws IOException { + if (sourcePersistenceContext != null) { + sourcePersistenceContext.close(); + } + } + }); + closeableBuilder.add(new Closeable() { + @Override + public void close() throws IOException { + if (targetConnection != null) { + try { + targetConnection.close(); + } catch (SQLException e) { + throw new TopiaException("Could not close targetConnection", e); + } + } + } + }); + this.closeables = closeableBuilder.build(); + } + + protected static void flush(Writer writer) { + try { + writer.flush(); + } catch (IOException e) { + throw new TopiaException("Could not flush writer", e); + } + } + + public R getRequest() { + return request; + } + + protected boolean useOutputWriter() { + return request.getWriter() != null; + } + + protected boolean useOutputDb() { + return request.getTargetTopiaApplicationContext() != null; + } + + protected abstract void execute() throws IOException, SQLException; + + @Override + public final void run() { + + try { + + before(); + execute(); + after(); + + } catch (Exception e) { + fail(e); + } + + } + + public void commit() { + + if (useOutputWriter()) { + flush(writer); + } + + if (useOutputDb()) { + + if (targetConnection != null) { + try { + targetConnection.commit(); + } catch (SQLException e) { + throw new TopiaException("Could not commit", e); + } + } + + } + + } + + @Override + public final void close() { + + Exception error = null; + for (Closeable closeable : closeables) { + try { + closeable.close(); + } catch (Exception e) { + error = e; + log.error("Could not close", e); + } + } + if (error != null) { + throw new RuntimeException("Could not close", error); + } + + } + + protected final void before() throws SQLException { + startTime = TimeLog.getTime(); + + if (useOutputWriter()) { + writer = request.getWriter(); + } + + if (useOutputDb()) { + OpenJdbcHelper jdbcHelper = new OpenJdbcHelper(request.getTargetTopiaApplicationContext().getConfiguration()); + targetConnection = jdbcHelper.openConnection(); + } + + } + + protected void fail(Exception e) { + + endTime = TIME_LOG.log(startTime, "Action failed", getClass().getName()); + + //FIXME + throw new TopiaException(e); + + } + + protected final void after() throws SQLException { + + endTime = TIME_LOG.log(startTime, "Action executed", getClass().getName()); + + } + + protected void executeSqlWork(TopiaSqlWork sqlWork) { + getSourcePersistenceContext().getSqlSupport().doSqlWork(sqlWork); + } + + protected AbstractTopiaPersistenceContext getSourcePersistenceContext() { + if (sourcePersistenceContext == null) { + sourcePersistenceContext = request.getSourceTopiaApplicationContext().newPersistenceContext(); + } + return (AbstractTopiaPersistenceContext) sourcePersistenceContext; + } + + protected ImmutableSet<String> getSchemaNames() { + TopiaApplicationContext<?> sourceTopiaApplicationContext = request.getSourceTopiaApplicationContext(); + return sourceTopiaApplicationContext.getSchemaNames(); + } + + protected static class OpenJdbcHelper extends JdbcHelper { + + public OpenJdbcHelper(JdbcConfiguration jdbcConfiguration) { + super(jdbcConfiguration); + } + + @Override + public Connection openConnection() throws SQLException { + return super.openConnection(); + } + } + +} diff --git a/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/actions/AbstractSqlRequest.java b/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/actions/AbstractSqlRequest.java new file mode 100644 index 0000000..bacc2fc --- /dev/null +++ b/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/actions/AbstractSqlRequest.java @@ -0,0 +1,114 @@ +package org.nuiton.topia.service.sql.batch.actions; + +/* + * #%L + * ToPIA :: Service Replication, tony Chemit + * %% + * Copyright (C) 2004 - 2015 CodeLutin, Tony Chemit + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + +import com.google.common.base.Preconditions; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.nuiton.topia.persistence.TopiaApplicationContext; + +import java.io.Writer; + +/** + * Support to create action request. + * <p> + * Created on 29/12/15. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 3.0.1 + */ +public abstract class AbstractSqlRequest { + + /** + * Logger. + */ + private static final Log log = LogFactory.getLog(AbstractSqlRequest.class); + + protected TopiaApplicationContext sourceTopiaApplicationContext; + + protected TopiaApplicationContext targetTopiaApplicationContext; + + protected Writer writer; + + public TopiaApplicationContext getTargetTopiaApplicationContext() { + return targetTopiaApplicationContext; + } + + protected void setTargetTopiaApplicationContext(TopiaApplicationContext targetTopiaApplicationContext) { + this.targetTopiaApplicationContext = targetTopiaApplicationContext; + } + + public TopiaApplicationContext getSourceTopiaApplicationContext() { + return sourceTopiaApplicationContext; + } + + protected void setSourceTopiaApplicationContext(TopiaApplicationContext sourceTopiaApplicationContext) { + this.sourceTopiaApplicationContext = sourceTopiaApplicationContext; + } + + public Writer getWriter() { + return writer; + } + + protected void setWriter(Writer writer) { + this.writer = writer; + } + + public static abstract class AbstractSqlRequestBuilder<B extends AbstractSqlRequestBuilder, R extends AbstractSqlRequest> { + + protected final R request; + + protected AbstractSqlRequestBuilder(R request) { + this.request = request; + } + + public B from(TopiaApplicationContext sourceTopiaApplicationContext) { + request.setSourceTopiaApplicationContext(sourceTopiaApplicationContext); + return returnThis(); + } + + public B to(TopiaApplicationContext targetTopiaApplicationContext) { + request.setTargetTopiaApplicationContext(targetTopiaApplicationContext); + return returnThis(); + } + + public B to(Writer writer) { + request.setWriter(writer); + return returnThis(); + } + + public R build() { + checkParams(); + return request; + } + + protected void checkParams() { + Preconditions.checkState(request.getSourceTopiaApplicationContext() != null, "No sourceTopiaApplicationContext defined"); + Preconditions.checkState(request.getWriter() != null || request.getTargetTopiaApplicationContext() != null, "No targetTopiaApplicationContext, nor writer defined"); + } + + protected B returnThis() { + return (B) this; + } + } +} diff --git a/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/actions/AbstractTablesAction.java b/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/actions/AbstractTablesAction.java new file mode 100644 index 0000000..02ece9e --- /dev/null +++ b/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/actions/AbstractTablesAction.java @@ -0,0 +1,214 @@ +package org.nuiton.topia.service.sql.batch.actions; + +/* + * #%L + * ToPIA :: Service Replication + * %% + * Copyright (C) 2004 - 2015 CodeLutin, Tony Chemit + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + +import org.apache.commons.io.output.ByteArrayOutputStream; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.nuiton.topia.persistence.support.TopiaSqlWork; +import org.nuiton.topia.service.sql.batch.tables.TopiaSqlTable; +import org.nuiton.util.TimeLog; + +import javax.sql.rowset.serial.SerialBlob; +import java.io.IOException; +import java.io.Writer; +import java.sql.Blob; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.ResultSetMetaData; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +/** + * Support to create action. + * <p> + * Created on 29/12/15. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 3.0.1 + */ +public abstract class AbstractTablesAction<R extends AbstractTablesRequest> extends AbstractSqlAction<R> { + + /** + * Logger. + */ + private static final Log log = LogFactory.getLog(AbstractTablesAction.class); + + protected AbstractTablesAction(R request) { + super(request); + } + + protected abstract void executeOnTable(R request, TopiaSqlTable table, PreparedStatement readStatement) throws SQLException; + + @Override + protected final void execute() { + + for (TopiaSqlTable table : request.getTables()) { + + long startTable = TimeLog.getTime(); + + TopiaSqlWork sqlWork = new ReadSqlWork(request, table); + executeSqlWork(sqlWork); + + TIME_LOG.log(startTable, "Executed on table.", table.getFullyTableName()); + + } + + } + + protected String generateSqlArguments(ResultSet readResultSet, Iterable<String> columnNames) throws SQLException, IOException { + + String statement = ""; + + for (String columnName : columnNames) { + + Object columnValue = readResultSet.getObject(columnName); + if (columnValue == null) { + statement += ", NULL"; + continue; + } + + if (columnValue instanceof String) { + String stringValue = (String) columnValue; + statement += ", '" + stringValue.replaceAll("'", "''") + "'"; + continue; + } + + if (columnValue instanceof Date) { + statement += ", '" + columnValue + "'"; + continue; + } + + if (columnValue instanceof Blob) { + Blob blob = (Blob) columnValue; + SerialBlob serialBlob = new SerialBlob(blob); + try (ByteArrayOutputStream stringWriter = new ByteArrayOutputStream((int) serialBlob.length())) { + stringWriter.write(serialBlob.getBinaryStream()); + statement += ", '" + new String(stringWriter.toByteArray()) + "'"; + } + continue; + } + + statement += ", " + columnValue; + } + + return statement.substring(2); + + } + + protected String generateWildcardArguments(Iterable<String> columnNames) throws SQLException { + + StringBuilder argsBuilder = new StringBuilder(); + + for (String ignored : columnNames) { + argsBuilder.append(", ?"); + } + + return argsBuilder.substring(2); + + } + + protected void flush(PreparedStatement writeStatement, Writer writer, String tableName, long index) throws SQLException { + + if (log.isDebugEnabled()) { + log.debug("Flush for : " + tableName + " (size: " + index + ")"); + } + + if (writeStatement != null) { + writeStatement.executeBatch(); + writeStatement.clearBatch(); + } + + if (writer != null) { + flush(writer); + } + } + + protected List<String> getColumnNames(ResultSetMetaData readResultTatMetaData, int columnCount) throws SQLException { + List<String> builder = new ArrayList<>(columnCount); + for (int i = 1; i <= columnCount; i++) { + builder.add(readResultTatMetaData.getColumnName(i).toLowerCase()); + } + return builder; + } + + protected class ReadSqlWork implements TopiaSqlWork { + + private final R request; + private final TopiaSqlTable table; + + public ReadSqlWork(R request, TopiaSqlTable table) { + this.request = request; + this.table = table; + } + + @Override + public void execute(Connection connection) throws SQLException { + + try (PreparedStatement readStatement = createReadStatement(table, connection)) { + + readStatement.execute(); + + executeOnTable(request, table, readStatement); + + } + + } + + protected PreparedStatement createReadStatement(TopiaSqlTable table, Connection connection) throws SQLException { + + StringBuilder sqlBuilder = new StringBuilder("SELECT " + table.getTableName() + ".*"); + + sqlBuilder.append(" FROM ").append(table.getFromClause()); + for (String joinClause : table.getJoinClauses()) { + sqlBuilder.append(" ").append(joinClause); + } + TopiaSqlTableSelectArgument selectArgument = request.getSelectArgument(); + boolean filter = selectArgument != null; + if (filter) { + sqlBuilder.append(" WHERE ").append(table.getWhereClause(selectArgument.getIds())); + } + + String sql = sqlBuilder.toString(); + if (log.isDebugEnabled()) { + log.debug("Read sql: " + sql); + } + PreparedStatement statement = connection.prepareStatement(sql); + + if (filter) { + int index = 1; + for (String id : selectArgument.getIds()) { + statement.setString(index++, id); + } + } + statement.setFetchSize(request.getFetchSize()); + return statement; + + } + + } + +} diff --git a/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/actions/AbstractTablesRequest.java b/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/actions/AbstractTablesRequest.java new file mode 100644 index 0000000..9edad80 --- /dev/null +++ b/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/actions/AbstractTablesRequest.java @@ -0,0 +1,105 @@ +package org.nuiton.topia.service.sql.batch.actions; + +/* + * #%L + * ToPIA :: Service Replication, tony Chemit + * %% + * Copyright (C) 2004 - 2015 CodeLutin, Tony Chemit + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.nuiton.topia.service.sql.batch.tables.TopiaSqlTables; + +/** + * Support to create action request. + * <p> + * Created on 29/12/15. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 3.0.1 + */ +public abstract class AbstractTablesRequest extends AbstractSqlRequest { + + public static final int DEFAULT_FETCH_SIZE = 100; + /** + * Logger. + */ + private static final Log log = LogFactory.getLog(AbstractTablesRequest.class); + protected int fetchSize; + + protected TopiaSqlTableSelectArgument selectArgument; + + protected TopiaSqlTables tables; + + public int getFetchSize() { + return fetchSize; + } + + public void setFetchSize(int fetchSize) { + this.fetchSize = fetchSize; + } + + public TopiaSqlTableSelectArgument getSelectArgument() { + return selectArgument; + } + + public void setSelectArgument(TopiaSqlTableSelectArgument selectArgument) { + this.selectArgument = selectArgument; + } + + public TopiaSqlTables getTables() { + return tables; + } + + public void setTables(TopiaSqlTables tables) { + this.tables = tables; + } + + /** + * Support to create action builder. + * <p> + * Created on 29/12/15. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 3.0.1 + */ + public abstract static class AbstractTablesRequestBuilder<B extends AbstractTablesRequestBuilder, R extends AbstractTablesRequest> extends AbstractSqlRequestBuilder<B, R> { + + protected AbstractTablesRequestBuilder(R sqlActionRequest) { + super(sqlActionRequest); + setFetchSize(DEFAULT_FETCH_SIZE); + } + + public B setTables(TopiaSqlTables tables) { + request.setTables(tables); + return returnThis(); + } + + public B setFetchSize(int fetchSize) { + request.setFetchSize(fetchSize); + return returnThis(); + } + + public B setSelectArgument(TopiaSqlTableSelectArgument arg) { + request.setSelectArgument(arg); + return returnThis(); + } + + } +} diff --git a/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/actions/TopiaSqlTableSelectArgument.java b/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/actions/TopiaSqlTableSelectArgument.java new file mode 100644 index 0000000..8f6723c --- /dev/null +++ b/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/actions/TopiaSqlTableSelectArgument.java @@ -0,0 +1,53 @@ +package org.nuiton.topia.service.sql.batch.actions; + +/* + * #%L + * ToPIA :: Service Sql batch + * %% + * Copyright (C) 2004 - 2016 CodeLutin, Tony Chemit + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Sets; + +/** + * Created on 02/01/16. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 3.0.1 + */ +public class TopiaSqlTableSelectArgument { + + protected final ImmutableSet<String> ids; + + protected TopiaSqlTableSelectArgument(Iterable<String> ids) { + this.ids = ImmutableSet.copyOf(ids); + } + + public static TopiaSqlTableSelectArgument of(String... ids) { + return ids.length == 0 ? null : new TopiaSqlTableSelectArgument(Sets.newHashSet(ids)); + } + + public static TopiaSqlTableSelectArgument of(Iterable<String> ids) { + return new TopiaSqlTableSelectArgument(ids); + } + + public ImmutableSet<String> getIds() { + return ids; + } +} diff --git a/topia-service-sql-batch/src/test/resources/log4j.properties b/topia-service-sql-batch/src/test/resources/log4j.properties new file mode 100644 index 0000000..9ee0066 --- /dev/null +++ b/topia-service-sql-batch/src/test/resources/log4j.properties @@ -0,0 +1,34 @@ +### +# #%L +# ToPIA :: Service Replication +# $Id$ +# $HeadURL$ +# %% +# Copyright (C) 2004 - 2014 CodeLutin +# %% +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Lesser Public License for more details. +# +# You should have received a copy of the GNU General Lesser Public +# License along with this program. If not, see +# <http://www.gnu.org/licenses/lgpl-3.0.html>. +# #L% +### +#\u00A0This log is used to display trace in generation + +# Global logging configuration +log4j.rootLogger=WARN, stdout +# Console output... +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout +log4j.appender.stdout.layout.ConversionPattern=%5p [%t] (%F:%L) %M - %m%n +# package level +log4j.logger.org.nuiton.topia=INFO +log4j.logger.org.nuiton.topia.service.sql.batch=INFO -- To stop receiving notification emails like this one, please contact nuiton.org SCM administrator <admin+scm@nuiton.org>.