Module: CaRuby::PropertyCharacteristics

Included in:
JavaProperty, Property
Defined in:
lib/caruby/metadata/property_characteristics.rb

Overview

The CaRuby::PropertyCharacteristics mixin captures persistence metadata.

Constant Summary collapse

SUPPORTED_FLAGS =

The supported persistence-specific property qualifier flags. This set augments the Jinx::Property::SUPPORTED_FLAGS set for persistence adapters. See the complementary methods for an explanation of the flag option, e.g. #autogenerated? for the :autogenerated flag.

[
:autogenerated, :logical, :cascaded, :no_cascade_update_to_create, :saved, :unsaved, :fetched,
:unfetched, :include_in_save_template, :fetch_saved, :create_only, :update_only, :nosync,
:volatile].to_set

Instance Method Summary collapse

Instance Method Details

#autogenerated?Boolean

Returns whether the subject attribute is a dependent whose value is automatically generated with place-holder domain objects when the parent is created. An attribute is auto-generated if the :autogenerated flag is set.

Returns:

  • (Boolean)

    whether the attribute is auto-generated



43
44
45
# File 'lib/caruby/metadata/property_characteristics.rb', line 43

def autogenerated?
  @flags.include?(:autogenerated)
end

#cascade_update_to_create?Boolean

Returns whether this attribute is ##cascaded? and cascades a parent update to a child create. This corresponds to the Hibernate save-update cascade style but not the Hibernate all cascade style.

This method returns true if this attribute is cascaded and the :no_cascade_update_to_create flag is not set. Set this flag if the Hibernate mapping specifies the all cascade style. Failure to set this flag will result in the caTissue Hibernate error:

Exception: gov.nih.nci.system.applicationservice.ApplicationException:
The given object has a null identifier:

followed by the attribute type name.

Returns:

  • (Boolean)

    whether the attribute cascades to crate when the owner is updated



114
115
116
# File 'lib/caruby/metadata/property_characteristics.rb', line 114

def cascade_update_to_create?
  cascaded? and not @flags.include?(:no_cascade_update_to_create)
end

#cascaded?Boolean

Indicates whether this reference propery is saved when its owner is saved.

Returns:

  • (Boolean)

    whether the attribute is a physical dependent or the :cascaded flag is set



90
91
92
# File 'lib/caruby/metadata/property_characteristics.rb', line 90

def cascaded?
  (dependent? and not logical?) or @flags.include?(:cascaded)
end

#creatable?Boolean

A Java attribute is creatable if all of the following conditions hold:

  • the attribute is #saved?

  • the attribute :update_only flag is not set

Returns:

  • (Boolean)

    whether this attribute is saved in a create operation



74
75
76
# File 'lib/caruby/metadata/property_characteristics.rb', line 74

def creatable?
  saved? and not @flags.include?(:update_only)
end

#fetch_saved?Boolean

Returns whether this attribute must be fetched when a declarer instance is saved. An attribute is a saved fetch attribute if any of the following conditions hold:

Returns:

  • (Boolean)

    whether the subject attribute must be refetched in order to reflect the database content



55
56
57
# File 'lib/caruby/metadata/property_characteristics.rb', line 55

def fetch_saved?
   @flags.include?(:fetch_saved) or autogenerated? or (cascaded? and @flags.include?(:unfetched))
end

#fetched?Boolean

Returns whether the subject attribute is fetched, determined as follows:

  • An attribute marked with the :fetched flag is fetched.

  • An attribute marked with the :unfetched flag is not fetched.

Otherwise, a non-domain attribute is fetched, and a domain attribute is fetched if one of the following conditions hold:

  • A dependent domain attribute is fetched if it is not logical.

  • An owner domain attribute is fetched by default.

  • An independent domain attribute is fetched if it is abstract and not derived.

Returns:

  • (Boolean)

    whether the attribute is fetched



25
26
27
28
29
# File 'lib/caruby/metadata/property_characteristics.rb', line 25

def fetched?
  return true if @flags.include?(:fetched)
  return false if @flags.include?(:unfetched)
  nondomain? or dependent? ? fetched_dependent? : fetched_independent?
end

#include_in_save_template?Boolean

Determines whether this propery is included in a save operation argument.

Returns:

  • (Boolean)

    whether this attribute is #cascaded? or marked with the :include_in_save_template flag



98
99
100
# File 'lib/caruby/metadata/property_characteristics.rb', line 98

def include_in_save_template?
  cascaded? or @flags.include?(:include_in_save_template)
end

#logical?Boolean

Returns whether the subject attribute is either:

  1. an owner attribute which does not automatically cascade application service creation or update to the referenced dependent, or

  2. the dependent attribute whose inverse is a logical owner attribute

Returns:

  • (Boolean)

    whether the attribute is an uncascaded dependent



65
66
67
# File 'lib/caruby/metadata/property_characteristics.rb', line 65

def logical?
  @flags.include?(:logical) or (owner? and inverse_property and inverse_property.logical?)
end

#proxied_save?Boolean

Returns whether the attribute return #type is a Resource class which implements the saver_proxy method.

Returns:

  • (Boolean)

    whether the attribute return #type is a Resource class which implements the saver_proxy method



148
149
150
# File 'lib/caruby/metadata/property_characteristics.rb', line 148

def proxied_save?
  domain? and type.method_defined?(:saver_proxy)
end

#savable_prerequisite?Boolean

Returns whether this attribute’s referents must exist before an instance of the declarer class can be created. An attribute is a savable prerequisite if it is either:

Returns:

  • (Boolean)

    whether this attribute is a create prerequisite



159
160
161
162
163
164
165
# File 'lib/caruby/metadata/property_characteristics.rb', line 159

def savable_prerequisite?
  return true if cascaded? and @flags.include?(:no_cascade_update_to_create)
  return false unless independent? and saved?
  return true unless collection?
  inv_prop = inverse_property
  inv_prop.nil? or inv_prop.collection?
end

#saved?Boolean

A Java property attribute is saved if none of the following conditions hold:

and any of the following conditions hold:

  • the attibute is #nondomain?

  • the attribute is cascaded

  • the attribute value is not a collection

  • the attribute does not have an inverse

  • the attribute :saved flag is set

Returns:

  • (Boolean)

    whether this attribute is saved in a create or update operation



129
130
131
132
133
# File 'lib/caruby/metadata/property_characteristics.rb', line 129

def saved?
  @flags.include?(:saved) or
    (java_property? and not @flags.include?(:unsaved) and not proxied_save? and
      (nondomain? or cascaded? or not collection? or inverse.nil? or unidirectional_java_dependent?))
end

#searchable?Boolean

Returns whether this is a non-collection Java attribute.

Returns:

  • (Boolean)

    whether this is a non-collection Java attribute



173
174
175
# File 'lib/caruby/metadata/property_characteristics.rb', line 173

def searchable?
  java_property? and not collection?
end

#sync?Boolean

Returns whether this attribute is ##saved? and does not have the :nosync flag set.

Returns:

  • (Boolean)

    whether this attribute is ##saved? and does not have the :nosync flag set



137
138
139
# File 'lib/caruby/metadata/property_characteristics.rb', line 137

def sync?
  saved? and not @flags.include?(:nosync)
end

#transient?Boolean

Returns whether the subject attribute is not saved.

Returns:

  • (Boolean)

    whether the subject attribute is not saved



168
169
170
# File 'lib/caruby/metadata/property_characteristics.rb', line 168

def transient?
  not saved?
end

#unsaved?Boolean

Returns whether this attribute is not #saved?.

Returns:

  • (Boolean)

    whether this attribute is not #saved?



34
35
36
# File 'lib/caruby/metadata/property_characteristics.rb', line 34

def unsaved?
  @flags.include?(:unsaved)
end

#updatable?Boolean

A Java attribute is updatable if all of the following conditions hold:

  • the attribute is #saved?

  • the attribute :create_only flag is not set

Returns:

  • (Boolean)

    whether this attribute is saved in a update operation



83
84
85
# File 'lib/caruby/metadata/property_characteristics.rb', line 83

def updatable?
  saved? and not @flags.include?(:create_only)
end

#volatile?Boolean

Returns whether this attribute is set by the server.

Returns:

  • (Boolean)

    whether this attribute is set by the server



178
179
180
# File 'lib/caruby/metadata/property_characteristics.rb', line 178

def volatile?
  to_sym == :identifier or @flags.include?(:volatile)
end