Module: Handle::Java::Persistence

Defined in:
lib/handle/java/persistence.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#connectionObject

Returns the value of attribute connection.



4
5
6
# File 'lib/handle/java/persistence.rb', line 4

def connection
  @connection
end

#handleObject

Returns the value of attribute handle.



4
5
6
# File 'lib/handle/java/persistence.rb', line 4

def handle
  @handle
end

Instance Method Details

#destroyObject



47
48
49
# File 'lib/handle/java/persistence.rb', line 47

def destroy
  connection.delete_handle(self.handle)
end

#reloadObject



16
17
18
# File 'lib/handle/java/persistence.rb', line 16

def reload
  self.initialize_with(connection.resolve_handle(self.handle).fields)
end

#save(new_handle = nil) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/handle/java/persistence.rb', line 20

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

#to_javaObject



6
7
8
9
10
11
12
13
14
# File 'lib/handle/java/persistence.rb', line 6

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