Skip to content

Commit

Permalink
Remove EnableTransactionManagement annotationwhen using bytea in Post…
Browse files Browse the repository at this point in the history
…greSQL
  • Loading branch information
nielsm5 committed Sep 24, 2024
1 parent fe30c64 commit 920883f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import java.io.StringReader;
import java.lang.invoke.MethodHandles;
import java.math.BigDecimal;
import java.sql.Blob;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Timestamp;
Expand All @@ -39,7 +38,6 @@
import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.PreparedStatementSetter;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

Expand Down Expand Up @@ -74,7 +72,7 @@
*/
// Without proxyTargetClass = true the test webapp will give: Bean named 'proofOfMigrationStorage' is expected to be of
// type 'nl.nn.testtool.storage.proofofmigration.ProofOfMigrationStorage' but was actually of type 'jdk.proxy3.$Proxy26'
@EnableTransactionManagement(proxyTargetClass = true)
// @EnableTransactionManagement(proxyTargetClass = true)
// REQUIRES_NEW to prevent interference with transactions in the application using Ladybug. E.g. when an error occurs in
// a Frank!Framework adapter the insert of the Ladybug report should not be rolled back (which happens otherwise because
// transactions are thread bound and Ladybug runs in the same thread). With NOT_SUPPORTED PostgreSQL will complain about
Expand Down Expand Up @@ -229,7 +227,7 @@ public void setValues(PreparedStatement ps) throws SQLException {
i++;
}
}
ps.setBlob(i, new ByteArrayInputStream(reportBytes));
ps.setBytes(i, reportBytes);
i++;
if (isStoreReportXml()) {
ps.setClob(i, new StringReader(reportXml));
Expand Down Expand Up @@ -270,15 +268,15 @@ public Report getReport(Integer storageId) throws StorageException {
String query = "select report from " + getTable() + " where " + getStorageIdColumn() + " = ?";
log.debug("Get report query: " + query);
List<Report> result = ladybugJdbcTemplate.query(query, new Object[]{storageId}, new int[] {Types.INTEGER},
(resultSet, rowNum) -> getReport(storageId, resultSet.getBlob(1)));
(resultSet, rowNum) -> getReport(storageId, resultSet.getBytes(1)));
return result.get(0);
}

// StorageException is allowed by Storage.getReport(), hence no need to handle it in the lambda expression that will
// call this method
@SneakyThrows
private static Report getReport(Integer storageId, Blob blob) {
return Import.getReport(blob.getBinaryStream(), storageId, blob.length(), log);
private static Report getReport(Integer storageId, byte[] blob) {
return Import.getReport(new ByteArrayInputStream(blob), storageId, (long) blob.length, log);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public String provideTrailingFirstRowsHint(int rowCount) {
}

public String getRowNumber(String order, String sort) {
if ("Oracle".equals(commonDatabaseName) || "Microsoft SQL Server".equals(commonDatabaseName)) {
if ("Oracle".equals(commonDatabaseName)) {
return "row_number() over (order by "+order+(sort==null?"":" "+sort)+") "+getRowNumberShortName();
}
return "";
Expand Down
5 changes: 4 additions & 1 deletion src/main/resources/ladybug/DatabaseChangelog_Debug.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.26.xsd"
>
<changeSet id="Ladybug:1" author="Jaco de Groot">
<property name="BLOB_FIELD_TYPE" value="bytea" dbms="postgresql"/>
<property name="BLOB_FIELD_TYPE" value="blob" dbms="!postgresql"/>

<changeSet id="Ladybug:1" author="Jaco de Groot" failOnError="false">
<comment>Add table LADYBUG</comment>
<createTable tableName="LADYBUG">
<column name="STORAGEID" type="INTEGER" autoIncrement="true">
Expand Down

0 comments on commit 920883f

Please sign in to comment.