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
June 2010
- 5 participants
- 63 discussions
r1998 - in trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration: . callback common kernel mappings transformation
by tchemit@users.nuiton.org 09 Jun '10
by tchemit@users.nuiton.org 09 Jun '10
09 Jun '10
Author: tchemit
Date: 2010-06-09 08:28:55 +0200 (Wed, 09 Jun 2010)
New Revision: 1998
Url: http://nuiton.org/repositories/revision/topia/1998
Log:
Evolution #670: Rethink the migration service and deprecates old versions
Modified:
trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/DatabaseManager.java
trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/ManualMigrationCallback.java
trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/ManualMigrationEngine.java
trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/MigrationService.java
trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/MigrationServiceImpl.java
trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/TopiaMigrationServiceImpl.java
trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/callback/MigrationCallbackHandler.java
trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/common/ExceptionAttributeUndefined.java
trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/common/MapAdapter.java
trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/common/MapAdapterAdmin.java
trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/common/MapAdapterImpl.java
trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/common/ProxyClass.java
trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/common/ProxyClassMapped.java
trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/common/SimpleProxyClass.java
trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/common/SimpleProxyClassMapped.java
trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/kernel/BaseException.java
trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/kernel/ConfigurationAdapter.java
trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/kernel/ConfigurationHelper.java
trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/kernel/DependenciesHelper.java
trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/kernel/NullMigrationClass.java
trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/kernel/ObjectNotFound.java
trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/kernel/Transformer.java
trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/mappings/TMSVersion.java
trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/transformation/AbstractMigration.java
trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/transformation/FinderMigration.java
trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/transformation/MapHelper.java
trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/transformation/Migration.java
trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/transformation/MigrationClass.java
trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/transformation/MigrationNull.java
Modified: trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/DatabaseManager.java
===================================================================
--- trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/DatabaseManager.java 2010-06-08 21:51:15 UTC (rev 1997)
+++ trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/DatabaseManager.java 2010-06-09 06:28:55 UTC (rev 1998)
@@ -25,16 +25,8 @@
package org.nuiton.topia.migration;
-import java.sql.Connection;
-import java.sql.SQLException;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Properties;
-
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.nuiton.util.Version;
-import org.nuiton.topia.migration.mappings.TMSVersion;
import org.hibernate.SQLQuery;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
@@ -51,43 +43,49 @@
import org.hibernate.tool.hbm2ddl.DatabaseMetadata;
import org.hibernate.tool.hbm2ddl.SchemaExport;
import org.hibernate.tool.hbm2ddl.TableMetadata;
+import org.nuiton.topia.migration.mappings.TMSVersion;
+import org.nuiton.util.Version;
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Properties;
+
/**
* DatabaseManager.java
- *
+ * <p/>
* Cette classe sert à acceder a la base, pour la version notement
* creer les schemas, renommer et supprimer les tables.
- *
+ *
* @author Chatellier Eric
* @author Chevallereau Benjamin
* @author Eon Sébastien
* @author Trève Vincent
* @version $Revision$
- *
- * Last update : $Date$
+ * @deprecated since 2.4, please use now the simplify service {@link TopiaMigrationEngine}
*/
+@Deprecated
public class DatabaseManager {
- /**
- * Session factory
- */
+ /** Session factory */
private SessionFactory sessionFactory;
+
/**
* Configuration pour se connecter a la base
* et manipuler la table version seulement
*/
private Configuration dbConfiguration;
- /**
- * Logger (common-logging)
- */
+
+ /** Logger (common-logging) */
private static Log logger = LogFactory.getLog(DatabaseManager.class);
- /**
- * Suffix du nom des tables : _tms_v0 par exemple
- */
+
+ /** Suffix du nom des tables : _tms_v0 par exemple */
private static String VERSIONNED_TABLES_SUFFIX = "_tmsv";
/**
* Constructeur
+ *
* @param pInfosConnexion Properties hibernate
*/
public DatabaseManager(Properties pInfosConnexion) {
@@ -113,6 +111,7 @@
/**
* Retourne la configuration Hibernate de la base.
+ *
* @return la configuration de la base
*/
public Configuration getDbConfiguration() {
@@ -121,7 +120,7 @@
/**
* @return une {@link Connection}, charge a l'appelant de la fermer par la
- * suite
+ * suite
*/
public Connection getConnection() {
Connection result = sessionFactory.openStatelessSession().connection();
@@ -130,6 +129,7 @@
/**
* Retourne la version de la base
+ *
* @return la version present en base, ou <tt>null</tt> si la version ne peut pas etre determinee
* @throws MigrationServiceException si un pb
*/
@@ -175,7 +175,7 @@
/**
* Renomme les tables en supprimant le suffixe
*
- * @param vdbVersion Version a ajouter
+ * @param vdbVersion Version a ajouter
* @param oldConfiguration Configuration contenant le schema
*/
public void renameTables(Configuration oldConfiguration, Version vdbVersion) {
@@ -276,6 +276,7 @@
/**
* Creer le nouveau schema pour l'application
+ *
* @param newConfiguration la configuration contenant le nouveau schema
*/
public void setApplicationSchemaInDatabase(Configuration newConfiguration) {
@@ -291,6 +292,7 @@
/**
* Creer un schema
+ *
* @param configuration la configuration contenant les schemas
*/
protected void createSchema(Configuration configuration) {
@@ -301,6 +303,7 @@
/**
* Supprimer un schema
+ *
* @param configuration la configuration contenant les schemas
*/
protected void dropSchema(Configuration configuration) {
@@ -309,9 +312,7 @@
schemaExport.drop(false, true);
}
- /**
- * Creer le schema pour la table "tms_version"
- */
+ /** Creer le schema pour la table "tms_version" */
public void createVersionTable() {
logger.debug("Adding table to put version");
@@ -326,6 +327,7 @@
/**
* Introduit la version du nouveau schema dans la base
+ *
* @param newVersion la version
*/
public void putVersionInDatabase(Version newVersion) {
@@ -376,7 +378,7 @@
/**
* Return table suffix name
- *
+ *
* @param version version
* @return suffix name
*/
@@ -387,9 +389,9 @@
/**
* Test si les tables correspondant a une configuration existent.
- *
+ * <p/>
* Test si au moins une table de la configuration existe.
- *
+ *
* @param configuration la configuration
* @return <tt>true</tt> si le schema existe
*/
@@ -425,9 +427,7 @@
return exist;
}
- /**
- * Se deconnecte
- */
+ /** Se deconnecte */
public void disconnect() {
//nettoye
sessionFactory.close();
Modified: trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/ManualMigrationCallback.java
===================================================================
--- trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/ManualMigrationCallback.java 2010-06-08 21:51:15 UTC (rev 1997)
+++ trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/ManualMigrationCallback.java 2010-06-09 06:28:55 UTC (rev 1998)
@@ -25,12 +25,6 @@
package org.nuiton.topia.migration;
-import java.lang.reflect.Method;
-import java.sql.Connection;
-import java.sql.PreparedStatement;
-import java.sql.SQLException;
-import java.util.List;
-
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.jdbc.Work;
@@ -39,6 +33,13 @@
import org.nuiton.topia.framework.TopiaContextImplementor;
import org.nuiton.util.StringUtil;
import org.nuiton.util.Version;
+
+import java.lang.reflect.Method;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+import java.util.List;
+
import static org.nuiton.i18n.I18n._;
/**
@@ -46,17 +47,15 @@
*
* @author tchemit <chemit(a)codelutin.com>
* @version $Revision$
- *
- * Last update : $Date$
- * By : */
+ * @deprecated since 2.4, please use now the simplify service {@link TopiaMigrationCallback}
+ */
+@Deprecated
public abstract class ManualMigrationCallback {
/** Logger */
static private Log log = LogFactory.getLog(ManualMigrationCallback.class);
- /**
- * CallbackHandler return type.
- */
+ /** CallbackHandler return type. */
public enum MigrationChoice {
// no migration
@@ -74,23 +73,23 @@
/**
* Tentative de migration depuis la version de la base version la version
* souhaitee.
- *
+ * <p/>
* On applique toutes les migrations de version indiquee dans le parametre
* <code>version</code>.
- *
+ * <p/>
* Pour chaque version, on cherche la methode migrateTo_XXX ou XXX est la
* version transforme en identifiant java via la methode
* {@link Version#getValidName()} et on l'execute.
- *
+ * <p/>
* Note: pour chaque version a appliquer, on ouvre une nouvelle transaction.
*
- * @param ctxt topia context de la transaction en cours
- * @param dbVersion database version
+ * @param ctxt topia context de la transaction en cours
+ * @param dbVersion database version
* @param applicationVersion application version
- * @param showSql drapeau pour afficher les requete sql
- * @param showProgression drapeau pour afficher la progression
- * @param versions all versions knwon by service @return migration a
- * ggrement
+ * @param showSql drapeau pour afficher les requete sql
+ * @param showProgression drapeau pour afficher la progression
+ * @param versions all versions knwon by service @return migration a
+ * ggrement
* @return le choix de migration executee
*/
public MigrationChoice doMigration(TopiaContext ctxt, Version dbVersion,
@@ -119,9 +118,9 @@
Method m;
try {
m = getClass().getMethod(methodName,
- TopiaContextImplementor.class,
- boolean.class,
- boolean.class);
+ TopiaContextImplementor.class,
+ boolean.class,
+ boolean.class);
m.setAccessible(true);
@@ -137,7 +136,7 @@
} catch (NoSuchMethodException e) {
// try with no boolean values (for legacy callbacks)
m = getClass().getMethod(methodName,
- TopiaContextImplementor.class);
+ TopiaContextImplementor.class);
m.setAccessible(true);
@@ -184,10 +183,10 @@
/**
* Executes the given {@code sqls} requests.
*
- * @param tx the session
- * @param showSql flag to see sql requests
+ * @param tx the session
+ * @param showSql flag to see sql requests
* @param showProgression flag to see progession on console
- * @param sqls requests to execute
+ * @param sqls requests to execute
* @throws TopiaException if any pb
* @since 2.3.0
*/
@@ -205,13 +204,13 @@
for (String s : sqls) {
buffer.append(s).append("\n");
}
- log.info("SQL TO EXECUTE :\n" +
- "--------------------------------------------------------------------------------\n" +
- "--------------------------------------------------------------------------------\n" +
- buffer.toString() +
- "--------------------------------------------------------------------------------\n" +
- "--------------------------------------------------------------------------------\n"
- );
+ log.info("SQL TO EXECUTE :\n" +
+ "--------------------------------------------------------------------------------\n" +
+ "--------------------------------------------------------------------------------\n" +
+ buffer.toString() +
+ "--------------------------------------------------------------------------------\n" +
+ "--------------------------------------------------------------------------------\n"
+ );
}
tx.getHibernate().doWork(new Work() {
Modified: trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/ManualMigrationEngine.java
===================================================================
--- trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/ManualMigrationEngine.java 2010-06-08 21:51:15 UTC (rev 1997)
+++ trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/ManualMigrationEngine.java 2010-06-09 06:28:55 UTC (rev 1998)
@@ -62,10 +62,9 @@
* Classe principale du projet.
*
* @author tchemit
- * @version $Revision$
- *
- * Last update : $Date$
+ * @deprecated since 2.4, please use now the simplify service {@link TopiaMigrationEngine}
*/
+@Deprecated
public class ManualMigrationEngine //extends MigrationServiceImpl
implements TopiaMigrationService {
Modified: trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/MigrationService.java
===================================================================
--- trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/MigrationService.java 2010-06-08 21:51:15 UTC (rev 1997)
+++ trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/MigrationService.java 2010-06-09 06:28:55 UTC (rev 1998)
@@ -38,7 +38,9 @@
* @version $Revision$
*
* Last update : $Date$
+ * @deprecated since 2.4, please use now the simplify service {@link TopiaMigrationEngine}
*/
+@Deprecated
public interface MigrationService {
/**
Modified: trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/MigrationServiceImpl.java
===================================================================
--- trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/MigrationServiceImpl.java 2010-06-08 21:51:15 UTC (rev 1997)
+++ trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/MigrationServiceImpl.java 2010-06-09 06:28:55 UTC (rev 1998)
@@ -59,10 +59,9 @@
* @author Chevallereau Benjamin
* @author Eon S�bastien
* @author Tr�ve Vincent
- * @version $Revision$
- *
- * Last update : $Date$
+ * @deprecated since 2.4, please use now the simplify service {@link TopiaMigrationEngine}
*/
+@Deprecated
public class MigrationServiceImpl implements MigrationService {
/**
Modified: trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/TopiaMigrationServiceImpl.java
===================================================================
--- trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/TopiaMigrationServiceImpl.java 2010-06-08 21:51:15 UTC (rev 1997)
+++ trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/TopiaMigrationServiceImpl.java 2010-06-09 06:28:55 UTC (rev 1998)
@@ -47,10 +47,9 @@
* @author Chevallereau Benjamin
* @author Eon S�bastien
* @author Tr�ve Vincent
- * @version $Revision$
- *
- * Last update : $Date$
+ * @deprecated since 2.4, please use now the simplify service {@link TopiaMigrationEngine}
*/
+@Deprecated
public class TopiaMigrationServiceImpl extends MigrationServiceImpl implements TopiaMigrationService {
// log
Modified: trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/callback/MigrationCallbackHandler.java
===================================================================
--- trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/callback/MigrationCallbackHandler.java 2010-06-08 21:51:15 UTC (rev 1997)
+++ trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/callback/MigrationCallbackHandler.java 2010-06-09 06:28:55 UTC (rev 1998)
@@ -26,16 +26,15 @@
package org.nuiton.topia.migration.callback;
import org.nuiton.topia.migration.DatabaseManager;
+import org.nuiton.topia.migration.TopiaMigrationEngine;
/**
* MigrationCallBackHandler
*
* @author chatellier
- * @version $Revision$
- *
- * Last update : $Date$
- * By : $Author$
+ * @deprecated since 2.4, please use now the simplify service {@link TopiaMigrationEngine}
*/
+@Deprecated
public interface MigrationCallbackHandler {
/**
Modified: trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/common/ExceptionAttributeUndefined.java
===================================================================
--- trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/common/ExceptionAttributeUndefined.java 2010-06-08 21:51:15 UTC (rev 1997)
+++ trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/common/ExceptionAttributeUndefined.java 2010-06-09 06:28:55 UTC (rev 1998)
@@ -25,6 +25,8 @@
package org.nuiton.topia.migration.common;
+import org.nuiton.topia.migration.TopiaMigrationEngine;
+
/**
* ExceptionAttributeUndefined.java
*
@@ -34,10 +36,9 @@
* @author Chevallereau Benjamin
* @author Eon Sébastien
* @author Trève Vincent
- * @version $Revision$
- *
- * Last update : $Date$
+ * @deprecated since 2.4, please use now the simplify service {@link TopiaMigrationEngine}
*/
+@Deprecated
public class ExceptionAttributeUndefined extends Exception {
/**
Modified: trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/common/MapAdapter.java
===================================================================
--- trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/common/MapAdapter.java 2010-06-08 21:51:15 UTC (rev 1997)
+++ trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/common/MapAdapter.java 2010-06-09 06:28:55 UTC (rev 1998)
@@ -25,6 +25,8 @@
package org.nuiton.topia.migration.common;
+import org.nuiton.topia.migration.TopiaMigrationEngine;
+
import java.io.Serializable;
import java.util.Map;
@@ -37,10 +39,9 @@
* @author Chevallereau Benjamin
* @author Eon Sébastien
* @author Trève Vincent
- * @version $Revision$
- *
- * Last update : $Date$
+ * @deprecated since 2.4, please use now the simplify service {@link TopiaMigrationEngine}
*/
+@Deprecated
public interface MapAdapter {
/**
Modified: trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/common/MapAdapterAdmin.java
===================================================================
--- trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/common/MapAdapterAdmin.java 2010-06-08 21:51:15 UTC (rev 1997)
+++ trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/common/MapAdapterAdmin.java 2010-06-09 06:28:55 UTC (rev 1998)
@@ -26,6 +26,8 @@
package org.nuiton.topia.migration.common;
import java.io.Serializable;
+
+import org.nuiton.topia.migration.TopiaMigrationEngine;
import org.nuiton.util.Version;
import java.util.Map;
@@ -38,10 +40,9 @@
* @author Chevallereau Benjamin
* @author Eon Sébastien
* @author Trève Vincent
- * @version $Revision$
- *
- * Last update : $Date$
+ * @deprecated since 2.4, please use now the simplify service {@link TopiaMigrationEngine}
*/
+@Deprecated
public interface MapAdapterAdmin extends MapAdapter {
/**
Modified: trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/common/MapAdapterImpl.java
===================================================================
--- trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/common/MapAdapterImpl.java 2010-06-08 21:51:15 UTC (rev 1997)
+++ trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/common/MapAdapterImpl.java 2010-06-09 06:28:55 UTC (rev 1998)
@@ -25,6 +25,7 @@
package org.nuiton.topia.migration.common;
+import org.nuiton.topia.migration.TopiaMigrationEngine;
import org.nuiton.util.Version;
import java.io.Serializable;
import java.util.HashMap;
@@ -43,10 +44,9 @@
* @author Chevallereau Benjamin
* @author Eon Sébastien
* @author Trève Vincent
- * @version $Revision$
- *
- * Last update : $Date$
+ * @deprecated since 2.4, please use now the simplify service {@link TopiaMigrationEngine}
*/
+@Deprecated
public class MapAdapterImpl implements MapAdapter, MapAdapterAdmin {
/**
Modified: trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/common/ProxyClass.java
===================================================================
--- trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/common/ProxyClass.java 2010-06-08 21:51:15 UTC (rev 1997)
+++ trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/common/ProxyClass.java 2010-06-09 06:28:55 UTC (rev 1998)
@@ -25,6 +25,8 @@
package org.nuiton.topia.migration.common;
+import org.nuiton.topia.migration.TopiaMigrationEngine;
+
/**
* ProxyClass.java
*
@@ -34,10 +36,9 @@
* @author Chevallereau Benjamin
* @author Eon Sébastien
* @author Trève Vincent
- * @version $Revision$
- *
- * Last update : $Date$
+ * @deprecated since 2.4, please use now the simplify service {@link TopiaMigrationEngine}
*/
+@Deprecated
public interface ProxyClass {
/**
Modified: trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/common/ProxyClassMapped.java
===================================================================
--- trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/common/ProxyClassMapped.java 2010-06-08 21:51:15 UTC (rev 1997)
+++ trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/common/ProxyClassMapped.java 2010-06-09 06:28:55 UTC (rev 1998)
@@ -27,6 +27,7 @@
import java.io.Serializable;
+import org.nuiton.topia.migration.TopiaMigrationEngine;
import org.nuiton.topia.migration.transformation.Migration;
/**
@@ -38,10 +39,9 @@
* @author Chevallereau Benjamin
* @author Eon Sébastien
* @author Trève Vincent
- * @version $Revision$
- *
- * Last update : $Date$
+ * @deprecated since 2.4, please use now the simplify service {@link TopiaMigrationEngine}
*/
+@Deprecated
public interface ProxyClassMapped {
/**
Modified: trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/common/SimpleProxyClass.java
===================================================================
--- trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/common/SimpleProxyClass.java 2010-06-08 21:51:15 UTC (rev 1997)
+++ trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/common/SimpleProxyClass.java 2010-06-09 06:28:55 UTC (rev 1998)
@@ -25,6 +25,8 @@
package org.nuiton.topia.migration.common;
+import org.nuiton.topia.migration.TopiaMigrationEngine;
+
import java.util.StringTokenizer;
/**
@@ -34,10 +36,9 @@
* @author Chevallereau Benjamin
* @author Eon Sébastien
* @author Trève Vincent
- * @version $Revision$
- *
- * Last update : $Date$
+ * @deprecated since 2.4, please use now the simplify service {@link TopiaMigrationEngine}
*/
+@Deprecated
public class SimpleProxyClass implements ProxyClass {
/**
Modified: trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/common/SimpleProxyClassMapped.java
===================================================================
--- trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/common/SimpleProxyClassMapped.java 2010-06-08 21:51:15 UTC (rev 1997)
+++ trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/common/SimpleProxyClassMapped.java 2010-06-09 06:28:55 UTC (rev 1998)
@@ -27,6 +27,7 @@
import java.io.Serializable;
+import org.nuiton.topia.migration.TopiaMigrationEngine;
import org.nuiton.topia.migration.transformation.Migration;
/**
@@ -36,10 +37,9 @@
* @author Chevallereau Benjamin
* @author Eon Sébastien
* @author Trève Vincent
- * @version $Revision$
- *
- * Last update : $Date$
+ * @deprecated since 2.4, please use now the simplify service {@link TopiaMigrationEngine}
*/
+@Deprecated
public class SimpleProxyClassMapped implements ProxyClassMapped {
private ProxyClass pc;
Modified: trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/kernel/BaseException.java
===================================================================
--- trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/kernel/BaseException.java 2010-06-08 21:51:15 UTC (rev 1997)
+++ trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/kernel/BaseException.java 2010-06-09 06:28:55 UTC (rev 1998)
@@ -25,6 +25,8 @@
package org.nuiton.topia.migration.kernel;
+import org.nuiton.topia.migration.TopiaMigrationEngine;
+
/**
* BaseException.java
*
@@ -32,10 +34,9 @@
* @author Chevallereau Benjamin
* @author Eon Sébastien
* @author Trève Vincent
- * @version $Revision$
- *
- * Last update : $Date$
+ * @deprecated since 2.4, please use now the simplify service {@link TopiaMigrationEngine}
*/
+@Deprecated
public class BaseException extends Exception {
/**
Modified: trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/kernel/ConfigurationAdapter.java
===================================================================
--- trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/kernel/ConfigurationAdapter.java 2010-06-08 21:51:15 UTC (rev 1997)
+++ trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/kernel/ConfigurationAdapter.java 2010-06-09 06:28:55 UTC (rev 1998)
@@ -36,6 +36,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.nuiton.topia.migration.TopiaMigrationEngine;
import org.nuiton.topia.migration.common.MapAdapterAdmin;
import org.nuiton.topia.migration.common.MapAdapterImpl;
import org.nuiton.topia.migration.common.ProxyClass;
@@ -66,10 +67,9 @@
* @author Chevallereau Benjamin
* @author Eon Sébastien
* @author Trève Vincent
- * @version $Revision$
- *
- * Last update : $Date$
+ * @deprecated since 2.4, please use now the simplify service {@link TopiaMigrationEngine}
*/
+@Deprecated
public class ConfigurationAdapter {
/**
Modified: trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/kernel/ConfigurationHelper.java
===================================================================
--- trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/kernel/ConfigurationHelper.java 2010-06-08 21:51:15 UTC (rev 1997)
+++ trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/kernel/ConfigurationHelper.java 2010-06-09 06:28:55 UTC (rev 1998)
@@ -40,6 +40,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.nuiton.topia.migration.TopiaMigrationEngine;
import org.nuiton.util.Resource;
import org.dom4j.Attribute;
import org.dom4j.Document;
@@ -60,10 +61,9 @@
* @author Chevallereau Benjamin
* @author Eon Sébastien
* @author Trève Vincent
- * @version $Revision$
- *
- * Last update : $Date$
+ * @deprecated since 2.4, please use now the simplify service {@link TopiaMigrationEngine}
*/
+@Deprecated
public class ConfigurationHelper {
/**
Modified: trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/kernel/DependenciesHelper.java
===================================================================
--- trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/kernel/DependenciesHelper.java 2010-06-08 21:51:15 UTC (rev 1997)
+++ trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/kernel/DependenciesHelper.java 2010-06-09 06:28:55 UTC (rev 1998)
@@ -35,6 +35,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.nuiton.topia.migration.TopiaMigrationEngine;
import org.nuiton.topia.migration.common.ProxyClass;
import org.nuiton.topia.migration.common.SimpleProxyClass;
import org.hibernate.SessionFactory;
@@ -58,10 +59,9 @@
* @author Chevallereau Benjamin
* @author Eon Sébastien
* @author Trève Vincent
- * @version $Revision$
- *
- * Last update : $Date$
+ * @deprecated since 2.4, please use now the simplify service {@link TopiaMigrationEngine}
*/
+@Deprecated
public class DependenciesHelper {
/**
Modified: trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/kernel/NullMigrationClass.java
===================================================================
--- trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/kernel/NullMigrationClass.java 2010-06-08 21:51:15 UTC (rev 1997)
+++ trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/kernel/NullMigrationClass.java 2010-06-09 06:28:55 UTC (rev 1998)
@@ -25,6 +25,7 @@
package org.nuiton.topia.migration.kernel;
+import org.nuiton.topia.migration.TopiaMigrationEngine;
import org.nuiton.topia.migration.common.ProxyClass;
import org.nuiton.topia.migration.transformation.MigrationClass;
import org.nuiton.util.Version;
@@ -36,10 +37,9 @@
* @author Chevallereau Benjamin
* @author Eon Sébastien
* @author Trève Vincent
- * @version $Revision$
- *
- * Last update : $Date$
+ * @deprecated since 2.4, please use now the simplify service {@link TopiaMigrationEngine}
*/
+@Deprecated
public class NullMigrationClass extends MigrationClass {
/**
Modified: trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/kernel/ObjectNotFound.java
===================================================================
--- trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/kernel/ObjectNotFound.java 2010-06-08 21:51:15 UTC (rev 1997)
+++ trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/kernel/ObjectNotFound.java 2010-06-09 06:28:55 UTC (rev 1998)
@@ -25,6 +25,8 @@
package org.nuiton.topia.migration.kernel;
+import org.nuiton.topia.migration.TopiaMigrationEngine;
+
/**
* ObjectNotFound.java
*
@@ -32,10 +34,9 @@
* @author Chevallereau Benjamin
* @author Eon Sébastien
* @author Trève Vincent
- * @version $Revision$
- *
- * Last update : $Date$
+ * @deprecated since 2.4, please use now the simplify service {@link TopiaMigrationEngine}
*/
+@Deprecated
public class ObjectNotFound extends Exception {
private static final long serialVersionUID = -4631241291076236289L;
Modified: trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/kernel/Transformer.java
===================================================================
--- trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/kernel/Transformer.java 2010-06-08 21:51:15 UTC (rev 1997)
+++ trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/kernel/Transformer.java 2010-06-09 06:28:55 UTC (rev 1998)
@@ -35,6 +35,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.nuiton.topia.migration.TopiaMigrationEngine;
import org.nuiton.topia.migration.common.MapAdapter;
import org.nuiton.topia.migration.common.MapAdapterAdmin;
import org.nuiton.topia.migration.common.ProxyClass;
@@ -55,10 +56,9 @@
* @author Chevallereau Benjamin
* @author Eon Sébastien
* @author Trève Vincent
- * @version $Revision$
- *
- * Last update : $Date$
+ * @deprecated since 2.4, please use now the simplify service {@link TopiaMigrationEngine}
*/
+@Deprecated
public class Transformer implements MapHelper {
private FinderMigration classFinder;
Modified: trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/mappings/TMSVersion.java
===================================================================
--- trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/mappings/TMSVersion.java 2010-06-08 21:51:15 UTC (rev 1997)
+++ trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/mappings/TMSVersion.java 2010-06-09 06:28:55 UTC (rev 1998)
@@ -25,6 +25,8 @@
package org.nuiton.topia.migration.mappings;
+import org.nuiton.topia.migration.TopiaMigrationEngine;
+
/**
* TMSVersion.java
*
@@ -32,10 +34,9 @@
* @author Chevallereau Benjamin
* @author Eon Sébastien
* @author Trève Vincent
- * @version $Revision$
- *
- * Last update : $Date$
+ * @deprecated since 2.4, please use now the simplify service {@link TopiaMigrationEngine}
*/
+@Deprecated
public class TMSVersion {
/**
Modified: trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/transformation/AbstractMigration.java
===================================================================
--- trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/transformation/AbstractMigration.java 2010-06-08 21:51:15 UTC (rev 1997)
+++ trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/transformation/AbstractMigration.java 2010-06-09 06:28:55 UTC (rev 1998)
@@ -27,6 +27,7 @@
import java.io.Serializable;
+import org.nuiton.topia.migration.TopiaMigrationEngine;
import org.nuiton.topia.migration.common.MapAdapter;
import org.nuiton.topia.migration.common.ProxyClass;
@@ -37,10 +38,9 @@
* @author Chevallereau Benjamin
* @author Eon Sébastien
* @author Trève Vincent
- * @version $Revision$
- *
- * Last update : $Date$
+ * @deprecated since 2.4, please use now the simplify service {@link TopiaMigrationEngine}
*/
+@Deprecated
public abstract class AbstractMigration implements Migration {
/**
Modified: trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/transformation/FinderMigration.java
===================================================================
--- trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/transformation/FinderMigration.java 2010-06-08 21:51:15 UTC (rev 1997)
+++ trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/transformation/FinderMigration.java 2010-06-09 06:28:55 UTC (rev 1998)
@@ -27,6 +27,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.nuiton.topia.migration.TopiaMigrationEngine;
import org.nuiton.topia.migration.common.ProxyClass;
import org.nuiton.util.Version;
@@ -37,10 +38,9 @@
* @author Chevallereau Benjamin
* @author Eon Sébastien
* @author Trève Vincent
- * @version $Revision$
- *
- * Last update : $Date$
+ * @deprecated since 2.4, please use now the simplify service {@link TopiaMigrationEngine}
*/
+@Deprecated
public class FinderMigration {
/**
Modified: trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/transformation/MapHelper.java
===================================================================
--- trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/transformation/MapHelper.java 2010-06-08 21:51:15 UTC (rev 1997)
+++ trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/transformation/MapHelper.java 2010-06-09 06:28:55 UTC (rev 1998)
@@ -28,6 +28,7 @@
import java.io.Serializable;
import java.util.Collection;
+import org.nuiton.topia.migration.TopiaMigrationEngine;
import org.nuiton.topia.migration.common.MapAdapter;
import org.nuiton.topia.migration.common.ProxyClass;
import org.nuiton.topia.migration.kernel.ObjectNotFound;
@@ -41,10 +42,9 @@
* @author Chevallereau Benjamin
* @author Eon Sébastien
* @author Trève Vincent
- * @version $Revision$
- *
- * Last update : $Date$
+ * @deprecated since 2.4, please use now the simplify service {@link TopiaMigrationEngine}
*/
+@Deprecated
public interface MapHelper {
/**
Modified: trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/transformation/Migration.java
===================================================================
--- trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/transformation/Migration.java 2010-06-08 21:51:15 UTC (rev 1997)
+++ trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/transformation/Migration.java 2010-06-09 06:28:55 UTC (rev 1998)
@@ -27,6 +27,7 @@
import java.io.Serializable;
+import org.nuiton.topia.migration.TopiaMigrationEngine;
import org.nuiton.topia.migration.common.MapAdapter;
import org.nuiton.topia.migration.common.ProxyClass;
@@ -37,10 +38,9 @@
* @author Chevallereau Benjamin
* @author Eon Sébastien
* @author Trève Vincent
- * @version $Revision$
- *
- * Last update : $Date$
+ * @deprecated since 2.4, please use now the simplify service {@link TopiaMigrationEngine}
*/
+@Deprecated
public interface Migration {
/**
Modified: trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/transformation/MigrationClass.java
===================================================================
--- trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/transformation/MigrationClass.java 2010-06-08 21:51:15 UTC (rev 1997)
+++ trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/transformation/MigrationClass.java 2010-06-09 06:28:55 UTC (rev 1998)
@@ -25,6 +25,7 @@
package org.nuiton.topia.migration.transformation;
+import org.nuiton.topia.migration.TopiaMigrationEngine;
import org.nuiton.topia.migration.common.ProxyClass;
import org.nuiton.topia.migration.common.SimpleProxyClass;
import org.nuiton.util.Version;
@@ -36,10 +37,9 @@
* @author Chevallereau Benjamin
* @author Eon Sébastien
* @author Trève Vincent
- * @version $Revision$
- *
- * Last update : $Date$
+ * @deprecated since 2.4, please use now the simplify service {@link TopiaMigrationEngine}
*/
+@Deprecated
public class MigrationClass implements Comparable<MigrationClass> {
//private static transient Log log = LogFactory.getLog(MigrationClass.class);
Modified: trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/transformation/MigrationNull.java
===================================================================
--- trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/transformation/MigrationNull.java 2010-06-08 21:51:15 UTC (rev 1997)
+++ trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/transformation/MigrationNull.java 2010-06-09 06:28:55 UTC (rev 1998)
@@ -25,6 +25,7 @@
package org.nuiton.topia.migration.transformation;
+import org.nuiton.topia.migration.TopiaMigrationEngine;
import org.nuiton.topia.migration.common.MapAdapter;
/**
@@ -34,10 +35,9 @@
* @author Chevallereau Benjamin
* @author Eon Sébastien
* @author Trève Vincent
- * @version $Revision$
- *
- * Last update : $Date$
+ * @deprecated since 2.4, please use now the simplify service {@link TopiaMigrationEngine}
*/
+@Deprecated
public class MigrationNull extends AbstractMigration {
@Override
1
0
r1997 - trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration
by tchemit@users.nuiton.org 08 Jun '10
by tchemit@users.nuiton.org 08 Jun '10
08 Jun '10
Author: tchemit
Date: 2010-06-08 23:51:15 +0200 (Tue, 08 Jun 2010)
New Revision: 1997
Url: http://nuiton.org/repositories/revision/topia/1997
Log:
Evolution #670: Rethink the migration service and deprecates old versions
Added:
trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/TopiaMigrationCallback.java
trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/TopiaMigrationEngine.java
Added: trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/TopiaMigrationCallback.java
===================================================================
--- trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/TopiaMigrationCallback.java (rev 0)
+++ trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/TopiaMigrationCallback.java 2010-06-08 21:51:15 UTC (rev 1997)
@@ -0,0 +1,238 @@
+/*
+ * #%L
+ * ToPIA :: Service Migration
+ *
+ * $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%
+ */
+
+package org.nuiton.topia.migration;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.hibernate.jdbc.Work;
+import org.nuiton.topia.TopiaContext;
+import org.nuiton.topia.TopiaException;
+import org.nuiton.topia.framework.TopiaContextImplementor;
+import org.nuiton.util.StringUtil;
+import org.nuiton.util.Version;
+
+import java.lang.reflect.Method;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+import java.util.List;
+
+import static org.nuiton.i18n.I18n._;
+
+/**
+ * Default migration call back to use.
+ * <p/>
+ * Replace deprecated implementation {@code ManualMigrationCallback}.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @version $Id$
+ * @since 2.4
+ */
+public abstract class TopiaMigrationCallback {
+
+ /** Logger */
+ static private Log log = LogFactory.getLog(TopiaMigrationCallback.class);
+
+ /** @return the available versions from the call back */
+ public abstract Version[] getAvailableVersions();
+
+ /** @return the current application version (says the version to use) */
+ public abstract Version getApplicationVersion();
+
+ /**
+ * Hook to ask user if migration can be performed.
+ *
+ * @param dbVersion the actual db version
+ * @param versions the versions to update
+ * @return {@code false} if migration is canceled, {@code true} otherwise.
+ */
+ public abstract boolean askUser(Version dbVersion,
+ List<Version> versions);
+
+ /**
+ * Tentative de migration depuis la version de la base version la version
+ * souhaitee.
+ * <p/>
+ * On applique toutes les migrations de version indiquee dans le parametre
+ * <code>version</code>.
+ * <p/>
+ * Pour chaque version, on cherche la methode migrateTo_XXX ou XXX est la
+ * version transforme en identifiant java via la methode
+ * {@link Version#getValidName()} et on l'execute.
+ * <p/>
+ * Note: pour chaque version a appliquer, on ouvre une nouvelle transaction.
+ *
+ * @param ctxt topia context de la transaction en cours
+ * @param dbVersion database version
+ * @param showSql drapeau pour afficher les requete sql
+ * @param showProgression drapeau pour afficher la progression
+ * @param versions all versions knwon by service @return migration a
+ * ggrement
+ * @return {@code true} si la migration est accepté, {@code false} autrement.
+ */
+ public boolean doMigration(TopiaContext ctxt,
+ Version dbVersion,
+ boolean showSql,
+ boolean showProgression,
+ List<Version> versions) {
+
+ boolean doMigrate = askUser(dbVersion, versions);
+
+ if (doMigrate) {
+ TopiaContextImplementor tx;
+
+ for (Version v : versions) {
+ // ouverture d'une connexion direct JDBC sur la base
+ try {
+
+ tx = (TopiaContextImplementor) ctxt.beginTransaction();
+
+ try {
+
+ Method m = getMigrationMethod(v);
+
+ m.setAccessible(true);
+
+ log.info(_("topia.migration.start.migrate", v));
+
+ if (log.isDebugEnabled()) {
+ log.debug("launch method " + m.getName());
+ }
+
+ m.invoke(this, tx, showSql, showProgression);
+
+ // commit des modifs
+ tx.commitTransaction();
+
+ } catch (Exception eee) {
+ // en cas d'erreur
+ log.error("Migration impossible de la base", eee);
+ // rollback du travail en cours
+ tx.rollbackTransaction();
+ } finally {
+ // close database connexion
+ if (tx != null) {
+ tx.closeContext();
+ }
+ }
+
+ } catch (Exception eee) {
+ log.error("Error lors de la tentative de migration", eee);
+ doMigrate = false;
+ }
+ }
+ }
+ return doMigrate;
+ }
+
+ protected Method getMigrationMethod(Version version) throws NoSuchMethodException {
+
+ String methodName = "migrateTo_" + version.getValidName();
+
+ Method m = getClass().getMethod(methodName,
+ TopiaContextImplementor.class,
+ boolean.class,
+ boolean.class
+ );
+ return m;
+ }
+
+ public void executeSQL(TopiaContextImplementor tx, String... sqls)
+ throws TopiaException {
+ executeSQL(tx, false, false, sqls);
+ }
+
+ /**
+ * Executes the given {@code sqls} requests.
+ *
+ * @param tx the session
+ * @param showSql flag to see sql requests
+ * @param showProgression flag to see progession on console
+ * @param sqls requests to execute
+ * @throws TopiaException if any pb
+ * @since 2.3.0
+ */
+ public void executeSQL(TopiaContextImplementor tx,
+ final boolean showSql,
+ final boolean showProgression,
+ final String... sqls) throws TopiaException {
+
+ if (log.isInfoEnabled()) {
+
+ log.info(_("topia.migration.start.sqls", sqls.length));
+ }
+ if (showSql) {
+ StringBuilder buffer = new StringBuilder();
+ for (String s : sqls) {
+ buffer.append(s).append("\n");
+ }
+ log.info("SQL TO EXECUTE :\n" +
+ "--------------------------------------------------------------------------------\n" +
+ "--------------------------------------------------------------------------------\n" +
+ buffer.toString() +
+ "--------------------------------------------------------------------------------\n" +
+ "--------------------------------------------------------------------------------\n"
+ );
+ }
+ tx.getHibernate().doWork(new Work() {
+
+ @Override
+ public void execute(Connection connection) throws SQLException {
+ int index = 0;
+ int max = sqls.length;
+ for (String sql : sqls) {
+ long t0 = System.nanoTime();
+ if (log.isInfoEnabled()) {
+ String message = "";
+
+ if (showProgression) {
+ message = _("topia.migration.start.sql", ++index, max);
+ }
+ if (showSql) {
+ message += "\n" + sql;
+ }
+ if (showProgression || showSql) {
+
+ log.info(message);
+ }
+ }
+ PreparedStatement sta = connection.prepareStatement(sql);
+ try {
+ sta.executeUpdate();
+ } finally {
+ sta.close();
+ }
+ if (log.isDebugEnabled()) {
+ String message;
+ message = _("topia.migration.end.sql", ++index, max, StringUtil.convertTime(System.nanoTime() - t0));
+ log.debug(message);
+ }
+ }
+ }
+ });
+
+ }
+}
\ No newline at end of file
Property changes on: trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/TopiaMigrationCallback.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: 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 (rev 0)
+++ trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/TopiaMigrationEngine.java 2010-06-08 21:51:15 UTC (rev 1997)
@@ -0,0 +1,509 @@
+/*
+ * #%L
+ * ToPIA :: Service Migration
+ *
+ * $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%
+ */
+
+package org.nuiton.topia.migration;
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.hibernate.cfg.Configuration;
+import org.hibernate.tool.hbm2ddl.SchemaExport;
+import org.nuiton.topia.TopiaContext;
+import org.nuiton.topia.TopiaException;
+import org.nuiton.topia.TopiaRuntimeException;
+import org.nuiton.topia.event.TopiaContextEvent;
+import org.nuiton.topia.event.TopiaTransactionEvent;
+import org.nuiton.topia.framework.TopiaContextImplementor;
+import org.nuiton.topia.framework.TopiaUtil;
+import org.nuiton.util.Version;
+import org.nuiton.util.VersionUtil;
+import org.nuiton.util.VersionUtil.VersionComparator;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.Properties;
+import java.util.SortedSet;
+import java.util.TreeSet;
+
+import static org.nuiton.i18n.I18n._;
+
+/**
+ * Le moteur de migration proposé par topia. Il est basé sur un {@link TopiaMigrationCallback}
+ * qui donne la version de l'application, les version de mises à jour disponibles.
+ * <p/>
+ * Le call back offre aussi les commandes sql à passer poru chaque version de mise à jour.
+ * <p/>
+ * TODO Finir cette documentation
+ *
+ * @author tchemit
+ * @version $Id$
+ * @since 2.4
+ */
+public class TopiaMigrationEngine implements TopiaMigrationService {
+
+ /** logger */
+ private final static Log log = LogFactory.getLog(TopiaMigrationEngine.class);
+
+ /** L'unique handler a utiliser */
+ static public final String MIGRATION_CALLBACK = "topia.service.migration.callback";
+
+ /** Un drapeau pour indiquer si on doit lancer le service au demarrage */
+ static public final String MIGRATION_MIGRATE_ON_INIT = "topia.service.migration.no.migrate.on.init";
+
+ /** Pour afficher les requetes sql executees */
+ static public final String MIGRATION_SHOW_SQL = "topia.service.migration.showSql";
+
+ /** Pour afficher la progression des requetes sql executees */
+ static public final String MIGRATION_SHOW_PROGRESSION = "topia.service.migration.showProgression";
+
+ /** Configuration hibernate ne mappant que l'entite version (initialise en pre-init) */
+ protected Configuration versionConfiguration;
+
+ /** Un drapeau pour savoir si la table version existe en base (initialise en pre-init) */
+ protected boolean versionTableExist;
+
+ /** Version courante de la base (initialise en pre-init) */
+ protected Version dbVersion;
+
+ /** Drapeau pour savoir si la base est versionnée ou non */
+ protected boolean dbNotVersioned;
+
+ /** Un drapeau pour effectuer la migration au demarrage (initialise en pre-init) */
+ protected boolean migrateOnInit;
+
+ /** CallbackHandler list (initialise en pre-init) */
+ protected TopiaMigrationCallback callback;
+
+ /** topia root context (initialise en pre-init) */
+ protected TopiaContextImplementor rootContext;
+
+ /** Un drapeau pour savoir si le service a bien ete initialise (i.e a bien fini la methode preInit) */
+ protected boolean init;
+
+ /** Un drapeau pour afficher les requetes sql executees */
+ protected boolean showSql;
+
+ /** Un drapeau pour afficher la progression des requetes sql executees */
+ protected boolean showProgression;
+
+ @Override
+ public Class<?>[] getPersistenceClasses() {
+ return new Class<?>[]{TMSVersionImpl.class};
+ }
+
+ @Override
+ public String getServiceName() {
+ return SERVICE_NAME;
+ }
+
+ protected String getSafeParameter(Properties config, String key) {
+ String value = config.getProperty(key, null);
+ if (StringUtils.isEmpty(value)) {
+ throw new IllegalStateException("'" + key + "' not set.");
+ }
+ return value;
+ }
+
+ @Override
+ public boolean preInit(TopiaContextImplementor context) {
+ rootContext = context;
+
+ Properties config = context.getConfig();
+
+ String callbackStr = getSafeParameter(config, MIGRATION_CALLBACK);
+ if (log.isDebugEnabled()) {
+ log.debug("Use callback - " + callbackStr);
+ }
+
+ migrateOnInit = Boolean.valueOf(config.getProperty(MIGRATION_MIGRATE_ON_INIT, "true"));
+ if (log.isDebugEnabled()) {
+ log.debug("Migrate on init - " + migrateOnInit);
+ }
+
+ showSql = Boolean.valueOf(config.getProperty(MIGRATION_SHOW_SQL, "false"));
+ if (log.isDebugEnabled()) {
+ log.debug("Show sql - " + showSql);
+ }
+
+ showProgression = Boolean.valueOf(config.getProperty(MIGRATION_SHOW_PROGRESSION, "false"));
+ if (log.isDebugEnabled()) {
+ log.debug("Show progression - " + showProgression);
+ }
+ // enregistrement du callback
+ try {
+ Class<?> clazz = Class.forName(callbackStr);
+ callback = (TopiaMigrationCallback) clazz.newInstance();
+ } catch (Exception e) {
+ log.error("Could not instanciate CallbackHandler [" + callbackStr + "]", e);
+ }
+
+ // creation de la configuration hibernate ne concernant que l'entite Version
+ // afin de pouvoir creer la table via un schemaExport si necessaire
+
+ versionConfiguration = new Configuration();
+
+ for (Class<?> clazz : getPersistenceClasses()) {
+ if (log.isDebugEnabled()) {
+ log.debug("addClass " + clazz);
+ }
+ versionConfiguration.addClass(clazz);
+ }
+
+ Properties prop = new Properties();
+ prop.putAll(versionConfiguration.getProperties());
+ prop.putAll(config);
+
+ versionConfiguration.setProperties(prop);
+
+ init = true;
+
+ // add topia context listener
+ context.addTopiaContextListener(this);
+ context.addTopiaTransactionVetoable(this);
+
+ if (migrateOnInit) {
+ try {
+
+ doMigrateSchema();
+
+ } catch (MigrationServiceException e) {
+ throw new TopiaRuntimeException("Can't migrate schema for reason " + e.getMessage(), e);
+ }
+ } else {
+ if (log.isDebugEnabled()) {
+ log.debug("migration service, skip migration on init");
+ }
+ }
+
+ return true;
+ }
+
+ @Override
+ public boolean postInit(TopiaContextImplementor context) {
+ return true;
+ }
+
+ @Override
+ public void preCreateSchema(TopiaContextEvent event) {
+ }
+
+ @Override
+ public void preRestoreSchema(TopiaContextEvent event) {
+ }
+
+ @Override
+ public void preUpdateSchema(TopiaContextEvent event) {
+ }
+
+ @Override
+ public void postCreateSchema(TopiaContextEvent event) {
+
+ if (log.isDebugEnabled()) {
+ log.debug("postCreateSchema event called : put version in database");
+ }
+
+ saveApplicationVersion();
+ }
+
+ @Override
+ public void postUpdateSchema(TopiaContextEvent event) {
+ if (log.isDebugEnabled()) {
+ log.debug("postUpdateSchema event called : put version in database");
+ }
+
+ saveApplicationVersion();
+ }
+
+ @Override
+ public void postRestoreSchema(TopiaContextEvent event) {
+ if (log.isDebugEnabled()) {
+ log.debug("postRestoreSchema event detected, redo, schema migration");
+ }
+ try {
+
+ doMigrateSchema();
+
+ } catch (Exception e) {
+ if (log.isErrorEnabled()) {
+ log.error("postRestoreSchema schema migration failed for reason " + e.getMessage(), e);
+ }
+ }
+ }
+
+ @Override
+ public void beginTransaction(TopiaTransactionEvent event) {
+
+ TopiaContextImplementor context = (TopiaContextImplementor) event.getSource();
+
+ // add topia context listener
+ context.addTopiaContextListener(this);
+ }
+
+ public void doMigrateSchema() throws MigrationServiceException {
+ // migration
+ boolean complete = migrateSchema();
+ if (!complete) {
+ if (log.isErrorEnabled()) {
+ log.error(_("topia.migration.migration.incomplete"));
+ }
+ throw new TopiaRuntimeException(_("topia.migration.migration.incomplete"));
+ }
+ }
+
+ @Override
+ public boolean migrateSchema() throws MigrationServiceException {
+
+ checkInit();
+
+ if (dbVersion == null || !migrateOnInit) {
+
+ // no db version was setted or service was not init on int
+ // force detection of version to be safe
+ if (log.isDebugEnabled()) {
+ log.debug("Will detects db version...");
+ }
+ detectDbVersion();
+ }
+
+ Version applicationVersion = callback.getApplicationVersion();
+
+ log.info(_("topia.migration.start.migration", applicationVersion.getVersion(), dbVersion.getVersion()));
+
+ // tell if migration is needed
+ boolean bMigrationNeeded = false;
+
+ if (log.isDebugEnabled()) {
+ log.debug("Migrate schema start version = " + dbVersion +
+ " _ not versioned = " + dbNotVersioned +
+ " _ TMSVersion exists = " + versionTableExist);
+ }
+
+ if (versionTableExist && dbVersion.equals(applicationVersion)) {
+ log.info(_("topia.migration.skip.migration.db.is.up.to.date"));
+ // la base est a jour
+ return true;
+ }
+
+ // Aucune version existante, la base de données est vierge
+ if (versionTableExist && dbNotVersioned && migrateOnInit) {
+ log.info(_("topia.migration.skip.migration.db.is.empty"));
+ // la base est vierge, aucune migration nécessaire
+ // mise à jour de la table tmsversion
+ saveApplicationVersion();
+ return true;
+ }
+
+ SortedSet<Version> allVersions =
+ new TreeSet<Version>(new VersionComparator());
+ allVersions.addAll(Arrays.asList(callback.getAvailableVersions()));
+ log.info(_("topia.migration.available.versions", allVersions));
+
+ if (dbVersion.before(applicationVersion)) {
+
+ // on filtre les versions a appliquer
+ List<Version> versionsToApply =
+ VersionUtil.filterVersions(allVersions,
+ dbVersion,
+ applicationVersion,
+ false,
+ true
+ );
+
+ if (versionsToApply.isEmpty()) {
+ log.info(_("topia.migration.skip.migration.no.version.to.apply"));
+ } else {
+ log.info(_("topia.migration.migrate.versions", versionsToApply));
+ // ask handler for migration
+ bMigrationNeeded = callback.doMigration(rootContext,
+ dbVersion,
+ showSql,
+ showProgression,
+ versionsToApply);
+
+ if (log.isDebugEnabled()) {
+ log.debug("Handler choose : " + bMigrationNeeded);
+ }
+ if (!bMigrationNeeded) {
+ // l'utilisateur a annule la migration
+ return false;
+ }
+ }
+ }
+
+ // on sauvegarde la version si necessaire (base non versionnee ou migration realisee)
+ if (!versionTableExist || bMigrationNeeded) {
+
+ if (log.isDebugEnabled()) {
+ log.debug("Set application version in database to " + applicationVersion);
+ }
+
+ // put version in database and create table if required
+ saveApplicationVersion();
+ }
+
+ // return succes flag
+ // - no migration needed
+ // - or migration needed and accepted
+ return true;
+ }
+
+ /**
+ * Enregistre la version donnee en base avec creation de la table
+ * si elle n'existe pas.
+ */
+ public void saveApplicationVersion() {
+
+ checkInit();
+
+ Version version = callback.getApplicationVersion();
+
+ if (log.isDebugEnabled()) {
+ log.debug("Save version = " + version +
+ " _ table exists = " + versionTableExist);
+ }
+
+ if (dbVersion == null) {
+ detectDbVersion();
+ }
+
+ try {
+
+ boolean createTable = !versionTableExist;
+ // update version even if database has not been migrated
+ // only case that database doesn't exist match this
+ if (createTable) {
+ // si la base n'etait pas versionnee, la table version n'existe pas
+ // creation
+ if (log.isDebugEnabled()) {
+ log.debug("Adding table to put version");
+ }
+
+ // creer le schema en base
+ // dans la configuration versionConfiguration, il n'y a que la table version
+ SchemaExport schemaExport = new SchemaExport(versionConfiguration);
+ schemaExport.create(log.isDebugEnabled(), true);
+
+ if (log.isDebugEnabled()) {
+ log.debug("Table for " + TMSVersion.class.getSimpleName() + " created");
+ }
+
+ }
+ // Changement de la version en base
+ TopiaContext tx = rootContext.beginTransaction();
+ try {
+
+ TMSVersionDAO dao = MigrationServiceDAOHelper.getTMSVersionDAO(tx);
+
+ //FIXME on supprime toues les versions precedentes ???
+ //FIXME il serait mieux de conserver toutes les versions je pense...
+ //FIXME on pourrait conserver l'information sur les date de mise a jour
+ List<TMSVersion> toDelete = dao.findAll();
+ for (TMSVersion v : toDelete) {
+ dao.delete(v);
+ }
+
+ log.info(_("topia.migration.saving.db.version", version));
+ dao.create(TMSVersion.VERSION, version.getVersion());
+
+ tx.commitTransaction();
+ } catch (TopiaException e) {
+ if (tx != null) {
+ tx.rollbackTransaction();
+ }
+ throw e;
+ } finally {
+ if (tx != null) {
+ tx.closeContext();
+ }
+ }
+ } catch (TopiaException e) {
+ throw new TopiaRuntimeException(e);
+ }
+
+ // on change les etats internes du service
+ // ainsi cela empechera le redeclanchement de la migration
+ // suite a une creation de schema
+ versionTableExist = true;
+ dbVersion = version;
+ }
+
+ /**
+ * Recupere depuis la base les états internes du service :
+ * <p/>
+ * <ul>
+ * <li>versionTableExist</li>
+ * <li>dbVersion</li>
+ * </ul>
+ */
+ protected void detectDbVersion() {
+
+ // on detecte si la table de versionning existe
+ versionTableExist = TopiaUtil.isSchemaExist(versionConfiguration, TMSVersionImpl.class.getName());
+
+ if (log.isDebugEnabled()) {
+ log.debug("Table TMSVersion exist = " + versionTableExist);
+ }
+ // recuperation de la version de la base
+ Version v = null;
+ try {
+ if (versionTableExist) {
+ TopiaContext tx = null;
+ try {
+ tx = rootContext.beginTransaction();
+ TMSVersionDAO dao = MigrationServiceDAOHelper.getTMSVersionDAO(tx);
+ List<TMSVersion> versionsInDB = dao.findAll();
+ if (!versionsInDB.isEmpty()) {
+ v = VersionUtil.valueOf(versionsInDB.get(0).getVersion());
+ }
+ } finally {
+ if (tx != null) {
+ tx.closeContext();
+ }
+ }
+ }
+ } catch (TopiaException e) {
+ throw new TopiaRuntimeException("Can't obtain dbVersion for reason " + e.getMessage(), e);
+ }
+
+ if (v == null) {
+ // la base dans ce cas n'est pas versionee.
+ // On dit que la version de la base est 0
+ // et les schema de cette version 0 doivent
+ // etre detenu en local
+ v = Version.VZERO;
+ dbNotVersioned = true;
+ log.info(_("topia.migration.db.not.versionned"));
+ } else {
+ log.info(_("topia.migration.detected.db.version", v));
+ }
+ dbVersion = v;
+ }
+
+ protected void checkInit() {
+ if (!init) {
+ throw new IllegalStateException("le service n'est pas initialisé!");
+ }
+ }
+}
\ No newline at end of file
Property changes on: trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/TopiaMigrationEngine.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
1
0
r1996 - trunk/topia-persistence/src/main/java/org/nuiton/topia/framework
by fdesbois@users.nuiton.org 08 Jun '10
by fdesbois@users.nuiton.org 08 Jun '10
08 Jun '10
Author: fdesbois
Date: 2010-06-08 15:23:33 +0200 (Tue, 08 Jun 2010)
New Revision: 1996
Url: http://nuiton.org/repositories/revision/topia/1996
Log:
Add methods in TopiaQuery : addBetween and addNull
Modified:
trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaQuery.java
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaQuery.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaQuery.java 2010-06-03 22:13:22 UTC (rev 1995)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaQuery.java 2010-06-08 13:23:33 UTC (rev 1996)
@@ -910,18 +910,63 @@
}
/**
- * Add link constraint between two properties. {@code propertyA} is in
- * elements of {@code propertyB} which is a collection with same type than
- * {@code propertyA}. (HQL : A IN elements (B))
+ * Add an element to the query with the constraint null.
*
- * @param propertyA contains in propertyB collection
- * @param propertyB collection which contains propertyA
+ * @param paramName name of the parameter in the query
* @return the TopiaQuery
+ */
+ public TopiaQuery addNull(String paramName) {
+ addWhere(paramName, Op.EQ, null);
+ return this;
+ }
+
+ /**
+ * Add an element with BETWEEN operation. The {@code paramName} will be
+ * found between {@code value1} and {@code value2}. Useful for date
+ * manipulations.
+ *
+ * @param paramName The name of the parameter in the query (entity property)
+ * @param value1 First value
+ * @param value2 Second value
+ * @return the TopiaQuery
+ */
+ public TopiaQuery addBetween(String paramName, Object value1, Object value2) {
+
+ String valueName = getValueName(paramName);
+ String valueName1 = new StringBuilder(valueName).append('1').toString();
+ String valueName2 = new StringBuilder(valueName).append('2').toString();
+
+ addParam(valueName1, value1);
+ addParam(valueName2, value2);
+
+ StringBuilder builder =
+ new StringBuilder(paramName).
+ append(" BETWEEN ").
+ append(':').append(valueName1).
+ append(" AND ").
+ append(':').append(valueName2);
+
+ parentheses = false;
+ addWhere(builder.toString());
+ parentheses = true;
+ return this;
+ }
+
+
+ /**
+ * Add link constraint between two properties. {@code elementProperty} is in
+ * elements of {@code containerProperty} which is a collection with same type
+ * than {@code elementProperty}. (HQL : elementProperty IN elements
+ * (containerProperty))
+ *
+ * @param elementProperty contains in containerProperty collection
+ * @param containerProperty collection which contains elementProperty
+ * @return the TopiaQuery
* @since 2.4
*/
- public TopiaQuery addInElements(String propertyA, String propertyB) {
- StringBuilder builder = new StringBuilder(propertyA).
- append(" IN elements(").append(propertyB).append(')');
+ public TopiaQuery addInElements(String elementProperty, String containerProperty) {
+ StringBuilder builder = new StringBuilder(elementProperty).
+ append(" IN elements(").append(containerProperty).append(')');
parentheses = false;
addWhere(builder.toString());
parentheses = true;
1
0
r1995 - trunk/topia-persistence/src/main/java/org/nuiton/topia/framework
by fdesbois@users.nuiton.org 03 Jun '10
by fdesbois@users.nuiton.org 03 Jun '10
03 Jun '10
Author: fdesbois
Date: 2010-06-04 00:13:22 +0200 (Fri, 04 Jun 2010)
New Revision: 1995
Url: http://nuiton.org/repositories/revision/topia/1995
Log:
Missing new classes from previous commit
Added:
trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/EntityFilter.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaFilter.java
Added: trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/EntityFilter.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/EntityFilter.java (rev 0)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/EntityFilter.java 2010-06-03 22:13:22 UTC (rev 1995)
@@ -0,0 +1,146 @@
+package org.nuiton.topia.framework;
+
+import java.beans.PropertyChangeListener;
+
+/**
+ * Created: 3 juin 2010
+ *
+ * @author fdesbois <fdesbois(a)codelutin.com>
+ * @version $Id$
+ */
+public interface EntityFilter {
+
+ String PROPERTY_START_INDEX = "startIndex";
+
+ String PROPERTY_END_INDEX = "endIndex";
+
+ String PROPERTY_ORDER_BY = "orderBy";
+
+ String PROPERTY_REFERENCE_ID = "referenceId";
+
+ String PROPERTY_REFERENCE_PROPERTY = "referenceProperty";
+
+ /**
+ * Get the value of startIndex
+ *
+ * @return the value of startIndex
+ */
+ Integer getStartIndex();
+
+ /**
+ * Set the value of startIndex
+ *
+ * @param startIndex new value of startIndex
+ */
+ void setStartIndex(Integer startIndex);
+
+ /**
+ * Get the value of orderBy
+ *
+ * @return the value of orderBy
+ */
+ String getOrderBy();
+
+ /**
+ * Set the value of orderBy
+ *
+ * @param orderBy new value of orderBy
+ */
+ void setOrderBy(String orderBy);
+
+ /**
+ * Get the value of endIndex
+ *
+ * @return the value of endIndex
+ */
+ Integer getEndIndex();
+
+ /**
+ * Set the value of endIndex
+ *
+ * @param endIndex new value of endIndex
+ */
+ void setEndIndex(Integer endIndex);
+
+ /**
+ * Get the value of referenceId
+ *
+ * @return the value of referenceId
+ */
+ String getReferenceId();
+
+ /**
+ * Set the value of referenceId
+ *
+ * @param referenceId
+ */
+ void setReferenceId(String referenceId);
+
+ /**
+ * Set the value of referenceId from {@code entity}
+ *
+ * @param entity
+ */
+ void setReference(Object entity) throws IllegalArgumentException;
+
+ /**
+ * Used to check if the filter contains a reference.
+ *
+ * @return true if the filter contains a reference
+ */
+ boolean hasReference();
+
+ /**
+ * Use to check if {@code reference} class is supported by the current
+ * filter reference. The reference can be not {@code mandatory}. Exceptions
+ * are thrown if the check failed. If you prefer to have a boolean instead
+ * of exceptions, you can use {@link #isClassReference(Class)}.
+ *
+ * @param reference Class reference to check
+ * @param mandatory If the existence of the reference is mandatory
+ * @throws IllegalArgumentException for errors on check
+ * @see #hasReference()
+ * @see #isClassReference(Class)
+ */
+ void checkReference(Class<?> reference, boolean mandatory)
+ throws IllegalArgumentException;
+
+ /**
+ * Test if the {@code entityClass} is corresponding to the current reference
+ * in the filter. Will return false if no reference is set in the filter.
+ *
+ * @param entityClass Class reference to test
+ * @return true if the classReference is corresponding, false otherwise
+ * @see #checkReference(Class, boolean)
+ */
+ boolean isClassReference(Class<?> entityClass);
+
+ /**
+ * Get the value of referenceProperty
+ *
+ * @return the value of referenceProperty
+ */
+ String getReferenceProperty();
+
+ /**
+ * Set the value of referenceProperty
+ *
+ * @param referenceProperty
+ */
+ void setReferenceProperty(String referenceProperty);
+
+ /**
+ * Add PropertyChangeListener.
+ *
+ * @param listener
+ */
+ void addPropertyChangeListener(PropertyChangeListener listener);
+
+ /**
+ * Remove PropertyChangeListener.
+ *
+ * @param listener
+ */
+ void removePropertyChangeListener(PropertyChangeListener listener);
+
+}
\ No newline at end of file
Property changes on: trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/EntityFilter.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaFilter.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaFilter.java (rev 0)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaFilter.java 2010-06-03 22:13:22 UTC (rev 1995)
@@ -0,0 +1,208 @@
+package org.nuiton.topia.framework;
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.nuiton.topia.TopiaNotFoundException;
+import org.nuiton.topia.persistence.TopiaEntity;
+import org.nuiton.topia.persistence.TopiaId;
+
+import java.beans.PropertyChangeListener;
+import java.beans.PropertyChangeSupport;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Filter
+ * <p/>
+ * Created: 23 avr. 2010
+ *
+ * @author fdesbois
+ * @since 2.0
+ */
+public class TopiaFilter implements EntityFilter {
+
+ private static final Log log = LogFactory.getLog(TopiaFilter.class);
+
+ protected Integer startIndex;
+
+ protected Integer endIndex;
+
+ protected String orderBy;
+
+ protected String referenceId;
+
+ protected String referenceProperty;
+
+ private PropertyChangeSupport propertyChangeSupport =
+ new PropertyChangeSupport(this);
+
+ @Override
+ public Integer getStartIndex() {
+ return startIndex;
+ }
+
+ @Override
+ public void setStartIndex(Integer startIndex) {
+ Integer oldStartIndex = this.startIndex;
+ this.startIndex = startIndex;
+ propertyChangeSupport.firePropertyChange(PROPERTY_START_INDEX,
+ oldStartIndex, startIndex);
+ }
+
+ @Override
+ public String getOrderBy() {
+ return orderBy;
+ }
+
+ @Override
+ public void setOrderBy(String orderBy) {
+ String oldOrderBy = this.orderBy;
+ this.orderBy = orderBy;
+ propertyChangeSupport.firePropertyChange(PROPERTY_ORDER_BY,
+ oldOrderBy, orderBy);
+ }
+
+ @Override
+ public Integer getEndIndex() {
+ return endIndex;
+ }
+
+ @Override
+ public void setEndIndex(Integer endIndex) {
+ Integer oldEndIndex = this.endIndex;
+ this.endIndex = endIndex;
+ propertyChangeSupport.firePropertyChange(PROPERTY_END_INDEX,
+ oldEndIndex, endIndex);
+ }
+
+ @Override
+ public String getReferenceId() {
+ return referenceId;
+ }
+
+ @Override
+ public void setReferenceId(String referenceId) {
+ String oldReferenceId = this.referenceId;
+ this.referenceId = referenceId;
+ propertyChangeSupport.firePropertyChange(PROPERTY_REFERENCE_ID,
+ oldReferenceId, referenceId);
+ }
+
+ @Override
+ public void setReference(Object entity) throws IllegalArgumentException {
+
+ if (! (entity instanceof TopiaEntity)) {
+ throw new IllegalArgumentException("Can't set reference of type '" +
+ entity.getClass().getName() + "' need a TopiaEntity");
+ }
+
+ setReferenceId(((TopiaEntity)entity).getTopiaId());
+ }
+
+ @Override
+ public boolean hasReference() {
+ return StringUtils.isNotEmpty(referenceId);
+ }
+
+ @Override
+ public String getReferenceProperty() {
+ return referenceProperty;
+ }
+
+ @Override
+ public void setReferenceProperty(String referenceProperty) {
+ String oldReferenceProperty = this.referenceProperty;
+ this.referenceProperty = referenceProperty;
+ propertyChangeSupport.firePropertyChange(PROPERTY_REFERENCE_PROPERTY,
+ oldReferenceProperty, referenceProperty);
+ }
+
+ @Override
+ public void addPropertyChangeListener(PropertyChangeListener listener) {
+ propertyChangeSupport.addPropertyChangeListener(listener);
+ }
+
+ @Override
+ public void removePropertyChangeListener(PropertyChangeListener listener) {
+ propertyChangeSupport.removePropertyChangeListener(listener);
+ }
+
+ /**
+ * Test if the {@code entityClass} is corresponding to the current reference
+ * in the filter. Will return false if no reference is set in the filter.
+ *
+ * @param entityClass Class reference to test
+ * @return true if the classReference is corresponding, false otherwise
+ * @see #checkReference(Class, boolean)
+ */
+ @Override
+ public boolean isClassReference(Class<?> entityClass) {
+
+ boolean result = false;
+
+ if (hasReference()) {
+ try {
+ Class<?> referenceClass = TopiaId.getClassName(referenceId);
+ if (referenceClass.isAssignableFrom(entityClass)) {
+ result = true;
+ }
+ } catch (TopiaNotFoundException eee) {
+ if (log.isWarnEnabled()) {
+ log.warn("ReferenceId '" + referenceId + "' is not a" +
+ " compatible topiaId : " + eee.getMessage());
+ }
+ }
+ }
+ return result;
+ }
+
+ /**
+ * Use to check if {@code reference} class is supported by the current
+ * filter reference. The reference can be not {@code mandatory}. Exceptions
+ * are thrown if the check failed. If you prefer to have a boolean instead
+ * of exceptions, you can use {@link #isClassReference(Class)}.
+ *
+ * @param reference Class reference to check
+ * @param mandatory If the existence of the reference is mandatory
+ * @throws IllegalArgumentException for errors on check
+ * @see #hasReference()
+ * @see #isClassReference(Class)
+ */
+ @Override
+ public void checkReference(Class<?> reference, boolean mandatory)
+ throws IllegalArgumentException {
+
+ if (log.isTraceEnabled()) {
+ log.trace("referenceClass to check : " + reference.getName());
+ log.trace("mandatory : " + mandatory);
+ log.trace("filter hasReference : " + hasReference());
+ log.trace("filter isClassReference : " + isClassReference(reference));
+ }
+
+ if (mandatory && !hasReference()) {
+ throw new IllegalArgumentException("The filter reference" +
+ " of type '" + reference.getSimpleName() + "' is mandatory !");
+ }
+
+ if (hasReference() &&
+ !isClassReference(reference)) {
+ throw new IllegalArgumentException("Reference filtered need to be" +
+ " a '" + reference.getSimpleName() + "' (referenceId = " +
+ referenceId + ")");
+ }
+
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder builder = new StringBuilder("TopiaFilter{").
+ append("referenceProperty = '").append(referenceProperty).
+ append("', startIndex = ").append(startIndex).
+ append(", endIndex = ").append(endIndex).
+ append(", orderBy = '").append(orderBy).
+ append("' , referenceId = '").append(referenceId).
+ append("'}");
+ return builder.toString();
+ }
+}
\ No newline at end of file
Property changes on: trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaFilter.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
1
0
r1994 - in trunk/topia-persistence/src: main/java/org/nuiton/topia main/java/org/nuiton/topia/framework test/java/org/nuiton/topia/framework
by fdesbois@users.nuiton.org 03 Jun '10
by fdesbois@users.nuiton.org 03 Jun '10
03 Jun '10
Author: fdesbois
Date: 2010-06-04 00:12:56 +0200 (Fri, 04 Jun 2010)
New Revision: 1994
Url: http://nuiton.org/repositories/revision/topia/1994
Log:
- Evo #660 : Introduce EntityFilter + TopiaFilter as implementation + add method addFilter in TopiaQuery
- Add method createQuery in TopiaContext
Modified:
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/TopiaQuery.java
trunk/topia-persistence/src/test/java/org/nuiton/topia/framework/TopiaQueryTest.java
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaContext.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaContext.java 2010-06-03 17:28:18 UTC (rev 1993)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaContext.java 2010-06-03 22:12:56 UTC (rev 1994)
@@ -186,6 +186,16 @@
List findByQuery(TopiaQuery query) throws TopiaException;
/**
+ * Instantiate a new TopiaQuery.
+ *
+ * @param entityClass main entity class for the Query
+ * @param alias alias of the entity in the Query
+ * @return a new TopiaQuery
+ * @see TopiaQuery
+ */
+ TopiaQuery createQuery(Class<?> entityClass, String alias);
+
+ /**
* Permet de faire une requete HQL hibernate directement sur la base.
*
* @param hql la requete a faire
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 2010-06-03 17:28:18 UTC (rev 1993)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaContextImpl.java 2010-06-03 22:12:56 UTC (rev 1994)
@@ -925,6 +925,11 @@
return query.execute(this);
}
+ @Override
+ public TopiaQuery createQuery(Class<?> entityClass, String alias) {
+ return new TopiaQuery((Class<? extends TopiaEntity>)entityClass, alias);
+ }
+
/*
* (non-Javadoc)
* @see TopiaContext#find(java.lang.String, java.lang.Object[])
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaQuery.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaQuery.java 2010-06-03 17:28:18 UTC (rev 1993)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaQuery.java 2010-06-03 22:12:56 UTC (rev 1994)
@@ -1131,6 +1131,99 @@
}
/**
+ * Add a {@code filter} to the query that contains limit indexes,
+ * orderBy condition and referenceId if needed. The referenceProperty is
+ * necessary to use the referenceId of the {@code filter}. The filter will
+ * be applied on the main entity in the query (using the mainAlias if
+ * necessary).
+ * <p/>
+ * Note : the default orderBy is the topiaCreateDate ordered desc (the most
+ * recent in first)
+ *
+ * @param filter Filter to apply on the query
+ * @see #addFilter(EntityFilter, String)
+ * @return the TopiaQuery
+ * @throws IllegalArgumentException if referenceId is defined but no
+ * referenceProperty was set
+ */
+ public TopiaQuery addFilter(EntityFilter filter)
+ throws IllegalArgumentException {
+ return addFilter(filter, null);
+ }
+
+ /**
+ * Add a {@code filter} to the query that contains limit indexes,
+ * orderBy condition and referenceId if needed. In some case it's necessary
+ * to specify explicitely the {@code propertyToFilter} in complex queries.
+ * The referenceProperty need to be specifie in {@code filter} to have a
+ * correspondance between the referenceId and it's property in the query. By
+ * default, the {@code propertyToFilter} is the mainAlias of the query.
+ * <p/>
+ * Note : the default orderBy is the topiaCreateDate ordered desc (the most
+ * recent in first)
+ *
+ * @param filter Filter to apply on the query
+ * @param propertyToFilter Explicit property to filter
+ * @return the TopiaQuery
+ * @throws IllegalArgumentException if referenceId is defined but no
+ * referenceProperty was set
+ */
+ public TopiaQuery addFilter(EntityFilter filter,
+ String propertyToFilter)
+ throws IllegalArgumentException {
+
+ if (propertyToFilter == null) {
+ propertyToFilter = mainAlias;
+ }
+
+ Integer startIndex = filter.getStartIndex();
+ Integer endIndex = filter.getEndIndex();
+ String orderBy = filter.getOrderBy();
+ String referenceId = filter.getReferenceId();
+ String referenceProperty = filter.getReferenceProperty();
+
+ if (log.isDebugEnabled()) {
+ log.debug("Filter added to the query : " + filter);
+ }
+
+ // Add limits. Only startIndex do nothing.
+ // startIndex + endIndex provides the limit
+ if (startIndex != null && endIndex != null) {
+ setLimit(startIndex, endIndex);
+
+ // endIndex only provides the maxResults wanted
+ } else if (endIndex != null) {
+ setMaxResults(endIndex);
+ }
+
+ // Add order to the main entity in the query, splitted by comma
+ if (orderBy != null) {
+ List<String> order = new ArrayList<String>();
+ for (String elmt : orderBy.split(",")) {
+ String property =
+ TopiaQuery.getProperty(propertyToFilter, elmt.trim());
+ order.add(property);
+ }
+ addOrder(order.toArray(new String[order.size()]));
+
+ // Default order by creation date
+ } else {
+ addOrderDesc(getPropertyCreateDate(propertyToFilter));
+ }
+
+ if (filter.hasReference()) {
+ if (referenceProperty == null) {
+ throw new IllegalArgumentException("Reference property need" +
+ " to be defined in filter to use referenceId = " +
+ referenceId);
+ }
+ addEquals(getPropertyId(referenceProperty), referenceId);
+ }
+
+ return this;
+ }
+
+ /**
* Simple execution of the query. This method use directly the find method
* in TopiaContext interface.
*
@@ -1559,6 +1652,18 @@
return result;
}
+ public String getPropertyId(String alias) {
+ return getProperty(alias, TopiaEntity.TOPIA_ID);
+ }
+
+ public String getPropertyCreateDate(String alias) {
+ return getProperty(alias, TopiaEntity.TOPIA_CREATE_DATE);
+ }
+
+ public String getPropertyVersion(String alias) {
+ return getProperty(alias, TopiaEntity.TOPIA_VERSION);
+ }
+
@Override
protected void finalize() throws Throwable {
// Clean StringBuilder statements
Modified: trunk/topia-persistence/src/test/java/org/nuiton/topia/framework/TopiaQueryTest.java
===================================================================
--- trunk/topia-persistence/src/test/java/org/nuiton/topia/framework/TopiaQueryTest.java 2010-06-03 17:28:18 UTC (rev 1993)
+++ trunk/topia-persistence/src/test/java/org/nuiton/topia/framework/TopiaQueryTest.java 2010-06-03 22:12:56 UTC (rev 1994)
@@ -29,6 +29,7 @@
import org.apache.commons.logging.LogFactory;
import org.junit.Assert;
import org.junit.Test;
+import org.nuiton.topia.persistence.TopiaEntity;
import org.nuiton.topiatest.QueriedEntity;
/** @author fdesbois */
@@ -125,4 +126,36 @@
}
+ /**
+ * Test of addFilter method, of class TopiaQuery.
+ */
+ @Test
+ public void testAddFilter() {
+ log.info("testAddFilter");
+
+ EntityFilter filter = new TopiaFilter();
+ filter.setStartIndex(1);
+ filter.setEndIndex(40);
+ filter.setOrderBy(QueriedEntity.TEST_ADD);
+
+ TopiaQuery query = new TopiaQuery(QueriedEntity.class).addFilter(filter);
+
+ log.debug("Query : " + query);
+
+ Assert.assertEquals(query.fullQuery(),
+ "FROM " + QueriedEntity.class.getName() +
+ " ORDER BY " + QueriedEntity.TEST_ADD);
+
+ filter.setOrderBy(null);
+
+ query = new TopiaQuery(QueriedEntity.class).addFilter(filter);
+
+ log.debug("Query : " + query);
+
+ Assert.assertEquals(query.fullQuery(),
+ "FROM " + QueriedEntity.class.getName() +
+ " ORDER BY " + TopiaEntity.TOPIA_CREATE_DATE + " DESC");
+
+ }
+
}
1
0
r1993 - trunk/topia-persistence/src/main/java/org/nuiton/topia/generator
by fdesbois@users.nuiton.org 03 Jun '10
by fdesbois@users.nuiton.org 03 Jun '10
03 Jun '10
Author: fdesbois
Date: 2010-06-03 19:28:18 +0200 (Thu, 03 Jun 2010)
New Revision: 1993
Url: http://nuiton.org/repositories/revision/topia/1993
Log:
[ServiceTransformer] Add missing throw default exception on implemented methods
Modified:
trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/ServiceTransformer.java
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/ServiceTransformer.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/ServiceTransformer.java 2010-06-03 14:29:42 UTC (rev 1992)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/ServiceTransformer.java 2010-06-03 17:28:18 UTC (rev 1993)
@@ -567,6 +567,9 @@
} catch (<%=exName%> eee) {
throw eee; }*/);
}
+ if (exceptionName != null) {
+ addException(implOp, exceptionName);
+ }
buffer.append(""
/*{
1
0
r1992 - in trunk/topia-service-security/src/main/java/org/nuiton/topia/taas: . jaas
by sletellier@users.nuiton.org 03 Jun '10
by sletellier@users.nuiton.org 03 Jun '10
03 Jun '10
Author: sletellier
Date: 2010-06-03 16:29:42 +0200 (Thu, 03 Jun 2010)
New Revision: 1992
Url: http://nuiton.org/repositories/revision/topia/1992
Log:
Fork TAAS (AccessController) to check permissions, don't work with JBoss 5.1.0
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/jaas/TaasLoginModule.java
trunk/topia-service-security/src/main/java/org/nuiton/topia/taas/jaas/TaasPermission.java
trunk/topia-service-security/src/main/java/org/nuiton/topia/taas/jaas/TaasPolicy.java
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 2010-06-02 23:28:25 UTC (rev 1991)
+++ trunk/topia-service-security/src/main/java/org/nuiton/topia/taas/TaasService.java 2010-06-03 14:29:42 UTC (rev 1992)
@@ -26,13 +26,13 @@
/* *
* TopiaSecurityVetoableListener.java
*
- * Created: 10 f�vr. 2006
+ * Created: 10 févr. 2006
*
* @author Arnaud Thimel <thimel(a)codelutin.com>
* @version $Revision$
*
* Mise a jour: $Date$
- * par : */
+ * par : sletellier */
package org.nuiton.topia.taas;
@@ -54,27 +54,19 @@
import org.nuiton.topia.taas.entities.TaasUserImpl;
import org.nuiton.topia.taas.event.TaasAccessEntity;
import org.nuiton.topia.taas.event.TaasEntityVetoable;
-import org.nuiton.topia.taas.jaas.TaasConfiguration;
-import org.nuiton.topia.taas.jaas.TaasLoginModule;
-import org.nuiton.topia.taas.jaas.TaasPermission;
-import org.nuiton.topia.taas.jaas.TaasPolicy;
-import org.nuiton.topia.taas.jaas.TaasSubjectFinder;
-import org.nuiton.topia.taas.jaas.TaasSubjectFinderImpl;
+import org.nuiton.topia.taas.jaas.*;
import javax.security.auth.Subject;
import javax.security.auth.login.Configuration;
import java.lang.reflect.Constructor;
import java.security.AccessController;
import java.security.Permission;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Properties;
+import java.util.*;
import static org.nuiton.topia.taas.TaasUtil.getPrincipalNames;
/**
- * Service pour la s�curit�
+ * Service pour la sécurité
* <p/>
* Pour utiliser le service taas, il suffit de rajouter les lignes suivantes
* dans le TopiaContext.properties :<p> topia.service.taas=org.nuiton.topia.taas.TaasService
@@ -89,11 +81,14 @@
public static final String SERVICE_NAME = "taas";
- public static final String SERVICE_LOGIN_MODULE = TaasLoginModule.class.getName();
+ public static final String SERVICE_LOGIN_MODULE =
+ TaasLoginModule.class.getName();
- public static final String SERVICE_EVENT = "topia.service.taas.event";
+ public static final String SERVICE_EVENT =
+ "topia.service.taas.event";
- public static final String SERVICE_SUBJECT = "topia.service.taas.subject";
+ public static final String SERVICE_SUBJECT =
+ "topia.service.taas.subject";
private TaasPolicy policy = new TaasPolicy(this);
@@ -143,7 +138,8 @@
rootContext = context;
initSecurity(rootContext);
try {
- org.hibernate.cfg.Configuration configuration = rootContext.getHibernateConfiguration();
+ org.hibernate.cfg.Configuration configuration =
+ rootContext.getHibernateConfiguration();
// Recuperation du parametre pour l'evenemnt
String eventString = configuration.getProperty(SERVICE_EVENT);
@@ -220,7 +216,8 @@
// Si pas de configuration autre que celle par d�faut
if (Configuration.getConfiguration() == null) {
- Configuration.setConfiguration(new TaasConfiguration(SERVICE_NAME, this));
+ Configuration.setConfiguration(
+ new TaasConfiguration(SERVICE_NAME, this));
}
return true;
}
@@ -240,19 +237,22 @@
* @return context root non securise
* @throws TopiaException
*/
- public TopiaContext getRootContextNoSecure() throws TopiaException {
+ public TopiaContext getRootContextNoSecure()
+ throws TopiaException {
return rootContextNoSecure;
}
/**
- * Permet de r�cup�rer le subject en cours
+ * Permet de récupérer le subject en cours
* @return subject
*/
public Subject findSubject() {
Subject subject = subjectFinder.findSubject();
if (log.isDebugEnabled()) {
- log.debug("findSubject : " + subjectFinder + " value " + subject);
+ log.debug("findSubject : " +
+ subjectFinder + " value " +
+ subject);
}
return subject;
@@ -260,22 +260,26 @@
/**
* Permet de verifier les authorizations sur une collection et de supprimer
- * les donnees non autoris�es
+ * les donnees non autorisées
*
* @param entities collection d'entites
* @param actions actions
- * @throws SecurityException en cas d'erreur de s�curit�
+ * @throws SecurityException en cas d'erreur de sécurité
*/
- public void check(Collection<? extends TopiaEntity> entities, int actions) throws SecurityException {
+ public void check(Collection<? extends TopiaEntity> entities, int actions)
+ throws SecurityException {
Subject subj = findSubject();
if (subj != null) {
- for (Iterator<? extends TopiaEntity> iterator = entities.iterator(); iterator.hasNext();) {
+ for (Iterator<? extends TopiaEntity> iterator =
+ entities.iterator(); iterator.hasNext();) {
TopiaEntity entity = iterator.next();
try {
- AccessController.checkPermission(new TaasPermission(entity.getTopiaId(), actions));
+ TaasPermission myp = new TaasPermission(entity.getTopiaId(), actions);
+ checkPermission(subj, myp);
} catch (SecurityException se) {
if (log.isDebugEnabled()) {
- log.debug(getPrincipalNames(subj) + " does not have permissions to load: " + entity);
+ log.debug(getPrincipalNames(subj) +
+ " does not have permissions to load: " + entity, se);
}
iterator.remove();
}
@@ -286,39 +290,33 @@
}
/**
- * Permet de v�rifier les authorizations
+ * Permet de vérifier les authorizations
*
- * @param entity entit�
+ * @param entity entité
* @param actions actions
- * @throws SecurityException en cas d'erreur de s�curit�
+ * @throws SecurityException en cas d'erreur de sécurité
*/
- public void check(TopiaEntity entity, int actions) throws SecurityException {
- Subject subj = findSubject();
- if (subj != null) {
- try {
- AccessController.checkPermission(new TaasPermission(entity.getTopiaId(), actions));
- } catch (SecurityException se) {
- throw new SecurityException("Access denied to object \"" + entity.getTopiaId() + "\" for \"" + getPrincipalNames(subj) + "\"");
- }
- } else {
- throw new SecurityException("Use doAs() and login first");
- }
+ public void check(TopiaEntity entity, int actions)
+ throws SecurityException {
+ check(entity.getTopiaId(), actions);
}
/**
- * Permet de v�rifier les authorizations
+ * Permet de vérifier les authorizations
*
* @param topiaId id de l'entite
* @param actions actions
- * @throws SecurityException en cas d'erreur de s�curit�
+ * @throws SecurityException en cas d'erreur de sécurité
*/
public void check(String topiaId, int actions) throws SecurityException {
Subject subj = findSubject();
if (subj != null) {
try {
- AccessController.checkPermission(new TaasPermission(topiaId, actions));
+ TaasPermission myp = new TaasPermission(topiaId, actions);
+ checkPermission(subj, myp);
} catch (SecurityException se) {
- throw new SecurityException("Access denied to object \"" + topiaId + "\" for \"" + getPrincipalNames(subj) + "\"");
+ throw new SecurityException("Access denied to object \"" +
+ topiaId + "\" for \"" + getPrincipalNames(subj) + "\"", se);
}
} else {
throw new SecurityException("Use doAs() and login first");
@@ -326,13 +324,40 @@
}
/**
- * Permet de v�rifier les authorizations
+ * Hack pour faire fonctionner la security. Normalement cette methode devrait etre seulement
+ * <pre>
+ * AccessController.checkPermission(myp);
+ * </pre>
*
- * @param entity entit�
+ * Mais comme ca ne fonctionne pas et pas vraiment de raison. Que le code au final a seulement besoin
+ * de checker les TaasPermissions des principales du subject. Cette methode est plus simple et plus rapide
+ * que le mode normal.
+ *
+ * @param subj
+ * @param myp
+ */
+ protected void checkPermission(Subject subj, Permission myp) {
+
+ // Code that note use realy jaas
+ Set<TaasPrincipalWrapper> ps = subj.getPrincipals(TaasPrincipalWrapper.class);
+ for (TaasPrincipalWrapper p : ps) {
+ if (!p.getPermissions().implies(myp)) {
+ throw new SecurityException("Access denied to object " + myp);
+ }
+ }
+ // Old code that use realy jaas
+ //AccessController.checkPermission(myp);
+ }
+
+ /**
+ * Permet de vérifier les authorizations
+ *
+ * @param entity entité
* @param actions actions
- * @throws SecurityException en cas d'erreur de s�curit�
+ * @throws SecurityException en cas d'erreur de sécurité
*/
- public void checkRequestPermission(TopiaEntity entity, int actions) throws SecurityException {
+ public void checkRequestPermission(TopiaEntity entity, int actions)
+ throws SecurityException {
Subject subj = findSubject();
if (subj != null) {
@@ -340,17 +365,22 @@
if (permissions == null) {
try {
- AccessController.checkPermission(new TaasPermission(entity.getTopiaId(), actions));
+ TaasPermission myp = new TaasPermission(entity.getTopiaId(), actions);
+ checkPermission(subj, myp);
} catch (SecurityException se) {
- throw new SecurityException("Access denied to object \"" + entity.getTopiaId() + "\" for \"" + getPrincipalNames(subj) + "\"");
+ throw new SecurityException("Access denied to object \"" +
+ entity.getTopiaId() + "\" for \"" +
+ getPrincipalNames(subj) + "\"", se);
}
} else {
for (Permission permission : permissions) {
try {
- AccessController.checkPermission(permission);
+ checkPermission(subj, permission);
break;
} catch (SecurityException se) {
- throw new SecurityException("Access denied to object \"" + entity.getTopiaId() + "\" for \"" + getPrincipalNames(subj) + "\"");
+ throw new SecurityException("Access denied to object \"" +
+ entity.getTopiaId() + "\" for \"" +
+ getPrincipalNames(subj) + "\"", se);
}
}
}
@@ -360,14 +390,15 @@
}
/**
- * Permet de v�rifier les authorizations sur une collection et de supprimer
- * les donn�es non autoris�es
+ * Permet de vérifier les authorizations sur une collection et de supprimer
+ * les données non autorisées
*
- * @param entities collection d'entit�s
+ * @param entities collection d'entités
* @param actions actions
- * @throws SecurityException en cas d'erreur de s�curit�
+ * @throws SecurityException en cas d'erreur de sécurité
*/
- public void checkRequestPermission(Collection<? extends TopiaEntity> entities, int actions) throws SecurityException {
+ public void checkRequestPermission(Collection<? extends TopiaEntity> entities,
+ int actions) throws SecurityException {
Subject subj = findSubject();
if (subj != null) {
@@ -398,11 +429,11 @@
}
/**
- * R�cup�ration des requests permissions dans les DAOs
+ * Récupération des requests permissions dans les DAOs
*
- * @param entity entit�
+ * @param entity entité
* @param actions actions
- * @return permissions � v�rifier
+ * @return permissions à vérifier
*/
public List<Permission> getRequestPermission(TopiaEntity entity, int actions) {
String topiaId = entity.getTopiaId();
Modified: trunk/topia-service-security/src/main/java/org/nuiton/topia/taas/jaas/TaasLoginModule.java
===================================================================
--- trunk/topia-service-security/src/main/java/org/nuiton/topia/taas/jaas/TaasLoginModule.java 2010-06-02 23:28:25 UTC (rev 1991)
+++ trunk/topia-service-security/src/main/java/org/nuiton/topia/taas/jaas/TaasLoginModule.java 2010-06-03 14:29:42 UTC (rev 1992)
@@ -195,8 +195,25 @@
*/
@Override
public boolean commit() throws LoginException {
- subject.getPrincipals().addAll(principals);
- subject.getPrivateCredentials().add(privateCredential);
+ try {
+ subject.getPrincipals().addAll(principals);
+ if (log.isDebugEnabled()) {
+ for (TaasPrincipalWrapper principal : principals) {
+ log.debug("Permissions for principal " +
+ principal.getName() + " : " +
+ principal.getPermissions());
+ }
+ }
+ subject.getPrivateCredentials().add(privateCredential);
+ if (log.isDebugEnabled()) {
+ log.debug("Private credential size : " +
+ subject.getPrivateCredentials().size() +
+ " for subject : " + subject);
+ }
+ } catch (Exception eee) {
+ log.error("Cant commit : ", eee);
+ throw new LoginException(eee.getMessage());
+ }
return true;
}
Modified: trunk/topia-service-security/src/main/java/org/nuiton/topia/taas/jaas/TaasPermission.java
===================================================================
--- trunk/topia-service-security/src/main/java/org/nuiton/topia/taas/jaas/TaasPermission.java 2010-06-02 23:28:25 UTC (rev 1991)
+++ trunk/topia-service-security/src/main/java/org/nuiton/topia/taas/jaas/TaasPermission.java 2010-06-03 14:29:42 UTC (rev 1992)
@@ -95,8 +95,11 @@
return false;
}
TaasPermission other = (TaasPermission)permission;
- return impliesExpression(authorizationExpression, other.getAuthorizationExpression()) &&
- impliesActions(authorizationActions, other.getAuthorizationActions());
+ boolean isImplies = impliesExpression(authorizationExpression, other.getAuthorizationExpression()) &&
+ impliesActions(authorizationActions, other.getAuthorizationActions());
+
+ log.debug("Implies " + permission + " with other " + other + " implies : " + isImplies);
+ return isImplies;
}
/*
Modified: trunk/topia-service-security/src/main/java/org/nuiton/topia/taas/jaas/TaasPolicy.java
===================================================================
--- trunk/topia-service-security/src/main/java/org/nuiton/topia/taas/jaas/TaasPolicy.java 2010-06-02 23:28:25 UTC (rev 1991)
+++ trunk/topia-service-security/src/main/java/org/nuiton/topia/taas/jaas/TaasPolicy.java 2010-06-03 14:29:42 UTC (rev 1992)
@@ -97,26 +97,34 @@
*/
@Override
public PermissionCollection getPermissions(ProtectionDomain domain) {
- PermissionCollection pc = parentPolicy.getPermissions(domain);
-
- Subject subject = taasService.findSubject();
- if (subject != null) {
- for (Principal principal : subject.getPrincipals()) {
- if(principal instanceof TaasPrincipalWrapper) {
- TaasPrincipalWrapper principalWrapper = (TaasPrincipalWrapper) principal;
- PermissionCollection permissions = principalWrapper.getPermissions();
-
- Enumeration<Permission> enumeration = permissions.elements();
- while(enumeration.hasMoreElements()){
- Permission permission = enumeration.nextElement();
- pc.add(permission);
+ if (log.isDebugEnabled()) {
+ log.debug("Get all permissions for domain : " + (domain==null?null:domain.getClass()));
+ }
+ try {
+ PermissionCollection pc = parentPolicy.getPermissions(domain);
+
+ Subject subject = taasService.findSubject();
+ if (subject != null) {
+ for (Principal principal : subject.getPrincipals()) {
+ if(principal instanceof TaasPrincipalWrapper) {
+ TaasPrincipalWrapper principalWrapper = (TaasPrincipalWrapper) principal;
+ PermissionCollection permissions = principalWrapper.getPermissions();
+
+ Enumeration<Permission> enumeration = permissions.elements();
+ while(enumeration.hasMoreElements()){
+ Permission permission = enumeration.nextElement();
+ pc.add(permission);
+ }
}
}
+ } else {
+ log.error("R�cup�ration des Permissions impossible");
}
- } else {
- log.error("R�cup�ration des Permissions impossible");
+ return pc;
+ } catch (Throwable eee) {
+ log.error("Cant get permissions : ", eee);
}
- return pc;
+ return null;
}
/* (non-Javadoc)
1
0
r1991 - trunk/topia-persistence/src/main/java/org/nuiton/topia/framework
by fdesbois@users.nuiton.org 02 Jun '10
by fdesbois@users.nuiton.org 02 Jun '10
02 Jun '10
Author: fdesbois
Date: 2010-06-03 01:28:25 +0200 (Thu, 03 Jun 2010)
New Revision: 1991
Url: http://nuiton.org/repositories/revision/topia/1991
Log:
missing case for empty select
Modified:
trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaQuery.java
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaQuery.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaQuery.java 2010-06-02 21:36:15 UTC (rev 1990)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaQuery.java 2010-06-02 23:28:25 UTC (rev 1991)
@@ -620,15 +620,19 @@
*/
public TopiaQuery addFetch(String... properties) {
+ // Check mainAlias, necessary to use join fetch
boolean needAlias = false;
if (StringUtils.isEmpty(mainAlias)) {
mainAlias = RandomStringUtils.randomAlphabetic(4);
- from.append(' ').append(mainAlias);
- if (select == null) {
- setSelect(mainAlias);
- }
+ from.append(' ').append(mainAlias);
needAlias = true;
}
+
+ // Init select for single result
+ if (select == null) {
+ setSelect(mainAlias);
+ }
+
for (String current : properties) {
// Add missing alias if needed
String property = needAlias ?
1
0
r1990 - trunk/topia-persistence/src/main/java/org/nuiton/topia/framework
by fdesbois@users.nuiton.org 02 Jun '10
by fdesbois@users.nuiton.org 02 Jun '10
02 Jun '10
Author: fdesbois
Date: 2010-06-02 23:36:15 +0200 (Wed, 02 Jun 2010)
New Revision: 1990
Url: http://nuiton.org/repositories/revision/topia/1990
Log:
Add fetch managment using addFetch method
Modified:
trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaQuery.java
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaQuery.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaQuery.java 2010-06-02 15:07:56 UTC (rev 1989)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaQuery.java 2010-06-02 21:36:15 UTC (rev 1990)
@@ -484,9 +484,9 @@
String alias, boolean fetch) {
String sep = separator;
if (fetch) {
- sep = new StringBuilder(separator).append("FETCH ").toString();
+ sep = new StringBuilder(separator).append(" FETCH").toString();
}
- return addFrom(separator, property, alias);
+ return addFrom(sep, property, alias);
}
/**
@@ -612,17 +612,49 @@
return this;
}
+ /**
+ * TODO-fdesbois-2010-06-02 : javadoc
+ *
+ * @param properties
+ * @return
+ */
public TopiaQuery addFetch(String... properties) {
+
+ boolean needAlias = false;
if (StringUtils.isEmpty(mainAlias)) {
mainAlias = RandomStringUtils.randomAlphabetic(4);
from.append(' ').append(mainAlias);
if (select == null) {
setSelect(mainAlias);
}
+ needAlias = true;
}
- for (String property : properties) {
- String propertyWithAlias = getProperty(mainAlias, property);
- addLeftJoin(propertyWithAlias, null, true);
+ for (String current : properties) {
+ // Add missing alias if needed
+ String property = needAlias ?
+ getProperty(mainAlias, current) : current;
+
+ // Split property on .
+ String[] parts = property.split("\\.");
+
+ // First alias need to be a property in query
+ String alias = parts[0];
+
+ for (int i = 1; i < parts.length; i++) {
+ // Construct property with current alias
+ String propertyToJoin = getProperty(alias, parts[i]);
+
+ // If next occurence exists create a new alias
+ if ((i + 1) < parts.length) {
+ alias = RandomStringUtils.randomAlphabetic(4);
+ } else {
+ // loop will stop, last alias is null
+ alias = null;
+ }
+
+ // Add the property in left join with fetch to true
+ addLeftJoin(propertyToJoin, alias, true);
+ }
}
return this;
}
1
0
r1989 - trunk/topia-persistence/src/main/java/org/nuiton/topia/framework
by fdesbois@users.nuiton.org 02 Jun '10
by fdesbois@users.nuiton.org 02 Jun '10
02 Jun '10
Author: fdesbois
Date: 2010-06-02 17:07:56 +0200 (Wed, 02 Jun 2010)
New Revision: 1989
Url: http://nuiton.org/repositories/revision/topia/1989
Log:
Add fetch managment (not fully tested)
Modified:
trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaQuery.java
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaQuery.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaQuery.java 2010-06-02 12:45:32 UTC (rev 1988)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaQuery.java 2010-06-02 15:07:56 UTC (rev 1989)
@@ -411,8 +411,8 @@
* @param str the element to add
* @return the TopiaQuery
* @see #addFrom(Class, String)
- * @see #addJoin(String, String)
- * @see #addLeftJoin(String, String)
+ * @see #addJoin(String, String, boolean)
+ * @see #addLeftJoin(String, String, boolean)
* @deprecated since 2.4 use correct addFrom or addJoin or addLeftJoin
*/
@Deprecated
@@ -445,37 +445,50 @@
/**
* Add a inner join {@code property} to the query with {@code alias}.
* The join is done in From statement as : FROM Contact C JOIN C.boat B. The
- * added part is 'JOIN C.boat B' using addJoin("C.boat", "B"). The order
+ * added part is 'JOIN C.boat B' using addJoin("C.boat", "B", false). The order
* of calling {@link #addFrom(Class, String)} or this method is very important.
* The first element in the FROM is always the main entity of the query.
*
* @param property Property name to use as a Join
* @param alias Alias of the property in the query
+ * @param fetch Add FETCH keyword to load the property in result (avoid
+ * lazy initialization)
* @return the TopiaQuery
* @since 2.4
*/
- public TopiaQuery addJoin(String property, String alias) {
- return addFrom(FROM_SEPARATOR_JOIN, property, alias);
+ public TopiaQuery addJoin(String property, String alias, boolean fetch) {
+ return addFromJoin(FROM_SEPARATOR_JOIN, property, alias, fetch);
}
/**
* Add a left join {@code property} to the query with {@code alias}.
* The join is done in From statement as : FROM Contact C LEFT JOIN C.boat B.
- * The added part is 'LEFT JOIN C.boat B' using addJoin("C.boat", "B").
+ * The added part is 'LEFT JOIN C.boat B' using addJoin("C.boat", "B", false).
* The order of calling {@link #addFrom(Class, String)} or this method is
* very important. The first element in the FROM is always the main entity
* of the query.
*
* @param property Property name to use as a Join
* @param alias Alias of the property in the query
+ * @param fetch Add FETCH keyword to load the property in result (avoid
+ * lazy initialization)
* @return the TopiaQuery
* @since 2.4
*/
- public TopiaQuery addLeftJoin(String property, String alias) {
- return addFrom(FROM_SEPARATOR_LEFT_JOIN, property, alias);
+ public TopiaQuery addLeftJoin(String property, String alias, boolean fetch) {
+ return addFromJoin(FROM_SEPARATOR_LEFT_JOIN, property, alias, fetch);
}
+ protected TopiaQuery addFromJoin(String separator, String property,
+ String alias, boolean fetch) {
+ String sep = separator;
+ if (fetch) {
+ sep = new StringBuilder(separator).append("FETCH ").toString();
+ }
+ return addFrom(separator, property, alias);
+ }
+
/**
* Add an other entity type to the from in the query.
*
@@ -599,6 +612,21 @@
return this;
}
+ public TopiaQuery addFetch(String... properties) {
+ if (StringUtils.isEmpty(mainAlias)) {
+ mainAlias = RandomStringUtils.randomAlphabetic(4);
+ from.append(' ').append(mainAlias);
+ if (select == null) {
+ setSelect(mainAlias);
+ }
+ }
+ for (String property : properties) {
+ String propertyWithAlias = getProperty(mainAlias, property);
+ addLeftJoin(propertyWithAlias, null, true);
+ }
+ return this;
+ }
+
protected List<String> getPropertiesToLoad() {
if (propertiesToLoad == null) {
propertiesToLoad = new ArrayList<String>();
@@ -816,7 +844,10 @@
public TopiaQuery addNotNull(String paramName) {
StringBuilder result =
new StringBuilder(paramName).append(' ').append(Op.NOT_NULL);
- return addWhere(result.toString());
+ parentheses = false;
+ addWhere(result.toString());
+ parentheses = true;
+ return this;
}
/**
1
0