Sandbox-commits
Threads by month
- ----- 2026 -----
- June
- May
- April
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
May 2013
- 3 participants
- 34 discussions
r629 - in nuiton-jpa: . nuiton-jpa-api nuiton-jpa-junit nuiton-jpa-templates nuiton-jpa-templates/src nuiton-jpa-templates/src/it nuiton-jpa-templates/src/it/magalie src src/site src/site/rst
by tchemit@users.nuiton.org 25 May '13
by tchemit@users.nuiton.org 25 May '13
25 May '13
Author: tchemit
Date: 2013-05-25 17:02:30 +0200 (Sat, 25 May 2013)
New Revision: 629
Url: http://nuiton.org/projects/sandbox/repository/revisions/629
Log:
- use magalie model as a first it
- fix pom (nearly ready to be a full project)
Added:
nuiton-jpa/nuiton-jpa-templates/src/it/
nuiton-jpa/nuiton-jpa-templates/src/it/magalie/
nuiton-jpa/nuiton-jpa-templates/src/it/magalie/LICENSE.txt
nuiton-jpa/nuiton-jpa-templates/src/it/magalie/README.txt
nuiton-jpa/nuiton-jpa-templates/src/it/magalie/changelog.txt
nuiton-jpa/nuiton-jpa-templates/src/it/magalie/goals.txt
nuiton-jpa/nuiton-jpa-templates/src/it/magalie/pom.xml
nuiton-jpa/nuiton-jpa-templates/src/it/magalie/postbuild.groovy
nuiton-jpa/nuiton-jpa-templates/src/it/settings.xml
nuiton-jpa/src/
nuiton-jpa/src/site/
nuiton-jpa/src/site/rst/
nuiton-jpa/src/site/rst/index.rst
nuiton-jpa/src/site/site.xml
Modified:
nuiton-jpa/nuiton-jpa-api/pom.xml
nuiton-jpa/nuiton-jpa-junit/pom.xml
nuiton-jpa/nuiton-jpa-templates/pom.xml
nuiton-jpa/pom.xml
Modified: nuiton-jpa/nuiton-jpa-api/pom.xml
===================================================================
--- nuiton-jpa/nuiton-jpa-api/pom.xml 2013-05-25 14:13:01 UTC (rev 628)
+++ nuiton-jpa/nuiton-jpa-api/pom.xml 2013-05-25 15:02:30 UTC (rev 629)
@@ -12,6 +12,7 @@
<groupId>org.nuiton.jpa</groupId>
<artifactId>nuiton-jpa-api</artifactId>
+ <name>Nuiton Jpa :: API</name>
<dependencies>
Modified: nuiton-jpa/nuiton-jpa-junit/pom.xml
===================================================================
--- nuiton-jpa/nuiton-jpa-junit/pom.xml 2013-05-25 14:13:01 UTC (rev 628)
+++ nuiton-jpa/nuiton-jpa-junit/pom.xml 2013-05-25 15:02:30 UTC (rev 629)
@@ -12,6 +12,7 @@
<groupId>org.nuiton.jpa</groupId>
<artifactId>nuiton-jpa-junit</artifactId>
+ <name>Nuiton Jpa :: Junit</name>
<dependencies>
Modified: nuiton-jpa/nuiton-jpa-templates/pom.xml
===================================================================
--- nuiton-jpa/nuiton-jpa-templates/pom.xml 2013-05-25 14:13:01 UTC (rev 628)
+++ nuiton-jpa/nuiton-jpa-templates/pom.xml 2013-05-25 15:02:30 UTC (rev 629)
@@ -14,6 +14,7 @@
<groupId>org.nuiton.jpa</groupId>
<artifactId>nuiton-jpa-templates</artifactId>
+ <name>Nuiton Jpa :: Temlates</name>
<dependencies>
@@ -110,10 +111,52 @@
<version>${plexusPluginVersion}</version>
</plugin>
+ <plugin>
+ <artifactId>maven-invoker-plugin</artifactId>
+ <version>${invokerPluginVersion}</version>
+ </plugin>
+
</plugins>
</reporting>
</profile>
+
+ <profile>
+ <id>run-its</id>
+ <activation>
+ <property>
+ <name>skipIts</name>
+ <value>!true</value>
+ </property>
+ </activation>
+ <build>
+ <defaultGoal>integration-test</defaultGoal>
+ <plugins>
+ <plugin>
+ <artifactId>maven-invoker-plugin</artifactId>
+ <configuration>
+ <pomIncludes>
+ <pomInclude>*/pom.xml</pomInclude>
+ </pomIncludes>
+ <localRepositoryPath>${basedir}/target/local-repo</localRepositoryPath>
+ <settingsFile>src/it/settings.xml</settingsFile>
+ <cloneProjectsTo>${project.build.directory}/its</cloneProjectsTo>
+ </configuration>
+ <executions>
+ <execution>
+ <id>integration-test</id>
+ <goals>
+ <goal>install</goal>
+ <goal>run</goal>
+ </goals>
+ <phase>integration-test</phase>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+
</profiles>
</project>
Added: nuiton-jpa/nuiton-jpa-templates/src/it/magalie/LICENSE.txt
===================================================================
--- nuiton-jpa/nuiton-jpa-templates/src/it/magalie/LICENSE.txt (rev 0)
+++ nuiton-jpa/nuiton-jpa-templates/src/it/magalie/LICENSE.txt 2013-05-25 15:02:30 UTC (rev 629)
@@ -0,0 +1,166 @@
+ GNU LESSER GENERAL PUBLIC LICENSE
+ Version 3, 29 June 2007
+
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+
+ This version of the GNU Lesser General Public License incorporates
+the terms and conditions of version 3 of the GNU General Public
+License, supplemented by the additional permissions listed below.
+
+ 0. Additional Definitions.
+
+ As used herein, "this License" refers to version 3 of the GNU Lesser
+General Public License, and the "GNU GPL" refers to version 3 of the GNU
+General Public License.
+
+ "The Library" refers to a covered work governed by this License,
+other than an Application or a Combined Work as defined below.
+
+ An "Application" is any work that makes use of an interface provided
+by the Library, but which is not otherwise based on the Library.
+Defining a subclass of a class defined by the Library is deemed a mode
+of using an interface provided by the Library.
+
+ A "Combined Work" is a work produced by combining or linking an
+Application with the Library. The particular version of the Library
+with which the Combined Work was made is also called the "Linked
+Version".
+
+ The "Minimal Corresponding Source" for a Combined Work means the
+Corresponding Source for the Combined Work, excluding any source code
+for portions of the Combined Work that, considered in isolation, are
+based on the Application, and not on the Linked Version.
+
+ The "Corresponding Application Code" for a Combined Work means the
+object code and/or source code for the Application, including any data
+and utility programs needed for reproducing the Combined Work from the
+Application, but excluding the System Libraries of the Combined Work.
+
+ 1. Exception to Section 3 of the GNU GPL.
+
+ You may convey a covered work under sections 3 and 4 of this License
+without being bound by section 3 of the GNU GPL.
+
+ 2. Conveying Modified Versions.
+
+ If you modify a copy of the Library, and, in your modifications, a
+facility refers to a function or data to be supplied by an Application
+that uses the facility (other than as an argument passed when the
+facility is invoked), then you may convey a copy of the modified
+version:
+
+ a) under this License, provided that you make a good faith effort to
+ ensure that, in the event an Application does not supply the
+ function or data, the facility still operates, and performs
+ whatever part of its purpose remains meaningful, or
+
+ b) under the GNU GPL, with none of the additional permissions of
+ this License applicable to that copy.
+
+ 3. Object Code Incorporating Material from Library Header Files.
+
+ The object code form of an Application may incorporate material from
+a header file that is part of the Library. You may convey such object
+code under terms of your choice, provided that, if the incorporated
+material is not limited to numerical parameters, data structure
+layouts and accessors, or small macros, inline functions and templates
+(ten or fewer lines in length), you do both of the following:
+
+ a) Give prominent notice with each copy of the object code that the
+ Library is used in it and that the Library and its use are
+ covered by this License.
+
+ b) Accompany the object code with a copy of the GNU GPL and this license
+ document.
+
+ 4. Combined Works.
+
+ You may convey a Combined Work under terms of your choice that,
+taken together, effectively do not restrict modification of the
+portions of the Library contained in the Combined Work and reverse
+engineering for debugging such modifications, if you also do each of
+the following:
+
+ a) Give prominent notice with each copy of the Combined Work that
+ the Library is used in it and that the Library and its use are
+ covered by this License.
+
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
+ document.
+
+ c) For a Combined Work that displays copyright notices during
+ execution, include the copyright notice for the Library among
+ these notices, as well as a reference directing the user to the
+ copies of the GNU GPL and this license document.
+
+ d) Do one of the following:
+
+ 0) Convey the Minimal Corresponding Source under the terms of this
+ License, and the Corresponding Application Code in a form
+ suitable for, and under terms that permit, the user to
+ recombine or relink the Application with a modified version of
+ the Linked Version to produce a modified Combined Work, in the
+ manner specified by section 6 of the GNU GPL for conveying
+ Corresponding Source.
+
+ 1) Use a suitable shared library mechanism for linking with the
+ Library. A suitable mechanism is one that (a) uses at run time
+ a copy of the Library already present on the user's computer
+ system, and (b) will operate properly with a modified version
+ of the Library that is interface-compatible with the Linked
+ Version.
+
+ e) Provide Installation Information, but only if you would otherwise
+ be required to provide such information under section 6 of the
+ GNU GPL, and only to the extent that such information is
+ necessary to install and execute a modified version of the
+ Combined Work produced by recombining or relinking the
+ Application with a modified version of the Linked Version. (If
+ you use option 4d0, the Installation Information must accompany
+ the Minimal Corresponding Source and Corresponding Application
+ Code. If you use option 4d1, you must provide the Installation
+ Information in the manner specified by section 6 of the GNU GPL
+ for conveying Corresponding Source.)
+
+ 5. Combined Libraries.
+
+ You may place library facilities that are a work based on the
+Library side by side in a single library together with other library
+facilities that are not Applications and are not covered by this
+License, and convey such a combined library under terms of your
+choice, if you do both of the following:
+
+ a) Accompany the combined library with a copy of the same work based
+ on the Library, uncombined with any other library facilities,
+ conveyed under the terms of this License.
+
+ b) Give prominent notice with the combined library that part of it
+ is a work based on the Library, and explaining where to find the
+ accompanying uncombined form of the same work.
+
+ 6. Revised Versions of the GNU Lesser General Public License.
+
+ The Free Software Foundation may publish revised and/or new versions
+of the GNU Lesser General Public License from time to time. Such new
+versions will be similar in spirit to the present version, but may
+differ in detail to address new problems or concerns.
+
+ Each version is given a distinguishing version number. If the
+Library as you received it specifies that a certain numbered version
+of the GNU Lesser General Public License "or any later version"
+applies to it, you have the option of following the terms and
+conditions either of that published version or of any later version
+published by the Free Software Foundation. If the Library as you
+received it does not specify a version number of the GNU Lesser
+General Public License, you may choose any version of the GNU Lesser
+General Public License ever published by the Free Software Foundation.
+
+ If the Library as you received it specifies that a proxy can decide
+whether future versions of the GNU Lesser General Public License shall
+apply, that proxy's public statement of acceptance of any version is
+permanent authorization for you to choose that version for the
+Library.
+
Property changes on: nuiton-jpa/nuiton-jpa-templates/src/it/magalie/LICENSE.txt
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Added: nuiton-jpa/nuiton-jpa-templates/src/it/magalie/README.txt
===================================================================
--- nuiton-jpa/nuiton-jpa-templates/src/it/magalie/README.txt (rev 0)
+++ nuiton-jpa/nuiton-jpa-templates/src/it/magalie/README.txt 2013-05-25 15:02:30 UTC (rev 629)
@@ -0,0 +1 @@
+Test jpa templates on project Magalie (see http://forge.codelutin.com/projects/franciaflex-magalie)
\ No newline at end of file
Property changes on: nuiton-jpa/nuiton-jpa-templates/src/it/magalie/README.txt
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Property changes on: nuiton-jpa/nuiton-jpa-templates/src/it/magalie/changelog.txt
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Added: nuiton-jpa/nuiton-jpa-templates/src/it/magalie/goals.txt
===================================================================
--- nuiton-jpa/nuiton-jpa-templates/src/it/magalie/goals.txt (rev 0)
+++ nuiton-jpa/nuiton-jpa-templates/src/it/magalie/goals.txt 2013-05-25 15:02:30 UTC (rev 629)
@@ -0,0 +1 @@
+clean compile
\ No newline at end of file
Property changes on: nuiton-jpa/nuiton-jpa-templates/src/it/magalie/goals.txt
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Added: nuiton-jpa/nuiton-jpa-templates/src/it/magalie/pom.xml
===================================================================
--- nuiton-jpa/nuiton-jpa-templates/src/it/magalie/pom.xml (rev 0)
+++ nuiton-jpa/nuiton-jpa-templates/src/it/magalie/pom.xml 2013-05-25 15:02:30 UTC (rev 629)
@@ -0,0 +1,119 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ #%L
+ EUGene :: Maven plugin
+
+ $Id$
+ $HeadURL$
+ %%
+ Copyright (C) 2006 - 2010 CodeLutin
+ %%
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as
+ published by the Free Software Foundation, either version 3 of the
+ License, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Lesser Public License for more details.
+
+ You should have received a copy of the GNU General Lesser Public
+ License along with this program. If not, see
+ <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ #L%
+ -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>org.nuiton.jpa.templates.test</groupId>
+ <artifactId>magalie</artifactId>
+ <version>@pom.version@</version>
+
+ <name>Nuiton Jpa Temlates :: Test magalie model</name>
+
+ <properties>
+
+ <eugeneVersion>@eugeneVersion@</eugeneVersion>
+
+ <!-- default encoding -->
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+
+ <!-- compiler configuration -->
+ <maven.compiler.source>1.6</maven.compiler.source>
+ <maven.compiler.target>1.6</maven.compiler.target>
+
+ </properties>
+
+ <dependencies>
+
+ <dependency>
+ <groupId>org.nuiton.jpa</groupId>
+ <artifactId>nuiton-jpa-api</artifactId>
+ <version>@pom.version@</version>
+ </dependency>
+
+ </dependencies>
+
+ <build>
+
+ <pluginManagement>
+ <plugins>
+ <plugin>
+ <groupId>org.nuiton.eugene</groupId>
+ <artifactId>eugene-maven-plugin</artifactId>
+ <version>${eugeneVersion}</version>
+ </plugin>
+ </plugins>
+ </pluginManagement>
+
+ <plugins>
+
+ <plugin>
+ <groupId>org.nuiton.eugene</groupId>
+ <artifactId>eugene-maven-plugin</artifactId>
+ <configuration>
+ <inputs>zargo</inputs>
+ <resolver>org.nuiton.util.FasterCachedResourceResolver</resolver>
+ </configuration>
+ <executions>
+ <execution>
+ <id>generate-entities</id>
+ <phase>generate-sources</phase>
+ <configuration>
+ <!-- Corresponding to extracted package from zargo file -->
+ <fullPackagePath>com.franciaflex.magalie.persistence.entity
+ </fullPackagePath>
+ <!-- defaultPackage used for generation -->
+ <defaultPackage>com.franciaflex.magalie.persistence
+ </defaultPackage>
+ <templates>
+ org.nuiton.jpa.templates.JpaEntityTransformer,
+ org.nuiton.jpa.templates.JpaDaoTransformer,
+ org.nuiton.jpa.templates.JpaPersistenceContextTransformer,
+ org.nuiton.eugene.java.JavaEnumerationTransformer
+ </templates>
+ </configuration>
+ <goals>
+ <goal>generate</goal>
+ </goals>
+ </execution>
+ </executions>
+ <dependencies>
+ <dependency>
+ <groupId>org.nuiton.jpa</groupId>
+ <artifactId>nuiton-jpa-templates</artifactId>
+ <version>@pom.version@</version>
+ </dependency>
+ </dependencies>
+ </plugin>
+
+ </plugins>
+ </build>
+</project>
+
+
Property changes on: nuiton-jpa/nuiton-jpa-templates/src/it/magalie/pom.xml
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Added: nuiton-jpa/nuiton-jpa-templates/src/it/magalie/postbuild.groovy
===================================================================
--- nuiton-jpa/nuiton-jpa-templates/src/it/magalie/postbuild.groovy (rev 0)
+++ nuiton-jpa/nuiton-jpa-templates/src/it/magalie/postbuild.groovy 2013-05-25 15:02:30 UTC (rev 629)
@@ -0,0 +1,39 @@
+/*
+ * #%L
+ * nuiton-jpa-templates
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2013 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
+
+outputDir = new File(basedir, 'target/generated-sources/java');
+
+file = new File(outputDir, 'com/franciaflex/magalie/persistence');
+assert file.exists();
+assert file.isDirectory();
+
+file = new File(outputDir, 'com/franciaflex/magalie/persistence/entity');
+assert file.exists();
+assert file.isDirectory();
+
+file = new File(outputDir, 'com/franciaflex/magalie/persistence/dao');
+assert file.exists();
+assert file.isDirectory();
+
+return true;
\ No newline at end of file
Property changes on: nuiton-jpa/nuiton-jpa-templates/src/it/magalie/postbuild.groovy
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Added: nuiton-jpa/nuiton-jpa-templates/src/it/settings.xml
===================================================================
--- nuiton-jpa/nuiton-jpa-templates/src/it/settings.xml (rev 0)
+++ nuiton-jpa/nuiton-jpa-templates/src/it/settings.xml 2013-05-25 15:02:30 UTC (rev 629)
@@ -0,0 +1,87 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ #%L
+ EUGene :: Maven plugin
+
+ $Id$
+ $HeadURL$
+ %%
+ Copyright (C) 2006 - 2010 CodeLutin
+ %%
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as
+ published by the Free Software Foundation, either version 3 of the
+ License, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Lesser Public License for more details.
+
+ You should have received a copy of the GNU General Lesser Public
+ License along with this program. If not, see
+ <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ #L%
+ -->
+
+<settings>
+
+ <profiles>
+ <profile>
+ <id>it-repo</id>
+ <activation>
+ <activeByDefault>true</activeByDefault>
+ </activation>
+ <repositories>
+ <repository>
+ <id>local.central</id>
+ <url>file:///@localRepository@</url>
+ <releases>
+ <enabled>true</enabled>
+ </releases>
+ <snapshots>
+ <enabled>true</enabled>
+ </snapshots>
+ </repository>
+
+ <!-- depot des releases nuiton -->
+ <repository>
+ <id>nuiton.release</id>
+ <name>NuitonReleaseRepository</name>
+ <url>http://maven.nuiton.org/release</url>
+ <snapshots>
+ <enabled>false</enabled>
+ </snapshots>
+ <releases>
+ <enabled>true</enabled>
+ <checksumPolicy>warn</checksumPolicy>
+ </releases>
+ </repository>
+ </repositories>
+ <pluginRepositories>
+ <pluginRepository>
+ <id>local.central</id>
+ <url>file:///@localRepository@</url>
+ <releases>
+ <enabled>true</enabled>
+ </releases>
+ <snapshots>
+ <enabled>true</enabled>
+ </snapshots>
+ </pluginRepository>
+
+ <pluginRepository>
+ <id>nuiton.release</id>
+ <name>NuitonReleaseRepository</name>
+ <url>http://maven.nuiton.org/release</url>
+ <snapshots>
+ <enabled>false</enabled>
+ </snapshots>
+ <releases>
+ <enabled>true</enabled>
+ </releases>
+ </pluginRepository>
+ </pluginRepositories>
+ </profile>
+ </profiles>
+</settings>
Property changes on: nuiton-jpa/nuiton-jpa-templates/src/it/settings.xml
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Modified: nuiton-jpa/pom.xml
===================================================================
--- nuiton-jpa/pom.xml 2013-05-25 14:13:01 UTC (rev 628)
+++ nuiton-jpa/pom.xml 2013-05-25 15:02:30 UTC (rev 629)
@@ -4,9 +4,6 @@
<modelVersion>4.0.0</modelVersion>
- <!-- ************************************************************* -->
- <!-- *** POM Relationships *************************************** -->
- <!-- ************************************************************* -->
<parent>
<groupId>org.nuiton</groupId>
<artifactId>mavenpom4redmineAndCentral</artifactId>
@@ -22,7 +19,7 @@
<module>nuiton-jpa-templates</module>
</modules>
- <name>nuiton-jpa</name>
+ <name>Nuiton Jpa</name>
<inceptionYear>2013</inceptionYear>
<url>http://maven-site.nuiton.org/nuiton-jpa</url>
@@ -35,27 +32,22 @@
<!-- libs version -->
<eugeneVersion>2.6.3-SNAPSHOT</eugeneVersion>
- <nuitonUtilsVersion>2.6.12</nuitonUtilsVersion>
<processorPluginVersion>1.3</processorPluginVersion>
<h2Version>1.3.170</h2Version>
- <hibernateVersion>4.1.9.Final</hibernateVersion>
+ <hibernateVersion>4.1.11.Final</hibernateVersion>
</properties>
- <!-- ************************************************************* -->
- <!-- *** Build Environment ************************************** -->
- <!-- ************************************************************* -->
-
<scm>
- <connection>scm:svn:http://svn.nuiton.org/svn/topia/trunk</connection>
- <developerConnection>scm:svn:http://svn.nuiton.org/svn/topia/trunk</developerConnection>
- <url>http://nuiton.org/projects/topia/repository/show/branches/trunk</url>
+ <connection>scm:svn:http://svn.nuiton.org/svn/sandbox/nuiton-jpa</connection>
+ <developerConnection>scm:svn:http://svn.nuiton.org/svn/sandbox/nuiton-jpa</developerConnection>
+ <url>http://nuiton.org/projects/sandbox/repository/show/nuiton-jpa</url>
</scm>
<distributionManagement>
<site>
<id>${platform}</id>
- <url>${our.site.repository}/${projectId}</url>
+ <url>${our.site.repository}/sandbox/${projectId}</url>
</site>
</distributionManagement>
@@ -105,11 +97,6 @@
</dependencyManagement>
- <!-- ************************************************************* -->
- <!-- *** Project Information ************************************* -->
- <!-- ************************************************************* -->
-
-
<developers>
<developer>
@@ -137,10 +124,6 @@
</developer>
</developers>
-
- <!-- ************************************************************* -->
- <!-- *** Build Settings ****************************************** -->
- <!-- ************************************************************* -->
<packaging>pom</packaging>
@@ -181,12 +164,6 @@
</plugin>
<plugin>
- <groupId>org.nuiton.i18n</groupId>
- <artifactId>i18n-maven-plugin</artifactId>
- <version>${nuitonI18nVersion}</version>
- </plugin>
-
- <plugin>
<artifactId>maven-site-plugin</artifactId>
<dependencies>
<dependency>
Added: nuiton-jpa/src/site/rst/index.rst
===================================================================
--- nuiton-jpa/src/site/rst/index.rst (rev 0)
+++ nuiton-jpa/src/site/rst/index.rst 2013-05-25 15:02:30 UTC (rev 629)
@@ -0,0 +1,28 @@
+.. -
+.. * #%L
+.. * Nuiton Jpa
+.. * $Id$
+.. * $HeadURL$
+.. * %%
+.. * Copyright (C) 2013 CodeLutin
+.. * %%
+.. * This program is free software: you can redistribute it and/or modify
+.. * it under the terms of the GNU Lesser General Public License as
+.. * published by the Free Software Foundation, either version 3 of the
+.. * License, or (at your option) any later version.
+.. *
+.. * This program is distributed in the hope that it will be useful,
+.. * but WITHOUT ANY WARRANTY; without even the implied warranty of
+.. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+.. * GNU General Lesser Public License for more details.
+.. *
+.. * You should have received a copy of the GNU General Lesser Public
+.. * License along with this program. If not, see
+.. * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+.. * #L%
+.. -
+==========
+Nuiton Jpa
+==========
+
+TODO
Property changes on: nuiton-jpa/src/site/rst/index.rst
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Added: nuiton-jpa/src/site/site.xml
===================================================================
--- nuiton-jpa/src/site/site.xml (rev 0)
+++ nuiton-jpa/src/site/site.xml 2013-05-25 15:02:30 UTC (rev 629)
@@ -0,0 +1,123 @@
+<!--
+ #%L
+ Nuiton Jpa
+ $Id$
+ $HeadURL$
+ %%
+ Copyright (C) 2013 CodeLutin
+ %%
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as
+ published by the Free Software Foundation, either version 3 of the
+ License, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Lesser Public License for more details.
+
+ You should have received a copy of the GNU General Lesser Public
+ License along with this program. If not, see
+ <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ #L%
+ -->
+
+<project name="${project.name}">
+
+ <skin>
+ <groupId>org.apache.maven.skins</groupId>
+ <artifactId>maven-fluido-skin</artifactId>
+ <version>1.3.0</version>
+ </skin>
+
+ <custom>
+ <fluidoSkin>
+ <topBarEnabled>false</topBarEnabled>
+ <googleSearch/>
+ <sideBarEnabled>true</sideBarEnabled>
+ <searchEnabled>true</searchEnabled>
+ <sourceLineNumbersEnabled>true</sourceLineNumbersEnabled>
+ </fluidoSkin>
+ </custom>
+
+ <bannerLeft>
+ <name>${project.name}</name>
+ <href>index.html</href>
+ </bannerLeft>
+
+ <bannerRight>
+ <src>http://www.codelutin.com/images/lutinorange-codelutin.png</src>
+ <href>http://www.codelutin.com</href>
+ </bannerRight>
+
+ <publishDate position="right"/>
+ <version position="right"/>
+
+ <poweredBy>
+ <logo href="http://maven.apache.org" name="Maven"
+ img="http://maven-site.nuiton.org/public/images/logos/maven-feather.png"/>
+ <logo href="http://maven-site.nuiton.org/jrst/" name="JRst"
+ img="http://maven-site.nuiton.org/public/images/logos/jrst-logo.png"/>
+ <logo href="http://docutils.sourceforge.net/rst.html"
+ name="ReStructuredText"
+ img="http://maven-site.nuiton.org/public/images/logos/restructuredtext-logo.png"/>
+ </poweredBy>
+
+ <body>
+
+ <breadcrumbs>
+ <item name="${project.name}" href="./index.html"/>
+ </breadcrumbs>
+
+ <head>
+ <script type="text/javascript"
+ src="http://maven-site.nuiton.org/public/js/maven-site-nuiton.org.js">
+ </script>
+ </head>
+
+ <links>
+ <item name="Nuiton.org" href="http://nuiton.org"/>
+ <item name="Code Lutin" href="http://www.codelutin.com"/>
+ <item name="Libre-Entreprise" href="http://www.libre-entreprise.org/"/>
+ </links>
+
+ <menu name="Home">
+ <item name="Home" href="index.html"/>
+ </menu>
+
+ <menu name="Project">
+ <item name="Forge" href="http://nuiton.org/projects/show/nuiton-jpa"/>
+ <item name="Downloads"
+ href="http://nuiton.org/projects/nuiton-jpa/files"/>
+ <item name="Trackers" href="http://nuiton.org/projects/nuiton-jpa/issues"/>
+ </menu>
+
+ <menu name="Links">
+ <item name="Nuiton-processor"
+ href="http://maven-site.nuiton.org/processor"/>
+ <item name="Eugene" href="http://maven-site.nuiton.org/eugene"/>
+ <item name="ArgoUML" href="http://argouml.tigris.org/"/>
+ <item name="UML" href="http://www.uml.org/"/>
+ <item name="XMI" href="http://www.omg.org/spec/XMI/"/>
+ </menu>
+
+ <menu ref="modules"/>
+
+ <menu ref="reports"/>
+
+ <footer>
+
+ <div id='projectMetas' locale='en'
+ projectversion='${project.version}'
+ platform='${project.platform}'
+ projectid='${project.projectId}'
+ scm='${project.scm.developerConnection}'
+ scmwebeditorenabled='${project.scmwebeditorEnabled}'
+ scmwebeditorurl='${project.scmwebeditorUrl}'
+ siteSourcesType='${project.siteSourcesType}'
+ piwikEnabled='${project.piwikEnabled}'
+ piwikId='${project.piwikId}'>
+ </div>
+ </footer>
+ </body>
+</project>
\ No newline at end of file
Property changes on: nuiton-jpa/src/site/site.xml
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
1
0
r628 - in nuiton-jpa: . nuiton-jpa-api nuiton-jpa-api/src/main/java/org/nuiton/jpa/api nuiton-jpa-junit/src/main/java/org/nuiton/jpa/junit nuiton-jpa-templates nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates
by tchemit@users.nuiton.org 25 May '13
by tchemit@users.nuiton.org 25 May '13
25 May '13
Author: tchemit
Date: 2013-05-25 16:13:01 +0200 (Sat, 25 May 2013)
New Revision: 628
Url: http://nuiton.org/projects/sandbox/repository/revisions/628
Log:
continue nuiton-jpa (works now on magalie project)
Added:
nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/JpaEntities.java
nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/JpaEntity.java
Modified:
nuiton-jpa/nuiton-jpa-api/pom.xml
nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/AbstractJpaDao.java
nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/AbstractJpaEntity.java
nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/JpaDao.java
nuiton-jpa/nuiton-jpa-junit/src/main/java/org/nuiton/jpa/junit/JpaEntityManagerRule.java
nuiton-jpa/nuiton-jpa-templates/pom.xml
nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/AbstractJpaTransformer.java
nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaDaoTransformer.java
nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaEntityTransformer.java
nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaPersistenceContextTransformer.java
nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaTemplatesGeneratorUtil.java
nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaTemplatesStereoTypes.java
nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaTemplatesTagValues.java
nuiton-jpa/pom.xml
Modified: nuiton-jpa/nuiton-jpa-api/pom.xml
===================================================================
--- nuiton-jpa/nuiton-jpa-api/pom.xml 2013-05-24 22:19:58 UTC (rev 627)
+++ nuiton-jpa/nuiton-jpa-api/pom.xml 2013-05-25 14:13:01 UTC (rev 628)
@@ -36,6 +36,11 @@
</dependency>
<dependency>
+ <groupId>com.google.guava</groupId>
+ <artifactId>guava</artifactId>
+ </dependency>
+
+ <dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</dependency>
Modified: nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/AbstractJpaDao.java
===================================================================
--- nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/AbstractJpaDao.java 2013-05-24 22:19:58 UTC (rev 627)
+++ nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/AbstractJpaDao.java 2013-05-25 14:13:01 UTC (rev 628)
@@ -45,7 +45,7 @@
*
* @since 0.1
*/
-public abstract class AbstractJpaDao<E extends AbstractJpaEntity> implements JpaDao<E> {
+public abstract class AbstractJpaDao<E extends JpaEntity> implements JpaDao<E> {
protected EntityManager entityManager;
Modified: nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/AbstractJpaEntity.java
===================================================================
--- nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/AbstractJpaEntity.java 2013-05-24 22:19:58 UTC (rev 627)
+++ nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/AbstractJpaEntity.java 2013-05-25 14:13:01 UTC (rev 628)
@@ -26,17 +26,15 @@
/**
* A AbstractJpaEntity must have a technical id.
- *
+ * <p/>
* Also equals() is defined for compliance with JPA expectations.
*
* @author bleny <leny(a)codelutin.com>
* @author tchemit <chemit(a)codelutin.com>
* @since 0.1
*/
-public abstract class AbstractJpaEntity {
+public abstract class AbstractJpaEntity implements JpaEntity{
- public abstract String getId();
-
@Override
public boolean equals(Object other) {
String id = getId();
@@ -55,7 +53,7 @@
@Override
public String toString() {
- return "AbstractJpaEntity{id=" + getId() + "}";
+ return getClass().getSimpleName() + "{id=" + getId() + "}";
}
}
Modified: nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/JpaDao.java
===================================================================
--- nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/JpaDao.java 2013-05-24 22:19:58 UTC (rev 627)
+++ nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/JpaDao.java 2013-05-25 14:13:01 UTC (rev 628)
@@ -2,7 +2,7 @@
/*
* #%L
- * MagaLiE :: Persistence
+ * nuiton-jpa-api
* $Id$
* $HeadURL$
* %%
@@ -35,7 +35,7 @@
* @author tchemit <chemit(a)codelutin.com>
* @since 0.1
*/
-public interface JpaDao<E extends AbstractJpaEntity> {
+public interface JpaDao<E extends JpaEntity> {
E findById(String id);
Added: nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/JpaEntities.java
===================================================================
--- nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/JpaEntities.java (rev 0)
+++ nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/JpaEntities.java 2013-05-25 14:13:01 UTC (rev 628)
@@ -0,0 +1,74 @@
+package org.nuiton.jpa.api;
+
+/*
+ * #%L
+ * nuiton-jpa-api
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2013 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
+
+import com.google.common.base.Function;
+import com.google.common.base.Predicate;
+import com.google.common.base.Predicates;
+import org.apache.commons.lang3.ObjectUtils;
+
+import java.io.Serializable;
+import java.util.Comparator;
+
+/**
+ * Helper class around {@link JpaEntity}.
+ *
+ * @author bleny <leny(a)codelutin.com>
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 0.1
+ */
+public class JpaEntities {
+
+ public static class GetIdFunction implements Function<JpaEntity, String> {
+
+ @Override
+ public String apply(JpaEntity entity) {
+ return entity.getId();
+ }
+ }
+
+ public static class ArbitraryComparator<E extends JpaEntity> implements Comparator<E>, Serializable {
+
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public int compare(E x, E y) {
+ return ObjectUtils.compare(x.getId(), y.getId());
+ }
+
+ }
+
+ public static Function<JpaEntity, String> getIdFunction() {
+ return new GetIdFunction();
+ }
+
+ public static Predicate<JpaEntity> entityHasId(String id) {
+ return Predicates.compose(Predicates.equalTo(id), getIdFunction());
+ }
+
+ public static <E extends JpaEntity> Comparator<E> arbitraryComparator() {
+ return new ArbitraryComparator<E>();
+ }
+}
Property changes on: nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/JpaEntities.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Added: nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/JpaEntity.java
===================================================================
--- nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/JpaEntity.java (rev 0)
+++ nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/JpaEntity.java 2013-05-25 14:13:01 UTC (rev 628)
@@ -0,0 +1,42 @@
+package org.nuiton.jpa.api;
+
+/*
+ * #%L
+ * nuiton-jpa-api
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2013 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
+
+/**
+ * A JpaEntity must have a technical id.
+ * <p/>
+ * Also {@link #equals(Object)} and {@link #hashCode()} {@code MUST} be defined
+ * for compliance with JPA expectations.
+ *
+ * @author bleny <leny(a)codelutin.com>
+ * @author tchemit <chemit(a)codelutin.com>
+ * @see AbstractJpaEntity
+ * @since 0.1
+ */
+public interface JpaEntity {
+
+ String getId();
+
+}
Property changes on: nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/JpaEntity.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Modified: nuiton-jpa/nuiton-jpa-junit/src/main/java/org/nuiton/jpa/junit/JpaEntityManagerRule.java
===================================================================
--- nuiton-jpa/nuiton-jpa-junit/src/main/java/org/nuiton/jpa/junit/JpaEntityManagerRule.java 2013-05-24 22:19:58 UTC (rev 627)
+++ nuiton-jpa/nuiton-jpa-junit/src/main/java/org/nuiton/jpa/junit/JpaEntityManagerRule.java 2013-05-25 14:13:01 UTC (rev 628)
@@ -2,7 +2,7 @@
/*
* #%L
- * MagaLiE :: Services
+ * nuiton-jpa-junit
* $Id$
* $HeadURL$
* %%
Modified: nuiton-jpa/nuiton-jpa-templates/pom.xml
===================================================================
--- nuiton-jpa/nuiton-jpa-templates/pom.xml 2013-05-24 22:19:58 UTC (rev 627)
+++ nuiton-jpa/nuiton-jpa-templates/pom.xml 2013-05-25 14:13:01 UTC (rev 628)
@@ -39,6 +39,11 @@
</dependency>
<dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-lang3</artifactId>
+ </dependency>
+
+ <dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
</dependency>
Modified: nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/AbstractJpaTransformer.java
===================================================================
--- nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/AbstractJpaTransformer.java 2013-05-24 22:19:58 UTC (rev 627)
+++ nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/AbstractJpaTransformer.java 2013-05-25 14:13:01 UTC (rev 628)
@@ -31,6 +31,7 @@
import org.nuiton.eugene.java.ObjectModelTransformerToJava;
import org.nuiton.eugene.models.object.ObjectModelAttribute;
import org.nuiton.eugene.models.object.ObjectModelClass;
+import org.nuiton.eugene.models.object.ObjectModelElement;
import org.nuiton.eugene.models.object.ObjectModelInterface;
import org.nuiton.eugene.models.object.ObjectModelJavaModifier;
import org.nuiton.eugene.models.object.ObjectModelOperation;
@@ -39,9 +40,7 @@
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.io.Serializable;
-import java.util.ArrayList;
import java.util.Collection;
-import java.util.List;
import java.util.Set;
/**
@@ -55,6 +54,27 @@
public static final String DEFAULT_CONSTANT_PREFIX = "PROPERTY_";
+ public String getDefaultPackageName() {
+ String packageName =
+ getOutputProperties().getProperty(PROP_DEFAULT_PACKAGE);
+ return packageName;
+ }
+
+ protected void addAnnotation(
+ ObjectModelClass output,
+ Class annotation) {
+ addAnnotation(output, output, annotation.getSimpleName());
+ addImport(output, annotation);
+ }
+
+ protected void addAnnotation(
+ ObjectModelClass output,
+ ObjectModelElement element,
+ Class annotation) {
+ addAnnotation(output, element, annotation.getSimpleName());
+ addImport(output, annotation);
+ }
+
protected void addConstructorWithEntityManager(ObjectModelClass output) {
ObjectModelOperation constructor = addConstructor(
@@ -105,7 +125,7 @@
String prefix,
Set<String> constantNames) {
- String attrName = getAttributeName(attr);
+ String attrName = JpaTemplatesGeneratorUtil.getAttributeName(attr);
String constantName = prefix + builder.getConstantName(attrName);
@@ -120,330 +140,6 @@
}
}
- protected String getAttributeName(ObjectModelAttribute attr) {
- String attrName = attr.getName();
- if (attr.hasAssociationClass()) {
- String assocAttrName = JpaTemplatesGeneratorUtil.getAssocAttrName(attr);
- attrName = JpaTemplatesGeneratorUtil.toLowerCaseFirstLetter(assocAttrName);
- }
- return attrName;
- }
-
- protected String getAttributeType(ObjectModelAttribute attr) {
- String attrType = attr.getType();
- if (attr.hasAssociationClass()) {
- attrType = attr.getAssociationClass().getName();
- }
- return attrType;
- }
-
- protected boolean containsMutiple(List<ObjectModelAttribute> attributes) {
-
- boolean result = false;
-
- for (ObjectModelAttribute attr : attributes) {
-
- if (JpaTemplatesGeneratorUtil.isNMultiplicity(attr)) {
- result = true;
-
- break;
- }
-
- }
- return result;
- }
-
-
- protected List<ObjectModelAttribute> getProperties(ObjectModelClass input) {
- List<ObjectModelAttribute> attributes =
- (List<ObjectModelAttribute>) input.getAttributes();
-
- List<ObjectModelAttribute> attrs =
- new ArrayList<ObjectModelAttribute>();
- for (ObjectModelAttribute attr : attributes) {
- if (attr.isNavigable()) {
-
- // only keep navigable attributes
- attrs.add(attr);
- }
- }
- return attrs;
- }
-
- protected void createGetMethod(ObjectModelClass output,
- String attrName,
- String attrType,
- String methodPrefix) {
-
- ObjectModelOperation operation = addOperation(
- output,
- getJavaBeanMethodName(methodPrefix, attrName),
- attrType,
- ObjectModelJavaModifier.PUBLIC
- );
- setOperationBody(operation, ""
- /*{
- return <%=attrName%>;
- }*/
- );
- }
-
- protected void createGetChildMethod(ObjectModelClass output,
- String attrName,
- String attrType,
- String simpleType) {
- ObjectModelOperation operation = addOperation(
- output,
- getJavaBeanMethodName("get", attrName),
- attrType,
- ObjectModelJavaModifier.PUBLIC
- );
- addParameter(operation, "int", "index");
- setOperationBody(operation, ""
- /*{
- <%=simpleType%> o = getChild(<%=attrName%>, index);
- return o;
- }*/
- );
- }
-
- protected void createIsEmptyMethod(ObjectModelClass output,
- String attrName) {
- ObjectModelOperation operation = addOperation(
- output,
- getJavaBeanMethodName("is", attrName) + "Empty",
- boolean.class,
- ObjectModelJavaModifier.PUBLIC
- );
- setOperationBody(operation, ""
- /*{
- return <%=attrName%> == null || <%=attrName%>.isEmpty();
- }*/
- );
- }
-
- protected void createSizeMethod(ObjectModelClass output,
- String attrName) {
- ObjectModelOperation operation = addOperation(
- output,
- getJavaBeanMethodName("size", attrName),
- int.class,
- ObjectModelJavaModifier.PUBLIC
- );
- setOperationBody(operation, ""
- /*{
- return <%=attrName%> == null ? 0 : <%=attrName%>.size();
- }*/
- );
- }
-
- protected void createAddChildMethod(ObjectModelClass output,
- String attrName,
- String attrType,
- String constantName,
- boolean usePCS) {
- ObjectModelOperation operation = addOperation(
- output,
- getJavaBeanMethodName("add", attrName),
- "void",
- ObjectModelJavaModifier.PUBLIC
- );
- addParameter(operation, attrType, attrName);
-
- String methodName = getJavaBeanMethodName("get", attrName);
- StringBuilder buffer = new StringBuilder(""
- /*{
- <%=methodName%>().add(<%=attrName%>);
- }*/
- );
- if (usePCS) {
- buffer.append(""
- /*{ firePropertyChange(<%=constantName%>, null, <%=attrName%>);
- }*/
- );
- }
- setOperationBody(operation, buffer.toString());
- }
-
- protected void createAddAllChildrenMethod(ObjectModelClass output,
- String attrName,
- String attrType,
- String constantName,
- boolean usePCS) {
- ObjectModelOperation operation = addOperation(
- output,
- getJavaBeanMethodName("addAll", attrName),
- "void",
- ObjectModelJavaModifier.PUBLIC
- );
- addParameter(operation, Collection.class.getName() + "<" + attrType + ">", attrName);
-
- String methodName = getJavaBeanMethodName("get", attrName);
- StringBuilder buffer = new StringBuilder(""
- /*{
- <%=methodName%>().addAll(<%=attrName%>);
- }*/
- );
- if (usePCS) {
- buffer.append(""
- /*{ firePropertyChange(<%=constantName%>, null, <%=attrName%>);
- }*/
- );
- }
- setOperationBody(operation, buffer.toString());
- }
-
- protected void createRemoveChildMethod(ObjectModelClass output,
- String attrName,
- String attrType,
- String constantName,
- boolean usePCS) {
- ObjectModelOperation operation = addOperation(
- output,
- getJavaBeanMethodName("remove", attrName),
- "boolean",
- ObjectModelJavaModifier.PUBLIC
- );
- addParameter(operation, attrType, attrName);
- String methodName = getJavaBeanMethodName("get", attrName);
- StringBuilder buffer = new StringBuilder();
- buffer.append(""
- /*{
- boolean removed = <%=methodName%>().remove(<%=attrName%>);}*/
- );
-
- if (usePCS) {
- buffer.append(""
- /*{
- if (removed) {
- firePropertyChange(<%=constantName%>, <%=attrName%>, null);
- }}*/
- );
- }
- buffer.append(""
- /*{
- return removed;
- }*/
- );
- setOperationBody(operation, buffer.toString());
- }
-
- protected void createRemoveAllChildrenMethod(ObjectModelClass output,
- String attrName,
- String attrType,
- String constantName,
- boolean usePCS) {
-
- ObjectModelOperation operation = addOperation(
- output,
- getJavaBeanMethodName("removeAll", attrName),
- "boolean",
- ObjectModelJavaModifier.PUBLIC
- );
- addParameter(operation, "java.util.Collection<" + attrType + ">", attrName);
- StringBuilder buffer = new StringBuilder();
- String methodName = getJavaBeanMethodName("get", attrName);
- buffer.append(""
- /*{
- boolean removed = <%=methodName%>().removeAll(<%=attrName%>);}*/
- );
-
- if (usePCS) {
- buffer.append(""
- /*{
- if (removed) {
- firePropertyChange(<%=constantName%>, <%=attrName%>, null);
- }}*/
- );
- }
- buffer.append(""
- /*{
- return removed;
- }*/
- );
- setOperationBody(operation, buffer.toString());
- }
-
- protected void createContainsChildMethod(ObjectModelClass output,
- String attrName,
- String attrType,
- String constantName,
- boolean usePCS) {
-
- ObjectModelOperation operation = addOperation(
- output,
- getJavaBeanMethodName("contains", attrName),
- "boolean",
- ObjectModelJavaModifier.PUBLIC
- );
- addParameter(operation, attrType, attrName);
- StringBuilder buffer = new StringBuilder();
- String methodName = getJavaBeanMethodName("get", attrName);
- buffer.append(""
- /*{
- boolean contains = <%=methodName%>().contains(<%=attrName%>);
- return contains;
- }*/
- );
- setOperationBody(operation, buffer.toString());
- }
-
- protected void createContainsAllChildrenMethod(ObjectModelClass output,
- String attrName,
- String attrType,
- String constantName,
- boolean usePCS) {
-
- ObjectModelOperation operation = addOperation(
- output,
- getJavaBeanMethodName("containsAll", attrName),
- "boolean",
- ObjectModelJavaModifier.PUBLIC
- );
- addParameter(operation, Collection.class.getName() + "<" + attrType + ">", attrName);
- StringBuilder buffer = new StringBuilder();
- String methodName = getJavaBeanMethodName("get", attrName);
- buffer.append(""
- /*{
- boolean contains = <%=methodName%>().containsAll(<%=attrName%>);
- return contains;
- }*/
- );
- setOperationBody(operation, buffer.toString());
- }
-
- protected void createSetMethod(ObjectModelClass output,
- String attrName,
- String attrType,
- String simpleType,
- String constantName,
- boolean usePCS) {
- ObjectModelOperation operation = addOperation(
- output,
- getJavaBeanMethodName("set", attrName),
- "void",
- ObjectModelJavaModifier.PUBLIC
- );
- addParameter(operation, attrType, attrName);
-
- if (usePCS) {
- String methodName = getJavaBeanMethodName("get", attrName);
- setOperationBody(operation, ""
- /*{
- <%=simpleType%> oldValue = <%=methodName%>();
- this.<%=attrName%> = <%=attrName%>;
- firePropertyChange(<%=constantName%>, oldValue, <%=attrName%>);
- }*/
- );
- } else {
- setOperationBody(operation, ""
- /*{
- this.<%=attrName%> = <%=attrName%>;
- }*/
- );
- }
- }
-
protected void addSerializable(ObjectModelClass input,
ObjectModelClass output,
boolean interfaceFound) {
@@ -577,37 +273,4 @@
);
}
- protected void createGetChildMethod(ObjectModelClass output) {
- ObjectModelOperation getChild = addOperation(
- output,
- "getChild", "<T> T",
- ObjectModelJavaModifier.PROTECTED
- );
- addImport(output, List.class);
-
- addParameter(getChild, "java.util.Collection<T>", "childs");
- addParameter(getChild, "int", "index");
- setOperationBody(getChild, ""
- /*{
- T result = null;
- if (childs != null) {
- if (childs instanceof List) {
- if (index < childs.size()) {
- result = ((List<T>) childs).get(index);
- }
- } else {
- int i = 0;
- for (T o : childs) {
- if (index == i) {
- result = o;
- break;
- }
- i++;
- }
- }
- }
- return result;
- }*/
- );
- }
}
Modified: nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaDaoTransformer.java
===================================================================
--- nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaDaoTransformer.java 2013-05-24 22:19:58 UTC (rev 627)
+++ nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaDaoTransformer.java 2013-05-25 14:13:01 UTC (rev 628)
@@ -31,6 +31,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.nuiton.eugene.models.object.ObjectModelClass;
+import org.nuiton.eugene.models.object.ObjectModelJavaModifier;
import org.nuiton.eugene.models.object.ObjectModelOperation;
import org.nuiton.jpa.api.AbstractJpaDao;
@@ -41,7 +42,6 @@
* <li>{@code AbstractXXXJpaDao}: abstract jpa dao for entity named {@code XXX}, will find here the generated stuff (with jpa mapping, technical stuff)</li>
* <li>{@code XXXJpaDao}: concrete public jpa dao to use in your persistence layer</li>
* </ul>
- * <p/>
* {@code Note:} All classes found in class-path are not generated.
*
* @author tchemit <chemit(a)codelutin.com>
@@ -56,35 +56,38 @@
@Override
public void transformFromClass(ObjectModelClass input) {
- String entityAbstractName = "Abstract" + input.getName() + "JpaDao";
+ String packageName = JpaTemplatesGeneratorUtil.getDaoPackage(this, model, input);
- String entityConcreteName = JpaTemplatesGeneratorUtil.getDaoConcreteName(input);
+ String abstractDaoName = JpaTemplatesGeneratorUtil.getDaoAbstractName(input);
- boolean generateAbstract = !isInClassPath(input.getPackageName(),
- entityAbstractName);
+ String concreteDaoName = JpaTemplatesGeneratorUtil.getDaoConcreteName(input);
- boolean generateConcrete = !isInClassPath(input.getPackageName(),
- entityConcreteName);
+ String concreteEntityQualifiedName=
+ JpaTemplatesGeneratorUtil.getConcreteEntityQualifiedName(this, model, input);
+ boolean generateAbstract = !isInClassPath(packageName, abstractDaoName);
+
+ boolean generateConcrete = !isInClassPath(packageName, concreteDaoName);
+
if (generateAbstract) {
- generateAbstract(input, entityAbstractName);
+ generateAbstract(input, packageName, abstractDaoName, concreteEntityQualifiedName);
}
if (generateConcrete) {
- generateImpl(input, entityAbstractName, entityConcreteName);
+ generateImpl(input, packageName, abstractDaoName, concreteDaoName, concreteEntityQualifiedName);
}
}
protected ObjectModelClass generateAbstract(ObjectModelClass input,
- String entityAbstractName) {
+ String packageName,
+ String abstractDaoName,
+ String concreteEntityQualifiedName) {
- String packageName = input.getPackageName();
-
ObjectModelClass output =
- createAbstractClass(entityAbstractName + "<E extends " + input.getName() + ">", packageName);
- addImport(output, input.getQualifiedName());
+ createAbstractClass(abstractDaoName + "<E extends " + input.getName() + ">", packageName);
+ addImport(output, concreteEntityQualifiedName);
// test if a super class is in same package (so is yet another entity)
boolean superClassIsEntity = isSuperClassEntity(input);
@@ -95,7 +98,9 @@
// get first super-class
ObjectModelClass superClassModel = input.getSuperclasses().iterator().next();
- superClass = JpaTemplatesGeneratorUtil.getDaoConcreteName(superClassModel);
+ superClass = JpaTemplatesGeneratorUtil.getDaoPackage(this, model, superClassModel) +
+ "." +
+ JpaTemplatesGeneratorUtil.getDaoConcreteName(superClassModel);
} else {
@@ -110,56 +115,50 @@
addImport(output, superClass);
}
}
-
- // detect if there is a contract to set on abstract
- String daoContractName = input.getPackageName() + "." + input.getName() + "Dao";
-
- boolean addUserDaoContract = isInClassPath(daoContractName);
-
setSuperClass(output, superClass);
- if (addUserDaoContract) {
- addInterface(output, daoContractName);
- }
-
addConstructorWithEntityManager(output);
// Add getEntityClass
- if (log.isDebugEnabled()) {
- log.debug("will generate " + output.getQualifiedName());
- }
- ObjectModelOperation operation = addOperation(output, "getEntityClass", "Class<E>");
- addAnnotation(output, operation, Override.class.getSimpleName());
+ ObjectModelOperation operation = addOperation(output, "getEntityClass", "Class<E>", ObjectModelJavaModifier.PROTECTED);
+ addAnnotation(output, operation, Override.class);
setOperationBody(operation, ""
/*{
return (Class<E>) <%=input.getName()%>.class;
}*/
);
-
+ if (isVerbose()) {
+ log.info("will generate " + output.getQualifiedName());
+ }
return output;
}
protected ObjectModelClass generateImpl(ObjectModelClass input,
- String entityAbstractName,
- String entityConcreteName) {
+ String packageName,
+ String abstractDaoName,
+ String concreteDaoName,
+ String concreteEntityQualifiedName) {
- ObjectModelClass output = createClass(
- entityConcreteName,
- input.getPackageName()
- );
+ ObjectModelClass output = createClass(concreteDaoName, packageName);
- // set the abstract resulClass as the resultClassImpl super class
- setSuperClass(output, input.getPackageName() + '.' + entityAbstractName + "<" + input.getName() + ">");
- addImport(output, input);
+ setSuperClass(output, packageName + '.' + abstractDaoName + "<" + input.getName() + ">");
+ addImport(output, concreteEntityQualifiedName);
addConstructorWithEntityManager(output);
- output.getSuperclasses();
- if (log.isDebugEnabled()) {
- log.debug("will generate " + output.getQualifiedName());
+ // detect if there is a contract to set on abstract
+ String daoContractName = packageName + "." + input.getName() + "Dao";
+
+ boolean addUserDaoContract = isInClassPath(daoContractName);
+
+ if (addUserDaoContract) {
+ addInterface(output, daoContractName);
}
+ if (isVerbose()) {
+ log.info("will generate " + output.getQualifiedName());
+ }
return output;
}
Modified: nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaEntityTransformer.java
===================================================================
--- nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaEntityTransformer.java 2013-05-24 22:19:58 UTC (rev 627)
+++ nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaEntityTransformer.java 2013-05-25 14:13:01 UTC (rev 628)
@@ -24,9 +24,12 @@
* #L%
*/
-import com.google.common.base.Preconditions;
+import com.google.common.base.Joiner;
import com.google.common.collect.ArrayListMultimap;
+import com.google.common.collect.ListMultimap;
+import com.google.common.collect.Lists;
import com.google.common.collect.Multimap;
+import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.nuiton.eugene.models.object.ObjectModelAttribute;
@@ -36,9 +39,11 @@
import org.nuiton.eugene.models.object.xml.ObjectModelAttributeImpl;
import org.nuiton.jpa.api.AbstractJpaEntity;
+import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
+import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
@@ -47,7 +52,6 @@
import javax.persistence.OneToOne;
import javax.persistence.OrderColumn;
import java.util.Collection;
-import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
@@ -63,7 +67,6 @@
* <p/>
* {@code Note:} All classes found in class-path are not generated.
*
- * TODO Deal with @GeneratedValue
* @author tchemit <chemit(a)codelutin.com>
* @plexus.component role="org.nuiton.eugene.Template" role-hint="org.nuiton.jpa.templates.JpaEntityTransformer"
* @since 0.1
@@ -73,44 +76,34 @@
private static final Log log =
LogFactory.getLog(JpaEntityTransformer.class);
- protected String getConcreteName(ObjectModelClass input) {
- return input.getName();
- }
+ public static final String PROPERTY_ID = "id";
@Override
public void transformFromClass(ObjectModelClass input) {
- String entityAbstractName = "Jpa" + input.getName();
+ String packageName = JpaTemplatesGeneratorUtil.getEntityPackage(this, model, input);
- String entityConcreteName = getConcreteName(input);
+ String entityAbstractName = JpaTemplatesGeneratorUtil.getEntityAbstractName(input);
- boolean generateAbstract = !isInClassPath(input.getPackageName(), entityAbstractName);
+ String entityConcreteName = JpaTemplatesGeneratorUtil.getEntityConcreteName(input);
- boolean generateConcrete = !isInClassPath(input.getPackageName(), entityConcreteName);
+ boolean generateAbstract = !isInClassPath(packageName, entityAbstractName);
+ boolean generateConcrete = !isInClassPath(packageName, entityConcreteName);
+
if (generateAbstract) {
- generateAbstract(input, entityAbstractName);
+ generateAbstract(input, packageName, entityAbstractName);
}
if (generateConcrete) {
- generateImpl(input, entityAbstractName, entityConcreteName);
+ generateImpl(input, packageName, entityAbstractName, entityConcreteName);
}
}
- protected void createAbstractOperations(ObjectModelClass ouput,
- Iterable<ObjectModelOperation> operations) {
- JpaTemplatesGeneratorUtil.cloneOperations(
- this,
- operations,
- ouput,
- true,
- ObjectModelJavaModifier.ABSTRACT
- );
- }
-
protected ObjectModelClass generateAbstract(ObjectModelClass input,
+ String packageName,
String entityAbstractName) {
// test if a super class is in same package (so is yet another entity)
@@ -123,8 +116,9 @@
// get first super-class
ObjectModelClass superClassModel =
input.getSuperclasses().iterator().next();
- superClass = getConcreteName(superClassModel);
-
+ superClass = JpaTemplatesGeneratorUtil.getEntityPackage(this, model, superClassModel) +
+ "." +
+ JpaTemplatesGeneratorUtil.getEntityConcreteName(superClassModel);
} else {
// try to find a super class by tag-value
@@ -144,18 +138,12 @@
}
ObjectModelClass output =
- createAbstractClass(entityAbstractName, input.getPackageName());
+ createAbstractClass(entityAbstractName, packageName);
setSuperClass(output, superClass);
- // Add annotation MappedSuperclass
- addAnnotation(output, output, MappedSuperclass.class.getSimpleName());
- addImport(output, MappedSuperclass.class);
+ addAnnotation(output, MappedSuperclass.class);
- if (log.isDebugEnabled()) {
- log.debug("will generate " + output.getQualifiedName());
- }
-
String prefix = getConstantPrefix(input, DEFAULT_CONSTANT_PREFIX);
setConstantPrefix(prefix);
@@ -171,29 +159,22 @@
Set<String> constantNames = addConstantsFromDependency(input, output);
// Get available properties
- List<ObjectModelAttribute> properties = getProperties(input);
+ List<ObjectModelAttribute> properties =
+ JpaTemplatesGeneratorUtil.getProperties(input);
- //TODO Deal with @GeneratedValue
+ // Create an id property
ObjectModelAttributeImpl idAttr = new ObjectModelAttributeImpl();
idAttr.setDeclaringElement(input);
- idAttr.setName("id");
+ idAttr.setName(PROPERTY_ID);
idAttr.setType(String.class.getName());
- properties.add(idAttr);
+ properties.add(0, idAttr);
- //TODO Add attribute id (+ @Id)
- //TODO 1 -> 1 @OnetoOne (uniquement navigeable sans bidi) si composition (Cascade = ALL) si aggregeation Cascade = (tout sauf ALL TODO A check) + orphanRemoval = true)
- //TODO * -> 1 @ManyToOne (uniquement navigeable sans bidi) si composition (Cascade = ALL) si aggregeation Cascade = (tout sauf ALL TODO A check) + orphanRemoval = true)
- //TODO 1 -> * @OneToMany (uniquement navigeable sans bidi) si composition (Cascade = ALL) si aggregeation Cascade = (tout sauf ALL TODO A check) + orphanRemoval = true)
- //TODO * -> * @ManyToMany (uniquement navigeable sans bidi) si composition (Cascade = ALL) si aggregeation Cascade = (tout sauf ALL TODO A check) + orphanRemoval = true)
-
//TODO Si ORDERED ou et UNIQUE choisir le bon type de collection (O+U = LHS (laisser ça comme definition), (U = HS + S), (O = ArrayList +L), ( = ArrayList + C)
- //TODO Si ORDERED ajouter l'annotation @OrderColumn
//TODO Si enumeration @Enumeration(value = EnumType.STRING) (Voir pour mettre une tag-value pour mettre en ordinal) + voir comment ça marche pour les collections
Multimap<ObjectModelAttribute, String> annotationsForAttributes =
generateAnnotationsForProperties(input, output, properties);
-
// Add properties constant
for (ObjectModelAttribute attr : properties) {
@@ -206,18 +187,48 @@
createProperty(output, attr, annotationsForAttributes.get(attr));
}
- boolean hasAMultipleProperty = containsMutiple(properties);
+ boolean hasAMultipleProperty =
+ JpaTemplatesGeneratorUtil.containsMutiple(properties);
// Add helper operations
if (hasAMultipleProperty) {
-
// add getChild methods
createGetChildMethod(output);
}
+
+ if (isVerbose()) {
+ log.info("will generate " + output.getQualifiedName());
+ }
return output;
}
+ protected ObjectModelClass generateImpl(ObjectModelClass input,
+ String packageName,
+ String entityAbstractName,
+ String entityConcreteName) {
+
+ ObjectModelClass output = createClass(entityConcreteName, packageName);
+
+ setSuperClass(output, entityAbstractName);
+
+ // add Entity annotation
+ addAnnotation(output, Entity.class);
+
+ // add a fix serialVersionUID, since the class has no field nor method
+ addConstant(output,
+ JpaTemplatesGeneratorUtil.SERIAL_VERSION_UID,
+ "long",
+ "1L",
+ ObjectModelJavaModifier.PRIVATE
+ );
+
+ if (isVerbose()) {
+ log.info("will generate " + output.getQualifiedName());
+ }
+ return output;
+ }
+
protected Multimap<ObjectModelAttribute, String> generateAnnotationsForProperties(ObjectModelClass input,
ObjectModelClass output,
List<ObjectModelAttribute> properties) {
@@ -227,10 +238,12 @@
for (ObjectModelAttribute property : properties) {
String propertyName = property.getName();
String propertyType = property.getType();
- if ("id".equals(propertyName)) {
+ if (PROPERTY_ID.equals(propertyName)) {
- result.put(property, Id.class.getSimpleName());
- addImport(output, Id.class);
+ addAnnotation(result, property, output, Id.class);
+ if (JpaTemplatesGeneratorUtil.hasGeneratedValueStereotype(input)) {
+ addAnnotation(result, property, output, GeneratedValue.class);
+ }
continue;
}
@@ -243,34 +256,61 @@
boolean bidirection = reverseAttribute != null &&
reverseAttribute.isNavigable();
- //TODO Deal with bidirection
- Preconditions.checkState(
- !bidirection,
- "Still can not deal with bidirection, but found one " + input.getQualifiedName() + "#" + propertyName);
+ boolean isInverse = false;
+ if (bidirection) {
+
+
+ // compute which is master of relation
+ String inverseValue = JpaTemplatesGeneratorUtil.getInverseTagValue(property);
+ if (StringUtils.isNotEmpty(inverseValue)) {
+ isInverse &= Boolean.parseBoolean(inverseValue);
+ // Si aucun tagvalue n'est défini, le choix est arbitraire : le
+ // premier attribut dans l'ordre alphabétique sera choisi pour porter le
+ // inverse="true"
+ } else {
+ isInverse &= JpaTemplatesGeneratorUtil.isFirstAttribute(property);
+ }
+ }
+
+ boolean composite = property.isComposite();
+
boolean entity = isEntity(input, propertyType);
boolean enumeration = getModel().getEnumeration(propertyType) != null;
if (JpaTemplatesGeneratorUtil.isNMultiplicity(property)) {
+ List<String> annotationParams = Lists.newArrayList();
+
+ if (composite) {
+ annotationParams.add("cascade = CascadeType.ALL");
+ annotationParams.add("orphanRemoval = true");
+ addImport(output, CascadeType.class);
+ }
+
+ if (bidirection && !isInverse) {
+
+ // add the mappedBy parameter
+ annotationParams.add("mappedBy = " + reverseAttribute.getName());
+ }
+
if (nMultiplicity) {
// * -> * (ManyToMany)
- result.put(property, ManyToMany.class.getSimpleName());
- addImport(output, ManyToMany.class);
+ addAnnotation(result, property, output, ManyToMany.class, annotationParams.toArray(new String[annotationParams.size()]));
+
} else {
// 0..1 -> * (OneToMany)
- result.put(property, OneToMany.class.getSimpleName());
- addImport(output, OneToMany.class);
+ addAnnotation(result, property, output, OneToMany.class, annotationParams.toArray(new String[annotationParams.size()]));
}
- boolean withOrdererStereotype = property.isOrdered() ||
+ boolean withOrdererStereotype =
+ property.isOrdered() ||
JpaTemplatesGeneratorUtil.hasOrderedStereotype(property);
if (withOrdererStereotype) {
- result.put(property, OrderColumn.class.getSimpleName());
- addImport(output, OrderColumn.class);
+ addAnnotation(result, property, output, OrderColumn.class);
}
continue;
}
@@ -278,8 +318,8 @@
if (enumeration) {
// is an enumeration
- result.put(property, Enumerated.class.getSimpleName() + "( value = " + EnumType.class.getSimpleName() + "." + EnumType.STRING + ")");
- addImport(output, Enumerated.class);
+ addAnnotation(result, property, output, Enumerated.class,
+ "value = EnumType.STRING");
addImport(output, EnumType.class);
}
@@ -288,13 +328,11 @@
if (nMultiplicity) {
// * -> 0..1 (ManyToOne)
- result.put(property, ManyToOne.class.getSimpleName());
- addImport(output, ManyToOne.class);
+ addAnnotation(result, property, output, ManyToOne.class);
} else {
// 0..1 -> 0..1 (OneToOne)
- result.put(property, OneToOne.class.getSimpleName());
- addImport(output, OneToOne.class);
+ addAnnotation(result, property, output, OneToOne.class);
}
continue;
@@ -306,30 +344,18 @@
return result;
}
- protected ObjectModelClass generateImpl(ObjectModelClass input,
- String entityAbstractName,
- String entityConcreteName) {
-
- ObjectModelClass output = createClass(
- entityConcreteName,
- input.getPackageName()
- );
-
- // set the abstract resulClass as the resultClassImpl super class
- setSuperClass(output, entityAbstractName);
-
- // add Entity annotation
- addAnnotation(output, output, Entity.class.getSimpleName());
- addImport(output, Entity.class);
-
- // add a fix serialVersionUID, since the class has no field nor method
- addConstant(output,
- JpaTemplatesGeneratorUtil.SERIAL_VERSION_UID,
- "long",
- "1L",
- ObjectModelJavaModifier.PRIVATE
- );
- return output;
+ protected void addAnnotation(
+ ListMultimap<ObjectModelAttribute, String> result,
+ ObjectModelAttribute property,
+ ObjectModelClass output,
+ Class annotation,
+ String... extraPart) {
+ String annotationStr = annotation.getSimpleName();
+ if (extraPart.length > 0) {
+ annotationStr += "(" + Joiner.on(',').join(extraPart) + ")";
+ }
+ result.put(property, annotationStr);
+ addImport(output, annotation);
}
protected void createProperty(ObjectModelClass output,
@@ -338,8 +364,8 @@
boolean usePCS = false;
- String attrName = getAttributeName(attr);
- String attrType = getAttributeType(attr);
+ String attrName = JpaTemplatesGeneratorUtil.getAttributeName(attr);
+ String attrType = JpaTemplatesGeneratorUtil.getAttributeType(attr);
boolean multiple = JpaTemplatesGeneratorUtil.isNMultiplicity(attr);
@@ -404,29 +430,10 @@
usePCS
);
- boolean ordered = attr.isOrdered() ||
- JpaTemplatesGeneratorUtil.hasOrderedStereotype(attr);
- boolean unique = JpaTemplatesGeneratorUtil.hasUniqueStereotype(attr);
-
// Change type for Multiple attribute
- if (ordered) {
+ Class<?> collectionType = JpaTemplatesGeneratorUtil.getCollectionType(attr);
+ attrType = collectionType.getName() + "<" + attrType + ">";
- if (unique) {
-
- attrType = LinkedHashSet.class.getName() + "<" + attrType + ">";
- } else {
-
- attrType = List.class.getName() + "<" + attrType + ">";
- }
- } else {
-
- if (unique) {
- attrType = Set.class.getName() + "<" + attrType + ">";
- } else {
- attrType = Collection.class.getName() + "<" + attrType + ">";
- }
- }
-
simpleType = JpaTemplatesGeneratorUtil.getSimpleName(attrType);
}
@@ -444,12 +451,16 @@
if (multiple || !booleanProperty) {
- createGetMethod(output,
- attrName,
- attrType,
- JpaTemplatesGeneratorUtil.OPERATION_GETTER_DEFAULT_PREFIX
+ ObjectModelOperation getMethod = createGetMethod(output,
+ attrName,
+ attrType,
+ JpaTemplatesGeneratorUtil.OPERATION_GETTER_DEFAULT_PREFIX
);
+ if (PROPERTY_ID.equals(attrName)) {
+ addAnnotation(output, getMethod, Override.class);
+ }
+
}
createSetMethod(output,
attrName,
@@ -473,4 +484,312 @@
}
+ protected ObjectModelOperation createGetMethod(ObjectModelClass output,
+ String attrName,
+ String attrType,
+ String methodPrefix) {
+
+ ObjectModelOperation operation = addOperation(
+ output,
+ getJavaBeanMethodName(methodPrefix, attrName),
+ attrType,
+ ObjectModelJavaModifier.PUBLIC
+ );
+ setOperationBody(operation, ""
+ /*{
+ return <%=attrName%>;
+ }*/
+ );
+ return operation;
+ }
+
+ protected void createGetChildMethod(ObjectModelClass output,
+ String attrName,
+ String attrType,
+ String simpleType) {
+ ObjectModelOperation operation = addOperation(
+ output,
+ getJavaBeanMethodName("get", attrName),
+ attrType,
+ ObjectModelJavaModifier.PUBLIC
+ );
+ addParameter(operation, "int", "index");
+ setOperationBody(operation, ""
+ /*{
+ <%=simpleType%> o = getChild(<%=attrName%>, index);
+ return o;
+ }*/
+ );
+ }
+
+ protected void createIsEmptyMethod(ObjectModelClass output,
+ String attrName) {
+ ObjectModelOperation operation = addOperation(
+ output,
+ getJavaBeanMethodName("is", attrName) + "Empty",
+ boolean.class,
+ ObjectModelJavaModifier.PUBLIC
+ );
+ setOperationBody(operation, ""
+ /*{
+ return <%=attrName%> == null || <%=attrName%>.isEmpty();
+ }*/
+ );
+ }
+
+ protected void createSizeMethod(ObjectModelClass output,
+ String attrName) {
+ ObjectModelOperation operation = addOperation(
+ output,
+ getJavaBeanMethodName("size", attrName),
+ int.class,
+ ObjectModelJavaModifier.PUBLIC
+ );
+ setOperationBody(operation, ""
+ /*{
+ return <%=attrName%> == null ? 0 : <%=attrName%>.size();
+ }*/
+ );
+ }
+
+ protected void createAddChildMethod(ObjectModelClass output,
+ String attrName,
+ String attrType,
+ String constantName,
+ boolean usePCS) {
+ ObjectModelOperation operation = addOperation(
+ output,
+ getJavaBeanMethodName("add", attrName),
+ "void",
+ ObjectModelJavaModifier.PUBLIC
+ );
+ addParameter(operation, attrType, attrName);
+
+ String methodName = getJavaBeanMethodName("get", attrName);
+ StringBuilder buffer = new StringBuilder(""
+ /*{
+ <%=methodName%>().add(<%=attrName%>);
+ }*/
+ );
+ if (usePCS) {
+ buffer.append(""
+ /*{ firePropertyChange(<%=constantName%>, null, <%=attrName%>);
+ }*/
+ );
+ }
+ setOperationBody(operation, buffer.toString());
+ }
+
+ protected void createAddAllChildrenMethod(ObjectModelClass output,
+ String attrName,
+ String attrType,
+ String constantName,
+ boolean usePCS) {
+ ObjectModelOperation operation = addOperation(
+ output,
+ getJavaBeanMethodName("addAll", attrName),
+ "void",
+ ObjectModelJavaModifier.PUBLIC
+ );
+ addParameter(operation, Collection.class.getName() + "<" + attrType + ">", attrName);
+
+ String methodName = getJavaBeanMethodName("get", attrName);
+ StringBuilder buffer = new StringBuilder(""
+ /*{
+ <%=methodName%>().addAll(<%=attrName%>);
+ }*/
+ );
+ if (usePCS) {
+ buffer.append(""
+ /*{ firePropertyChange(<%=constantName%>, null, <%=attrName%>);
+ }*/
+ );
+ }
+ setOperationBody(operation, buffer.toString());
+ }
+
+ protected void createRemoveChildMethod(ObjectModelClass output,
+ String attrName,
+ String attrType,
+ String constantName,
+ boolean usePCS) {
+ ObjectModelOperation operation = addOperation(
+ output,
+ getJavaBeanMethodName("remove", attrName),
+ "boolean",
+ ObjectModelJavaModifier.PUBLIC
+ );
+ addParameter(operation, attrType, attrName);
+ String methodName = getJavaBeanMethodName("get", attrName);
+ StringBuilder buffer = new StringBuilder();
+ buffer.append(""
+ /*{
+ boolean removed = <%=methodName%>().remove(<%=attrName%>);}*/
+ );
+
+ if (usePCS) {
+ buffer.append(""
+ /*{
+ if (removed) {
+ firePropertyChange(<%=constantName%>, <%=attrName%>, null);
+ }}*/
+ );
+ }
+ buffer.append(""
+ /*{
+ return removed;
+ }*/
+ );
+ setOperationBody(operation, buffer.toString());
+ }
+
+ protected void createRemoveAllChildrenMethod(ObjectModelClass output,
+ String attrName,
+ String attrType,
+ String constantName,
+ boolean usePCS) {
+
+ ObjectModelOperation operation = addOperation(
+ output,
+ getJavaBeanMethodName("removeAll", attrName),
+ "boolean",
+ ObjectModelJavaModifier.PUBLIC
+ );
+ addParameter(operation, "java.util.Collection<" + attrType + ">", attrName);
+ StringBuilder buffer = new StringBuilder();
+ String methodName = getJavaBeanMethodName("get", attrName);
+ buffer.append(""
+ /*{
+ boolean removed = <%=methodName%>().removeAll(<%=attrName%>);}*/
+ );
+
+ if (usePCS) {
+ buffer.append(""
+ /*{
+ if (removed) {
+ firePropertyChange(<%=constantName%>, <%=attrName%>, null);
+ }}*/
+ );
+ }
+ buffer.append(""
+ /*{
+ return removed;
+ }*/
+ );
+ setOperationBody(operation, buffer.toString());
+ }
+
+ protected void createContainsChildMethod(ObjectModelClass output,
+ String attrName,
+ String attrType,
+ String constantName,
+ boolean usePCS) {
+
+ ObjectModelOperation operation = addOperation(
+ output,
+ getJavaBeanMethodName("contains", attrName),
+ "boolean",
+ ObjectModelJavaModifier.PUBLIC
+ );
+ addParameter(operation, attrType, attrName);
+ StringBuilder buffer = new StringBuilder();
+ String methodName = getJavaBeanMethodName("get", attrName);
+ buffer.append(""
+ /*{
+ boolean contains = <%=methodName%>().contains(<%=attrName%>);
+ return contains;
+ }*/
+ );
+ setOperationBody(operation, buffer.toString());
+ }
+
+ protected void createContainsAllChildrenMethod(ObjectModelClass output,
+ String attrName,
+ String attrType,
+ String constantName,
+ boolean usePCS) {
+
+ ObjectModelOperation operation = addOperation(
+ output,
+ getJavaBeanMethodName("containsAll", attrName),
+ "boolean",
+ ObjectModelJavaModifier.PUBLIC
+ );
+ addParameter(operation, Collection.class.getName() + "<" + attrType + ">", attrName);
+ StringBuilder buffer = new StringBuilder();
+ String methodName = getJavaBeanMethodName("get", attrName);
+ buffer.append(""
+ /*{
+ boolean contains = <%=methodName%>().containsAll(<%=attrName%>);
+ return contains;
+ }*/
+ );
+ setOperationBody(operation, buffer.toString());
+ }
+
+ protected void createSetMethod(ObjectModelClass output,
+ String attrName,
+ String attrType,
+ String simpleType,
+ String constantName,
+ boolean usePCS) {
+ ObjectModelOperation operation = addOperation(
+ output,
+ getJavaBeanMethodName("set", attrName),
+ "void",
+ ObjectModelJavaModifier.PUBLIC
+ );
+ addParameter(operation, attrType, attrName);
+
+ if (usePCS) {
+ String methodName = getJavaBeanMethodName("get", attrName);
+ setOperationBody(operation, ""
+ /*{
+ <%=simpleType%> oldValue = <%=methodName%>();
+ this.<%=attrName%> = <%=attrName%>;
+ firePropertyChange(<%=constantName%>, oldValue, <%=attrName%>);
+ }*/
+ );
+ } else {
+ setOperationBody(operation, ""
+ /*{
+ this.<%=attrName%> = <%=attrName%>;
+ }*/
+ );
+ }
+ }
+
+ protected void createGetChildMethod(ObjectModelClass output) {
+ ObjectModelOperation getChild = addOperation(
+ output,
+ "getChild", "<T> T",
+ ObjectModelJavaModifier.PROTECTED
+ );
+ addImport(output, List.class);
+
+ addParameter(getChild, "java.util.Collection<T>", "childs");
+ addParameter(getChild, "int", "index");
+ setOperationBody(getChild, ""
+ /*{
+ T result = null;
+ if (childs != null) {
+ if (childs instanceof List) {
+ if (index < childs.size()) {
+ result = ((List<T>) childs).get(index);
+ }
+ } else {
+ int i = 0;
+ for (T o : childs) {
+ if (index == i) {
+ result = o;
+ break;
+ }
+ i++;
+ }
+ }
+ }
+ return result;
+ }*/
+ );
+ }
}
\ No newline at end of file
Modified: nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaPersistenceContextTransformer.java
===================================================================
--- nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaPersistenceContextTransformer.java 2013-05-24 22:19:58 UTC (rev 627)
+++ nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaPersistenceContextTransformer.java 2013-05-25 14:13:01 UTC (rev 628)
@@ -33,6 +33,13 @@
/*{generator option: writeString = +}*/
/**
+ * JpaPersistenceContextTransformer generates the persistence context for an model.
+ * <ul>
+ * <li>{@code AbstractXXXJpaPersistenceContext}: abstract jpa persistence context with all the technical stuff</li>
+ * <li>{@code XXXJpaPersistenceContext}: concrete public jpa persistence context to use in your persistence layer</li>
+ * </ul>
+ * {@code Note:} All classes found in class-path are not generated.
+ * <p/>
* TODO Liste des entités (A voir meta-modèle...)
*
* @author tchemit <chemit(a)codelutin.com>
@@ -44,20 +51,29 @@
@Override
public void transformFromModel(ObjectModel model) {
- String className = "Jpa" + model.getName() + "PersistenceContext";
+ String packageName = JpaTemplatesGeneratorUtil.getPersistenceContextPackage(this, model);
- String packageName =
- getOutputProperties().getProperty(PROP_DEFAULT_PACKAGE);
+ String entityAbstractName = JpaTemplatesGeneratorUtil.getPersistenceContextAbstractName(model);
- boolean generateAbstract = !isInClassPath(packageName, className);
+ String entityConcreteName = JpaTemplatesGeneratorUtil.getPersistenceContextConcreteName(model);
+ boolean generateAbstract = !isInClassPath(packageName, entityAbstractName);
+
+ boolean generateConcrete = !isInClassPath(packageName, entityConcreteName);
+
if (generateAbstract) {
- generate(packageName, className);
+ generateAbstract(packageName, entityAbstractName);
}
+
+ if (generateConcrete) {
+
+ generateImpl(packageName, entityAbstractName, entityConcreteName);
+ }
}
- protected void generate(String packageName, String className) {
+ protected void generateAbstract(String packageName,
+ String className) {
// try to find a super class by tag-value
String superClass = JpaTemplatesGeneratorUtil.getPersistenceContextSuperClassTagValue(
@@ -69,30 +85,44 @@
superClass = AbstractJpaPersistenceContext.class.getName();
}
- ObjectModelClass output = createClass(className, packageName);
+ ObjectModelClass output = createAbstractClass(className, packageName);
setSuperClass(output, superClass);
addConstructorWithEntityManager(output);
+ // add dao factories
for (ObjectModelClass aClass : getModel().getClasses()) {
- if (packageName.equals(aClass.getPackageName())) {
+ //FIXME Find a way to exclude none entities classes
+// if (packageName.equals(aClass.getPackageName())) {
- // add dao factory method
- String daoConcreteName = JpaTemplatesGeneratorUtil.getDaoConcreteName(aClass);
+ // add dao factory method
+ String daoPackageName = JpaTemplatesGeneratorUtil.getDaoPackage(this, model, aClass);
+ String daoConcreteName = JpaTemplatesGeneratorUtil.getDaoConcreteName(aClass);
- ObjectModelOperation operation = addOperation(
- output,
- "get" + daoConcreteName,
- packageName + "." + daoConcreteName);
- setOperationBody(operation, ""
+ ObjectModelOperation operation = addOperation(
+ output,
+ "get" + aClass.getName() + "Dao",
+ daoPackageName + "." + daoConcreteName);
+ setOperationBody(operation, ""
/*{
return new <%=daoConcreteName%>(entityManager);
}*/
- );
-
- }
+ );
+// }
}
}
+
+ protected ObjectModelClass generateImpl(String packageName,
+ String entityAbstractName,
+ String entityConcreteName) {
+
+ ObjectModelClass output = createClass(entityConcreteName, packageName);
+
+ setSuperClass(output, entityAbstractName);
+
+ addConstructorWithEntityManager(output);
+ return output;
+ }
}
Modified: nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaTemplatesGeneratorUtil.java
===================================================================
--- nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaTemplatesGeneratorUtil.java 2013-05-24 22:19:58 UTC (rev 627)
+++ nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaTemplatesGeneratorUtil.java 2013-05-25 14:13:01 UTC (rev 628)
@@ -30,6 +30,12 @@
import org.nuiton.eugene.models.object.ObjectModelClass;
import org.nuiton.eugene.models.object.ObjectModelClassifier;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Set;
+
/**
* Utility class for pure jpa templates.
*
@@ -38,10 +44,157 @@
*/
public class JpaTemplatesGeneratorUtil extends JavaGeneratorUtil {
+ public static String getPersistenceContextPackage(AbstractJpaTransformer transformer,
+ ObjectModel model) {
+
+ String result = getPersistenceContextPackageTagValue(model);
+ if (result == null) {
+
+ // use default package
+ result = transformer.getDefaultPackageName();
+ }
+
+ return result;
+ }
+
+ public static String getEntityPackage(AbstractJpaTransformer transformer,
+ ObjectModel model,
+ ObjectModelClassifier input) {
+
+ String result = getEntityPackageTagValue(model, input);
+ if (result == null) {
+
+ // use default package
+ result = transformer.getDefaultPackageName() + ".entity";
+ }
+
+ return result;
+ }
+
+ public static String getDaoPackage(AbstractJpaTransformer transformer,
+ ObjectModel model,
+ ObjectModelClassifier input) {
+
+ String result = getDaoPackageTagValue(model, input);
+ if (result == null) {
+
+ // use default package
+ result = transformer.getDefaultPackageName() + ".dao";
+ }
+
+ return result;
+ }
+
+ public static String getPersistenceContextAbstractName(ObjectModel model) {
+ return "AbstractJpa" + model.getName() + "PersistenceContext";
+ }
+
+ public static String getPersistenceContextConcreteName(ObjectModel model) {
+ return "Jpa" + model.getName() + "PersistenceContext";
+ }
+
+ public static String getEntityAbstractName(ObjectModelClass input) {
+ return "AbstractJpa" + input.getName();
+ }
+
+ public static String getEntityConcreteName(ObjectModelClass input) {
+ return input.getName();
+ }
+
+ public static String getDaoAbstractName(ObjectModelClass input) {
+ return "Abstract" + input.getName() + "JpaDao";
+ }
+
public static String getDaoConcreteName(ObjectModelClass input) {
return input.getName() + "JpaDao";
}
+ public static String getConcreteEntityQualifiedName(AbstractJpaTransformer transformer, ObjectModel model, ObjectModelClass input) {
+ return getEntityPackage(transformer, model, input) + "." + getEntityConcreteName(input);
+ }
+
+ public static String getConcreteDaoQualifiedName(AbstractJpaTransformer transformer, ObjectModel model, ObjectModelClass input) {
+ return getDaoPackage(transformer, model, input) + "." + getDaoConcreteName(input);
+ }
+
+ public static Class<?> getCollectionType(ObjectModelAttribute attr) {
+
+ boolean ordered = attr.isOrdered() ||
+ JpaTemplatesGeneratorUtil.hasOrderedStereotype(attr);
+ boolean unique = JpaTemplatesGeneratorUtil.hasUniqueStereotype(attr);
+
+ // Change type for Multiple attribute
+ Class<?> result;
+
+ if (ordered) {
+
+ if (unique) {
+
+ result = LinkedHashSet.class;
+ } else {
+
+ result = List.class;
+ }
+ } else {
+
+ if (unique) {
+ result = Set.class;
+ } else {
+ result = Collection.class;
+ }
+ }
+ return result;
+ }
+
+ public static boolean containsMutiple(List<ObjectModelAttribute> attributes) {
+
+ boolean result = false;
+
+ for (ObjectModelAttribute attr : attributes) {
+
+ if (isNMultiplicity(attr)) {
+ result = true;
+
+ break;
+ }
+
+ }
+ return result;
+ }
+
+ public static String getAttributeName(ObjectModelAttribute attr) {
+ String attrName = attr.getName();
+ if (attr.hasAssociationClass()) {
+ String assocAttrName = getAssocAttrName(attr);
+ attrName = toLowerCaseFirstLetter(assocAttrName);
+ }
+ return attrName;
+ }
+
+ public static String getAttributeType(ObjectModelAttribute attr) {
+ String attrType = attr.getType();
+ if (attr.hasAssociationClass()) {
+ attrType = attr.getAssociationClass().getName();
+ }
+ return attrType;
+ }
+
+ public static List<ObjectModelAttribute> getProperties(ObjectModelClass input) {
+ List<ObjectModelAttribute> attributes =
+ (List<ObjectModelAttribute>) input.getAttributes();
+
+ List<ObjectModelAttribute> attrs =
+ new ArrayList<ObjectModelAttribute>();
+ for (ObjectModelAttribute attr : attributes) {
+ if (attr.isNavigable()) {
+
+ // only keep navigable attributes
+ attrs.add(attr);
+ }
+ }
+ return attrs;
+ }
+
/**
* Obtain the value of the {@link JpaTemplatesTagValues#TAG_ENTITY_SUPER_CLASS}
* tag value on the given model or classifier.
@@ -60,6 +213,24 @@
}
/**
+ * Obtain the value of the {@link JpaTemplatesTagValues#TAG_ENTITY_PACKAGE}
+ * tag value on the given model.
+ * <p/>
+ * It will first look on the model, and then in the given classifier.
+ *
+ * @param model model to seek
+ * @param classifier classifier to seek
+ * @return the none empty value of the found tag value or {@code null} if not found nor empty.
+ * @see JpaTemplatesTagValues#TAG_ENTITY_PACKAGE
+ * @since 2.3
+ */
+ public static String getEntityPackageTagValue(ObjectModel model,
+ ObjectModelClassifier classifier) {
+ String value = findTagValue(JpaTemplatesTagValues.TAG_ENTITY_PACKAGE, classifier, model);
+ return value;
+ }
+
+ /**
* Obtain the value of the {@link JpaTemplatesTagValues#TAG_DAO_SUPER_CLASS}
* tag value on the given model or classifier.
* <p/>
@@ -77,6 +248,24 @@
}
/**
+ * Obtain the value of the {@link JpaTemplatesTagValues#TAG_DAO_PACKAGE}
+ * tag value on the given model.
+ * <p/>
+ * It will first look on the model, and then in the given classifier.
+ *
+ * @param model model to seek
+ * @param classifier classifier to seek
+ * @return the none empty value of the found tag value or {@code null} if not found nor empty.
+ * @see JpaTemplatesTagValues#TAG_DAO_PACKAGE
+ * @since 2.3
+ */
+ public static String getDaoPackageTagValue(ObjectModel model,
+ ObjectModelClassifier classifier) {
+ String value = findTagValue(JpaTemplatesTagValues.TAG_DAO_PACKAGE, classifier, model);
+ return value;
+ }
+
+ /**
* Obtain the value of the {@link JpaTemplatesTagValues#TAG_PERSISTENCE_CONTEXT_SUPER_CLASS}
* tag value on the given model.
*
@@ -91,6 +280,36 @@
}
/**
+ * Obtain the value of the {@link JpaTemplatesTagValues#TAG_PERSISTENCE_CONTEXT_PACKAGE}
+ * tag value on the given model.
+ * <p/>
+ *
+ * @param model model to seek
+ * @return the none empty value of the found tag value or {@code null} if not found nor empty.
+ * @see JpaTemplatesTagValues#TAG_PERSISTENCE_CONTEXT_PACKAGE
+ * @since 2.3
+ */
+ public static String getPersistenceContextPackageTagValue(ObjectModel model) {
+ String value = findTagValue(JpaTemplatesTagValues.TAG_PERSISTENCE_CONTEXT_PACKAGE, null, model);
+ return value;
+ }
+
+ /**
+ * Obtain the value of the {@link JpaTemplatesTagValues#TAG_INVERSE}
+ * tag value on the given attribute.
+ * <p/>
+ *
+ * @param attribute attribute to seek
+ * @return the none empty value of the found tag value or {@code null} if not found nor empty.
+ * @see JpaTemplatesTagValues#TAG_INVERSE
+ * @since 2.5
+ */
+ public static String getInverseTagValue(ObjectModelAttribute attribute) {
+ String value = findTagValue(JpaTemplatesTagValues.TAG_INVERSE, attribute, null);
+ return value;
+ }
+
+ /**
* Check if the given attribute has the
* {@link JpaTemplatesStereoTypes#STEREOTYPE_UNIQUE} stereotype.
*
@@ -102,4 +321,17 @@
public static boolean hasUniqueStereotype(ObjectModelAttribute attribute) {
return attribute.hasStereotype(JpaTemplatesStereoTypes.STEREOTYPE_UNIQUE);
}
+
+ /**
+ * Check if the given class has the
+ * {@link JpaTemplatesStereoTypes#STEREOTYPE_GENERATED_VALUE} stereotype.
+ *
+ * @param aClass class to test
+ * @return {@code true} if stereotype was found, {@code false otherwise}
+ * @see JpaTemplatesStereoTypes#STEREOTYPE_GENERATED_VALUE
+ * @since 2.5
+ */
+ public static boolean hasGeneratedValueStereotype(ObjectModelClassifier aClass) {
+ return aClass.hasStereotype(JpaTemplatesStereoTypes.STEREOTYPE_GENERATED_VALUE);
+ }
}
Modified: nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaTemplatesStereoTypes.java
===================================================================
--- nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaTemplatesStereoTypes.java 2013-05-24 22:19:58 UTC (rev 627)
+++ nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaTemplatesStereoTypes.java 2013-05-25 14:13:01 UTC (rev 628)
@@ -27,7 +27,10 @@
import org.nuiton.eugene.EugeneStereoTypes;
import org.nuiton.eugene.ModelPropertiesUtil;
import org.nuiton.eugene.models.object.ObjectModelAttribute;
+import org.nuiton.eugene.models.object.ObjectModelClassifier;
+import javax.persistence.GeneratedValue;
+
/**
* Defines all stereotypes managed by JPA templates.
*
@@ -44,4 +47,13 @@
@ModelPropertiesUtil.StereotypeDefinition(target = ObjectModelAttribute.class,
documentation = "To specify that an attribute is unique (JPA mapping)")
String STEREOTYPE_UNIQUE = "unique";
+
+ /**
+ * Stéréotype pour ajouter l'annoation {@link GeneratedValue} sur l'id.
+ *
+ * @see JpaTemplatesGeneratorUtil#hasGeneratedValueStereotype(ObjectModelClassifier)
+ */
+ @ModelPropertiesUtil.StereotypeDefinition(target = ObjectModelClassifier.class,
+ documentation = "To specify that an entity has a generated id (see GeneratedValue annotation) (JPA mapping)")
+ String STEREOTYPE_GENERATED_VALUE = "generatedValue";
}
Modified: nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaTemplatesTagValues.java
===================================================================
--- nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaTemplatesTagValues.java 2013-05-24 22:19:58 UTC (rev 627)
+++ nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaTemplatesTagValues.java 2013-05-25 14:13:01 UTC (rev 628)
@@ -27,6 +27,7 @@
import org.nuiton.eugene.EugeneTagValues;
import org.nuiton.eugene.ModelPropertiesUtil;
import org.nuiton.eugene.models.object.ObjectModel;
+import org.nuiton.eugene.models.object.ObjectModelAttribute;
import org.nuiton.eugene.models.object.ObjectModelClassifier;
/**
@@ -49,6 +50,16 @@
"for a class or any class of a model")
String TAG_ENTITY_SUPER_CLASS = "entitySuperClass";
+ /**
+ * Tag value to specify where to generate entities.
+ *
+ * @see JpaTemplatesGeneratorUtil#getEntityPackage(ObjectModel)
+ * @since 0.1
+ */
+ @ModelPropertiesUtil.TagValueDefinition(
+ target = {ObjectModel.class},
+ documentation = "To specify the package where to generate entities")
+ String TAG_ENTITY_PACKAGE = "entityPackage";
/**
* Tag value to use a super class for generated bean.
@@ -62,6 +73,16 @@
"for a class or any class of a model")
String TAG_DAO_SUPER_CLASS = "daoSuperClass";
+ /**
+ * Tag value to specify where to generate daos.
+ *
+ * @see JpaTemplatesGeneratorUtil#getDaoPackage(ObjectModel)
+ * @since 0.1
+ */
+ @ModelPropertiesUtil.TagValueDefinition(
+ target = {ObjectModel.class},
+ documentation = "To specify the package where to generate daos")
+ String TAG_DAO_PACKAGE = "daoPackage";
/**
* Tag value to use a super class for generated bean.
@@ -72,6 +93,31 @@
@ModelPropertiesUtil.TagValueDefinition(
target = {ObjectModel.class},
documentation = "To specify a super-class to used on generated persistence context")
- String TAG_PERSISTENCE_CONTEXT_SUPER_CLASS = "daoSuperClass";
+ String TAG_PERSISTENCE_CONTEXT_SUPER_CLASS = "persistenceContextSuperClass";
+ /**
+ * Tag value to specify where to generate persistenceContexts.
+ *
+ * @see JpaTemplatesGeneratorUtil#getPersistenceContextPackage(ObjectModel)
+ * @since 0.1
+ */
+ @ModelPropertiesUtil.TagValueDefinition(
+ target = {ObjectModel.class},
+ documentation = "To specify the package where to generate persistenceContexts")
+ String TAG_PERSISTENCE_CONTEXT_PACKAGE = "persistenceContextPackage";
+
+
+ /**
+ * Tag pour permettre de choisir qui contrôle la relation N-N
+ * bidirectionnelle. On a inverse=true sur le père de la relation..
+ * <p/>
+ * Par défaut le inverse=true est placé sur le premier rôle trouvé dans
+ * l'ordre alphabétique.
+ *
+ * @see JpaTemplatesGeneratorUtil#getInverseTagValue(ObjectModelAttribute)
+ * @since 2.5
+ */
+ @ModelPropertiesUtil.TagValueDefinition(target = {ObjectModelAttribute.class},
+ documentation = "Sets which part of a N-N relation is master (inverse=true) and slave (inverse=false) (must be put on each side on a such relation) (Hibernate mapping)")
+ String TAG_INVERSE = "inverse";
}
Modified: nuiton-jpa/pom.xml
===================================================================
--- nuiton-jpa/pom.xml 2013-05-24 22:19:58 UTC (rev 627)
+++ nuiton-jpa/pom.xml 2013-05-25 14:13:01 UTC (rev 628)
@@ -31,6 +31,8 @@
<!-- pour un muli module on doit fixer le projectId -->
<projectId>nuiton-jpa</projectId>
+ <redmine.skipGenerateChanges>true</redmine.skipGenerateChanges>
+
<!-- libs version -->
<eugeneVersion>2.6.3-SNAPSHOT</eugeneVersion>
<nuitonUtilsVersion>2.6.12</nuitonUtilsVersion>
1
0
r627 - in nuiton-jpa: . nuiton-jpa-api/src/license nuiton-jpa-api/src/main/java/org/nuiton/jpa/api nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/hibernate nuiton-jpa-junit/src/license nuiton-jpa-templates/src/license nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates
by tchemit@users.nuiton.org 24 May '13
by tchemit@users.nuiton.org 24 May '13
24 May '13
Author: tchemit
Date: 2013-05-25 00:19:58 +0200 (Sat, 25 May 2013)
New Revision: 627
Url: http://nuiton.org/projects/sandbox/repository/revisions/627
Log:
fix license headers + inceptionYear
Modified:
nuiton-jpa/nuiton-jpa-api/src/license/THIRD-PARTY.properties
nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/AbstractJpaDao.java
nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/AbstractJpaEntity.java
nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/AbstractJpaPersistenceContext.java
nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/JpaDao.java
nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/hibernate/HibernateUtil.java
nuiton-jpa/nuiton-jpa-junit/src/license/THIRD-PARTY.properties
nuiton-jpa/nuiton-jpa-templates/src/license/THIRD-PARTY.properties
nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaPersistenceContextTransformer.java
nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/package-info.java
nuiton-jpa/pom.xml
Property changes on: nuiton-jpa/nuiton-jpa-api/src/license/THIRD-PARTY.properties
___________________________________________________________________
Modified: svn:keywords
- Author Date Id Revision
+ Author Date Id Revision HeadURL
Modified: nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/AbstractJpaDao.java
===================================================================
--- nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/AbstractJpaDao.java 2013-05-24 22:14:35 UTC (rev 626)
+++ nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/AbstractJpaDao.java 2013-05-24 22:19:58 UTC (rev 627)
@@ -2,7 +2,7 @@
/*
* #%L
- * MagaLiE :: Persistence
+ * nuiton-jpa-api
* $Id$
* $HeadURL$
* %%
@@ -40,7 +40,9 @@
* also commun helpers methods for implementation business-specific operations
* exposed as protected.
*
- * @author bleny, tchemit
+ * @author bleny <leny(a)codelutin.com>
+ * @author tchemit <chemit(a)codelutin.com>
+ *
* @since 0.1
*/
public abstract class AbstractJpaDao<E extends AbstractJpaEntity> implements JpaDao<E> {
Modified: nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/AbstractJpaEntity.java
===================================================================
--- nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/AbstractJpaEntity.java 2013-05-24 22:14:35 UTC (rev 626)
+++ nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/AbstractJpaEntity.java 2013-05-24 22:19:58 UTC (rev 627)
@@ -2,7 +2,7 @@
/*
* #%L
- * MagaLiE :: Persistence
+ * nuiton-jpa-api
* $Id$
* $HeadURL$
* %%
@@ -29,7 +29,8 @@
*
* Also equals() is defined for compliance with JPA expectations.
*
- * @author bleny, tchemit
+ * @author bleny <leny(a)codelutin.com>
+ * @author tchemit <chemit(a)codelutin.com>
* @since 0.1
*/
public abstract class AbstractJpaEntity {
Modified: nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/AbstractJpaPersistenceContext.java
===================================================================
--- nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/AbstractJpaPersistenceContext.java 2013-05-24 22:14:35 UTC (rev 626)
+++ nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/AbstractJpaPersistenceContext.java 2013-05-24 22:19:58 UTC (rev 627)
@@ -6,7 +6,7 @@
* $Id$
* $HeadURL$
* %%
- * Copyright (C) 20013 CodeLutin
+ * Copyright (C) 2013 CodeLutin
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
@@ -30,6 +30,7 @@
/**
* TODO
*
+ * @author bleny <leny(a)codelutin.com>
* @author tchemit <chemit(a)codelutin.com>
* @since 0.1
*/
Modified: nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/JpaDao.java
===================================================================
--- nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/JpaDao.java 2013-05-24 22:14:35 UTC (rev 626)
+++ nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/JpaDao.java 2013-05-24 22:19:58 UTC (rev 627)
@@ -31,7 +31,8 @@
*
* @param <E> is the type of the entity manipulated with this DAO
*
- * @author bleny, tchemit
+ * @author bleny <leny(a)codelutin.com>
+ * @author tchemit <chemit(a)codelutin.com>
* @since 0.1
*/
public interface JpaDao<E extends AbstractJpaEntity> {
Modified: nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/hibernate/HibernateUtil.java
===================================================================
--- nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/hibernate/HibernateUtil.java 2013-05-24 22:14:35 UTC (rev 626)
+++ nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/hibernate/HibernateUtil.java 2013-05-24 22:19:58 UTC (rev 627)
@@ -6,7 +6,7 @@
* $Id$
* $HeadURL$
* %%
- * Copyright (C) 20013 CodeLutin
+ * Copyright (C) 2013 CodeLutin
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
Property changes on: nuiton-jpa/nuiton-jpa-junit/src/license/THIRD-PARTY.properties
___________________________________________________________________
Modified: svn:keywords
- Author Date Id Revision
+ Author Date Id Revision HeadURL
Property changes on: nuiton-jpa/nuiton-jpa-templates/src/license/THIRD-PARTY.properties
___________________________________________________________________
Modified: svn:keywords
- Author Date Id Revision
+ Author Date Id Revision HeadURL
Modified: nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaPersistenceContextTransformer.java
===================================================================
--- nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaPersistenceContextTransformer.java 2013-05-24 22:14:35 UTC (rev 626)
+++ nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaPersistenceContextTransformer.java 2013-05-24 22:19:58 UTC (rev 627)
@@ -6,7 +6,7 @@
* $Id$
* $HeadURL$
* %%
- * Copyright (C) 20013 CodeLutin
+ * Copyright (C) 2013 CodeLutin
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
Modified: nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/package-info.java
===================================================================
--- nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/package-info.java 2013-05-24 22:14:35 UTC (rev 626)
+++ nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/package-info.java 2013-05-24 22:19:58 UTC (rev 627)
@@ -14,7 +14,7 @@
* $Id$
* $HeadURL$
* %%
- * Copyright (C) 20013 CodeLutin
+ * Copyright (C) 2013 CodeLutin
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
Modified: nuiton-jpa/pom.xml
===================================================================
--- nuiton-jpa/pom.xml 2013-05-24 22:14:35 UTC (rev 626)
+++ nuiton-jpa/pom.xml 2013-05-24 22:19:58 UTC (rev 627)
@@ -24,7 +24,7 @@
<name>nuiton-jpa</name>
- <inceptionYear>20013</inceptionYear>
+ <inceptionYear>2013</inceptionYear>
<url>http://maven-site.nuiton.org/nuiton-jpa</url>
<properties>
@@ -195,18 +195,6 @@
</dependencies>
</plugin>
- <plugin>
- <groupId>org.codehaus.mojo</groupId>
- <artifactId>license-maven-plugin</artifactId>
- <configuration>
- <extraExtensions>
- <objectmodel>xml</objectmodel>
- <xsl>xml</xsl>
- <xsd>xml</xsd>
- </extraExtensions>
- </configuration>
- </plugin>
-
</plugins>
</pluginManagement>
1
0
Author: tchemit
Date: 2013-05-25 00:14:35 +0200 (Sat, 25 May 2013)
New Revision: 626
Url: http://nuiton.org/projects/sandbox/repository/revisions/626
Log:
nuiton-jpa first templates (works on magalie)
Added:
nuiton-jpa/nuiton-jpa-api/src/license/
nuiton-jpa/nuiton-jpa-api/src/license/THIRD-PARTY.properties
nuiton-jpa/nuiton-jpa-junit/src/license/
nuiton-jpa/nuiton-jpa-junit/src/license/THIRD-PARTY.properties
nuiton-jpa/nuiton-jpa-templates/src/license/
nuiton-jpa/nuiton-jpa-templates/src/license/THIRD-PARTY.properties
nuiton-jpa/nuiton-jpa-templates/src/main/resources/META-INF/
nuiton-jpa/nuiton-jpa-templates/src/main/resources/META-INF/services/
nuiton-jpa/nuiton-jpa-templates/src/main/resources/META-INF/services/org.nuiton.eugene.ModelPropertiesUtil$ModelPropertiesProvider
Modified:
nuiton-jpa/LICENSE.txt
nuiton-jpa/README.txt
nuiton-jpa/changelog.txt
nuiton-jpa/nuiton-jpa-api/LICENSE.txt
nuiton-jpa/nuiton-jpa-api/README.txt
nuiton-jpa/nuiton-jpa-api/changelog.txt
nuiton-jpa/nuiton-jpa-api/pom.xml
nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/AbstractJpaDao.java
nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/AbstractJpaEntity.java
nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/AbstractJpaPersistenceContext.java
nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/JpaDao.java
nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/hibernate/HibernateUtil.java
nuiton-jpa/nuiton-jpa-junit/LICENSE.txt
nuiton-jpa/nuiton-jpa-junit/README.txt
nuiton-jpa/nuiton-jpa-junit/changelog.txt
nuiton-jpa/nuiton-jpa-junit/pom.xml
nuiton-jpa/nuiton-jpa-junit/src/main/java/org/nuiton/jpa/junit/JpaEntityManagerRule.java
nuiton-jpa/nuiton-jpa-templates/LICENSE.txt
nuiton-jpa/nuiton-jpa-templates/README.txt
nuiton-jpa/nuiton-jpa-templates/changelog.txt
nuiton-jpa/nuiton-jpa-templates/pom.xml
nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/AbstractJpaTransformer.java
nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaDaoTransformer.java
nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaEntityTransformer.java
nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaPersistenceContextTransformer.java
nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaTemplatesGeneratorUtil.java
nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaTemplatesModelPropertiesProvider.java
nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaTemplatesStereoTypes.java
nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaTemplatesTagValues.java
nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/package-info.java
nuiton-jpa/pom.xml
Modified: nuiton-jpa/LICENSE.txt
===================================================================
--- nuiton-jpa/LICENSE.txt 2013-05-24 17:35:29 UTC (rev 625)
+++ nuiton-jpa/LICENSE.txt 2013-05-24 22:14:35 UTC (rev 626)
@@ -0,0 +1,166 @@
+ GNU LESSER GENERAL PUBLIC LICENSE
+ Version 3, 29 June 2007
+
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+
+ This version of the GNU Lesser General Public License incorporates
+the terms and conditions of version 3 of the GNU General Public
+License, supplemented by the additional permissions listed below.
+
+ 0. Additional Definitions.
+
+ As used herein, "this License" refers to version 3 of the GNU Lesser
+General Public License, and the "GNU GPL" refers to version 3 of the GNU
+General Public License.
+
+ "The Library" refers to a covered work governed by this License,
+other than an Application or a Combined Work as defined below.
+
+ An "Application" is any work that makes use of an interface provided
+by the Library, but which is not otherwise based on the Library.
+Defining a subclass of a class defined by the Library is deemed a mode
+of using an interface provided by the Library.
+
+ A "Combined Work" is a work produced by combining or linking an
+Application with the Library. The particular version of the Library
+with which the Combined Work was made is also called the "Linked
+Version".
+
+ The "Minimal Corresponding Source" for a Combined Work means the
+Corresponding Source for the Combined Work, excluding any source code
+for portions of the Combined Work that, considered in isolation, are
+based on the Application, and not on the Linked Version.
+
+ The "Corresponding Application Code" for a Combined Work means the
+object code and/or source code for the Application, including any data
+and utility programs needed for reproducing the Combined Work from the
+Application, but excluding the System Libraries of the Combined Work.
+
+ 1. Exception to Section 3 of the GNU GPL.
+
+ You may convey a covered work under sections 3 and 4 of this License
+without being bound by section 3 of the GNU GPL.
+
+ 2. Conveying Modified Versions.
+
+ If you modify a copy of the Library, and, in your modifications, a
+facility refers to a function or data to be supplied by an Application
+that uses the facility (other than as an argument passed when the
+facility is invoked), then you may convey a copy of the modified
+version:
+
+ a) under this License, provided that you make a good faith effort to
+ ensure that, in the event an Application does not supply the
+ function or data, the facility still operates, and performs
+ whatever part of its purpose remains meaningful, or
+
+ b) under the GNU GPL, with none of the additional permissions of
+ this License applicable to that copy.
+
+ 3. Object Code Incorporating Material from Library Header Files.
+
+ The object code form of an Application may incorporate material from
+a header file that is part of the Library. You may convey such object
+code under terms of your choice, provided that, if the incorporated
+material is not limited to numerical parameters, data structure
+layouts and accessors, or small macros, inline functions and templates
+(ten or fewer lines in length), you do both of the following:
+
+ a) Give prominent notice with each copy of the object code that the
+ Library is used in it and that the Library and its use are
+ covered by this License.
+
+ b) Accompany the object code with a copy of the GNU GPL and this license
+ document.
+
+ 4. Combined Works.
+
+ You may convey a Combined Work under terms of your choice that,
+taken together, effectively do not restrict modification of the
+portions of the Library contained in the Combined Work and reverse
+engineering for debugging such modifications, if you also do each of
+the following:
+
+ a) Give prominent notice with each copy of the Combined Work that
+ the Library is used in it and that the Library and its use are
+ covered by this License.
+
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
+ document.
+
+ c) For a Combined Work that displays copyright notices during
+ execution, include the copyright notice for the Library among
+ these notices, as well as a reference directing the user to the
+ copies of the GNU GPL and this license document.
+
+ d) Do one of the following:
+
+ 0) Convey the Minimal Corresponding Source under the terms of this
+ License, and the Corresponding Application Code in a form
+ suitable for, and under terms that permit, the user to
+ recombine or relink the Application with a modified version of
+ the Linked Version to produce a modified Combined Work, in the
+ manner specified by section 6 of the GNU GPL for conveying
+ Corresponding Source.
+
+ 1) Use a suitable shared library mechanism for linking with the
+ Library. A suitable mechanism is one that (a) uses at run time
+ a copy of the Library already present on the user's computer
+ system, and (b) will operate properly with a modified version
+ of the Library that is interface-compatible with the Linked
+ Version.
+
+ e) Provide Installation Information, but only if you would otherwise
+ be required to provide such information under section 6 of the
+ GNU GPL, and only to the extent that such information is
+ necessary to install and execute a modified version of the
+ Combined Work produced by recombining or relinking the
+ Application with a modified version of the Linked Version. (If
+ you use option 4d0, the Installation Information must accompany
+ the Minimal Corresponding Source and Corresponding Application
+ Code. If you use option 4d1, you must provide the Installation
+ Information in the manner specified by section 6 of the GNU GPL
+ for conveying Corresponding Source.)
+
+ 5. Combined Libraries.
+
+ You may place library facilities that are a work based on the
+Library side by side in a single library together with other library
+facilities that are not Applications and are not covered by this
+License, and convey such a combined library under terms of your
+choice, if you do both of the following:
+
+ a) Accompany the combined library with a copy of the same work based
+ on the Library, uncombined with any other library facilities,
+ conveyed under the terms of this License.
+
+ b) Give prominent notice with the combined library that part of it
+ is a work based on the Library, and explaining where to find the
+ accompanying uncombined form of the same work.
+
+ 6. Revised Versions of the GNU Lesser General Public License.
+
+ The Free Software Foundation may publish revised and/or new versions
+of the GNU Lesser General Public License from time to time. Such new
+versions will be similar in spirit to the present version, but may
+differ in detail to address new problems or concerns.
+
+ Each version is given a distinguishing version number. If the
+Library as you received it specifies that a certain numbered version
+of the GNU Lesser General Public License "or any later version"
+applies to it, you have the option of following the terms and
+conditions either of that published version or of any later version
+published by the Free Software Foundation. If the Library as you
+received it does not specify a version number of the GNU Lesser
+General Public License, you may choose any version of the GNU Lesser
+General Public License ever published by the Free Software Foundation.
+
+ If the Library as you received it specifies that a proxy can decide
+whether future versions of the GNU Lesser General Public License shall
+apply, that proxy's public statement of acceptance of any version is
+permanent authorization for you to choose that version for the
+Library.
+
Property changes on: nuiton-jpa/LICENSE.txt
___________________________________________________________________
Modified: svn:keywords
- Author Date Id Revision
+ Author Date Id Revision HeadURL
Property changes on: nuiton-jpa/README.txt
___________________________________________________________________
Modified: svn:keywords
- Author Date Id Revision
+ Author Date Id Revision HeadURL
Property changes on: nuiton-jpa/changelog.txt
___________________________________________________________________
Modified: svn:keywords
- Author Date Id Revision
+ Author Date Id Revision HeadURL
Modified: nuiton-jpa/nuiton-jpa-api/LICENSE.txt
===================================================================
--- nuiton-jpa/nuiton-jpa-api/LICENSE.txt 2013-05-24 17:35:29 UTC (rev 625)
+++ nuiton-jpa/nuiton-jpa-api/LICENSE.txt 2013-05-24 22:14:35 UTC (rev 626)
@@ -0,0 +1,166 @@
+ GNU LESSER GENERAL PUBLIC LICENSE
+ Version 3, 29 June 2007
+
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+
+ This version of the GNU Lesser General Public License incorporates
+the terms and conditions of version 3 of the GNU General Public
+License, supplemented by the additional permissions listed below.
+
+ 0. Additional Definitions.
+
+ As used herein, "this License" refers to version 3 of the GNU Lesser
+General Public License, and the "GNU GPL" refers to version 3 of the GNU
+General Public License.
+
+ "The Library" refers to a covered work governed by this License,
+other than an Application or a Combined Work as defined below.
+
+ An "Application" is any work that makes use of an interface provided
+by the Library, but which is not otherwise based on the Library.
+Defining a subclass of a class defined by the Library is deemed a mode
+of using an interface provided by the Library.
+
+ A "Combined Work" is a work produced by combining or linking an
+Application with the Library. The particular version of the Library
+with which the Combined Work was made is also called the "Linked
+Version".
+
+ The "Minimal Corresponding Source" for a Combined Work means the
+Corresponding Source for the Combined Work, excluding any source code
+for portions of the Combined Work that, considered in isolation, are
+based on the Application, and not on the Linked Version.
+
+ The "Corresponding Application Code" for a Combined Work means the
+object code and/or source code for the Application, including any data
+and utility programs needed for reproducing the Combined Work from the
+Application, but excluding the System Libraries of the Combined Work.
+
+ 1. Exception to Section 3 of the GNU GPL.
+
+ You may convey a covered work under sections 3 and 4 of this License
+without being bound by section 3 of the GNU GPL.
+
+ 2. Conveying Modified Versions.
+
+ If you modify a copy of the Library, and, in your modifications, a
+facility refers to a function or data to be supplied by an Application
+that uses the facility (other than as an argument passed when the
+facility is invoked), then you may convey a copy of the modified
+version:
+
+ a) under this License, provided that you make a good faith effort to
+ ensure that, in the event an Application does not supply the
+ function or data, the facility still operates, and performs
+ whatever part of its purpose remains meaningful, or
+
+ b) under the GNU GPL, with none of the additional permissions of
+ this License applicable to that copy.
+
+ 3. Object Code Incorporating Material from Library Header Files.
+
+ The object code form of an Application may incorporate material from
+a header file that is part of the Library. You may convey such object
+code under terms of your choice, provided that, if the incorporated
+material is not limited to numerical parameters, data structure
+layouts and accessors, or small macros, inline functions and templates
+(ten or fewer lines in length), you do both of the following:
+
+ a) Give prominent notice with each copy of the object code that the
+ Library is used in it and that the Library and its use are
+ covered by this License.
+
+ b) Accompany the object code with a copy of the GNU GPL and this license
+ document.
+
+ 4. Combined Works.
+
+ You may convey a Combined Work under terms of your choice that,
+taken together, effectively do not restrict modification of the
+portions of the Library contained in the Combined Work and reverse
+engineering for debugging such modifications, if you also do each of
+the following:
+
+ a) Give prominent notice with each copy of the Combined Work that
+ the Library is used in it and that the Library and its use are
+ covered by this License.
+
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
+ document.
+
+ c) For a Combined Work that displays copyright notices during
+ execution, include the copyright notice for the Library among
+ these notices, as well as a reference directing the user to the
+ copies of the GNU GPL and this license document.
+
+ d) Do one of the following:
+
+ 0) Convey the Minimal Corresponding Source under the terms of this
+ License, and the Corresponding Application Code in a form
+ suitable for, and under terms that permit, the user to
+ recombine or relink the Application with a modified version of
+ the Linked Version to produce a modified Combined Work, in the
+ manner specified by section 6 of the GNU GPL for conveying
+ Corresponding Source.
+
+ 1) Use a suitable shared library mechanism for linking with the
+ Library. A suitable mechanism is one that (a) uses at run time
+ a copy of the Library already present on the user's computer
+ system, and (b) will operate properly with a modified version
+ of the Library that is interface-compatible with the Linked
+ Version.
+
+ e) Provide Installation Information, but only if you would otherwise
+ be required to provide such information under section 6 of the
+ GNU GPL, and only to the extent that such information is
+ necessary to install and execute a modified version of the
+ Combined Work produced by recombining or relinking the
+ Application with a modified version of the Linked Version. (If
+ you use option 4d0, the Installation Information must accompany
+ the Minimal Corresponding Source and Corresponding Application
+ Code. If you use option 4d1, you must provide the Installation
+ Information in the manner specified by section 6 of the GNU GPL
+ for conveying Corresponding Source.)
+
+ 5. Combined Libraries.
+
+ You may place library facilities that are a work based on the
+Library side by side in a single library together with other library
+facilities that are not Applications and are not covered by this
+License, and convey such a combined library under terms of your
+choice, if you do both of the following:
+
+ a) Accompany the combined library with a copy of the same work based
+ on the Library, uncombined with any other library facilities,
+ conveyed under the terms of this License.
+
+ b) Give prominent notice with the combined library that part of it
+ is a work based on the Library, and explaining where to find the
+ accompanying uncombined form of the same work.
+
+ 6. Revised Versions of the GNU Lesser General Public License.
+
+ The Free Software Foundation may publish revised and/or new versions
+of the GNU Lesser General Public License from time to time. Such new
+versions will be similar in spirit to the present version, but may
+differ in detail to address new problems or concerns.
+
+ Each version is given a distinguishing version number. If the
+Library as you received it specifies that a certain numbered version
+of the GNU Lesser General Public License "or any later version"
+applies to it, you have the option of following the terms and
+conditions either of that published version or of any later version
+published by the Free Software Foundation. If the Library as you
+received it does not specify a version number of the GNU Lesser
+General Public License, you may choose any version of the GNU Lesser
+General Public License ever published by the Free Software Foundation.
+
+ If the Library as you received it specifies that a proxy can decide
+whether future versions of the GNU Lesser General Public License shall
+apply, that proxy's public statement of acceptance of any version is
+permanent authorization for you to choose that version for the
+Library.
+
Property changes on: nuiton-jpa/nuiton-jpa-api/LICENSE.txt
___________________________________________________________________
Modified: svn:keywords
- Author Date Id Revision
+ Author Date Id Revision HeadURL
Property changes on: nuiton-jpa/nuiton-jpa-api/README.txt
___________________________________________________________________
Modified: svn:keywords
- Author Date Id Revision
+ Author Date Id Revision HeadURL
Property changes on: nuiton-jpa/nuiton-jpa-api/changelog.txt
___________________________________________________________________
Modified: svn:keywords
- Author Date Id Revision
+ Author Date Id Revision HeadURL
Modified: nuiton-jpa/nuiton-jpa-api/pom.xml
===================================================================
--- nuiton-jpa/nuiton-jpa-api/pom.xml 2013-05-24 17:35:29 UTC (rev 625)
+++ nuiton-jpa/nuiton-jpa-api/pom.xml 2013-05-24 22:14:35 UTC (rev 626)
@@ -31,11 +31,6 @@
</dependency>
<dependency>
- <groupId>com.h2database</groupId>
- <artifactId>h2</artifactId>
- </dependency>
-
- <dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
Property changes on: nuiton-jpa/nuiton-jpa-api/pom.xml
___________________________________________________________________
Modified: svn:keywords
- Author Date Id Revision
+ Author Date Id Revision HeadURL
Added: nuiton-jpa/nuiton-jpa-api/src/license/THIRD-PARTY.properties
===================================================================
--- nuiton-jpa/nuiton-jpa-api/src/license/THIRD-PARTY.properties (rev 0)
+++ nuiton-jpa/nuiton-jpa-api/src/license/THIRD-PARTY.properties 2013-05-24 22:14:35 UTC (rev 626)
@@ -0,0 +1,21 @@
+# Generated by org.codehaus.mojo.license.AddThirdPartyMojo
+#-------------------------------------------------------------------------------
+# Already used licenses in project :
+# - Apache License 2.0
+# - BSD License
+# - COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0
+# - GNU Lesser General Public License, version 2.1
+# - Indiana University Extreme! Lab Software License, vesion 1.1.1
+# - Lesser General Public License (LPGL)
+# - Lesser General Public License (LPGL) v 2.1
+# - MIT License
+# - MPL 1.1
+# - The Apache Software License, Version 2.0
+# - The H2 License, Version 1.0
+# - license.txt
+#-------------------------------------------------------------------------------
+# Please fill the missing licenses for dependencies :
+#
+#
+#Sat May 25 00:05:21 CEST 2013
+dom4j--dom4j--1.6.1=BSD License
Property changes on: nuiton-jpa/nuiton-jpa-api/src/license/THIRD-PARTY.properties
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Modified: nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/AbstractJpaDao.java
===================================================================
--- nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/AbstractJpaDao.java 2013-05-24 17:35:29 UTC (rev 625)
+++ nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/AbstractJpaDao.java 2013-05-24 22:14:35 UTC (rev 626)
@@ -3,23 +3,24 @@
/*
* #%L
* MagaLiE :: Persistence
- * $Id:$
- * $HeadURL:$
+ * $Id$
+ * $HeadURL$
* %%
* Copyright (C) 2013 CodeLutin
* %%
* This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
+ * GNU General Lesser Public License for more details.
*
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
* #L%
*/
Property changes on: nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/AbstractJpaDao.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Modified: nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/AbstractJpaEntity.java
===================================================================
--- nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/AbstractJpaEntity.java 2013-05-24 17:35:29 UTC (rev 625)
+++ nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/AbstractJpaEntity.java 2013-05-24 22:14:35 UTC (rev 626)
@@ -3,23 +3,24 @@
/*
* #%L
* MagaLiE :: Persistence
- * $Id:$
- * $HeadURL:$
+ * $Id$
+ * $HeadURL$
* %%
* Copyright (C) 2013 CodeLutin
* %%
* This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
+ * GNU General Lesser Public License for more details.
*
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
* #L%
*/
Property changes on: nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/AbstractJpaEntity.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Modified: nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/AbstractJpaPersistenceContext.java
===================================================================
--- nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/AbstractJpaPersistenceContext.java 2013-05-24 17:35:29 UTC (rev 625)
+++ nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/AbstractJpaPersistenceContext.java 2013-05-24 22:14:35 UTC (rev 626)
@@ -1,5 +1,32 @@
package org.nuiton.jpa.api;
+/*
+ * #%L
+ * nuiton-jpa-api
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 20013 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
+
+import javax.persistence.EntityManager;
+import javax.persistence.EntityTransaction;
+
/**
* TODO
*
@@ -7,4 +34,29 @@
* @since 0.1
*/
public class AbstractJpaPersistenceContext {
+
+ protected EntityManager entityManager;
+
+ protected EntityTransaction entityTransaction;
+
+ public AbstractJpaPersistenceContext(EntityManager entityManager) {
+ this.entityManager = entityManager;
+ this.entityManager = entityManager;
+ entityTransaction = entityManager.getTransaction();
+ if (!entityTransaction.isActive()) {
+ entityTransaction.begin();
+ }
+ }
+
+ public void commit() {
+ entityTransaction.commit();
+ entityTransaction = entityManager.getTransaction();
+ entityTransaction.begin();
+ }
+
+ public void rollback() {
+ entityTransaction.rollback();
+ entityTransaction = entityManager.getTransaction();
+ entityTransaction.begin();
+ }
}
Property changes on: nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/AbstractJpaPersistenceContext.java
___________________________________________________________________
Modified: svn:keywords
- Author Date Id Revision
+ Author Date Id Revision HeadURL
Modified: nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/JpaDao.java
===================================================================
--- nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/JpaDao.java 2013-05-24 17:35:29 UTC (rev 625)
+++ nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/JpaDao.java 2013-05-24 22:14:35 UTC (rev 626)
@@ -3,23 +3,24 @@
/*
* #%L
* MagaLiE :: Persistence
- * $Id:$
- * $HeadURL:$
+ * $Id$
+ * $HeadURL$
* %%
* Copyright (C) 2013 CodeLutin
* %%
* This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
+ * GNU General Lesser Public License for more details.
*
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
* #L%
*/
Property changes on: nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/JpaDao.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Modified: nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/hibernate/HibernateUtil.java
===================================================================
--- nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/hibernate/HibernateUtil.java 2013-05-24 17:35:29 UTC (rev 625)
+++ nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/hibernate/HibernateUtil.java 2013-05-24 22:14:35 UTC (rev 626)
@@ -1,5 +1,29 @@
package org.nuiton.jpa.api.hibernate;
+/*
+ * #%L
+ * nuiton-jpa-api
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 20013 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
+
import org.apache.commons.lang3.SystemUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
Property changes on: nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/hibernate/HibernateUtil.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Modified: nuiton-jpa/nuiton-jpa-junit/LICENSE.txt
===================================================================
--- nuiton-jpa/nuiton-jpa-junit/LICENSE.txt 2013-05-24 17:35:29 UTC (rev 625)
+++ nuiton-jpa/nuiton-jpa-junit/LICENSE.txt 2013-05-24 22:14:35 UTC (rev 626)
@@ -0,0 +1,166 @@
+ GNU LESSER GENERAL PUBLIC LICENSE
+ Version 3, 29 June 2007
+
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+
+ This version of the GNU Lesser General Public License incorporates
+the terms and conditions of version 3 of the GNU General Public
+License, supplemented by the additional permissions listed below.
+
+ 0. Additional Definitions.
+
+ As used herein, "this License" refers to version 3 of the GNU Lesser
+General Public License, and the "GNU GPL" refers to version 3 of the GNU
+General Public License.
+
+ "The Library" refers to a covered work governed by this License,
+other than an Application or a Combined Work as defined below.
+
+ An "Application" is any work that makes use of an interface provided
+by the Library, but which is not otherwise based on the Library.
+Defining a subclass of a class defined by the Library is deemed a mode
+of using an interface provided by the Library.
+
+ A "Combined Work" is a work produced by combining or linking an
+Application with the Library. The particular version of the Library
+with which the Combined Work was made is also called the "Linked
+Version".
+
+ The "Minimal Corresponding Source" for a Combined Work means the
+Corresponding Source for the Combined Work, excluding any source code
+for portions of the Combined Work that, considered in isolation, are
+based on the Application, and not on the Linked Version.
+
+ The "Corresponding Application Code" for a Combined Work means the
+object code and/or source code for the Application, including any data
+and utility programs needed for reproducing the Combined Work from the
+Application, but excluding the System Libraries of the Combined Work.
+
+ 1. Exception to Section 3 of the GNU GPL.
+
+ You may convey a covered work under sections 3 and 4 of this License
+without being bound by section 3 of the GNU GPL.
+
+ 2. Conveying Modified Versions.
+
+ If you modify a copy of the Library, and, in your modifications, a
+facility refers to a function or data to be supplied by an Application
+that uses the facility (other than as an argument passed when the
+facility is invoked), then you may convey a copy of the modified
+version:
+
+ a) under this License, provided that you make a good faith effort to
+ ensure that, in the event an Application does not supply the
+ function or data, the facility still operates, and performs
+ whatever part of its purpose remains meaningful, or
+
+ b) under the GNU GPL, with none of the additional permissions of
+ this License applicable to that copy.
+
+ 3. Object Code Incorporating Material from Library Header Files.
+
+ The object code form of an Application may incorporate material from
+a header file that is part of the Library. You may convey such object
+code under terms of your choice, provided that, if the incorporated
+material is not limited to numerical parameters, data structure
+layouts and accessors, or small macros, inline functions and templates
+(ten or fewer lines in length), you do both of the following:
+
+ a) Give prominent notice with each copy of the object code that the
+ Library is used in it and that the Library and its use are
+ covered by this License.
+
+ b) Accompany the object code with a copy of the GNU GPL and this license
+ document.
+
+ 4. Combined Works.
+
+ You may convey a Combined Work under terms of your choice that,
+taken together, effectively do not restrict modification of the
+portions of the Library contained in the Combined Work and reverse
+engineering for debugging such modifications, if you also do each of
+the following:
+
+ a) Give prominent notice with each copy of the Combined Work that
+ the Library is used in it and that the Library and its use are
+ covered by this License.
+
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
+ document.
+
+ c) For a Combined Work that displays copyright notices during
+ execution, include the copyright notice for the Library among
+ these notices, as well as a reference directing the user to the
+ copies of the GNU GPL and this license document.
+
+ d) Do one of the following:
+
+ 0) Convey the Minimal Corresponding Source under the terms of this
+ License, and the Corresponding Application Code in a form
+ suitable for, and under terms that permit, the user to
+ recombine or relink the Application with a modified version of
+ the Linked Version to produce a modified Combined Work, in the
+ manner specified by section 6 of the GNU GPL for conveying
+ Corresponding Source.
+
+ 1) Use a suitable shared library mechanism for linking with the
+ Library. A suitable mechanism is one that (a) uses at run time
+ a copy of the Library already present on the user's computer
+ system, and (b) will operate properly with a modified version
+ of the Library that is interface-compatible with the Linked
+ Version.
+
+ e) Provide Installation Information, but only if you would otherwise
+ be required to provide such information under section 6 of the
+ GNU GPL, and only to the extent that such information is
+ necessary to install and execute a modified version of the
+ Combined Work produced by recombining or relinking the
+ Application with a modified version of the Linked Version. (If
+ you use option 4d0, the Installation Information must accompany
+ the Minimal Corresponding Source and Corresponding Application
+ Code. If you use option 4d1, you must provide the Installation
+ Information in the manner specified by section 6 of the GNU GPL
+ for conveying Corresponding Source.)
+
+ 5. Combined Libraries.
+
+ You may place library facilities that are a work based on the
+Library side by side in a single library together with other library
+facilities that are not Applications and are not covered by this
+License, and convey such a combined library under terms of your
+choice, if you do both of the following:
+
+ a) Accompany the combined library with a copy of the same work based
+ on the Library, uncombined with any other library facilities,
+ conveyed under the terms of this License.
+
+ b) Give prominent notice with the combined library that part of it
+ is a work based on the Library, and explaining where to find the
+ accompanying uncombined form of the same work.
+
+ 6. Revised Versions of the GNU Lesser General Public License.
+
+ The Free Software Foundation may publish revised and/or new versions
+of the GNU Lesser General Public License from time to time. Such new
+versions will be similar in spirit to the present version, but may
+differ in detail to address new problems or concerns.
+
+ Each version is given a distinguishing version number. If the
+Library as you received it specifies that a certain numbered version
+of the GNU Lesser General Public License "or any later version"
+applies to it, you have the option of following the terms and
+conditions either of that published version or of any later version
+published by the Free Software Foundation. If the Library as you
+received it does not specify a version number of the GNU Lesser
+General Public License, you may choose any version of the GNU Lesser
+General Public License ever published by the Free Software Foundation.
+
+ If the Library as you received it specifies that a proxy can decide
+whether future versions of the GNU Lesser General Public License shall
+apply, that proxy's public statement of acceptance of any version is
+permanent authorization for you to choose that version for the
+Library.
+
Property changes on: nuiton-jpa/nuiton-jpa-junit/LICENSE.txt
___________________________________________________________________
Modified: svn:keywords
- Author Date Id Revision
+ Author Date Id Revision HeadURL
Property changes on: nuiton-jpa/nuiton-jpa-junit/README.txt
___________________________________________________________________
Modified: svn:keywords
- Author Date Id Revision
+ Author Date Id Revision HeadURL
Property changes on: nuiton-jpa/nuiton-jpa-junit/changelog.txt
___________________________________________________________________
Modified: svn:keywords
- Author Date Id Revision
+ Author Date Id Revision HeadURL
Modified: nuiton-jpa/nuiton-jpa-junit/pom.xml
===================================================================
--- nuiton-jpa/nuiton-jpa-junit/pom.xml 2013-05-24 17:35:29 UTC (rev 625)
+++ nuiton-jpa/nuiton-jpa-junit/pom.xml 2013-05-24 22:14:35 UTC (rev 626)
@@ -27,6 +27,16 @@
<scope>provided</scope>
</dependency>
+ <dependency>
+ <groupId>org.hibernate.javax.persistence</groupId>
+ <artifactId>hibernate-jpa-2.0-api</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>commons-logging</groupId>
+ <artifactId>commons-logging</artifactId>
+ </dependency>
+
</dependencies>
<build>
Property changes on: nuiton-jpa/nuiton-jpa-junit/pom.xml
___________________________________________________________________
Modified: svn:keywords
- Author Date Id Revision
+ Author Date Id Revision HeadURL
Added: nuiton-jpa/nuiton-jpa-junit/src/license/THIRD-PARTY.properties
===================================================================
--- nuiton-jpa/nuiton-jpa-junit/src/license/THIRD-PARTY.properties (rev 0)
+++ nuiton-jpa/nuiton-jpa-junit/src/license/THIRD-PARTY.properties 2013-05-24 22:14:35 UTC (rev 626)
@@ -0,0 +1,24 @@
+# Generated by org.codehaus.mojo.license.AddThirdPartyMojo
+#-------------------------------------------------------------------------------
+# Already used licenses in project :
+# - Apache License 2.0
+# - BSD License
+# - COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0
+# - Common Public License Version 1.0
+# - GNU Lesser General Public License, version 2.1
+# - Indiana University Extreme! Lab Software License, vesion 1.1.1
+# - Lesser General Public License (LGPL) v 3.0
+# - Lesser General Public License (LPGL)
+# - Lesser General Public License (LPGL) v 2.1
+# - MIT License
+# - MPL 1.1
+# - New BSD License
+# - The Apache Software License, Version 2.0
+# - The H2 License, Version 1.0
+# - license.txt
+#-------------------------------------------------------------------------------
+# Please fill the missing licenses for dependencies :
+#
+#
+#Sat May 25 00:06:28 CEST 2013
+dom4j--dom4j--1.6.1=BSD License
Property changes on: nuiton-jpa/nuiton-jpa-junit/src/license/THIRD-PARTY.properties
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Modified: nuiton-jpa/nuiton-jpa-junit/src/main/java/org/nuiton/jpa/junit/JpaEntityManagerRule.java
===================================================================
--- nuiton-jpa/nuiton-jpa-junit/src/main/java/org/nuiton/jpa/junit/JpaEntityManagerRule.java 2013-05-24 17:35:29 UTC (rev 625)
+++ nuiton-jpa/nuiton-jpa-junit/src/main/java/org/nuiton/jpa/junit/JpaEntityManagerRule.java 2013-05-24 22:14:35 UTC (rev 626)
@@ -3,23 +3,24 @@
/*
* #%L
* MagaLiE :: Services
- * $Id:$
- * $HeadURL:$
+ * $Id$
+ * $HeadURL$
* %%
* Copyright (C) 2013 CodeLutin
* %%
* This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
+ * GNU General Lesser Public License for more details.
*
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
* #L%
*/
Property changes on: nuiton-jpa/nuiton-jpa-junit/src/main/java/org/nuiton/jpa/junit/JpaEntityManagerRule.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Modified: nuiton-jpa/nuiton-jpa-templates/LICENSE.txt
===================================================================
--- nuiton-jpa/nuiton-jpa-templates/LICENSE.txt 2013-05-24 17:35:29 UTC (rev 625)
+++ nuiton-jpa/nuiton-jpa-templates/LICENSE.txt 2013-05-24 22:14:35 UTC (rev 626)
@@ -0,0 +1,166 @@
+ GNU LESSER GENERAL PUBLIC LICENSE
+ Version 3, 29 June 2007
+
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+
+ This version of the GNU Lesser General Public License incorporates
+the terms and conditions of version 3 of the GNU General Public
+License, supplemented by the additional permissions listed below.
+
+ 0. Additional Definitions.
+
+ As used herein, "this License" refers to version 3 of the GNU Lesser
+General Public License, and the "GNU GPL" refers to version 3 of the GNU
+General Public License.
+
+ "The Library" refers to a covered work governed by this License,
+other than an Application or a Combined Work as defined below.
+
+ An "Application" is any work that makes use of an interface provided
+by the Library, but which is not otherwise based on the Library.
+Defining a subclass of a class defined by the Library is deemed a mode
+of using an interface provided by the Library.
+
+ A "Combined Work" is a work produced by combining or linking an
+Application with the Library. The particular version of the Library
+with which the Combined Work was made is also called the "Linked
+Version".
+
+ The "Minimal Corresponding Source" for a Combined Work means the
+Corresponding Source for the Combined Work, excluding any source code
+for portions of the Combined Work that, considered in isolation, are
+based on the Application, and not on the Linked Version.
+
+ The "Corresponding Application Code" for a Combined Work means the
+object code and/or source code for the Application, including any data
+and utility programs needed for reproducing the Combined Work from the
+Application, but excluding the System Libraries of the Combined Work.
+
+ 1. Exception to Section 3 of the GNU GPL.
+
+ You may convey a covered work under sections 3 and 4 of this License
+without being bound by section 3 of the GNU GPL.
+
+ 2. Conveying Modified Versions.
+
+ If you modify a copy of the Library, and, in your modifications, a
+facility refers to a function or data to be supplied by an Application
+that uses the facility (other than as an argument passed when the
+facility is invoked), then you may convey a copy of the modified
+version:
+
+ a) under this License, provided that you make a good faith effort to
+ ensure that, in the event an Application does not supply the
+ function or data, the facility still operates, and performs
+ whatever part of its purpose remains meaningful, or
+
+ b) under the GNU GPL, with none of the additional permissions of
+ this License applicable to that copy.
+
+ 3. Object Code Incorporating Material from Library Header Files.
+
+ The object code form of an Application may incorporate material from
+a header file that is part of the Library. You may convey such object
+code under terms of your choice, provided that, if the incorporated
+material is not limited to numerical parameters, data structure
+layouts and accessors, or small macros, inline functions and templates
+(ten or fewer lines in length), you do both of the following:
+
+ a) Give prominent notice with each copy of the object code that the
+ Library is used in it and that the Library and its use are
+ covered by this License.
+
+ b) Accompany the object code with a copy of the GNU GPL and this license
+ document.
+
+ 4. Combined Works.
+
+ You may convey a Combined Work under terms of your choice that,
+taken together, effectively do not restrict modification of the
+portions of the Library contained in the Combined Work and reverse
+engineering for debugging such modifications, if you also do each of
+the following:
+
+ a) Give prominent notice with each copy of the Combined Work that
+ the Library is used in it and that the Library and its use are
+ covered by this License.
+
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
+ document.
+
+ c) For a Combined Work that displays copyright notices during
+ execution, include the copyright notice for the Library among
+ these notices, as well as a reference directing the user to the
+ copies of the GNU GPL and this license document.
+
+ d) Do one of the following:
+
+ 0) Convey the Minimal Corresponding Source under the terms of this
+ License, and the Corresponding Application Code in a form
+ suitable for, and under terms that permit, the user to
+ recombine or relink the Application with a modified version of
+ the Linked Version to produce a modified Combined Work, in the
+ manner specified by section 6 of the GNU GPL for conveying
+ Corresponding Source.
+
+ 1) Use a suitable shared library mechanism for linking with the
+ Library. A suitable mechanism is one that (a) uses at run time
+ a copy of the Library already present on the user's computer
+ system, and (b) will operate properly with a modified version
+ of the Library that is interface-compatible with the Linked
+ Version.
+
+ e) Provide Installation Information, but only if you would otherwise
+ be required to provide such information under section 6 of the
+ GNU GPL, and only to the extent that such information is
+ necessary to install and execute a modified version of the
+ Combined Work produced by recombining or relinking the
+ Application with a modified version of the Linked Version. (If
+ you use option 4d0, the Installation Information must accompany
+ the Minimal Corresponding Source and Corresponding Application
+ Code. If you use option 4d1, you must provide the Installation
+ Information in the manner specified by section 6 of the GNU GPL
+ for conveying Corresponding Source.)
+
+ 5. Combined Libraries.
+
+ You may place library facilities that are a work based on the
+Library side by side in a single library together with other library
+facilities that are not Applications and are not covered by this
+License, and convey such a combined library under terms of your
+choice, if you do both of the following:
+
+ a) Accompany the combined library with a copy of the same work based
+ on the Library, uncombined with any other library facilities,
+ conveyed under the terms of this License.
+
+ b) Give prominent notice with the combined library that part of it
+ is a work based on the Library, and explaining where to find the
+ accompanying uncombined form of the same work.
+
+ 6. Revised Versions of the GNU Lesser General Public License.
+
+ The Free Software Foundation may publish revised and/or new versions
+of the GNU Lesser General Public License from time to time. Such new
+versions will be similar in spirit to the present version, but may
+differ in detail to address new problems or concerns.
+
+ Each version is given a distinguishing version number. If the
+Library as you received it specifies that a certain numbered version
+of the GNU Lesser General Public License "or any later version"
+applies to it, you have the option of following the terms and
+conditions either of that published version or of any later version
+published by the Free Software Foundation. If the Library as you
+received it does not specify a version number of the GNU Lesser
+General Public License, you may choose any version of the GNU Lesser
+General Public License ever published by the Free Software Foundation.
+
+ If the Library as you received it specifies that a proxy can decide
+whether future versions of the GNU Lesser General Public License shall
+apply, that proxy's public statement of acceptance of any version is
+permanent authorization for you to choose that version for the
+Library.
+
Property changes on: nuiton-jpa/nuiton-jpa-templates/LICENSE.txt
___________________________________________________________________
Modified: svn:keywords
- Author Date Id Revision
+ Author Date Id Revision HeadURL
Property changes on: nuiton-jpa/nuiton-jpa-templates/README.txt
___________________________________________________________________
Modified: svn:keywords
- Author Date Id Revision
+ Author Date Id Revision HeadURL
Property changes on: nuiton-jpa/nuiton-jpa-templates/changelog.txt
___________________________________________________________________
Modified: svn:keywords
- Author Date Id Revision
+ Author Date Id Revision HeadURL
Modified: nuiton-jpa/nuiton-jpa-templates/pom.xml
===================================================================
--- nuiton-jpa/nuiton-jpa-templates/pom.xml 2013-05-24 17:35:29 UTC (rev 625)
+++ nuiton-jpa/nuiton-jpa-templates/pom.xml 2013-05-24 22:14:35 UTC (rev 626)
@@ -29,13 +29,13 @@
</dependency>
<dependency>
- <groupId>org.apache.commons</groupId>
- <artifactId>commons-lang3</artifactId>
+ <groupId>commons-logging</groupId>
+ <artifactId>commons-logging</artifactId>
</dependency>
<dependency>
- <groupId>commons-logging</groupId>
- <artifactId>commons-logging</artifactId>
+ <groupId>com.google.guava</groupId>
+ <artifactId>guava</artifactId>
</dependency>
<dependency>
@@ -63,7 +63,52 @@
<build>
+ <plugins>
+ <plugin>
+ <groupId>org.nuiton.processor</groupId>
+ <artifactId>processor-maven-plugin</artifactId>
+ </plugin>
+ <!-- expose new plexus components -->
+ <plugin>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-component-metadata</artifactId>
+ <executions>
+ <execution>
+ <goals>
+ <goal>generate-metadata</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+
</build>
+ <profiles>
+
+ <!-- reporting at release time -->
+ <profile>
+ <id>reporting</id>
+ <activation>
+ <property>
+ <name>performRelease</name>
+ <value>true</value>
+ </property>
+ </activation>
+
+ <reporting>
+ <plugins>
+ <plugin>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-maven-plugin</artifactId>
+ <version>${plexusPluginVersion}</version>
+ </plugin>
+
+ </plugins>
+ </reporting>
+
+ </profile>
+ </profiles>
+
</project>
Property changes on: nuiton-jpa/nuiton-jpa-templates/pom.xml
___________________________________________________________________
Modified: svn:keywords
- Author Date Id Revision
+ Author Date Id Revision HeadURL
Added: nuiton-jpa/nuiton-jpa-templates/src/license/THIRD-PARTY.properties
===================================================================
--- nuiton-jpa/nuiton-jpa-templates/src/license/THIRD-PARTY.properties (rev 0)
+++ nuiton-jpa/nuiton-jpa-templates/src/license/THIRD-PARTY.properties 2013-05-24 22:14:35 UTC (rev 626)
@@ -0,0 +1,30 @@
+# Generated by org.codehaus.mojo.license.AddThirdPartyMojo
+#-------------------------------------------------------------------------------
+# Already used licenses in project :
+# - Apache License 2.0
+# - Apache License Version 2.0
+# - BSD License
+# - COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0
+# - Common Public License Version 1.0
+# - GNU Lesser General Public License, version 2.1
+# - Indiana University Extreme! Lab Software License, vesion 1.1.1
+# - Lesser General Public License (LGPL) v 3.0
+# - Lesser General Public License (LPGL)
+# - Lesser General Public License (LPGL) v 2.1
+# - MIT License
+# - MPL 1.1
+# - Mozilla Public License Version 1.0
+# - New BSD License
+# - The Apache Software License, Version 2.0
+# - The H2 License, Version 1.0
+# - The SAX License
+# - The W3C License
+# - http://jaxen.codehaus.org/license.html
+# - license.txt
+#-------------------------------------------------------------------------------
+# Please fill the missing licenses for dependencies :
+#
+#
+#Sat May 25 00:06:31 CEST 2013
+commons-primitives--commons-primitives--1.0=The Apache Software License, Version 2.0
+dom4j--dom4j--1.6.1=BSD License
Property changes on: nuiton-jpa/nuiton-jpa-templates/src/license/THIRD-PARTY.properties
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Modified: nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/AbstractJpaTransformer.java
===================================================================
--- nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/AbstractJpaTransformer.java 2013-05-24 17:35:29 UTC (rev 625)
+++ nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/AbstractJpaTransformer.java 2013-05-24 22:14:35 UTC (rev 626)
@@ -4,7 +4,7 @@
* #%L
* EUGene :: JPA templates
* $Id$
- * $HeadURL: http://svn.nuiton.org/svn/eugene/trunk/eugene-jpa-templates/src/main/java/o… $
+ * $HeadURL$
* %%
* Copyright (C) 2013 CodeLutin, Tony Chemit
* %%
@@ -35,6 +35,7 @@
import org.nuiton.eugene.models.object.ObjectModelJavaModifier;
import org.nuiton.eugene.models.object.ObjectModelOperation;
+import javax.persistence.EntityManager;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.io.Serializable;
@@ -54,6 +55,21 @@
public static final String DEFAULT_CONSTANT_PREFIX = "PROPERTY_";
+ protected void addConstructorWithEntityManager(ObjectModelClass output) {
+
+ ObjectModelOperation constructor = addConstructor(
+ output,
+ ObjectModelJavaModifier.PUBLIC);
+
+ addParameter(constructor, EntityManager.class, "entityManager");
+
+ setOperationBody(constructor, ""
+ /*{
+ super(entityManager);
+ }*/
+ );
+ }
+
protected boolean isInClassPath(String packageName, String className) {
return isInClassPath(packageName + "." + className);
@@ -74,6 +90,16 @@
return superClassIsBean;
}
+ protected boolean isEntity(ObjectModelClass input, String type) {
+
+ ObjectModelClass aClass = getModel().getClass(type);
+
+ // test if a super class is in same package (so is another entity)
+ boolean result = aClass != null &&
+ input.getPackageName().equals(aClass.getPackageName());
+ return result;
+ }
+
protected void createPropertyConstant(ObjectModelClass output,
ObjectModelAttribute attr,
String prefix,
@@ -128,7 +154,6 @@
}
-
protected List<ObjectModelAttribute> getProperties(ObjectModelClass input) {
List<ObjectModelAttribute> attributes =
(List<ObjectModelAttribute>) input.getAttributes();
@@ -251,7 +276,7 @@
"void",
ObjectModelJavaModifier.PUBLIC
);
- addParameter(operation, "java.util.Collection<" + attrType + ">", attrName);
+ addParameter(operation, Collection.class.getName() + "<" + attrType + ">", attrName);
String methodName = getJavaBeanMethodName("get", attrName);
StringBuilder buffer = new StringBuilder(""
@@ -375,7 +400,7 @@
"boolean",
ObjectModelJavaModifier.PUBLIC
);
- addParameter(operation, "java.util.Collection<" + attrType + ">", attrName);
+ addParameter(operation, Collection.class.getName() + "<" + attrType + ">", attrName);
StringBuilder buffer = new StringBuilder();
String methodName = getJavaBeanMethodName("get", attrName);
buffer.append(""
@@ -563,7 +588,7 @@
addParameter(getChild, "java.util.Collection<T>", "childs");
addParameter(getChild, "int", "index");
setOperationBody(getChild, ""
-/*{
+ /*{
T result = null;
if (childs != null) {
if (childs instanceof List) {
@@ -582,7 +607,7 @@
}
}
return result;
-}*/
+ }*/
);
}
}
Property changes on: nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/AbstractJpaTransformer.java
___________________________________________________________________
Modified: svn:keywords
- Author Date Id Revision
+ Author Date Id Revision HeadURL
Modified: nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaDaoTransformer.java
===================================================================
--- nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaDaoTransformer.java 2013-05-24 17:35:29 UTC (rev 625)
+++ nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaDaoTransformer.java 2013-05-24 22:14:35 UTC (rev 626)
@@ -4,7 +4,7 @@
* #%L
* EUGene :: JPA templates
* $Id$
- * $HeadURL: http://svn.nuiton.org/svn/eugene/trunk/eugene-jpa-templates/src/main/java/o… $
+ * $HeadURL$
* %%
* Copyright (C) 2013 CodeLutin
* %%
@@ -31,12 +31,9 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.nuiton.eugene.models.object.ObjectModelClass;
-import org.nuiton.eugene.models.object.ObjectModelJavaModifier;
import org.nuiton.eugene.models.object.ObjectModelOperation;
import org.nuiton.jpa.api.AbstractJpaDao;
-import javax.persistence.EntityManager;
-
/**
* JpaDaoTransformer generates a dao for an entity.
* <p/>
@@ -48,23 +45,20 @@
* {@code Note:} All classes found in class-path are not generated.
*
* @author tchemit <chemit(a)codelutin.com>
- * @plexus.component role="org.nuiton.eugene.Template" role-hint="org.nuiton.eugene.jpa.JpaDaoTransformer"
+ * @plexus.component role="org.nuiton.eugene.Template" role-hint="org.nuiton.jpa.templates.JpaDaoTransformer"
* @since 0.1
*/
public class JpaDaoTransformer extends AbstractJpaTransformer {
private static final Log log = LogFactory.getLog(JpaDaoTransformer.class);
- protected String getConcreteName(ObjectModelClass input) {
- return input.getName() + "JpaDao";
- }
@Override
public void transformFromClass(ObjectModelClass input) {
String entityAbstractName = "Abstract" + input.getName() + "JpaDao";
- String entityConcreteName = getConcreteName(input);
+ String entityConcreteName = JpaTemplatesGeneratorUtil.getDaoConcreteName(input);
boolean generateAbstract = !isInClassPath(input.getPackageName(),
entityAbstractName);
@@ -79,13 +73,19 @@
if (generateConcrete) {
- generateImpl(input, entityConcreteName);
+ generateImpl(input, entityAbstractName, entityConcreteName);
}
}
protected ObjectModelClass generateAbstract(ObjectModelClass input,
String entityAbstractName) {
+ String packageName = input.getPackageName();
+
+ ObjectModelClass output =
+ createAbstractClass(entityAbstractName + "<E extends " + input.getName() + ">", packageName);
+ addImport(output, input.getQualifiedName());
+
// test if a super class is in same package (so is yet another entity)
boolean superClassIsEntity = isSuperClassEntity(input);
@@ -95,7 +95,7 @@
// get first super-class
ObjectModelClass superClassModel = input.getSuperclasses().iterator().next();
- superClass = getConcreteName(superClassModel);
+ superClass = JpaTemplatesGeneratorUtil.getDaoConcreteName(superClassModel);
} else {
@@ -106,37 +106,34 @@
if (superClass == null) {
// no super-class, use default one
- superClass = AbstractJpaDao.class.getName();
+ superClass = AbstractJpaDao.class.getName() + "<E>";
+ addImport(output, superClass);
}
}
// detect if there is a contract to set on abstract
- String packageName = input.getPackageName();
-
String daoContractName = input.getPackageName() + "." + input.getName() + "Dao";
boolean addUserDaoContract = isInClassPath(daoContractName);
- ObjectModelClass output =
- createAbstractClass(entityAbstractName, packageName);
-
setSuperClass(output, superClass);
if (addUserDaoContract) {
addInterface(output, daoContractName);
}
- addConstructor(output);
+ addConstructorWithEntityManager(output);
// Add getEntityClass
if (log.isDebugEnabled()) {
log.debug("will generate " + output.getQualifiedName());
}
- ObjectModelOperation operation = addOperation(output, "getEntityClass", "Class<" + input.getName() + ">");
+ ObjectModelOperation operation = addOperation(output, "getEntityClass", "Class<E>");
+ addAnnotation(output, operation, Override.class.getSimpleName());
setOperationBody(operation, ""
/*{
- return <%=input.getName()%>.class;
+ return (Class<E>) <%=input.getName()%>.class;
}*/
);
@@ -145,6 +142,7 @@
}
protected ObjectModelClass generateImpl(ObjectModelClass input,
+ String entityAbstractName,
String entityConcreteName) {
ObjectModelClass output = createClass(
@@ -153,10 +151,11 @@
);
// set the abstract resulClass as the resultClassImpl super class
- setSuperClass(output, input.getQualifiedName());
+ setSuperClass(output, input.getPackageName() + '.' + entityAbstractName + "<" + input.getName() + ">");
+ addImport(output, input);
+ addConstructorWithEntityManager(output);
+ output.getSuperclasses();
- addConstructor(output);
-
if (log.isDebugEnabled()) {
log.debug("will generate " + output.getQualifiedName());
}
@@ -164,12 +163,4 @@
return output;
}
- protected void addConstructor(ObjectModelClass output) {
-
- ObjectModelOperation constructor = addConstructor(
- output,
- ObjectModelJavaModifier.PUBLIC);
-
- addParameter(constructor, EntityManager.class, "entityManager");
- }
}
\ No newline at end of file
Property changes on: nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaDaoTransformer.java
___________________________________________________________________
Modified: svn:keywords
- Author Date Id Revision
+ Author Date Id Revision HeadURL
Modified: nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaEntityTransformer.java
===================================================================
--- nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaEntityTransformer.java 2013-05-24 17:35:29 UTC (rev 625)
+++ nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaEntityTransformer.java 2013-05-24 22:14:35 UTC (rev 626)
@@ -4,7 +4,7 @@
* #%L
* EUGene :: JPA templates
* $Id$
- * $HeadURL: http://svn.nuiton.org/svn/eugene/trunk/eugene-jpa-templates/src/main/java/o… $
+ * $HeadURL$
* %%
* Copyright (C) 2013 CodeLutin, Tony Chemit
* %%
@@ -24,6 +24,7 @@
* #L%
*/
+import com.google.common.base.Preconditions;
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.Multimap;
import org.apache.commons.logging.Log;
@@ -36,8 +37,17 @@
import org.nuiton.jpa.api.AbstractJpaEntity;
import javax.persistence.Entity;
+import javax.persistence.EnumType;
+import javax.persistence.Enumerated;
+import javax.persistence.Id;
+import javax.persistence.ManyToMany;
+import javax.persistence.ManyToOne;
import javax.persistence.MappedSuperclass;
+import javax.persistence.OneToMany;
+import javax.persistence.OneToOne;
+import javax.persistence.OrderColumn;
import java.util.Collection;
+import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
@@ -53,8 +63,9 @@
* <p/>
* {@code Note:} All classes found in class-path are not generated.
*
+ * TODO Deal with @GeneratedValue
* @author tchemit <chemit(a)codelutin.com>
- * @plexus.component role="org.nuiton.eugene.Template" role-hint="org.nuiton.eugene.jpa.JpaEntityTransformer"
+ * @plexus.component role="org.nuiton.eugene.Template" role-hint="org.nuiton.jpa.templates.JpaEntityTransformer"
* @since 0.1
*/
public class JpaEntityTransformer extends AbstractJpaTransformer {
@@ -84,7 +95,7 @@
if (generateConcrete) {
- generateImpl(input, entityConcreteName);
+ generateImpl(input, entityAbstractName, entityConcreteName);
}
}
@@ -138,7 +149,8 @@
setSuperClass(output, superClass);
// Add annotation MappedSuperclass
- addAnnotation(output, output, MappedSuperclass.class.getName());
+ addAnnotation(output, output, MappedSuperclass.class.getSimpleName());
+ addImport(output, MappedSuperclass.class);
if (log.isDebugEnabled()) {
log.debug("will generate " + output.getQualifiedName());
@@ -161,6 +173,7 @@
// Get available properties
List<ObjectModelAttribute> properties = getProperties(input);
+ //TODO Deal with @GeneratedValue
ObjectModelAttributeImpl idAttr = new ObjectModelAttributeImpl();
idAttr.setDeclaringElement(input);
idAttr.setName("id");
@@ -177,9 +190,8 @@
//TODO Si ORDERED ajouter l'annotation @OrderColumn
//TODO Si enumeration @Enumeration(value = EnumType.STRING) (Voir pour mettre une tag-value pour mettre en ordinal) + voir comment ça marche pour les collections
- //TODO Generate Persistence annotations
Multimap<ObjectModelAttribute, String> annotationsForAttributes =
- generateAnnotationsForProperties();
+ generateAnnotationsForProperties(input, output, properties);
// Add properties constant
@@ -202,17 +214,100 @@
// add getChild methods
createGetChildMethod(output);
-
-
}
return output;
}
- protected Multimap<ObjectModelAttribute, String> generateAnnotationsForProperties() {
- return ArrayListMultimap.create();
+ protected Multimap<ObjectModelAttribute, String> generateAnnotationsForProperties(ObjectModelClass input,
+ ObjectModelClass output,
+ List<ObjectModelAttribute> properties) {
+ ArrayListMultimap<ObjectModelAttribute, String> result =
+ ArrayListMultimap.create();
+
+ for (ObjectModelAttribute property : properties) {
+ String propertyName = property.getName();
+ String propertyType = property.getType();
+ if ("id".equals(propertyName)) {
+
+ result.put(property, Id.class.getSimpleName());
+ addImport(output, Id.class);
+ continue;
+ }
+
+ ObjectModelAttribute reverseAttribute =
+ property.getReverseAttribute();
+
+ boolean nMultiplicity = reverseAttribute != null &&
+ JpaTemplatesGeneratorUtil.isNMultiplicity(reverseAttribute);
+
+ boolean bidirection = reverseAttribute != null &&
+ reverseAttribute.isNavigable();
+
+ //TODO Deal with bidirection
+ Preconditions.checkState(
+ !bidirection,
+ "Still can not deal with bidirection, but found one " + input.getQualifiedName() + "#" + propertyName);
+
+ boolean entity = isEntity(input, propertyType);
+ boolean enumeration = getModel().getEnumeration(propertyType) != null;
+
+ if (JpaTemplatesGeneratorUtil.isNMultiplicity(property)) {
+
+ if (nMultiplicity) {
+
+ // * -> * (ManyToMany)
+ result.put(property, ManyToMany.class.getSimpleName());
+ addImport(output, ManyToMany.class);
+ } else {
+
+ // 0..1 -> * (OneToMany)
+ result.put(property, OneToMany.class.getSimpleName());
+ addImport(output, OneToMany.class);
+ }
+
+ boolean withOrdererStereotype = property.isOrdered() ||
+ JpaTemplatesGeneratorUtil.hasOrderedStereotype(property);
+
+ if (withOrdererStereotype) {
+ result.put(property, OrderColumn.class.getSimpleName());
+ addImport(output, OrderColumn.class);
+ }
+ continue;
+ }
+
+ if (enumeration) {
+
+ // is an enumeration
+ result.put(property, Enumerated.class.getSimpleName() + "( value = " + EnumType.class.getSimpleName() + "." + EnumType.STRING + ")");
+ addImport(output, Enumerated.class);
+ addImport(output, EnumType.class);
+ }
+
+ if (entity) {
+
+ if (nMultiplicity) {
+
+ // * -> 0..1 (ManyToOne)
+ result.put(property, ManyToOne.class.getSimpleName());
+ addImport(output, ManyToOne.class);
+ } else {
+
+ // 0..1 -> 0..1 (OneToOne)
+ result.put(property, OneToOne.class.getSimpleName());
+ addImport(output, OneToOne.class);
+ }
+
+ continue;
+ }
+
+ // simple property
+ // no annotation
+ }
+ return result;
}
protected ObjectModelClass generateImpl(ObjectModelClass input,
+ String entityAbstractName,
String entityConcreteName) {
ObjectModelClass output = createClass(
@@ -221,10 +316,11 @@
);
// set the abstract resulClass as the resultClassImpl super class
- setSuperClass(output, input.getQualifiedName());
+ setSuperClass(output, entityAbstractName);
// add Entity annotation
- addAnnotation(output, output, Entity.class.getName());
+ addAnnotation(output, output, Entity.class.getSimpleName());
+ addImport(output, Entity.class);
// add a fix serialVersionUID, since the class has no field nor method
addConstant(output,
@@ -308,11 +404,27 @@
usePCS
);
+ boolean ordered = attr.isOrdered() ||
+ JpaTemplatesGeneratorUtil.hasOrderedStereotype(attr);
+ boolean unique = JpaTemplatesGeneratorUtil.hasUniqueStereotype(attr);
+
// Change type for Multiple attribute
- if (attr.isOrdered()) {
- attrType = List.class.getName() + "<" + attrType + ">";
+ if (ordered) {
+
+ if (unique) {
+
+ attrType = LinkedHashSet.class.getName() + "<" + attrType + ">";
+ } else {
+
+ attrType = List.class.getName() + "<" + attrType + ">";
+ }
} else {
- attrType = Collection.class.getName() + "<" + attrType + ">";
+
+ if (unique) {
+ attrType = Set.class.getName() + "<" + attrType + ">";
+ } else {
+ attrType = Collection.class.getName() + "<" + attrType + ">";
+ }
}
simpleType = JpaTemplatesGeneratorUtil.getSimpleName(attrType);
Property changes on: nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaEntityTransformer.java
___________________________________________________________________
Modified: svn:keywords
- Author Date Id Revision
+ Author Date Id Revision HeadURL
Modified: nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaPersistenceContextTransformer.java
===================================================================
--- nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaPersistenceContextTransformer.java 2013-05-24 17:35:29 UTC (rev 625)
+++ nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaPersistenceContextTransformer.java 2013-05-24 22:14:35 UTC (rev 626)
@@ -1,16 +1,98 @@
package org.nuiton.jpa.templates;
+/*
+ * #%L
+ * nuiton-jpa-templates
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 20013 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
+
+import org.nuiton.eugene.models.object.ObjectModel;
+import org.nuiton.eugene.models.object.ObjectModelClass;
+import org.nuiton.eugene.models.object.ObjectModelOperation;
+import org.nuiton.jpa.api.AbstractJpaPersistenceContext;
+
+/*{generator option: parentheses = false}*/
+/*{generator option: writeString = +}*/
+
/**
- * TODO entityManager (constructor + getter)
- * TODO dao factory (une méthode par dao)
- * TODO commit/rollback
* TODO Liste des entités (A voir meta-modèle...)
- * TODO Se servir d'un AbstractJpaPersistenceContext
*
* @author tchemit <chemit(a)codelutin.com>
- * @plexus.component role="org.nuiton.eugene.Template" role-hint="org.nuiton.eugene.jpa.JpaPersistenceContextTransformer"
+ * @plexus.component role="org.nuiton.eugene.Template" role-hint="org.nuiton.jpa.templates.JpaPersistenceContextTransformer"
* @since 0.1
*/
-public class JpaPersistenceContextTransformer {
+public class JpaPersistenceContextTransformer extends AbstractJpaTransformer {
+ @Override
+ public void transformFromModel(ObjectModel model) {
+
+ String className = "Jpa" + model.getName() + "PersistenceContext";
+
+ String packageName =
+ getOutputProperties().getProperty(PROP_DEFAULT_PACKAGE);
+
+ boolean generateAbstract = !isInClassPath(packageName, className);
+
+ if (generateAbstract) {
+
+ generate(packageName, className);
+ }
+ }
+
+ protected void generate(String packageName, String className) {
+
+ // try to find a super class by tag-value
+ String superClass = JpaTemplatesGeneratorUtil.getPersistenceContextSuperClassTagValue(
+ model);
+
+ if (superClass == null) {
+
+ // no super-class, use default one
+ superClass = AbstractJpaPersistenceContext.class.getName();
+ }
+
+ ObjectModelClass output = createClass(className, packageName);
+
+ setSuperClass(output, superClass);
+
+ addConstructorWithEntityManager(output);
+
+ for (ObjectModelClass aClass : getModel().getClasses()) {
+ if (packageName.equals(aClass.getPackageName())) {
+
+ // add dao factory method
+ String daoConcreteName = JpaTemplatesGeneratorUtil.getDaoConcreteName(aClass);
+
+ ObjectModelOperation operation = addOperation(
+ output,
+ "get" + daoConcreteName,
+ packageName + "." + daoConcreteName);
+ setOperationBody(operation, ""
+ /*{
+ return new <%=daoConcreteName%>(entityManager);
+ }*/
+ );
+
+ }
+ }
+
+ }
}
Property changes on: nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaPersistenceContextTransformer.java
___________________________________________________________________
Modified: svn:keywords
- Author Date Id Revision
+ Author Date Id Revision HeadURL
Modified: nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaTemplatesGeneratorUtil.java
===================================================================
--- nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaTemplatesGeneratorUtil.java 2013-05-24 17:35:29 UTC (rev 625)
+++ nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaTemplatesGeneratorUtil.java 2013-05-24 22:14:35 UTC (rev 626)
@@ -4,7 +4,7 @@
* #%L
* EUGene :: JPA templates
* $Id$
- * $HeadURL: http://svn.nuiton.org/svn/eugene/trunk/eugene-jpa-templates/src/main/java/o… $
+ * $HeadURL$
* %%
* Copyright (C) 2013 CodeLutin, Tony Chemit
* %%
@@ -26,6 +26,8 @@
import org.nuiton.eugene.java.JavaGeneratorUtil;
import org.nuiton.eugene.models.object.ObjectModel;
+import org.nuiton.eugene.models.object.ObjectModelAttribute;
+import org.nuiton.eugene.models.object.ObjectModelClass;
import org.nuiton.eugene.models.object.ObjectModelClassifier;
/**
@@ -36,6 +38,10 @@
*/
public class JpaTemplatesGeneratorUtil extends JavaGeneratorUtil {
+ public static String getDaoConcreteName(ObjectModelClass input) {
+ return input.getName() + "JpaDao";
+ }
+
/**
* Obtain the value of the {@link JpaTemplatesTagValues#TAG_ENTITY_SUPER_CLASS}
* tag value on the given model or classifier.
@@ -66,7 +72,34 @@
* @since 2.3
*/
public static String getDaoSuperClassTagValue(ObjectModel model, ObjectModelClassifier classifier) {
- String value = findTagValue(JpaTemplatesTagValues.TAG_ENTITY_SUPER_CLASS, classifier, model);
+ String value = findTagValue(JpaTemplatesTagValues.TAG_DAO_SUPER_CLASS, classifier, model);
return value;
}
+
+ /**
+ * Obtain the value of the {@link JpaTemplatesTagValues#TAG_PERSISTENCE_CONTEXT_SUPER_CLASS}
+ * tag value on the given model.
+ *
+ * @param model model to seek
+ * @return the none empty value of the found tag value or {@code null} if not found nor empty.
+ * @see JpaTemplatesTagValues#TAG_PERSISTENCE_CONTEXT_SUPER_CLASS
+ * @since 2.3
+ */
+ public static String getPersistenceContextSuperClassTagValue(ObjectModel model) {
+ String value = findTagValue(JpaTemplatesTagValues.TAG_PERSISTENCE_CONTEXT_SUPER_CLASS, null, model);
+ return value;
+ }
+
+ /**
+ * Check if the given attribute has the
+ * {@link JpaTemplatesStereoTypes#STEREOTYPE_UNIQUE} stereotype.
+ *
+ * @param attribute attribute to test
+ * @return {@code true} if stereotype was found, {@code false otherwise}
+ * @see JpaTemplatesStereoTypes#STEREOTYPE_UNIQUE
+ * @since 2.5
+ */
+ public static boolean hasUniqueStereotype(ObjectModelAttribute attribute) {
+ return attribute.hasStereotype(JpaTemplatesStereoTypes.STEREOTYPE_UNIQUE);
+ }
}
Property changes on: nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaTemplatesGeneratorUtil.java
___________________________________________________________________
Modified: svn:keywords
- Author Date Id Revision
+ Author Date Id Revision HeadURL
Modified: nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaTemplatesModelPropertiesProvider.java
===================================================================
--- nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaTemplatesModelPropertiesProvider.java 2013-05-24 17:35:29 UTC (rev 625)
+++ nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaTemplatesModelPropertiesProvider.java 2013-05-24 22:14:35 UTC (rev 626)
@@ -4,7 +4,7 @@
* #%L
* EUGene :: JPA templates
* $Id$
- * $HeadURL: http://svn.nuiton.org/svn/eugene/trunk/eugene-jpa-templates/src/main/java/o… $
+ * $HeadURL$
* %%
* Copyright (C) 2013 CodeLutin, Tony Chemit
* %%
Property changes on: nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaTemplatesModelPropertiesProvider.java
___________________________________________________________________
Modified: svn:keywords
- Author Date Id Revision
+ Author Date Id Revision HeadURL
Modified: nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaTemplatesStereoTypes.java
===================================================================
--- nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaTemplatesStereoTypes.java 2013-05-24 17:35:29 UTC (rev 625)
+++ nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaTemplatesStereoTypes.java 2013-05-24 22:14:35 UTC (rev 626)
@@ -4,7 +4,7 @@
* #%L
* EUGene :: JPA templates
* $Id$
- * $HeadURL: http://svn.nuiton.org/svn/eugene/trunk/eugene-jpa-templates/src/main/java/o… $
+ * $HeadURL$
* %%
* Copyright (C) 2013 CodeLutin, Tony Chemit
* %%
@@ -25,6 +25,8 @@
*/
import org.nuiton.eugene.EugeneStereoTypes;
+import org.nuiton.eugene.ModelPropertiesUtil;
+import org.nuiton.eugene.models.object.ObjectModelAttribute;
/**
* Defines all stereotypes managed by JPA templates.
@@ -34,4 +36,12 @@
*/
public interface JpaTemplatesStereoTypes extends EugeneStereoTypes {
+ /**
+ * Stéréotype pour les collections avec unicité.
+ *
+ * @see JpaTemplatesGeneratorUtil#hasUniqueStereotype(ObjectModelAttribute)
+ */
+ @ModelPropertiesUtil.StereotypeDefinition(target = ObjectModelAttribute.class,
+ documentation = "To specify that an attribute is unique (JPA mapping)")
+ String STEREOTYPE_UNIQUE = "unique";
}
Property changes on: nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaTemplatesStereoTypes.java
___________________________________________________________________
Modified: svn:keywords
- Author Date Id Revision
+ Author Date Id Revision HeadURL
Modified: nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaTemplatesTagValues.java
===================================================================
--- nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaTemplatesTagValues.java 2013-05-24 17:35:29 UTC (rev 625)
+++ nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaTemplatesTagValues.java 2013-05-24 22:14:35 UTC (rev 626)
@@ -4,7 +4,7 @@
* #%L
* EUGene :: JPA templates
* $Id$
- * $HeadURL: http://svn.nuiton.org/svn/eugene/trunk/eugene-jpa-templates/src/main/java/o… $
+ * $HeadURL$
* %%
* Copyright (C) 2013 CodeLutin, Tony Chemit
* %%
@@ -62,4 +62,16 @@
"for a class or any class of a model")
String TAG_DAO_SUPER_CLASS = "daoSuperClass";
+
+ /**
+ * Tag value to use a super class for generated bean.
+ *
+ * @see JpaTemplatesGeneratorUtil#getDaoSuperClassTagValue(ObjectModel, ObjectModelClassifier)
+ * @since 0.1
+ */
+ @ModelPropertiesUtil.TagValueDefinition(
+ target = {ObjectModel.class},
+ documentation = "To specify a super-class to used on generated persistence context")
+ String TAG_PERSISTENCE_CONTEXT_SUPER_CLASS = "daoSuperClass";
+
}
Property changes on: nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaTemplatesTagValues.java
___________________________________________________________________
Modified: svn:keywords
- Author Date Id Revision
+ Author Date Id Revision HeadURL
Modified: nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/package-info.java
===================================================================
--- nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/package-info.java 2013-05-24 17:35:29 UTC (rev 625)
+++ nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/package-info.java 2013-05-24 22:14:35 UTC (rev 626)
@@ -8,3 +8,27 @@
*/
package org.nuiton.jpa.templates;
+/*
+ * #%L
+ * nuiton-jpa-templates
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 20013 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
+
Property changes on: nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/package-info.java
___________________________________________________________________
Modified: svn:keywords
- Author Date Id Revision
+ Author Date Id Revision HeadURL
Added: nuiton-jpa/nuiton-jpa-templates/src/main/resources/META-INF/services/org.nuiton.eugene.ModelPropertiesUtil$ModelPropertiesProvider
===================================================================
--- nuiton-jpa/nuiton-jpa-templates/src/main/resources/META-INF/services/org.nuiton.eugene.ModelPropertiesUtil$ModelPropertiesProvider (rev 0)
+++ nuiton-jpa/nuiton-jpa-templates/src/main/resources/META-INF/services/org.nuiton.eugene.ModelPropertiesUtil$ModelPropertiesProvider 2013-05-24 22:14:35 UTC (rev 626)
@@ -0,0 +1 @@
+org.nuiton.jpa.templates.JpaTemplatesModelPropertiesProvider
\ No newline at end of file
Property changes on: nuiton-jpa/nuiton-jpa-templates/src/main/resources/META-INF/services/org.nuiton.eugene.ModelPropertiesUtil$ModelPropertiesProvider
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Modified: nuiton-jpa/pom.xml
===================================================================
--- nuiton-jpa/pom.xml 2013-05-24 17:35:29 UTC (rev 625)
+++ nuiton-jpa/pom.xml 2013-05-24 22:14:35 UTC (rev 626)
@@ -32,7 +32,7 @@
<projectId>nuiton-jpa</projectId>
<!-- libs version -->
- <eugeneVersion>2.6.2</eugeneVersion>
+ <eugeneVersion>2.6.3-SNAPSHOT</eugeneVersion>
<nuitonUtilsVersion>2.6.12</nuitonUtilsVersion>
<processorPluginVersion>1.3</processorPluginVersion>
<h2Version>1.3.170</h2Version>
Property changes on: nuiton-jpa/pom.xml
___________________________________________________________________
Modified: svn:keywords
- Author Date Id Revision
+ Author Date Id Revision HeadURL
1
0
r625 - nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api
by bleny@users.nuiton.org 24 May '13
by bleny@users.nuiton.org 24 May '13
24 May '13
Author: bleny
Date: 2013-05-24 19:35:29 +0200 (Fri, 24 May 2013)
New Revision: 625
Url: http://nuiton.org/projects/sandbox/repository/revisions/625
Log:
add some helper methods in AbstractJpaDao
Modified:
nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/AbstractJpaDao.java
Modified: nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/AbstractJpaDao.java
===================================================================
--- nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/AbstractJpaDao.java 2013-05-24 17:04:41 UTC (rev 624)
+++ nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/AbstractJpaDao.java 2013-05-24 17:35:29 UTC (rev 625)
@@ -23,9 +23,14 @@
* #L%
*/
+import org.apache.commons.lang3.StringUtils;
+
import javax.persistence.EntityManager;
import javax.persistence.TypedQuery;
+import java.util.HashMap;
+import java.util.LinkedList;
import java.util.List;
+import java.util.Map;
/**
* This abstract class gather all code which is common to all daos for all entities.
@@ -95,12 +100,52 @@
return newInstance;
}
+ protected TypedQuery<E> createQuery(String propertyName,
+ Object propertyValue,
+ Object... others) {
+
+ Map<String, Object> properties = new HashMap<String, Object>();
+ properties.put(propertyName, propertyValue);
+ Object name = null;
+ for (int i = 0; i < others.length; ) {
+ try {
+ name = others[i++];
+ propertyValue = others[i++];
+ properties.put((String) name, propertyValue);
+ } catch (ClassCastException eee) {
+ throw new IllegalArgumentException(
+ "Les noms des propriétés doivent être des chaines et " +
+ "non pas " + propertyName.getClass().getName(),
+ eee);
+ } catch (ArrayIndexOutOfBoundsException eee) {
+ throw new IllegalArgumentException(
+ "Le nombre d'argument n'est pas un nombre pair: "
+ + (others.length + 2)
+ + " La dernière propriété était: " + name, eee);
+ }
+ }
+ return createQuery(properties);
+ }
+
+ protected TypedQuery<E> createQuery(Map<String, Object> properties) {
+ List<String> whereClauses = new LinkedList<String>();
+ for (String propertyName : properties.keySet()) {
+ whereClauses.add(propertyName + " = :" + propertyName);
+ }
+ String hql = "from " + getEntityClass().getSimpleName() + " where " + StringUtils.join(whereClauses, " and ");
+ TypedQuery<E> query = createQuery(hql);
+ for (Map.Entry<String, Object> property : properties.entrySet()) {
+ query.setParameter(property.getKey(), property.getValue());
+ }
+ return query;
+ }
+
protected TypedQuery<E> createQuery(String hql) {
TypedQuery<E> query = entityManager.createQuery(hql, getEntityClass());
return query;
}
- protected List<E> findAll(TypedQuery<E> query) {
+ protected List<E> findAll(TypedQuery <E> query) {
return query.getResultList();
}
@@ -129,4 +174,9 @@
return onlyElement;
}
+ protected long count(TypedQuery<E> query) {
+ // XXX brendan 24/05/13 worst way to do, use hql
+ return findAll(query).size();
+ }
+
}
1
0
r624 - in nuiton-jpa: nuiton-jpa-api/src/main/java/org/nuiton/jpa/api nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates
by tchemit@users.nuiton.org 24 May '13
by tchemit@users.nuiton.org 24 May '13
24 May '13
Author: tchemit
Date: 2013-05-24 19:04:41 +0200 (Fri, 24 May 2013)
New Revision: 624
Url: http://nuiton.org/projects/sandbox/repository/revisions/624
Log:
nuiton-api
Added:
nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/AbstractJpaPersistenceContext.java
Modified:
nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaDaoTransformer.java
nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaPersistenceContextTransformer.java
Added: nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/AbstractJpaPersistenceContext.java
===================================================================
--- nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/AbstractJpaPersistenceContext.java (rev 0)
+++ nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/AbstractJpaPersistenceContext.java 2013-05-24 17:04:41 UTC (rev 624)
@@ -0,0 +1,10 @@
+package org.nuiton.jpa.api;
+
+/**
+ * TODO
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 0.1
+ */
+public class AbstractJpaPersistenceContext {
+}
Property changes on: nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/AbstractJpaPersistenceContext.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Modified: nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaDaoTransformer.java
===================================================================
--- nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaDaoTransformer.java 2013-05-24 16:51:57 UTC (rev 623)
+++ nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaDaoTransformer.java 2013-05-24 17:04:41 UTC (rev 624)
@@ -133,9 +133,12 @@
log.debug("will generate " + output.getQualifiedName());
}
- //TODO
ObjectModelOperation operation = addOperation(output, "getEntityClass", "Class<" + input.getName() + ">");
- setOperationBody(operation,"return ");
+ setOperationBody(operation, ""
+ /*{
+ return <%=input.getName()%>.class;
+ }*/
+ );
return output;
Modified: nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaPersistenceContextTransformer.java
===================================================================
--- nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaPersistenceContextTransformer.java 2013-05-24 16:51:57 UTC (rev 623)
+++ nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaPersistenceContextTransformer.java 2013-05-24 17:04:41 UTC (rev 624)
@@ -1,11 +1,15 @@
package org.nuiton.jpa.templates;
/**
- * TODO
+ * TODO entityManager (constructor + getter)
+ * TODO dao factory (une méthode par dao)
+ * TODO commit/rollback
+ * TODO Liste des entités (A voir meta-modèle...)
+ * TODO Se servir d'un AbstractJpaPersistenceContext
*
* @author tchemit <chemit(a)codelutin.com>
+ * @plexus.component role="org.nuiton.eugene.Template" role-hint="org.nuiton.eugene.jpa.JpaPersistenceContextTransformer"
* @since 0.1
- * @plexus.component role="org.nuiton.eugene.Template" role-hint="org.nuiton.eugene.jpa.JpaPersistenceContextTransformer"
*/
public class JpaPersistenceContextTransformer {
1
0
r623 - nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates
by tchemit@users.nuiton.org 24 May '13
by tchemit@users.nuiton.org 24 May '13
24 May '13
Author: tchemit
Date: 2013-05-24 18:51:57 +0200 (Fri, 24 May 2013)
New Revision: 623
Url: http://nuiton.org/projects/sandbox/repository/revisions/623
Log:
nuiton-api
Added:
nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaPersistenceContextTransformer.java
Modified:
nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaDaoTransformer.java
nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaEntityTransformer.java
Modified: nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaDaoTransformer.java
===================================================================
--- nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaDaoTransformer.java 2013-05-24 16:42:23 UTC (rev 622)
+++ nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaDaoTransformer.java 2013-05-24 16:51:57 UTC (rev 623)
@@ -128,10 +128,16 @@
addConstructor(output);
+ // Add getEntityClass
if (log.isDebugEnabled()) {
log.debug("will generate " + output.getQualifiedName());
}
+ //TODO
+ ObjectModelOperation operation = addOperation(output, "getEntityClass", "Class<" + input.getName() + ">");
+ setOperationBody(operation,"return ");
+
+
return output;
}
Modified: nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaEntityTransformer.java
===================================================================
--- nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaEntityTransformer.java 2013-05-24 16:42:23 UTC (rev 622)
+++ nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaEntityTransformer.java 2013-05-24 16:51:57 UTC (rev 623)
@@ -32,8 +32,11 @@
import org.nuiton.eugene.models.object.ObjectModelClass;
import org.nuiton.eugene.models.object.ObjectModelJavaModifier;
import org.nuiton.eugene.models.object.ObjectModelOperation;
+import org.nuiton.eugene.models.object.xml.ObjectModelAttributeImpl;
import org.nuiton.jpa.api.AbstractJpaEntity;
+import javax.persistence.Entity;
+import javax.persistence.MappedSuperclass;
import java.util.Collection;
import java.util.List;
import java.util.Set;
@@ -134,6 +137,9 @@
setSuperClass(output, superClass);
+ // Add annotation MappedSuperclass
+ addAnnotation(output, output, MappedSuperclass.class.getName());
+
if (log.isDebugEnabled()) {
log.debug("will generate " + output.getQualifiedName());
}
@@ -155,8 +161,13 @@
// Get available properties
List<ObjectModelAttribute> properties = getProperties(input);
+ ObjectModelAttributeImpl idAttr = new ObjectModelAttributeImpl();
+ idAttr.setDeclaringElement(input);
+ idAttr.setName("id");
+ idAttr.setType(String.class.getName());
+ properties.add(idAttr);
+
//TODO Add attribute id (+ @Id)
- //TODO Add @MappedSuperClass sur output)
//TODO 1 -> 1 @OnetoOne (uniquement navigeable sans bidi) si composition (Cascade = ALL) si aggregeation Cascade = (tout sauf ALL TODO A check) + orphanRemoval = true)
//TODO * -> 1 @ManyToOne (uniquement navigeable sans bidi) si composition (Cascade = ALL) si aggregeation Cascade = (tout sauf ALL TODO A check) + orphanRemoval = true)
//TODO 1 -> * @OneToMany (uniquement navigeable sans bidi) si composition (Cascade = ALL) si aggregeation Cascade = (tout sauf ALL TODO A check) + orphanRemoval = true)
@@ -168,7 +179,7 @@
//TODO Generate Persistence annotations
Multimap<ObjectModelAttribute, String> annotationsForAttributes =
- ArrayListMultimap.create();
+ generateAnnotationsForProperties();
// Add properties constant
@@ -197,25 +208,32 @@
return output;
}
+ protected Multimap<ObjectModelAttribute, String> generateAnnotationsForProperties() {
+ return ArrayListMultimap.create();
+ }
+
protected ObjectModelClass generateImpl(ObjectModelClass input,
String entityConcreteName) {
- ObjectModelClass resultClassImpl = createClass(
+ ObjectModelClass output = createClass(
entityConcreteName,
input.getPackageName()
);
// set the abstract resulClass as the resultClassImpl super class
- setSuperClass(resultClassImpl, input.getQualifiedName());
+ setSuperClass(output, input.getQualifiedName());
+ // add Entity annotation
+ addAnnotation(output, output, Entity.class.getName());
+
// add a fix serialVersionUID, since the class has no field nor method
- addConstant(resultClassImpl,
+ addConstant(output,
JpaTemplatesGeneratorUtil.SERIAL_VERSION_UID,
"long",
"1L",
ObjectModelJavaModifier.PRIVATE
);
- return resultClassImpl;
+ return output;
}
protected void createProperty(ObjectModelClass output,
Added: nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaPersistenceContextTransformer.java
===================================================================
--- nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaPersistenceContextTransformer.java (rev 0)
+++ nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaPersistenceContextTransformer.java 2013-05-24 16:51:57 UTC (rev 623)
@@ -0,0 +1,12 @@
+package org.nuiton.jpa.templates;
+
+/**
+ * TODO
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 0.1
+ * @plexus.component role="org.nuiton.eugene.Template" role-hint="org.nuiton.eugene.jpa.JpaPersistenceContextTransformer"
+ */
+public class JpaPersistenceContextTransformer {
+
+}
Property changes on: nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaPersistenceContextTransformer.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
1
0
r622 - in nuiton-jpa: . nuiton-jpa-api/src/main/java/org/nuiton/jpa/api nuiton-jpa-templates/src/main/java/org/nuiton/jpa nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates
by tchemit@users.nuiton.org 24 May '13
by tchemit@users.nuiton.org 24 May '13
24 May '13
Author: tchemit
Date: 2013-05-24 18:42:23 +0200 (Fri, 24 May 2013)
New Revision: 622
Url: http://nuiton.org/projects/sandbox/repository/revisions/622
Log:
nuiton-api
Added:
nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/AbstractJpaEntity.java
nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/
nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/AbstractJpaTransformer.java
nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaDaoTransformer.java
nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaEntityTransformer.java
nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaTemplatesGeneratorUtil.java
nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaTemplatesModelPropertiesProvider.java
nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaTemplatesStereoTypes.java
nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaTemplatesTagValues.java
nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/package-info.java
Removed:
nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/JpaEntity.java
Modified:
nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/AbstractJpaDao.java
nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/JpaDao.java
nuiton-jpa/pom.xml
Modified: nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/AbstractJpaDao.java
===================================================================
--- nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/AbstractJpaDao.java 2013-05-24 15:48:17 UTC (rev 621)
+++ nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/AbstractJpaDao.java 2013-05-24 16:42:23 UTC (rev 622)
@@ -37,7 +37,7 @@
* @author bleny, tchemit
* @since 0.1
*/
-public abstract class AbstractJpaDao<E extends JpaEntity> implements JpaDao<E> {
+public abstract class AbstractJpaDao<E extends AbstractJpaEntity> implements JpaDao<E> {
protected EntityManager entityManager;
Copied: nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/AbstractJpaEntity.java (from rev 621, nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/JpaEntity.java)
===================================================================
--- nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/AbstractJpaEntity.java (rev 0)
+++ nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/AbstractJpaEntity.java 2013-05-24 16:42:23 UTC (rev 622)
@@ -0,0 +1,59 @@
+package org.nuiton.jpa.api;
+
+/*
+ * #%L
+ * MagaLiE :: Persistence
+ * $Id:$
+ * $HeadURL:$
+ * %%
+ * Copyright (C) 2013 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+
+/**
+ * A AbstractJpaEntity must have a technical id.
+ *
+ * Also equals() is defined for compliance with JPA expectations.
+ *
+ * @author bleny, tchemit
+ * @since 0.1
+ */
+public abstract class AbstractJpaEntity {
+
+ public abstract String getId();
+
+ @Override
+ public boolean equals(Object other) {
+ String id = getId();
+ if (other instanceof AbstractJpaEntity) {
+ AbstractJpaEntity that = (AbstractJpaEntity) other;
+ return id != null && that.getId() != null && id.equals(that.getId());
+ }
+ return false;
+ }
+
+ @Override
+ public int hashCode() {
+ String id = getId();
+ return id == null ? 0 : id.hashCode();
+ }
+
+ @Override
+ public String toString() {
+ return "AbstractJpaEntity{id=" + getId() + "}";
+ }
+
+}
Modified: nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/JpaDao.java
===================================================================
--- nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/JpaDao.java 2013-05-24 15:48:17 UTC (rev 621)
+++ nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/JpaDao.java 2013-05-24 16:42:23 UTC (rev 622)
@@ -33,7 +33,7 @@
* @author bleny, tchemit
* @since 0.1
*/
-public interface JpaDao<E extends JpaEntity> {
+public interface JpaDao<E extends AbstractJpaEntity> {
E findById(String id);
Deleted: nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/JpaEntity.java
===================================================================
--- nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/JpaEntity.java 2013-05-24 15:48:17 UTC (rev 621)
+++ nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/JpaEntity.java 2013-05-24 16:42:23 UTC (rev 622)
@@ -1,59 +0,0 @@
-package org.nuiton.jpa.api;
-
-/*
- * #%L
- * MagaLiE :: Persistence
- * $Id:$
- * $HeadURL:$
- * %%
- * Copyright (C) 2013 CodeLutin
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- * #L%
- */
-
-/**
- * A JpaEntity must have a technical id.
- *
- * Also equals() is defined for compliance with JPA expectations.
- *
- * @author bleny, tchemit
- * @since 0.1
- */
-public abstract class JpaEntity {
-
- public abstract String getId();
-
- @Override
- public boolean equals(Object other) {
- String id = getId();
- if (other instanceof JpaEntity) {
- JpaEntity that = (JpaEntity) other;
- return id != null && that.getId() != null && id.equals(that.getId());
- }
- return false;
- }
-
- @Override
- public int hashCode() {
- String id = getId();
- return id == null ? 0 : id.hashCode();
- }
-
- @Override
- public String toString() {
- return "JpaEntity{id=" + getId() + "}";
- }
-
-}
Added: nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/AbstractJpaTransformer.java
===================================================================
--- nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/AbstractJpaTransformer.java (rev 0)
+++ nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/AbstractJpaTransformer.java 2013-05-24 16:42:23 UTC (rev 622)
@@ -0,0 +1,588 @@
+package org.nuiton.jpa.templates;
+
+/*
+ * #%L
+ * EUGene :: JPA templates
+ * $Id$
+ * $HeadURL: http://svn.nuiton.org/svn/eugene/trunk/eugene-jpa-templates/src/main/java/o… $
+ * %%
+ * Copyright (C) 2013 CodeLutin, Tony Chemit
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
+
+/*{generator option: parentheses = false}*/
+/*{generator option: writeString = +}*/
+
+import org.apache.commons.collections.CollectionUtils;
+import org.nuiton.eugene.java.ObjectModelTransformerToJava;
+import org.nuiton.eugene.models.object.ObjectModelAttribute;
+import org.nuiton.eugene.models.object.ObjectModelClass;
+import org.nuiton.eugene.models.object.ObjectModelInterface;
+import org.nuiton.eugene.models.object.ObjectModelJavaModifier;
+import org.nuiton.eugene.models.object.ObjectModelOperation;
+
+import java.beans.PropertyChangeListener;
+import java.beans.PropertyChangeSupport;
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * Common class form jpa like transformer.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @see JpaEntityTransformer
+ * @since 2.7
+ */
+public abstract class AbstractJpaTransformer extends ObjectModelTransformerToJava {
+
+ public static final String DEFAULT_CONSTANT_PREFIX = "PROPERTY_";
+
+ protected boolean isInClassPath(String packageName, String className) {
+
+ return isInClassPath(packageName + "." + className);
+ }
+
+ protected boolean isSuperClassEntity(ObjectModelClass input) {
+ // test if a super class is in same package (so is another entity)
+ boolean superClassIsBean = false;
+ Collection<ObjectModelClass> superclasses = input.getSuperclasses();
+ if (CollectionUtils.isNotEmpty(superclasses)) {
+ for (ObjectModelClass superclass : superclasses) {
+ if (input.getPackageName().equals(superclass.getPackageName())) {
+ superClassIsBean = true;
+ break;
+ }
+ }
+ }
+ return superClassIsBean;
+ }
+
+ protected void createPropertyConstant(ObjectModelClass output,
+ ObjectModelAttribute attr,
+ String prefix,
+ Set<String> constantNames) {
+
+ String attrName = getAttributeName(attr);
+
+ String constantName = prefix + builder.getConstantName(attrName);
+
+ if (!constantNames.contains(constantName)) {
+
+ addConstant(output,
+ constantName,
+ String.class,
+ "\"" + attrName + "\"",
+ ObjectModelJavaModifier.PUBLIC
+ );
+ }
+ }
+
+ protected String getAttributeName(ObjectModelAttribute attr) {
+ String attrName = attr.getName();
+ if (attr.hasAssociationClass()) {
+ String assocAttrName = JpaTemplatesGeneratorUtil.getAssocAttrName(attr);
+ attrName = JpaTemplatesGeneratorUtil.toLowerCaseFirstLetter(assocAttrName);
+ }
+ return attrName;
+ }
+
+ protected String getAttributeType(ObjectModelAttribute attr) {
+ String attrType = attr.getType();
+ if (attr.hasAssociationClass()) {
+ attrType = attr.getAssociationClass().getName();
+ }
+ return attrType;
+ }
+
+ protected boolean containsMutiple(List<ObjectModelAttribute> attributes) {
+
+ boolean result = false;
+
+ for (ObjectModelAttribute attr : attributes) {
+
+ if (JpaTemplatesGeneratorUtil.isNMultiplicity(attr)) {
+ result = true;
+
+ break;
+ }
+
+ }
+ return result;
+ }
+
+
+
+ protected List<ObjectModelAttribute> getProperties(ObjectModelClass input) {
+ List<ObjectModelAttribute> attributes =
+ (List<ObjectModelAttribute>) input.getAttributes();
+
+ List<ObjectModelAttribute> attrs =
+ new ArrayList<ObjectModelAttribute>();
+ for (ObjectModelAttribute attr : attributes) {
+ if (attr.isNavigable()) {
+
+ // only keep navigable attributes
+ attrs.add(attr);
+ }
+ }
+ return attrs;
+ }
+
+ protected void createGetMethod(ObjectModelClass output,
+ String attrName,
+ String attrType,
+ String methodPrefix) {
+
+ ObjectModelOperation operation = addOperation(
+ output,
+ getJavaBeanMethodName(methodPrefix, attrName),
+ attrType,
+ ObjectModelJavaModifier.PUBLIC
+ );
+ setOperationBody(operation, ""
+ /*{
+ return <%=attrName%>;
+ }*/
+ );
+ }
+
+ protected void createGetChildMethod(ObjectModelClass output,
+ String attrName,
+ String attrType,
+ String simpleType) {
+ ObjectModelOperation operation = addOperation(
+ output,
+ getJavaBeanMethodName("get", attrName),
+ attrType,
+ ObjectModelJavaModifier.PUBLIC
+ );
+ addParameter(operation, "int", "index");
+ setOperationBody(operation, ""
+ /*{
+ <%=simpleType%> o = getChild(<%=attrName%>, index);
+ return o;
+ }*/
+ );
+ }
+
+ protected void createIsEmptyMethod(ObjectModelClass output,
+ String attrName) {
+ ObjectModelOperation operation = addOperation(
+ output,
+ getJavaBeanMethodName("is", attrName) + "Empty",
+ boolean.class,
+ ObjectModelJavaModifier.PUBLIC
+ );
+ setOperationBody(operation, ""
+ /*{
+ return <%=attrName%> == null || <%=attrName%>.isEmpty();
+ }*/
+ );
+ }
+
+ protected void createSizeMethod(ObjectModelClass output,
+ String attrName) {
+ ObjectModelOperation operation = addOperation(
+ output,
+ getJavaBeanMethodName("size", attrName),
+ int.class,
+ ObjectModelJavaModifier.PUBLIC
+ );
+ setOperationBody(operation, ""
+ /*{
+ return <%=attrName%> == null ? 0 : <%=attrName%>.size();
+ }*/
+ );
+ }
+
+ protected void createAddChildMethod(ObjectModelClass output,
+ String attrName,
+ String attrType,
+ String constantName,
+ boolean usePCS) {
+ ObjectModelOperation operation = addOperation(
+ output,
+ getJavaBeanMethodName("add", attrName),
+ "void",
+ ObjectModelJavaModifier.PUBLIC
+ );
+ addParameter(operation, attrType, attrName);
+
+ String methodName = getJavaBeanMethodName("get", attrName);
+ StringBuilder buffer = new StringBuilder(""
+ /*{
+ <%=methodName%>().add(<%=attrName%>);
+ }*/
+ );
+ if (usePCS) {
+ buffer.append(""
+ /*{ firePropertyChange(<%=constantName%>, null, <%=attrName%>);
+ }*/
+ );
+ }
+ setOperationBody(operation, buffer.toString());
+ }
+
+ protected void createAddAllChildrenMethod(ObjectModelClass output,
+ String attrName,
+ String attrType,
+ String constantName,
+ boolean usePCS) {
+ ObjectModelOperation operation = addOperation(
+ output,
+ getJavaBeanMethodName("addAll", attrName),
+ "void",
+ ObjectModelJavaModifier.PUBLIC
+ );
+ addParameter(operation, "java.util.Collection<" + attrType + ">", attrName);
+
+ String methodName = getJavaBeanMethodName("get", attrName);
+ StringBuilder buffer = new StringBuilder(""
+ /*{
+ <%=methodName%>().addAll(<%=attrName%>);
+ }*/
+ );
+ if (usePCS) {
+ buffer.append(""
+ /*{ firePropertyChange(<%=constantName%>, null, <%=attrName%>);
+ }*/
+ );
+ }
+ setOperationBody(operation, buffer.toString());
+ }
+
+ protected void createRemoveChildMethod(ObjectModelClass output,
+ String attrName,
+ String attrType,
+ String constantName,
+ boolean usePCS) {
+ ObjectModelOperation operation = addOperation(
+ output,
+ getJavaBeanMethodName("remove", attrName),
+ "boolean",
+ ObjectModelJavaModifier.PUBLIC
+ );
+ addParameter(operation, attrType, attrName);
+ String methodName = getJavaBeanMethodName("get", attrName);
+ StringBuilder buffer = new StringBuilder();
+ buffer.append(""
+ /*{
+ boolean removed = <%=methodName%>().remove(<%=attrName%>);}*/
+ );
+
+ if (usePCS) {
+ buffer.append(""
+ /*{
+ if (removed) {
+ firePropertyChange(<%=constantName%>, <%=attrName%>, null);
+ }}*/
+ );
+ }
+ buffer.append(""
+ /*{
+ return removed;
+ }*/
+ );
+ setOperationBody(operation, buffer.toString());
+ }
+
+ protected void createRemoveAllChildrenMethod(ObjectModelClass output,
+ String attrName,
+ String attrType,
+ String constantName,
+ boolean usePCS) {
+
+ ObjectModelOperation operation = addOperation(
+ output,
+ getJavaBeanMethodName("removeAll", attrName),
+ "boolean",
+ ObjectModelJavaModifier.PUBLIC
+ );
+ addParameter(operation, "java.util.Collection<" + attrType + ">", attrName);
+ StringBuilder buffer = new StringBuilder();
+ String methodName = getJavaBeanMethodName("get", attrName);
+ buffer.append(""
+ /*{
+ boolean removed = <%=methodName%>().removeAll(<%=attrName%>);}*/
+ );
+
+ if (usePCS) {
+ buffer.append(""
+ /*{
+ if (removed) {
+ firePropertyChange(<%=constantName%>, <%=attrName%>, null);
+ }}*/
+ );
+ }
+ buffer.append(""
+ /*{
+ return removed;
+ }*/
+ );
+ setOperationBody(operation, buffer.toString());
+ }
+
+ protected void createContainsChildMethod(ObjectModelClass output,
+ String attrName,
+ String attrType,
+ String constantName,
+ boolean usePCS) {
+
+ ObjectModelOperation operation = addOperation(
+ output,
+ getJavaBeanMethodName("contains", attrName),
+ "boolean",
+ ObjectModelJavaModifier.PUBLIC
+ );
+ addParameter(operation, attrType, attrName);
+ StringBuilder buffer = new StringBuilder();
+ String methodName = getJavaBeanMethodName("get", attrName);
+ buffer.append(""
+ /*{
+ boolean contains = <%=methodName%>().contains(<%=attrName%>);
+ return contains;
+ }*/
+ );
+ setOperationBody(operation, buffer.toString());
+ }
+
+ protected void createContainsAllChildrenMethod(ObjectModelClass output,
+ String attrName,
+ String attrType,
+ String constantName,
+ boolean usePCS) {
+
+ ObjectModelOperation operation = addOperation(
+ output,
+ getJavaBeanMethodName("containsAll", attrName),
+ "boolean",
+ ObjectModelJavaModifier.PUBLIC
+ );
+ addParameter(operation, "java.util.Collection<" + attrType + ">", attrName);
+ StringBuilder buffer = new StringBuilder();
+ String methodName = getJavaBeanMethodName("get", attrName);
+ buffer.append(""
+ /*{
+ boolean contains = <%=methodName%>().containsAll(<%=attrName%>);
+ return contains;
+ }*/
+ );
+ setOperationBody(operation, buffer.toString());
+ }
+
+ protected void createSetMethod(ObjectModelClass output,
+ String attrName,
+ String attrType,
+ String simpleType,
+ String constantName,
+ boolean usePCS) {
+ ObjectModelOperation operation = addOperation(
+ output,
+ getJavaBeanMethodName("set", attrName),
+ "void",
+ ObjectModelJavaModifier.PUBLIC
+ );
+ addParameter(operation, attrType, attrName);
+
+ if (usePCS) {
+ String methodName = getJavaBeanMethodName("get", attrName);
+ setOperationBody(operation, ""
+ /*{
+ <%=simpleType%> oldValue = <%=methodName%>();
+ this.<%=attrName%> = <%=attrName%>;
+ firePropertyChange(<%=constantName%>, oldValue, <%=attrName%>);
+ }*/
+ );
+ } else {
+ setOperationBody(operation, ""
+ /*{
+ this.<%=attrName%> = <%=attrName%>;
+ }*/
+ );
+ }
+ }
+
+ protected void addSerializable(ObjectModelClass input,
+ ObjectModelClass output,
+ boolean interfaceFound) {
+ if (!interfaceFound) {
+ addInterface(output, Serializable.class);
+ }
+
+ // Generate the serialVersionUID
+ long serialVersionUID = JpaTemplatesGeneratorUtil.generateSerialVersionUID(input);
+
+ addConstant(output,
+ JpaTemplatesGeneratorUtil.SERIAL_VERSION_UID,
+ "long",
+ serialVersionUID + "L",
+ ObjectModelJavaModifier.PRIVATE
+ );
+ }
+
+ /**
+ * Add all interfaces defines in input class and returns if
+ * {@link Serializable} interface was found.
+ *
+ * @param input the input model class to process
+ * @param output the output generated class
+ * @return {@code true} if {@link Serializable} was found from input,
+ * {@code false} otherwise
+ */
+ protected boolean addInterfaces(ObjectModelClass input,
+ ObjectModelClass output) {
+ boolean foundSerializable = false;
+ for (ObjectModelInterface parentInterface : input.getInterfaces()) {
+ String fqn = parentInterface.getQualifiedName();
+ addInterface(output, fqn);
+ if (Serializable.class.getName().equals(fqn)) {
+ foundSerializable = true;
+ }
+ }
+ return foundSerializable;
+ }
+
+ protected void createPropertyChangeSupport(ObjectModelClass output) {
+
+ addAttribute(output,
+ "pcs",
+ PropertyChangeSupport.class,
+ "new PropertyChangeSupport(this)",
+ ObjectModelJavaModifier.PROTECTED,
+ ObjectModelJavaModifier.FINAL,
+ ObjectModelJavaModifier.TRANSIENT
+ );
+
+ // Add PropertyListener
+
+ ObjectModelOperation operation;
+
+ operation = addOperation(output,
+ "addPropertyChangeListener",
+ "void",
+ ObjectModelJavaModifier.PUBLIC
+ );
+ addParameter(operation, PropertyChangeListener.class, "listener");
+ setOperationBody(operation, ""
+ /*{
+ pcs.addPropertyChangeListener(listener);
+ }*/
+ );
+
+ operation = addOperation(output,
+ "addPropertyChangeListener",
+ "void",
+ ObjectModelJavaModifier.PUBLIC
+ );
+ addParameter(operation, String.class, "propertyName");
+ addParameter(operation, PropertyChangeListener.class, "listener");
+ setOperationBody(operation, ""
+ /*{
+ pcs.addPropertyChangeListener(propertyName, listener);
+ }*/
+ );
+
+ operation = addOperation(output,
+ "removePropertyChangeListener",
+ "void",
+ ObjectModelJavaModifier.PUBLIC
+ );
+ addParameter(operation, PropertyChangeListener.class, "listener");
+ setOperationBody(operation, ""
+ /*{
+ pcs.removePropertyChangeListener(listener);
+ }*/
+ );
+
+ operation = addOperation(output,
+ "removePropertyChangeListener",
+ "void",
+ ObjectModelJavaModifier.PUBLIC
+ );
+ addParameter(operation, String.class, "propertyName");
+ addParameter(operation, PropertyChangeListener.class, "listener");
+ setOperationBody(operation, ""
+ /*{
+ pcs.removePropertyChangeListener(propertyName, listener);
+ }*/
+ );
+
+ operation = addOperation(output,
+ "firePropertyChange",
+ "void",
+ ObjectModelJavaModifier.PROTECTED
+ );
+ addParameter(operation, String.class, "propertyName");
+ addParameter(operation, Object.class, "oldValue");
+ addParameter(operation, Object.class, "newValue");
+ setOperationBody(operation, ""
+ /*{
+ pcs.firePropertyChange(propertyName, oldValue, newValue);
+ }*/
+ );
+
+ operation = addOperation(output,
+ "firePropertyChange",
+ "void",
+ ObjectModelJavaModifier.PROTECTED
+ );
+ addParameter(operation, String.class, "propertyName");
+ addParameter(operation, Object.class, "newValue");
+ setOperationBody(operation, ""
+ /*{
+ firePropertyChange(propertyName, null, newValue);
+ }*/
+ );
+ }
+
+ protected void createGetChildMethod(ObjectModelClass output) {
+ ObjectModelOperation getChild = addOperation(
+ output,
+ "getChild", "<T> T",
+ ObjectModelJavaModifier.PROTECTED
+ );
+ addImport(output, List.class);
+
+ addParameter(getChild, "java.util.Collection<T>", "childs");
+ addParameter(getChild, "int", "index");
+ setOperationBody(getChild, ""
+/*{
+ T result = null;
+ if (childs != null) {
+ if (childs instanceof List) {
+ if (index < childs.size()) {
+ result = ((List<T>) childs).get(index);
+ }
+ } else {
+ int i = 0;
+ for (T o : childs) {
+ if (index == i) {
+ result = o;
+ break;
+ }
+ i++;
+ }
+ }
+ }
+ return result;
+}*/
+ );
+ }
+}
Property changes on: nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/AbstractJpaTransformer.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Added: nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaDaoTransformer.java
===================================================================
--- nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaDaoTransformer.java (rev 0)
+++ nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaDaoTransformer.java 2013-05-24 16:42:23 UTC (rev 622)
@@ -0,0 +1,166 @@
+package org.nuiton.jpa.templates;
+
+/*
+ * #%L
+ * EUGene :: JPA templates
+ * $Id$
+ * $HeadURL: http://svn.nuiton.org/svn/eugene/trunk/eugene-jpa-templates/src/main/java/o… $
+ * %%
+ * Copyright (C) 2013 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
+
+
+/*{generator option: parentheses = false}*/
+/*{generator option: writeString = +}*/
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.nuiton.eugene.models.object.ObjectModelClass;
+import org.nuiton.eugene.models.object.ObjectModelJavaModifier;
+import org.nuiton.eugene.models.object.ObjectModelOperation;
+import org.nuiton.jpa.api.AbstractJpaDao;
+
+import javax.persistence.EntityManager;
+
+/**
+ * JpaDaoTransformer generates a dao for an entity.
+ * <p/>
+ * <ul>
+ * <li>{@code AbstractXXXJpaDao}: abstract jpa dao for entity named {@code XXX}, will find here the generated stuff (with jpa mapping, technical stuff)</li>
+ * <li>{@code XXXJpaDao}: concrete public jpa dao to use in your persistence layer</li>
+ * </ul>
+ * <p/>
+ * {@code Note:} All classes found in class-path are not generated.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @plexus.component role="org.nuiton.eugene.Template" role-hint="org.nuiton.eugene.jpa.JpaDaoTransformer"
+ * @since 0.1
+ */
+public class JpaDaoTransformer extends AbstractJpaTransformer {
+
+ private static final Log log = LogFactory.getLog(JpaDaoTransformer.class);
+
+ protected String getConcreteName(ObjectModelClass input) {
+ return input.getName() + "JpaDao";
+ }
+
+ @Override
+ public void transformFromClass(ObjectModelClass input) {
+
+ String entityAbstractName = "Abstract" + input.getName() + "JpaDao";
+
+ String entityConcreteName = getConcreteName(input);
+
+ boolean generateAbstract = !isInClassPath(input.getPackageName(),
+ entityAbstractName);
+
+ boolean generateConcrete = !isInClassPath(input.getPackageName(),
+ entityConcreteName);
+
+ if (generateAbstract) {
+
+ generateAbstract(input, entityAbstractName);
+ }
+
+ if (generateConcrete) {
+
+ generateImpl(input, entityConcreteName);
+ }
+ }
+
+ protected ObjectModelClass generateAbstract(ObjectModelClass input,
+ String entityAbstractName) {
+
+ // test if a super class is in same package (so is yet another entity)
+ boolean superClassIsEntity = isSuperClassEntity(input);
+
+ String superClass;
+
+ if (superClassIsEntity) {
+
+ // get first super-class
+ ObjectModelClass superClassModel = input.getSuperclasses().iterator().next();
+ superClass = getConcreteName(superClassModel);
+
+ } else {
+
+ // try to find a super class by tag-value
+ superClass = JpaTemplatesGeneratorUtil.getDaoSuperClassTagValue(
+ model, input);
+
+ if (superClass == null) {
+
+ // no super-class, use default one
+ superClass = AbstractJpaDao.class.getName();
+ }
+ }
+
+ // detect if there is a contract to set on abstract
+ String packageName = input.getPackageName();
+
+ String daoContractName = input.getPackageName() + "." + input.getName() + "Dao";
+
+ boolean addUserDaoContract = isInClassPath(daoContractName);
+
+ ObjectModelClass output =
+ createAbstractClass(entityAbstractName, packageName);
+
+ setSuperClass(output, superClass);
+
+ if (addUserDaoContract) {
+ addInterface(output, daoContractName);
+ }
+
+ addConstructor(output);
+
+ if (log.isDebugEnabled()) {
+ log.debug("will generate " + output.getQualifiedName());
+ }
+
+ return output;
+ }
+
+ protected ObjectModelClass generateImpl(ObjectModelClass input,
+ String entityConcreteName) {
+
+ ObjectModelClass output = createClass(
+ entityConcreteName,
+ input.getPackageName()
+ );
+
+ // set the abstract resulClass as the resultClassImpl super class
+ setSuperClass(output, input.getQualifiedName());
+
+ addConstructor(output);
+
+ if (log.isDebugEnabled()) {
+ log.debug("will generate " + output.getQualifiedName());
+ }
+
+ return output;
+ }
+
+ protected void addConstructor(ObjectModelClass output) {
+
+ ObjectModelOperation constructor = addConstructor(
+ output,
+ ObjectModelJavaModifier.PUBLIC);
+
+ addParameter(constructor, EntityManager.class, "entityManager");
+ }
+}
\ No newline at end of file
Property changes on: nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaDaoTransformer.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Added: nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaEntityTransformer.java
===================================================================
--- nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaEntityTransformer.java (rev 0)
+++ nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaEntityTransformer.java 2013-05-24 16:42:23 UTC (rev 622)
@@ -0,0 +1,346 @@
+package org.nuiton.jpa.templates;
+
+/*
+ * #%L
+ * EUGene :: JPA templates
+ * $Id$
+ * $HeadURL: http://svn.nuiton.org/svn/eugene/trunk/eugene-jpa-templates/src/main/java/o… $
+ * %%
+ * Copyright (C) 2013 CodeLutin, Tony Chemit
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
+
+import com.google.common.collect.ArrayListMultimap;
+import com.google.common.collect.Multimap;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.nuiton.eugene.models.object.ObjectModelAttribute;
+import org.nuiton.eugene.models.object.ObjectModelClass;
+import org.nuiton.eugene.models.object.ObjectModelJavaModifier;
+import org.nuiton.eugene.models.object.ObjectModelOperation;
+import org.nuiton.jpa.api.AbstractJpaEntity;
+
+import java.util.Collection;
+import java.util.List;
+import java.util.Set;
+
+/*{generator option: parentheses = false}*/
+/*{generator option: writeString = +}*/
+
+/**
+ * JpaEntityTransformer generates two type of classes:
+ * <ul>
+ * <li>{@code AbstractJpaXXXEntity}: abstract jpa entity for entity named {@code XXX}, will find here the generated stuff (with jpa mapping, technical stuff) </li>
+ * <li>{@code JpaXXXEntity}: concrete public jpa entity to use in your persistence layer</li>
+ * </ul>
+ * <p/>
+ * {@code Note:} All classes found in class-path are not generated.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @plexus.component role="org.nuiton.eugene.Template" role-hint="org.nuiton.eugene.jpa.JpaEntityTransformer"
+ * @since 0.1
+ */
+public class JpaEntityTransformer extends AbstractJpaTransformer {
+
+ private static final Log log =
+ LogFactory.getLog(JpaEntityTransformer.class);
+
+ protected String getConcreteName(ObjectModelClass input) {
+ return input.getName();
+ }
+
+ @Override
+ public void transformFromClass(ObjectModelClass input) {
+
+ String entityAbstractName = "Jpa" + input.getName();
+
+ String entityConcreteName = getConcreteName(input);
+
+ boolean generateAbstract = !isInClassPath(input.getPackageName(), entityAbstractName);
+
+ boolean generateConcrete = !isInClassPath(input.getPackageName(), entityConcreteName);
+
+ if (generateAbstract) {
+
+ generateAbstract(input, entityAbstractName);
+ }
+
+ if (generateConcrete) {
+
+ generateImpl(input, entityConcreteName);
+ }
+ }
+
+ protected void createAbstractOperations(ObjectModelClass ouput,
+ Iterable<ObjectModelOperation> operations) {
+ JpaTemplatesGeneratorUtil.cloneOperations(
+ this,
+ operations,
+ ouput,
+ true,
+ ObjectModelJavaModifier.ABSTRACT
+ );
+ }
+
+ protected ObjectModelClass generateAbstract(ObjectModelClass input,
+ String entityAbstractName) {
+
+ // test if a super class is in same package (so is yet another entity)
+ boolean superClassIsEntity = isSuperClassEntity(input);
+
+ String superClass;
+
+ if (superClassIsEntity) {
+
+ // get first super-class
+ ObjectModelClass superClassModel =
+ input.getSuperclasses().iterator().next();
+ superClass = getConcreteName(superClassModel);
+
+ } else {
+
+ // try to find a super class by tag-value
+ superClass = JpaTemplatesGeneratorUtil.getDaoSuperClassTagValue(
+ model, input);
+
+ if (superClass == null) {
+
+ // no super-class, use default one
+ superClass = AbstractJpaEntity.class.getName();
+
+ } else {
+
+ // will act as if super class is a bean
+ superClassIsEntity = true;
+ }
+ }
+
+ ObjectModelClass output =
+ createAbstractClass(entityAbstractName, input.getPackageName());
+
+ setSuperClass(output, superClass);
+
+ if (log.isDebugEnabled()) {
+ log.debug("will generate " + output.getQualifiedName());
+ }
+
+ String prefix = getConstantPrefix(input, DEFAULT_CONSTANT_PREFIX);
+
+ setConstantPrefix(prefix);
+
+ boolean serializableFound = addInterfaces(input, output);
+
+ if (superClassIsEntity) {
+ serializableFound = true;
+ }
+
+ addSerializable(input, output, serializableFound);
+
+ Set<String> constantNames = addConstantsFromDependency(input, output);
+
+ // Get available properties
+ List<ObjectModelAttribute> properties = getProperties(input);
+
+ //TODO Add attribute id (+ @Id)
+ //TODO Add @MappedSuperClass sur output)
+ //TODO 1 -> 1 @OnetoOne (uniquement navigeable sans bidi) si composition (Cascade = ALL) si aggregeation Cascade = (tout sauf ALL TODO A check) + orphanRemoval = true)
+ //TODO * -> 1 @ManyToOne (uniquement navigeable sans bidi) si composition (Cascade = ALL) si aggregeation Cascade = (tout sauf ALL TODO A check) + orphanRemoval = true)
+ //TODO 1 -> * @OneToMany (uniquement navigeable sans bidi) si composition (Cascade = ALL) si aggregeation Cascade = (tout sauf ALL TODO A check) + orphanRemoval = true)
+ //TODO * -> * @ManyToMany (uniquement navigeable sans bidi) si composition (Cascade = ALL) si aggregeation Cascade = (tout sauf ALL TODO A check) + orphanRemoval = true)
+
+ //TODO Si ORDERED ou et UNIQUE choisir le bon type de collection (O+U = LHS (laisser ça comme definition), (U = HS + S), (O = ArrayList +L), ( = ArrayList + C)
+ //TODO Si ORDERED ajouter l'annotation @OrderColumn
+ //TODO Si enumeration @Enumeration(value = EnumType.STRING) (Voir pour mettre une tag-value pour mettre en ordinal) + voir comment ça marche pour les collections
+
+ //TODO Generate Persistence annotations
+ Multimap<ObjectModelAttribute, String> annotationsForAttributes =
+ ArrayListMultimap.create();
+
+
+ // Add properties constant
+ for (ObjectModelAttribute attr : properties) {
+
+ createPropertyConstant(output, attr, prefix, constantNames);
+ }
+
+ // Add properties field + javabean methods
+ for (ObjectModelAttribute attr : properties) {
+
+ createProperty(output, attr, annotationsForAttributes.get(attr));
+ }
+
+ boolean hasAMultipleProperty = containsMutiple(properties);
+
+ // Add helper operations
+ if (hasAMultipleProperty) {
+
+
+ // add getChild methods
+ createGetChildMethod(output);
+
+
+ }
+ return output;
+ }
+
+ protected ObjectModelClass generateImpl(ObjectModelClass input,
+ String entityConcreteName) {
+
+ ObjectModelClass resultClassImpl = createClass(
+ entityConcreteName,
+ input.getPackageName()
+ );
+
+ // set the abstract resulClass as the resultClassImpl super class
+ setSuperClass(resultClassImpl, input.getQualifiedName());
+
+ // add a fix serialVersionUID, since the class has no field nor method
+ addConstant(resultClassImpl,
+ JpaTemplatesGeneratorUtil.SERIAL_VERSION_UID,
+ "long",
+ "1L",
+ ObjectModelJavaModifier.PRIVATE
+ );
+ return resultClassImpl;
+ }
+
+ protected void createProperty(ObjectModelClass output,
+ ObjectModelAttribute attr,
+ Collection<String> annotations) {
+
+ boolean usePCS = false;
+
+ String attrName = getAttributeName(attr);
+ String attrType = getAttributeType(attr);
+
+ boolean multiple = JpaTemplatesGeneratorUtil.isNMultiplicity(attr);
+
+ String constantName = getConstantName(attrName);
+ String simpleType = JpaTemplatesGeneratorUtil.getSimpleName(attrType);
+
+ if (multiple) {
+
+ createGetChildMethod(output,
+ attrName,
+ attrType,
+ simpleType
+ );
+
+ createIsEmptyMethod(output,
+ attrName
+ );
+
+ createSizeMethod(output,
+ attrName
+ );
+
+ createAddChildMethod(output,
+ attrName,
+ attrType,
+ constantName,
+ usePCS
+ );
+
+ createAddAllChildrenMethod(output,
+ attrName,
+ attrType,
+ constantName,
+ usePCS
+ );
+
+ createRemoveChildMethod(output,
+ attrName,
+ attrType,
+ constantName,
+ usePCS
+ );
+
+ createRemoveAllChildrenMethod(output,
+ attrName,
+ attrType,
+ constantName,
+ usePCS
+ );
+
+ createContainsChildMethod(output,
+ attrName,
+ attrType,
+ constantName,
+ usePCS
+ );
+
+ createContainsAllChildrenMethod(output,
+ attrName,
+ attrType,
+ constantName,
+ usePCS
+ );
+
+ // Change type for Multiple attribute
+ if (attr.isOrdered()) {
+ attrType = List.class.getName() + "<" + attrType + ">";
+ } else {
+ attrType = Collection.class.getName() + "<" + attrType + ">";
+ }
+
+ simpleType = JpaTemplatesGeneratorUtil.getSimpleName(attrType);
+ }
+
+ boolean booleanProperty = JpaTemplatesGeneratorUtil.isBooleanPrimitive(attr);
+
+ if (booleanProperty && !multiple) {
+
+ // creates a isXXX method
+ createGetMethod(output,
+ attrName,
+ attrType,
+ JpaTemplatesGeneratorUtil.OPERATION_GETTER_BOOLEAN_PREFIX
+ );
+ }
+
+ if (multiple || !booleanProperty) {
+
+ createGetMethod(output,
+ attrName,
+ attrType,
+ JpaTemplatesGeneratorUtil.OPERATION_GETTER_DEFAULT_PREFIX
+ );
+
+ }
+ createSetMethod(output,
+ attrName,
+ attrType,
+ simpleType,
+ constantName,
+ usePCS
+ );
+
+ // Add attribute to the class
+ ObjectModelAttribute attribute = addAttribute(output,
+ attrName,
+ attrType,
+ "",
+ ObjectModelJavaModifier.PROTECTED
+ );
+
+ for (String annotation : annotations) {
+ addAnnotation(output, attribute, annotation);
+ }
+
+ }
+
+}
\ No newline at end of file
Property changes on: nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaEntityTransformer.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Added: nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaTemplatesGeneratorUtil.java
===================================================================
--- nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaTemplatesGeneratorUtil.java (rev 0)
+++ nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaTemplatesGeneratorUtil.java 2013-05-24 16:42:23 UTC (rev 622)
@@ -0,0 +1,72 @@
+package org.nuiton.jpa.templates;
+
+/*
+ * #%L
+ * EUGene :: JPA templates
+ * $Id$
+ * $HeadURL: http://svn.nuiton.org/svn/eugene/trunk/eugene-jpa-templates/src/main/java/o… $
+ * %%
+ * Copyright (C) 2013 CodeLutin, Tony Chemit
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
+
+import org.nuiton.eugene.java.JavaGeneratorUtil;
+import org.nuiton.eugene.models.object.ObjectModel;
+import org.nuiton.eugene.models.object.ObjectModelClassifier;
+
+/**
+ * Utility class for pure jpa templates.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.7
+ */
+public class JpaTemplatesGeneratorUtil extends JavaGeneratorUtil {
+
+ /**
+ * Obtain the value of the {@link JpaTemplatesTagValues#TAG_ENTITY_SUPER_CLASS}
+ * tag value on the given model or classifier.
+ * <p/>
+ * It will first look on the model, and then in the given classifier.
+ *
+ * @param model model to seek
+ * @param classifier classifier to seek
+ * @return the none empty value of the found tag value or {@code null} if not found nor empty.
+ * @see JpaTemplatesTagValues#TAG_ENTITY_SUPER_CLASS
+ * @since 2.3
+ */
+ public static String getEntitySuperClassTagValue(ObjectModel model, ObjectModelClassifier classifier) {
+ String value = findTagValue(JpaTemplatesTagValues.TAG_ENTITY_SUPER_CLASS, classifier, model);
+ return value;
+ }
+
+ /**
+ * Obtain the value of the {@link JpaTemplatesTagValues#TAG_DAO_SUPER_CLASS}
+ * tag value on the given model or classifier.
+ * <p/>
+ * It will first look on the model, and then in the given classifier.
+ *
+ * @param model model to seek
+ * @param classifier classifier to seek
+ * @return the none empty value of the found tag value or {@code null} if not found nor empty.
+ * @see JpaTemplatesTagValues#TAG_DAO_SUPER_CLASS
+ * @since 2.3
+ */
+ public static String getDaoSuperClassTagValue(ObjectModel model, ObjectModelClassifier classifier) {
+ String value = findTagValue(JpaTemplatesTagValues.TAG_ENTITY_SUPER_CLASS, classifier, model);
+ return value;
+ }
+}
Property changes on: nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaTemplatesGeneratorUtil.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Added: nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaTemplatesModelPropertiesProvider.java
===================================================================
--- nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaTemplatesModelPropertiesProvider.java (rev 0)
+++ nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaTemplatesModelPropertiesProvider.java 2013-05-24 16:42:23 UTC (rev 622)
@@ -0,0 +1,43 @@
+package org.nuiton.jpa.templates;
+
+/*
+ * #%L
+ * EUGene :: JPA templates
+ * $Id$
+ * $HeadURL: http://svn.nuiton.org/svn/eugene/trunk/eugene-jpa-templates/src/main/java/o… $
+ * %%
+ * Copyright (C) 2013 CodeLutin, Tony Chemit
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
+
+import org.nuiton.eugene.ModelPropertiesUtil;
+
+/**
+ * The JPA templates provider of tag values and stereotypes.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @plexus.component role="org.nuiton.eugene.ModelPropertiesUtil$ModelPropertiesProvider" role-hint="jpa"
+ * @since 2.7
+ */
+public class JpaTemplatesModelPropertiesProvider extends ModelPropertiesUtil.ModelPropertiesProvider {
+
+ @Override
+ public void init() throws IllegalAccessException {
+ scanStereotypeClass(JpaTemplatesStereoTypes.class);
+ scanTagValueClass(JpaTemplatesTagValues.class);
+ }
+}
Property changes on: nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaTemplatesModelPropertiesProvider.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Added: nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaTemplatesStereoTypes.java
===================================================================
--- nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaTemplatesStereoTypes.java (rev 0)
+++ nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaTemplatesStereoTypes.java 2013-05-24 16:42:23 UTC (rev 622)
@@ -0,0 +1,37 @@
+package org.nuiton.jpa.templates;
+
+/*
+ * #%L
+ * EUGene :: JPA templates
+ * $Id$
+ * $HeadURL: http://svn.nuiton.org/svn/eugene/trunk/eugene-jpa-templates/src/main/java/o… $
+ * %%
+ * Copyright (C) 2013 CodeLutin, Tony Chemit
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
+
+import org.nuiton.eugene.EugeneStereoTypes;
+
+/**
+ * Defines all stereotypes managed by JPA templates.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.7
+ */
+public interface JpaTemplatesStereoTypes extends EugeneStereoTypes {
+
+}
Property changes on: nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaTemplatesStereoTypes.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Added: nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaTemplatesTagValues.java
===================================================================
--- nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaTemplatesTagValues.java (rev 0)
+++ nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaTemplatesTagValues.java 2013-05-24 16:42:23 UTC (rev 622)
@@ -0,0 +1,65 @@
+package org.nuiton.jpa.templates;
+
+/*
+ * #%L
+ * EUGene :: JPA templates
+ * $Id$
+ * $HeadURL: http://svn.nuiton.org/svn/eugene/trunk/eugene-jpa-templates/src/main/java/o… $
+ * %%
+ * Copyright (C) 2013 CodeLutin, Tony Chemit
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
+
+import org.nuiton.eugene.EugeneTagValues;
+import org.nuiton.eugene.ModelPropertiesUtil;
+import org.nuiton.eugene.models.object.ObjectModel;
+import org.nuiton.eugene.models.object.ObjectModelClassifier;
+
+/**
+ * Defines all tag values managed by JPA templates.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.7
+ */
+public interface JpaTemplatesTagValues extends EugeneTagValues {
+
+ /**
+ * Tag value to use a super class for generated bean.
+ *
+ * @see JpaTemplatesGeneratorUtil#getEntitySuperClassTagValue(ObjectModel, ObjectModelClassifier)
+ * @since 0.1
+ */
+ @ModelPropertiesUtil.TagValueDefinition(
+ target = {ObjectModel.class, ObjectModelClassifier.class},
+ documentation = "To specify a super-class to used on generated entities " +
+ "for a class or any class of a model")
+ String TAG_ENTITY_SUPER_CLASS = "entitySuperClass";
+
+
+ /**
+ * Tag value to use a super class for generated bean.
+ *
+ * @see JpaTemplatesGeneratorUtil#getDaoSuperClassTagValue(ObjectModel, ObjectModelClassifier)
+ * @since 0.1
+ */
+ @ModelPropertiesUtil.TagValueDefinition(
+ target = {ObjectModel.class, ObjectModelClassifier.class},
+ documentation = "To specify a super-class to used on generated dao " +
+ "for a class or any class of a model")
+ String TAG_DAO_SUPER_CLASS = "daoSuperClass";
+
+}
Property changes on: nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/JpaTemplatesTagValues.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Added: nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/package-info.java
===================================================================
--- nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/package-info.java (rev 0)
+++ nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/package-info.java 2013-05-24 16:42:23 UTC (rev 622)
@@ -0,0 +1,10 @@
+/**
+ * Eugene jpa package : JPA generators.
+ * <pre>
+ * - Generator : {@link JpaEntityTransformer } to generate a jap entity.
+ * - Generator : {@link JpaDaoTransformer } to generate a dao.
+ * - Generator : {@link JpaPersistenceContextTransformer } to generate a dao.
+ * </pre>
+ */
+package org.nuiton.jpa.templates;
+
Property changes on: nuiton-jpa/nuiton-jpa-templates/src/main/java/org/nuiton/jpa/templates/package-info.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Modified: nuiton-jpa/pom.xml
===================================================================
--- nuiton-jpa/pom.xml 2013-05-24 15:48:17 UTC (rev 621)
+++ nuiton-jpa/pom.xml 2013-05-24 16:42:23 UTC (rev 622)
@@ -76,12 +76,6 @@
</dependency>
<dependency>
- <groupId>org.nuiton</groupId>
- <artifactId>nuiton-utils</artifactId>
- <version>${nuitonUtilsVersion}</version>
- </dependency>
-
- <dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.0-api</artifactId>
<version>1.0.1.Final</version>
1
0
r621 - in nuiton-jpa: . nuiton-jpa-api nuiton-jpa-api/src/main/java/org/nuiton/jpa nuiton-jpa-api/src/main/java/org/nuiton/jpa/api nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/hibernate nuiton-jpa-junit nuiton-jpa-junit/src/main/java/org/nuiton/jpa nuiton-jpa-junit/src/main/java/org/nuiton/jpa/junit
by bleny@users.nuiton.org 24 May '13
by bleny@users.nuiton.org 24 May '13
24 May '13
Author: bleny
Date: 2013-05-24 17:48:17 +0200 (Fri, 24 May 2013)
New Revision: 621
Url: http://nuiton.org/projects/sandbox/repository/revisions/621
Log:
introduce classes in nuiton-jpa-api and nuiton-jpa-junit
Added:
nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/
nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/AbstractJpaDao.java
nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/JpaDao.java
nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/JpaEntity.java
nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/hibernate/
nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/hibernate/HibernateUtil.java
nuiton-jpa/nuiton-jpa-junit/src/main/java/org/nuiton/jpa/junit/
nuiton-jpa/nuiton-jpa-junit/src/main/java/org/nuiton/jpa/junit/JpaEntityManagerRule.java
Modified:
nuiton-jpa/nuiton-jpa-api/pom.xml
nuiton-jpa/nuiton-jpa-junit/pom.xml
nuiton-jpa/pom.xml
Modified: nuiton-jpa/nuiton-jpa-api/pom.xml
===================================================================
--- nuiton-jpa/nuiton-jpa-api/pom.xml 2013-05-24 15:21:33 UTC (rev 620)
+++ nuiton-jpa/nuiton-jpa-api/pom.xml 2013-05-24 15:48:17 UTC (rev 621)
@@ -13,6 +13,40 @@
<groupId>org.nuiton.jpa</groupId>
<artifactId>nuiton-jpa-api</artifactId>
+ <dependencies>
+
+ <dependency>
+ <groupId>org.hibernate.javax.persistence</groupId>
+ <artifactId>hibernate-jpa-2.0-api</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.hibernate</groupId>
+ <artifactId>hibernate-core</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.hibernate</groupId>
+ <artifactId>hibernate-entitymanager</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>com.h2database</groupId>
+ <artifactId>h2</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-lang3</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>commons-logging</groupId>
+ <artifactId>commons-logging</artifactId>
+ </dependency>
+
+ </dependencies>
+
<build>
Added: nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/AbstractJpaDao.java
===================================================================
--- nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/AbstractJpaDao.java (rev 0)
+++ nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/AbstractJpaDao.java 2013-05-24 15:48:17 UTC (rev 621)
@@ -0,0 +1,132 @@
+package org.nuiton.jpa.api;
+
+/*
+ * #%L
+ * MagaLiE :: Persistence
+ * $Id:$
+ * $HeadURL:$
+ * %%
+ * Copyright (C) 2013 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+
+import javax.persistence.EntityManager;
+import javax.persistence.TypedQuery;
+import java.util.List;
+
+/**
+ * This abstract class gather all code which is common to all daos for all entities.
+ *
+ * Code included is common implementations of {@link JpaDao} interface and there is
+ * also commun helpers methods for implementation business-specific operations
+ * exposed as protected.
+ *
+ * @author bleny, tchemit
+ * @since 0.1
+ */
+public abstract class AbstractJpaDao<E extends JpaEntity> implements JpaDao<E> {
+
+ protected EntityManager entityManager;
+
+ public AbstractJpaDao(EntityManager entityManager) {
+ this.entityManager = entityManager;
+ }
+
+ protected abstract Class<E> getEntityClass();
+
+ @Override
+ public E findById(String id) {
+ E entity = entityManager.find(getEntityClass(), id);
+ return entity;
+ }
+
+ @Override
+ public List<E> findAll() {
+ String simpleName = getEntityClass().getSimpleName();
+ TypedQuery<E> query = entityManager.createQuery("from " + simpleName, getEntityClass());
+ return query.getResultList();
+ }
+
+ @Override
+ public void persist(E entity) {
+ entityManager.persist(entity);
+ }
+
+ @Override
+ public E merge(E entity) {
+ E merge = entityManager.merge(entity);
+ return merge;
+ }
+
+ @Override
+ public void remove(E entity) {
+ entityManager.remove(entity);
+ }
+
+ @Override
+ public boolean contains(E entity) {
+ return entityManager.contains(entity);
+ }
+
+ @Override
+ public E newInstance() {
+ E newInstance;
+ try {
+ newInstance = getEntityClass().newInstance();
+ // TODO brendan 24/05/13 proper exception management
+ } catch (InstantiationException e) {
+ throw new RuntimeException(e);
+ } catch (IllegalAccessException e) {
+ throw new RuntimeException(e);
+ }
+ return newInstance;
+ }
+
+ protected TypedQuery<E> createQuery(String hql) {
+ TypedQuery<E> query = entityManager.createQuery(hql, getEntityClass());
+ return query;
+ }
+
+ protected List<E> findAll(TypedQuery<E> query) {
+ return query.getResultList();
+ }
+
+ protected E findUnique(TypedQuery<E> query) {
+ return query.getSingleResult();
+ }
+
+ protected E findAnyOrNull(TypedQuery<E> query) {
+ List<E> all = findAll(query);
+ E onlyElement = null;
+ if ( ! all.isEmpty()) {
+ onlyElement = all.get(0);
+ }
+ return onlyElement;
+ }
+
+ protected E findUniqueOrNull(TypedQuery<E> query) {
+ List<E> all = findAll(query);
+ E onlyElement = null;
+ if ( ! all.isEmpty()) {
+ if (all.size() > 1) {
+ throw new IllegalStateException("multiple results " + all);
+ }
+ onlyElement = all.get(0);
+ }
+ return onlyElement;
+ }
+
+}
Added: nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/JpaDao.java
===================================================================
--- nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/JpaDao.java (rev 0)
+++ nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/JpaDao.java 2013-05-24 15:48:17 UTC (rev 621)
@@ -0,0 +1,52 @@
+package org.nuiton.jpa.api;
+
+/*
+ * #%L
+ * MagaLiE :: Persistence
+ * $Id:$
+ * $HeadURL:$
+ * %%
+ * Copyright (C) 2013 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+
+import java.util.List;
+
+/**
+ * Represents de common operation we can do using JPA
+ *
+ * @param <E> is the type of the entity manipulated with this DAO
+ *
+ * @author bleny, tchemit
+ * @since 0.1
+ */
+public interface JpaDao<E extends JpaEntity> {
+
+ E findById(String id);
+
+ List<E> findAll();
+
+ void persist(E entity);
+
+ E merge(E entity);
+
+ void remove(E entity);
+
+ boolean contains(E entity);
+
+ E newInstance();
+
+}
Added: nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/JpaEntity.java
===================================================================
--- nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/JpaEntity.java (rev 0)
+++ nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/JpaEntity.java 2013-05-24 15:48:17 UTC (rev 621)
@@ -0,0 +1,59 @@
+package org.nuiton.jpa.api;
+
+/*
+ * #%L
+ * MagaLiE :: Persistence
+ * $Id:$
+ * $HeadURL:$
+ * %%
+ * Copyright (C) 2013 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+
+/**
+ * A JpaEntity must have a technical id.
+ *
+ * Also equals() is defined for compliance with JPA expectations.
+ *
+ * @author bleny, tchemit
+ * @since 0.1
+ */
+public abstract class JpaEntity {
+
+ public abstract String getId();
+
+ @Override
+ public boolean equals(Object other) {
+ String id = getId();
+ if (other instanceof JpaEntity) {
+ JpaEntity that = (JpaEntity) other;
+ return id != null && that.getId() != null && id.equals(that.getId());
+ }
+ return false;
+ }
+
+ @Override
+ public int hashCode() {
+ String id = getId();
+ return id == null ? 0 : id.hashCode();
+ }
+
+ @Override
+ public String toString() {
+ return "JpaEntity{id=" + getId() + "}";
+ }
+
+}
Added: nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/hibernate/HibernateUtil.java
===================================================================
--- nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/hibernate/HibernateUtil.java (rev 0)
+++ nuiton-jpa/nuiton-jpa-api/src/main/java/org/nuiton/jpa/api/hibernate/HibernateUtil.java 2013-05-24 15:48:17 UTC (rev 621)
@@ -0,0 +1,132 @@
+package org.nuiton.jpa.api.hibernate;
+
+import org.apache.commons.lang3.SystemUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.hibernate.cfg.Configuration;
+import org.hibernate.cfg.Environment;
+import org.hibernate.ejb.AvailableSettings;
+import org.hibernate.ejb.EntityManagerFactoryImpl;
+import org.hibernate.service.ServiceRegistry;
+import org.hibernate.service.internal.SessionFactoryServiceRegistryImpl;
+import org.hibernate.tool.hbm2ddl.SchemaExport;
+
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.Persistence;
+import java.io.File;
+import java.lang.reflect.Field;
+import java.sql.Driver;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+public class HibernateUtil {
+
+ private static final Log log = LogFactory.getLog(HibernateUtil.class);
+
+ protected static final Map<String, String> HIBERNATE_H2_CONFIG;
+
+ public static final String HBM2DDL_AUTO_VALIDATE = "validate";
+
+ public static final String HBM2DDL_AUTO_CREATE_DROP = "create-drop";
+
+ public static final String HBM2DDL_AUTO_CREATE = "create";
+
+ public static final String HBM2DDL_AUTO_UPDATE = "update";
+
+ static {
+
+ Map<String, String> hibernateH2Config = new HashMap<String, String>();
+
+ hibernateH2Config.put(AvailableSettings.JDBC_DRIVER, Driver.class.getName());
+ hibernateH2Config.put(AvailableSettings.JDBC_USER, "sa");
+ hibernateH2Config.put(AvailableSettings.JDBC_PASSWORD, "");
+ hibernateH2Config.put(Environment.DIALECT, org.hibernate.dialect.H2Dialect.class.getName());
+ hibernateH2Config.put(Environment.HBM2DDL_AUTO, HBM2DDL_AUTO_CREATE);
+
+ HIBERNATE_H2_CONFIG = Collections.unmodifiableMap(hibernateH2Config);
+
+ }
+
+ private HibernateUtil() {}
+
+ public static EntityManagerFactory createTempEntityManagerFactory(String persistenceUnitName, String context) {
+
+ EntityManagerFactory tempEntityManagerFactory =
+ createTempEntityManagerFactory(
+ persistenceUnitName,
+ context, Collections.<String, String>emptyMap());
+
+ return tempEntityManagerFactory;
+
+ }
+
+ public static EntityManagerFactory createTempEntityManagerFactory(String persistenceUnitName, String context, Map<String, String> jpaParameters) {
+
+ Map<String, String> allJpaParameters = new HashMap<String, String>();
+
+ allJpaParameters.putAll(jpaParameters);
+
+ allJpaParameters.putAll(HIBERNATE_H2_CONFIG);
+
+ File tempDirFile = SystemUtils.getJavaIoTmpDir();
+
+ File databaseFile = new File(tempDirFile, context);
+
+ String h2dataPath = databaseFile.getAbsolutePath() + File.separator + "h2data";
+
+ String jdbcUrl = "jdbc:h2:file:" + h2dataPath;
+
+ allJpaParameters.put(AvailableSettings.JDBC_URL, jdbcUrl);
+
+ if (log.isTraceEnabled()) {
+ log.trace("will store H2 data in " + h2dataPath);
+ log.trace("jdbc url is\n" + jdbcUrl);
+ log.trace("allJpaParameters = " + allJpaParameters);
+ }
+
+ EntityManagerFactory entityManagerFactory = Persistence.createEntityManagerFactory(persistenceUnitName, allJpaParameters);
+
+ return entityManagerFactory;
+
+ }
+
+ public static void cleanDatabase(EntityManager entityManager) {
+
+ if (log.isInfoEnabled()) {
+ log.info("will clean database");
+ }
+
+ ServiceRegistry serviceRegistry =
+ ((EntityManagerFactoryImpl) entityManager.getEntityManagerFactory())
+ .getSessionFactory().getServiceRegistry();
+
+ Configuration configuration = null;
+ try {
+ Field configurationField = SessionFactoryServiceRegistryImpl.class.getDeclaredField("configuration");
+ configurationField.setAccessible(true);
+ configuration = (Configuration) configurationField.get(serviceRegistry);
+ } catch (IllegalAccessException e) {
+ if (log.isErrorEnabled()) {
+ log.error("should not occur", e);
+ }
+ } catch (NoSuchFieldException e) {
+ if (log.isErrorEnabled()) {
+ log.error("should not occur", e);
+ }
+ }
+
+ SchemaExport schemaExport= new SchemaExport(serviceRegistry, configuration);
+
+ schemaExport.setHaltOnError(true);
+
+ // drop
+ schemaExport.execute(true, true, true, false);
+
+ // create
+ schemaExport.execute(true, true, false, true);
+
+ }
+
+}
\ No newline at end of file
Modified: nuiton-jpa/nuiton-jpa-junit/pom.xml
===================================================================
--- nuiton-jpa/nuiton-jpa-junit/pom.xml 2013-05-24 15:21:33 UTC (rev 620)
+++ nuiton-jpa/nuiton-jpa-junit/pom.xml 2013-05-24 15:48:17 UTC (rev 621)
@@ -14,6 +14,7 @@
<artifactId>nuiton-jpa-junit</artifactId>
<dependencies>
+
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>nuiton-jpa-api</artifactId>
@@ -25,7 +26,9 @@
<artifactId>junit</artifactId>
<scope>provided</scope>
</dependency>
+
</dependencies>
+
<build>
Added: nuiton-jpa/nuiton-jpa-junit/src/main/java/org/nuiton/jpa/junit/JpaEntityManagerRule.java
===================================================================
--- nuiton-jpa/nuiton-jpa-junit/src/main/java/org/nuiton/jpa/junit/JpaEntityManagerRule.java (rev 0)
+++ nuiton-jpa/nuiton-jpa-junit/src/main/java/org/nuiton/jpa/junit/JpaEntityManagerRule.java 2013-05-24 15:48:17 UTC (rev 621)
@@ -0,0 +1,127 @@
+package org.nuiton.jpa.junit;
+
+/*
+ * #%L
+ * MagaLiE :: Services
+ * $Id:$
+ * $HeadURL:$
+ * %%
+ * Copyright (C) 2013 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.junit.rules.TestRule;
+import org.junit.runner.Description;
+import org.junit.runners.model.Statement;
+import org.nuiton.jpa.api.hibernate.HibernateUtil;
+
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+import java.util.Date;
+import java.util.Map;
+
+public class JpaEntityManagerRule implements TestRule {
+
+ private static final Log log = LogFactory.getLog(JpaEntityManagerRule.class);
+
+ protected String persistenceUnitName;
+
+ protected String timestamp = String.valueOf(new Date().getTime());
+
+ protected EntityManager entityManager;
+
+ protected boolean open = false;
+
+ protected Map<String, String> jpaParameters;
+
+ public JpaEntityManagerRule(String persistenceUnitName, Map<String, String> jpaParameters) {
+ this.persistenceUnitName = persistenceUnitName;
+ this.jpaParameters = jpaParameters;
+ }
+
+ @Override
+ public Statement apply(final Statement base, Description description) {
+
+ final String testClassName = description.getClassName();
+
+ final String testMethodName = description.getMethodName();
+
+ if (log.isDebugEnabled()) {
+ log.debug("will create entityManager for test class "
+ + testClassName + " and method " + testMethodName);
+ }
+
+ return new Statement() {
+ @Override
+ public void evaluate() throws Throwable {
+ createEntityManager(testClassName, testMethodName);
+ try {
+ base.evaluate();
+ } finally {
+ closeEntityManager();
+ }
+ }
+ };
+ }
+
+ protected void createEntityManager(String testClassName, String testMethodName) {
+
+ String context = testClassName
+ + '_' + testMethodName
+ + '_' + timestamp;
+
+ EntityManagerFactory entityManagerFactory =
+ HibernateUtil.createTempEntityManagerFactory(
+ persistenceUnitName, context, jpaParameters);
+
+ entityManager = entityManagerFactory.createEntityManager();
+
+ if (log.isDebugEnabled()) {
+ log.debug("created entityManager " + entityManager);
+ }
+
+ open = true;
+
+ }
+
+ public EntityManager getEntityManager() {
+
+ if ( ! open) {
+ throw new IllegalStateException("entity manager is not yet opened");
+ }
+
+ return entityManager;
+
+ }
+
+ /**
+ * Override to tear down your specific external resource.
+ */
+ protected void closeEntityManager() {
+
+ if (log.isDebugEnabled()) {
+ log.debug("close entityManager " + entityManager);
+ }
+
+ open = false;
+
+ entityManager.close();
+
+ }
+
+}
Modified: nuiton-jpa/pom.xml
===================================================================
--- nuiton-jpa/pom.xml 2013-05-24 15:21:33 UTC (rev 620)
+++ nuiton-jpa/pom.xml 2013-05-24 15:48:17 UTC (rev 621)
@@ -35,6 +35,8 @@
<eugeneVersion>2.6.2</eugeneVersion>
<nuitonUtilsVersion>2.6.12</nuitonUtilsVersion>
<processorPluginVersion>1.3</processorPluginVersion>
+ <h2Version>1.3.170</h2Version>
+ <hibernateVersion>4.1.9.Final</hibernateVersion>
</properties>
@@ -85,7 +87,26 @@
<version>1.0.1.Final</version>
</dependency>
+ <dependency>
+ <groupId>org.hibernate</groupId>
+ <artifactId>hibernate-core</artifactId>
+ <version>${hibernateVersion}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.hibernate</groupId>
+ <artifactId>hibernate-entitymanager</artifactId>
+ <version>${hibernateVersion}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>com.h2database</groupId>
+ <artifactId>h2</artifactId>
+ <version>${h2Version}</version>
+ </dependency>
+
</dependencies>
+
</dependencyManagement>
<!-- ************************************************************* -->
1
0
Author: tchemit
Date: 2013-05-24 17:21:33 +0200 (Fri, 24 May 2013)
New Revision: 620
Url: http://nuiton.org/projects/sandbox/repository/revisions/620
Log:
nuiton-jpa structure
Modified:
nuiton-jpa/nuiton-jpa-templates/pom.xml
nuiton-jpa/pom.xml
Modified: nuiton-jpa/nuiton-jpa-templates/pom.xml
===================================================================
--- nuiton-jpa/nuiton-jpa-templates/pom.xml 2013-05-24 15:10:32 UTC (rev 619)
+++ nuiton-jpa/nuiton-jpa-templates/pom.xml 2013-05-24 15:21:33 UTC (rev 620)
@@ -18,15 +18,47 @@
<dependencies>
<dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>nuiton-jpa-api</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <dependency>
<groupId>org.nuiton.eugene</groupId>
<artifactId>eugene</artifactId>
</dependency>
<dependency>
- <groupId>${project.groupId}</groupId>
- <artifactId>nuiton-jpa-api</artifactId>
- <version>${project.version}</version>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-lang3</artifactId>
</dependency>
+
+ <dependency>
+ <groupId>commons-logging</groupId>
+ <artifactId>commons-logging</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>commons-collections</groupId>
+ <artifactId>commons-collections</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.hibernate.javax.persistence</groupId>
+ <artifactId>hibernate-jpa-2.0-api</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>log4j</groupId>
+ <artifactId>log4j</artifactId>
+ <scope>test</scope>
+ </dependency>
+
</dependencies>
<build>
Modified: nuiton-jpa/pom.xml
===================================================================
--- nuiton-jpa/pom.xml 2013-05-24 15:10:32 UTC (rev 619)
+++ nuiton-jpa/pom.xml 2013-05-24 15:21:33 UTC (rev 620)
@@ -79,6 +79,12 @@
<version>${nuitonUtilsVersion}</version>
</dependency>
+ <dependency>
+ <groupId>org.hibernate.javax.persistence</groupId>
+ <artifactId>hibernate-jpa-2.0-api</artifactId>
+ <version>1.0.1.Final</version>
+ </dependency>
+
</dependencies>
</dependencyManagement>
1
0