Skip to content

Commit

Permalink
fix: fix blob handling in psql
Browse files Browse the repository at this point in the history
  • Loading branch information
matteo-s committed Apr 4, 2024
1 parent 9748058 commit 5dabf59
Showing 1 changed file with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.support.SqlLobValue;
import org.springframework.stereotype.Repository;
import org.springframework.util.Assert;

Expand Down Expand Up @@ -40,10 +41,11 @@ public void save(String clazz, RunnableEntity entity) {
}

Timestamp now = new Timestamp(Instant.now().toDate().getTime());
SqlLobValue lob = new SqlLobValue(entity.getData());

jdbcTemplate.update(
INSERT_SQL,
new Object[] { entity.getId(), now, now, clazz, entity.getData() },
new Object[] { entity.getId(), now, now, clazz, lob },
new int[] { Types.VARCHAR, Types.TIMESTAMP, Types.TIMESTAMP, Types.VARCHAR, Types.BLOB }
);
}
Expand All @@ -54,10 +56,11 @@ public void update(String clazz, String id, RunnableEntity entity) {
}

Timestamp now = new Timestamp(Instant.now().toDate().getTime());
SqlLobValue lob = new SqlLobValue(entity.getData());

jdbcTemplate.update(
UPDATE_SQL,
new Object[] { entity.getData(), now, id, clazz },
new Object[] { lob, now, id, clazz },
new int[] { Types.BLOB, Types.TIMESTAMP, Types.VARCHAR, Types.VARCHAR }
);
}
Expand Down

0 comments on commit 5dabf59

Please sign in to comment.