ontomde-uml2-jpa 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.txt +5 -0
- data/Manifest.txt +15 -0
- data/README.txt +41 -0
- data/Rakefile +21 -0
- data/lib/ontomde-uml2-jpa/configuration.rb +176 -0
- data/lib/ontomde-uml2-jpa/finder.rb +72 -0
- data/lib/ontomde-uml2-jpa/jpa.rb +483 -0
- data/lib/ontomde-uml2-jpa/jpa.rdoc +20 -0
- data/lib/ontomde-uml2-jpa/locking.rb +17 -0
- data/lib/ontomde-uml2-jpa/mapping.rb +277 -0
- data/lib/ontomde-uml2-jpa/redefined.rb +75 -0
- data/lib/ontomde-uml2-jpa/simulationAutoImplement.rb +54 -0
- data/lib/ontomde-uml2-jpa/version.rb +8 -0
- data/lib/ontomde-uml2-jpa.rb +21 -0
- data/test/test_ontomde-uml2-jpa.rb +0 -0
- metadata +87 -0
data/History.txt
ADDED
data/Manifest.txt
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
History.txt
|
2
|
+
Manifest.txt
|
3
|
+
README.txt
|
4
|
+
Rakefile
|
5
|
+
lib/ontomde-uml2-jpa.rb
|
6
|
+
lib/ontomde-uml2-jpa/version.rb
|
7
|
+
lib/ontomde-uml2-jpa/configuration.rb
|
8
|
+
lib/ontomde-uml2-jpa/redefined.rb
|
9
|
+
lib/ontomde-uml2-jpa/locking.rb
|
10
|
+
lib/ontomde-uml2-jpa/mapping.rb
|
11
|
+
lib/ontomde-uml2-jpa/finder.rb
|
12
|
+
lib/ontomde-uml2-jpa/simulationAutoImplement.rb
|
13
|
+
lib/ontomde-uml2-jpa/jpa.rb
|
14
|
+
lib/ontomde-uml2-jpa/jpa.rdoc
|
15
|
+
test/test_ontomde-uml2-jpa.rb
|
data/README.txt
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
ontomde-uml2-jpa
|
2
|
+
by stephane (Pierre) Carrie
|
3
|
+
http://ontomde.rubyforge.org
|
4
|
+
|
5
|
+
== DESCRIPTION:
|
6
|
+
|
7
|
+
JPA annotation generator library.
|
8
|
+
|
9
|
+
Most users will used this library trough ontomde-java-frontend command line utility options.
|
10
|
+
|
11
|
+
== FEATURES/PROBLEMS:
|
12
|
+
|
13
|
+
== SYNOPSIS:
|
14
|
+
|
15
|
+
== REQUIREMENTS:
|
16
|
+
|
17
|
+
== INSTALL:
|
18
|
+
|
19
|
+
* (win) gem install ontomde-uml2-jpa
|
20
|
+
* (unix) sudo gem install ontomde-uml2-jpa
|
21
|
+
|
22
|
+
Additional information is available on ontoMDE web site :
|
23
|
+
http://ontomde.rubyforge.org/website/download.html
|
24
|
+
== LICENSE:
|
25
|
+
|
26
|
+
Copyright (C) 2008 Orange-labs
|
27
|
+
38 rue General Leclerc
|
28
|
+
92130 ISSY LES MOULINEAUX, France
|
29
|
+
|
30
|
+
This program is free software: you can redistribute it and/or modify
|
31
|
+
it under the terms of the GNU Affero General Public License as
|
32
|
+
published by the Free Software Foundation, either version 3 of the
|
33
|
+
License, or (at your option) any later version.
|
34
|
+
|
35
|
+
This program is distributed in the hope that it will be useful,
|
36
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
37
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
38
|
+
GNU Affero General Public License for more details.
|
39
|
+
|
40
|
+
You should have received a copy of the GNU Affero General Public License
|
41
|
+
along with this program. If not, see http://www.gnu.org/licenses/.
|
data/Rakefile
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'hoe'
|
5
|
+
require './lib/ontomde-uml2-jpa/version.rb'
|
6
|
+
|
7
|
+
Hoe.new('ontomde-uml2-jpa', Ontomde::Uml2::Jpa::VERSION) do |p|
|
8
|
+
p.rubyforge_name = 'ontomde'
|
9
|
+
p.author = 'Stephane (Pierre) Carrie'
|
10
|
+
p.email = 'stephanepierre.carrie@orange-ftgroup.com'
|
11
|
+
p.summary = 'OntoMDE JPA cartridge'
|
12
|
+
p.description = p.paragraphs_of('README.txt', 2..5).join("\n\n")
|
13
|
+
p.url="http://ontomde.rubyforge.org"
|
14
|
+
p.changes = p.paragraphs_of('History.txt', 0..1).join("\n\n")
|
15
|
+
p.extra_deps=[
|
16
|
+
['ontomde-uml2-java',"= #{Ontomde::Uml2::Jpa::VERSION}"]
|
17
|
+
]
|
18
|
+
p.spec_extras={ :required_ruby_version => '>=1.8.6',:required_rubygems_version => '>=1.0.0' }
|
19
|
+
end
|
20
|
+
|
21
|
+
# vim: syntax=Ruby
|
@@ -0,0 +1,176 @@
|
|
1
|
+
module Mrdf_Model
|
2
|
+
|
3
|
+
#Generates persistence configuration file
|
4
|
+
def db_generateConfiguration
|
5
|
+
jpa_generateConfiguration
|
6
|
+
end
|
7
|
+
|
8
|
+
#Generates hibernate configuration file
|
9
|
+
def jpa_generateConfiguration
|
10
|
+
if context[:struts_useSpring]
|
11
|
+
mtk_writeSession("#{context[:jpaConfigDir,context[:javaDir]]}/META-INF/persistence.xml") {
|
12
|
+
jpa_writeConfigurationForSpring
|
13
|
+
}
|
14
|
+
else
|
15
|
+
# empty
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
def jpa_writeConfigurationForSpring
|
21
|
+
write %{<?xml version="1.0" encoding="UTF-8"?>
|
22
|
+
<!-- This configuration file is for a spring enabled application. -->
|
23
|
+
<!-- For database settings, please see ApplicationContext-jpa.xml -->
|
24
|
+
|
25
|
+
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
|
26
|
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
27
|
+
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
|
28
|
+
version="1.0">
|
29
|
+
#{mtk_stss{jpa_writeWebAppConfiguration}}
|
30
|
+
|
31
|
+
#{mtk_stss{jpa_writeDeploymentConfiguration}}
|
32
|
+
</persistence>
|
33
|
+
}
|
34
|
+
end
|
35
|
+
|
36
|
+
def jpa_writeWebAppConfiguration
|
37
|
+
write %{
|
38
|
+
<persistence-unit name="persistence-unit-test"
|
39
|
+
transaction-type="RESOURCE_LOCAL">
|
40
|
+
<provider>org.hibernate.ejb.HibernatePersistence</provider>
|
41
|
+
#{mtk_stss{jpa_writeConfigurationPersistentClasses}}
|
42
|
+
<properties>
|
43
|
+
#{mtk_stss{jpa_writeOptimizedHibernateProperties}}
|
44
|
+
</properties>
|
45
|
+
</persistence-unit>
|
46
|
+
}
|
47
|
+
end
|
48
|
+
|
49
|
+
def jpa_writeDeploymentConfiguration
|
50
|
+
write %{
|
51
|
+
<!-- This persistence unit is used only by hibernateTools in "deployBD.xml"
|
52
|
+
to generate tables. -->
|
53
|
+
<persistence-unit name="deployment-persistence-unit"
|
54
|
+
transaction-type="RESOURCE_LOCAL">
|
55
|
+
<provider>org.hibernate.ejb.HibernatePersistence</provider>
|
56
|
+
#{mtk_stss{jpa_writeConfigurationPersistentClasses}}
|
57
|
+
<properties>
|
58
|
+
#{mtk_stss{jpa_writeDBConnectionParameters}}
|
59
|
+
</properties>
|
60
|
+
</persistence-unit>
|
61
|
+
}
|
62
|
+
end
|
63
|
+
|
64
|
+
|
65
|
+
|
66
|
+
#writes jpa configuration file to current
|
67
|
+
def jpa_writeConfigurationStandard
|
68
|
+
write %{<?xml version="1.0" encoding="UTF-8"?>
|
69
|
+
<persistence
|
70
|
+
xmlns="http://java.sun.com/xml/ns/persistence"
|
71
|
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
72
|
+
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
|
73
|
+
version="1.0">
|
74
|
+
<persistence-unit
|
75
|
+
name="persistence-unit-test"
|
76
|
+
transaction-type="RESOURCE_LOCAL"
|
77
|
+
>
|
78
|
+
}
|
79
|
+
jpa_writeConfigurationPersistentClasses
|
80
|
+
|
81
|
+
write %{<properties>\n}
|
82
|
+
jpa_writeDBConnectionParameters
|
83
|
+
jpa_writeConnectionPool
|
84
|
+
write %{
|
85
|
+
<!-- Echo all executed SQL to stdout -->
|
86
|
+
<property name="hibernate.show_sql" value="false"/>
|
87
|
+
<!-- recreate schema ? validate | update | create | create-drop -->
|
88
|
+
<property name="hibernate.hbm2ddl.auto" value="#{context[:jpa_ddl_mode,"update"]}"/>
|
89
|
+
}
|
90
|
+
|
91
|
+
write %{</properties>\n</persistence-unit>\n</persistence>\n}
|
92
|
+
end
|
93
|
+
|
94
|
+
#writes configuration parameter for hibernate sgbd connection.
|
95
|
+
#Some parameter are extracted from context.
|
96
|
+
def jpa_default_db_url
|
97
|
+
#name=umlx_model.uml_name_one.tr('^a-zA-Z0-9','_')
|
98
|
+
return %{jdbc:mysql:///#{context[:db_schema_name,"testschema"]}}
|
99
|
+
end
|
100
|
+
def jpa_writeDBConnectionParameters
|
101
|
+
write %{<!-- TPL:HIB-2001 -->
|
102
|
+
<property name="hibernate.dialect" value="#{context[:hib_dialect,"org.hibernate.dialect.MySQL5InnoDBDialect"]}"/>
|
103
|
+
<property name="hibernate.connection.driver_class" value="#{context[:hib_connection_driver_class,"com.mysql.jdbc.Driver"]}"/>
|
104
|
+
<property name="hibernate.connection.url" value="#{context[:hib_connection_url,jpa_default_db_url]}"/>
|
105
|
+
<property name="hibernate.connection.username" value="#{context[:hib_connection_username,"testuser"]}"/>
|
106
|
+
<property name="hibernate.connection.password" value="#{context[:hib_connection_password,"testpwd"]}"/>
|
107
|
+
<!--
|
108
|
+
<property name="hibernate.connection.driver_class" value="org.hsqldb.jdbcDriver"/>
|
109
|
+
<property name="hibernate.connection.username" value="sa"/>
|
110
|
+
<property name="hibernate.connection.password" value=""/>
|
111
|
+
<property name="hibernate.connection.url" value="jdbc:hsqldb:hsql://localhost:1701"/>
|
112
|
+
<property name="hibernate.hbm2ddl.auto" value="update"/>
|
113
|
+
<property name="hibernate.cache.provider_class" value="org.hibernate.cache.HashtableCacheProvider"/>
|
114
|
+
-->
|
115
|
+
}
|
116
|
+
end
|
117
|
+
|
118
|
+
|
119
|
+
def jpa_writeOptimizedHibernateProperties
|
120
|
+
write %{
|
121
|
+
<property name="hibernate.show_sql" value="false" />
|
122
|
+
<property name="hibernate.hbm2ddl.auto" value="update" />
|
123
|
+
|
124
|
+
<!-- Set a maximum "depth" for the outer join fetch tree for single-ended associations (one-to-one, many-to-one) -->
|
125
|
+
<property name="hibernate.max_fetch_depth" value="0" />
|
126
|
+
|
127
|
+
<!-- determines the JDBC fetch size (calls Statement.setFetchSize()) -->
|
128
|
+
<property name="hibernate.jdbc.fetch_size" value="4" />
|
129
|
+
|
130
|
+
<!-- makes Hibernate start faster (it does not try to build cglib-enhanced objects to access getter/setters) -->
|
131
|
+
<property name="hibernate.bytecode.use_reflection_optimizer" value="false" />
|
132
|
+
}
|
133
|
+
end
|
134
|
+
|
135
|
+
#writes configuration parameter for hibernate connection pool.
|
136
|
+
def jpa_writeConnectionPool
|
137
|
+
write %{
|
138
|
+
<!-- connection pool -->
|
139
|
+
<!-- cf: http://www.hibernate.org/214.html -->
|
140
|
+
<property name="hibernate.c3p0.min_size" value="5"/>
|
141
|
+
<property name="hibernate.c3p0.max_size" value="20"/>
|
142
|
+
<property name="hibernate.c3p0.timeout" value="1800"/> <!-- seconds -->
|
143
|
+
<property name="hibernate.c3p0.idle_test_period" value="100"/> <!-- seconds -->
|
144
|
+
<property name="hibernate.c3p0.max_statement" value="50"/>
|
145
|
+
}
|
146
|
+
end
|
147
|
+
|
148
|
+
#writes jpa configuration list of persistent class
|
149
|
+
def jpa_writeConfigurationPersistentClasses
|
150
|
+
write %{<!-- begin Persistent classes declaration -->\n}
|
151
|
+
uml_Class_all.each {|c|
|
152
|
+
next unless c.kind_of?(Muml_Class) && c.umlx_isReallyAClass?
|
153
|
+
c.jpa_writeConfiguration
|
154
|
+
}
|
155
|
+
#TODO: remove hack
|
156
|
+
# context[:db_additionalPersistentClass,["com.jbpm.wrapper.process.Process"]].each { |cl|
|
157
|
+
# write %{<class>#{cl}</class>\n}
|
158
|
+
# }
|
159
|
+
write %{<exclude-unlisted-classes>true</exclude-unlisted-classes>\n}
|
160
|
+
write %{<!-- end Persistent classes declaration -->\n}
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
module Muml_Class
|
165
|
+
#
|
166
|
+
#writes jpa entry for this class if this class is persistent.
|
167
|
+
def jpa_writeConfiguration()
|
168
|
+
ignoreExternal=false
|
169
|
+
return if java_ignoreMe?(ignoreExternal)
|
170
|
+
return unless umlx_owner_one.kind_of?(Muml_Package)
|
171
|
+
return unless jpa_isPersistent?
|
172
|
+
return if db_isTransient?
|
173
|
+
write %{<class>#{java_qualifiedName}</class>\n}
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
@@ -0,0 +1,72 @@
|
|
1
|
+
module Muml_Class
|
2
|
+
#adds a finder to eao
|
3
|
+
#self is supposed to be the bean and eao the "dao".
|
4
|
+
def jpa_addFindAll!(eao)
|
5
|
+
# java_NameBean is added to avoid name clash with inheritance
|
6
|
+
m=eao.umlx_createAndAddOperation(rdf_uri+"_findAll","findAll")#+self.java_NameBean)
|
7
|
+
m.uml_isStatic=RDF_TRUE
|
8
|
+
#m.uml_class=self
|
9
|
+
m.uml_visibility=Cuml_VisibilityKind::Public
|
10
|
+
#m.uml_isStatic=RDF_TRUE
|
11
|
+
|
12
|
+
#em=m.umlx_createAndAddParameter(m.rdf_uri+"_entityManager","entityManager")
|
13
|
+
#em.uml_type=umlx_getOrCreateClass(JPA::EntityManager)
|
14
|
+
#em.uml_direction=Cuml_ParameterDirectionKind::In
|
15
|
+
#em.uml_upperValue=umlx_literal(1)
|
16
|
+
#em.uml_lowerValue=umlx_literal(1)
|
17
|
+
|
18
|
+
rp=m.umlx_createAndAddParameter(m.rdf_uri+"_ret_param","return")
|
19
|
+
rp.uml_direction=Cuml_ParameterDirectionKind::Return
|
20
|
+
rp.uml_upperValue=umlx_literal(-1)
|
21
|
+
rp.uml_lowerValue=umlx_literal(0)
|
22
|
+
rp.uml_type=self
|
23
|
+
rp.uml_isOrdered=RDF_TRUE
|
24
|
+
|
25
|
+
#m.java_code="return (#{self.java_qualifiedName})entityManager.find( #{self.java_qualifiedName}.class, #{ip.uml_name});"
|
26
|
+
|
27
|
+
m.java_code=%{return (java.util.List<#{self.java_qualifiedName}>) getEntityManager().createQuery( "select Object(c) from #{java_Name} as c").getResultList();}
|
28
|
+
m.java_annotation_add(%{@SuppressWarnings("unchecked")})
|
29
|
+
|
30
|
+
# because A<-B is not Set<A> <- Set<B>
|
31
|
+
# we need to have an extra parameter
|
32
|
+
# so method overloading is OK.
|
33
|
+
# (this is not necessary when A is return)
|
34
|
+
|
35
|
+
if context[:db_useExtraTypeParameterForFindAll]
|
36
|
+
t=m.umlx_createAndAddParameter(m.rdf_uri+"_class","nullCast")
|
37
|
+
t.uml_type=self
|
38
|
+
end
|
39
|
+
return m
|
40
|
+
end
|
41
|
+
def jpa_addFindByPrimaryKey!(eao)
|
42
|
+
m=eao.umlx_createAndAddOperation(rdf_uri+"_finderop","find")
|
43
|
+
m.uml_isStatic=RDF_TRUE
|
44
|
+
#m.uml_class=self
|
45
|
+
m.uml_visibility=Cuml_VisibilityKind::Public
|
46
|
+
#m.uml_isStatic=RDF_TRUE
|
47
|
+
|
48
|
+
#em=m.umlx_createAndAddParameter(m.rdf_uri+"_entityManager","entityManager")
|
49
|
+
#em.uml_type=umlx_getOrCreateClass(JPA::EntityManager)
|
50
|
+
#em.uml_direction=Cuml_ParameterDirectionKind::In
|
51
|
+
#em.uml_upperValue=umlx_literal(1)
|
52
|
+
#em.uml_lowerValue=umlx_literal(1)
|
53
|
+
|
54
|
+
ip=m.umlx_createAndAddParameter(m.rdf_uri+"_id_param","primaryKey")
|
55
|
+
ip.uml_direction=Cuml_ParameterDirectionKind::In
|
56
|
+
ip.uml_upperValue=umlx_literal(1)
|
57
|
+
ip.uml_lowerValue=umlx_literal(1)
|
58
|
+
ip.uml_type=umlx_dataType_long
|
59
|
+
#ip.uml_isOrdered=RDF_FALSE
|
60
|
+
|
61
|
+
rp=m.umlx_createAndAddParameter(m.rdf_uri+"_ret_param","return")
|
62
|
+
rp.uml_direction=Cuml_ParameterDirectionKind::Return
|
63
|
+
rp.uml_upperValue=umlx_literal(1)
|
64
|
+
rp.uml_lowerValue=umlx_literal(0)
|
65
|
+
rp.uml_type=self
|
66
|
+
#rp.uml_isOrdered=RDF_FALSE
|
67
|
+
|
68
|
+
m.java_code="return (#{self.java_qualifiedName})getEntityManager().find( #{self.java_qualifiedName}.class, #{ip.uml_name});"
|
69
|
+
|
70
|
+
return m
|
71
|
+
end
|
72
|
+
end
|