Module: Muml_Property
- Defined in:
- lib/ontomde-uml2-jpa/jpa.rb,
lib/ontomde-uml2-jpa/mapping.rb
Constant Summary collapse
- DEFAULT_CASCADE =
"(cascade=CascadeType.ALL)"
- DEFAULT_CASCADE_I =
",cascade=CascadeType.ALL"
Instance Method Summary collapse
- #jpa_addJoinColumn!(ah) ⇒ Object
-
#jpa_addJoinTable(ah) ⇒ Object
adds a java annotation to specify the name of the join table.
- #jpa_addPersistenceBidirManyToManyMaster!(ah) ⇒ Object
- #jpa_addPersistenceBidirManyToManySlave!(ah) ⇒ Object
- #jpa_addPersistenceBidirManyToOneMaster!(ah) ⇒ Object
- #jpa_addPersistenceBidirManyToOneSlave!(ah) ⇒ Object
- #jpa_addPersistenceBidirOneToManyMaster!(ah) ⇒ Object
- #jpa_addPersistenceBidirOneToManySlave!(ah) ⇒ Object
- #jpa_addPersistenceBidirOneToOneMaster!(ah) ⇒ Object
- #jpa_addPersistenceBidirOneToOneSlave!(ah) ⇒ Object
-
#jpa_addPersistenceManyAttribute!(ah) ⇒ Object
adds JPA annotation for an attribute with a cardinality *.
-
#jpa_addPersistenceOneAttribute!(ah) ⇒ Object
adds JPA annotation for an attribute with a cardinality 0..1 or 1.
-
#jpa_addPersistenceTo!(ah) ⇒ Object
adds property persistence annotation to annotationHolder.
- #jpa_addPersistenceToAssociation!(ah) ⇒ Object
- #jpa_addPersistenceToAssociationBidir!(ah) ⇒ Object
- #jpa_addPersistenceToAssociationUnidir!(ah) ⇒ Object
- #jpa_addPersistenceToAttribute!(ah) ⇒ Object
- #jpa_addPersistenceToAttribute_TypeModificator!(ah) ⇒ Object
- #jpa_addPersistenceUnidirManyToMany!(ah) ⇒ Object
- #jpa_addPersistenceUnidirManyToOne!(ah) ⇒ Object
- #jpa_addPersistenceUnidirOneToMany!(ah) ⇒ Object
- #jpa_addPersistenceUnidirOneToOne!(ah) ⇒ Object
- #jpa_addRelationCascadeType(isIncludeType = true) ⇒ Object
- #jpa_isPersistent? ⇒ Boolean
Instance Method Details
#jpa_addJoinColumn!(ah) ⇒ Object
153 154 155 |
# File 'lib/ontomde-uml2-jpa/mapping.rb', line 153 def jpa_addJoinColumn!(ah) ah.java_annotation_add(%{@JoinColumn(name="#{java_NameProperty}_fk") /*TPL:103*/}) end |
#jpa_addJoinTable(ah) ⇒ Object
adds a java annotation to specify the name of the join table.
Note:
Explicitely naming join colums and join table is required whenever multiple associations exists between two classes and also with reflexive associations.
Examples: Object A (rolea)–>(roleb) Object B Table A_roleb
field : A_id
field : B_id
Object A (rolea)–>(roleb) Object A
Table A_roleb
field : A_id
field : A_self_id
129 130 131 132 133 134 135 136 |
# File 'lib/ontomde-uml2-jpa/mapping.rb', line 129 def jpa_addJoinTable(ah) postfix=(uml_ownedAttribute_inv_one==uml_type_one) ? "_self" : "" ah.java_annotation_add %{ @JoinTable( name="#{uml_ownedAttribute_inv_one.java_Name}_#{java_NameProperty}", joinColumns={@JoinColumn( name="#{uml_ownedAttribute_inv_one.java_Name}_id")}, inverseJoinColumns={@JoinColumn(name="#{uml_type_one.java_Name}#{postfix}_id")} ) /*TPL:116*/} end |
#jpa_addPersistenceBidirManyToManyMaster!(ah) ⇒ Object
71 72 73 74 75 |
# File 'lib/ontomde-uml2-jpa/mapping.rb', line 71 def jpa_addPersistenceBidirManyToManyMaster!(ah) ah.java_annotation_add("@ManyToMany #{jpa_addRelationCascadeType(false)}/*TPL:106*/") jpa_addJoinColumn!(ah) jpa_addJoinTable(ah) end |
#jpa_addPersistenceBidirManyToManySlave!(ah) ⇒ Object
76 77 78 79 80 81 82 |
# File 'lib/ontomde-uml2-jpa/mapping.rb', line 76 def jpa_addPersistenceBidirManyToManySlave!(ah) ah.java_annotation_add("@ManyToMany #{jpa_addRelationCascadeType(false)}/*TPL:107*/") jpa_addJoinColumn!(ah) #Do not add join column ! #(or you will get 2 join tables) #jpa_addJoinTable(ah) end |
#jpa_addPersistenceBidirManyToOneMaster!(ah) ⇒ Object
100 101 102 103 104 105 |
# File 'lib/ontomde-uml2-jpa/mapping.rb', line 100 def jpa_addPersistenceBidirManyToOneMaster!(ah) #ah.java_annotation_add(%{@ManyToOne(mappedBy="#{umlx_otherEnd.java_NameProperty}") /*TPL:112*/}) ah.java_annotation_add(%{@ManyToOne #{jpa_addRelationCascadeType(false)} /*TPL:112*/}) #ah.java_annotation_add(%{@JoinColumn(name="#{java_NameProperty}_fk"}) jpa_addJoinColumn!(ah) end |
#jpa_addPersistenceBidirManyToOneSlave!(ah) ⇒ Object
106 107 108 109 110 111 |
# File 'lib/ontomde-uml2-jpa/mapping.rb', line 106 def jpa_addPersistenceBidirManyToOneSlave!(ah) #ah.java_annotation_add(%{@ManyToOne(mappedBy="#{umlx_otherEnd.java_NameProperty}") /*TPL:113*/}) ah.java_annotation_add(%{@ManyToOne #{jpa_addRelationCascadeType(false)} /*TPL:113*/}) #ah.java_annotation_add(%{@JoinColumn(name="#{java_NameProperty}_fk"}) jpa_addJoinColumn!(ah) end |
#jpa_addPersistenceBidirOneToManyMaster!(ah) ⇒ Object
92 93 94 |
# File 'lib/ontomde-uml2-jpa/mapping.rb', line 92 def jpa_addPersistenceBidirOneToManyMaster!(ah) ah.java_annotation_add(%{@OneToMany (mappedBy="#{umlx_otherEnd.java_NameProperty}"#{jpa_addRelationCascadeType}) /*TPL:110*/}) end |
#jpa_addPersistenceBidirOneToManySlave!(ah) ⇒ Object
95 96 97 98 |
# File 'lib/ontomde-uml2-jpa/mapping.rb', line 95 def jpa_addPersistenceBidirOneToManySlave!(ah) ah.java_annotation_add(%{@OneToMany (mappedBy="#{umlx_otherEnd.java_NameProperty}"#{jpa_addRelationCascadeType}) /*TPL:111*/}) #jpa_addJoinColumn!(ah) end |
#jpa_addPersistenceBidirOneToOneMaster!(ah) ⇒ Object
84 85 86 87 |
# File 'lib/ontomde-uml2-jpa/mapping.rb', line 84 def jpa_addPersistenceBidirOneToOneMaster!(ah) ah.java_annotation_add(%{@OneToOne #{jpa_addRelationCascadeType(false)}/*TPL:108*/}) jpa_addJoinColumn!(ah) end |
#jpa_addPersistenceBidirOneToOneSlave!(ah) ⇒ Object
88 89 90 |
# File 'lib/ontomde-uml2-jpa/mapping.rb', line 88 def jpa_addPersistenceBidirOneToOneSlave!(ah) ah.java_annotation_add(%{@OneToOne(mappedBy="#{umlx_otherEnd.java_NameProperty}" #{jpa_addRelationCascadeType}) /*TPL:109*/}) end |
#jpa_addPersistenceManyAttribute!(ah) ⇒ Object
adds JPA annotation for an attribute with a cardinality *
149 150 151 |
# File 'lib/ontomde-uml2-jpa/mapping.rb', line 149 def jpa_addPersistenceManyAttribute!(ah) ah.java_annotation_add(%{@Transient //TODO: standard JPA cannot handle this case. Hibernate extension @CollectionOfElements is required/*TPL:115*/}) end |
#jpa_addPersistenceOneAttribute!(ah) ⇒ Object
adds JPA annotation for an attribute with a cardinality 0..1 or 1
139 140 141 142 143 144 145 146 |
# File 'lib/ontomde-uml2-jpa/mapping.rb', line 139 def jpa_addPersistenceOneAttribute!(ah) ml=JavaMapping.instance.getTemplate(self.uml_type_one).maxStringLength if ml.nil? ah.java_annotation_add(%{@Basic /*TPL:114*/}) else ah.java_annotation_add(%{@Column(length=#{ml}) /*TPL:114b*/}) end end |
#jpa_addPersistenceTo!(ah) ⇒ Object
adds property persistence annotation to annotationHolder.
annotationHolder may be depending on annotation style:
-
property itself self
-
getter for the property
162 163 164 165 166 167 168 |
# File 'lib/ontomde-uml2-jpa/mapping.rb', line 162 def jpa_addPersistenceTo!(ah) if umlx_isAttribute? jpa_addPersistenceToAttribute!(ah) else jpa_addPersistenceToAssociation!(ah) end end |
#jpa_addPersistenceToAssociation!(ah) ⇒ Object
185 186 187 188 189 190 191 192 193 |
# File 'lib/ontomde-uml2-jpa/mapping.rb', line 185 def jpa_addPersistenceToAssociation!(ah) oe=umlx_otherEnd binav=(!oe.nil?) && oe.umlx_isNavigable? if binav jpa_addPersistenceToAssociationBidir!(ah) else jpa_addPersistenceToAssociationUnidir!(ah) end end |
#jpa_addPersistenceToAssociationBidir!(ah) ⇒ Object
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 |
# File 'lib/ontomde-uml2-jpa/mapping.rb', line 210 def jpa_addPersistenceToAssociationBidir!(ah) toOne=umlx_upperValueIsOne? fromOne=umlx_otherEnd.nil? ? true : umlx_otherEnd.umlx_upperValueIsOne? master=umlx_masterEnd? if fromOne && toOne && (master) jpa_addPersistenceBidirOneToOneMaster!(ah) elsif fromOne && toOne && (!master) jpa_addPersistenceBidirOneToOneSlave!(ah) elsif fromOne && !toOne && (master) jpa_addPersistenceBidirOneToManyMaster!(ah) elsif fromOne && !toOne && (!master) jpa_addPersistenceBidirOneToManySlave!(ah) elsif !fromOne && toOne && (master) jpa_addPersistenceBidirManyToOneMaster!(ah) elsif !fromOne && toOne && (!master) jpa_addPersistenceBidirManyToOneSlave!(ah) elsif !fromOne && !toOne && (master) jpa_addPersistenceBidirManyToManyMaster!(ah) elsif !fromOne && !toOne && (!master) jpa_addPersistenceBidirManyToManySlave!(ah) else raise Warning.new("Internal error") end return # if umlx_oneToOne? # if umlx_otherEnd.nil? || !umlx_otherEnd.umlx_isNavigable? # jpa_addPersistenceUnidirOneToOne!(ah) # #ah.java_annotation_add("@OneToOne") # # elsif umlx_masterEnd? # ah.java_annotation_add("@OneToOne(cascade = {CascadeType.MERGE, CascadeType.REFRESH, CascadeType.PERSIST, CascadeType.REMOVE})") # ah.java_annotation_add("@JoinColumn(name=\"#{umlx_otherEnd.java_NameBean}_fk\")") # elsif # ah.java_annotation_add("@OneToOne(mappedBy=\"#{umlx_otherEnd.java_NameProperty}\")") # end # end # if umlx_manyToOne? # if umlx_unidirectionnel? # ah.java_annotation_add("//TOFIX MANY TO ONE Unideirectionnel NOT IMPLEMENTED") # elsif # ah.java_annotation_add("@ManyToOne") # ah.java_annotation_add("@JoinColumn(name=\"#{umlx_otherEnd.java_NameBean}_fk\")") # end # end end |
#jpa_addPersistenceToAssociationUnidir!(ah) ⇒ Object
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 |
# File 'lib/ontomde-uml2-jpa/mapping.rb', line 195 def jpa_addPersistenceToAssociationUnidir!(ah) toOne=umlx_upperValueIsOne? fromOne=umlx_otherEnd.nil? ? true : umlx_otherEnd.umlx_upperValueIsOne? if fromOne && toOne jpa_addPersistenceUnidirOneToOne!(ah) elsif fromOne && !toOne jpa_addPersistenceUnidirOneToMany!(ah) elsif !fromOne && toOne jpa_addPersistenceUnidirManyToOne!(ah) elsif !fromOne && !toOne jpa_addPersistenceUnidirManyToMany!(ah) else raise Warning.new("Internal error") end end |
#jpa_addPersistenceToAttribute!(ah) ⇒ Object
170 171 172 173 174 175 176 177 178 |
# File 'lib/ontomde-uml2-jpa/mapping.rb', line 170 def jpa_addPersistenceToAttribute!(ah) jpa_addPersistenceToAttribute_TypeModificator!(ah) if umlx_upperValueIsOne? jpa_addPersistenceOneAttribute!(ah) else jpa_addPersistenceManyAttribute!(ah) end return end |
#jpa_addPersistenceToAttribute_TypeModificator!(ah) ⇒ Object
180 181 182 183 |
# File 'lib/ontomde-uml2-jpa/mapping.rb', line 180 def jpa_addPersistenceToAttribute_TypeModificator!(ah) tpl=JavaMapping.instance.getTemplate(self.uml_type_one) tpl.jpa_addTypeModificator(ah) end |
#jpa_addPersistenceUnidirManyToMany!(ah) ⇒ Object
66 67 68 69 70 |
# File 'lib/ontomde-uml2-jpa/mapping.rb', line 66 def jpa_addPersistenceUnidirManyToMany!(ah) ah.java_annotation_add("@ManyToMany #{jpa_addRelationCascadeType(false)} /*TPL:105*/") jpa_addJoinTable(ah) jpa_addJoinColumn!(ah) end |
#jpa_addPersistenceUnidirManyToOne!(ah) ⇒ Object
61 62 63 64 |
# File 'lib/ontomde-uml2-jpa/mapping.rb', line 61 def jpa_addPersistenceUnidirManyToOne!(ah) ah.java_annotation_add("@ManyToOne #{jpa_addRelationCascadeType(false)} /*TPL:104*/") jpa_addJoinColumn!(ah) end |
#jpa_addPersistenceUnidirOneToMany!(ah) ⇒ Object
55 56 57 58 |
# File 'lib/ontomde-uml2-jpa/mapping.rb', line 55 def jpa_addPersistenceUnidirOneToMany!(ah) ah.java_annotation_add(%{@OneToMany(fetch=FetchType.EAGER #{jpa_addRelationCascadeType(true)}) /*TPL:102*/}) jpa_addJoinTable(ah) end |
#jpa_addPersistenceUnidirOneToOne!(ah) ⇒ Object
49 50 51 52 53 |
# File 'lib/ontomde-uml2-jpa/mapping.rb', line 49 def jpa_addPersistenceUnidirOneToOne!(ah) #TODO: unicity constraint ah.java_annotation_add("@OneToOne(cascade=CascadeType.ALL) /*TPL: 101*/") #TODO: affiner cascadeType pour les delete end |
#jpa_addRelationCascadeType(isIncludeType = true) ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/ontomde-uml2-jpa/mapping.rb', line 42 def jpa_addRelationCascadeType(isIncludeType=true) if (isIncludeType) return DEFAULT_CASCADE_I else return DEFAULT_CASCADE end end |
#jpa_isPersistent? ⇒ Boolean
461 462 463 464 |
# File 'lib/ontomde-uml2-jpa/jpa.rb', line 461 def jpa_isPersistent? return false if uml_isDerived? return true end |