Class: Relation
- Inherits:
-
Object
- Object
- Relation
- Defined in:
- lib/kody/builder/relation_builder.rb
Instance Attribute Summary collapse
-
#annotations ⇒ Object
readonly
Returns the value of attribute annotations.
-
#imports ⇒ Object
readonly
Returns the value of attribute imports.
Instance Method Summary collapse
-
#initialize(uml_class_from, uml_association_end, model, type, nullable = true) ⇒ Relation
constructor
UmlAssociationEnd.
- #to_liquid ⇒ Object
Constructor Details
#initialize(uml_class_from, uml_association_end, model, type, nullable = true) ⇒ Relation
UmlAssociationEnd
9 10 11 12 13 14 15 16 17 18 19 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 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/kody/builder/relation_builder.rb', line 9 def initialize(uml_class_from, uml_association_end, model, type, nullable = true) @type = type @nullable = nullable @name = uml_association_end.name @fetch = nil @visibility = uml_association_end.visibility @visibility = "private" if @visibility.empty? participant = model.find_recursive_class_by_id(uml_association_end.participant) @uml_class_name_to = participant.name unless participant.nil? @name = @uml_class_name_to.lower_camel_case if @name.empty? && !@uml_class_name_to.nil? @annotations = Array.new @imports = Array.new class_to_under = @uml_class_name_to.underscore class_from_under = uml_class_from.name.underscore case type when "OneToOne" @att_type = @uml_class_name_to when "ManyToOne" @join_column_name = "#{@name}_fk" @att_type = @uml_class_name_to @target_entity = "#{@uml_class_name_to}.class" @annotations << "@ManyToOne(targetEntity=#{@uml_class_name_to}.class)" @annotations << "@JoinColumn(name = \"#{class_to_under}_fk\", nullable = #{@nullable})" @imports << "javax.persistence.ManyToOne" @imports << "javax.persistence.JoinColumn" when "OneToMany" @att_type = "List<#{@uml_class_name_to}>" @initialize = " = new ArrayList<#{@uml_class_name_to}>()" @annotations << '@OneToMany(mappedBy="' + class_from_under + '")' @imports << "javax.persistence.OneToMany" @imports << "java.util.ArrayList" @imports << "java.util.List" when "ManyToMany" @att_type = "List<#{@uml_class_name_to}>" @initialize = " = new ArrayList<#{@uml_class_name_to}>()" @imports << "java.util.ArrayList" @imports << "java.util.List" if uml_association_end.first join_table = "#{class_to_under}_#{class_from_under}" else join_table = "#{class_from_under}_#{class_to_under}" end join_column = "#{class_from_under}_fk" inverse_join_column = "#{class_to_under}_fk" @annotations << "@ManyToMany(targetEntity=#{@uml_class_name_to}.class)" @annotations << '@JoinTable(name = "' + join_table + '", joinColumns = { @JoinColumn(name = "' + join_column + '") }, inverseJoinColumns = { @JoinColumn(name = "' + inverse_join_column + '") })' @imports << "javax.persistence.ManyToMany" @imports << "javax.persistence.JoinTable" @imports << "javax.persistence.JoinColumn" end uml_association_end.tagged_values.each do |t| #puts "Tag: " + t.name + ", " + t.value case t.name when '@andromda.hibernate.cascade' @cascade = Datatype.cascade(t.value) when '@andromda.hibernate.orderByColumns' @imports << "javax.persistence.OrderBy" @annotations << '@OrderBy("' + t.value + '")' end end end |
Instance Attribute Details
#annotations ⇒ Object (readonly)
Returns the value of attribute annotations.
5 6 7 |
# File 'lib/kody/builder/relation_builder.rb', line 5 def annotations @annotations end |
#imports ⇒ Object (readonly)
Returns the value of attribute imports.
6 7 8 |
# File 'lib/kody/builder/relation_builder.rb', line 6 def imports @imports end |
Instance Method Details
#to_liquid ⇒ Object
98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/kody/builder/relation_builder.rb', line 98 def to_liquid { 'annotations'=>@annotations, 'att_type'=>@att_type, 'name'=>@name, 'initialize'=>@initialize, 'visibility'=>@visibility, 'uml_class_to'=>@uml_class_name_to, 'type'=>@type } end |