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, :transient, :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 this property 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 this property is auto-generated



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

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 this property cascades to crate when the owner is updated



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

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 this property is a physical dependent or the :cascaded flag is set



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

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

#creatable?Boolean

This property is creatable if all of the following conditions hold:

  • it is #saved?

  • the :update_only flag is not set

Returns:

  • (Boolean)

    whether this attribute is saved in a create operation



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

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 this property must be refetched in order to reflect the database content



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

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

#fetched?Boolean

Returns whether this property is fetched, determined as follows:

  • this property is marked with the :fetched flag

  • this property is not marked with the :transient or :unfetched flag

  • otherwise, this is a non-domain property

  • otherwise, this is a domain property and one of the following conditions hold:

    • this is a non-logical dependent domain property

    • this is an owner property

    • this is an abstract, non-derived independent property

Returns:

  • (Boolean)

    whether this property 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?(:transient) or @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



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

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

#logical?Boolean

Returns whether this property 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 this property is an uncascaded dependent



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

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

#proxied_save?Boolean

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

Returns:

  • (Boolean)

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



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

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



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

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

This property is saved if it is a Java property that is not #unsaved or #proxied_save? and any of the following conditions hold:

  • it is #nondomain?

  • it is #cascaded?

  • it is not a #collection?

  • it does not have an inverse

  • it is a #unidirectional_java_dependent?

Returns:

  • (Boolean)

    whether this attribute is saved in a create or update operation



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

def saved?
  @flags.include?(:saved) or
    (java_property? and not (@flags.include?(:unsaved) or transient? or 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



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

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



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

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

#transient?Boolean

Returns whether this property is unfetched, unsaved and should not be lazy-loaded, determined by whether it is marked with the :transient flag.

Returns:

  • (Boolean)

    whether this property is transient



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

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

#unsaved?Boolean

Returns whether this attribute is not #saved?.

Returns:

  • (Boolean)

    whether this attribute is not #saved?



141
142
143
# File 'lib/caruby/metadata/property_characteristics.rb', line 141

def unsaved?
  not saved?
end

#updatable?Boolean

This property is updatable if all of the following conditions hold:

  • it is #saved?

  • the :create_only flag is not set

Returns:

  • (Boolean)

    whether this attribute is saved in a update operation



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

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



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

def volatile?
  # TODO - subsume by autogenerated?
  to_sym == :identifier or @flags.include?(:volatile)
end