Class: CaTissue::Annotation::EntityFacade
- Inherits:
-
Object
- Object
- CaTissue::Annotation::EntityFacade
- Includes:
- Singleton
- Defined in:
- lib/catissue/database/annotation/entity_facade.rb
Overview
EntityFacade is the caRuby substitute for the broken caTissue EntityManager. EntityManager is the caTissue singleton Winnebago object for doing lots of things with dynamic extensions. The EntityManager defects are listed in the various Rubydoc quirks.
Instance Method Summary collapse
-
#annotation_entity_id(klass, validate = true) ⇒ Integer
The caTissue entity id for the class.
- #annotation_table_for_entity_id(eid) ⇒ String
-
#associated_entity_id(eid, name) ⇒ Integer
The referenced CaTissue::Annotation class entity id.
-
#container_id(eid) ⇒ Integer
Obtains the undocumented caTisue container id for the given primary entity id.
-
#hook_entity_id(klass) ⇒ Integer
The class entity id.
-
#initialize ⇒ EntityFacade
constructor
Initializes the id generator and a SQL executor.
-
#next_identifier(annotation) ⇒ Integer
A new identifier for the given annotation object.
-
#next_identifier_for_table(table) ⇒ Integer
The next identifier to use when creating a table record.
-
#parent_entity_id(eid) ⇒ Integer?
The parent entity id, if any.
-
#primary?(eid) ⇒ Boolean
Whether the entity is primary.
Constructor Details
#initialize ⇒ EntityFacade
Initializes the id generator and a SQL executor. The id generator and executor are used for the caTissue bug work-arounds described in the method docs and IdGenerator.
17 18 19 20 21 22 23 24 |
# File 'lib/catissue/database/annotation/entity_facade.rb', line 17 def initialize # the work-around id generator @idgen = IdGenerator.new # a general-purpose SQL executor for calling the work-arounds @executor = CaTissue::Database.current.executor # the primary entity class => entity id hash @pr_eid_hash = {} end |
Instance Method Details
#annotation_entity_id(klass, validate = true) ⇒ Integer
Returns the caTissue entity id for the class.
52 53 54 55 56 |
# File 'lib/catissue/database/annotation/entity_facade.rb', line 52 def annotation_entity_id(klass, validate=true) eid = @pr_eid_hash[klass] ||= recursive_annotation_entity_id(klass) if eid.nil? and validate then raise AnnotationError.new("Entity not found for annotation #{klass}") end eid end |
#annotation_table_for_entity_id(eid) ⇒ String
104 105 106 107 108 109 110 |
# File 'lib/catissue/database/annotation/entity_facade.rb', line 104 def annotation_table_for_entity_id(eid) result = @executor.query(TABLE_NAME_SQL, eid).first if result.nil? then raise AnnotationError.new("Table not found for annotation entity id #{eid}") end tbl = result[0] logger.debug { "Annotation entity with id #{eid} has table #{tbl}." } tbl end |
#associated_entity_id(eid, name) ⇒ Integer
Returns the referenced CaTissue::Annotation class entity id.
82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/catissue/database/annotation/entity_facade.rb', line 82 def associated_entity_id(eid, name) # The caTissue role is capitalized. role = name.capitalize_first ref_eid = recursive_associated_entity_id(eid, role) if ref_eid then logger.debug { "Entity id #{eid} is associated with property #{name} via entity id #{ref_eid}." } else logger.debug { "Entity id #{eid} is not associated with property #{name}." } end ref_eid end |
#container_id(eid) ⇒ Integer
Obtains the undocumented caTisue container id for the given primary entity id.
135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/catissue/database/annotation/entity_facade.rb', line 135 def container_id(eid) # The following call is broken in caTissue 1.1.2 (see method doc). # EntityManager.instance.get_container_id_for_entity(eid) # Work-around this caTissue bug with a direct query. result = @executor.query(CTR_ID_SQL, eid).first if result.nil? then logger.debug("Dynamic extension container id not found for annotation with entity id #{eid}") return end cid = result[0].to_i logger.debug { "Annotation with entity id #{eid} has container id #{cid}." } cid end |
#hook_entity_id(klass) ⇒ Integer
Returns the class entity id.
67 68 69 70 71 72 73 |
# File 'lib/catissue/database/annotation/entity_facade.rb', line 67 def hook_entity_id(klass) result = @executor.query(HOOK_ENTITY_ID_SQL, klass.java_class.name).first if result.nil? then raise AnnotationError.new("Entity id not found for static hook class #{klass.qp}") end eid = result[0].to_i logger.debug { "Static hook class #{klass.qp} has entity id #{eid}." } eid end |
#next_identifier(annotation) ⇒ Integer
Returns a new identifier for the given annotation object.
28 29 30 31 32 33 34 |
# File 'lib/catissue/database/annotation/entity_facade.rb', line 28 def next_identifier(annotation) # The entity table name, which will be a cryptic value like DE_E_1283. eid = annotation_entity_id(annotation.class) aeid = common_ancestor_entity_id(eid) tbl = annotation_table_for_entity_id(aeid) next_identifier_for_table(tbl) end |
#next_identifier_for_table(table) ⇒ Integer
Returns the next identifier to use when creating a table record.
38 39 40 41 |
# File 'lib/catissue/database/annotation/entity_facade.rb', line 38 def next_identifier_for_table(table) # delegate to id generator @idgen.next_identifier(table) end |
#parent_entity_id(eid) ⇒ Integer?
Returns the parent entity id, if any.
114 115 116 117 |
# File 'lib/catissue/database/annotation/entity_facade.rb', line 114 def parent_entity_id(eid) result = @executor.query(PARENT_ENTITY_ID_SQL, eid).first result[0].to_i if result and result[0] end |
#primary?(eid) ⇒ Boolean
Returns whether the entity is primary.
60 61 62 63 |
# File 'lib/catissue/database/annotation/entity_facade.rb', line 60 def primary?(eid) result = @executor.query(IS_PRIMARY_SQL, eid).first not result.nil? end |