Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jacaetevha/173931 to your computer and use it in GitHub Desktop.
Save jacaetevha/173931 to your computer and use it in GitHub Desktop.
module Sequel
module JDBC
module Oracle
class Dataset < JDBC::Dataset
# this, of course, brings the entire CLOB into memory (perhaps that is what we want)
def read_clob(clob)
# what about converting it to a Ruby IO object, as in:
# Java.java_to_ruby(org.jruby.RubyIO.new(JRuby.runtime, clob.getCharacterStream()).java_object)
reader = java.io.BufferedReader.new(clob.getCharacterStream())
answer = []
while (str = reader.readLine)
answer << str
end
reader.close
answer.join("\n")
end
# this, of course, brings the entire BLOB into memory (almost assuredly what we DON'T want to do)
def read_blob(blob)
# what about converting it to a Ruby IO object, as in:
# Java.java_to_ruby(org.jruby.RubyIO.new(JRuby.runtime, blob.getBinaryStream()).java_object)
reader = java.io.BufferedInputStream.new(blob.getBinaryStream())
answer = []
while((byte = reader.read) != -1)
answer << byte
end
reader.close
answer
end
def convert_type_with_extra_behavior(v)
if v.class.to_s =~ /lob$/i
if v.class.to_s == 'Java::OracleSql::CLOB'
read_clob(v)
elsif v.class.to_s == 'Java::OracleSql::BLOB'
read_blob(v)
else
v.inspect
end
else
convert_type_without_extra_behavior(v)
end
end
alias_method :convert_type_without_extra_behavior, :convert_type unless method_defined?(:convert_type_without_extra_behavior)
alias_method :convert_type, :convert_type_with_extra_behavior
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment