Topia-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
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2006 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2005 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2004 -----
- December
- November
- October
- September
- August
- July
- June
- May
August 2013
- 4 participants
- 17 discussions
r2791 - in trunk: . src/site src/site/resources src/site/rst src/site/rst/user topia-persistence/src/site topia-persistence/src/site/resources topia-persistence/src/site/rst
by athimel@users.nuiton.org 05 Aug '13
by athimel@users.nuiton.org 05 Aug '13
05 Aug '13
Author: athimel
Date: 2013-08-05 11:30:26 +0200 (Mon, 05 Aug 2013)
New Revision: 2791
Url: http://nuiton.org/projects/topia/repository/revisions/2791
Log:
refs #1146 Start documentation re-arrangement
Added:
trunk/src/site/resources/ClassDiagram_BookAuthor.png
trunk/src/site/resources/ClassDiagram_BookAuthorWithOperation.png
trunk/src/site/resources/ContactUseCases.png
trunk/src/site/resources/ServiceCall.png
trunk/src/site/resources/modelForTopiaQuery.png
trunk/src/site/resources/modelForTopiaQuery.zargo
trunk/src/site/resources/topia.zargo
trunk/src/site/rst/TopiaDocumentation.rst
trunk/src/site/rst/devel/
trunk/src/site/rst/user/
Removed:
trunk/topia-persistence/src/site/resources/ClassDiagram_BookAuthor.png
trunk/topia-persistence/src/site/resources/ClassDiagram_BookAuthorWithOperation.png
trunk/topia-persistence/src/site/resources/ContactUseCases.png
trunk/topia-persistence/src/site/resources/ServiceCall.png
trunk/topia-persistence/src/site/resources/modelForTopiaQuery.png
trunk/topia-persistence/src/site/resources/modelForTopiaQuery.zargo
trunk/topia-persistence/src/site/resources/topia.zargo
trunk/topia-persistence/src/site/rst/TopiaDocumentation.rst
trunk/topia-persistence/src/site/rst/devel/
trunk/topia-persistence/src/site/rst/user/
Modified:
trunk/pom.xml
trunk/src/site/rst/index.rst
trunk/src/site/rst/migrate_to_3.0.rst
trunk/src/site/rst/user/FAQ.rst
trunk/src/site/rst/user/ModelGeneration.rst.vm
trunk/src/site/rst/user/start.rst.vm
trunk/src/site/site_fr.xml
trunk/topia-persistence/src/site/rst/index.rst
trunk/topia-persistence/src/site/site_fr.xml
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2013-08-05 08:49:05 UTC (rev 2790)
+++ trunk/pom.xml 2013-08-05 09:30:26 UTC (rev 2791)
@@ -58,6 +58,9 @@
<!-- pour un muli module on doit fixer le projectId -->
<projectId>topia</projectId>
+ <!-- do not relativize links in generated site -->
+ <relativizeDecorationLinks>false</relativizeDecorationLinks>
+
<!-- libs version -->
<eugeneVersion>2.7</eugeneVersion>
<nuitonUtilsVersion>2.7</nuitonUtilsVersion>
Copied: trunk/src/site/resources/ClassDiagram_BookAuthor.png (from rev 2789, trunk/topia-persistence/src/site/resources/ClassDiagram_BookAuthor.png)
===================================================================
(Binary files differ)
Copied: trunk/src/site/resources/ClassDiagram_BookAuthorWithOperation.png (from rev 2789, trunk/topia-persistence/src/site/resources/ClassDiagram_BookAuthorWithOperation.png)
===================================================================
(Binary files differ)
Copied: trunk/src/site/resources/ContactUseCases.png (from rev 2789, trunk/topia-persistence/src/site/resources/ContactUseCases.png)
===================================================================
(Binary files differ)
Copied: trunk/src/site/resources/ServiceCall.png (from rev 2789, trunk/topia-persistence/src/site/resources/ServiceCall.png)
===================================================================
(Binary files differ)
Copied: trunk/src/site/resources/modelForTopiaQuery.png (from rev 2789, trunk/topia-persistence/src/site/resources/modelForTopiaQuery.png)
===================================================================
(Binary files differ)
Copied: trunk/src/site/resources/modelForTopiaQuery.zargo (from rev 2789, trunk/topia-persistence/src/site/resources/modelForTopiaQuery.zargo)
===================================================================
(Binary files differ)
Copied: trunk/src/site/resources/topia.zargo (from rev 2789, trunk/topia-persistence/src/site/resources/topia.zargo)
===================================================================
(Binary files differ)
Copied: trunk/src/site/rst/TopiaDocumentation.rst (from rev 2789, trunk/topia-persistence/src/site/rst/TopiaDocumentation.rst)
===================================================================
--- trunk/src/site/rst/TopiaDocumentation.rst (rev 0)
+++ trunk/src/site/rst/TopiaDocumentation.rst 2013-08-05 09:30:26 UTC (rev 2791)
@@ -0,0 +1,69 @@
+.. -
+.. * #%L
+.. * ToPIA :: Persistence
+.. *
+.. * $Id$
+.. * $HeadURL$
+.. * %%
+.. * Copyright (C) 2004 - 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%
+.. -
+
+=====
+ToPIA
+=====
+
+Buts
+====
+
+- Abstraction de la persistence
+- Sauvegarde/restauration en XML
+- Sécurité sur les instances d'objets
+- Génération de code même si ce n'est pas un prérequis pour utiliser ToPIA
+
+Ce qu'il serait bien de récuperer par rapport à la version 2
+
+- support des sous-transactions
+
+Peut-être plus tard
+
+- Gestion des services
+- Distribution transparente
+
+La vision ToPIA
+===============
+
+Un point d'entrée le TopiaContext sur lequel on ouvre des transactions ce qui
+retourne un autre TopiaContext à partir duquel on récupère les DAO des
+différentes entités qui permettent de faire les traitements que l'on souhaite.
+
+Ensuite on peut appeler la methode commit de ce sous TopiaContext pour mettre
+à jour la base de données et permettre à d'autres TopiaContext d'avoir la
+nouvelle vision de nos objets.
+
+Chaque TopiaContext créé sur le TopiaContext root est indépendant.
+
+Lorsque l'on travaille avec un objet provenant d'un TopiaContext sur lequel
+on a fait un rollback, celui-ci n'est plus valide et il vaut mieux en recupérer
+une version correcte sur le TopiaContext.
+
+Après avoir fait un commit ou un rollback sur un TopiaContext on peut continuer
+a l'utiliser et refaire des commits pour synchroniser de temps en temps les
+modification faites sur la base.
+
+Un TopiaContext peu servir aussi longtemps que l'on souhaite, il ne maintient
+pas inutilement de transaction sur la base.
Modified: trunk/src/site/rst/index.rst
===================================================================
--- trunk/src/site/rst/index.rst 2013-08-05 08:49:05 UTC (rev 2790)
+++ trunk/src/site/rst/index.rst 2013-08-05 09:30:26 UTC (rev 2791)
@@ -27,26 +27,102 @@
Accueil
=======
-Presentation
-------------
+.. contents::
-ToPIA stands for Tools for Portable and Independent Architecture. It is a
-technical platform abstraction framework. This documentation is not up-to-date
-and in French. We are in the process to update this documentation, we will
-translate it in English at the same time.
-
Présentation
------------
ToPIA, pour Tools for Portable and Independant Architecture, est un framework
d'abstraction des plateformes techniques.
+
+C'est à dire ?
+~~~~~~~~~~~~~~
+
+Le cycle de développement en Y traditionnel peut être représenté de la manière
+suivante :
+
+Les deux branches, la branche fonctionnelle, porteuse de la solution logique, et
+la branche technique, qui définit la plateforme technique sur laquelle la
+solution sera implantée, se rejoignent en amont de la conception détaillée et du
+codage. Cette projection peut être accompagnée de génération de code, mais il
+reste toujours une certaine quantité de code écrite à la main.
+
+Cette séparation des responsabilités et ce processsus donne pleine satisfaction
+lors du développement initial d'un logiciel. La vie d'un logiciel commence
+toutefois au moment de sa mise en production et les évolutions qui y seront
+apportées sont de deux natures :
+
+ - Évolutions fonctionnelles : Ajout de fonctionnalités, correction de bugs, ...
+ - Evolutions techniques : Changement de bases de données, changement de techno
+ sur les UI, nouveaux accès (SOAP ?), ...
+
+Si les évolutions fonctionnelles sont prises en compte par la nature itérative
+des processus de développement, les évolutions techniques sont elles difficiles.
+
+Comment passer d'hibernate à JDO, de Swing au client léger, des EJB aux
+conteneurs légers ? En supprimant les dépendances de votre code sur les briques
+techniques, en codant sur une plateforme technique abstraite, interfaces et
+facades au travers desquels vous pourrez manipuler les différentes solutions
+techniques que vous retiendrez. Hibernate et JDO ne sont que deux API d'accès
+aux données; Swing et client léger, des UI; les EJB et les conteneurs légers,
+des logiques métiers déportées...
+
+Et ToPIA alors ?
+~~~~~~~~~~~~~~~~
+
+ToPIA propose une telle plateforme. Vous codez en regard d'une API qui abstrait
+la distribution (1-tiers ?, 2-tiers ?, 3-tiers ?, n-tiers ? quels protocoles
+d'accès ?), la persistence (quelles bases bien sûr, mais également quel
+framework ?, quelle API de requètage (EJB-QL, JDO-QL, ... ?), quel méchanisme
+transactionnel ?), quelle UI ? Puis vous projettez votre application sur la
+palteforme de votre choix.
+
+Fonctionnement classique
+------------------------
+
+Le framework ToPIA permet dans un projet de générer la partie métier de l'application,
+c'est à dire les classes JAVA ainsi que le mapping Hibernate pour la persistance.
+Cela représente un travail considérable en moins pour le développeur et une
+flexibilité importante dans les évolutions futures de la parties métier.
+
+L'utilisation du framework ToPIA se découpe en plusieurs phases, elles sont
+itératives :
+
+ 1. Création du diagramme de classe sur ArgoUML_ par exemple
+ 2. Exportation du modèle en XMI
+ 3. Génération des fichiers JAVA et Hibernate par Eugene_
+ 4. Implentation des méthodes
+
+ToPIA-service
+-------------
+
+Le framework ToPIA peut être complêté par une multitude de services. Il existe
+actuellement trois :
+
+ - `service pour la sécurité`_ : permet la gestion des authentification et des
+ autorisations. Il repose sur le mécanisme de JAAS.
+ - `service pour la gestion des mises à jour`_ : permet de mettre à jour une version
+ de base à partir d'un modèle versionné.
+ - `service de réplication`_ : permet de répliquer des données de base à base.
+ - ``service pour la gestion d'un historique`` : permet de conserver l'ensemble des
+ actions réalisées sur la base de données (**plus maintenu depuis la 2.3.3**).
+ - ``service pour la recherche`` : permet de rechercher un mot clé parmis les entités
+ de l'application. Il repose sur la librairie lucene d'apache (**plus maintenu depuis la 2.3.3**).
+
+.. _service pour la sécurité: ../topia-service-security
+.. _service pour la gestion des mises à jour: ../topia-service-migration
+.. _service de réplication: ../topia-service-replication
+.. _Eugene: http://maven-site.nuiton.org/eugene/
+.. _ArgoUML: http://argouml.tigris.org/
+
+
Constitution
------------
Il est actuellement composé d'un module principal :
- * `ToPIA-persistence`_ : pour la gestion de la persistance sur hibernate
+ * `ToPIA-persistence`_ : pour la gestion de la persistance sur Hibernate
Depuis la version 2.3.3, le module **ToPIA-soa** n'est plus maintenu.
Modified: trunk/src/site/rst/migrate_to_3.0.rst
===================================================================
--- trunk/src/site/rst/migrate_to_3.0.rst 2013-08-05 08:49:05 UTC (rev 2790)
+++ trunk/src/site/rst/migrate_to_3.0.rst 2013-08-05 09:30:26 UTC (rev 2791)
@@ -26,6 +26,7 @@
Migrer depuis ToPIA 2.x vers 3.0
================================
+.. contents::
Gestion des dépendances
Modified: trunk/src/site/rst/user/FAQ.rst
===================================================================
--- trunk/topia-persistence/src/site/rst/user/FAQ.rst 2013-08-05 08:22:58 UTC (rev 2789)
+++ trunk/src/site/rst/user/FAQ.rst 2013-08-05 09:30:26 UTC (rev 2791)
@@ -23,9 +23,9 @@
.. * #L%
.. -
-===
-FAQ
-===
+==========================
+Frequently Asked Questions
+==========================
Problème lors du chargement d'une entity
========================================
Modified: trunk/src/site/rst/user/ModelGeneration.rst.vm
===================================================================
--- trunk/topia-persistence/src/site/rst/user/ModelGeneration.rst.vm 2013-08-05 08:22:58 UTC (rev 2789)
+++ trunk/src/site/rst/user/ModelGeneration.rst.vm 2013-08-05 09:30:26 UTC (rev 2791)
@@ -51,41 +51,41 @@
Pour générer les sources dans la phase "generate-sources" de maven, et utiliser
les sources générées, et faut configurer le pom.
-Plugin eugene
+Plugin Eugene
=============
::
-<plugin>
+ <plugin>
<groupId>org.nuiton.eugene</groupId>
<artifactId>eugene-maven-plugin</artifactId>
<version>${eugeneVersion}</version>
<executions>
- <execution>
- <id>Generator</id>
- <phase>generate-sources</phase>
- <configuration>
- <inputs>zargo</inputs>
- <fullPackagePath>org.company.package</fullPackagePath>
- <extractedPackages>org.company.package</extractedPackages>
- <templates>org.nuiton.topia.generator.TopiaMetaGenerator</templates>
- <defaultPackage>org.company.package</defaultPackage>
- </configuration>
- <goals>
- <goal>generate</goal>
- </goals>
- </execution>
+ <execution>
+ <id>Generator</id>
+ <phase>generate-sources</phase>
+ <configuration>
+ <inputs>zargo</inputs>
+ <fullPackagePath>org.company.package</fullPackagePath>
+ <extractedPackages>org.company.package</extractedPackages>
+ <templates>org.nuiton.topia.generator.TopiaMetaGenerator</templates>
+ <defaultPackage>org.company.package</defaultPackage>
+ </configuration>
+ <goals>
+ <goal>generate</goal>
+ </goals>
+ </execution>
</executions>
<dependencies>
- <dependency>
- <groupId>org.nuiton.topia</groupId>
- <artifactId>topia-persistence</artifactId>
- <version>${project.version}</version>
- </dependency>
+ <dependency>
+ <groupId>org.nuiton.topia</groupId>
+ <artifactId>topia-persistence</artifactId>
+ <version>${project.version}</version>
+ </dependency>
</dependencies>
-</plugin>
+ </plugin>
-Pour plus d'information à propos d'eugene, merci de consulter le site :
+Pour plus d'information à propos d'Eugene, merci de consulter le site :
http://maven-site.nuiton.org/eugene/
Dépendances du projet
@@ -95,8 +95,8 @@
::
-<dependency>
+ <dependency>
<groupId>org.nuiton.topia</groupId>
<artifactId>topia-persistence</artifactId>
<version>${project.version}</version>
-</dependency>
+ </dependency>
Modified: trunk/src/site/rst/user/start.rst.vm
===================================================================
--- trunk/topia-persistence/src/site/rst/user/start.rst.vm 2013-08-05 08:22:58 UTC (rev 2789)
+++ trunk/src/site/rst/user/start.rst.vm 2013-08-05 09:30:26 UTC (rev 2791)
@@ -228,6 +228,7 @@
On peut voir que ToPIA a généré ``LibraryDAOHelper`` qui va nous permettre de
récupérer les différents DAO et, pour chaque entité de notre modèle :
+
* Une interface
* Une classe abstraite, qui implémente déjà tout le contrat
* Une implantation (vide, seulement les constructeurs)
Modified: trunk/src/site/site_fr.xml
===================================================================
--- trunk/src/site/site_fr.xml 2013-08-05 08:49:05 UTC (rev 2790)
+++ trunk/src/site/site_fr.xml 2013-08-05 09:30:26 UTC (rev 2791)
@@ -27,7 +27,7 @@
<project name="ToPIA">
<bannerLeft>
- <src alt="ToPIA">http://maven-site.nuiton.org/public/images/logos/topia-logo.png</src>
+ <!--<src alt="ToPIA">http://maven-site.nuiton.org/public/images/logos/topia-logo.png</src>-->
<name>${project.name}</name>
<href>index.html</href>
</bannerLeft>
@@ -45,9 +45,15 @@
<custom>
<fluidoSkin>
- <topBarEnabled>false</topBarEnabled>
- <googleSearch/>
- <sideBarEnabled>true</sideBarEnabled>
+ <topBarEnabled>true</topBarEnabled>
+ <topBarIcon>
+ <name>ToPIA</name>
+ <alt>ToPIA</alt>
+ <src><!-- TODO Create a 108*20 px icon --></src>
+ <href>/index.html</href>
+ </topBarIcon>
+ <sideBarEnabled>false</sideBarEnabled>
+ <googleSearch>false</googleSearch>
<searchEnabled>true</searchEnabled>
<sourceLineNumbersEnabled>true</sourceLineNumbersEnabled>
</fluidoSkin>
@@ -87,14 +93,43 @@
<item href="http://maven-site.nuiton.org/topia" name="${project.name}"/>
</breadcrumbs>
- <menu name="Utilisateur">
- <item href="/index.html" name="Accueil"/>
+ <menu name="Documentation" inherit="top">
+ <item name="Présentation" href="index.html" />
+ <item name="Utilisation" href="user/howto.html" />
+ <item name="Génération des modèles" href="user/ModelGeneration.html"/>
+ <item name="Tag values" href="user/tagvalues.html" />
+ <item name="TopiaQuery" href="user/TopiaQuery.html"/>
+ <item name="FAQ" href="user/FAQ.html"/>
</menu>
+ <menu name="Tutoriels" inherit="top">
+ <item name="Démarrer avec ToPIA et Maven" href="user/start.html" />
+ <item name="Commencer à développer avec l'API ToPIA" href="user/start_using_api.html" />
+ <item name="Étendre le modèle" href="user/extend_model.html" />
+ <item name="Continer le développement" href="user/continue_devel.html" />
+ </menu>
+
+ <menu name="Développeurs">
+ <item name="Todo" href="devel/Todo.html"/>
+ <item name="Mapping hibernate" href="devel/HibernateMapping.html"/>
+ <item name="Isolation" href="devel/Isolation.html"/>
+ <item name="Schema migration" href="devel/SchemaMigration.html"/>
+ <item name="Sécurité" href="devel/security.html"/>
+ <item name="TopiaContextFactory" href="devel/Devel.html"/>
+ <item name="Projets similaires" href="devel/project.html"/>
+ <item name="Gestion des évènements" href="user/event.html"/>
+ </menu>
+
<menu ref="modules"/>
<menu ref="reports"/>
+ <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>
+
<footer>
<div id='projectMetas' locale='fr'
Deleted: trunk/topia-persistence/src/site/resources/ClassDiagram_BookAuthor.png
===================================================================
(Binary files differ)
Deleted: trunk/topia-persistence/src/site/resources/ClassDiagram_BookAuthorWithOperation.png
===================================================================
(Binary files differ)
Deleted: trunk/topia-persistence/src/site/resources/ContactUseCases.png
===================================================================
(Binary files differ)
Deleted: trunk/topia-persistence/src/site/resources/ServiceCall.png
===================================================================
(Binary files differ)
Deleted: trunk/topia-persistence/src/site/resources/modelForTopiaQuery.png
===================================================================
(Binary files differ)
Deleted: trunk/topia-persistence/src/site/resources/modelForTopiaQuery.zargo
===================================================================
(Binary files differ)
Deleted: trunk/topia-persistence/src/site/resources/topia.zargo
===================================================================
(Binary files differ)
Deleted: trunk/topia-persistence/src/site/rst/TopiaDocumentation.rst
===================================================================
--- trunk/topia-persistence/src/site/rst/TopiaDocumentation.rst 2013-08-05 08:49:05 UTC (rev 2790)
+++ trunk/topia-persistence/src/site/rst/TopiaDocumentation.rst 2013-08-05 09:30:26 UTC (rev 2791)
@@ -1,69 +0,0 @@
-.. -
-.. * #%L
-.. * ToPIA :: Persistence
-.. *
-.. * $Id$
-.. * $HeadURL$
-.. * %%
-.. * Copyright (C) 2004 - 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%
-.. -
-
-=====
-ToPIA
-=====
-
-But
-===
-
-- abstraction de la persistence
-- sauvegarde/restauration en XML
-- sécurité sur les instances d'objets
-- génération de code même si non obligatoire pour utiliser ToPIA
-
-Ce qu'il serait bien de récuperer par rapport à la version 2
-
-- support des sous-transactions
-
-peut-être plus tard
-
-- gestion des services
-- distribution transparente
-
-La vision ToPIA
-===============
-
-Un point d'entre le TopiaContext sur lequel on ouvre des transactions ce qui
-retourne un autre TopiaContext à partir duquel on récupère les DAO des
-différentes entités qui permettent de faire les traitements que l'on souhaite.
-
-Ensuite on peut appeler la methode commit de ce sous TopiaContext pour mettre
-à jour la base de données et permettre à d'autres TopiaContext d'avoir la
-nouvelle vision de nos objets.
-
-Chaque TopiaContext créé sur le TopiaContext root est indépendant.
-
-Lorsque l'on travaille avec un objet provenant d'un TopiaContext sur lequel
-on a fait un rollback, celui-ci n'est plus valide et il vaut mieux en recupérer
-une version correcte sur le TopiaContext.
-
-Après avoir fait un commit ou un rollback sur un TopiaContext on peut continuer
-a l'utiliser et refaire des commits pour synchroniser de temps en temps les
-modification faites sur la base.
-
-Un TopiaContext peu servir aussi longtemps que l'on souhaite, il ne maintient
-pas inutilement de transaction sur la base.
Modified: trunk/topia-persistence/src/site/rst/index.rst
===================================================================
--- trunk/topia-persistence/src/site/rst/index.rst 2013-08-05 08:49:05 UTC (rev 2790)
+++ trunk/topia-persistence/src/site/rst/index.rst 2013-08-05 09:30:26 UTC (rev 2791)
@@ -23,92 +23,17 @@
.. * #L%
.. -
-=====
-ToPIA
-=====
+=================
+ToPIA Persistence
+=================
-.. contents::
-
Présentation
------------
-ToPIA, pour Tools for Portable and Independant Architecture, est un framework
-d'abstraction des plateformes techniques.
+Ce sous module de ToPIA est le module principal.
-C'est à dire ?
-~~~~~~~~~~~~~~
-
-Le cycle de développement en Y traditionnel peut être représenté de la manière
-suivante :
+Il contient :
+ - les classes de base du framework ;
+ - les templates de génération ;
+ - ...
-Les deux branches, la branche fonctionnelle, porteuse de la solution logique, et
-la branche technique, qui définit la plateforme technique sur laquelle la
-solution sera implantée, se rejoignent en amont de la conception détaillée et du
-codage. Cette projection peut être accompagnée de génération de code, mais il
-reste toujours une certaine quantité de code écrite à la main.
-
-Cette séparation des responsabilités et ce processsus donne pleine satisfaction
-lors du développement initial d'un logiciel. La vie d'un logiciel commence
-toutefois au moment de sa mise en production et les évolutions qui y seront
-apportées sont de deux natures :
- - Évolutions fonctionnelles : Ajout de fonctionnalités, correction de bugs, ...
- - Evolutions techniques : Changement de bases de données, changement de techno
- sur les UI, nouveaux accès (SOAP ?), ...
-
-Si les évolutions fonctionnelles sont prises en compte par la nature itérative
-des processus de développement, les évolutions techniques sont elles difficiles.
-
-Comment passer d'hibernate à JDO, de Swing au client léger, des EJB aux
-conteneurs légers ? En supprimant les dépendances de votre code sur les briques
-techniques, en codant sur une plateforme technique abstraite, interfaces et
-facades au travers desquels vous pourrez manipuler les différentes solutions
-techniques que vous retiendrez. Hibernate et JDO ne sont que deux API d'accès
-aux données; Swing et client léger, des UI; les EJB et les conteneurs légers,
-des logiques métiers déportées...
-
-Et ToPIA alors ?
-~~~~~~~~~~~~~~~~
-
-ToPIA propose une telle plateforme. Vous codez en regard d'une API qui abstrait
-la distribution (1-tiers ?, 2-tiers ?, 3-tiers ?, n-tiers ? quels protocoles
-d'accès ?), la persistence (quelles bases bien sûr, mais également quel
-framework ?, quelle API de requètage (EJB-QL, JDO-QL, ... ?), quel méchanisme
-transactionnel ?), quelle UI ? Puis vous projettez votre application sur la
-palteforme de votre choix.
-
-Fonctionnement classique
-------------------------
-
-Le framework ToPIA permet dans un projet de générer la partie métier de l'application,
-c'est à dire les classes JAVA ainsi que le mapping Hibernate pour la persistance.
-Cela représente un travail considérable en moins pour le développeur et une
-flexibilité importante dans les évolutions futures de la parties métier.
-
-L'utilisation du framework ToPIA se découpe en plusieurs phases, elles sont
-itératives :
- 1. Création du diagramme de classe sur ArgoUML_ par exemple
- 2. Exportation du modèle en XMI
- 3. Génération des fichiers JAVA et Hibernate par Eugene_
- 4. Implentation des méthodes
-
-ToPIA-service
--------------
-
-Le framework ToPIA peut être complèté par une multitude de services. Il existe
-actuellement trois :
-
- - `service pour la sécurité`_ : permet la gestion des authentification et des
- autorisations. Il repose sur le mécanisme de JAAS.
- - `service pour la gestion des mises à jour`_ : permet de mettre à jour une version
- de base à partir d'un modèle versionné.
- - `service de réplication`_ : permet de répliquer des données de base à base.
- - ``service pour la gestion d'un historique`` : permet de conserver l'ensemble des
- actions réalisées sur la base de données (**plus maintenu depuis la 2.3.3**).
- - ``service pour la recherche`` : permet de rechercher un mot clé parmis les entités
- de l'application. Il repose sur la librairie lucene d'apache (**plus maintenu depuis la 2.3.3**).
-
-.. _service pour la sécurité: ../topia-service-security
-.. _service pour la gestion des mises à jour: ../topia-service-migration
-.. _service de réplication: ../topia-service-replication
-.. _Eugene: http://maven-site.nuiton.org/eugene/
-.. _ArgoUML: http://argouml.tigris.org/
Modified: trunk/topia-persistence/src/site/site_fr.xml
===================================================================
--- trunk/topia-persistence/src/site/site_fr.xml 2013-08-05 08:49:05 UTC (rev 2790)
+++ trunk/topia-persistence/src/site/site_fr.xml 2013-08-05 09:30:26 UTC (rev 2791)
@@ -48,32 +48,32 @@
<menu ref="parent"/>
- <menu name="Tutoriel" inherit="top">
- <item name="Démarrer avec ToPIA et Maven" href="user/start.html" />
- <item name="Commencer à développer avec l'API ToPIA" href="user/start_using_api.html" />
- <item name="Étendre le modèle" href="user/extend_model.html" />
- <item name="Continer le développement" href="user/continue_devel.html" />
- </menu>
+ <!--<menu name="Tutoriel" inherit="top">-->
+ <!--<item name="Démarrer avec ToPIA et Maven" href="../user/start.html" />-->
+ <!--<item name="Commencer à développer avec l'API ToPIA" href="user/start_using_api.html" />-->
+ <!--<item name="Étendre le modèle" href="user/extend_model.html" />-->
+ <!--<item name="Continer le développement" href="user/continue_devel.html" />-->
+ <!--</menu>-->
- <menu name="Utilisateur" inherit="top">
- <item name="Presentation" href="index.html" />
- <!--item name="Utilisation" href="user/howto.html" />
- <item name="Génération des modèles" href="user/ModelGeneration.html"/>
- <item name="Tag values" href="user/tagvalues.html" /-->
- <item name="TopiaQuery" href="user/TopiaQuery.html"/>
- <item name="FAQ" href="user/FAQ.html"/>
- </menu>
+ <!--<menu name="Utilisateur" inherit="top">-->
+ <!--<item name="Presentation" href="index.html" />-->
+ <!--<!–item name="Utilisation" href="user/howto.html" />-->
+ <!--<item name="Génération des modèles" href="user/ModelGeneration.html"/>-->
+ <!--<item name="Tag values" href="user/tagvalues.html" /–>-->
+ <!--<item name="TopiaQuery" href="user/TopiaQuery.html"/>-->
+ <!--<item name="FAQ" href="user/FAQ.html"/>-->
+ <!--</menu>-->
- <menu name="Developpeur">
- <item name="Todo" href="devel/Todo.html"/>
- <item name="Mapping hibernate" href="devel/HibernateMapping.html"/>
- <item name="Isolation" href="devel/Isolation.html"/>
- <item name="Schema migration" href="devel/SchemaMigration.html"/>
- <item name="Securité" href="devel/security.html"/>
- <item name="TopiaContextFactory" href="devel/Devel.html"/>
- <item name="Projets similaires" href="devel/project.html"/>
- <item name="Gestion des evenements" href="user/event.html"/>
- </menu>
+ <!--<menu name="Developpeur">-->
+ <!--<item name="Todo" href="devel/Todo.html"/>-->
+ <!--<item name="Mapping hibernate" href="devel/HibernateMapping.html"/>-->
+ <!--<item name="Isolation" href="devel/Isolation.html"/>-->
+ <!--<item name="Schema migration" href="devel/SchemaMigration.html"/>-->
+ <!--<item name="Securité" href="devel/security.html"/>-->
+ <!--<item name="TopiaContextFactory" href="devel/Devel.html"/>-->
+ <!--<item name="Projets similaires" href="devel/project.html"/>-->
+ <!--<item name="Gestion des evenements" href="user/event.html"/>-->
+ <!--</menu>-->
<menu name="Téléchargement">
<item href="${repository.home.url}/org/nuiton/topia/${project.artifactId}/${project.version}/${project.build.finalName}.jar"
1
0
r2790 - trunk/topia-persistence/src/main/java/org/nuiton/topia
by athimel@users.nuiton.org 05 Aug '13
by athimel@users.nuiton.org 05 Aug '13
05 Aug '13
Author: athimel
Date: 2013-08-05 10:49:05 +0200 (Mon, 05 Aug 2013)
New Revision: 2790
Url: http://nuiton.org/projects/topia/repository/revisions/2790
Log:
Relocate beginTransaction on TopiaContext for the moment
Modified:
trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaContext.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaTransaction.java
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaContext.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaContext.java 2013-08-05 08:22:58 UTC (rev 2789)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaContext.java 2013-08-05 08:49:05 UTC (rev 2790)
@@ -63,11 +63,14 @@
*
* @return new context with transaction
* @throws TopiaException if any exception
- * @deprecated use method from {@link TopiaTransaction}
+ * @deprecated we need another method that returns a {@link TopiaTransaction} only. This method doesn't exist yet
*/
@Deprecated
TopiaContext beginTransaction() throws TopiaException;
+ // TODO AThimel 03/08/13 We need another API to obtain a TopiaTransaction
+ // TODO AThimel 03/08/13 This new method has to be located somewhere else (TopiaTransactionSupplier ? TopiaTransactionSupport ? or just TopiaPersistenceContext ?)
+
/**
* Applies all the modifications made to this context on the persistence
* device. Once commit is done, a new transaction is started.
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaTransaction.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaTransaction.java 2013-08-05 08:22:58 UTC (rev 2789)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaTransaction.java 2013-08-05 08:49:05 UTC (rev 2790)
@@ -33,18 +33,6 @@
public interface TopiaTransaction {
/**
- * Returns a new context containing its own transaction.
- *
- * @return new context with transaction
- * @deprecated Sub contexts are not supported anymore, it is not possible to get a transaction FROM a transaction
- */
- @Deprecated
- TopiaContext beginTransaction();
-
- // TODO AThimel 03/08/13 We need another API to obtain a TopiaTransaction
- // TODO AThimel 03/08/13 This new method has to be located somewhere else (TopiaTransactionSupplier ? TopiaTransactionSupport ? or just TopiaPersistenceContext ?)
-
- /**
* Applies all the modifications made to this context on the persistence
* device. Once commit is done, a new transaction is started.
*/
1
0
r2789 - trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence
by tchemit@users.nuiton.org 05 Aug '13
by tchemit@users.nuiton.org 05 Aug '13
05 Aug '13
Author: tchemit
Date: 2013-08-05 10:22:58 +0200 (Mon, 05 Aug 2013)
New Revision: 2789
Url: http://nuiton.org/projects/topia/repository/revisions/2789
Log:
bad code commited (break back compat)
Modified:
trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAOImpl.java
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAOImpl.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAOImpl.java 2013-08-05 08:20:12 UTC (rev 2788)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAOImpl.java 2013-08-05 08:22:58 UTC (rev 2789)
@@ -244,8 +244,8 @@
}
@Override
- public TopiaContext getContext() {
- return getTopiaContext();
+ public TopiaContextImplementor getContext() {
+ return (TopiaContextImplementor) getTopiaContext();
}
@Override
1
0
r2788 - trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence
by tchemit@users.nuiton.org 05 Aug '13
by tchemit@users.nuiton.org 05 Aug '13
05 Aug '13
Author: tchemit
Date: 2013-08-05 10:20:12 +0200 (Mon, 05 Aug 2013)
New Revision: 2788
Url: http://nuiton.org/projects/topia/repository/revisions/2788
Log:
bad code commited (break back compat) + remove double deprecated javadoc
Modified:
trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAO.java
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAO.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAO.java 2013-08-03 01:14:27 UTC (rev 2787)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAO.java 2013-08-05 08:20:12 UTC (rev 2788)
@@ -656,7 +656,7 @@
* @deprecated use {@link #getTopiaContext()}
*/
@Deprecated
- TopiaContext getContext();
+ TopiaContextImplementor getContext();
/**
* Returns the context used by this DAO.
@@ -729,7 +729,6 @@
* @return la liste des permissions
* @throws TopiaException if any pb while getting datas
* @since 2.6.14
- * @deprecated {@code TopiaQuery} will be removed in version 3.0
* @deprecated topia-service-security will be removed in 3.0
*/
@Deprecated
1
0
r2787 - in trunk: src/site src/site/resources src/site/rst topia-persistence/src/main/java/org/nuiton/topia topia-persistence/src/main/java/org/nuiton/topia/framework topia-persistence/src/main/java/org/nuiton/topia/persistence topia-persistence/src/main/java/org/nuiton/topia/persistence/csv
by athimel@users.nuiton.org 03 Aug '13
by athimel@users.nuiton.org 03 Aug '13
03 Aug '13
Author: athimel
Date: 2013-08-03 03:14:27 +0200 (Sat, 03 Aug 2013)
New Revision: 2787
Url: http://nuiton.org/projects/topia/repository/revisions/2787
Log:
refs #1146 Prepare migrate site page
refs #552 Improve APIs Javadoc
refs #2748 Minimal documentation on newly created contracts
Added:
trunk/src/site/resources/
trunk/src/site/resources/mandatory.png
trunk/src/site/resources/recommended.png
trunk/src/site/rst/changelog_3.0.rst
trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaHibernateSupport.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaListenableSupport.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaTransaction.java
Removed:
trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaHibernate.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaListenable.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaTransactionSupport.java
Modified:
trunk/src/site/rst/migrate_to_3.0.rst
trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaContext.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaException.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaJpaSupport.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaNotFoundException.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaPersistenceContext.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaReplicationSupport.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaServiceSupport.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaSqlSupport.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaVetoException.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/AbstractTopiaContext.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaContextImplementor.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/DefaultTopiaIdFactory.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/LegacyTopiaIdFactory.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAO.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaEntities.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaId.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaIdFactory.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/csv/EntityCsvModel.java
Added: trunk/src/site/resources/mandatory.png
===================================================================
(Binary files differ)
Property changes on: trunk/src/site/resources/mandatory.png
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: trunk/src/site/resources/recommended.png
===================================================================
(Binary files differ)
Property changes on: trunk/src/site/resources/recommended.png
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: trunk/src/site/rst/changelog_3.0.rst
===================================================================
--- trunk/src/site/rst/changelog_3.0.rst (rev 0)
+++ trunk/src/site/rst/changelog_3.0.rst 2013-08-03 01:14:27 UTC (rev 2787)
@@ -0,0 +1,48 @@
+.. -
+.. * #%L
+.. * ToPIA
+.. * $Id$
+.. * $HeadURL$
+.. * %%
+.. * Copyright (C) 2004 - 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%
+.. -
+
+Les nouveautés de ToPIA 3.0
+===========================
+
+
+Modularisation de la génération des TopiaId
+-------------------------------------------
+
+La forme des topiaIds générés à changé. Si vous souhaitez conserver l'ancienne forme parce que vous
+souhaitez conserver l'uniformité avec une base de données existante ou si vous utilisez
+topia-service-security, vous devez explicitement le spécifier à Topia 3.0 via la configuration :
+
+ ``topia.persistence.topiaIdFactoryClassName=org.nuiton.topia.persistence.LegacyTopiaIdFactory``
+
+Le classe **TopiaID** est dépréciée, elle sera supprimée dans les prochaines versions.
+
+::
+
+ FIXME tchemit : je ne suis pas convaincu par ça, le module security pour moi doit aussi être déprécié, donc la dernière phrase est caduc.
+
+
+TopiaEntities enrichi
+---------------------
+
+TODO
Property changes on: trunk/src/site/rst/changelog_3.0.rst
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Modified: trunk/src/site/rst/migrate_to_3.0.rst
===================================================================
--- trunk/src/site/rst/migrate_to_3.0.rst 2013-08-02 17:26:06 UTC (rev 2786)
+++ trunk/src/site/rst/migrate_to_3.0.rst 2013-08-03 01:14:27 UTC (rev 2787)
@@ -22,71 +22,110 @@
.. * #L%
.. -
+================================
Migrer depuis ToPIA 2.x vers 3.0
================================
-::
- FIXME tchemit : dans ce guide je ne vois pas ce qui est obligatoire de faire ?
- Y'a des choses qui restent compatibles ? Il faudrait explicitement dire ce
- qu'il faut faire (ce document dans sa forme actuelle est plus un changelog
- qu'un guide de migration...).
- On devrait plutôt avoir une section *choses incompatibles* ou *à faire*.
-
Gestion des dépendances
------------------------
+=======================
- * ToPIA utilise au minimum Eugene 2.6.4.
- * ToPIA utilise au minimum Hibernate 4.2.1.Final.
+|MANDATORY|
-Renommage de variables
-----------------------
+ToPIA nécessite des versions minimum de Eugene et Hibernate. Vous devez utiliser les version suivantes :
- * Les constantes de TopiaEntity ont été renommé avec le prefix PROPERTY_
+ * Eugene >= 2.6.4
+ * Hibernate >= 4.2.1.Final
-Gestion des exceptions
-----------------------
- * TopiaRuntimeException est dépréciée. Il faut désormais déclarer TopiaException dans la clause catch ;
- * TopiaException devient Runtime. Il n'est plus nécessaire de la gérer.
+Code déprécié
+=============
-Modularisation de la génération des TopiaID
--------------------------------------------
-La forme des topiaIds générés à changé. Si vous souhaitez conserver l'ancienne forme parce que vous
-souhaitez conserver l'uniformité avec une base de données existante ou si vous utilisez
-topia-service-security, vous devez explicitement le spécifier à Topia 3.0 via la configuration :
+La migration vers ToPIA 3.0 voit un certain nombre de classes et attributs dépréciés.
- topia.persistence.topiaIdFactoryClassName=org.nuiton.topia.persistence.LegacyTopiaIdFactory
+Gérer les impacts n'est pas *nécessaire* pour passer à ToPIA 3.0, mais c'est fortement recommandé. En effet, ce code
+deviendra incompatible avec ToPIA 3.1, gérer les impacts au plus tôt permettra une migration en douceur.
-Le classe TopiaID est dépréciée, elle sera déplacée dans topia-service-security. Utilisez plutôt une
-référence vers une instance de TopiaIdFactory (disponible dans le TopiaContextImplementor et donc dans les DAOs).
-::
+Propriétés TOPIA_*
+------------------
- FIXME tchemit : je ne suis pas convaincu par ça, le module security pour moi doit aussi être déprécié, donc la dernière phrase est caduc.
+|RECOMMENDED|
+Les constantes suivantes sont à remplacer par leurs homologues avec le prefix *PROPERTY_* :
+
+ * ``TopiaEntity#TOPIA_ID`` devient ``TopiaEntity#PROPERTY_TOPIA_ID``
+ * ``TopiaEntity#TOPIA_CREATE_DATE`` devient ``TopiaEntity#PROPERTY_TOPIA_CREATE_DATE``
+ * ``TopiaEntity#TOPIA_VERSION`` devient ``TopiaEntity#PROPERTY_TOPIA_VERSION``
+ * ``TopiaEntityContextable#TOPIA_CONTEXT`` devient ``TopiaEntityContextable#PROPERTY_TOPIA_CONTEXT``
+
+
+TopiaId
+-------
+
+|RECOMMENDED|
+
+La classe sera supprimée. Pour manipuler les topiaId, il faut utiliser le **TopiaIdFactory**.
+
+
+TopiaEntities#getTopiaIdFunction()
+----------------------------------
+
+|RECOMMENDED|
+
+La méthode est dépréciée, il faut maintenant utiliser ``TopiaEntities#GET_TOPIA_ID``.
+
+
+TopiaContextImplementor est déprécié
+------------------------------------
+
+Cette classe joue un rôle central dans ToPIA 2. Si nous avons essayé de limiter les impacts pour la version 3, il est
+tout de même nécessaire d'appliquer quelques modifications.
+
+TopiaService#[preInit|postInit](...)
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+|MANDATORY|
+
+Les services implémentant **TopiaService** doivent changer leur code.
+Les méthodes ``preInit(TopiaContextImplementor)`` et ``postInit(TopiaContextImplementor)`` doivent être remplacées par
+``preInit(TopiaContext)`` et ``postInit(TopiaContext)``
+
+
+Gestion des exceptions
+----------------------
+
+|RECOMMENDED|
+
+**TopiaRuntimeException** est dépréciée. Il faut désormais déclarer **TopiaException** dans la clause catch.
+**TopiaException** devient Runtime. Il n'est plus nécessaire de l'intercepter.
+
Généricité
----------
-Les methodes
+|RECOMMENDED|
- * TopiaContext#find(...)
- * TopiaContext#findAll(...)
- * TopiaContext#findUnique(...)
+Les methodes suivantes sont désormais génériques :
-sont devenu génériques.
+ * ``TopiaContext#find(...)``
+ * ``TopiaContext#findAll(...)``
+ * ``TopiaContext#findUnique(...)``
-Si le code précédent réalisait un cast, il faut le supprimer car cela peut
-causer maintenant une erreur de compilation.
+Si le code précédent réalisait un cast, il faut le supprimer car cela peut causer maintenant une erreur de compilation.
TopiaContextListener
--------------------
-L'API TopiaContextListener contenant des opérations de manipulation du schéma de base de données a été déprécié.
-L'interface est remplacée par TopiaSchemaListener. Les méthodes présentes sur le TopiaContext qui servaient à ajouter/
-supprimer un TopiaContextListener sont elles aussi dépréciées au profit de méthodes manipulant des TopiaSchemaListener.
+|RECOMMENDED|
+L'API **TopiaContextListener** contenant des opérations de manipulation du schéma de base de données a été déprécié.
+L'interface est remplacée par **TopiaSchemaListener**. Les méthodes présentes sur le **TopiaContext** qui servaient à
+ajouter/supprimer un **TopiaContextListener** sont elles aussi dépréciées au profit de méthodes manipulant des
+**TopiaSchemaListener**.
+
+.. |RECOMMENDED| image:: recommended.png
+.. |MANDATORY| image:: mandatory.png
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaContext.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaContext.java 2013-08-02 17:26:06 UTC (rev 2786)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaContext.java 2013-08-03 01:14:27 UTC (rev 2787)
@@ -33,7 +33,6 @@
import org.nuiton.topia.event.TopiaEntitiesVetoable;
import org.nuiton.topia.event.TopiaEntityListener;
import org.nuiton.topia.event.TopiaEntityVetoable;
-import org.nuiton.topia.event.TopiaSchemaListener;
import org.nuiton.topia.event.TopiaTransactionListener;
import org.nuiton.topia.event.TopiaTransactionVetoable;
import org.nuiton.topia.framework.TopiaService;
@@ -54,8 +53,8 @@
* @author athimel <thimel(a)codelutin.com>
* @version $Id$
*/
-public interface TopiaContext extends TopiaTransactionSupport, TopiaListenable, TopiaSqlSupport, TopiaJpaSupport,
- TopiaPersistenceContext, TopiaServiceSupport, TopiaReplicationSupport, TopiaHibernate {
+public interface TopiaContext extends TopiaTransaction, TopiaListenableSupport, TopiaSqlSupport, TopiaJpaSupport,
+ TopiaPersistenceContext, TopiaServiceSupport, TopiaReplicationSupport, TopiaHibernateSupport {
/* -------------------- TRANSACTION MANAGEMENT --------------------------*/
@@ -64,7 +63,7 @@
*
* @return new context with transaction
* @throws TopiaException if any exception
- * @deprecated use method from {@link TopiaTransactionSupport}
+ * @deprecated use method from {@link TopiaTransaction}
*/
@Deprecated
TopiaContext beginTransaction() throws TopiaException;
@@ -74,7 +73,7 @@
* device. Once commit is done, a new transaction is started.
*
* @throws TopiaException if any exception
- * @deprecated use method from {@link TopiaTransactionSupport}
+ * @deprecated use method from {@link TopiaTransaction}
*/
@Deprecated
void commitTransaction() throws TopiaException;
@@ -85,7 +84,7 @@
* transaction is started.
*
* @throws TopiaException if any exception
- * @deprecated use method from {@link TopiaTransactionSupport}
+ * @deprecated use method from {@link TopiaTransaction}
*/
@Deprecated
void rollbackTransaction() throws TopiaException;
@@ -95,7 +94,7 @@
* time.
*
* @throws TopiaException if any exception
- * @deprecated use method from {@link TopiaTransactionSupport}
+ * @deprecated use method from {@link TopiaTransaction}
*/
@Deprecated
void closeContext() throws TopiaException;
@@ -104,7 +103,7 @@
* Tells if the context is closed
*
* @return {@code true} if the context is closed, {@code false} otherwise
- * @deprecated use method from {@link TopiaTransactionSupport}
+ * @deprecated use method from {@link TopiaTransaction}
*/
@Deprecated
boolean isClosed();
@@ -119,7 +118,7 @@
* the entity.
*
* @param listener the listener instance to register
- * @deprecated use method from {@link TopiaListenable}
+ * @deprecated use method from {@link TopiaListenableSupport}
*/
@Deprecated
void addTopiaEntityListener(TopiaEntityListener listener);
@@ -131,7 +130,7 @@
*
* @param entityClass the TopiaEntity's class to listen
* @param listener the listener instance to register
- * @deprecated use method from {@link TopiaListenable}
+ * @deprecated use method from {@link TopiaListenableSupport}
*/
@Deprecated
void addTopiaEntityListener(Class<? extends TopiaEntity> entityClass,
@@ -142,7 +141,7 @@
* context
*
* @param listener the listener instance to unregister
- * @deprecated use method from {@link TopiaListenable}
+ * @deprecated use method from {@link TopiaListenableSupport}
*/
@Deprecated
void removeTopiaEntityListener(TopiaEntityListener listener);
@@ -153,7 +152,7 @@
*
* @param entityClass the listened TopiaEntity's class
* @param listener the listener instance to unregister
- * @deprecated use method from {@link TopiaListenable}
+ * @deprecated use method from {@link TopiaListenableSupport}
*/
@Deprecated
void removeTopiaEntityListener(Class<? extends TopiaEntity> entityClass,
@@ -168,7 +167,7 @@
* the entity.
*
* @param vetoable the vetoable instance to register
- * @deprecated use method from {@link TopiaListenable}
+ * @deprecated use method from {@link TopiaListenableSupport}
*/
@Deprecated
void addTopiaEntityVetoable(TopiaEntityVetoable vetoable);
@@ -180,7 +179,7 @@
*
* @param entityClass the TopiaEntity's class to listen
* @param vetoable the vetoable instance to register
- * @deprecated use method from {@link TopiaListenable}
+ * @deprecated use method from {@link TopiaListenableSupport}
*/
@Deprecated
void addTopiaEntityVetoable(Class<? extends TopiaEntity> entityClass,
@@ -191,7 +190,7 @@
* context
*
* @param vetoable the vetoable instance to unregister
- * @deprecated use method from {@link TopiaListenable}
+ * @deprecated use method from {@link TopiaListenableSupport}
*/
@Deprecated
void removeTopiaEntityVetoable(TopiaEntityVetoable vetoable);
@@ -202,7 +201,7 @@
*
* @param entityClass the listened TopiaEntity's class
* @param vetoable the vetoable instance to unregister
- * @deprecated use method from {@link TopiaListenable}
+ * @deprecated use method from {@link TopiaListenableSupport}
*/
@Deprecated
void removeTopiaEntityVetoable(Class<? extends TopiaEntity> entityClass,
@@ -216,7 +215,7 @@
* <code>vetoable</code> instance will be notified BEFORE any entity load
*
* @param vetoable the vetoable instance to register
- * @deprecated use method from {@link TopiaListenable}
+ * @deprecated use method from {@link TopiaListenableSupport}
*/
@Deprecated
void addTopiaEntitiesVetoable(TopiaEntitiesVetoable vetoable);
@@ -226,7 +225,7 @@
* context
*
* @param vetoable the vetoable instance to unregister
- * @deprecated use method from {@link TopiaListenable}
+ * @deprecated use method from {@link TopiaListenableSupport}
*/
@Deprecated
void removeTopiaEntitiesVetoable(TopiaEntitiesVetoable vetoable);
@@ -240,7 +239,7 @@
* the transaction.
*
* @param listener the listener instance to register
- * @deprecated use method from {@link TopiaListenable}
+ * @deprecated use method from {@link TopiaListenableSupport}
*/
@Deprecated
void addTopiaTransactionListener(TopiaTransactionListener listener);
@@ -250,7 +249,7 @@
* the context
*
* @param listener the listener instance to unregister
- * @deprecated use method from {@link TopiaListenable}
+ * @deprecated use method from {@link TopiaListenableSupport}
*/
@Deprecated
void removeTopiaTransactionListener(TopiaTransactionListener listener);
@@ -264,7 +263,7 @@
* the transaction.
*
* @param vetoable the vetoable instance to register
- * @deprecated use method from {@link TopiaListenable}
+ * @deprecated use method from {@link TopiaListenableSupport}
*/
@Deprecated
void addTopiaTransactionVetoable(TopiaTransactionVetoable vetoable);
@@ -274,7 +273,7 @@
* the context
*
* @param vetoable the vetoable instance to unregister
- * @deprecated use method from {@link TopiaListenable}
+ * @deprecated use method from {@link TopiaListenableSupport}
*/
@Deprecated
void removeTopiaTransactionVetoable(TopiaTransactionVetoable vetoable);
@@ -288,7 +287,7 @@
* any change on the entity's property
*
* @param listener the listener instance to register
- * @deprecated use method from {@link TopiaListenable}
+ * @deprecated use method from {@link TopiaListenableSupport}
*/
@Deprecated
void addPropertyChangeListener(PropertyChangeListener listener);
@@ -298,36 +297,12 @@
* property change from the context
*
* @param listener the listener instance to unregister
- * @deprecated use method from {@link TopiaListenable}
+ * @deprecated use method from {@link TopiaListenableSupport}
*/
@Deprecated
void removePropertyChangeListener(PropertyChangeListener listener);
- /* TopiaSchemaListener */
-
- /**
- * Register to the context a TopiaSchemaListener about any schema
- * modification. <code>listener</code> instance will be notified BEFORE and
- * AFTER any change on the schema
- *
- * @param listener the listener instance to register
- * @deprecated use method from {@link TopiaListenable}
- */
- @Deprecated
- void addTopiaSchemaListener(TopiaSchemaListener listener);
-
- /**
- * Unregister the given TopiaSchemaListener about any schema modification
- * from the context
- *
- * @param listener the listener instance to unregister
- * @deprecated use method from {@link TopiaListenable}
- */
- @Deprecated
- void removeTopiaSchemaListener(TopiaSchemaListener listener);
-
-
/* TopiaContextListener */
/**
@@ -378,7 +353,7 @@
* Clear persistence implementation cache.
*
* @since 2.6.13
- * @deprecated use {@link TopiaHibernate#getHibernateSession().clear()}
+ * @deprecated use {@link TopiaHibernateSupport#getHibernateSession().clear()}
*/
@Deprecated
void clearCache() throws TopiaException;
@@ -468,16 +443,8 @@
@Deprecated
void executeSQL(String sqlScript) throws TopiaException;
- // TODO AThimel 20/07/13 Copy "void doSQLWork(TopiaSQLWork sqlWork);" from topia-3.0-jpa ?
-
/* -------------------- SCHEMA MANAGMENT -----------------------------*/
- // TODO AThimel 20/07/13 Copy "boolean isSchemaEmpty();" from topia-3.0-jpa ?
-
- // TODO AThimel 20/07/13 Copy "boolean isTableExists(Class<?> clazz);" from topia-3.0-jpa ?
-
- // TODO AThimel 20/07/13 Copy "String getSchemaName();" from topia-3.0-jpa ?
-
/**
* Triggers database schema creation
*
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaException.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaException.java 2013-08-02 17:26:06 UTC (rev 2786)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaException.java 2013-08-03 01:14:27 UTC (rev 2787)
@@ -26,8 +26,8 @@
package org.nuiton.topia;
/**
- * Main exception for Topia errors on hibernate manipulations.
- *
+ * Main exception for any Topia error
+ * <p/>
* Created: 23 déc. 2005 23:03:36
*
* @author poussin <poussin(a)codelutin.com>
@@ -39,7 +39,7 @@
private static final long serialVersionUID = -1251439453383121393L;
/**
- * Default constructor.
+ * Default constructor.
*/
public TopiaException() {
}
@@ -58,7 +58,7 @@
* with a {@code message}.
*
* @param message exception message
- * @param cause exception cause
+ * @param cause exception cause
*/
public TopiaException(String message, Throwable cause) {
super(message, cause);
Deleted: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaHibernate.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaHibernate.java 2013-08-02 17:26:06 UTC (rev 2786)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaHibernate.java 2013-08-03 01:14:27 UTC (rev 2787)
@@ -1,55 +0,0 @@
-package org.nuiton.topia;
-
-/*
- * #%L
- * ToPIA :: Persistence
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2004 - 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 org.hibernate.Session;
-import org.hibernate.SessionFactory;
-import org.hibernate.cfg.Configuration;
-
-/**
- * @author Arnaud Thimel <thimel(a)codelutin.com>
- */
-public interface TopiaHibernate {
-
- /**
- * @return Returns the hibernate's Session.
- * @throws TopiaException si aucune transaction n'est ouverte
- */
- Session getHibernateSession() throws TopiaException;
-
- /**
- * @return Returns the hibernateFactory.
- * @throws TopiaNotFoundException
- */
- SessionFactory getHibernateFactory() throws TopiaNotFoundException;
-
- /**
- * @return Returns the hibernate configuration
- * @throws TopiaNotFoundException
- */
- Configuration getHibernateConfiguration()
- throws TopiaNotFoundException;
-
-}
Copied: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaHibernateSupport.java (from rev 2786, trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaHibernate.java)
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaHibernateSupport.java (rev 0)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaHibernateSupport.java 2013-08-03 01:14:27 UTC (rev 2787)
@@ -0,0 +1,54 @@
+package org.nuiton.topia;
+
+/*
+ * #%L
+ * ToPIA :: Persistence
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2004 - 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 org.hibernate.Session;
+import org.hibernate.SessionFactory;
+import org.hibernate.cfg.Configuration;
+
+/**
+ * This API provides methods to interact with Hibernate
+ *
+ * @author Arnaud Thimel <thimel(a)codelutin.com>
+ * @since 3.0
+ */
+public interface TopiaHibernateSupport {
+
+ /**
+ * @return Returns the Hibernate's Session.
+ */
+ Session getHibernateSession();
+
+ /**
+ * @return Returns the HibernateFactory.
+ */
+ SessionFactory getHibernateFactory();
+
+ /**
+ * @return Returns the Hibernate configuration
+ */
+ Configuration getHibernateConfiguration();
+
+}
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaJpaSupport.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaJpaSupport.java 2013-08-02 17:26:06 UTC (rev 2786)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaJpaSupport.java 2013-08-03 01:14:27 UTC (rev 2787)
@@ -27,12 +27,16 @@
import java.util.List;
/**
+ * This API provides methods to use persistence using JPA queries
+ *
* @author Arnaud Thimel <thimel(a)codelutin.com>
+ * @since 3.0
*/
+// TODO AThimel 02/08/13 I think we need another name
public interface TopiaJpaSupport {
/**
- * Allow to do some HQL query
+ * Allow to do some JPA-QL query
* <p/>
* WARNING : Depending on the registered service, this method may not
* support something else than queries on TopiaEntity
@@ -41,10 +45,9 @@
* @param propertyNamesAndValues the query parameters. Arguments are key-value paired :
* [propertyName;value;propertyName;value;...]
* @return The result list
- * @throws TopiaException for any error during querying
*/
<T> List<T> findAll(String jpaql,
- Object... propertyNamesAndValues) throws TopiaException;
+ Object... propertyNamesAndValues);
/**
* Allow to do some JPA-QL query using the given bounds.
@@ -61,15 +64,14 @@
* @param propertyNamesAndValues the query parameters. Arguments are key-value paired :
* [propertyName;value;propertyName;value;...]
* @return The result list
- * @throws TopiaException for any error during querying
*/
<T> List<T> find(String jpaql,
int startIndex,
int endIndex,
- Object... propertyNamesAndValues) throws TopiaException;
+ Object... propertyNamesAndValues);
/**
- * Allow to do some HQL query and return an unique result. If nothing if
+ * Allow to do some JPA-QL query and return an unique result. If nothing if
* found by the query, will return null. If more than one result is found,
* will throw an exception.
* <p/>
@@ -80,22 +82,20 @@
* @param propertyNamesAndValues the query parameters. Arguments are key-value paired :
* [propertyName;value;propertyName;value;...]
* @return The result instance or null
- * @throws TopiaException for any error during querying or if the the query
- * returns more than one result.
*/
+ // TODO AThimel 02/08/13 Throw another exception if more than 1 result is found
<T> T findUnique(String jpaql,
- Object... propertyNamesAndValues) throws TopiaException;
+ Object... propertyNamesAndValues);
/**
- * Execute HQL operation on data (Update, Delete).
+ * Execute JPA-QL operation on data (Update, Delete).
*
* @param jpaql the JPA-QL query
* @param propertyNamesAndValues the query parameters. Arguments are key-value paired :
* [propertyName;value;propertyName;value;...]
* @return The number of entities updated or deleted.
- * @throws TopiaException if any exception
*/
int execute(String jpaql,
- Object... propertyNamesAndValues) throws TopiaException;
+ Object... propertyNamesAndValues);
}
Deleted: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaListenable.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaListenable.java 2013-08-02 17:26:06 UTC (rev 2786)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaListenable.java 2013-08-03 01:14:27 UTC (rev 2787)
@@ -1,223 +0,0 @@
-package org.nuiton.topia;
-
-/*
- * #%L
- * ToPIA :: Persistence
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2004 - 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 java.beans.PropertyChangeListener;
-
-import org.nuiton.topia.event.TopiaEntitiesVetoable;
-import org.nuiton.topia.event.TopiaEntityListener;
-import org.nuiton.topia.event.TopiaEntityVetoable;
-import org.nuiton.topia.event.TopiaSchemaListener;
-import org.nuiton.topia.event.TopiaTransactionListener;
-import org.nuiton.topia.event.TopiaTransactionVetoable;
-import org.nuiton.topia.persistence.TopiaEntity;
-
-/**
- * @author Arnaud Thimel <thimel(a)codelutin.com>
- */
-public interface TopiaListenable {
-
- /* TopiaEntityListener */
-
- /**
- * Register to the context a TopiaEntityListener about any TopiaEntity.
- * <code>listener</code> instance will be notified AFTER any operation on
- * the entity.
- *
- * @param listener the listener instance to register
- */
- void addTopiaEntityListener(TopiaEntityListener listener);
-
- /**
- * Register to the context a TopiaEntityListener about the given entity
- * class. <code>listener</code> instance will be notified AFTER any
- * operation on the entity.
- *
- * @param entityClass the TopiaEntity's class to listen
- * @param listener the listener instance to register
- */
- void addTopiaEntityListener(Class<? extends TopiaEntity> entityClass,
- TopiaEntityListener listener);
-
- /**
- * Unregister the given TopiaEntityListener about any TopiaEntity from the
- * context
- *
- * @param listener the listener instance to unregister
- */
- void removeTopiaEntityListener(TopiaEntityListener listener);
-
- /**
- * Unregister the given TopiaEntityListener about the given entity class
- * from the context
- *
- * @param entityClass the listened TopiaEntity's class
- * @param listener the listener instance to unregister
- */
- void removeTopiaEntityListener(Class<? extends TopiaEntity> entityClass,
- TopiaEntityListener listener);
-
-
- /* TopiaEntityVetoable */
-
- /**
- * Register to the context a TopiaEntityVetoable about any TopiaEntity.
- * <code>vetoable</code> instance will be notified BEFORE any operation on
- * the entity.
- *
- * @param vetoable the vetoable instance to register
- */
- void addTopiaEntityVetoable(TopiaEntityVetoable vetoable);
-
- /**
- * Register to the context a TopiaEntityVetoable about the given entity
- * class. <code>vetoable</code> instance will be notified BEFORE any
- * operation on the entity.
- *
- * @param entityClass the TopiaEntity's class to listen
- * @param vetoable the vetoable instance to register
- */
- void addTopiaEntityVetoable(Class<? extends TopiaEntity> entityClass,
- TopiaEntityVetoable vetoable);
-
- /**
- * Unregister the given TopiaEntityVetoable about any TopiaEntity from the
- * context
- *
- * @param vetoable the vetoable instance to unregister
- */
- void removeTopiaEntityVetoable(TopiaEntityVetoable vetoable);
-
- /**
- * Unregister the given TopiaEntityVetoable about the given entity class
- * from the context
- *
- * @param entityClass the listened TopiaEntity's class
- * @param vetoable the vetoable instance to unregister
- */
- void removeTopiaEntityVetoable(Class<? extends TopiaEntity> entityClass,
- TopiaEntityVetoable vetoable);
-
-
- /* TopiaEntitiesVetoable */
-
- /**
- * Register to the context a TopiaEntitiesVetoable about any TopiaEntity.
- * <code>vetoable</code> instance will be notified BEFORE any entity load
- *
- * @param vetoable the vetoable instance to register
- */
- void addTopiaEntitiesVetoable(TopiaEntitiesVetoable vetoable);
-
- /**
- * Unregister the given TopiaEntitiesVetoable about any TopiaEntity from the
- * context
- *
- * @param vetoable the vetoable instance to unregister
- */
- void removeTopiaEntitiesVetoable(TopiaEntitiesVetoable vetoable);
-
-
- /* TopiaTransactionListener */
-
- /**
- * Register to the context a TopiaTransactionListener about the transaction.
- * <code>listener</code> instance will be notified AFTER any operation on
- * the transaction.
- *
- * @param listener the listener instance to register
- */
- void addTopiaTransactionListener(TopiaTransactionListener listener);
-
- /**
- * Unregister the given TopiaTransactionListener about the transaction from
- * the context
- *
- * @param listener the listener instance to unregister
- */
- void removeTopiaTransactionListener(TopiaTransactionListener listener);
-
-
- /* TopiaTransactionVetoable */
-
- /**
- * Register to the context a TopiaTransactionVetoable about the transaction.
- * <code>vetoable</code> instance will be notified BEFORE any operation on
- * the transaction.
- *
- * @param vetoable the vetoable instance to register
- */
- void addTopiaTransactionVetoable(TopiaTransactionVetoable vetoable);
-
- /**
- * Unregister the given TopiaTransactionVetoable about the transaction from
- * the context
- *
- * @param vetoable the vetoable instance to unregister
- */
- void removeTopiaTransactionVetoable(TopiaTransactionVetoable vetoable);
-
-
- /* PropertyChangeListener */
-
- /**
- * Register to the context a PropertyChangeListener about some entity's
- * property change. <code>listener</code> instance will be notified AFTER
- * any change on the entity's property
- *
- * @param listener the listener instance to register
- */
- void addPropertyChangeListener(PropertyChangeListener listener);
-
- /**
- * Unregister the given PropertyChangeListener about some entity's
- * property change from the context
- *
- * @param listener the listener instance to unregister
- */
- void removePropertyChangeListener(PropertyChangeListener listener);
-
-
- /* TopiaSchemaListener */
-
- /**
- * Register to the context a TopiaSchemaListener about any schema
- * modification. <code>listener</code> instance will be notified BEFORE and
- * AFTER any change on the schema
- *
- * @param listener the listener instance to register
- */
- void addTopiaSchemaListener(TopiaSchemaListener listener);
-
- /**
- * Unregister the given TopiaSchemaListener about any schema modification
- * from the context
- *
- * @param listener the listener instance to unregister
- */
- void removeTopiaSchemaListener(TopiaSchemaListener listener);
-
-
-}
Copied: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaListenableSupport.java (from rev 2786, trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaListenable.java)
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaListenableSupport.java (rev 0)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaListenableSupport.java 2013-08-03 01:14:27 UTC (rev 2787)
@@ -0,0 +1,227 @@
+package org.nuiton.topia;
+
+/*
+ * #%L
+ * ToPIA :: Persistence
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2004 - 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 java.beans.PropertyChangeListener;
+
+import org.nuiton.topia.event.TopiaEntitiesVetoable;
+import org.nuiton.topia.event.TopiaEntityListener;
+import org.nuiton.topia.event.TopiaEntityVetoable;
+import org.nuiton.topia.event.TopiaSchemaListener;
+import org.nuiton.topia.event.TopiaTransactionListener;
+import org.nuiton.topia.event.TopiaTransactionVetoable;
+import org.nuiton.topia.persistence.TopiaEntity;
+
+/**
+ * This API provides methods to add/remove any kind of listener
+ *
+ * @author Arnaud Thimel <thimel(a)codelutin.com>
+ * @since 3.0
+ */
+public interface TopiaListenableSupport {
+
+ /* TopiaEntityListener */
+
+ /**
+ * Register to the context a TopiaEntityListener about any TopiaEntity.
+ * <code>listener</code> instance will be notified AFTER any operation on
+ * the entity.
+ *
+ * @param listener the listener instance to register
+ */
+ void addTopiaEntityListener(TopiaEntityListener listener);
+
+ /**
+ * Register to the context a TopiaEntityListener about the given entity
+ * class. <code>listener</code> instance will be notified AFTER any
+ * operation on the entity.
+ *
+ * @param entityClass the TopiaEntity's class to listen
+ * @param listener the listener instance to register
+ */
+ void addTopiaEntityListener(Class<? extends TopiaEntity> entityClass,
+ TopiaEntityListener listener);
+
+ /**
+ * Unregister the given TopiaEntityListener about any TopiaEntity from the
+ * context
+ *
+ * @param listener the listener instance to unregister
+ */
+ void removeTopiaEntityListener(TopiaEntityListener listener);
+
+ /**
+ * Unregister the given TopiaEntityListener about the given entity class
+ * from the context
+ *
+ * @param entityClass the listened TopiaEntity's class
+ * @param listener the listener instance to unregister
+ */
+ void removeTopiaEntityListener(Class<? extends TopiaEntity> entityClass,
+ TopiaEntityListener listener);
+
+
+ /* TopiaEntityVetoable */
+
+ /**
+ * Register to the context a TopiaEntityVetoable about any TopiaEntity.
+ * <code>vetoable</code> instance will be notified BEFORE any operation on
+ * the entity.
+ *
+ * @param vetoable the vetoable instance to register
+ */
+ void addTopiaEntityVetoable(TopiaEntityVetoable vetoable);
+
+ /**
+ * Register to the context a TopiaEntityVetoable about the given entity
+ * class. <code>vetoable</code> instance will be notified BEFORE any
+ * operation on the entity.
+ *
+ * @param entityClass the TopiaEntity's class to listen
+ * @param vetoable the vetoable instance to register
+ */
+ void addTopiaEntityVetoable(Class<? extends TopiaEntity> entityClass,
+ TopiaEntityVetoable vetoable);
+
+ /**
+ * Unregister the given TopiaEntityVetoable about any TopiaEntity from the
+ * context
+ *
+ * @param vetoable the vetoable instance to unregister
+ */
+ void removeTopiaEntityVetoable(TopiaEntityVetoable vetoable);
+
+ /**
+ * Unregister the given TopiaEntityVetoable about the given entity class
+ * from the context
+ *
+ * @param entityClass the listened TopiaEntity's class
+ * @param vetoable the vetoable instance to unregister
+ */
+ void removeTopiaEntityVetoable(Class<? extends TopiaEntity> entityClass,
+ TopiaEntityVetoable vetoable);
+
+
+ /* TopiaEntitiesVetoable */
+
+ /**
+ * Register to the context a TopiaEntitiesVetoable about any TopiaEntity.
+ * <code>vetoable</code> instance will be notified BEFORE any entity load
+ *
+ * @param vetoable the vetoable instance to register
+ */
+ void addTopiaEntitiesVetoable(TopiaEntitiesVetoable vetoable);
+
+ /**
+ * Unregister the given TopiaEntitiesVetoable about any TopiaEntity from the
+ * context
+ *
+ * @param vetoable the vetoable instance to unregister
+ */
+ void removeTopiaEntitiesVetoable(TopiaEntitiesVetoable vetoable);
+
+
+ /* TopiaTransactionListener */
+
+ /**
+ * Register to the context a TopiaTransactionListener about the transaction.
+ * <code>listener</code> instance will be notified AFTER any operation on
+ * the transaction.
+ *
+ * @param listener the listener instance to register
+ */
+ void addTopiaTransactionListener(TopiaTransactionListener listener);
+
+ /**
+ * Unregister the given TopiaTransactionListener about the transaction from
+ * the context
+ *
+ * @param listener the listener instance to unregister
+ */
+ void removeTopiaTransactionListener(TopiaTransactionListener listener);
+
+
+ /* TopiaTransactionVetoable */
+
+ /**
+ * Register to the context a TopiaTransactionVetoable about the transaction.
+ * <code>vetoable</code> instance will be notified BEFORE any operation on
+ * the transaction.
+ *
+ * @param vetoable the vetoable instance to register
+ */
+ void addTopiaTransactionVetoable(TopiaTransactionVetoable vetoable);
+
+ /**
+ * Unregister the given TopiaTransactionVetoable about the transaction from
+ * the context
+ *
+ * @param vetoable the vetoable instance to unregister
+ */
+ void removeTopiaTransactionVetoable(TopiaTransactionVetoable vetoable);
+
+
+ /* PropertyChangeListener */
+
+ /**
+ * Register to the context a PropertyChangeListener about some entity's
+ * property change. <code>listener</code> instance will be notified AFTER
+ * any change on the entity's property
+ *
+ * @param listener the listener instance to register
+ */
+ void addPropertyChangeListener(PropertyChangeListener listener);
+
+ /**
+ * Unregister the given PropertyChangeListener about some entity's
+ * property change from the context
+ *
+ * @param listener the listener instance to unregister
+ */
+ void removePropertyChangeListener(PropertyChangeListener listener);
+
+
+ /* TopiaSchemaListener */
+
+ /**
+ * Register to the context a TopiaSchemaListener about any schema
+ * modification. <code>listener</code> instance will be notified BEFORE and
+ * AFTER any change on the schema
+ *
+ * @param listener the listener instance to register
+ * @since 3.0
+ */
+ void addTopiaSchemaListener(TopiaSchemaListener listener);
+
+ /**
+ * Unregister the given TopiaSchemaListener about any schema modification
+ * from the context
+ *
+ * @param listener the listener instance to unregister
+ * @since 3.0
+ */
+ void removeTopiaSchemaListener(TopiaSchemaListener listener);
+
+}
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaNotFoundException.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaNotFoundException.java 2013-08-02 17:26:06 UTC (rev 2786)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaNotFoundException.java 2013-08-03 01:14:27 UTC (rev 2787)
@@ -26,7 +26,7 @@
package org.nuiton.topia;
/**
- * TODO-FD20100507 : Need javadoc.
+ * Exception thrown if one of the entry from the configuration is missing at runtime
*
* Created: 23 déc. 2005 23:04:28
*
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaPersistenceContext.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaPersistenceContext.java 2013-08-02 17:26:06 UTC (rev 2786)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaPersistenceContext.java 2013-08-03 01:14:27 UTC (rev 2787)
@@ -32,69 +32,53 @@
import org.nuiton.topia.persistence.TopiaIdFactory;
/**
+ * This API provides all methods related to persistence :
+ * <ul>
+ * <li>Generic entity find</li>
+ * <li>Persistence customization</li>
+ * <li>DAO factory</li>
+ * <li>Schema management</li>
+ * </ul>
+ *
* @author Arnaud Thimel <thimel(a)codelutin.com>
+ * @since 3.0
*/
public interface TopiaPersistenceContext {
/**
- * Retrieve {@link org.nuiton.topia.persistence.TopiaEntity} using its unique {@code id}.
+ * Retrieve {@link org.nuiton.topia.persistence.TopiaEntity} using its unique {@code topiaId}.
*
* @param topiaId unique identifier of the entity in all the application.
* @return the entity found or null
- * @throws TopiaException for errors on retrieving the entity
*/
- <E extends TopiaEntity> E findByTopiaId(String topiaId) throws TopiaException;
+ <E extends TopiaEntity> E findByTopiaId(String topiaId);
/**
* Add into this TopiaContext an entity created by another TopiaContext
*
- * @param e the entity to add
- * @throws TopiaException if any exception
+ * @param entity the entity to add
*/
- void update(TopiaEntity e) throws TopiaException;
+ void update(TopiaEntity entity);
/**
- * Triggers database schema creation
+ * Get the currently configured {@link TopiaIdFactory}.
*
- * @throws TopiaException if any exception
- */
- void createSchema() throws TopiaException;
-
- /**
- * Displays the SQL queries that would be used for a schema creation
- *
- * @throws TopiaException if any exception
- */
- void showCreateSchema() throws TopiaException;
-
- /**
- * Triggers database schema update
- *
- * @throws TopiaException if any exception
- */
- void updateSchema() throws TopiaException;
-
- /**
- * Triggers database schema drop
- *
- * @throws TopiaException if any exception
+ * @return the {@link TopiaIdFactory} in use
+ * @see {@link TopiaIdFactory}
* @since 3.0
*/
- void dropSchema() throws TopiaException;
+ TopiaIdFactory getTopiaIdFactory();
/**
- * @return Returns the config.
+ * @return the list of classes managed by this TopiaPersistenceContext
*/
- Properties getConfig(); // TODO AThimel 02/08/13 Change type ?
+ List<Class<?>> getPersistenceClasses();
- // TODO AThimel 02/08/13 Javadoc
- TopiaIdFactory getTopiaIdFactory();
-
/**
* Tells to the context if it has to use a flush mode before each query.
- *
+ * <p/>
* By default, we use a flush mode, but in some case it costs to much doing
- * this, that's why you can desactivate it setting the value to {@code false}.
+ * this, that's why you can disable it setting the value to {@code false}.
*
* @param useFlushMode the new value to set
* @since 2.5
@@ -102,40 +86,74 @@
void setUseFlushMode(boolean useFlushMode);
/**
- * Detect if the table is created on storage for a given persistant class.
- *
- * @param clazz the researched class
- * @return Returns the hibernate.
- * @throws TopiaException si aucune transaction n'est ouverte
+ * @return Returns the config.
*/
- boolean isSchemaExist(Class<?> clazz) throws TopiaException;
+ Properties getConfig(); // TODO AThimel 02/08/13 Change type ?
/**
* Get DAO for specified class. If Specialized DAO exists then it returned
* otherwize TopiaDAO<entityClass> is returned
*
- * @param <E> type of entity
* @param entityClass type of entity
- * @return the required dao
- * @throws TopiaException if any error
+ * @return the expected dao
*/
- <E extends TopiaEntity> TopiaDAO<E> getDAO(Class<E> entityClass)
- throws TopiaException;
+ <E extends TopiaEntity> TopiaDAO<E> getDAO(Class<E> entityClass);
/**
* Get DAO for specified class. If Specialized DAO exists then it returned
* otherwize TopiaDAO<entityClass> is returned
*
- * @param <E> type of entity
* @param entityClass type of entity
- * @param daoClass the concrete dao class to use
- * @return the required dao
- * @throws TopiaException if any error
+ * @param daoClass the concrete dao class to use
+ * @return the expected dao
*/
- <E extends TopiaEntity, D extends TopiaDAO<E>> D getDAO(Class<E> entityClass,Class<D> daoClass)
- throws TopiaException;
+ <E extends TopiaEntity, D extends TopiaDAO<E>> D getDAO(Class<E> entityClass, Class<D> daoClass);
- // TODO AThimel 02/08/13 Javadoc
- List<Class<?>> getPersistenceClasses();
+ /**
+ * Detects if the db associated to the current context contains at least one
+ * entity table.
+ *
+ * @return {@code true} if there is no schema for any of the dealed entities,
+ * {@code false} otherwise.
+ * @since 3.0
+ */
+ boolean isSchemaEmpty();
+ /**
+ * Detects if the table is created on storage for a given persistent class.
+ *
+ * @param clazz the researched class
+ * @return true if the table exists on storage
+ * @since 3.0
+ */
+ boolean isTableExists(Class<?> clazz);
+
+ /**
+ * @return the current schema name
+ * @since 3.0
+ */
+ String getSchemaName();
+
+ /**
+ * Triggers database schema creation
+ */
+ void createSchema();
+
+ /**
+ * Displays the SQL queries that would be used for a schema creation
+ */
+ void showCreateSchema();
+
+ /**
+ * Triggers database schema update
+ */
+ void updateSchema();
+
+ /**
+ * Triggers database schema drop
+ *
+ * @since 3.0
+ */
+ void dropSchema();
+
}
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaReplicationSupport.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaReplicationSupport.java 2013-08-02 17:26:06 UTC (rev 2786)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaReplicationSupport.java 2013-08-03 01:14:27 UTC (rev 2787)
@@ -29,11 +29,13 @@
import org.nuiton.topia.persistence.TopiaEntity;
/**
+ * This API provides methods about entities replication
+ *
* @author Arnaud Thimel <thimel(a)codelutin.com>
+ * @since 3.0
*/
public interface TopiaReplicationSupport {
-
/**
* Makes a replication of some entities from this context to the given
* context without any entity modification.
@@ -49,27 +51,24 @@
* @param entityAndCondition [key;value;...] parameter which key is the
* entity class to replicate, and value the
* "where" condition to use when querying entities
- * @throws TopiaException if any problem occurred during replicate
* @throws IllegalArgumentException if one of the context is closed or if
* trying to replicate within the same
* database
*/
void replicate(TopiaContext destinationContext,
- Object... entityAndCondition) throws TopiaException, IllegalArgumentException;
+ Object... entityAndCondition) throws IllegalArgumentException;
/**
* Replicate a given entity from this context to the given context.
*
* @param destinationContext the destination context
* @param entity the entity instance to replicate
- * @param <T> type of the entity to replicate
- * @throws TopiaException if any problem occurred during replicate
* @throws IllegalArgumentException if one of the context is closed or if
* trying to replicate within the same
* database
*/
<T extends TopiaEntity> void replicateEntity(TopiaContext destinationContext,
- T entity) throws TopiaException, IllegalArgumentException;
+ T entity) throws IllegalArgumentException;
/**
* Makes a replication of some entities from this context to the given
@@ -77,13 +76,11 @@
*
* @param destinationContext the destination context
* @param entities the list of entities instance to replicate
- * @param <T> type of the entities to replicate
- * @throws TopiaException if any problem occurred during replicate
* @throws IllegalArgumentException if one of the context is closed or if
* trying to replicate within the same
* database
*/
<T extends TopiaEntity> void replicateEntities(TopiaContext destinationContext,
- List<T> entities) throws TopiaException, IllegalArgumentException;
+ List<T> entities) throws IllegalArgumentException;
}
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaServiceSupport.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaServiceSupport.java 2013-08-02 17:26:06 UTC (rev 2786)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaServiceSupport.java 2013-08-03 01:14:27 UTC (rev 2787)
@@ -29,14 +29,16 @@
import org.nuiton.topia.framework.TopiaService;
/**
+ * This API provides methods to manipulate services
+ *
* @author Arnaud Thimel <thimel(a)codelutin.com>
+ * @since 3.0
*/
public interface TopiaServiceSupport {
/**
* Return true if specific service is available.
*
- * @param <E> type of service
* @param interfaceService fqn of the service
* @return the service
*/
@@ -46,13 +48,17 @@
* Return the service. This service must be valid with public static final
* SERVICE_NAME property.
*
- * @param <E> type of service
* @param interfaceService class of the service
* @return the service
* @throws TopiaNotFoundException if service can't be retrieved
*/
<E extends TopiaService> E getService(Class<E> interfaceService) throws TopiaNotFoundException;
+ /**
+ * The list of registered services. The map key is the service name, and the value is the service instance.
+ *
+ * @return a map with {serviceName, serviceInstance} values
+ */
Map<String, TopiaService> getServices();
}
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaSqlSupport.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaSqlSupport.java 2013-08-02 17:26:06 UTC (rev 2786)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaSqlSupport.java 2013-08-03 01:14:27 UTC (rev 2787)
@@ -25,7 +25,10 @@
*/
/**
+ * This API provides methods to run SQL queries
+ *
* @author Arnaud Thimel <thimel(a)codelutin.com>
+ * @since 3.0
*/
public interface TopiaSqlSupport {
@@ -33,8 +36,9 @@
* Execute a given sql code inside this transaction.
*
* @param sqlScript the sql script to execute
- * @throws TopiaException if any problem occurred while executing the sql script.
*/
- void executeSQL(String sqlScript) throws TopiaException;
+ void executeSQL(String sqlScript);
+ // TODO AThimel 20/07/13 Copy "void doSQLWork(TopiaSQLWork sqlWork);" from topia-3.0-jpa
+
}
Copied: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaTransaction.java (from rev 2786, trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaTransactionSupport.java)
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaTransaction.java (rev 0)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaTransaction.java 2013-08-03 01:14:27 UTC (rev 2787)
@@ -0,0 +1,73 @@
+package org.nuiton.topia;
+
+/*
+ * #%L
+ * ToPIA :: Persistence
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2004 - 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%
+ */
+
+/**
+ * This API provides methods to manipulate transaction
+ *
+ * @author Arnaud Thimel <thimel(a)codelutin.com>
+ * @since 3.0
+ */
+public interface TopiaTransaction {
+
+ /**
+ * Returns a new context containing its own transaction.
+ *
+ * @return new context with transaction
+ * @deprecated Sub contexts are not supported anymore, it is not possible to get a transaction FROM a transaction
+ */
+ @Deprecated
+ TopiaContext beginTransaction();
+
+ // TODO AThimel 03/08/13 We need another API to obtain a TopiaTransaction
+ // TODO AThimel 03/08/13 This new method has to be located somewhere else (TopiaTransactionSupplier ? TopiaTransactionSupport ? or just TopiaPersistenceContext ?)
+
+ /**
+ * Applies all the modifications made to this context on the persistence
+ * device. Once commit is done, a new transaction is started.
+ */
+ void commitTransaction();
+
+ /**
+ * Cancels all the modifications made to this context, coming back to the
+ * state on the last beginTransaction. Once rollback is done, a new
+ * transaction is started.
+ */
+ void rollbackTransaction();
+
+ /**
+ * Closes the context. All the children contexts will be closed in the same
+ * time.
+ */
+ void closeContext();
+
+ /**
+ * Tells if the context is closed
+ *
+ * @return {@code true} if the context is closed, {@code false} otherwise
+ */
+ boolean isClosed();
+
+}
Deleted: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaTransactionSupport.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaTransactionSupport.java 2013-08-02 17:26:06 UTC (rev 2786)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaTransactionSupport.java 2013-08-03 01:14:27 UTC (rev 2787)
@@ -1,72 +0,0 @@
-package org.nuiton.topia;
-
-/*
- * #%L
- * ToPIA :: Persistence
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2004 - 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%
- */
-
-/**
- * @author Arnaud Thimel <thimel(a)codelutin.com>
- */
-public interface TopiaTransactionSupport {
-
- /**
- * Returns a new context containing its own transaction.
- *
- * @return new context with transaction
- * @throws TopiaException if any exception
- */
- TopiaContext beginTransaction() throws TopiaException;
-
- /**
- * Applies all the modifications made to this context on the persistence
- * device. Once commit is done, a new transaction is started.
- *
- * @throws TopiaException if any exception
- */
- void commitTransaction() throws TopiaException;
-
- /**
- * Cancels all the modifications made to this context, coming back to the
- * state on the last beginTransaction. Once rollback is done, a new
- * transaction is started.
- *
- * @throws TopiaException if any exception
- */
- void rollbackTransaction() throws TopiaException;
-
- /**
- * Closes the context. All the children contexts will be closed in the same
- * time.
- *
- * @throws TopiaException if any exception
- */
- void closeContext() throws TopiaException;
-
- /**
- * Tells if the context is closed
- *
- * @return {@code true} if the context is closed, {@code false} otherwise
- */
- boolean isClosed();
-
-}
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaVetoException.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaVetoException.java 2013-08-02 17:26:06 UTC (rev 2786)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaVetoException.java 2013-08-03 01:14:27 UTC (rev 2787)
@@ -26,13 +26,14 @@
package org.nuiton.topia;
/**
- * TODO-FD20100507 : Need javadoc.
- *
+ * Exception thrown when something went wrong during event firing
+ * <p/>
* Created: 5 janv. 2006 00:47:51
*
* @author poussin <poussin(a)codelutin.com>
* @version $Id$
*/
+// TODO AThimel 03/08/13 Extends TopiaException ?
public class TopiaVetoException extends RuntimeException {
/** Version UID */
@@ -58,7 +59,7 @@
* with a {@code message}.
*
* @param message exception message
- * @param cause exception cause
+ * @param cause exception cause
*/
public TopiaVetoException(String message, Throwable cause) {
super(message, cause);
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/AbstractTopiaContext.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/AbstractTopiaContext.java 2013-08-02 17:26:06 UTC (rev 2786)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/AbstractTopiaContext.java 2013-08-03 01:14:27 UTC (rev 2787)
@@ -114,8 +114,7 @@
*/
//TODO-fdesbois-20100507 : Need translation of javadoc.
// TODO AThimel 02/08/13 must be abstract
-public class AbstractTopiaContext implements TopiaContext
- , TopiaContextImplementor {
+public class AbstractTopiaContext implements TopiaContext, TopiaContextImplementor {
/**
* to use log facility, just put in your code: log.info(\"...\");
@@ -563,7 +562,7 @@
}
@Override
- public SessionFactory getHibernateFactory() throws TopiaNotFoundException {
+ public SessionFactory getHibernateFactory() {
if (hibernateFactory == null) {
if (getParentContext() != null) {
hibernateFactory = getParentContext().getHibernateFactory();
@@ -597,8 +596,7 @@
}
@Override
- public Configuration getHibernateConfiguration()
- throws TopiaNotFoundException {
+ public Configuration getHibernateConfiguration() {
if (hibernateConfiguration == null) {
if (getParentContext() != null) {
hibernateConfiguration = getParentContext().getHibernateConfiguration();
@@ -644,7 +642,7 @@
log.debug("Load persistent class : " + classname);
}
- // XXX echatellier 20111007 ce cqui est dommage ici, c'est
+ // XXX echatellier 20111007 ce qui est dommage ici, c'est
// la definition de cette classe ne sert a rien (apart security)
// car pour hibernate hibernateConfiguration.addClass(persistanceClass)
// il ne se sert pas de la classe en fait et fait seulement
@@ -967,7 +965,7 @@
@Override
public <E extends TopiaEntity> E findByTopiaId(String id) throws TopiaException {
checkClosed(String.format("This context is closed, it is not possible to release the operation '%1$s'",
- "findById"));
+ "findByTopiaId"));
Class<E> entityClass = getTopiaIdFactory().getClassName(id);
TopiaDAO<E> dao = getDAO(entityClass);
@@ -1291,12 +1289,29 @@
@Override
public boolean isSchemaExist(Class<?> clazz)
throws TopiaException {
+ return isTableExists(clazz);
+ }
+
+ @Override
+ public boolean isSchemaEmpty() {
+ // TODO AThimel 02/08/13 Implement
+ throw new UnsupportedOperationException("Not yet implemented");
+ }
+
+ @Override
+ public boolean isTableExists(Class<?> clazz) {
checkClosed(String.format("This context is closed, it is not possible to release the operation '%1$s'",
"replicateEntity"));
boolean result = TopiaUtil.isSchemaExist(this, clazz.getName());
return result;
}
+ @Override
+ public String getSchemaName() {
+ // TODO AThimel 02/08/13 I absolutely don't know if it works
+ return getConfig().getProperty(TopiaContextFactory.CONFIG_DEFAULT_SCHEMA);
+ }
+
/* Listeners adders */
@Override
@@ -1528,14 +1543,14 @@
}
@Override
- public void update(TopiaEntity e) throws TopiaException {
+ public void update(TopiaEntity entity) throws TopiaException {
checkClosed(String.format("This context is closed, it is not possible to release the operation '%1$s'",
"add"));
- String id = e.getTopiaId();
+ String id = entity.getTopiaId();
Class<TopiaEntity> entityClass = getTopiaIdFactory().getClassName(id);
TopiaDAO<TopiaEntity> dao = getDAO(entityClass);
- dao.update(e);
+ dao.update(entity);
}
} //AbstractTopiaContext
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaContextImplementor.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaContextImplementor.java 2013-08-02 17:26:06 UTC (rev 2786)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaContextImplementor.java 2013-08-03 01:14:27 UTC (rev 2787)
@@ -30,11 +30,9 @@
import org.hibernate.cfg.Configuration;
import org.nuiton.topia.TopiaContext;
import org.nuiton.topia.TopiaException;
-import org.nuiton.topia.TopiaHibernate;
import org.nuiton.topia.TopiaNotFoundException;
import org.nuiton.topia.persistence.TopiaDAO;
import org.nuiton.topia.persistence.TopiaEntity;
-import org.nuiton.topia.persistence.TopiaIdFactory;
import java.util.List;
import java.util.Map;
@@ -91,7 +89,7 @@
/**
* @return Returns the hibernate.
* @throws TopiaException si aucune transaction n'est ouverte
- * @deprecated use method from {@link TopiaHibernate}
+ * @deprecated use method from {@link org.nuiton.topia.TopiaHibernateSupport}
*/
@Deprecated
Session getHibernate() throws TopiaException;
@@ -99,7 +97,7 @@
/**
* @return Returns the hibernateFactory.
* @throws TopiaNotFoundException
- * @deprecated use method from {@link TopiaHibernate}
+ * @deprecated use method from {@link org.nuiton.topia.TopiaHibernateSupport}
*/
@Deprecated
SessionFactory getHibernateFactory() throws TopiaNotFoundException;
@@ -107,7 +105,7 @@
/**
* @return Returns the hibernate configuration
* @throws TopiaNotFoundException
- * @deprecated use method from {@link TopiaHibernate}
+ * @deprecated use method from {@link org.nuiton.topia.TopiaHibernateSupport}
*/
@Deprecated
Configuration getHibernateConfiguration()
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/DefaultTopiaIdFactory.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/DefaultTopiaIdFactory.java 2013-08-02 17:26:06 UTC (rev 2786)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/DefaultTopiaIdFactory.java 2013-08-03 01:14:27 UTC (rev 2787)
@@ -24,25 +24,30 @@
* #L%
*/
+import java.util.UUID;
+
+import org.nuiton.topia.TopiaException;
+
import com.google.common.base.Splitter;
import com.google.common.collect.Iterables;
-import org.nuiton.topia.TopiaException;
-import java.util.UUID;
-
/**
* Default implementation of {@link TopiaIdFactory}. Generates an FQN followed
* by an random UUID.
+ *
+ * @author Brendan Le Ny <leny(a)codelutin.com>
+ * @since 3.0
*/
public class DefaultTopiaIdFactory implements TopiaIdFactory {
@Override
public <E extends TopiaEntity> String newTopiaId(Class<E> entityClass, TopiaEntity topiaEntity) {
- if ( ! entityClass.isInterface()) {
+ if (!entityClass.isInterface()) {
throw new IllegalArgumentException(
"Only interface is permit to create id: " + entityClass);
}
- return entityClass.getName() + '_' + UUID.randomUUID().toString();
+ String result = entityClass.getName() + '_' + UUID.randomUUID().toString();
+ return result;
}
@Override
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/LegacyTopiaIdFactory.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/LegacyTopiaIdFactory.java 2013-08-02 17:26:06 UTC (rev 2786)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/LegacyTopiaIdFactory.java 2013-08-03 01:14:27 UTC (rev 2787)
@@ -56,7 +56,7 @@
* @throws org.nuiton.topia.TopiaNotFoundException
*/
@Override
- public Class getClassName(String topiaId) throws TopiaNotFoundException {
+ public <E extends TopiaEntity> Class<E> getClassName(String topiaId) {
String className = "";
int i = topiaId.indexOf('#');
if (i > 0) {
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAO.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAO.java 2013-08-02 17:26:06 UTC (rev 2786)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAO.java 2013-08-03 01:14:27 UTC (rev 2787)
@@ -663,7 +663,7 @@
*
* @return Returns the context.
*/
- // TODO AThimel 02/08/13 Use only TopiaPersistenceContext and TopiaHibernate
+ // TODO AThimel 02/08/13 Use only TopiaPersistenceContext and TopiaHibernateSupport
TopiaContext getTopiaContext();
/**
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaEntities.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaEntities.java 2013-08-02 17:26:06 UTC (rev 2786)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaEntities.java 2013-08-03 01:14:27 UTC (rev 2787)
@@ -25,10 +25,14 @@
*/
import com.google.common.base.Function;
+import com.google.common.base.Optional;
+import com.google.common.base.Predicate;
+import com.google.common.base.Predicates;
+import com.google.common.collect.Iterables;
public class TopiaEntities {
- protected static final Function<TopiaEntity, String> GET_TOPIA_ID = new Function<TopiaEntity, String>() {
+ public static final Function<TopiaEntity, String> GET_TOPIA_ID = new Function<TopiaEntity, String>() {
@Override
public String apply(TopiaEntity input) {
@@ -36,12 +40,28 @@
}
};
+ public static Predicate<TopiaEntity> entityHasId(String id) {
+ return Predicates.compose(Predicates.equalTo(id), GET_TOPIA_ID);
+ }
+
+ public static <E extends TopiaEntity> E findByTopiaId(Iterable<E> entities, String id) {
+ E result;
+ if (entities == null) {
+ result = null;
+ } else {
+ Optional<E> eOptional = Iterables.tryFind(entities, entityHasId(id));
+ result = eOptional.orNull();
+ }
+ return result;
+ }
+
/**
* Function to obtain {@link TopiaEntity#getTopiaId()} from any entity.
*
* @since 2.6.12
+ * @deprecated use directly {@link #GET_TOPIA_ID} function
*/
- // TODO AThimel 20/07/13 Why is this function useful ? Why not use directly the GET_TOPIA_ID Function ?
+ @Deprecated
public static Function<TopiaEntity, String> getTopiaIdFunction() {
return GET_TOPIA_ID;
}
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaId.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaId.java 2013-08-02 17:26:06 UTC (rev 2786)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaId.java 2013-08-03 01:14:27 UTC (rev 2787)
@@ -57,7 +57,7 @@
* @author tchemit <tchemit(a)codelutin.com>
* @author chatellier <chatellier(a)codelutin.com>
* @version $Id$
- * @deprecated since 3.0 depends on implementation of TopiaIdFactory. WILL BE moved to topia-service-security
+ * @deprecated since 3.0 depends on implementation of TopiaIdFactory. Will be removed in next versions
*/
@Deprecated
public class TopiaId implements Serializable { // TopiaId
@@ -69,10 +69,10 @@
* Function to obtain {@link TopiaEntity#getTopiaId()} from any entity.
*
* @since 2.6.12
- * @deprecated since 3.0 use {@link org.nuiton.topia.persistence.TopiaEntities#getTopiaIdFunction()}
+ * @deprecated since 3.0 use {@link org.nuiton.topia.persistence.TopiaEntities#GET_TOPIA_ID}
*/
@Deprecated
- public static final Function<TopiaEntity, String> GET_TOPIA_ID = TopiaEntities.getTopiaIdFunction();
+ public static final Function<TopiaEntity, String> GET_TOPIA_ID = TopiaEntities.GET_TOPIA_ID;
public String topiaId;
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaIdFactory.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaIdFactory.java 2013-08-02 17:26:06 UTC (rev 2786)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaIdFactory.java 2013-08-03 01:14:27 UTC (rev 2787)
@@ -25,10 +25,10 @@
*/
/**
- * Contract representing a strategy of id generation.
+ * This API represents an ID generation strategy
*
+ * @author bleny
* @since 3.0
- * @author bleny
*/
public interface TopiaIdFactory {
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/csv/EntityCsvModel.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/csv/EntityCsvModel.java 2013-08-02 17:26:06 UTC (rev 2786)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/csv/EntityCsvModel.java 2013-08-03 01:14:27 UTC (rev 2787)
@@ -131,7 +131,7 @@
Collection<E> entities) {
Map<String, E> universe = Maps.uniqueIndex(entities,
- TopiaEntities.getTopiaIdFunction());
+ TopiaEntities.GET_TOPIA_ID);
newMandatoryColumn(propertyName,
TopiaCsvCommons.newForeignKeyValue(entityType,
1
0
Author: athimel
Date: 2013-08-02 19:26:06 +0200 (Fri, 02 Aug 2013)
New Revision: 2786
Url: http://nuiton.org/projects/topia/repository/revisions/2786
Log:
refs #2748 Rename TopiaContextImpl to AbstractTopiaContext
Added:
trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaTransactionSupport.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/AbstractTopiaContext.java
Removed:
trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaTransaction.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaContextImpl.java
Modified:
trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaContext.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaContextFactory.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaContextImplementor.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaFiresSupport.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaService.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/package-info.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityDAOTransformer.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAO.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAOImpl.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/csv/in/TopiaCsvImports.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/DBMapping.java
trunk/topia-persistence/src/test/java/org/nuiton/topia/TopiaContextFactoryTest.java
trunk/topia-persistence/src/test/java/org/nuiton/topia/framework/TopiaContextImplTest.java
trunk/topia-persistence/src/test/java/org/nuiton/topiatest/service/FakeService.java
trunk/topia-persistence/src/test/java/org/nuiton/topiatest/service/TestService.java
trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/TopiaMigrationEngine.java
trunk/topia-service-replication/src/main/java/org/nuiton/topia/replication/TopiaReplicationServiceImpl.java
trunk/topia-service-security/src/main/java/org/nuiton/topia/security/TopiaSecurityServiceImpl.java
trunk/topia-service-security/src/main/java/org/nuiton/topia/security/util/TopiaSecurityUtil.java
trunk/topia-service-security/src/main/java/org/nuiton/topia/taas/TaasService.java
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaContext.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaContext.java 2013-08-02 16:21:12 UTC (rev 2785)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaContext.java 2013-08-02 17:26:06 UTC (rev 2786)
@@ -53,11 +53,9 @@
* @author tchemit <tchemit(a)codelutin.com>
* @author athimel <thimel(a)codelutin.com>
* @version $Id$
- * @deprecated Since 3.0, TopiaContext is splitted in multiple contracts
*/
-@Deprecated
-public interface TopiaContext extends TopiaTransaction, TopiaListenable, TopiaSqlSupport, TopiaJpaSupport,
- TopiaPersistenceContext, TopiaServiceSupport, TopiaReplicationSupport {
+public interface TopiaContext extends TopiaTransactionSupport, TopiaListenable, TopiaSqlSupport, TopiaJpaSupport,
+ TopiaPersistenceContext, TopiaServiceSupport, TopiaReplicationSupport, TopiaHibernate {
/* -------------------- TRANSACTION MANAGEMENT --------------------------*/
@@ -66,7 +64,7 @@
*
* @return new context with transaction
* @throws TopiaException if any exception
- * @deprecated use method from {@link TopiaTransaction}
+ * @deprecated use method from {@link TopiaTransactionSupport}
*/
@Deprecated
TopiaContext beginTransaction() throws TopiaException;
@@ -76,7 +74,7 @@
* device. Once commit is done, a new transaction is started.
*
* @throws TopiaException if any exception
- * @deprecated use method from {@link TopiaTransaction}
+ * @deprecated use method from {@link TopiaTransactionSupport}
*/
@Deprecated
void commitTransaction() throws TopiaException;
@@ -87,7 +85,7 @@
* transaction is started.
*
* @throws TopiaException if any exception
- * @deprecated use method from {@link TopiaTransaction}
+ * @deprecated use method from {@link TopiaTransactionSupport}
*/
@Deprecated
void rollbackTransaction() throws TopiaException;
@@ -97,7 +95,7 @@
* time.
*
* @throws TopiaException if any exception
- * @deprecated use method from {@link TopiaTransaction}
+ * @deprecated use method from {@link TopiaTransactionSupport}
*/
@Deprecated
void closeContext() throws TopiaException;
@@ -106,7 +104,7 @@
* Tells if the context is closed
*
* @return {@code true} if the context is closed, {@code false} otherwise
- * @deprecated use method from {@link TopiaTransaction}
+ * @deprecated use method from {@link TopiaTransactionSupport}
*/
@Deprecated
boolean isClosed();
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaContextFactory.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaContextFactory.java 2013-08-02 16:21:12 UTC (rev 2785)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaContextFactory.java 2013-08-02 17:26:06 UTC (rev 2786)
@@ -30,7 +30,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.cfg.Environment;
-import org.nuiton.topia.framework.TopiaContextImpl;
+import org.nuiton.topia.framework.AbstractTopiaContext;
import org.nuiton.topia.framework.TopiaUtil;
import java.util.ArrayList;
@@ -133,7 +133,7 @@
*/
public static void removeContext(TopiaContext context) {
// Properties key = null;
-// for (Entry<Properties, TopiaContextImpl> e : contextCache.entrySet()) {
+// for (Entry<Properties, AbstractTopiaContext> e : contextCache.entrySet()) {
// if (e.getValue() == context) {
// key = e.getKey();
// break;
@@ -157,7 +157,7 @@
}
/**
- * Utilise par defaut le fichier de propriete TopiaContextImpl.properties
+ * Utilise par defaut le fichier de propriete AbstractTopiaContext.properties
*
* @return the context using the default configuration file
* @throws TopiaNotFoundException Si le fichier de configuration par defaut
@@ -172,7 +172,7 @@
/**
* Methode static permettant de recuperer un context. Si on donne plusieurs
* fois le meme objet config, on obtient la meme instance de
- * TopiaContextImpl. Si le context qui devrait etre retourné est ferme,
+ * AbstractTopiaContext. Si le context qui devrait etre retourné est ferme,
* alors un nouveau est creer et retourné.
*
* @param config the configuration of the context
@@ -192,7 +192,7 @@
TopiaContext result = contextCache.get(cloned);
// useless test, context is automatically removed from Factory when closed
if (result == null/* || result.isClosed()*/) {
- result = new TopiaContextImpl(cloned);
+ result = new AbstractTopiaContext(cloned);
if (log.isDebugEnabled()) {
log.debug("instantiate new topiaContext : " + result);
}
Deleted: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaTransaction.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaTransaction.java 2013-08-02 16:21:12 UTC (rev 2785)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaTransaction.java 2013-08-02 17:26:06 UTC (rev 2786)
@@ -1,72 +0,0 @@
-package org.nuiton.topia;
-
-/*
- * #%L
- * ToPIA :: Persistence
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2004 - 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%
- */
-
-/**
- * @author Arnaud Thimel <thimel(a)codelutin.com>
- */
-public interface TopiaTransaction {
-
- /**
- * Returns a new context containing its own transaction.
- *
- * @return new context with transaction
- * @throws TopiaException if any exception
- */
- TopiaContext beginTransaction() throws TopiaException;
-
- /**
- * Applies all the modifications made to this context on the persistence
- * device. Once commit is done, a new transaction is started.
- *
- * @throws TopiaException if any exception
- */
- void commitTransaction() throws TopiaException;
-
- /**
- * Cancels all the modifications made to this context, coming back to the
- * state on the last beginTransaction. Once rollback is done, a new
- * transaction is started.
- *
- * @throws TopiaException if any exception
- */
- void rollbackTransaction() throws TopiaException;
-
- /**
- * Closes the context. All the children contexts will be closed in the same
- * time.
- *
- * @throws TopiaException if any exception
- */
- void closeContext() throws TopiaException;
-
- /**
- * Tells if the context is closed
- *
- * @return {@code true} if the context is closed, {@code false} otherwise
- */
- boolean isClosed();
-
-}
Copied: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaTransactionSupport.java (from rev 2785, trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaTransaction.java)
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaTransactionSupport.java (rev 0)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaTransactionSupport.java 2013-08-02 17:26:06 UTC (rev 2786)
@@ -0,0 +1,72 @@
+package org.nuiton.topia;
+
+/*
+ * #%L
+ * ToPIA :: Persistence
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2004 - 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%
+ */
+
+/**
+ * @author Arnaud Thimel <thimel(a)codelutin.com>
+ */
+public interface TopiaTransactionSupport {
+
+ /**
+ * Returns a new context containing its own transaction.
+ *
+ * @return new context with transaction
+ * @throws TopiaException if any exception
+ */
+ TopiaContext beginTransaction() throws TopiaException;
+
+ /**
+ * Applies all the modifications made to this context on the persistence
+ * device. Once commit is done, a new transaction is started.
+ *
+ * @throws TopiaException if any exception
+ */
+ void commitTransaction() throws TopiaException;
+
+ /**
+ * Cancels all the modifications made to this context, coming back to the
+ * state on the last beginTransaction. Once rollback is done, a new
+ * transaction is started.
+ *
+ * @throws TopiaException if any exception
+ */
+ void rollbackTransaction() throws TopiaException;
+
+ /**
+ * Closes the context. All the children contexts will be closed in the same
+ * time.
+ *
+ * @throws TopiaException if any exception
+ */
+ void closeContext() throws TopiaException;
+
+ /**
+ * Tells if the context is closed
+ *
+ * @return {@code true} if the context is closed, {@code false} otherwise
+ */
+ boolean isClosed();
+
+}
Copied: trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/AbstractTopiaContext.java (from rev 2785, trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaContextImpl.java)
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/AbstractTopiaContext.java (rev 0)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/AbstractTopiaContext.java 2013-08-02 17:26:06 UTC (rev 2786)
@@ -0,0 +1,1542 @@
+/*
+ * #%L
+ * ToPIA :: Persistence
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2004 - 2013 CodeLutin, Chatellier Eric
+ * %%
+ * 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%
+ */
+
+package org.nuiton.topia.framework;
+
+import java.beans.PropertyChangeListener;
+import java.io.BufferedInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStream;
+import java.lang.reflect.Field;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+import java.util.WeakHashMap;
+import java.util.zip.GZIPInputStream;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.hibernate.FlushMode;
+import org.hibernate.HibernateException;
+import org.hibernate.Query;
+import org.hibernate.ReplicationMode;
+import org.hibernate.SQLQuery;
+import org.hibernate.Session;
+import org.hibernate.SessionFactory;
+import org.hibernate.Transaction;
+import org.hibernate.cfg.Configuration;
+import org.hibernate.engine.spi.SessionFactoryImplementor;
+import org.hibernate.event.service.spi.EventListenerRegistry;
+import org.hibernate.event.spi.EventType;
+import org.hibernate.jdbc.Work;
+import org.hibernate.service.ServiceRegistry;
+import org.hibernate.service.ServiceRegistryBuilder;
+import org.hibernate.service.jdbc.connections.spi.ConnectionProvider;
+import org.hibernate.service.spi.Stoppable;
+import org.hibernate.tool.hbm2ddl.SchemaExport;
+import org.hibernate.tool.hbm2ddl.SchemaUpdate;
+import org.nuiton.topia.TopiaContext;
+import org.nuiton.topia.TopiaContextFactory;
+import org.nuiton.topia.TopiaException;
+import org.nuiton.topia.TopiaNotFoundException;
+import org.nuiton.topia.event.TopiaContextListener;
+import org.nuiton.topia.event.TopiaEntitiesVetoable;
+import org.nuiton.topia.event.TopiaEntityListener;
+import org.nuiton.topia.event.TopiaEntityVetoable;
+import org.nuiton.topia.event.TopiaSchemaListener;
+import org.nuiton.topia.event.TopiaTransactionListener;
+import org.nuiton.topia.event.TopiaTransactionVetoable;
+import org.nuiton.topia.persistence.DefaultTopiaIdFactory;
+import org.nuiton.topia.persistence.TopiaDAO;
+import org.nuiton.topia.persistence.TopiaDAOImpl;
+import org.nuiton.topia.persistence.TopiaEntity;
+import org.nuiton.topia.persistence.TopiaIdFactory;
+
+/**
+ * Le AbstractTopiaContext est le point d'entre pour acceder aux donnees. Il est
+ * configurer par un fichier de propriete
+ * <p/>
+ * List des proprietes disponible <dl> <dt> topia.persistence.properties.file
+ * <dd> le fichier de propriété a utiliser pour configurer hibernate
+ * <p/>
+ * <dt> topia.persistence.directories <dd> la liste des repertoires contenant
+ * les mappings hibernates (.hbm.xml) la liste de repertoire est separer par des
+ * virgules ','
+ * <p/>
+ * <dt> topia.persistence.classes <dd> la liste des classes que doit géré
+ * hibernate. On peut tres bien utiliser topia.persistence.directories pour un
+ * ensemble d'entié du meme repertoire et topia.persistence.classes pour
+ * d'autres classes </dl>
+ * <p/>
+ * AbstractTopiaContext.java
+ * <p/>
+ * Created: 23 déc. 2005 16:58:50
+ *
+ * @author bpoussin <poussin(a)codelutin.com>
+ * @author tchemit <chemit(a)codelutin.com>
+ * @author fdesbois <desbois(a)codelutin.com>
+ * @version $Id$
+ */
+//TODO-fdesbois-20100507 : Need translation of javadoc.
+// TODO AThimel 02/08/13 must be abstract
+public class AbstractTopiaContext implements TopiaContext
+ , TopiaContextImplementor {
+
+ /**
+ * to use log facility, just put in your code: log.info(\"...\");
+ */
+ private static final Log log = LogFactory.getLog(AbstractTopiaContext.class);
+
+ /**
+ * Le pere de ce context, les contexts initaux n'ont pas de context pere
+ *
+ * @deprecated Hierarchical context are not supported anymore
+ */
+ @Deprecated
+ protected TopiaContextImplementor parentContext;
+
+ /**
+ * L'objet configuration utilisé pour la creation de la factory hibernate
+ */
+ protected Configuration hibernateConfiguration;
+
+ /**
+ * la factory permettant de recuperer la session hibernate. Seul les
+ * AbstractTopiaContext initiaux contiennent un hibernateFactory
+ */
+ protected SessionFactory hibernateFactory;
+
+ /**
+ * La session utilisé par le AbstractTopiaContext
+ */
+ protected Session hibernate;
+
+ /**
+ * Indique si le contexte a ete ferme
+ */
+ protected boolean closed;
+
+ /**
+ * This flag permits to use (or not) the flush mode when doing queries.
+ * <p/>
+ * The normal usage is to says yes (that's why the default value is
+ * {@code true}), in that case whebn doing queries (says in method
+ * {@link #findAll(String, Object...)} or {@link #find(String, int, int, Object...)})
+ * it will use the flush mode {@link FlushMode#AUTO}).
+ * <p/>
+ * But sometimes, when doing a lot of queries (for some imports for example),
+ * we do NOT want the session to be flushed each time we do a find, then you
+ * can set this flag to {@code false} using the method {@link #setUseFlushMode(boolean)}
+ *
+ * @since 2.5
+ */
+ protected boolean useFlushMode = true;
+
+ /**
+ * Propriete de configuration
+ */
+ protected Properties config;
+
+ /**
+ * Used to affect a new topiaId when create is called.
+ *
+ * @since 3.0
+ */
+ protected TopiaIdFactory topiaIdFactory;
+
+ /**
+ * cache des DAO deja chargé pour ce context
+ */
+ protected Map<Class<? extends TopiaEntity>,
+ TopiaDAO<? extends TopiaEntity>> daoCache =
+ new HashMap<Class<? extends TopiaEntity>,
+ TopiaDAO<? extends TopiaEntity>>();
+
+ /**
+ * Set of child context created with {@link #beginTransaction()}. We are
+ * listener on these context. A WeakHashMap is used to remove old context
+ * automically when it's not used anymore. The {@link #finalize} method will
+ * be executed when Garbage collector is called when reference is removed.
+ * The set is synchronized in case of using multi-threading.
+ *
+ * @see Collections#synchronizedSet(Set)
+ * @see Collections#newSetFromMap(Map)
+ */
+ protected final Set<TopiaContextImplementor> childContext =
+ Collections.synchronizedSet(
+ Collections.newSetFromMap(
+ new WeakHashMap<TopiaContextImplementor, Boolean>()));
+
+ /**
+ * key: service name; value: service instance
+ */
+ protected Map<String, TopiaService> services;
+
+ protected TopiaFiresSupport firesSupport = new TopiaFiresSupport();
+
+ /**
+ * Liste des classes perssitance
+ */
+ protected List<Class<?>> persistenceClasses = new ArrayList<Class<?>>();
+
+ /**
+ * Default constructor, useful for tests.
+ */
+ protected AbstractTopiaContext() {
+
+ }
+
+ /**
+ * Constructor used by {@link TopiaContextFactory} to initialize rootContext
+ * using {@code config}.
+ *
+ * @param config for the new root context
+ * @throws TopiaNotFoundException if one of persistent class from
+ * configuration is not found
+ */
+ public AbstractTopiaContext(Properties config) throws TopiaNotFoundException {
+ this.config = config;
+ initTopiaIdFactory();
+ services = loadServices(config);
+ preInitServices(services);
+ getHibernateConfiguration(); // force mapping loading
+ postInitServices(services);
+ }
+
+ protected void initTopiaIdFactory() {
+ String configTopiaIdFactoryClassName =
+ getConfig().getProperty(TopiaContextFactory.CONFIG_PERSISTENCE_TOPIA_ID_FACTORY_CLASS_NAME, "");
+ if (StringUtils.isEmpty(configTopiaIdFactoryClassName)) {
+ topiaIdFactory = new DefaultTopiaIdFactory();
+ } else {
+ try {
+ Class configPersistenceTopiaIdFactoryClass =
+ Class.forName(configTopiaIdFactoryClassName);
+ if (TopiaIdFactory.class.isAssignableFrom(configPersistenceTopiaIdFactoryClass)) {
+ topiaIdFactory = (TopiaIdFactory) configPersistenceTopiaIdFactoryClass.newInstance();
+ } else {
+ throw new IllegalArgumentException(
+ configTopiaIdFactoryClassName + " is not a valid class name. The class must implements "
+ + TopiaIdFactory.class.getSimpleName());
+ }
+ } catch (ClassNotFoundException e) {
+ throw new TopiaException(e);
+ } catch (InstantiationException e) {
+ throw new TopiaException(e);
+ } catch (IllegalAccessException e) {
+ throw new TopiaException(e);
+ }
+ }
+ }
+
+ protected String getProperExceptionMessage(Throwable eee) {
+ return eee.getClass().getSimpleName() + " : " +
+ eee.getMessage();
+ }
+
+ /* -------------------- SERVICES MANAGMENT -------------------------------*/
+
+ protected Map<String, TopiaService> loadServices(Properties config) {
+ Map<String, TopiaService> result = new HashMap<String, TopiaService>();
+ // recherche des services present dans la config
+ for (Enumeration<?> e = config.propertyNames(); e.hasMoreElements(); ) {
+ String key = (String) e.nextElement();
+ if (key.matches("^topia\\.service\\.\\w+$")) {
+ String classService = config.getProperty(key);
+ try {
+ Class<?> forName = Class.forName(classService);
+ Object newInstance = forName.getConstructor().newInstance();
+ TopiaService service = (TopiaService) newInstance;
+ if (key.equals("topia.service." + service.getServiceName())) {
+ result.put(service.getServiceName(), service);
+ log.info(String.format("Service '%1$s' loaded (implementation %2$s)",
+ key, classService));
+ } else {
+ log.warn(String.format("The service with key '%1$s' has a different name '%2$s'! (service not activated)",
+ key, service.getServiceName()));
+ }
+ } catch (Throwable eee) {
+ String message =
+ String.format("The service %1$s of type %2$s was not found.",
+ key, classService);
+ if (log.isDebugEnabled()) {
+ log.debug(message, eee);
+ } else if (log.isErrorEnabled()) {
+ log.error(message);
+ }
+ }
+ }
+ }
+ return result;
+ }
+
+ protected void preInitServices(Map<String, TopiaService> services) {
+ for (TopiaService service : services.values()) {
+ if (!service.preInit(this)) {
+ log.warn(String.format("The service named '%1$s' could not be post-initialized (service not activated)",
+ service.getServiceName()));
+ }
+ }
+ }
+
+ protected void postInitServices(Map<String, TopiaService> services) {
+ for (TopiaService service : services.values()) {
+ if (!service.postInit(this)) {
+ log.warn(String.format("The service named '%1$s' could not be pre-initialized (service not activated)",
+ service.getServiceName()));
+ }
+ }
+ }
+
+ protected TopiaService getService(String name) {
+ TopiaService result = getServices().get(name);
+ return result;
+ }
+
+ protected boolean serviceEnabled(String name) {
+ boolean result = getServices().containsKey(name);
+ return result;
+ }
+
+ /**
+ * Retrieve service name using SERVICE_NAME static field on service
+ * interface.
+ *
+ * @param interfaceService class of the service
+ * @param <E> type of the service that extends {@link
+ * TopiaService}
+ * @return the service name
+ * @throws IllegalAccessException if field SERVICE_NAME can't be accessed
+ * @throws NoSuchFieldException if no field SERVICE_NAME is defined
+ */
+ protected <E extends TopiaService> String getServiceName(
+ Class<E> interfaceService)
+ throws IllegalAccessException, NoSuchFieldException {
+ Field f = interfaceService.getField("SERVICE_NAME");
+ String name = (String) f.get(null);
+ return name;
+ }
+
+ @Override
+ public Map<String, TopiaService> getServices() {
+ TopiaContextImplementor parent = getParentContext();
+
+ Map<String, TopiaService> result;
+ if (parent != null) {
+ result = parent.getServices();
+ } else {
+ result = services;
+ }
+ return result;
+ }
+
+ /**
+ * Take one service, this service must be valid service interface with
+ * public static final SERVICE_NAME declaration.
+ *
+ * @param <E> type of the service that extends {@link TopiaService}
+ * @throws TopiaNotFoundException if an error appears or service not found.
+ * @see #getServiceName(Class)
+ */
+ @Override
+ public <E extends TopiaService> E getService(Class<E> interfaceService)
+ throws TopiaNotFoundException {
+ E result;
+ try {
+ String name = getServiceName(interfaceService);
+ result = (E) getService(name);
+ } catch (Exception eee) {
+ throw new TopiaNotFoundException(
+ String.format("Could not retreave service %1$s for following reason: %2$s",
+ interfaceService, getProperExceptionMessage(eee)),
+ eee);
+ }
+ if (result == null) {
+ throw new TopiaNotFoundException(
+ String.format("The service %1$s was not found.",
+ interfaceService));
+ }
+ return result;
+ }
+
+ @Override
+ public <E extends TopiaService> boolean serviceEnabled(
+ Class<E> interfaceService) {
+ boolean result = false;
+ try {
+ String name = getServiceName(interfaceService);
+ result = serviceEnabled(name);
+ } catch (Exception eee) {
+ String message = String.format("The service named '%1$s' could not be found for following reason: %2$s",
+ interfaceService, getProperExceptionMessage(eee));
+ if (log.isDebugEnabled()) {
+ log.debug(message, eee);
+ } else if (log.isWarnEnabled()) {
+ log.warn(message);
+ }
+ }
+ return result;
+ }
+
+ /* -------------------- CONTEXT HIERARCHY MANAGMENT ----------------------*/
+
+ /**
+ * Constructor used by {@link #beginTransaction()} to instantiate child from
+ * {@code parentContext}.
+ *
+ * @param parentContext context parent of the new TopiaContext child
+ */
+ protected AbstractTopiaContext(TopiaContextImplementor parentContext) {
+ this.parentContext = parentContext;
+ }
+
+ @Override
+ public Set<TopiaContextImplementor> getChildContext() {
+ // fdesbois-20100421 : Ano #546
+ // Copy the childContext into a new set
+ Set<TopiaContextImplementor> values;
+ // Synchronize copy to be thread-safe during iteration
+ synchronized (childContext) {
+ values = new HashSet<TopiaContextImplementor>(childContext);
+ }
+ return values;
+ }
+
+ protected void addChildContext(TopiaContextImplementor child) {
+ childContext.add(child);
+ }
+
+ @Override
+ public void removeChildContext(TopiaContext child) {
+ // Remove child only if this context is not already closed.
+ if (!closed) {
+ childContext.remove(child);
+ }
+ }
+
+ @Override
+ public TopiaContextImplementor getParentContext() {
+ return parentContext;
+ }
+
+ @Override
+ public TopiaContextImplementor getRootContext() {
+ TopiaContextImplementor result = this;
+ if (getParentContext() != null) {
+ result = getParentContext().getRootContext();
+ }
+ return result;
+ }
+
+ @Override
+ public Properties getConfig() {
+ if (config == null && getParentContext() != null) {
+ config = getParentContext().getConfig();
+ }
+ return config;
+ }
+
+ @Override
+ public TopiaIdFactory getTopiaIdFactory() {
+ if (topiaIdFactory == null) {
+ initTopiaIdFactory();
+ }
+ return topiaIdFactory;
+ }
+
+ /**
+ * Change the value of flag {@link #useFlushMode}.
+ *
+ * @param useFlushMode the new value to set
+ * @see #useFlushMode
+ * @since 2.5
+ */
+ public void setUseFlushMode(boolean useFlushMode) {
+ this.useFlushMode = useFlushMode;
+ }
+
+ /* -------------------- HIBERNATE MANAGMENT -----------------------------*/
+
+ @Override
+ public void createSchema() throws TopiaException {
+ try {
+ boolean showSchema = false;
+ if (log.isDebugEnabled()) {
+ showSchema = true;
+ }
+ getFiresSupport().firePreCreateSchema(this);
+ new SchemaExport(getHibernateConfiguration()).execute(showSchema, true, false, true);
+ getFiresSupport().firePostCreateSchema(this);
+ } catch (HibernateException eee) {
+ throw new TopiaException(
+ String.format("Could not create schema for reason: %s",
+ eee.getMessage()), eee);
+ }
+ }
+
+ @Override
+ public void showCreateSchema() throws TopiaException {
+ try {
+ new SchemaExport(getHibernateConfiguration()).
+ execute(true, false, false, true);
+ } catch (HibernateException eee) {
+ throw new TopiaException(
+ String.format("Could not show create schema for reason: %s",
+ eee.getMessage()), eee);
+ }
+ }
+
+ @Override
+ public void updateSchema() throws TopiaException {
+ try {
+ boolean showSchema = false;
+ if (log.isDebugEnabled()) {
+ showSchema = true;
+ }
+ getFiresSupport().firePreUpdateSchema(this);
+ new SchemaUpdate(getHibernateConfiguration()).execute(showSchema,
+ true);
+ getFiresSupport().firePostUpdateSchema(this);
+ } catch (HibernateException eee) {
+ throw new TopiaException(
+ String.format("Could not update schema for reason: %s",
+ eee.getMessage()), eee);
+ }
+ }
+
+ @Override
+ public void dropSchema() throws TopiaException {
+ try {
+ boolean showSchema = false;
+ if (log.isDebugEnabled()) {
+ showSchema = true;
+ }
+ getFiresSupport().firePreDropSchema(this);
+ new SchemaExport(getHibernateConfiguration()).execute(showSchema, true, true, false);
+ getFiresSupport().firePostDropSchema(this);
+ } catch (HibernateException eee) {
+ throw new TopiaException(
+ String.format("Could not drop schema for reason: %s",
+ eee.getMessage()), eee);
+ }
+ }
+
+ @Override
+ public Session getHibernate() throws TopiaException {
+ Session result = getHibernateSession();
+ return result;
+ }
+
+ @Override
+ public SessionFactory getHibernateFactory() throws TopiaNotFoundException {
+ if (hibernateFactory == null) {
+ if (getParentContext() != null) {
+ hibernateFactory = getParentContext().getHibernateFactory();
+ } else {
+
+ // init service registry
+ ServiceRegistry serviceRegistry = new ServiceRegistryBuilder().applySettings(
+ getHibernateConfiguration().getProperties()).buildServiceRegistry();
+
+ hibernateFactory = getHibernateConfiguration().buildSessionFactory(serviceRegistry);
+
+ // we can't reuse original serviceRegistry instance
+ // we must call getServiceRegistry on factory to get a working one
+ ServiceRegistry serviceRegistryInit = ((SessionFactoryImplementor) hibernateFactory).getServiceRegistry();
+ EventListenerRegistry eventListenerRegistry = serviceRegistryInit.getService(EventListenerRegistry.class);
+ TopiaFiresSupport.TopiaHibernateEvent listener = new TopiaFiresSupport.TopiaHibernateEvent(this);
+ eventListenerRegistry.appendListeners(EventType.PRE_INSERT, listener);
+ eventListenerRegistry.appendListeners(EventType.PRE_LOAD, listener);
+ eventListenerRegistry.appendListeners(EventType.PRE_UPDATE, listener);
+ eventListenerRegistry.appendListeners(EventType.PRE_DELETE, listener);
+ eventListenerRegistry.appendListeners(EventType.POST_INSERT, listener);
+ eventListenerRegistry.appendListeners(EventType.POST_LOAD, listener);
+ eventListenerRegistry.appendListeners(EventType.POST_UPDATE, listener);
+ eventListenerRegistry.appendListeners(EventType.POST_DELETE, listener);
+
+ // following listeners must be called before hibernate
+ eventListenerRegistry.prependListeners(EventType.SAVE_UPDATE, listener);
+ }
+ }
+ return hibernateFactory;
+ }
+
+ @Override
+ public Configuration getHibernateConfiguration()
+ throws TopiaNotFoundException {
+ if (hibernateConfiguration == null) {
+ if (getParentContext() != null) {
+ hibernateConfiguration = getParentContext().getHibernateConfiguration();
+ } else {
+ hibernateConfiguration = new Configuration();
+
+ // ajout des repertoires contenant les mappings hibernate
+ String[] dirs = getConfig().getProperty(
+ TopiaContextFactory.CONFIG_PERSISTENCE_DIRECTORIES, "").split(",");
+ for (String dir : dirs) {
+ dir = dir.trim();
+ if (StringUtils.isNotEmpty(dir)) {
+ if (log.isDebugEnabled()) {
+ log.debug("Load persistence from dir : " + dir);
+ }
+ hibernateConfiguration.addDirectory(new File(dir));
+ }
+ }
+
+ // ajout des classes dites persistentes
+ Set<Class<?>> hibernatePersistanceClasses = new HashSet<Class<?>>();
+ for (TopiaService service : getServices().values()) {
+ Class<?>[] classes = service.getPersistenceClasses();
+
+ // certains service n'ont pas de classe persistantes
+ if (classes != null) {
+ // sletellier 20110411 : http://www.nuiton.org/issues/show/1454
+ hibernatePersistanceClasses.addAll(Arrays.asList(classes));
+// for (Class<?> clazz : classes) {
+// hibernateConfiguration.addClass(clazz);
+// }
+ }
+ }
+
+ String listPersistenceClasses = getConfig().getProperty(
+ TopiaContextFactory.CONFIG_PERSISTENCE_CLASSES, "");
+
+ String[] classes = listPersistenceClasses.split(",");
+ for (String classname : classes) {
+ classname = classname.trim();
+ if (StringUtils.isNotEmpty(classname)) {
+ if (log.isDebugEnabled()) {
+ log.debug("Load persistent class : " + classname);
+ }
+
+ // XXX echatellier 20111007 ce cqui est dommage ici, c'est
+ // la definition de cette classe ne sert a rien (apart security)
+ // car pour hibernate hibernateConfiguration.addClass(persistanceClass)
+ // il ne se sert pas de la classe en fait et fait seulement
+ // un classname.replace( '.', '/' ) + ".hbm.xml";
+ // pour obtenir le mapping et la reinstancier ensuite
+
+ Class<?> clazz;
+ try {
+ clazz = Class.forName(classname);
+ } catch (ClassNotFoundException eee) {
+ if (log.isDebugEnabled()) {
+ log.debug("Class " + classname + " not found");
+ }
+ throw new TopiaNotFoundException(
+ String.format("Persistence class %1$s not found",
+ classname));
+ }
+ persistenceClasses.add(clazz);
+
+ // sletellier 20110411 : http://www.nuiton.org/issues/show/1454
+// hibernateConfiguration.addClass(clazz);
+ hibernatePersistanceClasses.add(clazz);
+ }
+ }
+
+ // sletellier 20110411 : http://www.nuiton.org/issues/show/1454
+ // Add persistance classes in hibernate config
+ for (Class<?> persistanceClass : hibernatePersistanceClasses) {
+ hibernateConfiguration.addClass(persistanceClass);
+ }
+
+ Properties prop = new Properties();
+ prop.putAll(hibernateConfiguration.getProperties());
+ prop.putAll(getConfig());
+
+ // Strange behavior, all properties are already loaded from
+ // constructor. Difficult to use this behavior, need to have
+ // TOPIA_PERSISTENCE_PROPERTIES_FILE in config.
+ Properties propertiesFromClasspath =
+ TopiaUtil.getProperties(getConfig().
+ getProperty(TopiaContextFactory.CONFIG_PERSISTENCE_PROPERTIES_FILE));
+
+ if (!propertiesFromClasspath.isEmpty()) {
+ if (log.isDebugEnabled()) {
+ log.debug("Load properties from file : " +
+ propertiesFromClasspath);
+ }
+ prop.putAll(propertiesFromClasspath);
+ }
+
+ hibernateConfiguration.setProperties(prop);
+
+ // tchemit 2011-05-26 When using hibernate > 3.3, need to make sure all mappings are loaded (the one from directory files are not still done).
+ hibernateConfiguration.buildMappings();
+ }
+ }
+ return hibernateConfiguration;
+ }
+
+ /* -------------------- CHILD CONTEXT AND DAOS --------------------------*/
+
+ @Override
+ public <E extends TopiaEntity> TopiaDAO<E> getDAO(Class<E> entityClass)
+ throws TopiaException {
+ if (entityClass == null) {
+ throw new IllegalArgumentException(
+ String.format("The method '%1$s' requires a non null parameter '%2$s'.",
+ "entityClass", "getDAO"));
+ }
+ if (equals(getRootContext())) {
+ throw new TopiaException(
+ "You are on root context, you MUST open a transaction to perform any database access.");
+ }
+ if (getHibernateFactory().getClassMetadata(entityClass) == null &&
+ getHibernateFactory().getClassMetadata(
+ entityClass.getName() + "Impl") == null &&
+ getHibernateFactory().getClassMetadata(
+ entityClass.getName() + "Abstract") == null) {
+
+ log.info(String.format("List of supported persistence classes: %1$s",
+ getHibernateFactory().getAllClassMetadata().keySet()));
+ throw new TopiaException(
+ String.format("The following entity type %1$s is not managed by this context, you probably forgot to declare it.",
+ entityClass.getName()));
+ }
+
+ TopiaDAOImpl<E> result = (TopiaDAOImpl<E>) daoCache.get(entityClass);
+ if (result == null) {
+
+ // looking for specialized DAO
+ // normalement il en existe un car il est généré automatiquement
+ // si on utilise la génération
+ String daoClassname = entityClass.getName() + "DAO";
+ try {
+ Class<TopiaDAOImpl<E>> daoClass =
+ (Class<TopiaDAOImpl<E>>) Class.forName(daoClassname);
+ TopiaDAOImpl<E> spe = daoClass.getConstructor().newInstance();
+ result = spe;
+ } catch (Exception eee) {
+ log.warn("specialized DAO " + daoClassname +
+ " not found, use default TopiaDAOHibernate");
+ result = new TopiaDAOImpl<E>();
+ }
+
+ result.init(this, entityClass, getFiresSupport());
+ daoCache.put(entityClass, result);
+ }
+ return result;
+ }
+
+ @SuppressWarnings({"unchecked"})
+ @Override
+ public <E extends TopiaEntity, D extends TopiaDAO<E>> D getDAO(Class<E> entityClass,
+ Class<D> daoClass) throws TopiaException {
+ return (D) getDAO(entityClass);
+ }
+
+ @Override
+ public TopiaContext beginTransaction() throws TopiaException {
+ checkClosed("Context is closed, no operation is possible.");
+ AbstractTopiaContext result = new AbstractTopiaContext(this);
+
+ SessionFactory factory = getHibernateFactory();
+ result.hibernate = factory.openSession();
+
+ // new TopiaInterceptor(result));
+ // on ne synchronise jamais les données avec la base tant que
+ // l'utilisateur n'a pas fait de commit du context
+ result.hibernate.setFlushMode(FlushMode.MANUAL);
+
+ // tchemit 2010-12-06 propagates the value of the flag
+ result.useFlushMode = useFlushMode;
+
+ // 20060926 poussin ajouter pour voir si ca regle les problemes de
+ // deadlock h2. Conclusion, il faut bien ouvrir une transaction
+ // maintenant, sinon lorsque l'on fait des acces a la base, une
+ // transaction par defaut est utilisé mais elle n'est jamais vraiment
+ // fermé ce qui pose des problemes de lock sur les tables.
+ try {
+ result.hibernate.beginTransaction();
+ } catch (Exception eee) {
+
+ // on a pas pu ouvrir la transaction, on faut donc tout fermer
+ // et declancher une exception
+ try {
+ result.hibernate.close();
+ } catch (HibernateException e1) {
+ if (log.isErrorEnabled()) {
+ log.error("Could not close hibernate session", e1);
+ }
+ }
+
+ throw new TopiaException(
+ String.format("An error occurs while asking a new transaction: %1$s",
+ eee.getMessage()),
+ eee);
+ }
+
+ // 20081217 : add child AFTER hibernate session is opened
+ addChildContext(result);
+
+ // fire event
+ getFiresSupport().fireOnBeginTransaction(result);
+ return result;
+ }
+
+ @Override
+ public void commitTransaction() throws TopiaException {
+ if (equals(getRootContext())) {
+ throw new TopiaException(String.format("Unsupported operation %s on root context",
+ "commit"));
+ }
+ checkClosed(String.format("This context is closed, it is not possible to release the operation '%1$s'",
+ "commit"));
+
+ try {
+// for (TopiaDAO<? extends TopiaEntity> dao : daoCache.values()) {
+// // TODO-fdesbois-20100507 : need to be removed for 2.5 version
+// dao.commitTransaction();
+// }
+ Transaction tx = hibernate.getTransaction();
+ // Transaction tx = hibernate.beginTransaction();
+ hibernate.flush();
+ tx.commit();
+
+ getFiresSupport().fireOnPostCommit(this);
+ TopiaContextImplementor parent = getParentContext();
+ if (parent != null) {
+ parent.getFiresSupport().fireOnPostCommit(this);
+ }
+
+ hibernate.beginTransaction();
+
+ // it's seem necessary to change session after commit
+ // NON, NON, NON, il ne faut surtout pas le faire, ca pose plein de
+ // probleme
+ // hibernate = getHibernateFactory().openSession();
+ // hibernate.setFlushMode(FlushMode.NEVER);
+ } catch (Exception eee) {
+ throw new TopiaException(String.format("An error occurs while commit operation: %1$s",
+ eee.getMessage()), eee);
+ }
+ }
+
+ @Override
+ public void rollbackTransaction() throws TopiaException {
+ if (equals(getRootContext())) {
+ throw new TopiaException(String.format("Unsupported operation %s on root context",
+ "rollback"));
+ }
+ checkClosed(String.format("This context is closed, it is not possible to release the operation '%1$s'",
+ "rollback"));
+ try {
+// for (TopiaDAO<? extends TopiaEntity> dao : daoCache.values()) {
+// // TODO-fdesbois-20100507 : need to be removed for 2.5 version
+// dao.rollbackTransaction();
+// }
+ Transaction tx = hibernate.getTransaction();
+ // Transaction tx = hibernate.beginTransaction();
+ hibernate.clear();
+ tx.rollback();
+ hibernate.close();
+ // it's very important to change the session after rollback
+ // otherwize there are many error during next Entity's modification
+ hibernate = getHibernateFactory().openSession();
+ hibernate.setFlushMode(FlushMode.MANUAL);
+
+ hibernate.beginTransaction();
+
+ getFiresSupport().fireOnPostRollback(this);
+ TopiaContextImplementor parent = getParentContext();
+ if (parent != null) {
+ parent.getFiresSupport().fireOnPostRollback(this);
+ }
+
+ } catch (HibernateException eee) {
+ throw new TopiaException(
+ String.format("An error occurs while rollback operation: %1$s",
+ eee.getMessage()), eee);
+ }
+ }
+
+ @Override
+ public void closeContext() throws TopiaException {
+ // Throw exception if context is already closed
+ checkClosed("Context was already closed");
+
+ // FD-20100421 : Ano #546 : no need to copy childContext, the
+ // {@link #getChildContext()} provides a thread-safe copy to iterate
+ // on it.
+// TopiaContextImplementor[] children = childContext.toArray(
+// new TopiaContextImplementor[childContext.size()]);
+
+ // Remove all children context
+ for (TopiaContextImplementor child : getChildContext()) {
+ // Avoid to have exception from checkClosed method on child
+ if (!child.isClosed()) {
+ child.closeContext();
+ }
+ }
+
+ // on se desenregistre du context pere et on ferme les connexions si
+ // on est pas le root context
+ if (!equals(getRootContext())) {
+ closed = true;
+ hibernate.close();
+ getParentContext().removeChildContext(this);
+ } else {
+ if (hibernateFactory != null) {
+ hibernateFactory.close();
+ // close connection provider if possible (http://nuiton.org/issues/2757)
+ ConnectionProvider service = ((SessionFactoryImplementor) hibernateFactory).getServiceRegistry().getService(ConnectionProvider.class);
+ if (service instanceof Stoppable) {
+ Stoppable stoppable = (Stoppable) service;
+ stoppable.stop();
+ }
+ closed = true;
+ TopiaContextFactory.removeContext(this);
+ log.debug("TopiaContext removed");
+ }
+ }
+ }
+
+ /**
+ * Pour le context root on ferme tous les fils, et la factory hibernate.
+ */
+ @Override
+ protected void finalize() throws Throwable {
+ if (hibernateFactory != null) {
+ closeContext();
+ hibernateFactory.close();
+ closed = true;
+ log.debug("TopiaContext finalized");
+ }
+ }
+
+ @Override
+ public boolean isClosed() {
+ return closed;
+ }
+
+ @Override
+ public void executeSQL(String sqlScript) throws TopiaException {
+ SQLWork sqlWork = new SQLWork(sqlScript);
+ try {
+ getHibernate().doWork(sqlWork);
+ } catch (HibernateException e) {
+ throw new TopiaException("Could not execute sql code", e);
+ }
+ }
+
+ protected void checkClosed(String message) throws TopiaException {
+ if (closed) {
+ throw new TopiaException(message);
+ }
+ }
+
+ /* -------------------- GLOBAL OPERATIONS ON SCHEMA ----------------------*/
+
+ @Override
+ public <E extends TopiaEntity> E findByTopiaId(String id) throws TopiaException {
+ checkClosed(String.format("This context is closed, it is not possible to release the operation '%1$s'",
+ "findById"));
+
+ Class<E> entityClass = getTopiaIdFactory().getClassName(id);
+ TopiaDAO<E> dao = getDAO(entityClass);
+ E result = dao.findByTopiaId(id);
+ return result;
+ }
+
+ @Override
+ public <E> List<E> findAll(String jpaql, Object... propertyNamesAndValues) throws TopiaException {
+ checkClosed(String.format("This context is closed, it is not possible to release the operation '%1$s'",
+ "findAll"));
+
+ try {
+ Query query = getHibernate().createQuery(jpaql);
+ for (int j = 0; j < propertyNamesAndValues.length; j += 2) {
+ String name = (String) propertyNamesAndValues[j];
+ Object value = propertyNamesAndValues[j + 1];
+ if (value.getClass().isArray()) {
+ query.setParameterList(name, (Object[]) value);
+ } else if (value instanceof Collection<?>) {
+ query.setParameterList(name, (Collection<?>) value);
+ } else {
+ query.setParameter(name, value);
+ }
+ }
+ // tchemit 2010-11-30 reproduce the same behaviour than before with the dao legacy
+ if (useFlushMode) {
+ query.setFlushMode(FlushMode.AUTO);
+ }
+ List result = query.list();
+ result = firesSupport.fireEntitiesLoad(this, result);
+ return result;
+ } catch (HibernateException eee) {
+ throw new TopiaException(String.format("An error occurs while query operation: %1$s : %2$s",
+ jpaql, eee.getMessage()), eee);
+ }
+ }
+
+ @Override
+ public <E> List<E> find(String jpaql, int startIndex, int endIndex, Object... propertyNamesAndValues)
+ throws TopiaException {
+ checkClosed(String.format("This context is closed, it is not possible to release the operation '%1$s'",
+ "find"));
+
+ try {
+ Query query = getHibernate().createQuery(jpaql);
+ for (int j = 0; j < propertyNamesAndValues.length; j += 2) {
+ String name = (String) propertyNamesAndValues[j];
+ Object value = propertyNamesAndValues[j + 1];
+ if (value.getClass().isArray()) {
+ query.setParameterList(name, (Object[]) value);
+ } else if (value instanceof Collection<?>) {
+ query.setParameterList(name, (Collection<?>) value);
+ } else {
+ query.setParameter(name, value);
+ }
+ }
+ query.setFirstResult(startIndex);
+ query.setMaxResults(endIndex - startIndex + 1);
+ // tchemit 2010-11-30 reproduce the same behaviour than before with the dao legacy
+ if (useFlushMode) {
+ query.setFlushMode(FlushMode.AUTO);
+ }
+ List result = query.list();
+ result = firesSupport.fireEntitiesLoad(this, result);
+ return result;
+ } catch (HibernateException eee) {
+ throw new TopiaException(String.format("An error occurs while query operation: %1$s : %2$s",
+ jpaql, eee.getMessage()), eee);
+ }
+ }
+
+ @Override
+ public <E> E findUnique(String jpaql, Object... propertyNamesAndValues)
+ throws TopiaException {
+ checkClosed(String.format("This context is closed, it is not possible to release the operation '%1$s'",
+ "findUnique"));
+
+ List<E> results = find(jpaql, 0, 1, propertyNamesAndValues);
+
+ // If there is more than 1 result, throw an exception
+ if (results.size() > 1) {
+ String message = String.format(
+ "Query '%s' returns more than 1 unique result", jpaql);
+ throw new TopiaException(message);
+ }
+
+ // otherwise return the first one, or null
+ E result = null;
+ if (!results.isEmpty()) {
+ result = results.get(0);
+ }
+ return result;
+ }
+
+ /**
+ * Execute HQL operation on data (Update, Delete)
+ *
+ * @param jpaql HQL query
+ * @param propertyNamesAndValues arguments for query
+ * @return The number of entities updated or deleted.
+ * @throws TopiaException
+ */
+ @Override
+ public int execute(String jpaql, Object... propertyNamesAndValues) throws TopiaException {
+ checkClosed(String.format("This context is closed, it is not possible to release the operation '%1$s'",
+ "find"));
+
+ try {
+ Query query = getHibernate().createQuery(jpaql);
+ for (int j = 0; j < propertyNamesAndValues.length; j += 2) {
+ query.setParameter((String) propertyNamesAndValues[j], propertyNamesAndValues[j + 1]);
+ }
+ int result = query.executeUpdate();
+ return result;
+ } catch (HibernateException eee) {
+ throw new TopiaException(String.format("An error occurs while query operation: %1$s : %2$s",
+ jpaql, eee.getMessage()), eee);
+ }
+ }
+
+ @Override
+ public void add(TopiaEntity e) throws TopiaException {
+ update(e);
+ }
+
+ @Override
+ public void replicate(TopiaContext dstCtxt, Object... entityAndCondition)
+ throws TopiaException, IllegalArgumentException {
+ checkClosed(String.format("This context is closed, it is not possible to release the operation '%1$s'",
+ "replicate"));
+
+ AbstractTopiaContext dstContextImpl = (AbstractTopiaContext) dstCtxt;
+ dstContextImpl.checkClosed(
+ String.format("This context is closed, it is not possible to release the operation '%1$s'",
+ "replicate"));
+
+ if (getRootContext().equals(dstContextImpl.getRootContext())) {
+ throw new IllegalArgumentException("Can not do a replication operation on same database.");
+ }
+
+ String[] queries = buildQueries(entityAndCondition);
+ try {
+ for (String query : queries) {
+ if (log.isDebugEnabled()) {
+ log.debug("acquire entities " + query);
+ }
+ // acquire data to replicate
+ List<?> entities = findAll(query);
+ replicate0(dstContextImpl, entities.toArray());
+ if (log.isDebugEnabled()) {
+ log.debug("replication of entities " + query +
+ " was sucessfully done.");
+ }
+ }
+ } catch (HibernateException eee) {
+ throw new TopiaException(String.format("An error occurs while a replication operation: %s",
+ eee.getMessage()), eee);
+ }
+ }
+
+ @Override
+ public <T extends TopiaEntity> void replicateEntity(TopiaContext dstCtxt,
+ T entity)
+ throws TopiaException, IllegalArgumentException {
+ checkClosed(String.format("This context is closed, it is not possible to release the operation '%1$s'",
+ "replicateEntity"));
+
+ AbstractTopiaContext dstContextImpl = (AbstractTopiaContext) dstCtxt;
+ dstContextImpl.checkClosed(String.format("This context is closed, it is not possible to release the operation '%1$s'",
+ "replicateEntity"));
+
+ if (getRootContext().equals(dstContextImpl.getRootContext())) {
+ throw new IllegalArgumentException("Can not do a replication operation on same database.");
+ }
+ replicate0(dstContextImpl, entity);
+ }
+
+ @Override
+ public <T extends TopiaEntity> void replicateEntities(TopiaContext dstCtxt,
+ List<T> entities)
+ throws TopiaException, IllegalArgumentException {
+ checkClosed(String.format("This context is closed, it is not possible to release the operation '%1$s'",
+ "replicateEntities"));
+
+ AbstractTopiaContext dstContextImpl = (AbstractTopiaContext) dstCtxt;
+ dstContextImpl.checkClosed(String.format("This context is closed, it is not possible to release the operation '%1$s'",
+ "replicateEntities"));
+
+ if (getRootContext().equals(dstContextImpl.getRootContext())) {
+ throw new IllegalArgumentException("Can not do a replication operation on same database.");
+ }
+ replicate0(dstContextImpl, entities.toArray());
+ }
+
+ @Override
+ public TopiaFiresSupport getFiresSupport() {
+ return firesSupport;
+ }
+
+ /**
+ * Backup database in gzip compressed file.
+ * <p/>
+ * <b>Note: </b> Only works for h2 database.
+ *
+ * @param file file to write backup
+ * @param compress if true then use gzip to compress file
+ * @see TopiaContext#backup(File, boolean)
+ */
+ @Override
+ public void backup(File file, boolean compress) throws TopiaException {
+ checkClosed(String.format("This context is closed, it is not possible to release the operation '%1$s'",
+ "backup"));
+ try {
+ String options = "";
+ if (compress) {
+ options += " COMPRESSION GZIP";
+ }
+
+ SQLQuery query = getHibernate().createSQLQuery(
+ "SCRIPT TO '" + file.getAbsolutePath() + "'" + options);
+ query.list();
+
+ } catch (Exception eee) {
+ throw new TopiaException(String.format(
+ "An error occurs while backup operation: %1$s",
+ eee.getMessage()), eee);
+ }
+ }
+
+ /**
+ * Read database from gzip compressed file
+ * <p/>
+ * Only work for h2 database
+ *
+ * @see TopiaContext#restore(File)
+ */
+ @Override
+ public void restore(File file) throws TopiaException {
+ // send event
+ getFiresSupport().firePreRestoreSchema(this);
+ checkClosed(String.format("This context is closed, it is not possible to release the operation '%1$s'",
+ "restore"));
+
+ String sql = null;
+ String options = "";
+ try {
+ // decompresse file in temporary file
+ InputStream in = new BufferedInputStream(new FileInputStream(file));
+ try {
+ in.mark(2);
+
+ // read header to see if is compressed file
+ int b = in.read();
+ // redundant cast : int magic = ((int) in.read() << 8) | b;
+ int magic = in.read() << 8 | b;
+ in.reset();
+
+ if (magic == GZIPInputStream.GZIP_MAGIC) {
+ options += " COMPRESSION GZIP";
+ }
+ } finally {
+
+ in.close();
+ }
+
+ SQLQuery query = getHibernate().createSQLQuery(
+ "RUNSCRIPT FROM '" + file.getAbsolutePath() + "'" + options);
+
+ query.executeUpdate();
+
+ // send event AFTER restore
+ getFiresSupport().firePostRestoreSchema(this);
+ } catch (Exception eee) {
+ throw new TopiaException(String.format(
+ String.format("An error occurs while restore operation: %1$s : %2$s",
+ sql, eee.getMessage())), eee);
+ }
+ }
+
+ /**
+ * Only h2 supported for now
+ *
+ * @see TopiaContext#clear(boolean)
+ */
+ @Override
+ public void clear(boolean dropDatabase) throws TopiaException {
+ try {
+ AbstractTopiaContext root = (AbstractTopiaContext) getRootContext();
+ AbstractTopiaContext tx = (AbstractTopiaContext) root.beginTransaction();
+
+ String sql = "DROP ALL OBJECTS";
+ if (dropDatabase) {
+ sql += " DELETE FILES";
+ }
+ Query query = tx.getHibernate().createSQLQuery(sql);
+ query.executeUpdate();
+ tx.closeContext();
+ root.finalize();
+ } catch (Throwable eee) {
+ throw new TopiaException(
+ String.format("Error %s on clear operation", eee.getMessage()), eee);
+ }
+ }
+
+ /**
+ * Clear hibernate cache to free memory.
+ * <p/>
+ * see http://docs.jboss.org/hibernate/orm/3.5/reference/en-US/html/transactions.h…
+ */
+ @Override
+ public void clearCache() throws TopiaException {
+ getHibernate().clear();
+ }
+
+ @Override
+ public List<Class<?>> getPersistenceClasses() {
+ return persistenceClasses;
+ }
+
+ @Override
+ public boolean isSchemaExist(Class<?> clazz)
+ throws TopiaException {
+ checkClosed(String.format("This context is closed, it is not possible to release the operation '%1$s'",
+ "replicateEntity"));
+ boolean result = TopiaUtil.isSchemaExist(this, clazz.getName());
+ return result;
+ }
+
+ /* Listeners adders */
+
+ @Override
+ public void addTopiaEntityListener(TopiaEntityListener listener) {
+ getFiresSupport().addTopiaEntityListener(listener);
+ }
+
+ @Override
+ public void addTopiaEntityListener(
+ Class<? extends TopiaEntity> entityClass,
+ TopiaEntityListener listener) {
+ getFiresSupport().addTopiaEntityListener(entityClass, listener);
+ }
+
+ @Override
+ public void addTopiaEntityVetoable(TopiaEntityVetoable vetoable) {
+ getFiresSupport().addTopiaEntityVetoable(TopiaEntity.class, vetoable);
+ }
+
+ @Override
+ public void addTopiaEntityVetoable(
+ Class<? extends TopiaEntity> entityClass,
+ TopiaEntityVetoable vetoable) {
+ getFiresSupport().addTopiaEntityVetoable(entityClass, vetoable);
+ }
+
+ @Override
+ public void addTopiaTransactionListener(TopiaTransactionListener listener) {
+ getFiresSupport().addTopiaTransactionListener(listener);
+ }
+
+ @Override
+ public void addTopiaTransactionVetoable(TopiaTransactionVetoable vetoable) {
+ getFiresSupport().addTopiaTransactionVetoable(vetoable);
+ }
+
+ @Override
+ public void addPropertyChangeListener(PropertyChangeListener listener) {
+ getFiresSupport().addPropertyChangeListener(listener);
+ }
+
+ @Override
+ @Deprecated
+ public void addTopiaContextListener(TopiaContextListener listener) {
+ getFiresSupport().addTopiaContextListener(listener);
+ }
+
+ @Override
+ public void addTopiaSchemaListener(TopiaSchemaListener listener) {
+ getFiresSupport().addTopiaSchemaListener(listener);
+ }
+
+ /* Listeners removers */
+
+ @Override
+ public void removeTopiaEntityListener(TopiaEntityListener listener) {
+ getFiresSupport().removeTopiaEntityListener(TopiaEntity.class,
+ listener);
+ }
+
+ @Override
+ public void removeTopiaEntityListener(
+ Class<? extends TopiaEntity> entityClass,
+ TopiaEntityListener listener) {
+ getFiresSupport().removeTopiaEntityListener(entityClass, listener);
+ }
+
+ @Override
+ public void removeTopiaEntityVetoable(TopiaEntityVetoable vetoable) {
+ getFiresSupport().removeTopiaEntityVetoable(TopiaEntity.class,
+ vetoable);
+ }
+
+ @Override
+ public void removeTopiaEntityVetoable(
+ Class<? extends TopiaEntity> entityClass,
+ TopiaEntityVetoable vetoable) {
+ getFiresSupport().removeTopiaEntityVetoable(entityClass, vetoable);
+ }
+
+ @Override
+ public void removeTopiaTransactionListener(
+ TopiaTransactionListener listener) {
+ getFiresSupport().removeTopiaTransactionListener(listener);
+ }
+
+ @Override
+ public void removeTopiaTransactionVetoable(
+ TopiaTransactionVetoable vetoable) {
+ getFiresSupport().removeTopiaTransactionVetoable(vetoable);
+ }
+
+ @Override
+ public void removePropertyChangeListener(PropertyChangeListener listener) {
+ getFiresSupport().removePropertyChangeListener(listener);
+ }
+
+ @Override
+ @Deprecated
+ public void removeTopiaContextListener(TopiaContextListener listener) {
+ getFiresSupport().removeTopiaContextListener(listener);
+ }
+
+ @Override
+ public void removeTopiaSchemaListener(TopiaSchemaListener listener) {
+ getFiresSupport().removeTopiaSchemaListener(listener);
+ }
+
+ @Override
+ public void addTopiaEntitiesVetoable(TopiaEntitiesVetoable vetoable) {
+ getFiresSupport().addTopiaEntitiesVetoable(vetoable);
+ }
+
+ @Override
+ public void removeTopiaEntitiesVetoable(TopiaEntitiesVetoable vetoable) {
+ getFiresSupport().removeTopiaEntitiesVetoable(vetoable);
+ }
+
+ /**
+ * Build the list of queries from the given parameter
+ * <code>entityAndCondition</code>.
+ * <p/>
+ * If no parameter is given, then build the queries for all entities is db,
+ * with no condition.
+ *
+ * @param entityAndCondition the list of tuples (Class,String)
+ * @return the list of queries.
+ * @throws TopiaException if any pb of db while getting entities
+ * classes.
+ * @throws IllegalArgumentException if any pb with the given parameter
+ * (mainly ClassCastException).
+ */
+ protected String[] buildQueries(Object... entityAndCondition)
+ throws TopiaException, IllegalArgumentException {
+ Class<?> entityClass;
+ String condition;
+
+ // si entityAndcondition est vide alors il faut le remplir
+ // avec toutes les entités du mapping (class, null)
+ if (entityAndCondition.length == 0) {
+ Map<?, ?> classMetadata = getHibernateFactory().getAllClassMetadata();
+ entityAndCondition = new Object[classMetadata.size() * 2];
+ int i = 0;
+ for (Object className : classMetadata.keySet()) {
+ try {
+ entityAndCondition[i++] = Class.forName((String) className);
+ } catch (ClassNotFoundException e) {
+ // should never happen!
+ throw new TopiaException(
+ "class cast exception for entity " + className);
+ }
+ entityAndCondition[i++] = null;
+
+ }
+ }
+
+ // prepare queries to perform beofre opening any transaction
+ if (entityAndCondition.length % 2 != 0) {
+ throw new IllegalArgumentException(
+ "entityAndCondition must be a couple of (Class, String)");
+ }
+ String queries[] = new String[entityAndCondition.length / 2];
+ for (int i = 0; i < entityAndCondition.length; ) {
+ try {
+ entityClass = (Class<?>) entityAndCondition[i++];
+ condition = (String) entityAndCondition[i++];
+ String query = "from " + entityClass.getName();
+ if (condition != null && !condition.isEmpty()) {
+ query += " where " + condition;
+ }
+ queries[(i - 1) / 2] = query;
+ } catch (ClassCastException e) {
+ if (i % 2 == 0) {
+ throw new IllegalArgumentException(
+ "Others arguement must be String not " +
+ entityAndCondition[i - 1], e);
+ } else {
+ throw new IllegalArgumentException(
+ "Others arguement must be Class not " +
+ entityAndCondition[i - 1], e);
+ }
+ }
+ }
+ return queries;
+ }
+
+ protected void replicate0(AbstractTopiaContext dstContextImpl,
+ Object... entities) throws TopiaException {
+ try {
+ for (Object entity : entities) {
+ // dettach entity to source session, to make possible copy of
+ // collection without a hibernate exception (list opened in
+ // two session...)
+ getHibernate().evict(entity);
+ dstContextImpl.getHibernate().replicate(entity,
+ ReplicationMode.EXCEPTION);
+ }
+
+ } catch (HibernateException eee) {
+ throw new TopiaException(String.format("An error occurs while a replication operation : %s",
+ eee.getMessage()), eee);
+ }
+ }
+
+ public static class SQLWork implements Work {
+ private final String script;
+
+ public SQLWork(String script) {
+ this.script = script;
+ }
+
+ @Override
+ public void execute(Connection connection) throws SQLException {
+ PreparedStatement sta = connection.prepareStatement(script);
+ try {
+ sta.execute();
+ } finally {
+ sta.close();
+ }
+ }
+ }
+
+ @Override
+ public Session getHibernateSession() throws TopiaException {
+ if (hibernate == null) {
+ throw new TopiaException("No hibernate session");
+ }
+ return hibernate;
+ }
+
+ @Override
+ public void update(TopiaEntity e) throws TopiaException {
+ checkClosed(String.format("This context is closed, it is not possible to release the operation '%1$s'",
+ "add"));
+
+ String id = e.getTopiaId();
+ Class<TopiaEntity> entityClass = getTopiaIdFactory().getClassName(id);
+ TopiaDAO<TopiaEntity> dao = getDAO(entityClass);
+ dao.update(e);
+ }
+
+} //AbstractTopiaContext
+
Deleted: trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaContextImpl.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaContextImpl.java 2013-08-02 16:21:12 UTC (rev 2785)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaContextImpl.java 2013-08-02 17:26:06 UTC (rev 2786)
@@ -1,1538 +0,0 @@
-/*
- * #%L
- * ToPIA :: Persistence
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2004 - 2013 CodeLutin, Chatellier Eric
- * %%
- * 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%
- */
-
-package org.nuiton.topia.framework;
-
-import java.beans.PropertyChangeListener;
-import java.io.BufferedInputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.InputStream;
-import java.lang.reflect.Field;
-import java.sql.Connection;
-import java.sql.PreparedStatement;
-import java.sql.SQLException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-import java.util.Set;
-import java.util.WeakHashMap;
-import java.util.zip.GZIPInputStream;
-
-import org.apache.commons.lang3.StringUtils;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.hibernate.FlushMode;
-import org.hibernate.HibernateException;
-import org.hibernate.Query;
-import org.hibernate.ReplicationMode;
-import org.hibernate.SQLQuery;
-import org.hibernate.Session;
-import org.hibernate.SessionFactory;
-import org.hibernate.Transaction;
-import org.hibernate.cfg.Configuration;
-import org.hibernate.engine.spi.SessionFactoryImplementor;
-import org.hibernate.event.service.spi.EventListenerRegistry;
-import org.hibernate.event.spi.EventType;
-import org.hibernate.jdbc.Work;
-import org.hibernate.service.ServiceRegistry;
-import org.hibernate.service.ServiceRegistryBuilder;
-import org.hibernate.service.jdbc.connections.spi.ConnectionProvider;
-import org.hibernate.service.spi.Stoppable;
-import org.hibernate.tool.hbm2ddl.SchemaExport;
-import org.hibernate.tool.hbm2ddl.SchemaUpdate;
-import org.nuiton.topia.TopiaContext;
-import org.nuiton.topia.TopiaContextFactory;
-import org.nuiton.topia.TopiaException;
-import org.nuiton.topia.TopiaNotFoundException;
-import org.nuiton.topia.event.TopiaContextListener;
-import org.nuiton.topia.event.TopiaEntitiesVetoable;
-import org.nuiton.topia.event.TopiaEntityListener;
-import org.nuiton.topia.event.TopiaEntityVetoable;
-import org.nuiton.topia.event.TopiaSchemaListener;
-import org.nuiton.topia.event.TopiaTransactionListener;
-import org.nuiton.topia.event.TopiaTransactionVetoable;
-import org.nuiton.topia.persistence.DefaultTopiaIdFactory;
-import org.nuiton.topia.persistence.TopiaDAO;
-import org.nuiton.topia.persistence.TopiaDAOImpl;
-import org.nuiton.topia.persistence.TopiaEntity;
-import org.nuiton.topia.persistence.TopiaIdFactory;
-
-/**
- * Le TopiaContextImpl est le point d'entre pour acceder aux donnees. Il est
- * configurer par un fichier de propriete
- * <p/>
- * List des proprietes disponible <dl> <dt> topia.persistence.properties.file
- * <dd> le fichier de propriété a utiliser pour configurer hibernate
- * <p/>
- * <dt> topia.persistence.directories <dd> la liste des repertoires contenant
- * les mappings hibernates (.hbm.xml) la liste de repertoire est separer par des
- * virgules ','
- * <p/>
- * <dt> topia.persistence.classes <dd> la liste des classes que doit géré
- * hibernate. On peut tres bien utiliser topia.persistence.directories pour un
- * ensemble d'entié du meme repertoire et topia.persistence.classes pour
- * d'autres classes </dl>
- * <p/>
- * TopiaContextImpl.java
- * <p/>
- * Created: 23 déc. 2005 16:58:50
- *
- * @author bpoussin <poussin(a)codelutin.com>
- * @author tchemit <chemit(a)codelutin.com>
- * @author fdesbois <desbois(a)codelutin.com>
- * @version $Id$
- */
-//TODO-fdesbois-20100507 : Need translation of javadoc.
-public class TopiaContextImpl implements TopiaContextImplementor {
-
- /**
- * to use log facility, just put in your code: log.info(\"...\");
- */
- private static final Log log = LogFactory.getLog(TopiaContextImpl.class);
-
- /**
- * Le pere de ce context, les contexts initaux n'ont pas de context pere
- */
- protected TopiaContextImplementor parentContext;
-
- /**
- * L'objet configuration utilisé pour la creation de la factory hibernate
- */
- protected Configuration hibernateConfiguration;
-
- /**
- * la factory permettant de recuperer la session hibernate. Seul les
- * TopiaContextImpl initiaux contiennent un hibernateFactory
- */
- protected SessionFactory hibernateFactory;
-
- /**
- * La session utilisé par le TopiaContextImpl
- */
- protected Session hibernate;
-
- /**
- * Indique si le contexte a ete ferme
- */
- protected boolean closed;
-
- /**
- * This flag permits to use (or not) the flush mode when doing queries.
- * <p/>
- * The normal usage is to says yes (that's why the default value is
- * {@code true}), in that case whebn doing queries (says in method
- * {@link #findAll(String, Object...)} or {@link #find(String, int, int, Object...)})
- * it will use the flush mode {@link FlushMode#AUTO}).
- * <p/>
- * But sometimes, when doing a lot of queries (for some imports for example),
- * we do NOT want the session to be flushed each time we do a find, then you
- * can set this flag to {@code false} using the method {@link #setUseFlushMode(boolean)}
- *
- * @since 2.5
- */
- protected boolean useFlushMode = true;
-
- /**
- * Propriete de configuration
- */
- protected Properties config;
-
- /**
- * Used to affect a new topiaId when create is called.
- *
- * @since 3.0
- */
- protected TopiaIdFactory topiaIdFactory;
-
- /**
- * cache des DAO deja chargé pour ce context
- */
- protected Map<Class<? extends TopiaEntity>,
- TopiaDAO<? extends TopiaEntity>> daoCache =
- new HashMap<Class<? extends TopiaEntity>,
- TopiaDAO<? extends TopiaEntity>>();
-
- /**
- * Set of child context created with {@link #beginTransaction()}. We are
- * listener on these context. A WeakHashMap is used to remove old context
- * automically when it's not used anymore. The {@link #finalize} method will
- * be executed when Garbage collector is called when reference is removed.
- * The set is synchronized in case of using multi-threading.
- *
- * @see Collections#synchronizedSet(Set)
- * @see Collections#newSetFromMap(Map)
- */
- protected final Set<TopiaContextImplementor> childContext =
- Collections.synchronizedSet(
- Collections.newSetFromMap(
- new WeakHashMap<TopiaContextImplementor, Boolean>()));
-
- /**
- * key: service name; value: service instance
- */
- protected Map<String, TopiaService> services;
-
- protected TopiaFiresSupport firesSupport = new TopiaFiresSupport();
-
- /**
- * Liste des classes perssitance
- */
- protected List<Class<?>> persistenceClasses = new ArrayList<Class<?>>();
-
- /**
- * Default constructor, useful for tests.
- */
- protected TopiaContextImpl() {
-
- }
-
- /**
- * Constructor used by {@link TopiaContextFactory} to initialize rootContext
- * using {@code config}.
- *
- * @param config for the new root context
- * @throws TopiaNotFoundException if one of persistent class from
- * configuration is not found
- */
- public TopiaContextImpl(Properties config) throws TopiaNotFoundException {
- this.config = config;
- initTopiaIdFactory();
- services = loadServices(config);
- preInitServices(services);
- getHibernateConfiguration(); // force mapping loading
- postInitServices(services);
- }
-
- protected void initTopiaIdFactory() {
- String configTopiaIdFactoryClassName =
- getConfig().getProperty(TopiaContextFactory.CONFIG_PERSISTENCE_TOPIA_ID_FACTORY_CLASS_NAME, "");
- if (StringUtils.isEmpty(configTopiaIdFactoryClassName)) {
- topiaIdFactory = new DefaultTopiaIdFactory();
- } else {
- try {
- Class configPersistenceTopiaIdFactoryClass =
- Class.forName(configTopiaIdFactoryClassName);
- if (TopiaIdFactory.class.isAssignableFrom(configPersistenceTopiaIdFactoryClass)) {
- topiaIdFactory = (TopiaIdFactory) configPersistenceTopiaIdFactoryClass.newInstance();
- } else {
- throw new IllegalArgumentException(
- configTopiaIdFactoryClassName + " is not a valid class name. The class must implements "
- + TopiaIdFactory.class.getSimpleName());
- }
- } catch (ClassNotFoundException e) {
- throw new TopiaException(e);
- } catch (InstantiationException e) {
- throw new TopiaException(e);
- } catch (IllegalAccessException e) {
- throw new TopiaException(e);
- }
- }
- }
-
- protected String getProperExceptionMessage(Throwable eee) {
- return eee.getClass().getSimpleName() + " : " +
- eee.getMessage();
- }
-
- /* -------------------- SERVICES MANAGMENT -------------------------------*/
-
- protected Map<String, TopiaService> loadServices(Properties config) {
- Map<String, TopiaService> result = new HashMap<String, TopiaService>();
- // recherche des services present dans la config
- for (Enumeration<?> e = config.propertyNames(); e.hasMoreElements(); ) {
- String key = (String) e.nextElement();
- if (key.matches("^topia\\.service\\.\\w+$")) {
- String classService = config.getProperty(key);
- try {
- Class<?> forName = Class.forName(classService);
- Object newInstance = forName.getConstructor().newInstance();
- TopiaService service = (TopiaService) newInstance;
- if (key.equals("topia.service." + service.getServiceName())) {
- result.put(service.getServiceName(), service);
- log.info(String.format("Service '%1$s' loaded (implementation %2$s)",
- key, classService));
- } else {
- log.warn(String.format("The service with key '%1$s' has a different name '%2$s'! (service not activated)",
- key, service.getServiceName()));
- }
- } catch (Throwable eee) {
- String message =
- String.format("The service %1$s of type %2$s was not found.",
- key, classService);
- if (log.isDebugEnabled()) {
- log.debug(message, eee);
- } else if (log.isErrorEnabled()) {
- log.error(message);
- }
- }
- }
- }
- return result;
- }
-
- protected void preInitServices(Map<String, TopiaService> services) {
- for (TopiaService service : services.values()) {
- if (!service.preInit(this)) {
- log.warn(String.format("The service named '%1$s' could not be post-initialized (service not activated)",
- service.getServiceName()));
- }
- }
- }
-
- protected void postInitServices(Map<String, TopiaService> services) {
- for (TopiaService service : services.values()) {
- if (!service.postInit(this)) {
- log.warn(String.format("The service named '%1$s' could not be pre-initialized (service not activated)",
- service.getServiceName()));
- }
- }
- }
-
- protected TopiaService getService(String name) {
- TopiaService result = getServices().get(name);
- return result;
- }
-
- protected boolean serviceEnabled(String name) {
- boolean result = getServices().containsKey(name);
- return result;
- }
-
- /**
- * Retrieve service name using SERVICE_NAME static field on service
- * interface.
- *
- * @param interfaceService class of the service
- * @param <E> type of the service that extends {@link
- * TopiaService}
- * @return the service name
- * @throws IllegalAccessException if field SERVICE_NAME can't be accessed
- * @throws NoSuchFieldException if no field SERVICE_NAME is defined
- */
- protected <E extends TopiaService> String getServiceName(
- Class<E> interfaceService)
- throws IllegalAccessException, NoSuchFieldException {
- Field f = interfaceService.getField("SERVICE_NAME");
- String name = (String) f.get(null);
- return name;
- }
-
- @Override
- public Map<String, TopiaService> getServices() {
- TopiaContextImplementor parent = getParentContext();
-
- Map<String, TopiaService> result;
- if (parent != null) {
- result = parent.getServices();
- } else {
- result = services;
- }
- return result;
- }
-
- /**
- * Take one service, this service must be valid service interface with
- * public static final SERVICE_NAME declaration.
- *
- * @param <E> type of the service that extends {@link TopiaService}
- * @throws TopiaNotFoundException if an error appears or service not found.
- * @see #getServiceName(Class)
- */
- @Override
- public <E extends TopiaService> E getService(Class<E> interfaceService)
- throws TopiaNotFoundException {
- E result;
- try {
- String name = getServiceName(interfaceService);
- result = (E) getService(name);
- } catch (Exception eee) {
- throw new TopiaNotFoundException(
- String.format("Could not retreave service %1$s for following reason: %2$s",
- interfaceService, getProperExceptionMessage(eee)),
- eee);
- }
- if (result == null) {
- throw new TopiaNotFoundException(
- String.format("The service %1$s was not found.",
- interfaceService));
- }
- return result;
- }
-
- @Override
- public <E extends TopiaService> boolean serviceEnabled(
- Class<E> interfaceService) {
- boolean result = false;
- try {
- String name = getServiceName(interfaceService);
- result = serviceEnabled(name);
- } catch (Exception eee) {
- String message = String.format("The service named '%1$s' could not be found for following reason: %2$s",
- interfaceService, getProperExceptionMessage(eee));
- if (log.isDebugEnabled()) {
- log.debug(message, eee);
- } else if (log.isWarnEnabled()) {
- log.warn(message);
- }
- }
- return result;
- }
-
- /* -------------------- CONTEXT HIERARCHY MANAGMENT ----------------------*/
-
- /**
- * Constructor used by {@link #beginTransaction()} to instantiate child from
- * {@code parentContext}.
- *
- * @param parentContext context parent of the new TopiaContext child
- */
- protected TopiaContextImpl(TopiaContextImplementor parentContext) {
- this.parentContext = parentContext;
- }
-
- @Override
- public Set<TopiaContextImplementor> getChildContext() {
- // fdesbois-20100421 : Ano #546
- // Copy the childContext into a new set
- Set<TopiaContextImplementor> values;
- // Synchronize copy to be thread-safe during iteration
- synchronized (childContext) {
- values = new HashSet<TopiaContextImplementor>(childContext);
- }
- return values;
- }
-
- protected void addChildContext(TopiaContextImplementor child) {
- childContext.add(child);
- }
-
- @Override
- public void removeChildContext(TopiaContextImplementor child) {
- // Remove child only if this context is not already closed.
- if (!closed) {
- childContext.remove(child);
- }
- }
-
- @Override
- public TopiaContextImplementor getParentContext() {
- return parentContext;
- }
-
- @Override
- public TopiaContextImplementor getRootContext() {
- TopiaContextImplementor result = this;
- if (getParentContext() != null) {
- result = getParentContext().getRootContext();
- }
- return result;
- }
-
- @Override
- public Properties getConfig() {
- if (config == null && getParentContext() != null) {
- config = getParentContext().getConfig();
- }
- return config;
- }
-
- @Override
- public TopiaIdFactory getTopiaIdFactory() {
- if (topiaIdFactory == null) {
- initTopiaIdFactory();
- }
- return topiaIdFactory;
- }
-
- /**
- * Change the value of flag {@link #useFlushMode}.
- *
- * @param useFlushMode the new value to set
- * @see #useFlushMode
- * @since 2.5
- */
- public void setUseFlushMode(boolean useFlushMode) {
- this.useFlushMode = useFlushMode;
- }
-
- /* -------------------- HIBERNATE MANAGMENT -----------------------------*/
-
- @Override
- public void createSchema() throws TopiaException {
- try {
- boolean showSchema = false;
- if (log.isDebugEnabled()) {
- showSchema = true;
- }
- getFiresSupport().firePreCreateSchema(this);
- new SchemaExport(getHibernateConfiguration()).execute(showSchema, true, false, true);
- getFiresSupport().firePostCreateSchema(this);
- } catch (HibernateException eee) {
- throw new TopiaException(
- String.format("Could not create schema for reason: %s",
- eee.getMessage()), eee);
- }
- }
-
- @Override
- public void showCreateSchema() throws TopiaException {
- try {
- new SchemaExport(getHibernateConfiguration()).
- execute(true, false, false, true);
- } catch (HibernateException eee) {
- throw new TopiaException(
- String.format("Could not show create schema for reason: %s",
- eee.getMessage()), eee);
- }
- }
-
- @Override
- public void updateSchema() throws TopiaException {
- try {
- boolean showSchema = false;
- if (log.isDebugEnabled()) {
- showSchema = true;
- }
- getFiresSupport().firePreUpdateSchema(this);
- new SchemaUpdate(getHibernateConfiguration()).execute(showSchema,
- true);
- getFiresSupport().firePostUpdateSchema(this);
- } catch (HibernateException eee) {
- throw new TopiaException(
- String.format("Could not update schema for reason: %s",
- eee.getMessage()), eee);
- }
- }
-
- @Override
- public void dropSchema() throws TopiaException {
- try {
- boolean showSchema = false;
- if (log.isDebugEnabled()) {
- showSchema = true;
- }
- getFiresSupport().firePreDropSchema(this);
- new SchemaExport(getHibernateConfiguration()).execute(showSchema, true, true, false);
- getFiresSupport().firePostDropSchema(this);
- } catch (HibernateException eee) {
- throw new TopiaException(
- String.format("Could not drop schema for reason: %s",
- eee.getMessage()), eee);
- }
- }
-
- @Override
- public Session getHibernate() throws TopiaException {
- Session result = getHibernateSession();
- return result;
- }
-
- @Override
- public SessionFactory getHibernateFactory() throws TopiaNotFoundException {
- if (hibernateFactory == null) {
- if (getParentContext() != null) {
- hibernateFactory = getParentContext().getHibernateFactory();
- } else {
-
- // init service registry
- ServiceRegistry serviceRegistry = new ServiceRegistryBuilder().applySettings(
- getHibernateConfiguration().getProperties()).buildServiceRegistry();
-
- hibernateFactory = getHibernateConfiguration().buildSessionFactory(serviceRegistry);
-
- // we can't reuse original serviceRegistry instance
- // we must call getServiceRegistry on factory to get a working one
- ServiceRegistry serviceRegistryInit = ((SessionFactoryImplementor) hibernateFactory).getServiceRegistry();
- EventListenerRegistry eventListenerRegistry = serviceRegistryInit.getService(EventListenerRegistry.class);
- TopiaFiresSupport.TopiaHibernateEvent listener = new TopiaFiresSupport.TopiaHibernateEvent(this);
- eventListenerRegistry.appendListeners(EventType.PRE_INSERT, listener);
- eventListenerRegistry.appendListeners(EventType.PRE_LOAD, listener);
- eventListenerRegistry.appendListeners(EventType.PRE_UPDATE, listener);
- eventListenerRegistry.appendListeners(EventType.PRE_DELETE, listener);
- eventListenerRegistry.appendListeners(EventType.POST_INSERT, listener);
- eventListenerRegistry.appendListeners(EventType.POST_LOAD, listener);
- eventListenerRegistry.appendListeners(EventType.POST_UPDATE, listener);
- eventListenerRegistry.appendListeners(EventType.POST_DELETE, listener);
-
- // following listeners must be called before hibernate
- eventListenerRegistry.prependListeners(EventType.SAVE_UPDATE, listener);
- }
- }
- return hibernateFactory;
- }
-
- @Override
- public Configuration getHibernateConfiguration()
- throws TopiaNotFoundException {
- if (hibernateConfiguration == null) {
- if (getParentContext() != null) {
- hibernateConfiguration = getParentContext().getHibernateConfiguration();
- } else {
- hibernateConfiguration = new Configuration();
-
- // ajout des repertoires contenant les mappings hibernate
- String[] dirs = getConfig().getProperty(
- TopiaContextFactory.CONFIG_PERSISTENCE_DIRECTORIES, "").split(",");
- for (String dir : dirs) {
- dir = dir.trim();
- if (StringUtils.isNotEmpty(dir)) {
- if (log.isDebugEnabled()) {
- log.debug("Load persistence from dir : " + dir);
- }
- hibernateConfiguration.addDirectory(new File(dir));
- }
- }
-
- // ajout des classes dites persistentes
- Set<Class<?>> hibernatePersistanceClasses = new HashSet<Class<?>>();
- for (TopiaService service : getServices().values()) {
- Class<?>[] classes = service.getPersistenceClasses();
-
- // certains service n'ont pas de classe persistantes
- if (classes != null) {
- // sletellier 20110411 : http://www.nuiton.org/issues/show/1454
- hibernatePersistanceClasses.addAll(Arrays.asList(classes));
-// for (Class<?> clazz : classes) {
-// hibernateConfiguration.addClass(clazz);
-// }
- }
- }
-
- String listPersistenceClasses = getConfig().getProperty(
- TopiaContextFactory.CONFIG_PERSISTENCE_CLASSES, "");
-
- String[] classes = listPersistenceClasses.split(",");
- for (String classname : classes) {
- classname = classname.trim();
- if (StringUtils.isNotEmpty(classname)) {
- if (log.isDebugEnabled()) {
- log.debug("Load persistent class : " + classname);
- }
-
- // XXX echatellier 20111007 ce cqui est dommage ici, c'est
- // la definition de cette classe ne sert a rien (apart security)
- // car pour hibernate hibernateConfiguration.addClass(persistanceClass)
- // il ne se sert pas de la classe en fait et fait seulement
- // un classname.replace( '.', '/' ) + ".hbm.xml";
- // pour obtenir le mapping et la reinstancier ensuite
-
- Class<?> clazz;
- try {
- clazz = Class.forName(classname);
- } catch (ClassNotFoundException eee) {
- if (log.isDebugEnabled()) {
- log.debug("Class " + classname + " not found");
- }
- throw new TopiaNotFoundException(
- String.format("Persistence class %1$s not found",
- classname));
- }
- persistenceClasses.add(clazz);
-
- // sletellier 20110411 : http://www.nuiton.org/issues/show/1454
-// hibernateConfiguration.addClass(clazz);
- hibernatePersistanceClasses.add(clazz);
- }
- }
-
- // sletellier 20110411 : http://www.nuiton.org/issues/show/1454
- // Add persistance classes in hibernate config
- for (Class<?> persistanceClass : hibernatePersistanceClasses) {
- hibernateConfiguration.addClass(persistanceClass);
- }
-
- Properties prop = new Properties();
- prop.putAll(hibernateConfiguration.getProperties());
- prop.putAll(getConfig());
-
- // Strange behavior, all properties are already loaded from
- // constructor. Difficult to use this behavior, need to have
- // TOPIA_PERSISTENCE_PROPERTIES_FILE in config.
- Properties propertiesFromClasspath =
- TopiaUtil.getProperties(getConfig().
- getProperty(TopiaContextFactory.CONFIG_PERSISTENCE_PROPERTIES_FILE));
-
- if (!propertiesFromClasspath.isEmpty()) {
- if (log.isDebugEnabled()) {
- log.debug("Load properties from file : " +
- propertiesFromClasspath);
- }
- prop.putAll(propertiesFromClasspath);
- }
-
- hibernateConfiguration.setProperties(prop);
-
- // tchemit 2011-05-26 When using hibernate > 3.3, need to make sure all mappings are loaded (the one from directory files are not still done).
- hibernateConfiguration.buildMappings();
- }
- }
- return hibernateConfiguration;
- }
-
- /* -------------------- CHILD CONTEXT AND DAOS --------------------------*/
-
- @SuppressWarnings({"unchecked"})
- @Override
- public <E extends TopiaEntity> TopiaDAO<E> getDAO(Class<E> entityClass)
- throws TopiaException {
- if (entityClass == null) {
- throw new IllegalArgumentException(
- String.format("The method '%1$s' requires a non null parameter '%2$s'.",
- "entityClass", "getDAO"));
- }
- if (equals(getRootContext())) {
- throw new TopiaException(
- "You are on root context, you MUST open a transaction to perform any database access.");
- }
- if (getHibernateFactory().getClassMetadata(entityClass) == null &&
- getHibernateFactory().getClassMetadata(
- entityClass.getName() + "Impl") == null &&
- getHibernateFactory().getClassMetadata(
- entityClass.getName() + "Abstract") == null) {
-
- log.info(String.format("List of supported persistence classes: %1$s",
- getHibernateFactory().getAllClassMetadata().keySet()));
- throw new TopiaException(
- String.format("The following entity type %1$s is not managed by this context, you probably forgot to declare it.",
- entityClass.getName()));
- }
-
- TopiaDAO<E> result = (TopiaDAO<E>) daoCache.get(entityClass);
- if (result == null) {
-
- // looking for specialized DAO
- // normalement il en existe un car il est généré automatiquement
- // si on utilise la génération
- String daoClassname = entityClass.getName() + "DAO";
- try {
- Class<TopiaDAO<E>> daoClass =
- (Class<TopiaDAO<E>>) Class.forName(daoClassname);
- TopiaDAO<E> spe = daoClass.getConstructor().newInstance();
- result = spe;
- } catch (Exception eee) {
- log.warn("specialized DAO " + daoClassname +
- " not found, use default TopiaDAOHibernate");
- result = new TopiaDAOImpl<E>();
- }
-
- result.init(this, entityClass);
- daoCache.put(entityClass, result);
- }
- return result;
- }
-
- @SuppressWarnings({"unchecked"})
- @Override
- public <E extends TopiaEntity, D extends TopiaDAO<E>> D getDAO(Class<E> entityClass,
- Class<D> daoClass) throws TopiaException {
- return (D) getDAO(entityClass);
- }
-
- @Override
- public TopiaContext beginTransaction() throws TopiaException {
- checkClosed("Context is closed, no operation is possible.");
- TopiaContextImpl result = new TopiaContextImpl(this);
-
- SessionFactory factory = getHibernateFactory();
- result.hibernate = factory.openSession();
-
- // new TopiaInterceptor(result));
- // on ne synchronise jamais les données avec la base tant que
- // l'utilisateur n'a pas fait de commit du context
- result.hibernate.setFlushMode(FlushMode.MANUAL);
-
- // tchemit 2010-12-06 propagates the value of the flag
- result.useFlushMode = useFlushMode;
-
- // 20060926 poussin ajouter pour voir si ca regle les problemes de
- // deadlock h2. Conclusion, il faut bien ouvrir une transaction
- // maintenant, sinon lorsque l'on fait des acces a la base, une
- // transaction par defaut est utilisé mais elle n'est jamais vraiment
- // fermé ce qui pose des problemes de lock sur les tables.
- try {
- result.hibernate.beginTransaction();
- } catch (Exception eee) {
-
- // on a pas pu ouvrir la transaction, on faut donc tout fermer
- // et declancher une exception
- try {
- result.hibernate.close();
- } catch (HibernateException e1) {
- if (log.isErrorEnabled()) {
- log.error("Could not close hibernate session", e1);
- }
- }
-
- throw new TopiaException(
- String.format("An error occurs while asking a new transaction: %1$s",
- eee.getMessage()),
- eee);
- }
-
- // 20081217 : add child AFTER hibernate session is opened
- addChildContext(result);
-
- // fire event
- getFiresSupport().fireOnBeginTransaction(result);
- return result;
- }
-
- @Override
- public void commitTransaction() throws TopiaException {
- if (equals(getRootContext())) {
- throw new TopiaException(String.format("Unsupported operation %s on root context",
- "commit"));
- }
- checkClosed(String.format("This context is closed, it is not possible to release the operation '%1$s'",
- "commit"));
-
- try {
-// for (TopiaDAO<? extends TopiaEntity> dao : daoCache.values()) {
-// // TODO-fdesbois-20100507 : need to be removed for 2.5 version
-// dao.commitTransaction();
-// }
- Transaction tx = hibernate.getTransaction();
- // Transaction tx = hibernate.beginTransaction();
- hibernate.flush();
- tx.commit();
-
- getFiresSupport().fireOnPostCommit(this);
- TopiaContextImplementor parent = getParentContext();
- if (parent != null) {
- parent.getFiresSupport().fireOnPostCommit(this);
- }
-
- hibernate.beginTransaction();
-
- // it's seem necessary to change session after commit
- // NON, NON, NON, il ne faut surtout pas le faire, ca pose plein de
- // probleme
- // hibernate = getHibernateFactory().openSession();
- // hibernate.setFlushMode(FlushMode.NEVER);
- } catch (Exception eee) {
- throw new TopiaException(String.format("An error occurs while commit operation: %1$s",
- eee.getMessage()), eee);
- }
- }
-
- @Override
- public void rollbackTransaction() throws TopiaException {
- if (equals(getRootContext())) {
- throw new TopiaException(String.format("Unsupported operation %s on root context",
- "rollback"));
- }
- checkClosed(String.format("This context is closed, it is not possible to release the operation '%1$s'",
- "rollback"));
- try {
-// for (TopiaDAO<? extends TopiaEntity> dao : daoCache.values()) {
-// // TODO-fdesbois-20100507 : need to be removed for 2.5 version
-// dao.rollbackTransaction();
-// }
- Transaction tx = hibernate.getTransaction();
- // Transaction tx = hibernate.beginTransaction();
- hibernate.clear();
- tx.rollback();
- hibernate.close();
- // it's very important to change the session after rollback
- // otherwize there are many error during next Entity's modification
- hibernate = getHibernateFactory().openSession();
- hibernate.setFlushMode(FlushMode.MANUAL);
-
- hibernate.beginTransaction();
-
- getFiresSupport().fireOnPostRollback(this);
- TopiaContextImplementor parent = getParentContext();
- if (parent != null) {
- parent.getFiresSupport().fireOnPostRollback(this);
- }
-
- } catch (HibernateException eee) {
- throw new TopiaException(
- String.format("An error occurs while rollback operation: %1$s",
- eee.getMessage()), eee);
- }
- }
-
- @Override
- public void closeContext() throws TopiaException {
- // Throw exception if context is already closed
- checkClosed("Context was already closed");
-
- // FD-20100421 : Ano #546 : no need to copy childContext, the
- // {@link #getChildContext()} provides a thread-safe copy to iterate
- // on it.
-// TopiaContextImplementor[] children = childContext.toArray(
-// new TopiaContextImplementor[childContext.size()]);
-
- // Remove all children context
- for (TopiaContextImplementor child : getChildContext()) {
- // Avoid to have exception from checkClosed method on child
- if (!child.isClosed()) {
- child.closeContext();
- }
- }
-
- // on se desenregistre du context pere et on ferme les connexions si
- // on est pas le root context
- if (!equals(getRootContext())) {
- closed = true;
- hibernate.close();
- getParentContext().removeChildContext(this);
- } else {
- if (hibernateFactory != null) {
- hibernateFactory.close();
- // close connection provider if possible (http://nuiton.org/issues/2757)
- ConnectionProvider service = ((SessionFactoryImplementor) hibernateFactory).getServiceRegistry().getService(ConnectionProvider.class);
- if (service instanceof Stoppable) {
- Stoppable stoppable = (Stoppable) service;
- stoppable.stop();
- }
- closed = true;
- TopiaContextFactory.removeContext(this);
- log.debug("TopiaContext removed");
- }
- }
- }
-
- /**
- * Pour le context root on ferme tous les fils, et la factory hibernate.
- */
- @Override
- protected void finalize() throws Throwable {
- if (hibernateFactory != null) {
- closeContext();
- hibernateFactory.close();
- closed = true;
- log.debug("TopiaContext finalized");
- }
- }
-
- @Override
- public boolean isClosed() {
- return closed;
- }
-
- @Override
- public void executeSQL(String sqlScript) throws TopiaException {
- SQLWork sqlWork = new SQLWork(sqlScript);
- try {
- getHibernate().doWork(sqlWork);
- } catch (HibernateException e) {
- throw new TopiaException("Could not execute sql code", e);
- }
- }
-
- protected void checkClosed(String message) throws TopiaException {
- if (closed) {
- throw new TopiaException(message);
- }
- }
-
- /* -------------------- GLOBAL OPERATIONS ON SCHEMA ----------------------*/
-
- @Override
- public <E extends TopiaEntity> E findByTopiaId(String id) throws TopiaException {
- checkClosed(String.format("This context is closed, it is not possible to release the operation '%1$s'",
- "findById"));
-
- Class<E> entityClass = getTopiaIdFactory().getClassName(id);
- TopiaDAO<E> dao = getDAO(entityClass);
- E result = dao.findByTopiaId(id);
- return result;
- }
-
- @Override
- public <E> List<E> findAll(String jpaql, Object... propertyNamesAndValues) throws TopiaException {
- checkClosed(String.format("This context is closed, it is not possible to release the operation '%1$s'",
- "findAll"));
-
- try {
- Query query = getHibernate().createQuery(jpaql);
- for (int j = 0; j < propertyNamesAndValues.length; j += 2) {
- String name = (String) propertyNamesAndValues[j];
- Object value = propertyNamesAndValues[j + 1];
- if (value.getClass().isArray()) {
- query.setParameterList(name, (Object[]) value);
- } else if (value instanceof Collection<?>) {
- query.setParameterList(name, (Collection<?>) value);
- } else {
- query.setParameter(name, value);
- }
- }
- // tchemit 2010-11-30 reproduce the same behaviour than before with the dao legacy
- if (useFlushMode) {
- query.setFlushMode(FlushMode.AUTO);
- }
- List result = query.list();
- result = firesSupport.fireEntitiesLoad(this, result);
- return result;
- } catch (HibernateException eee) {
- throw new TopiaException(String.format("An error occurs while query operation: %1$s : %2$s",
- jpaql, eee.getMessage()), eee);
- }
- }
-
- @Override
- public <E> List<E> find(String jpaql, int startIndex, int endIndex, Object... propertyNamesAndValues)
- throws TopiaException {
- checkClosed(String.format("This context is closed, it is not possible to release the operation '%1$s'",
- "find"));
-
- try {
- Query query = getHibernate().createQuery(jpaql);
- for (int j = 0; j < propertyNamesAndValues.length; j += 2) {
- String name = (String) propertyNamesAndValues[j];
- Object value = propertyNamesAndValues[j + 1];
- if (value.getClass().isArray()) {
- query.setParameterList(name, (Object[]) value);
- } else if (value instanceof Collection<?>) {
- query.setParameterList(name, (Collection<?>) value);
- } else {
- query.setParameter(name, value);
- }
- }
- query.setFirstResult(startIndex);
- query.setMaxResults(endIndex - startIndex + 1);
- // tchemit 2010-11-30 reproduce the same behaviour than before with the dao legacy
- if (useFlushMode) {
- query.setFlushMode(FlushMode.AUTO);
- }
- List result = query.list();
- result = firesSupport.fireEntitiesLoad(this, result);
- return result;
- } catch (HibernateException eee) {
- throw new TopiaException(String.format("An error occurs while query operation: %1$s : %2$s",
- jpaql, eee.getMessage()), eee);
- }
- }
-
- @Override
- public <E> E findUnique(String jpaql, Object... propertyNamesAndValues)
- throws TopiaException {
- checkClosed(String.format("This context is closed, it is not possible to release the operation '%1$s'",
- "findUnique"));
-
- List<E> results = find(jpaql, 0, 1, propertyNamesAndValues);
-
- // If there is more than 1 result, throw an exception
- if (results.size() > 1) {
- String message = String.format(
- "Query '%s' returns more than 1 unique result", jpaql);
- throw new TopiaException(message);
- }
-
- // otherwise return the first one, or null
- E result = null;
- if (!results.isEmpty()) {
- result = results.get(0);
- }
- return result;
- }
-
- /**
- * Execute HQL operation on data (Update, Delete)
- *
- * @param jpaql HQL query
- * @param propertyNamesAndValues arguments for query
- * @return The number of entities updated or deleted.
- * @throws TopiaException
- */
- @Override
- public int execute(String jpaql, Object... propertyNamesAndValues) throws TopiaException {
- checkClosed(String.format("This context is closed, it is not possible to release the operation '%1$s'",
- "find"));
-
- try {
- Query query = getHibernate().createQuery(jpaql);
- for (int j = 0; j < propertyNamesAndValues.length; j += 2) {
- query.setParameter((String) propertyNamesAndValues[j], propertyNamesAndValues[j + 1]);
- }
- int result = query.executeUpdate();
- return result;
- } catch (HibernateException eee) {
- throw new TopiaException(String.format("An error occurs while query operation: %1$s : %2$s",
- jpaql, eee.getMessage()), eee);
- }
- }
-
- @Override
- public void add(TopiaEntity e) throws TopiaException {
- update(e);
- }
-
- @Override
- public void replicate(TopiaContext dstCtxt, Object... entityAndCondition)
- throws TopiaException, IllegalArgumentException {
- checkClosed(String.format("This context is closed, it is not possible to release the operation '%1$s'",
- "replicate"));
-
- TopiaContextImpl dstContextImpl = (TopiaContextImpl) dstCtxt;
- dstContextImpl.checkClosed(
- String.format("This context is closed, it is not possible to release the operation '%1$s'",
- "replicate"));
-
- if (getRootContext().equals(dstContextImpl.getRootContext())) {
- throw new IllegalArgumentException("Can not do a replication operation on same database.");
- }
-
- String[] queries = buildQueries(entityAndCondition);
- try {
- for (String query : queries) {
- if (log.isDebugEnabled()) {
- log.debug("acquire entities " + query);
- }
- // acquire data to replicate
- List<?> entities = findAll(query);
- replicate0(dstContextImpl, entities.toArray());
- if (log.isDebugEnabled()) {
- log.debug("replication of entities " + query +
- " was sucessfully done.");
- }
- }
- } catch (HibernateException eee) {
- throw new TopiaException(String.format("An error occurs while a replication operation: %s",
- eee.getMessage()), eee);
- }
- }
-
- @Override
- public <T extends TopiaEntity> void replicateEntity(TopiaContext dstCtxt,
- T entity)
- throws TopiaException, IllegalArgumentException {
- checkClosed(String.format("This context is closed, it is not possible to release the operation '%1$s'",
- "replicateEntity"));
-
- TopiaContextImpl dstContextImpl = (TopiaContextImpl) dstCtxt;
- dstContextImpl.checkClosed(String.format("This context is closed, it is not possible to release the operation '%1$s'",
- "replicateEntity"));
-
- if (getRootContext().equals(dstContextImpl.getRootContext())) {
- throw new IllegalArgumentException("Can not do a replication operation on same database.");
- }
- replicate0(dstContextImpl, entity);
- }
-
- @Override
- public <T extends TopiaEntity> void replicateEntities(TopiaContext dstCtxt,
- List<T> entities)
- throws TopiaException, IllegalArgumentException {
- checkClosed(String.format("This context is closed, it is not possible to release the operation '%1$s'",
- "replicateEntities"));
-
- TopiaContextImpl dstContextImpl = (TopiaContextImpl) dstCtxt;
- dstContextImpl.checkClosed(String.format("This context is closed, it is not possible to release the operation '%1$s'",
- "replicateEntities"));
-
- if (getRootContext().equals(dstContextImpl.getRootContext())) {
- throw new IllegalArgumentException("Can not do a replication operation on same database.");
- }
- replicate0(dstContextImpl, entities.toArray());
- }
-
- @Override
- public TopiaFiresSupport getFiresSupport() {
- return firesSupport;
- }
-
- /**
- * Backup database in gzip compressed file.
- * <p/>
- * <b>Note: </b> Only works for h2 database.
- *
- * @param file file to write backup
- * @param compress if true then use gzip to compress file
- * @see TopiaContext#backup(File, boolean)
- */
- @Override
- public void backup(File file, boolean compress) throws TopiaException {
- checkClosed(String.format("This context is closed, it is not possible to release the operation '%1$s'",
- "backup"));
- try {
- String options = "";
- if (compress) {
- options += " COMPRESSION GZIP";
- }
-
- SQLQuery query = getHibernate().createSQLQuery(
- "SCRIPT TO '" + file.getAbsolutePath() + "'" + options);
- query.list();
-
- } catch (Exception eee) {
- throw new TopiaException(String.format(
- "An error occurs while backup operation: %1$s",
- eee.getMessage()), eee);
- }
- }
-
- /**
- * Read database from gzip compressed file
- * <p/>
- * Only work for h2 database
- *
- * @see TopiaContext#restore(File)
- */
- @Override
- public void restore(File file) throws TopiaException {
- // send event
- getFiresSupport().firePreRestoreSchema(this);
- checkClosed(String.format("This context is closed, it is not possible to release the operation '%1$s'",
- "restore"));
-
- String sql = null;
- String options = "";
- try {
- // decompresse file in temporary file
- InputStream in = new BufferedInputStream(new FileInputStream(file));
- try {
- in.mark(2);
-
- // read header to see if is compressed file
- int b = in.read();
- // redundant cast : int magic = ((int) in.read() << 8) | b;
- int magic = in.read() << 8 | b;
- in.reset();
-
- if (magic == GZIPInputStream.GZIP_MAGIC) {
- options += " COMPRESSION GZIP";
- }
- } finally {
-
- in.close();
- }
-
- SQLQuery query = getHibernate().createSQLQuery(
- "RUNSCRIPT FROM '" + file.getAbsolutePath() + "'" + options);
-
- query.executeUpdate();
-
- // send event AFTER restore
- getFiresSupport().firePostRestoreSchema(this);
- } catch (Exception eee) {
- throw new TopiaException(String.format(
- String.format("An error occurs while restore operation: %1$s : %2$s",
- sql, eee.getMessage())), eee);
- }
- }
-
- /**
- * Only h2 supported for now
- *
- * @see TopiaContext#clear(boolean)
- */
- @Override
- public void clear(boolean dropDatabase) throws TopiaException {
- try {
- TopiaContextImpl root = (TopiaContextImpl) getRootContext();
- TopiaContextImpl tx = (TopiaContextImpl) root.beginTransaction();
-
- String sql = "DROP ALL OBJECTS";
- if (dropDatabase) {
- sql += " DELETE FILES";
- }
- Query query = tx.getHibernate().createSQLQuery(sql);
- query.executeUpdate();
- tx.closeContext();
- root.finalize();
- } catch (Throwable eee) {
- throw new TopiaException(
- String.format("Error %s on clear operation", eee.getMessage()), eee);
- }
- }
-
- /**
- * Clear hibernate cache to free memory.
- * <p/>
- * see http://docs.jboss.org/hibernate/orm/3.5/reference/en-US/html/transactions.h…
- */
- @Override
- public void clearCache() throws TopiaException {
- getHibernate().clear();
- }
-
- @Override
- public List<Class<?>> getPersistenceClasses() {
- return persistenceClasses;
- }
-
- @Override
- public boolean isSchemaExist(Class<?> clazz)
- throws TopiaException {
- checkClosed(String.format("This context is closed, it is not possible to release the operation '%1$s'",
- "replicateEntity"));
- boolean result = TopiaUtil.isSchemaExist(this, clazz.getName());
- return result;
- }
-
- /* Listeners adders */
-
- @Override
- public void addTopiaEntityListener(TopiaEntityListener listener) {
- getFiresSupport().addTopiaEntityListener(listener);
- }
-
- @Override
- public void addTopiaEntityListener(
- Class<? extends TopiaEntity> entityClass,
- TopiaEntityListener listener) {
- getFiresSupport().addTopiaEntityListener(entityClass, listener);
- }
-
- @Override
- public void addTopiaEntityVetoable(TopiaEntityVetoable vetoable) {
- getFiresSupport().addTopiaEntityVetoable(TopiaEntity.class, vetoable);
- }
-
- @Override
- public void addTopiaEntityVetoable(
- Class<? extends TopiaEntity> entityClass,
- TopiaEntityVetoable vetoable) {
- getFiresSupport().addTopiaEntityVetoable(entityClass, vetoable);
- }
-
- @Override
- public void addTopiaTransactionListener(TopiaTransactionListener listener) {
- getFiresSupport().addTopiaTransactionListener(listener);
- }
-
- @Override
- public void addTopiaTransactionVetoable(TopiaTransactionVetoable vetoable) {
- getFiresSupport().addTopiaTransactionVetoable(vetoable);
- }
-
- @Override
- public void addPropertyChangeListener(PropertyChangeListener listener) {
- getFiresSupport().addPropertyChangeListener(listener);
- }
-
- @Override
- @Deprecated
- public void addTopiaContextListener(TopiaContextListener listener) {
- getFiresSupport().addTopiaContextListener(listener);
- }
-
- @Override
- public void addTopiaSchemaListener(TopiaSchemaListener listener) {
- getFiresSupport().addTopiaSchemaListener(listener);
- }
-
- /* Listeners removers */
-
- @Override
- public void removeTopiaEntityListener(TopiaEntityListener listener) {
- getFiresSupport().removeTopiaEntityListener(TopiaEntity.class,
- listener);
- }
-
- @Override
- public void removeTopiaEntityListener(
- Class<? extends TopiaEntity> entityClass,
- TopiaEntityListener listener) {
- getFiresSupport().removeTopiaEntityListener(entityClass, listener);
- }
-
- @Override
- public void removeTopiaEntityVetoable(TopiaEntityVetoable vetoable) {
- getFiresSupport().removeTopiaEntityVetoable(TopiaEntity.class,
- vetoable);
- }
-
- @Override
- public void removeTopiaEntityVetoable(
- Class<? extends TopiaEntity> entityClass,
- TopiaEntityVetoable vetoable) {
- getFiresSupport().removeTopiaEntityVetoable(entityClass, vetoable);
- }
-
- @Override
- public void removeTopiaTransactionListener(
- TopiaTransactionListener listener) {
- getFiresSupport().removeTopiaTransactionListener(listener);
- }
-
- @Override
- public void removeTopiaTransactionVetoable(
- TopiaTransactionVetoable vetoable) {
- getFiresSupport().removeTopiaTransactionVetoable(vetoable);
- }
-
- @Override
- public void removePropertyChangeListener(PropertyChangeListener listener) {
- getFiresSupport().removePropertyChangeListener(listener);
- }
-
- @Override
- @Deprecated
- public void removeTopiaContextListener(TopiaContextListener listener) {
- getFiresSupport().removeTopiaContextListener(listener);
- }
-
- @Override
- public void removeTopiaSchemaListener(TopiaSchemaListener listener) {
- getFiresSupport().removeTopiaSchemaListener(listener);
- }
-
- @Override
- public void addTopiaEntitiesVetoable(TopiaEntitiesVetoable vetoable) {
- getFiresSupport().addTopiaEntitiesVetoable(vetoable);
- }
-
- @Override
- public void removeTopiaEntitiesVetoable(TopiaEntitiesVetoable vetoable) {
- getFiresSupport().removeTopiaEntitiesVetoable(vetoable);
- }
-
- /**
- * Build the list of queries from the given parameter
- * <code>entityAndCondition</code>.
- * <p/>
- * If no parameter is given, then build the queries for all entities is db,
- * with no condition.
- *
- * @param entityAndCondition the list of tuples (Class,String)
- * @return the list of queries.
- * @throws TopiaException if any pb of db while getting entities
- * classes.
- * @throws IllegalArgumentException if any pb with the given parameter
- * (mainly ClassCastException).
- */
- protected String[] buildQueries(Object... entityAndCondition)
- throws TopiaException, IllegalArgumentException {
- Class<?> entityClass;
- String condition;
-
- // si entityAndcondition est vide alors il faut le remplir
- // avec toutes les entités du mapping (class, null)
- if (entityAndCondition.length == 0) {
- Map<?, ?> classMetadata = getHibernateFactory().getAllClassMetadata();
- entityAndCondition = new Object[classMetadata.size() * 2];
- int i = 0;
- for (Object className : classMetadata.keySet()) {
- try {
- entityAndCondition[i++] = Class.forName((String) className);
- } catch (ClassNotFoundException e) {
- // should never happen!
- throw new TopiaException(
- "class cast exception for entity " + className);
- }
- entityAndCondition[i++] = null;
-
- }
- }
-
- // prepare queries to perform beofre opening any transaction
- if (entityAndCondition.length % 2 != 0) {
- throw new IllegalArgumentException(
- "entityAndCondition must be a couple of (Class, String)");
- }
- String queries[] = new String[entityAndCondition.length / 2];
- for (int i = 0; i < entityAndCondition.length; ) {
- try {
- entityClass = (Class<?>) entityAndCondition[i++];
- condition = (String) entityAndCondition[i++];
- String query = "from " + entityClass.getName();
- if (condition != null && !condition.isEmpty()) {
- query += " where " + condition;
- }
- queries[(i - 1) / 2] = query;
- } catch (ClassCastException e) {
- if (i % 2 == 0) {
- throw new IllegalArgumentException(
- "Others arguement must be String not " +
- entityAndCondition[i - 1], e);
- } else {
- throw new IllegalArgumentException(
- "Others arguement must be Class not " +
- entityAndCondition[i - 1], e);
- }
- }
- }
- return queries;
- }
-
- protected void replicate0(TopiaContextImpl dstContextImpl,
- Object... entities) throws TopiaException {
- try {
- for (Object entity : entities) {
- // dettach entity to source session, to make possible copy of
- // collection without a hibernate exception (list opened in
- // two session...)
- getHibernate().evict(entity);
- dstContextImpl.getHibernate().replicate(entity,
- ReplicationMode.EXCEPTION);
- }
-
- } catch (HibernateException eee) {
- throw new TopiaException(String.format("An error occurs while a replication operation : %s",
- eee.getMessage()), eee);
- }
- }
-
- public static class SQLWork implements Work {
- private final String script;
-
- public SQLWork(String script) {
- this.script = script;
- }
-
- @Override
- public void execute(Connection connection) throws SQLException {
- PreparedStatement sta = connection.prepareStatement(script);
- try {
- sta.execute();
- } finally {
- sta.close();
- }
- }
- }
-
- @Override
- public Session getHibernateSession() throws TopiaException {
- if (hibernate == null) {
- throw new TopiaException("No hibernate session");
- }
- return hibernate;
- }
-
- @Override
- public void update(TopiaEntity e) throws TopiaException {
- checkClosed(String.format("This context is closed, it is not possible to release the operation '%1$s'",
- "add"));
-
- String id = e.getTopiaId();
- Class<TopiaEntity> entityClass = getTopiaIdFactory().getClassName(id);
- TopiaDAO<TopiaEntity> dao = getDAO(entityClass);
- dao.update(e);
- }
-
-} //TopiaContextImpl
-
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaContextImplementor.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaContextImplementor.java 2013-08-02 16:21:12 UTC (rev 2785)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaContextImplementor.java 2013-08-02 17:26:06 UTC (rev 2786)
@@ -52,7 +52,7 @@
*/
//TODO-fdesbois-20100507 : Need more javadoc.
@Deprecated
-public interface TopiaContextImplementor extends TopiaContext, TopiaHibernate {
+public interface TopiaContextImplementor extends TopiaContext {
/**
* Retrieve a thread-safe copy of children context set.
@@ -80,7 +80,7 @@
* @deprecated Hierarchical context are not supported anymore
*/
@Deprecated
- void removeChildContext(TopiaContextImplementor child);
+ void removeChildContext(TopiaContext child);
/** @return Returns the config.
* @deprecated use method from {@link org.nuiton.topia.TopiaPersistenceContext}
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaFiresSupport.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaFiresSupport.java 2013-08-02 16:21:12 UTC (rev 2785)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaFiresSupport.java 2013-08-02 17:26:06 UTC (rev 2786)
@@ -928,7 +928,7 @@
* @return the list of entities loaded
*/
public <E extends TopiaEntity> List<E> fireEntitiesLoad(
- TopiaContextImplementor context, List<E> entities) {
+ TopiaContext context, List<E> entities) {
if (log.isDebugEnabled()) {
log.debug("fireEntitiesLoad");
}
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaService.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaService.java 2013-08-02 16:21:12 UTC (rev 2785)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaService.java 2013-08-02 17:26:06 UTC (rev 2786)
@@ -37,6 +37,8 @@
package org.nuiton.topia.framework;
+import org.nuiton.topia.TopiaContext;
+
/**
* Used to implement a service for Topia. You have to provide a static property
* called SERVICE_NAME that identify the service :
@@ -70,17 +72,17 @@
/**
* Initiliaze the service before create the {@code context}.
*
- * @param context TopiaContextImplementor
+ * @param context
* @return true if service need to be activated or not
*/
- boolean preInit(TopiaContextImplementor context);
+ boolean preInit(TopiaContext context);
/**
* Initiliaze the service after create the {@code context}.
*
- * @param context TopiaContextImplementor
+ * @param context
* @return true if service need to be activated or not
*/
- boolean postInit(TopiaContextImplementor context);
+ boolean postInit(TopiaContext context);
}
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/package-info.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/package-info.java 2013-08-02 16:21:12 UTC (rev 2785)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/package-info.java 2013-08-02 17:26:06 UTC (rev 2786)
@@ -25,7 +25,7 @@
/**
* Contains two interfaces, one {@link org.nuiton.topia.framework.TopiaContextImplementor} for internal
* manipulations of {@link org.nuiton.topia.TopiaContext} and one {@link org.nuiton.topia.framework.TopiaService} for topia
- * services. This package contains also the main implementation {@link org.nuiton.topia.framework.TopiaContextImpl}
+ * services. This package contains also the main implementation {@link org.nuiton.topia.framework.AbstractTopiaContext}
* for both {@link org.nuiton.topia.TopiaContext} for final applications and
* {@link org.nuiton.topia.framework.TopiaContextImplementor} for internal.
* <p />
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityDAOTransformer.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityDAOTransformer.java 2013-08-02 16:21:12 UTC (rev 2785)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityDAOTransformer.java 2013-08-02 17:26:06 UTC (rev 2786)
@@ -614,7 +614,7 @@
body.append(""
/*{
{
- List<<%=attrType%>> list = getContext().getHibernate().createSQLQuery(
+ List<<%=attrType%>> list = getContext().getHibernateSession().createSQLQuery(
"SELECT main.topiaid " +
"from <%=attrClassifierDBName%> main, <%=attrJoinTableName%> secondary " +
"where main.topiaid=secondary.<%=attrDBName%>" +
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAO.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAO.java 2013-08-02 16:21:12 UTC (rev 2785)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAO.java 2013-08-02 17:26:06 UTC (rev 2786)
@@ -36,6 +36,7 @@
*/
package org.nuiton.topia.persistence;
+import org.nuiton.topia.TopiaContext;
import org.nuiton.topia.TopiaException;
import org.nuiton.topia.event.TopiaEntityListener;
import org.nuiton.topia.event.TopiaEntityVetoable;
@@ -652,19 +653,18 @@
* Returns the context used by this DAO.
*
* @return Returns the context.
+ * @deprecated use {@link #getTopiaContext()}
*/
- TopiaContextImplementor getContext();
+ @Deprecated
+ TopiaContext getContext();
/**
- * Method to invoke right after instance creation. It is done by the
- * TopiaContext.
+ * Returns the context used by this DAO.
*
- * @param context context
- * @param entityClass entity class
- * @throws TopiaException if any pb while init
+ * @return Returns the context.
*/
- void init(TopiaContextImplementor context,
- Class<E> entityClass) throws TopiaException;
+ // TODO AThimel 02/08/13 Use only TopiaPersistenceContext and TopiaHibernate
+ TopiaContext getTopiaContext();
/**
* Get the entityEnum of the type of entity managed by this DAO.
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAOImpl.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAOImpl.java 2013-08-02 16:21:12 UTC (rev 2785)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAOImpl.java 2013-08-02 17:26:06 UTC (rev 2786)
@@ -53,10 +53,12 @@
import org.hibernate.criterion.Projections;
import org.hibernate.criterion.Restrictions;
import org.hibernate.metadata.ClassMetadata;
+import org.nuiton.topia.TopiaContext;
import org.nuiton.topia.TopiaException;
import org.nuiton.topia.event.TopiaEntityListener;
import org.nuiton.topia.event.TopiaEntityVetoable;
import org.nuiton.topia.framework.TopiaContextImplementor;
+import org.nuiton.topia.framework.TopiaFiresSupport;
import org.nuiton.topia.persistence.pager.TopiaPagerBean;
import org.nuiton.util.PagerBeanUtil;
@@ -101,8 +103,10 @@
*
* @since ever
*/
- protected TopiaContextImplementor context;
+ protected TopiaContext context;
+ protected TopiaFiresSupport topiaFiresSupport;
+
/**
* Default batch size used to iterate on data.
*
@@ -139,7 +143,7 @@
criteria.setMaxResults(1);
List<E> result = (List<E>) criteria.list();
int sizeBefore = result != null ? result.size() : 0;
- result = getContext().getFiresSupport().fireEntitiesLoad(context, result);
+ result = topiaFiresSupport.fireEntitiesLoad(context, result);
int sizeAfter = result != null ? result.size() : 0;
if (sizeAfter < sizeBefore) {
if (log.isDebugEnabled()) {
@@ -226,24 +230,33 @@
}
/**
- * When TopiaContextImpl create the TopiaDAOHibernate, it must call this
+ * When AbstractTopiaContext create the TopiaDAOHibernate, it must call this
* method just after.
*
* @param entityClass
*/
- @Override
- public void init(TopiaContextImplementor context, Class<E> entityClass)
+ public void init(TopiaContext context, Class<E> entityClass, TopiaFiresSupport topiaFiresSupport)
throws TopiaException {
log.debug("init dao for " + entityClass.getName());
this.context = context;
this.entityClass = entityClass;
+ this.topiaFiresSupport = topiaFiresSupport;
}
@Override
- public TopiaContextImplementor getContext() {
+ public TopiaContext getContext() {
+ return getTopiaContext();
+ }
+
+ @Override
+ public TopiaContext getTopiaContext() {
return context;
}
+ protected TopiaFiresSupport getTopiaFiresSupport() {
+ return topiaFiresSupport;
+ }
+
@Override
public String createSimpleQuery(String alias) {
String hql = "FROM " + getTopiaEntityEnum().getImplementationFQN();
@@ -333,7 +346,7 @@
// save entity
getSession().save(entity);
- getContext().getFiresSupport().warnOnCreateEntity(entity);
+ topiaFiresSupport.warnOnCreateEntity(entity);
return entity;
} catch (HibernateException eee) {
throw new TopiaException(eee);
@@ -401,7 +414,7 @@
public E update(E e) throws TopiaException {
try {
getSession().saveOrUpdate(e);
- getContext().getFiresSupport().warnOnUpdateEntity(e);
+ topiaFiresSupport.warnOnUpdateEntity(e);
return e;
} catch (HibernateException eee) {
throw new TopiaException(eee);
@@ -413,7 +426,7 @@
try {
getSession().delete(e);
e.notifyDeleted();
- getContext().getFiresSupport().warnOnDeleteEntity(e);
+ topiaFiresSupport.warnOnDeleteEntity(e);
} catch (HibernateException eee) {
throw new TopiaException(eee);
}
@@ -462,7 +475,7 @@
try {
Criteria criteria = createCriteria(FlushMode.AUTO);
List<E> result = (List<E>) criteria.list();
- result = getContext().getFiresSupport().fireEntitiesLoad(context,
+ result = topiaFiresSupport.fireEntitiesLoad(context,
result);
return result;
} catch (HibernateException eee) {
@@ -506,7 +519,7 @@
Criteria criteria = createCriteria(FlushMode.AUTO);
criteria.add(criterion);
List<E> result = (List<E>) criteria.list();
- result = getContext().getFiresSupport().fireEntitiesLoad(context,
+ result = topiaFiresSupport.fireEntitiesLoad(context,
result);
return result;
} catch (HibernateException eee) {
@@ -523,7 +536,7 @@
criteria.addOrder(Order.asc(propertyName));
}
List<E> result = (List<E>) criteria.list();
- result = getContext().getFiresSupport().fireEntitiesLoad(context,
+ result = topiaFiresSupport.fireEntitiesLoad(context,
result);
return result;
} catch (HibernateException eee) {
@@ -808,8 +821,8 @@
}
}
List<R> result = findAllByQueryWithBound(type, hql,
- (int) pager.getRecordStartIndex(),
- (int) pager.getRecordEndIndex() - 1,
+ (int) pager.getRecordStartIndex(),
+ (int) pager.getRecordEndIndex() - 1,
propertyNamesAndValues);
return result;
}
@@ -844,7 +857,7 @@
* @throws TopiaException if any pb
*/
protected Session getSession() throws TopiaException {
- Session result = getContext().getHibernate();
+ Session result = getContext().getHibernateSession();
return result;
}
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/csv/in/TopiaCsvImports.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/csv/in/TopiaCsvImports.java 2013-08-02 16:21:12 UTC (rev 2785)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/csv/in/TopiaCsvImports.java 2013-08-02 17:26:06 UTC (rev 2786)
@@ -273,7 +273,7 @@
CsvImportResult<T> csvResult,
int nbRowBuffer) throws TopiaException {
- TopiaContextImplementor context = dao.getContext();
+ TopiaContext context = dao.getContext();
CsvProgressModel progressModel = csvResult == null ? null :
csvResult.getProgressModel();
@@ -296,7 +296,7 @@
compt++;
if (compt % nbRowBuffer == 0) {
// flush it
- context.getHibernate().flush();
+ context.getHibernateSession().flush();
}
}
}
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/DBMapping.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/DBMapping.java 2013-08-02 16:21:12 UTC (rev 2785)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/DBMapping.java 2013-08-02 17:26:06 UTC (rev 2786)
@@ -30,7 +30,7 @@
import org.hibernate.exception.SQLGrammarException;
import org.nuiton.topia.TopiaContext;
import org.nuiton.topia.TopiaException;
-import org.nuiton.topia.framework.TopiaContextImpl;
+import org.nuiton.topia.framework.AbstractTopiaContext;
import org.nuiton.topia.persistence.TopiaEntity;
import org.hibernate.SQLQuery;
import org.hibernate.jdbc.Work;
@@ -327,7 +327,7 @@
BigInteger size = defaultSize;
if (ctxt != null) {
try {
- SQLQuery query = ((TopiaContextImpl) ctxt).getHibernate().createSQLQuery(sql);
+ SQLQuery query = ((AbstractTopiaContext) ctxt).getHibernate().createSQLQuery(sql);
size = (BigInteger) query.list().get(0);
} catch (SQLGrammarException e) {
// could not obtain sequence
@@ -340,7 +340,7 @@
protected void doSQLWork(TopiaContext ctxt, final String sql) throws TopiaException {
if (ctxt != null) {
//ctxt.beginTransaction();
- ((TopiaContextImpl) ctxt).getHibernate().doWork(new Work() {
+ ((AbstractTopiaContext) ctxt).getHibernate().doWork(new Work() {
public void execute(Connection connection) throws SQLException {
if (log.isDebugEnabled()) {
log.debug(sql);
Modified: trunk/topia-persistence/src/test/java/org/nuiton/topia/TopiaContextFactoryTest.java
===================================================================
--- trunk/topia-persistence/src/test/java/org/nuiton/topia/TopiaContextFactoryTest.java 2013-08-02 16:21:12 UTC (rev 2785)
+++ trunk/topia-persistence/src/test/java/org/nuiton/topia/TopiaContextFactoryTest.java 2013-08-02 17:26:06 UTC (rev 2786)
@@ -30,7 +30,7 @@
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
-import org.nuiton.topia.framework.TopiaContextImpl;
+import org.nuiton.topia.framework.AbstractTopiaContext;
import java.io.File;
import java.io.IOException;
@@ -77,7 +77,7 @@
String url = "jdbc:h2:file:" + dbDirectory;
properties.setProperty("hibernate.connection.url", url);
- TopiaContextImpl test = new TopiaContextImpl(properties);
+ AbstractTopiaContext test = new AbstractTopiaContext(properties);
TopiaContextFactory.contextCache.put(properties, test);
/** EXEC METHOD **/
@@ -91,7 +91,7 @@
log.debug("## testRemoveContext");
/** PREPARE DATA **/
- TopiaContextImpl test = new TopiaContextImpl(properties);
+ AbstractTopiaContext test = new AbstractTopiaContext(properties);
TopiaContextFactory.contextCache.put(properties, test);
/** EXEC METHOD **/
Modified: trunk/topia-persistence/src/test/java/org/nuiton/topia/framework/TopiaContextImplTest.java
===================================================================
--- trunk/topia-persistence/src/test/java/org/nuiton/topia/framework/TopiaContextImplTest.java 2013-08-02 16:21:12 UTC (rev 2785)
+++ trunk/topia-persistence/src/test/java/org/nuiton/topia/framework/TopiaContextImplTest.java 2013-08-02 17:26:06 UTC (rev 2786)
@@ -87,7 +87,7 @@
properties.setProperty("topia.service.test",
TestService.class.getName());
- TopiaContextImpl context = new TopiaContextImpl();
+ AbstractTopiaContext context = new AbstractTopiaContext();
/** EXEC METHOD **/
if (log.isInfoEnabled()) {
@@ -134,10 +134,10 @@
TestService.class.getName());
// Calling the constructor with properties will load the services
- TopiaContextImpl context = new TopiaContextImpl(properties);
+ AbstractTopiaContext context = new AbstractTopiaContext(properties);
// Instantiate a child context and set its parent
- TopiaContextImpl child = new TopiaContextImpl(context);
+ AbstractTopiaContext child = new AbstractTopiaContext(context);
/** EXEC METHOD **/
if (log.isInfoEnabled()) {
@@ -180,7 +180,7 @@
properties.clear();
properties.setProperty("topia.service.fake",
FakeService.class.getName());
- TopiaContextImpl otherContext = new TopiaContextImpl(properties);
+ AbstractTopiaContext otherContext = new AbstractTopiaContext(properties);
boolean test6 = otherContext.serviceEnabled(FakeService.class);
Assert.assertFalse(test6);
@@ -208,28 +208,28 @@
}
/** PREPARE DATA **/
- TopiaContextImpl context = new TopiaContextImpl(properties);
+ AbstractTopiaContext context = new AbstractTopiaContext(properties);
/** EXEC METHODS **/
if (log.isInfoEnabled()) {
log.info("test 1 : constructor with parent context");
}
- TopiaContextImpl test1 = new TopiaContextImpl(context);
+ AbstractTopiaContext test1 = new AbstractTopiaContext(context);
Assert.assertEquals(context, test1.parentContext);
if (log.isInfoEnabled()) {
log.info("test 2 : addChildContext");
}
- TopiaContextImpl test2 = new TopiaContextImpl(properties);
- TopiaContextImpl child2 = new TopiaContextImpl();
+ AbstractTopiaContext test2 = new AbstractTopiaContext(properties);
+ AbstractTopiaContext child2 = new AbstractTopiaContext();
test2.addChildContext(child2);
Assert.assertEquals(1, test2.childContext.size());
if (log.isInfoEnabled()) {
log.info("test 3 : removeChildContext");
}
- TopiaContextImpl test3 = new TopiaContextImpl(properties);
- TopiaContextImpl child3 = new TopiaContextImpl(test3);
+ AbstractTopiaContext test3 = new AbstractTopiaContext(properties);
+ AbstractTopiaContext child3 = new AbstractTopiaContext(test3);
test3.childContext.add(child3);
test3.removeChildContext(child3);
Assert.assertEquals(0, test3.childContext.size());
@@ -274,7 +274,7 @@
}
/** PREPARE DATA **/
- TopiaContextImpl context = new TopiaContextImpl();
+ AbstractTopiaContext context = new AbstractTopiaContext();
context.services = new HashMap<String, TopiaService>();
String basedir = System.getenv("basedir");
@@ -325,7 +325,7 @@
log.info("test 2 : load mappings for all entities");
}
//reset from previous test
- context = new TopiaContextImpl();
+ context = new AbstractTopiaContext();
context.services = new HashMap<String, TopiaService>();
properties.clear();
@@ -343,7 +343,7 @@
log.info("test 3 : add properties from file");
}
//reset from previous test
- context = new TopiaContextImpl();
+ context = new AbstractTopiaContext();
context.services = new HashMap<String, TopiaService>();
properties.clear();
Modified: trunk/topia-persistence/src/test/java/org/nuiton/topiatest/service/FakeService.java
===================================================================
--- trunk/topia-persistence/src/test/java/org/nuiton/topiatest/service/FakeService.java 2013-08-02 16:21:12 UTC (rev 2785)
+++ trunk/topia-persistence/src/test/java/org/nuiton/topiatest/service/FakeService.java 2013-08-02 17:26:06 UTC (rev 2786)
@@ -24,16 +24,15 @@
*/
package org.nuiton.topiatest.service;
-import org.nuiton.topia.framework.TopiaContextImpl;
+import org.nuiton.topia.TopiaContext;
import org.nuiton.topia.framework.TopiaContextImplTest;
-import org.nuiton.topia.framework.TopiaContextImplementor;
import org.nuiton.topia.framework.TopiaService;
/**
* FakeService which implements {@link TopiaService} to test existing service
* from {@link TopiaContextImplTest#testGetServices()}. This fake service
* doesn't contains property SERVICE_NAME used by {@link
- * TopiaContextImpl#serviceEnabled(Class)}.
+ * org.nuiton.topia.framework.AbstractTopiaContext#serviceEnabled(Class)}.
* <p/>
* Created: 10 mai 2010
*
@@ -53,12 +52,12 @@
}
@Override
- public boolean preInit(TopiaContextImplementor context) {
+ public boolean preInit(TopiaContext context) {
return true;
}
@Override
- public boolean postInit(TopiaContextImplementor context) {
+ public boolean postInit(TopiaContext context) {
return true;
}
}
Modified: trunk/topia-persistence/src/test/java/org/nuiton/topiatest/service/TestService.java
===================================================================
--- trunk/topia-persistence/src/test/java/org/nuiton/topiatest/service/TestService.java 2013-08-02 16:21:12 UTC (rev 2785)
+++ trunk/topia-persistence/src/test/java/org/nuiton/topiatest/service/TestService.java 2013-08-02 17:26:06 UTC (rev 2786)
@@ -56,12 +56,12 @@
}
@Override
- public boolean preInit(TopiaContextImplementor context) {
+ public boolean preInit(TopiaContext context) {
return true;
}
@Override
- public boolean postInit(TopiaContextImplementor context) {
+ public boolean postInit(TopiaContext context) {
return true;
}
}
Modified: trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/TopiaMigrationEngine.java
===================================================================
--- trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/TopiaMigrationEngine.java 2013-08-02 16:21:12 UTC (rev 2785)
+++ trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/TopiaMigrationEngine.java 2013-08-02 17:26:06 UTC (rev 2786)
@@ -101,7 +101,7 @@
protected AbstractTopiaMigrationCallback callback;
/** topia root context (initialise en pre-init) */
- protected TopiaContextImplementor rootContext;
+ protected TopiaContext rootContext;
/** Un drapeau pour savoir si le service a bien ete initialise (i.e a bien fini la methode preInit) */
protected boolean init;
@@ -194,7 +194,7 @@
}
@Override
- public boolean preInit(TopiaContextImplementor context) {
+ public boolean preInit(TopiaContext context) {
rootContext = context;
Properties config = context.getConfig();
@@ -267,7 +267,7 @@
}
@Override
- public boolean postInit(TopiaContextImplementor context) {
+ public boolean postInit(TopiaContext context) {
// nothing to do in post-init
return true;
}
Modified: trunk/topia-service-replication/src/main/java/org/nuiton/topia/replication/TopiaReplicationServiceImpl.java
===================================================================
--- trunk/topia-service-replication/src/main/java/org/nuiton/topia/replication/TopiaReplicationServiceImpl.java 2013-08-02 16:21:12 UTC (rev 2785)
+++ trunk/topia-service-replication/src/main/java/org/nuiton/topia/replication/TopiaReplicationServiceImpl.java 2013-08-02 17:26:06 UTC (rev 2786)
@@ -52,7 +52,7 @@
LogFactory.getLog(TopiaReplicationServiceImpl.class);
/** le contexte sur la base source de la replication */
- protected TopiaContextImplementor context;
+ protected TopiaContext context;
/**
* le constructeur de modèle de réplication.
@@ -77,13 +77,13 @@
}
@Override
- public boolean preInit(TopiaContextImplementor context) {
+ public boolean preInit(TopiaContext context) {
// nothing to init
return true;
}
@Override
- public boolean postInit(TopiaContextImplementor context) {
+ public boolean postInit(TopiaContext context) {
// set the incoming root context from topia
this.context = context;
//TODO avoir un objet pour lire les contrainte de resolution de cycle
Modified: trunk/topia-service-security/src/main/java/org/nuiton/topia/security/TopiaSecurityServiceImpl.java
===================================================================
--- trunk/topia-service-security/src/main/java/org/nuiton/topia/security/TopiaSecurityServiceImpl.java 2013-08-02 16:21:12 UTC (rev 2785)
+++ trunk/topia-service-security/src/main/java/org/nuiton/topia/security/TopiaSecurityServiceImpl.java 2013-08-02 17:26:06 UTC (rev 2786)
@@ -149,7 +149,7 @@
*/
@Override
- public boolean preInit(TopiaContextImplementor context) {
+ public boolean preInit(TopiaContext context) {
return true;
}
@@ -159,7 +159,7 @@
*/
@Override
- public boolean postInit(TopiaContextImplementor context) {
+ public boolean postInit(TopiaContext context) {
rootContext = context;
securityContext = null;
Modified: trunk/topia-service-security/src/main/java/org/nuiton/topia/security/util/TopiaSecurityUtil.java
===================================================================
--- trunk/topia-service-security/src/main/java/org/nuiton/topia/security/util/TopiaSecurityUtil.java 2013-08-02 16:21:12 UTC (rev 2785)
+++ trunk/topia-service-security/src/main/java/org/nuiton/topia/security/util/TopiaSecurityUtil.java 2013-08-02 17:26:06 UTC (rev 2786)
@@ -43,7 +43,7 @@
import org.nuiton.topia.TopiaContext;
import org.nuiton.topia.TopiaContextFactory;
import org.nuiton.topia.TopiaException;
-import org.nuiton.topia.framework.TopiaContextImpl;
+import org.nuiton.topia.framework.AbstractTopiaContext;
import org.nuiton.topia.persistence.TopiaId;
import org.nuiton.topia.security.entities.authorization.TopiaAssociationAuthorizationImpl;
import org.nuiton.topia.security.entities.authorization.TopiaAuthorizationImpl;
@@ -242,7 +242,7 @@
* @throws TopiaException if any topia pb
*/
public static TopiaContext beginTransactionWithoutSecurity(TopiaContext transaction) throws TopiaException {
- TopiaContextImpl context = (TopiaContextImpl) transaction;
+ AbstractTopiaContext context = (AbstractTopiaContext) transaction;
Properties config = context.getConfig();
config.setProperty("topia.service.security", "");
Modified: trunk/topia-service-security/src/main/java/org/nuiton/topia/taas/TaasService.java
===================================================================
--- trunk/topia-service-security/src/main/java/org/nuiton/topia/taas/TaasService.java 2013-08-02 16:21:12 UTC (rev 2785)
+++ trunk/topia-service-security/src/main/java/org/nuiton/topia/taas/TaasService.java 2013-08-02 17:26:06 UTC (rev 2786)
@@ -108,7 +108,7 @@
private TaasPolicy policy = new TaasPolicy(this);
- private TopiaContextImplementor rootContext;
+ private TopiaContext rootContext;
private TopiaContext rootContextNoSecure;
@@ -139,7 +139,7 @@
}
@Override
- public boolean preInit(TopiaContextImplementor context) {
+ public boolean preInit(TopiaContext context) {
rootContext = context;
try {
@@ -218,7 +218,7 @@
}
@Override
- public boolean postInit(TopiaContextImplementor context) {
+ public boolean postInit(TopiaContext context) {
policy.installPolicy();
// Si pas de configuration autre que celle par defaut
@@ -234,7 +234,7 @@
*
* @return context root
*/
- public TopiaContextImplementor getRootContext() {
+ public TopiaContext getRootContext() {
return rootContext;
}
1
0
r2785 - in trunk: . topia-persistence topia-persistence/src/main/java/org/nuiton/topia topia-persistence/src/main/java/org/nuiton/topia/framework topia-service-migration topia-service-replication topia-service-security
by athimel@users.nuiton.org 02 Aug '13
by athimel@users.nuiton.org 02 Aug '13
02 Aug '13
Author: athimel
Date: 2013-08-02 18:21:12 +0200 (Fri, 02 Aug 2013)
New Revision: 2785
Url: http://nuiton.org/projects/topia/repository/revisions/2785
Log:
refs #2748 Split TopiaContext in several smaller contracts
Added:
trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaHibernate.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaJpaSupport.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaListenable.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaPersistenceContext.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaReplicationSupport.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaServiceSupport.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaSqlSupport.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaTransaction.java
Modified:
trunk/pom.xml
trunk/topia-persistence/pom.xml
trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaContext.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaContextImpl.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaContextImplementor.java
trunk/topia-service-migration/pom.xml
trunk/topia-service-replication/pom.xml
trunk/topia-service-security/pom.xml
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2013-07-25 17:03:03 UTC (rev 2784)
+++ trunk/pom.xml 2013-08-02 16:21:12 UTC (rev 2785)
@@ -37,7 +37,7 @@
</parent>
<artifactId>topia</artifactId>
- <version>3.0-alpha-2-SNAPSHOT</version>
+ <version>3.0-SNAPSHOT</version>
<modules>
<module>topia-persistence</module>
Modified: trunk/topia-persistence/pom.xml
===================================================================
--- trunk/topia-persistence/pom.xml 2013-07-25 17:03:03 UTC (rev 2784)
+++ trunk/topia-persistence/pom.xml 2013-08-02 16:21:12 UTC (rev 2785)
@@ -35,7 +35,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>topia</artifactId>
- <version>3.0-alpha-2-SNAPSHOT</version>
+ <version>3.0-SNAPSHOT</version>
</parent>
<groupId>org.nuiton.topia</groupId>
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaContext.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaContext.java 2013-07-25 17:03:03 UTC (rev 2784)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaContext.java 2013-08-02 16:21:12 UTC (rev 2785)
@@ -25,6 +25,10 @@
package org.nuiton.topia;
+import java.beans.PropertyChangeListener;
+import java.io.File;
+import java.util.List;
+
import org.nuiton.topia.event.TopiaContextListener;
import org.nuiton.topia.event.TopiaEntitiesVetoable;
import org.nuiton.topia.event.TopiaEntityListener;
@@ -35,10 +39,6 @@
import org.nuiton.topia.framework.TopiaService;
import org.nuiton.topia.persistence.TopiaEntity;
-import java.beans.PropertyChangeListener;
-import java.io.File;
-import java.util.List;
-
/**
* The TopiaContext is the most important class of ToPIA. It contains all the
* methods to manipulate data : transaction management, entities querying, event
@@ -53,8 +53,11 @@
* @author tchemit <tchemit(a)codelutin.com>
* @author athimel <thimel(a)codelutin.com>
* @version $Id$
+ * @deprecated Since 3.0, TopiaContext is splitted in multiple contracts
*/
-public interface TopiaContext {
+@Deprecated
+public interface TopiaContext extends TopiaTransaction, TopiaListenable, TopiaSqlSupport, TopiaJpaSupport,
+ TopiaPersistenceContext, TopiaServiceSupport, TopiaReplicationSupport {
/* -------------------- TRANSACTION MANAGEMENT --------------------------*/
@@ -63,7 +66,9 @@
*
* @return new context with transaction
* @throws TopiaException if any exception
+ * @deprecated use method from {@link TopiaTransaction}
*/
+ @Deprecated
TopiaContext beginTransaction() throws TopiaException;
/**
@@ -71,7 +76,9 @@
* device. Once commit is done, a new transaction is started.
*
* @throws TopiaException if any exception
+ * @deprecated use method from {@link TopiaTransaction}
*/
+ @Deprecated
void commitTransaction() throws TopiaException;
/**
@@ -80,7 +87,9 @@
* transaction is started.
*
* @throws TopiaException if any exception
+ * @deprecated use method from {@link TopiaTransaction}
*/
+ @Deprecated
void rollbackTransaction() throws TopiaException;
/**
@@ -88,14 +97,18 @@
* time.
*
* @throws TopiaException if any exception
+ * @deprecated use method from {@link TopiaTransaction}
*/
+ @Deprecated
void closeContext() throws TopiaException;
/**
* Tells if the context is closed
*
* @return {@code true} if the context is closed, {@code false} otherwise
+ * @deprecated use method from {@link TopiaTransaction}
*/
+ @Deprecated
boolean isClosed();
/* ------------------------ EVENT FIRING --------------------------*/
@@ -108,7 +121,9 @@
* the entity.
*
* @param listener the listener instance to register
+ * @deprecated use method from {@link TopiaListenable}
*/
+ @Deprecated
void addTopiaEntityListener(TopiaEntityListener listener);
/**
@@ -118,7 +133,9 @@
*
* @param entityClass the TopiaEntity's class to listen
* @param listener the listener instance to register
+ * @deprecated use method from {@link TopiaListenable}
*/
+ @Deprecated
void addTopiaEntityListener(Class<? extends TopiaEntity> entityClass,
TopiaEntityListener listener);
@@ -127,7 +144,9 @@
* context
*
* @param listener the listener instance to unregister
+ * @deprecated use method from {@link TopiaListenable}
*/
+ @Deprecated
void removeTopiaEntityListener(TopiaEntityListener listener);
/**
@@ -136,7 +155,9 @@
*
* @param entityClass the listened TopiaEntity's class
* @param listener the listener instance to unregister
+ * @deprecated use method from {@link TopiaListenable}
*/
+ @Deprecated
void removeTopiaEntityListener(Class<? extends TopiaEntity> entityClass,
TopiaEntityListener listener);
@@ -149,7 +170,9 @@
* the entity.
*
* @param vetoable the vetoable instance to register
+ * @deprecated use method from {@link TopiaListenable}
*/
+ @Deprecated
void addTopiaEntityVetoable(TopiaEntityVetoable vetoable);
/**
@@ -159,7 +182,9 @@
*
* @param entityClass the TopiaEntity's class to listen
* @param vetoable the vetoable instance to register
+ * @deprecated use method from {@link TopiaListenable}
*/
+ @Deprecated
void addTopiaEntityVetoable(Class<? extends TopiaEntity> entityClass,
TopiaEntityVetoable vetoable);
@@ -168,7 +193,9 @@
* context
*
* @param vetoable the vetoable instance to unregister
+ * @deprecated use method from {@link TopiaListenable}
*/
+ @Deprecated
void removeTopiaEntityVetoable(TopiaEntityVetoable vetoable);
/**
@@ -177,7 +204,9 @@
*
* @param entityClass the listened TopiaEntity's class
* @param vetoable the vetoable instance to unregister
+ * @deprecated use method from {@link TopiaListenable}
*/
+ @Deprecated
void removeTopiaEntityVetoable(Class<? extends TopiaEntity> entityClass,
TopiaEntityVetoable vetoable);
@@ -189,7 +218,9 @@
* <code>vetoable</code> instance will be notified BEFORE any entity load
*
* @param vetoable the vetoable instance to register
+ * @deprecated use method from {@link TopiaListenable}
*/
+ @Deprecated
void addTopiaEntitiesVetoable(TopiaEntitiesVetoable vetoable);
/**
@@ -197,7 +228,9 @@
* context
*
* @param vetoable the vetoable instance to unregister
+ * @deprecated use method from {@link TopiaListenable}
*/
+ @Deprecated
void removeTopiaEntitiesVetoable(TopiaEntitiesVetoable vetoable);
@@ -209,7 +242,9 @@
* the transaction.
*
* @param listener the listener instance to register
+ * @deprecated use method from {@link TopiaListenable}
*/
+ @Deprecated
void addTopiaTransactionListener(TopiaTransactionListener listener);
/**
@@ -217,7 +252,9 @@
* the context
*
* @param listener the listener instance to unregister
+ * @deprecated use method from {@link TopiaListenable}
*/
+ @Deprecated
void removeTopiaTransactionListener(TopiaTransactionListener listener);
@@ -229,7 +266,9 @@
* the transaction.
*
* @param vetoable the vetoable instance to register
+ * @deprecated use method from {@link TopiaListenable}
*/
+ @Deprecated
void addTopiaTransactionVetoable(TopiaTransactionVetoable vetoable);
/**
@@ -237,7 +276,9 @@
* the context
*
* @param vetoable the vetoable instance to unregister
+ * @deprecated use method from {@link TopiaListenable}
*/
+ @Deprecated
void removeTopiaTransactionVetoable(TopiaTransactionVetoable vetoable);
@@ -249,7 +290,9 @@
* any change on the entity's property
*
* @param listener the listener instance to register
+ * @deprecated use method from {@link TopiaListenable}
*/
+ @Deprecated
void addPropertyChangeListener(PropertyChangeListener listener);
/**
@@ -257,7 +300,9 @@
* property change from the context
*
* @param listener the listener instance to unregister
+ * @deprecated use method from {@link TopiaListenable}
*/
+ @Deprecated
void removePropertyChangeListener(PropertyChangeListener listener);
@@ -269,7 +314,9 @@
* AFTER any change on the schema
*
* @param listener the listener instance to register
+ * @deprecated use method from {@link TopiaListenable}
*/
+ @Deprecated
void addTopiaSchemaListener(TopiaSchemaListener listener);
/**
@@ -277,7 +324,9 @@
* from the context
*
* @param listener the listener instance to unregister
+ * @deprecated use method from {@link TopiaListenable}
*/
+ @Deprecated
void removeTopiaSchemaListener(TopiaSchemaListener listener);
@@ -312,10 +361,31 @@
* @param topiaId unique identifier of the entity in all the application.
* @return the entity found or null
* @throws TopiaException for errors on retrieving the entity
+ * @deprecated use {@link TopiaPersistenceContext#findByTopiaId(String)}
*/
+ @Deprecated
<E extends TopiaEntity> E findByTopiaId(String topiaId) throws TopiaException;
/**
+ * Add into this TopiaContext an entity created by another TopiaContext
+ *
+ * @param e the entity to add
+ * @throws TopiaException if any exception
+ * @deprecated use {@link TopiaPersistenceContext#update(org.nuiton.topia.persistence.TopiaEntity)}
+ */
+ @Deprecated
+ void add(TopiaEntity e) throws TopiaException;
+
+ /**
+ * Clear persistence implementation cache.
+ *
+ * @since 2.6.13
+ * @deprecated use {@link TopiaHibernate#getHibernateSession().clear()}
+ */
+ @Deprecated
+ void clearCache() throws TopiaException;
+
+ /**
* Allow to do some HQL query
* <p/>
* WARNING : Depending on the registered service, this method may not
@@ -326,7 +396,9 @@
* [propertyName;value;propertyName;value;...]
* @return The result list
* @throws TopiaException for any error during querying
+ * @deprecated use method from {@link TopiaJpaSupport}
*/
+ @Deprecated
<E> List<E> findAll(String hql,
Object... propertyNamesAndValues) throws TopiaException;
@@ -346,7 +418,9 @@
* [propertyName;value;propertyName;value;...]
* @return The result list
* @throws TopiaException for any error during querying
+ * @deprecated use method from {@link TopiaJpaSupport}
*/
+ @Deprecated
<E> List<E> find(String hql,
int startIndex,
int endIndex,
@@ -366,36 +440,13 @@
* @return The result instance or null
* @throws TopiaException for any error during querying or if the the query
* returns more than one result.
+ * @deprecated use method from {@link TopiaJpaSupport}
*/
+ @Deprecated
<E> E findUnique(String hql,
Object... propertyNamesAndValues) throws TopiaException;
/**
- * Add into this TopiaContext an entity created by another TopiaContext
- *
- * @param e the entity to add
- * @throws TopiaException if any exception
- */
- void add(TopiaEntity e) throws TopiaException;
-
- /**
- * Detaches the given entity from the session
- *
- * @param e the entity to detach
- * @throws TopiaException if any exception
- *
- * @since 3.0
- */
- void evict(TopiaEntity e) throws TopiaException;
-
- /**
- * Clear persistence implementation cache.
- *
- * @since 2.6.13
- */
- void clearCache() throws TopiaException;
-
- /**
* Execute HQL operation on data (Update, Delete).
*
* @param hql the HQL query
@@ -403,7 +454,9 @@
* [propertyName;value;propertyName;value;...]
* @return The number of entities updated or deleted.
* @throws TopiaException if any exception
+ * @deprecated use method from {@link TopiaJpaSupport}
*/
+ @Deprecated
int execute(String hql,
Object... propertyNamesAndValues) throws TopiaException;
@@ -412,7 +465,9 @@
*
* @param sqlScript the sql script to execute
* @throws TopiaException if any problem occurred while executing the sql script.
+ * @deprecated use method from {@link TopiaSqlSupport}
*/
+ @Deprecated
void executeSQL(String sqlScript) throws TopiaException;
// TODO AThimel 20/07/13 Copy "void doSQLWork(TopiaSQLWork sqlWork);" from topia-3.0-jpa ?
@@ -429,31 +484,29 @@
* Triggers database schema creation
*
* @throws TopiaException if any exception
+ * @deprecated use methods from {@link TopiaPersistenceContext}
*/
+ @Deprecated
void createSchema() throws TopiaException;
/**
* Displays the SQL queries that would be used for a schema creation
*
* @throws TopiaException if any exception
+ * @deprecated use methods from {@link TopiaPersistenceContext}
*/
+ @Deprecated
void showCreateSchema() throws TopiaException;
/**
* Triggers database schema update
*
* @throws TopiaException if any exception
+ * @deprecated use methods from {@link TopiaPersistenceContext}
*/
+ @Deprecated
void updateSchema() throws TopiaException;
- /**
- * Triggers database schema drop
- *
- * @throws TopiaException if any exception
- * @since 3.0
- */
- void dropSchema() throws TopiaException;
-
/* -------------------- SERVICES MANAGMENT -------------------------------*/
/**
@@ -462,7 +515,9 @@
* @param <E> type of service
* @param interfaceService fqn of the service
* @return the service
+ * @deprecated use methods from {@link TopiaServiceSupport}
*/
+ @Deprecated
<E extends TopiaService> boolean serviceEnabled(Class<E> interfaceService);
/**
@@ -473,7 +528,9 @@
* @param interfaceService class of the service
* @return the service
* @throws TopiaNotFoundException if service can't be retrieved
+ * @deprecated use methods from {@link TopiaServiceSupport}
*/
+ @Deprecated
<E extends TopiaService> E getService(Class<E> interfaceService) throws TopiaNotFoundException;
/* ------------------ IMPORT / EXPORT / REPLICATION ---------------------*/
@@ -497,7 +554,9 @@
* @throws IllegalArgumentException if one of the context is closed or if
* trying to replicate within the same
* database
+ * @deprecated use methods from {@link TopiaReplicationSupport}
*/
+ @Deprecated
void replicate(TopiaContext destinationContext,
Object... entityAndCondition) throws TopiaException, IllegalArgumentException;
@@ -511,7 +570,9 @@
* @throws IllegalArgumentException if one of the context is closed or if
* trying to replicate within the same
* database
+ * @deprecated use methods from {@link TopiaReplicationSupport}
*/
+ @Deprecated
<T extends TopiaEntity> void replicateEntity(TopiaContext destinationContext,
T entity) throws TopiaException, IllegalArgumentException;
@@ -526,7 +587,9 @@
* @throws IllegalArgumentException if one of the context is closed or if
* trying to replicate within the same
* database
+ * @deprecated use methods from {@link TopiaReplicationSupport}
*/
+ @Deprecated
<T extends TopiaEntity> void replicateEntities(TopiaContext destinationContext,
List<T> entities) throws TopiaException, IllegalArgumentException;
@@ -548,7 +611,7 @@
boolean compress) throws TopiaException;
/**
- * l'inverse de la methode {@link #backup(File,boolean)}.
+ * l'inverse de la methode {@link #backup(File, boolean)}.
*
* @param file le fichier ou prendre les informations, il peut-etre
* compressé avec gzip ou non.
Added: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaHibernate.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaHibernate.java (rev 0)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaHibernate.java 2013-08-02 16:21:12 UTC (rev 2785)
@@ -0,0 +1,55 @@
+package org.nuiton.topia;
+
+/*
+ * #%L
+ * ToPIA :: Persistence
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2004 - 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 org.hibernate.Session;
+import org.hibernate.SessionFactory;
+import org.hibernate.cfg.Configuration;
+
+/**
+ * @author Arnaud Thimel <thimel(a)codelutin.com>
+ */
+public interface TopiaHibernate {
+
+ /**
+ * @return Returns the hibernate's Session.
+ * @throws TopiaException si aucune transaction n'est ouverte
+ */
+ Session getHibernateSession() throws TopiaException;
+
+ /**
+ * @return Returns the hibernateFactory.
+ * @throws TopiaNotFoundException
+ */
+ SessionFactory getHibernateFactory() throws TopiaNotFoundException;
+
+ /**
+ * @return Returns the hibernate configuration
+ * @throws TopiaNotFoundException
+ */
+ Configuration getHibernateConfiguration()
+ throws TopiaNotFoundException;
+
+}
Property changes on: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaHibernate.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Added: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaJpaSupport.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaJpaSupport.java (rev 0)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaJpaSupport.java 2013-08-02 16:21:12 UTC (rev 2785)
@@ -0,0 +1,101 @@
+package org.nuiton.topia;
+
+/*
+ * #%L
+ * ToPIA :: Persistence
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2004 - 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 java.util.List;
+
+/**
+ * @author Arnaud Thimel <thimel(a)codelutin.com>
+ */
+public interface TopiaJpaSupport {
+
+ /**
+ * Allow to do some HQL query
+ * <p/>
+ * WARNING : Depending on the registered service, this method may not
+ * support something else than queries on TopiaEntity
+ *
+ * @param jpaql the JPA-QL query
+ * @param propertyNamesAndValues the query parameters. Arguments are key-value paired :
+ * [propertyName;value;propertyName;value;...]
+ * @return The result list
+ * @throws TopiaException for any error during querying
+ */
+ <T> List<T> findAll(String jpaql,
+ Object... propertyNamesAndValues) throws TopiaException;
+
+ /**
+ * Allow to do some JPA-QL query using the given bounds.
+ * <p/>
+ * No lower bound : <code>startIndex</code> = 0.<br/>
+ * No upper bound : <code>endIndex</code> = -1.
+ * <p/>
+ * WARNING : Depending on the registered service, this method may not
+ * support something else than queries on TopiaEntity
+ *
+ * @param jpaql the JPA-QL query
+ * @param startIndex first index of entity to return
+ * @param endIndex last index of entity to return
+ * @param propertyNamesAndValues the query parameters. Arguments are key-value paired :
+ * [propertyName;value;propertyName;value;...]
+ * @return The result list
+ * @throws TopiaException for any error during querying
+ */
+ <T> List<T> find(String jpaql,
+ int startIndex,
+ int endIndex,
+ Object... propertyNamesAndValues) throws TopiaException;
+
+ /**
+ * Allow to do some HQL query and return an unique result. If nothing if
+ * found by the query, will return null. If more than one result is found,
+ * will throw an exception.
+ * <p/>
+ * WARNING : Depending on the registered service, this method may not
+ * support something else than queries on TopiaEntity
+ *
+ * @param jpaql the JPA-QL query
+ * @param propertyNamesAndValues the query parameters. Arguments are key-value paired :
+ * [propertyName;value;propertyName;value;...]
+ * @return The result instance or null
+ * @throws TopiaException for any error during querying or if the the query
+ * returns more than one result.
+ */
+ <T> T findUnique(String jpaql,
+ Object... propertyNamesAndValues) throws TopiaException;
+
+ /**
+ * Execute HQL operation on data (Update, Delete).
+ *
+ * @param jpaql the JPA-QL query
+ * @param propertyNamesAndValues the query parameters. Arguments are key-value paired :
+ * [propertyName;value;propertyName;value;...]
+ * @return The number of entities updated or deleted.
+ * @throws TopiaException if any exception
+ */
+ int execute(String jpaql,
+ Object... propertyNamesAndValues) throws TopiaException;
+
+}
Property changes on: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaJpaSupport.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Added: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaListenable.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaListenable.java (rev 0)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaListenable.java 2013-08-02 16:21:12 UTC (rev 2785)
@@ -0,0 +1,223 @@
+package org.nuiton.topia;
+
+/*
+ * #%L
+ * ToPIA :: Persistence
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2004 - 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 java.beans.PropertyChangeListener;
+
+import org.nuiton.topia.event.TopiaEntitiesVetoable;
+import org.nuiton.topia.event.TopiaEntityListener;
+import org.nuiton.topia.event.TopiaEntityVetoable;
+import org.nuiton.topia.event.TopiaSchemaListener;
+import org.nuiton.topia.event.TopiaTransactionListener;
+import org.nuiton.topia.event.TopiaTransactionVetoable;
+import org.nuiton.topia.persistence.TopiaEntity;
+
+/**
+ * @author Arnaud Thimel <thimel(a)codelutin.com>
+ */
+public interface TopiaListenable {
+
+ /* TopiaEntityListener */
+
+ /**
+ * Register to the context a TopiaEntityListener about any TopiaEntity.
+ * <code>listener</code> instance will be notified AFTER any operation on
+ * the entity.
+ *
+ * @param listener the listener instance to register
+ */
+ void addTopiaEntityListener(TopiaEntityListener listener);
+
+ /**
+ * Register to the context a TopiaEntityListener about the given entity
+ * class. <code>listener</code> instance will be notified AFTER any
+ * operation on the entity.
+ *
+ * @param entityClass the TopiaEntity's class to listen
+ * @param listener the listener instance to register
+ */
+ void addTopiaEntityListener(Class<? extends TopiaEntity> entityClass,
+ TopiaEntityListener listener);
+
+ /**
+ * Unregister the given TopiaEntityListener about any TopiaEntity from the
+ * context
+ *
+ * @param listener the listener instance to unregister
+ */
+ void removeTopiaEntityListener(TopiaEntityListener listener);
+
+ /**
+ * Unregister the given TopiaEntityListener about the given entity class
+ * from the context
+ *
+ * @param entityClass the listened TopiaEntity's class
+ * @param listener the listener instance to unregister
+ */
+ void removeTopiaEntityListener(Class<? extends TopiaEntity> entityClass,
+ TopiaEntityListener listener);
+
+
+ /* TopiaEntityVetoable */
+
+ /**
+ * Register to the context a TopiaEntityVetoable about any TopiaEntity.
+ * <code>vetoable</code> instance will be notified BEFORE any operation on
+ * the entity.
+ *
+ * @param vetoable the vetoable instance to register
+ */
+ void addTopiaEntityVetoable(TopiaEntityVetoable vetoable);
+
+ /**
+ * Register to the context a TopiaEntityVetoable about the given entity
+ * class. <code>vetoable</code> instance will be notified BEFORE any
+ * operation on the entity.
+ *
+ * @param entityClass the TopiaEntity's class to listen
+ * @param vetoable the vetoable instance to register
+ */
+ void addTopiaEntityVetoable(Class<? extends TopiaEntity> entityClass,
+ TopiaEntityVetoable vetoable);
+
+ /**
+ * Unregister the given TopiaEntityVetoable about any TopiaEntity from the
+ * context
+ *
+ * @param vetoable the vetoable instance to unregister
+ */
+ void removeTopiaEntityVetoable(TopiaEntityVetoable vetoable);
+
+ /**
+ * Unregister the given TopiaEntityVetoable about the given entity class
+ * from the context
+ *
+ * @param entityClass the listened TopiaEntity's class
+ * @param vetoable the vetoable instance to unregister
+ */
+ void removeTopiaEntityVetoable(Class<? extends TopiaEntity> entityClass,
+ TopiaEntityVetoable vetoable);
+
+
+ /* TopiaEntitiesVetoable */
+
+ /**
+ * Register to the context a TopiaEntitiesVetoable about any TopiaEntity.
+ * <code>vetoable</code> instance will be notified BEFORE any entity load
+ *
+ * @param vetoable the vetoable instance to register
+ */
+ void addTopiaEntitiesVetoable(TopiaEntitiesVetoable vetoable);
+
+ /**
+ * Unregister the given TopiaEntitiesVetoable about any TopiaEntity from the
+ * context
+ *
+ * @param vetoable the vetoable instance to unregister
+ */
+ void removeTopiaEntitiesVetoable(TopiaEntitiesVetoable vetoable);
+
+
+ /* TopiaTransactionListener */
+
+ /**
+ * Register to the context a TopiaTransactionListener about the transaction.
+ * <code>listener</code> instance will be notified AFTER any operation on
+ * the transaction.
+ *
+ * @param listener the listener instance to register
+ */
+ void addTopiaTransactionListener(TopiaTransactionListener listener);
+
+ /**
+ * Unregister the given TopiaTransactionListener about the transaction from
+ * the context
+ *
+ * @param listener the listener instance to unregister
+ */
+ void removeTopiaTransactionListener(TopiaTransactionListener listener);
+
+
+ /* TopiaTransactionVetoable */
+
+ /**
+ * Register to the context a TopiaTransactionVetoable about the transaction.
+ * <code>vetoable</code> instance will be notified BEFORE any operation on
+ * the transaction.
+ *
+ * @param vetoable the vetoable instance to register
+ */
+ void addTopiaTransactionVetoable(TopiaTransactionVetoable vetoable);
+
+ /**
+ * Unregister the given TopiaTransactionVetoable about the transaction from
+ * the context
+ *
+ * @param vetoable the vetoable instance to unregister
+ */
+ void removeTopiaTransactionVetoable(TopiaTransactionVetoable vetoable);
+
+
+ /* PropertyChangeListener */
+
+ /**
+ * Register to the context a PropertyChangeListener about some entity's
+ * property change. <code>listener</code> instance will be notified AFTER
+ * any change on the entity's property
+ *
+ * @param listener the listener instance to register
+ */
+ void addPropertyChangeListener(PropertyChangeListener listener);
+
+ /**
+ * Unregister the given PropertyChangeListener about some entity's
+ * property change from the context
+ *
+ * @param listener the listener instance to unregister
+ */
+ void removePropertyChangeListener(PropertyChangeListener listener);
+
+
+ /* TopiaSchemaListener */
+
+ /**
+ * Register to the context a TopiaSchemaListener about any schema
+ * modification. <code>listener</code> instance will be notified BEFORE and
+ * AFTER any change on the schema
+ *
+ * @param listener the listener instance to register
+ */
+ void addTopiaSchemaListener(TopiaSchemaListener listener);
+
+ /**
+ * Unregister the given TopiaSchemaListener about any schema modification
+ * from the context
+ *
+ * @param listener the listener instance to unregister
+ */
+ void removeTopiaSchemaListener(TopiaSchemaListener listener);
+
+
+}
Property changes on: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaListenable.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Added: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaPersistenceContext.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaPersistenceContext.java (rev 0)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaPersistenceContext.java 2013-08-02 16:21:12 UTC (rev 2785)
@@ -0,0 +1,141 @@
+package org.nuiton.topia;
+
+/*
+ * #%L
+ * ToPIA :: Persistence
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2004 - 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 java.util.List;
+import java.util.Properties;
+
+import org.nuiton.topia.persistence.TopiaDAO;
+import org.nuiton.topia.persistence.TopiaEntity;
+import org.nuiton.topia.persistence.TopiaIdFactory;
+
+/**
+ * @author Arnaud Thimel <thimel(a)codelutin.com>
+ */
+public interface TopiaPersistenceContext {
+
+ /**
+ * Retrieve {@link org.nuiton.topia.persistence.TopiaEntity} using its unique {@code id}.
+ *
+ * @param topiaId unique identifier of the entity in all the application.
+ * @return the entity found or null
+ * @throws TopiaException for errors on retrieving the entity
+ */
+ <E extends TopiaEntity> E findByTopiaId(String topiaId) throws TopiaException;
+
+ /**
+ * Add into this TopiaContext an entity created by another TopiaContext
+ *
+ * @param e the entity to add
+ * @throws TopiaException if any exception
+ */
+ void update(TopiaEntity e) throws TopiaException;
+
+ /**
+ * Triggers database schema creation
+ *
+ * @throws TopiaException if any exception
+ */
+ void createSchema() throws TopiaException;
+
+ /**
+ * Displays the SQL queries that would be used for a schema creation
+ *
+ * @throws TopiaException if any exception
+ */
+ void showCreateSchema() throws TopiaException;
+
+ /**
+ * Triggers database schema update
+ *
+ * @throws TopiaException if any exception
+ */
+ void updateSchema() throws TopiaException;
+
+ /**
+ * Triggers database schema drop
+ *
+ * @throws TopiaException if any exception
+ * @since 3.0
+ */
+ void dropSchema() throws TopiaException;
+
+ /**
+ * @return Returns the config.
+ */
+ Properties getConfig(); // TODO AThimel 02/08/13 Change type ?
+
+ // TODO AThimel 02/08/13 Javadoc
+ TopiaIdFactory getTopiaIdFactory();
+
+ /**
+ * Tells to the context if it has to use a flush mode before each query.
+ *
+ * By default, we use a flush mode, but in some case it costs to much doing
+ * this, that's why you can desactivate it setting the value to {@code false}.
+ *
+ * @param useFlushMode the new value to set
+ * @since 2.5
+ */
+ void setUseFlushMode(boolean useFlushMode);
+
+ /**
+ * Detect if the table is created on storage for a given persistant class.
+ *
+ * @param clazz the researched class
+ * @return Returns the hibernate.
+ * @throws TopiaException si aucune transaction n'est ouverte
+ */
+ boolean isSchemaExist(Class<?> clazz) throws TopiaException;
+
+ /**
+ * Get DAO for specified class. If Specialized DAO exists then it returned
+ * otherwize TopiaDAO<entityClass> is returned
+ *
+ * @param <E> type of entity
+ * @param entityClass type of entity
+ * @return the required dao
+ * @throws TopiaException if any error
+ */
+ <E extends TopiaEntity> TopiaDAO<E> getDAO(Class<E> entityClass)
+ throws TopiaException;
+
+ /**
+ * Get DAO for specified class. If Specialized DAO exists then it returned
+ * otherwize TopiaDAO<entityClass> is returned
+ *
+ * @param <E> type of entity
+ * @param entityClass type of entity
+ * @param daoClass the concrete dao class to use
+ * @return the required dao
+ * @throws TopiaException if any error
+ */
+ <E extends TopiaEntity, D extends TopiaDAO<E>> D getDAO(Class<E> entityClass,Class<D> daoClass)
+ throws TopiaException;
+
+ // TODO AThimel 02/08/13 Javadoc
+ List<Class<?>> getPersistenceClasses();
+
+}
Property changes on: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaPersistenceContext.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Added: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaReplicationSupport.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaReplicationSupport.java (rev 0)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaReplicationSupport.java 2013-08-02 16:21:12 UTC (rev 2785)
@@ -0,0 +1,89 @@
+package org.nuiton.topia;
+
+/*
+ * #%L
+ * ToPIA :: Persistence
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2004 - 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 java.util.List;
+
+import org.nuiton.topia.persistence.TopiaEntity;
+
+/**
+ * @author Arnaud Thimel <thimel(a)codelutin.com>
+ */
+public interface TopiaReplicationSupport {
+
+
+ /**
+ * Makes a replication of some entities from this context to the given
+ * context without any entity modification.
+ * <p/>
+ * <b>Note:</b> If the <code>entityAndCondition</code> parameter is empty,
+ * all the database will be replicated
+ * <p/>
+ * <b>Note 2:</b> The simple replication may not be sufficent. You may want
+ * to replicate only a part of some entities : use the method {@link
+ * #replicateEntities(TopiaContext, java.util.List)}.
+ *
+ * @param destinationContext the destination context
+ * @param entityAndCondition [key;value;...] parameter which key is the
+ * entity class to replicate, and value the
+ * "where" condition to use when querying entities
+ * @throws TopiaException if any problem occurred during replicate
+ * @throws IllegalArgumentException if one of the context is closed or if
+ * trying to replicate within the same
+ * database
+ */
+ void replicate(TopiaContext destinationContext,
+ Object... entityAndCondition) throws TopiaException, IllegalArgumentException;
+
+ /**
+ * Replicate a given entity from this context to the given context.
+ *
+ * @param destinationContext the destination context
+ * @param entity the entity instance to replicate
+ * @param <T> type of the entity to replicate
+ * @throws TopiaException if any problem occurred during replicate
+ * @throws IllegalArgumentException if one of the context is closed or if
+ * trying to replicate within the same
+ * database
+ */
+ <T extends TopiaEntity> void replicateEntity(TopiaContext destinationContext,
+ T entity) throws TopiaException, IllegalArgumentException;
+
+ /**
+ * Makes a replication of some entities from this context to the given
+ * context without any entity modification.
+ *
+ * @param destinationContext the destination context
+ * @param entities the list of entities instance to replicate
+ * @param <T> type of the entities to replicate
+ * @throws TopiaException if any problem occurred during replicate
+ * @throws IllegalArgumentException if one of the context is closed or if
+ * trying to replicate within the same
+ * database
+ */
+ <T extends TopiaEntity> void replicateEntities(TopiaContext destinationContext,
+ List<T> entities) throws TopiaException, IllegalArgumentException;
+
+}
Property changes on: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaReplicationSupport.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Added: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaServiceSupport.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaServiceSupport.java (rev 0)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaServiceSupport.java 2013-08-02 16:21:12 UTC (rev 2785)
@@ -0,0 +1,58 @@
+package org.nuiton.topia;
+
+/*
+ * #%L
+ * ToPIA :: Persistence
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2004 - 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 java.util.Map;
+
+import org.nuiton.topia.framework.TopiaService;
+
+/**
+ * @author Arnaud Thimel <thimel(a)codelutin.com>
+ */
+public interface TopiaServiceSupport {
+
+ /**
+ * Return true if specific service is available.
+ *
+ * @param <E> type of service
+ * @param interfaceService fqn of the service
+ * @return the service
+ */
+ <E extends TopiaService> boolean serviceEnabled(Class<E> interfaceService);
+
+ /**
+ * Return the service. This service must be valid with public static final
+ * SERVICE_NAME property.
+ *
+ * @param <E> type of service
+ * @param interfaceService class of the service
+ * @return the service
+ * @throws TopiaNotFoundException if service can't be retrieved
+ */
+ <E extends TopiaService> E getService(Class<E> interfaceService) throws TopiaNotFoundException;
+
+ Map<String, TopiaService> getServices();
+
+}
Property changes on: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaServiceSupport.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Added: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaSqlSupport.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaSqlSupport.java (rev 0)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaSqlSupport.java 2013-08-02 16:21:12 UTC (rev 2785)
@@ -0,0 +1,40 @@
+package org.nuiton.topia;
+
+/*
+ * #%L
+ * ToPIA :: Persistence
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2004 - 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%
+ */
+
+/**
+ * @author Arnaud Thimel <thimel(a)codelutin.com>
+ */
+public interface TopiaSqlSupport {
+
+ /**
+ * Execute a given sql code inside this transaction.
+ *
+ * @param sqlScript the sql script to execute
+ * @throws TopiaException if any problem occurred while executing the sql script.
+ */
+ void executeSQL(String sqlScript) throws TopiaException;
+
+}
Property changes on: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaSqlSupport.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Added: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaTransaction.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaTransaction.java (rev 0)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaTransaction.java 2013-08-02 16:21:12 UTC (rev 2785)
@@ -0,0 +1,72 @@
+package org.nuiton.topia;
+
+/*
+ * #%L
+ * ToPIA :: Persistence
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2004 - 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%
+ */
+
+/**
+ * @author Arnaud Thimel <thimel(a)codelutin.com>
+ */
+public interface TopiaTransaction {
+
+ /**
+ * Returns a new context containing its own transaction.
+ *
+ * @return new context with transaction
+ * @throws TopiaException if any exception
+ */
+ TopiaContext beginTransaction() throws TopiaException;
+
+ /**
+ * Applies all the modifications made to this context on the persistence
+ * device. Once commit is done, a new transaction is started.
+ *
+ * @throws TopiaException if any exception
+ */
+ void commitTransaction() throws TopiaException;
+
+ /**
+ * Cancels all the modifications made to this context, coming back to the
+ * state on the last beginTransaction. Once rollback is done, a new
+ * transaction is started.
+ *
+ * @throws TopiaException if any exception
+ */
+ void rollbackTransaction() throws TopiaException;
+
+ /**
+ * Closes the context. All the children contexts will be closed in the same
+ * time.
+ *
+ * @throws TopiaException if any exception
+ */
+ void closeContext() throws TopiaException;
+
+ /**
+ * Tells if the context is closed
+ *
+ * @return {@code true} if the context is closed, {@code false} otherwise
+ */
+ boolean isClosed();
+
+}
Property changes on: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaTransaction.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaContextImpl.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaContextImpl.java 2013-07-25 17:03:03 UTC (rev 2784)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaContextImpl.java 2013-08-02 16:21:12 UTC (rev 2785)
@@ -25,6 +25,29 @@
package org.nuiton.topia.framework;
+import java.beans.PropertyChangeListener;
+import java.io.BufferedInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStream;
+import java.lang.reflect.Field;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+import java.util.WeakHashMap;
+import java.util.zip.GZIPInputStream;
+
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -64,29 +87,6 @@
import org.nuiton.topia.persistence.TopiaEntity;
import org.nuiton.topia.persistence.TopiaIdFactory;
-import java.beans.PropertyChangeListener;
-import java.io.BufferedInputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.InputStream;
-import java.lang.reflect.Field;
-import java.sql.Connection;
-import java.sql.PreparedStatement;
-import java.sql.SQLException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-import java.util.Set;
-import java.util.WeakHashMap;
-import java.util.zip.GZIPInputStream;
-
/**
* Le TopiaContextImpl est le point d'entre pour acceder aux donnees. Il est
* configurer par un fichier de propriete
@@ -115,13 +115,19 @@
//TODO-fdesbois-20100507 : Need translation of javadoc.
public class TopiaContextImpl implements TopiaContextImplementor {
- /** to use log facility, just put in your code: log.info(\"...\"); */
+ /**
+ * to use log facility, just put in your code: log.info(\"...\");
+ */
private static final Log log = LogFactory.getLog(TopiaContextImpl.class);
- /** Le pere de ce context, les contexts initaux n'ont pas de context pere */
+ /**
+ * Le pere de ce context, les contexts initaux n'ont pas de context pere
+ */
protected TopiaContextImplementor parentContext;
- /** L'objet configuration utilisé pour la creation de la factory hibernate */
+ /**
+ * L'objet configuration utilisé pour la creation de la factory hibernate
+ */
protected Configuration hibernateConfiguration;
/**
@@ -130,28 +136,35 @@
*/
protected SessionFactory hibernateFactory;
- /** La session utilisé par le TopiaContextImpl */
+ /**
+ * La session utilisé par le TopiaContextImpl
+ */
protected Session hibernate;
- /** Indique si le contexte a ete ferme */
+ /**
+ * Indique si le contexte a ete ferme
+ */
protected boolean closed;
/**
* This flag permits to use (or not) the flush mode when doing queries.
- *
+ * <p/>
* The normal usage is to says yes (that's why the default value is
* {@code true}), in that case whebn doing queries (says in method
* {@link #findAll(String, Object...)} or {@link #find(String, int, int, Object...)})
* it will use the flush mode {@link FlushMode#AUTO}).
- *
+ * <p/>
* But sometimes, when doing a lot of queries (for some imports for example),
* we do NOT want the session to be flushed each time we do a find, then you
* can set this flag to {@code false} using the method {@link #setUseFlushMode(boolean)}
+ *
* @since 2.5
*/
protected boolean useFlushMode = true;
- /** Propriete de configuration */
+ /**
+ * Propriete de configuration
+ */
protected Properties config;
/**
@@ -161,7 +174,9 @@
*/
protected TopiaIdFactory topiaIdFactory;
- /** cache des DAO deja chargé pour ce context */
+ /**
+ * cache des DAO deja chargé pour ce context
+ */
protected Map<Class<? extends TopiaEntity>,
TopiaDAO<? extends TopiaEntity>> daoCache =
new HashMap<Class<? extends TopiaEntity>,
@@ -182,15 +197,21 @@
Collections.newSetFromMap(
new WeakHashMap<TopiaContextImplementor, Boolean>()));
- /** key: service name; value: service instance */
+ /**
+ * key: service name; value: service instance
+ */
protected Map<String, TopiaService> services;
protected TopiaFiresSupport firesSupport = new TopiaFiresSupport();
- /** Liste des classes perssitance */
+ /**
+ * Liste des classes perssitance
+ */
protected List<Class<?>> persistenceClasses = new ArrayList<Class<?>>();
- /** Default constructor, useful for tests. */
+ /**
+ * Default constructor, useful for tests.
+ */
protected TopiaContextImpl() {
}
@@ -248,7 +269,7 @@
protected Map<String, TopiaService> loadServices(Properties config) {
Map<String, TopiaService> result = new HashMap<String, TopiaService>();
// recherche des services present dans la config
- for (Enumeration<?> e = config.propertyNames(); e.hasMoreElements();) {
+ for (Enumeration<?> e = config.propertyNames(); e.hasMoreElements(); ) {
String key = (String) e.nextElement();
if (key.matches("^topia\\.service\\.\\w+$")) {
String classService = config.getProperty(key);
@@ -455,7 +476,7 @@
/**
* Change the value of flag {@link #useFlushMode}.
- *
+ *
* @param useFlushMode the new value to set
* @see #useFlushMode
* @since 2.5
@@ -520,22 +541,20 @@
if (log.isDebugEnabled()) {
showSchema = true;
}
- getFiresSupport().firePreCreateSchema(this);
+ getFiresSupport().firePreDropSchema(this);
new SchemaExport(getHibernateConfiguration()).execute(showSchema, true, true, false);
- getFiresSupport().firePostCreateSchema(this);
+ getFiresSupport().firePostDropSchema(this);
} catch (HibernateException eee) {
throw new TopiaException(
String.format("Could not drop schema for reason: %s",
- eee.getMessage()), eee);
+ eee.getMessage()), eee);
}
}
@Override
public Session getHibernate() throws TopiaException {
- if (hibernate == null) {
- throw new TopiaException("No hibernate session");
- }
- return hibernate;
+ Session result = getHibernateSession();
+ return result;
}
@Override
@@ -546,9 +565,9 @@
} else {
// init service registry
- ServiceRegistry serviceRegistry = new ServiceRegistryBuilder().applySettings(
+ ServiceRegistry serviceRegistry = new ServiceRegistryBuilder().applySettings(
getHibernateConfiguration().getProperties()).buildServiceRegistry();
-
+
hibernateFactory = getHibernateConfiguration().buildSessionFactory(serviceRegistry);
// we can't reuse original serviceRegistry instance
@@ -564,7 +583,7 @@
eventListenerRegistry.appendListeners(EventType.POST_LOAD, listener);
eventListenerRegistry.appendListeners(EventType.POST_UPDATE, listener);
eventListenerRegistry.appendListeners(EventType.POST_DELETE, listener);
-
+
// following listeners must be called before hibernate
eventListenerRegistry.prependListeners(EventType.SAVE_UPDATE, listener);
}
@@ -619,7 +638,7 @@
if (log.isDebugEnabled()) {
log.debug("Load persistent class : " + classname);
}
-
+
// XXX echatellier 20111007 ce cqui est dommage ici, c'est
// la definition de cette classe ne sert a rien (apart security)
// car pour hibernate hibernateConfiguration.addClass(persistanceClass)
@@ -636,7 +655,7 @@
}
throw new TopiaNotFoundException(
String.format("Persistence class %1$s not found",
- classname));
+ classname));
}
persistenceClasses.add(clazz);
@@ -751,7 +770,7 @@
// on ne synchronise jamais les données avec la base tant que
// l'utilisateur n'a pas fait de commit du context
result.hibernate.setFlushMode(FlushMode.MANUAL);
-
+
// tchemit 2010-12-06 propagates the value of the flag
result.useFlushMode = useFlushMode;
@@ -776,7 +795,7 @@
throw new TopiaException(
String.format("An error occurs while asking a new transaction: %1$s",
- eee.getMessage()),
+ eee.getMessage()),
eee);
}
@@ -953,12 +972,12 @@
}
@Override
- public <E> List<E> findAll(String hql, Object... propertyNamesAndValues) throws TopiaException {
+ public <E> List<E> findAll(String jpaql, Object... propertyNamesAndValues) throws TopiaException {
checkClosed(String.format("This context is closed, it is not possible to release the operation '%1$s'",
"findAll"));
try {
- Query query = getHibernate().createQuery(hql);
+ Query query = getHibernate().createQuery(jpaql);
for (int j = 0; j < propertyNamesAndValues.length; j += 2) {
String name = (String) propertyNamesAndValues[j];
Object value = propertyNamesAndValues[j + 1];
@@ -979,18 +998,18 @@
return result;
} catch (HibernateException eee) {
throw new TopiaException(String.format("An error occurs while query operation: %1$s : %2$s",
- hql, eee.getMessage()), eee);
+ jpaql, eee.getMessage()), eee);
}
}
@Override
- public <E> List<E> find(String hql, int startIndex, int endIndex, Object... propertyNamesAndValues)
+ public <E> List<E> find(String jpaql, int startIndex, int endIndex, Object... propertyNamesAndValues)
throws TopiaException {
checkClosed(String.format("This context is closed, it is not possible to release the operation '%1$s'",
"find"));
try {
- Query query = getHibernate().createQuery(hql);
+ Query query = getHibernate().createQuery(jpaql);
for (int j = 0; j < propertyNamesAndValues.length; j += 2) {
String name = (String) propertyNamesAndValues[j];
Object value = propertyNamesAndValues[j + 1];
@@ -1013,22 +1032,22 @@
return result;
} catch (HibernateException eee) {
throw new TopiaException(String.format("An error occurs while query operation: %1$s : %2$s",
- hql, eee.getMessage()), eee);
+ jpaql, eee.getMessage()), eee);
}
}
@Override
- public <E> E findUnique(String hql, Object... propertyNamesAndValues)
+ public <E> E findUnique(String jpaql, Object... propertyNamesAndValues)
throws TopiaException {
checkClosed(String.format("This context is closed, it is not possible to release the operation '%1$s'",
"findUnique"));
- List<E> results = find(hql, 0, 1, propertyNamesAndValues);
+ List<E> results = find(jpaql, 0, 1, propertyNamesAndValues);
// If there is more than 1 result, throw an exception
if (results.size() > 1) {
String message = String.format(
- "Query '%s' returns more than 1 unique result", hql);
+ "Query '%s' returns more than 1 unique result", jpaql);
throw new TopiaException(message);
}
@@ -1043,18 +1062,18 @@
/**
* Execute HQL operation on data (Update, Delete)
*
- * @param hql HQL query
+ * @param jpaql HQL query
* @param propertyNamesAndValues arguments for query
* @return The number of entities updated or deleted.
* @throws TopiaException
*/
@Override
- public int execute(String hql, Object... propertyNamesAndValues) throws TopiaException {
+ public int execute(String jpaql, Object... propertyNamesAndValues) throws TopiaException {
checkClosed(String.format("This context is closed, it is not possible to release the operation '%1$s'",
"find"));
try {
- Query query = getHibernate().createQuery(hql);
+ Query query = getHibernate().createQuery(jpaql);
for (int j = 0; j < propertyNamesAndValues.length; j += 2) {
query.setParameter((String) propertyNamesAndValues[j], propertyNamesAndValues[j + 1]);
}
@@ -1062,27 +1081,16 @@
return result;
} catch (HibernateException eee) {
throw new TopiaException(String.format("An error occurs while query operation: %1$s : %2$s",
- hql, eee.getMessage()), eee);
+ jpaql, eee.getMessage()), eee);
}
}
@Override
public void add(TopiaEntity e) throws TopiaException {
- checkClosed(String.format("This context is closed, it is not possible to release the operation '%1$s'",
- "add"));
-
- String id = e.getTopiaId();
- Class<TopiaEntity> entityClass = getTopiaIdFactory().getClassName(id);
- TopiaDAO<TopiaEntity> dao = getDAO(entityClass);
- dao.update(e);
+ update(e);
}
@Override
- public void evict(TopiaEntity e) throws TopiaException {
- getHibernate().evict(e);
- }
-
- @Override
public void replicate(TopiaContext dstCtxt, Object... entityAndCondition)
throws TopiaException, IllegalArgumentException {
checkClosed(String.format("This context is closed, it is not possible to release the operation '%1$s'",
@@ -1158,12 +1166,12 @@
/**
* Backup database in gzip compressed file.
- *
+ * <p/>
* <b>Note: </b> Only works for h2 database.
*
* @param file file to write backup
* @param compress if true then use gzip to compress file
- * @see TopiaContext#backup(File,boolean)
+ * @see TopiaContext#backup(File, boolean)
*/
@Override
public void backup(File file, boolean compress) throws TopiaException {
@@ -1206,7 +1214,7 @@
// decompresse file in temporary file
InputStream in = new BufferedInputStream(new FileInputStream(file));
try {
- in.mark(2);
+ in.mark(2);
// read header to see if is compressed file
int b = in.read();
@@ -1224,7 +1232,7 @@
SQLQuery query = getHibernate().createSQLQuery(
"RUNSCRIPT FROM '" + file.getAbsolutePath() + "'" + options);
-
+
query.executeUpdate();
// send event AFTER restore
@@ -1232,7 +1240,7 @@
} catch (Exception eee) {
throw new TopiaException(String.format(
String.format("An error occurs while restore operation: %1$s : %2$s",
- sql, eee.getMessage())), eee);
+ sql, eee.getMessage())), eee);
}
}
@@ -1263,7 +1271,7 @@
/**
* Clear hibernate cache to free memory.
- *
+ * <p/>
* see http://docs.jboss.org/hibernate/orm/3.5/reference/en-US/html/transactions.h…
*/
@Override
@@ -1425,7 +1433,7 @@
// si entityAndcondition est vide alors il faut le remplir
// avec toutes les entités du mapping (class, null)
if (entityAndCondition.length == 0) {
- Map<?,?> classMetadata = getHibernateFactory().getAllClassMetadata();
+ Map<?, ?> classMetadata = getHibernateFactory().getAllClassMetadata();
entityAndCondition = new Object[classMetadata.size() * 2];
int i = 0;
for (Object className : classMetadata.keySet()) {
@@ -1447,7 +1455,7 @@
"entityAndCondition must be a couple of (Class, String)");
}
String queries[] = new String[entityAndCondition.length / 2];
- for (int i = 0; i < entityAndCondition.length;) {
+ for (int i = 0; i < entityAndCondition.length; ) {
try {
entityClass = (Class<?>) entityAndCondition[i++];
condition = (String) entityAndCondition[i++];
@@ -1506,5 +1514,25 @@
}
}
}
+
+ @Override
+ public Session getHibernateSession() throws TopiaException {
+ if (hibernate == null) {
+ throw new TopiaException("No hibernate session");
+ }
+ return hibernate;
+ }
+
+ @Override
+ public void update(TopiaEntity e) throws TopiaException {
+ checkClosed(String.format("This context is closed, it is not possible to release the operation '%1$s'",
+ "add"));
+
+ String id = e.getTopiaId();
+ Class<TopiaEntity> entityClass = getTopiaIdFactory().getClassName(id);
+ TopiaDAO<TopiaEntity> dao = getDAO(entityClass);
+ dao.update(e);
+ }
+
} //TopiaContextImpl
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaContextImplementor.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaContextImplementor.java 2013-07-25 17:03:03 UTC (rev 2784)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaContextImplementor.java 2013-08-02 16:21:12 UTC (rev 2785)
@@ -30,6 +30,7 @@
import org.hibernate.cfg.Configuration;
import org.nuiton.topia.TopiaContext;
import org.nuiton.topia.TopiaException;
+import org.nuiton.topia.TopiaHibernate;
import org.nuiton.topia.TopiaNotFoundException;
import org.nuiton.topia.persistence.TopiaDAO;
import org.nuiton.topia.persistence.TopiaEntity;
@@ -50,42 +51,65 @@
* @version $Id$
*/
//TODO-fdesbois-20100507 : Need more javadoc.
-public interface TopiaContextImplementor extends TopiaContext {
+@Deprecated
+public interface TopiaContextImplementor extends TopiaContext, TopiaHibernate {
/**
* Retrieve a thread-safe copy of children context set.
*
* @return Returns the childContext.
+ * @deprecated Hierarchical context are not supported anymore
*/
+ @Deprecated
Set<TopiaContextImplementor> getChildContext();
- /** @return Returns the parentContext. */
+ /**
+ * @return Returns the parentContext.
+ * @deprecated Hierarchical context are not supported anymore
+ */
+ @Deprecated
TopiaContextImplementor getParentContext();
+ /**
+ * @deprecated Hierarchical context are not supported anymore
+ */
+ @Deprecated
TopiaContextImplementor getRootContext();
- /** @return Returns the config. */
+ /**
+ * @deprecated Hierarchical context are not supported anymore
+ */
+ @Deprecated
+ void removeChildContext(TopiaContextImplementor child);
+
+ /** @return Returns the config.
+ * @deprecated use method from {@link org.nuiton.topia.TopiaPersistenceContext}
+ */
+ @Deprecated
Properties getConfig();
- // TODO brendan 05/07/13 expose it in TopiaContext ?
- TopiaIdFactory getTopiaIdFactory();
-
/**
* @return Returns the hibernate.
* @throws TopiaException si aucune transaction n'est ouverte
+ * @deprecated use method from {@link TopiaHibernate}
*/
+ @Deprecated
Session getHibernate() throws TopiaException;
/**
* @return Returns the hibernateFactory.
* @throws TopiaNotFoundException
+ * @deprecated use method from {@link TopiaHibernate}
*/
+ @Deprecated
SessionFactory getHibernateFactory() throws TopiaNotFoundException;
/**
* @return Returns the hibernate configuration
* @throws TopiaNotFoundException
+ * @deprecated use method from {@link TopiaHibernate}
*/
+ @Deprecated
Configuration getHibernateConfiguration()
throws TopiaNotFoundException;
@@ -97,15 +121,20 @@
*
* @param useFlushMode the new value to set
* @since 2.5
+ * @deprecated use method from {@link org.nuiton.topia.TopiaPersistenceContext}
*/
+ @Deprecated
void setUseFlushMode(boolean useFlushMode);
+
/**
* Detect if the table is created on storage for a given persistant class.
*
* @param clazz the researched class
* @return Returns the hibernate.
* @throws TopiaException si aucune transaction n'est ouverte
+ * @deprecated use method from {@link org.nuiton.topia.TopiaPersistenceContext}
*/
+ @Deprecated
boolean isSchemaExist(Class<?> clazz) throws TopiaException;
/**
@@ -116,7 +145,9 @@
* @param entityClass type of entity
* @return the required dao
* @throws TopiaException if any error
+ * @deprecated use method from {@link org.nuiton.topia.TopiaPersistenceContext}
*/
+ @Deprecated
<E extends TopiaEntity> TopiaDAO<E> getDAO(Class<E> entityClass)
throws TopiaException;
@@ -129,16 +160,29 @@
* @param daoClass the concrete dao class to use
* @return the required dao
* @throws TopiaException if any error
+ * @deprecated use method from {@link org.nuiton.topia.TopiaPersistenceContext}
*/
+ @Deprecated
<E extends TopiaEntity, D extends TopiaDAO<E>> D getDAO(Class<E> entityClass,Class<D> daoClass)
throws TopiaException;
+ /**
+ * @deprecated internal usage
+ */
+ @Deprecated
TopiaFiresSupport getFiresSupport();
- void removeChildContext(TopiaContextImplementor child);
-
+ /**
+ * @deprecated use methods from {@link org.nuiton.topia.TopiaServiceSupport}
+ */
+ @Deprecated
Map<String, TopiaService> getServices();
+ /**
+ * @deprecated use method from {@link org.nuiton.topia.TopiaPersistenceContext}
+ */
+ @Deprecated
List<Class<?>> getPersistenceClasses();
+
} //TopiaContextImplementor
Modified: trunk/topia-service-migration/pom.xml
===================================================================
--- trunk/topia-service-migration/pom.xml 2013-07-25 17:03:03 UTC (rev 2784)
+++ trunk/topia-service-migration/pom.xml 2013-08-02 16:21:12 UTC (rev 2785)
@@ -35,7 +35,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>topia</artifactId>
- <version>3.0-alpha-2-SNAPSHOT</version>
+ <version>3.0-SNAPSHOT</version>
</parent>
<groupId>org.nuiton.topia</groupId>
Modified: trunk/topia-service-replication/pom.xml
===================================================================
--- trunk/topia-service-replication/pom.xml 2013-07-25 17:03:03 UTC (rev 2784)
+++ trunk/topia-service-replication/pom.xml 2013-08-02 16:21:12 UTC (rev 2785)
@@ -35,7 +35,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>topia</artifactId>
- <version>3.0-alpha-2-SNAPSHOT</version>
+ <version>3.0-SNAPSHOT</version>
</parent>
<groupId>org.nuiton.topia</groupId>
Modified: trunk/topia-service-security/pom.xml
===================================================================
--- trunk/topia-service-security/pom.xml 2013-07-25 17:03:03 UTC (rev 2784)
+++ trunk/topia-service-security/pom.xml 2013-08-02 16:21:12 UTC (rev 2785)
@@ -35,7 +35,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>topia</artifactId>
- <version>3.0-alpha-2-SNAPSHOT</version>
+ <version>3.0-SNAPSHOT</version>
</parent>
<groupId>org.nuiton.topia</groupId>
1
0