branch develop updated (db50d47 -> f942af0)
This is an automated email from the git hooks/post-receive script. New change to branch develop in repository observe. See https://gitlab.nuiton.org/codelutin/observe.git from db50d47 Use last stable of topia new d8bb540 use c3p0 new f942af0 [LL] Problème de copie de marée avec des pièces-jointes (Fixes #8670) The 2 revisions listed above as "new" are entirely new to this repository and will be described in separate emails. The revisions listed as "adds" were already present in the repository and have only been added to this reference. Detailed log of new commits: commit f942af088b3aa1601ac06853db59ace4c13ad7fe Author: Tony CHEMIT <chemit@codelutin.com> Date: Wed Oct 19 17:39:00 2016 +0200 [LL] Problème de copie de marée avec des pièces-jointes (Fixes #8670) commit d8bb540f6596e268cee720ba4ccad441e2c9ef25 Author: Tony CHEMIT <chemit@codelutin.com> Date: Wed Oct 19 17:38:37 2016 +0200 use c3p0 Summary of changes: entities/pom.xml | 4 + pom.xml | 15 ++++ topia-extension/pom.xml | 12 +++ .../sql/batch/actions/ReplicateTablesAction.java | 98 +++++++++++++++++----- 4 files changed, 109 insertions(+), 20 deletions(-) -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.
This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository observe. See https://gitlab.nuiton.org/codelutin/observe.git commit d8bb540f6596e268cee720ba4ccad441e2c9ef25 Author: Tony CHEMIT <chemit@codelutin.com> Date: Wed Oct 19 17:38:37 2016 +0200 use c3p0 --- pom.xml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/pom.xml b/pom.xml index 4508a6b..7c78b02 100644 --- a/pom.xml +++ b/pom.xml @@ -563,6 +563,21 @@ <version>${hibernateVersion}</version> </dependency> + <dependency> + <groupId>org.hibernate</groupId> + <artifactId>hibernate-c3p0</artifactId> + <version>${hibernateVersion}</version> + <scope>runtime</scope> + </dependency> + + <dependency> + <groupId>com.mchange</groupId> + <artifactId>c3p0</artifactId> + <version>0.9.5.2</version> + <scope>runtime</scope> + </dependency> + + <!-- Map --> <dependency> <groupId>org.geotools</groupId> -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.
This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository observe. See https://gitlab.nuiton.org/codelutin/observe.git commit f942af088b3aa1601ac06853db59ace4c13ad7fe Author: Tony CHEMIT <chemit@codelutin.com> Date: Wed Oct 19 17:39:00 2016 +0200 [LL] Problème de copie de marée avec des pièces-jointes (Fixes #8670) --- entities/pom.xml | 4 + topia-extension/pom.xml | 12 +++ .../sql/batch/actions/ReplicateTablesAction.java | 98 +++++++++++++++++----- 3 files changed, 94 insertions(+), 20 deletions(-) diff --git a/entities/pom.xml b/entities/pom.xml index 650ec32..ec5f34c 100644 --- a/entities/pom.xml +++ b/entities/pom.xml @@ -97,6 +97,10 @@ <groupId>org.hibernate</groupId> <artifactId>hibernate-core</artifactId> </dependency> + <dependency> + <groupId>org.hibernate</groupId> + <artifactId>hibernate-c3p0</artifactId> + </dependency> <!-- test --> <dependency> diff --git a/topia-extension/pom.xml b/topia-extension/pom.xml index d053b63..4255bcd 100644 --- a/topia-extension/pom.xml +++ b/topia-extension/pom.xml @@ -76,6 +76,18 @@ <artifactId>hibernate-core</artifactId> </dependency> + <dependency> + <groupId>org.postgresql</groupId> + <artifactId>postgresql</artifactId> + </dependency> + + <dependency> + <groupId>com.mchange</groupId> + <artifactId>c3p0</artifactId> + <version>0.9.5.2</version> + <scope>compile</scope> + </dependency> + <!-- test --> <dependency> <groupId>junit</groupId> diff --git a/topia-extension/src/main/java/org/nuiton/topia/service/sql/batch/actions/ReplicateTablesAction.java b/topia-extension/src/main/java/org/nuiton/topia/service/sql/batch/actions/ReplicateTablesAction.java index b263ba7..3e8df88 100644 --- a/topia-extension/src/main/java/org/nuiton/topia/service/sql/batch/actions/ReplicateTablesAction.java +++ b/topia-extension/src/main/java/org/nuiton/topia/service/sql/batch/actions/ReplicateTablesAction.java @@ -22,16 +22,24 @@ package org.nuiton.topia.service.sql.batch.actions; * #L% */ +import com.mchange.v2.c3p0.impl.NewProxyConnection; import org.apache.commons.io.output.ByteArrayOutputStream; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.nuiton.topia.persistence.metadata.TopiaMetadataEntity; import org.nuiton.topia.service.sql.batch.tables.TopiaSqlTable; import org.nuiton.topia.service.sql.batch.tables.TopiaSqlTables; +import org.postgresql.PGConnection; +import org.postgresql.jdbc.PgConnection; +import org.postgresql.largeobject.LargeObject; +import org.postgresql.largeobject.LargeObjectManager; import javax.sql.rowset.serial.SerialBlob; import java.io.IOException; +import java.io.InputStream; +import java.lang.reflect.Field; import java.sql.Blob; +import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.ResultSetMetaData; @@ -123,7 +131,12 @@ public class ReplicateTablesAction extends AbstractTablesAction<ReplicateTablesR try { - String arguments = generateSqlArguments(readResultSet, columnNames, blobsBuilder); + String blobColumn = null; + if (useBlob) { + blobColumn = metadataEntity.getBlobProperties().iterator().next(); + } + Connection connection = readStatement.getConnection(); + String arguments = generateSqlArguments(readResultSet, columnNames, blobColumn, blobsBuilder, connection); String sql = String.format(insertStatementSql, arguments); writer.append(sql); @@ -152,7 +165,15 @@ public class ReplicateTablesAction extends AbstractTablesAction<ReplicateTablesR StringBuilder columnNamesBuilder = new StringBuilder(); - columnNames.forEach(columnName -> columnNamesBuilder.append(", ").append(columnName)); + String blobColumn = null; + if (table.getMetadataEntity().withBlob()) { + blobColumn = table.getMetadataEntity().getBlobProperties().iterator().next(); + } + for (String columnName : columnNames) { + if (!columnName.equals(blobColumn)) { + columnNamesBuilder.append(", ").append(columnName); + } + } String sql = String.format(INSERT_STATEMENT, table.getSchemaName(), @@ -168,13 +189,67 @@ public class ReplicateTablesAction extends AbstractTablesAction<ReplicateTablesR protected String generateSqlArguments(ResultSet readResultSet, Iterable<String> columnNames, - BlobsContainer.Builder blobsBuilder) throws SQLException, IOException { + String blobColumn, BlobsContainer.Builder blobsBuilder, + Connection connection) throws SQLException, IOException { String statement = ""; for (String columnName : columnNames) { Object columnValue = readResultSet.getObject(columnName); + + if (columnName.equals(blobColumn)) { + + InputStream stream; + int size; + if (columnValue instanceof Long) { + + PGConnection pgConnection; + + if (connection instanceof PgConnection) { + pgConnection = (PGConnection) connection; + } else if (connection instanceof NewProxyConnection) { + + NewProxyConnection connection1 = (NewProxyConnection) connection; + try { + Field field = connection1.getClass().getDeclaredField("inner"); + field.setAccessible(true); + pgConnection = (PGConnection) field.get(connection1); + } catch (Exception e) { + throw new RuntimeException(e); + } + + } else { + throw new IllegalStateException("Can't know how to manage connection: " + connection); + } + + LargeObjectManager lobj = pgConnection.getLargeObjectAPI(); + + LargeObject obj = lobj.open((long) columnValue, LargeObjectManager.READ); + size = obj.size(); + stream = obj.getInputStream(); + + } else { + Blob blob = (Blob) columnValue; + + stream = blob.getBinaryStream(); + SerialBlob serialBlob = new SerialBlob(blob); + size = (int) serialBlob.length(); + } + + try (ByteArrayOutputStream stringWriter = new ByteArrayOutputStream(size)) { + stringWriter.write(stream); + String topiaId = readResultSet.getString("topiaId"); + Objects.nonNull(topiaId); + blobsBuilder.addBlob(topiaId, stringWriter.toByteArray()); + if (log.isInfoEnabled()) { + log.info("Add blob: " + topiaId); + } + } + + continue; + } + if (columnValue == null) { statement += ", NULL"; continue; @@ -191,23 +266,6 @@ public class ReplicateTablesAction extends AbstractTablesAction<ReplicateTablesR 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()) + "'"; - statement += ", NULL"; - String topiaId = readResultSet.getString("topiaId"); - Objects.nonNull(topiaId); - blobsBuilder.addBlob(topiaId, stringWriter.toByteArray()); - if (log.isInfoEnabled()) { - log.info("Add blob: " + topiaId); - } - } - continue; - } - statement += ", " + columnValue; } -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.
participants (1)
-
codelutin.com scm