Module: CarrierWave::Storage::Adapters::JDBCConnection
- Included in:
- PostgresqlLo::File
- Defined in:
- lib/carrierwave/storage/adapters/jdbc_connection.rb
Instance Method Summary collapse
Instance Method Details
#delete ⇒ Object
31 32 33 |
# File 'lib/carrierwave/storage/adapters/jdbc_connection.rb', line 31 def delete lo_manager.java_send :unlink, [Java::long], identifier end |
#file_length ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/carrierwave/storage/adapters/jdbc_connection.rb', line 35 def file_length @uploader.model.transaction do lo = lo_manager.java_send :open, [Java::long], identifier size = lo.size lo.close size end end |
#identifier ⇒ Object
6 7 8 |
# File 'lib/carrierwave/storage/adapters/jdbc_connection.rb', line 6 def identifier @oid ||= connection.connection.getLargeObjectAPI.createLO end |
#read ⇒ Object
10 11 12 13 14 15 16 17 |
# File 'lib/carrierwave/storage/adapters/jdbc_connection.rb', line 10 def read @uploader.model.transaction do lo = lo_manager.java_send :open, [Java::long], identifier bytes = lo.read(lo.size) lo.close String.from_java_bytes(bytes) end end |
#write(file) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/carrierwave/storage/adapters/jdbc_connection.rb', line 19 def write(file) array_buf = java.nio.file.Files.readAllBytes(java.nio.file.Paths.get(file.path)) @uploader.model.transaction do lo = lo_manager.java_send :open, [Java::long, Java::int], identifier, Java::OrgPostgresqlLargeobject::LargeObjectManager::WRITE lo.truncate(0) lo.write(array_buf) size = lo.size lo.close size end end |