Skip to content

Commit

Permalink
fixed error when inserting large text values in Oracle DB, by properl…
Browse files Browse the repository at this point in the history
…y utilizing JDBC's CLOB type
  • Loading branch information
albogdano committed Aug 1, 2024
1 parent 1d2e9ce commit df1e019
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/main/java/com/erudika/para/server/persistence/SqlUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import com.zaxxer.hikari.HikariDataSource;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.NClob;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
Expand Down Expand Up @@ -362,7 +363,13 @@ protected static <P extends ParaObject> void createRows(String appid, List<P> ob
} else {
ps.setNull(3, Types.NULL);
}
ps.setString(4, objectJson);
if (useOrSqlSyntax) {
NClob clob = connection.createNClob();
clob.setString(1, objectJson);
ps.setClob(4, clob);
} else {
ps.setString(4, objectJson);
}

if (useMySqlSyntax || usePGSqlSyntax || useLiSqlSyntax) {
ps.setString(5, object.getType());
Expand Down Expand Up @@ -408,7 +415,14 @@ protected static <P extends ParaObject> void updateRows(String appid, List<P> ob
if (object != null && !StringUtils.isBlank(object.getId())) {
object.setUpdated(Utils.timestamp());
Map<String, Object> data = ParaObjectUtils.getAnnotatedFields(object, Locked.class, false);
ps.setString(1, ParaObjectUtils.getJsonWriterNoIdent().writeValueAsString(data));
String objectJson = ParaObjectUtils.getJsonWriterNoIdent().writeValueAsString(data);
if (useOrSqlSyntax) {
NClob clob = connection.createNClob();
clob.setString(1, objectJson);
ps.setClob(1, clob);
} else {
ps.setString(1, objectJson);
}
ps.setString(2, object.getId());
ps.addBatch();
}
Expand Down

0 comments on commit df1e019

Please sign in to comment.