Sha256: 22b0b54d51b6206496ee4a373448f7b385e4cdbaf22f74f50ee0ff179f00da67
Contents?: true
Size: 1.62 KB
Versions: 7
Compression:
Stored size: 1.62 KB
Contents
module Handle module Java module Persistence attr_accessor :handle, :connection def to_java result = self.collect do |field| perm_params = field.perms.to_bool Native::HandleValue.new(field.index.to_java(:int), field.class.value_type.to_java_bytes, field.value.to_java_bytes, Native::HandleValue::TTL_TYPE_RELATIVE.to_java(:byte), field.ttl.to_java(:int), 0.to_java(:int), nil, *perm_params) end result.to_java(Native::HandleValue) end def reload self.initialize_with(connection.resolve_handle(self.handle).fields) end def save(new_handle=nil) save_handle = new_handle || self.handle if save_handle.nil? raise Handle::HandleError.new("No handle provided.") end if save_handle == self.handle begin original = connection.resolve_handle(save_handle) actions = original | self actions.each_value { |v| v.connection = connection } [:delete,:update,:add].each do |action| unless actions[action].empty? connection.send("#{action}_handle_values".to_sym, save_handle, actions[action]) end end rescue Handle::NotFound connection.create_handle(save_handle, self) @handle = save_handle end else connection.create_handle(save_handle, self) @handle = new_handle end self end def destroy connection.delete_handle(self.handle) end end end Persistence = Java::Persistence end
Version data entries
7 entries across 7 versions & 1 rubygems