Module: Mrdf_Model
- Defined in:
- lib/ontomde-uml2-jpa/simulationAutoImplement.rb,
lib/ontomde-uml2-jpa/jpa.rb,
lib/ontomde-uml2-jpa/jpa.rb,
lib/ontomde-uml2-jpa/configuration.rb
Overview
automatically populate methods with simulated code. Methods will return an element or a liste of element of the specified type.
Instance Method Summary collapse
- #db_addDAO! ⇒ Object
- #db_addPersistence! ⇒ Object
- #db_addTestImplementations! ⇒ Object
- #db_Class_persistent ⇒ Object
- #db_findNameUsingDB_URI_ALIAS(k) ⇒ Object
-
#db_generateConfiguration ⇒ Object
Generates persistence configuration file.
- #db_saveDB_DISCRIMINATOR ⇒ Object
- #jpa_addPersistence! ⇒ Object
- #jpa_addTestImplementations! ⇒ Object
- #jpa_copyInterfaceAttributesToClass! ⇒ Object
-
#jpa_default_db_url ⇒ Object
writes configuration parameter for hibernate sgbd connection.
-
#jpa_generateConfiguration ⇒ Object
Generates hibernate configuration file.
- #jpa_writeConfigurationForSpring ⇒ Object
-
#jpa_writeConfigurationPersistentClasses ⇒ Object
writes jpa configuration list of persistent class.
-
#jpa_writeConfigurationStandard ⇒ Object
writes jpa configuration file to current.
-
#jpa_writeConnectionPool ⇒ Object
writes configuration parameter for hibernate connection pool.
- #jpa_writeDBConnectionParameters ⇒ Object
- #jpa_writeDeploymentConfiguration ⇒ Object
- #jpa_writeOptimizedHibernateProperties ⇒ Object
- #jpa_writeWebAppConfiguration ⇒ Object
Instance Method Details
#db_addDAO! ⇒ Object
80 81 82 83 84 |
# File 'lib/ontomde-uml2-jpa/jpa.rb', line 80 def db_addDAO! db_Class_persistent.each { |c| c.jpa_addDAO! } end |
#db_addPersistence! ⇒ Object
31 32 33 |
# File 'lib/ontomde-uml2-jpa/jpa.rb', line 31 def db_addPersistence! jpa_addPersistence! end |
#db_addTestImplementations! ⇒ Object
7 8 9 |
# File 'lib/ontomde-uml2-jpa/simulationAutoImplement.rb', line 7 def db_addTestImplementations! jpa_addTestImplementations! end |
#db_Class_persistent ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/ontomde-uml2-jpa/jpa.rb', line 34 def db_Class_persistent ret=Set.new uml_Class_all.each { |c| next if c.kind_of?(Muml_Interface) || c.kind_of?(Muml_Enumeration) next unless c.kind_of?(Muml_Class) if context[:db_useStereotypeMarker,false] c.db_isTransient=((c.umlx_hasStereotype?(context[:db_persistentStereotype,'Persistent'])) ? RDF_FALSE : RDF_TRUE) end next if c.db_isTransient? if c.umlx_package.nil? log.error("no package for #{c}::#{c.class.name} #{c.rdf_uri}. Skipping addPersistence!") next end ret<< c } return ret end |
#db_findNameUsingDB_URI_ALIAS(k) ⇒ Object
177 178 179 180 181 182 183 184 185 186 187 188 |
# File 'lib/ontomde-uml2-jpa/jpa.rb', line 177 def db_findNameUsingDB_URI_ALIAS(k) n="-- key not found for #{k}--" if self[k].nil? # an uri present in old file no longer exists ::Muml_Class::DB_URI_ALIAS.each {|key,v| n=key if v==k } else n=self[k].java_qualifiedName end return n end |
#db_generateConfiguration ⇒ Object
Generates persistence configuration file
4 5 6 |
# File 'lib/ontomde-uml2-jpa/configuration.rb', line 4 def db_generateConfiguration jpa_generateConfiguration end |
#db_saveDB_DISCRIMINATOR ⇒ Object
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 |
# File 'lib/ontomde-uml2-jpa/jpa.rb', line 190 def db_saveDB_DISCRIMINATOR return unless context[:dbTypeDiscriminator]==:int mtk_writeSession("#{context[:dbDiscriminatorCacheRelFile]}") { write <<END # saved discriminator numbers # This file is read and rewritten by generator def declarePredefinedDiscrimators() # first parameter is java qualified class name # second parameter is the identifier used in database # when different java type are stored in a # single table and need to be differenciated. END ::Muml_Class::DB_DISCRIMINATOR.sort{|a,b| a[1]<=>b[1]}.each { |k| n=db_findNameUsingDB_URI_ALIAS(k[0]) write(%{ db_disc("#{n}",#{k[1]})\n}) } write("end\n") write <<END # ########################### # END OF USER MODIFIABLE ZONE # ########################### # Conversion to model URI def db_disc(k,v) ::Muml_Class::DB_DISCRIMINATOR[::Muml_Class::DB_URI_ALIAS[k]]=v end ::Muml_Class::DB_URI_ALIAS.merge!({ END ::Muml_Class::DB_DISCRIMINATOR.sort{|a,b| a[0]<=>b[0]}.each { |k| n=db_findNameUsingDB_URI_ALIAS(k[0]) write(" %{#{n}} => %{#{k[0]}} ,\n") } write("})\n") write <<END declarePredefinedDiscrimators(); #free ressources def declarePredefinedDiscrimators() end END } end |
#jpa_addPersistence! ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/ontomde-uml2-jpa/jpa.rb', line 51 def jpa_addPersistence! #jpa_copyInterfaceAttributesToClass! uml_Class_all.each { |c| next unless c.kind_of?(Muml_Interface) || c.kind_of?(Muml_Enumeration) c.db_isTransient=RDF_TRUE } db_Class_persistent.each { |c| c.jpa_addPersistence!() c.jpa_addPersistenceId! c.jpa_addOptimisticLockingVar! } uml_Class_all.each { |i| #TODO ??? next unless i.kind_of?(Muml_Interface) i.jpa_addPersistenceId! #c.jpa_addOptimisticLockingVar! } end |
#jpa_addTestImplementations! ⇒ Object
10 11 12 13 14 15 |
# File 'lib/ontomde-uml2-jpa/simulationAutoImplement.rb', line 10 def jpa_addTestImplementations! each { |k,m| next unless m.kind_of?(Muml_Operation) m.jpa_addTestImplementation! } end |
#jpa_copyInterfaceAttributesToClass! ⇒ Object
71 72 73 74 75 76 77 78 79 |
# File 'lib/ontomde-uml2-jpa/jpa.rb', line 71 def jpa_copyInterfaceAttributesToClass! uml_Class_all.each { |c| next unless c.kind_of?(Muml_Interface) puts "found interface #{c}" c.uml_ownedAttribute.each { |a| puts "found attribute #{a.uml_name}" } } end |
#jpa_default_db_url ⇒ Object
writes configuration parameter for hibernate sgbd connection. Some parameter are extracted from context.
96 97 98 99 |
# File 'lib/ontomde-uml2-jpa/configuration.rb', line 96 def jpa_default_db_url #name=umlx_model.uml_name_one.tr('^a-zA-Z0-9','_') return %{jdbc:mysql:///#{context[:db_schema_name,"testschema"]}} end |
#jpa_generateConfiguration ⇒ Object
Generates hibernate configuration file
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/ontomde-uml2-jpa/configuration.rb', line 9 def jpa_generateConfiguration if context[:struts_useSpring] mtk_writeSession("#{context[:jpaConfigDir,context[:javaDir]]}/META-INF/persistence.xml") { jpa_writeConfigurationForSpring } else # empty end end |
#jpa_writeConfigurationForSpring ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/ontomde-uml2-jpa/configuration.rb', line 20 def jpa_writeConfigurationForSpring write %{<?xml version="1.0" encoding="UTF-8"?> <!-- This configuration file is for a spring enabled application. --> <!-- For database settings, please see ApplicationContext-jpa.xml --> <persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd" version="1.0"> #{mtk_stss{jpa_writeWebAppConfiguration}} #{mtk_stss{jpa_writeDeploymentConfiguration}} </persistence> } end |
#jpa_writeConfigurationPersistentClasses ⇒ Object
writes jpa configuration list of persistent class
149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/ontomde-uml2-jpa/configuration.rb', line 149 def jpa_writeConfigurationPersistentClasses write %{<!-- begin Persistent classes declaration -->\n} uml_Class_all.each {|c| next unless c.kind_of?(Muml_Class) && c.umlx_isReallyAClass? c.jpa_writeConfiguration } #TODO: remove hack # context[:db_additionalPersistentClass,["com.jbpm.wrapper.process.Process"]].each { |cl| # write %{<class>#{cl}</class>\n} # } write %{<exclude-unlisted-classes>true</exclude-unlisted-classes>\n} write %{<!-- end Persistent classes declaration -->\n} end |
#jpa_writeConfigurationStandard ⇒ Object
writes jpa configuration file to current
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 |
# File 'lib/ontomde-uml2-jpa/configuration.rb', line 67 def jpa_writeConfigurationStandard write %{<?xml version="1.0" encoding="UTF-8"?> <persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd" version="1.0"> <persistence-unit name="persistence-unit-test" transaction-type="RESOURCE_LOCAL" > } jpa_writeConfigurationPersistentClasses write %{<properties>\n} jpa_writeDBConnectionParameters jpa_writeConnectionPool write %{ <!-- Echo all executed SQL to stdout --> <property name="hibernate.show_sql" value="false"/> <!-- recreate schema ? validate | update | create | create-drop --> <property name="hibernate.hbm2ddl.auto" value="#{context[:jpa_ddl_mode,"update"]}"/> } write %{</properties>\n</persistence-unit>\n</persistence>\n} end |
#jpa_writeConnectionPool ⇒ Object
writes configuration parameter for hibernate connection pool.
136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/ontomde-uml2-jpa/configuration.rb', line 136 def jpa_writeConnectionPool write %{ <!-- connection pool --> <!-- cf: http://www.hibernate.org/214.html --> <property name="hibernate.c3p0.min_size" value="5"/> <property name="hibernate.c3p0.max_size" value="20"/> <property name="hibernate.c3p0.timeout" value="1800"/> <!-- seconds --> <property name="hibernate.c3p0.idle_test_period" value="100"/> <!-- seconds --> <property name="hibernate.c3p0.max_statement" value="50"/> } end |
#jpa_writeDBConnectionParameters ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/ontomde-uml2-jpa/configuration.rb', line 100 def jpa_writeDBConnectionParameters write %{<!-- TPL:HIB-2001 --> <property name="hibernate.dialect" value="#{context[:hib_dialect,"org.hibernate.dialect.MySQL5InnoDBDialect"]}"/> <property name="hibernate.connection.driver_class" value="#{context[:hib_connection_driver_class,"com.mysql.jdbc.Driver"]}"/> <property name="hibernate.connection.url" value="#{context[:hib_connection_url,jpa_default_db_url]}"/> <property name="hibernate.connection.username" value="#{context[:hib_connection_username,"testuser"]}"/> <property name="hibernate.connection.password" value="#{context[:hib_connection_password,"testpwd"]}"/> <!-- <property name="hibernate.connection.driver_class" value="org.hsqldb.jdbcDriver"/> <property name="hibernate.connection.username" value="sa"/> <property name="hibernate.connection.password" value=""/> <property name="hibernate.connection.url" value="jdbc:hsqldb:hsql://localhost:1701"/> <property name="hibernate.hbm2ddl.auto" value="update"/> <property name="hibernate.cache.provider_class" value="org.hibernate.cache.HashtableCacheProvider"/> --> } end |
#jpa_writeDeploymentConfiguration ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/ontomde-uml2-jpa/configuration.rb', line 49 def jpa_writeDeploymentConfiguration write %{ <!-- This persistence unit is used only by hibernateTools in "deployBD.xml" to generate tables. --> <persistence-unit name="deployment-persistence-unit" transaction-type="RESOURCE_LOCAL"> <provider>org.hibernate.ejb.HibernatePersistence</provider> #{mtk_stss{jpa_writeConfigurationPersistentClasses}} <properties> #{mtk_stss{jpa_writeDBConnectionParameters}} </properties> </persistence-unit> } end |
#jpa_writeOptimizedHibernateProperties ⇒ Object
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/ontomde-uml2-jpa/configuration.rb', line 119 def jpa_writeOptimizedHibernateProperties write %{ <property name="hibernate.show_sql" value="false" /> <property name="hibernate.hbm2ddl.auto" value="update" /> <!-- Set a maximum "depth" for the outer join fetch tree for single-ended associations (one-to-one, many-to-one) --> <property name="hibernate.max_fetch_depth" value="0" /> <!-- determines the JDBC fetch size (calls Statement.setFetchSize()) --> <property name="hibernate.jdbc.fetch_size" value="4" /> <!-- makes Hibernate start faster (it does not try to build cglib-enhanced objects to access getter/setters) --> <property name="hibernate.bytecode.use_reflection_optimizer" value="false" /> } end |
#jpa_writeWebAppConfiguration ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/ontomde-uml2-jpa/configuration.rb', line 36 def jpa_writeWebAppConfiguration write %{ <persistence-unit name="persistence-unit-test" transaction-type="RESOURCE_LOCAL"> <provider>org.hibernate.ejb.HibernatePersistence</provider> #{mtk_stss{jpa_writeConfigurationPersistentClasses}} <properties> #{mtk_stss{jpa_writeOptimizedHibernateProperties}} </properties> </persistence-unit> } end |