Skip to content

Commit

Permalink
Java heap space error when writing > 2 GB file content as Blob into O…
Browse files Browse the repository at this point in the history
…racle Table #1617
  • Loading branch information
Tapac committed Nov 12, 2022
1 parent 03c3493 commit 4a97034
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -724,8 +724,8 @@ class BlobColumnType : ColumnType() {

override fun valueFromDB(value: Any): ExposedBlob = when (value) {
is ExposedBlob -> value
is Blob -> ExposedBlob(value.binaryStream.use { it.readBytes() })
is InputStream -> ExposedBlob(value.use { it.readBytes() })
is Blob -> ExposedBlob(value.binaryStream)
is InputStream -> ExposedBlob(value)
is ByteArray -> ExposedBlob(value)
else -> error("Unexpected value of type Blob: $value of ${value::class.qualifiedName}")
}
Expand All @@ -740,10 +740,10 @@ class BlobColumnType : ColumnType() {

override fun nonNullValueToString(value: Any): String = "?"

override fun readObject(rs: ResultSet, index: Int) = rs.getBytes(index)?.let(::ExposedBlob)
override fun readObject(rs: ResultSet, index: Int) = rs.getBinaryStream(index)?.let(::ExposedBlob)

override fun setParameter(stmt: PreparedStatementApi, index: Int, value: Any?) {
when (val toSetValue = (value as? ExposedBlob)?.bytes?.inputStream() ?: value) {
when (val toSetValue = (value as? ExposedBlob)?.inputStream ?: value) {
is InputStream -> stmt.setInputStream(index, toSetValue)
null, is Op.NULL -> stmt.setNull(index, this)
else -> super.setParameter(stmt, index, toSetValue)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
package org.jetbrains.exposed.sql.statements.api

class ExposedBlob(val bytes: ByteArray) {
import java.io.InputStream

class ExposedBlob(val inputStream: InputStream) {
constructor(bytes: ByteArray) : this (bytes.inputStream())

val bytes get() = inputStream.readBytes().also { inputStream.reset() }

This comment has been minimized.

Copy link
@kimble

kimble Nov 17, 2022

This change broke our application

Caused by: java.io.IOException: mark/reset not supported
	at java.base/java.io.InputStream.reset(InputStream.java:733)
	at java.base/java.io.FilterInputStream.reset(FilterInputStream.java:224)

org.h2.mvstore.StreamStore.Stream doesn't implement reset


override fun equals(other: Any?): Boolean {
if (this === other) return true
if (other !is ExposedBlob) return false


if (!bytes.contentEquals(other.bytes)) return false

return true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -344,9 +344,11 @@ class DDLTests : DatabaseTestsBase() {
} get (t.id)

val readOn = t.select { t.id eq id }.first()[t.b]
val text = String(readOn.bytes) // .reader().readText()
val text1 = String(readOn.bytes)
val text2 = readOn.inputStream.bufferedReader().readText()

assertEquals("Hello there!", text)
assertEquals("Hello there!", text1)
assertEquals("Hello there!", text2)
}
}

Expand Down

0 comments on commit 4a97034

Please sign in to comment.