Class: CaTissue::Annotation::ReferenceWriter
- Inherits:
-
Object
- Object
- CaTissue::Annotation::ReferenceWriter
- Defined in:
- lib/catissue/database/annotation/reference_writer.rb
Overview
A ReferenceWriter saves annotations to the database. This is a helper class to work around caTissue DE API defects. This class infers a direct data mapping by navigating the caTissue DYEXT tables of the introspected Java annotation class properties.
Instance Method Summary collapse
-
#initialize(eid, prop, assn_eid = nil) ⇒ ReferenceWriter
constructor
A new instance of ReferenceWriter.
- #save(annotation) ⇒ Object
Constructor Details
#initialize(eid, prop, assn_eid = nil) ⇒ ReferenceWriter
Returns a new instance of ReferenceWriter.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/catissue/database/annotation/reference_writer.rb', line 10 def initialize(eid, prop, assn_eid=nil) logger.debug { "Mapping annotation #{prop.declarer.qp}.#{prop} role attributes to database columns..." } efcd = EntityFacade.instance # the referenced annotation entity id assn_eid ||= associated_entity_id(eid, prop) # the referenced entity database table @table = efcd.annotation_table_for_entity_id(assn_eid) # map the attribute => column attr_col_hash = map_attributes(prop.type, assn_eid) logger.debug { "Annotation #{prop.declarer.qp} #{prop} reference type #{prop.type.qp} maps to #{@table} as #{attr_col_hash.qp}" } # the mapped attributes and columns @attributes, cols = attr_col_hash.to_a.transpose # the SQL parameters clause params = Array.new(cols.size, '?').join(', ') # the create SQL @cr_sql = CREATE_SQL % [@table, cols.join(', '), params] # the update SQL @upd_sql = UPDATE_SQL % [@table, cols.map { |col| "#{col} = ?" }.join(', ')] # the superclass writer for annotations with superclass DE forms @parent = obtain_parent_writer(eid, prop) end |
Instance Method Details
#save(annotation) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/catissue/database/annotation/reference_writer.rb', line 33 def save(annotation) # select the SQL based on whether this is an update or a create sql = annotation.identifier ? @upd_sql : @cr_sql # allocate a new database identifier annotation.identifier ||= next_identifier # the values to bind to the SQL parameters values = database_parameters(annotation) logger.debug { "Saving annotation #{annotation} to #{@table}..." } # dispatch the SQL update or create statement Database.current.executor.transact(sql, *values) # Save the superclass attributes. if @parent then logger.debug { "Saving #{annotation} parent entity attributes..." } @parent.save(annotation) end end |