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
December 2010
- 1 participants
- 16 discussions
r2169 - trunk/topia-persistence/src/main/java/org/nuiton/topia/framework
by tchemit@users.nuiton.org 27 Dec '10
by tchemit@users.nuiton.org 27 Dec '10
27 Dec '10
Author: tchemit
Date: 2010-12-27 11:07:33 +0100 (Mon, 27 Dec 2010)
New Revision: 2169
Url: http://nuiton.org/repositories/revision/topia/2169
Log:
Evolution #1169: Introduce a TopiaSQLQuery
Added:
trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaSQLQuery.java
Added: trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaSQLQuery.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaSQLQuery.java (rev 0)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaSQLQuery.java 2010-12-27 10:07:33 UTC (rev 2169)
@@ -0,0 +1,114 @@
+package org.nuiton.topia.framework;
+
+import org.hibernate.jdbc.Work;
+import org.nuiton.topia.TopiaException;
+import org.nuiton.topia.TopiaRuntimeException;
+
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * An executor of sql query which permits to obtain a single result via
+ * the method {@link #findSingleResult(TopiaContextImplementor)}
+ * or a multiple result with method {@link #findMultipleResult(TopiaContextImplementor)}.
+ *
+ * @param <O> the type of result data
+ * @since 2.5
+ */
+public abstract class TopiaSQLQuery<O> {
+
+ /**
+ * Prepare the statement used to do the sql query.
+ *
+ * @param connection jdbc connection to use
+ * @return the statement containing the query to execute
+ * @throws SQLException if any problem
+ */
+ protected abstract PreparedStatement prepareQuery(Connection connection) throws SQLException;
+
+ /**
+ * given a result set, extract the data.
+ *
+ * @param set the result set
+ * @return the data extracted from the current set, or {@code null}
+ * @throws SQLException if any prob
+ */
+ protected abstract O prepareResult(ResultSet set) throws SQLException;
+
+ /**
+ * Obtain a single result from the builded sql query.
+ *
+ * @param tx the transaction used to execute the query.
+ * @return the single result or {@code null} if none found.
+ * @throws TopiaException for any pb
+ */
+ public O findSingleResult(TopiaContextImplementor tx) throws TopiaException {
+ final List<O> result = new ArrayList<O>();
+
+ tx.getHibernate().doWork(new Work() {
+
+ @Override
+ public void execute(Connection connection) throws SQLException {
+
+ PreparedStatement ps = prepareQuery(connection);
+
+ try {
+ ResultSet set = ps.executeQuery();
+
+ if (set.next()) {
+ O singleResult = prepareResult(set);
+ if (singleResult != null) {
+ result.add(singleResult);
+ }
+ }
+ } catch (Exception e) {
+ throw new TopiaRuntimeException("Could not execute query", e);
+ } finally {
+ ps.close();
+ }
+ }
+ });
+ return result.isEmpty() ? null : result.get(0);
+ }
+
+ /**
+ * Obtain a multiple results fro the builded sql query.
+ *
+ * @param tx the transaction used to execute the query.
+ * @return the list of results (the list is empty if non result is found).
+ * @throws TopiaException for any pb
+ */
+ public List<O> findMultipleResult(TopiaContextImplementor tx) throws TopiaException {
+ final List<O> result = new ArrayList<O>();
+
+ tx.getHibernate().doWork(new Work() {
+
+ @Override
+ public void execute(Connection connection) throws SQLException {
+
+ PreparedStatement ps = prepareQuery(connection);
+ try {
+ ResultSet set = ps.executeQuery();
+
+ while (set.next()) {
+ O singleResult = prepareResult(set);
+
+ if (singleResult != null) {
+ result.add(singleResult);
+ }
+ }
+ } catch (Exception e) {
+ throw new TopiaRuntimeException("Could not execute query", e);
+ } finally {
+ ps.close();
+ }
+ }
+ });
+ return result;
+ }
+
+}
Property changes on: trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaSQLQuery.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
1
0
r2168 - in trunk: . topia-persistence/src/main/resources/META-INF/services topia-persistence/src/test/java/org/nuiton/topia/generator topia-service-migration/src/main/java/org/nuiton/topia/migration
by tchemit@users.nuiton.org 26 Dec '10
by tchemit@users.nuiton.org 26 Dec '10
26 Dec '10
Author: tchemit
Date: 2010-12-26 16:25:30 +0100 (Sun, 26 Dec 2010)
New Revision: 2168
Url: http://nuiton.org/repositories/revision/topia/2168
Log:
use last release of nuiton-i18n, nuiton-utils, eugene
Evolution #1168: Implements a second way of migrate versions (one class by version)
Added:
trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/AbstractTopiaMigrationCallback.java
trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/TopiaMigrationCallbackByClass.java
trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/TopiaMigrationCallbackByMethod.java
Modified:
trunk/pom.xml
trunk/topia-persistence/src/main/resources/META-INF/services/org.nuiton.eugene.ModelPropertiesUtil$ModelPropertiesProvider
trunk/topia-persistence/src/test/java/org/nuiton/topia/generator/TopiaModelPropertiesProviderTest.java
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
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2010-12-12 12:39:34 UTC (rev 2167)
+++ trunk/pom.xml 2010-12-26 15:25:30 UTC (rev 2168)
@@ -133,81 +133,6 @@
<scope>test</scope>
</dependency>
- <!--dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <version>4.8.2</version>
- <scope>test</scope>
- </dependency-->
-
- <!-- All theses dependancies are no more used
- Keep them for topia-soa and topia-service-XXX
- -->
-
- <!--dependency>
- <groupId>org.apache.xmlrpc</groupId>
- <artifactId>xmlrpc-server</artifactId>
- <version>${xmlrpcVersion}</version>
- <scope>compile</scope>
-
- </dependency>
- <dependency>
- <groupId>org.apache.xmlrpc</groupId>
- <artifactId>xmlrpc-client</artifactId>
- <version>${xmlrpcVersion}</version>
- <scope>compile</scope>
- </dependency-->
-
- <!-- Dependencies for class generation -->
- <!--dependency>
- <groupId>org.nuiton.thirdparty</groupId>
- <artifactId>asm</artifactId>
- <version>1.5.4-snapshot</version>
- <scope>compile</scope>
- </dependency>
- <dependency>
- <groupId>xom</groupId>
- <artifactId>xom</artifactId>
- <version>1.1</version>
- </dependency-->
-
- <!--dependency>
- <groupId>org.codehaus.xfire</groupId>
- <artifactId>xfire-java5</artifactId>
- <version>1.2.6</version>
- <scope>compile</scope>
- <exclusions-->
- <!-- Fix org.apache.ant conflict) -->
- <!--exclusion>
- <groupId>ant</groupId>
- <artifactId>ant</artifactId>
- </exclusion>
- </exclusions>
- </dependency>
-
- <dependency>
- <groupId>commons-httpclient</groupId>
- <artifactId>commons-httpclient</artifactId>
- <version>3.1</version>
- <scope>runtime</scope>
- </dependency-->
-
-
- <!-- branch 5.1 : ne fonctionne pas en 6+ -->
- <!--dependency>
- <groupId>jetty</groupId>
- <artifactId>jetty</artifactId>
- <version>5.1.10</version>
- <scope>test</scope>
- </dependency>
-
- <dependency>
- <groupId>org.apache.lucene</groupId>
- <artifactId>lucene-core</artifactId>
- <version>3.0.1</version>
- <scope>compile</scope>
- </dependency-->
-
</dependencies>
</dependencyManagement>
@@ -341,10 +266,10 @@
<projectId>topia</projectId>
<!-- libs version -->
- <eugeneVersion>2.3-SNAPSHOT</eugeneVersion>
- <nuitonUtilsVersion>1.5.2-SNAPSHOT</nuitonUtilsVersion>
+ <eugeneVersion>2.3</eugeneVersion>
+ <nuitonUtilsVersion>1.5.2</nuitonUtilsVersion>
<processorPluginVersion>1.0.4</processorPluginVersion>
- <nuitonI18nVersion>2.0</nuitonI18nVersion>
+ <nuitonI18nVersion>2.0.1</nuitonI18nVersion>
<xmlrpcVersion>3.1.2</xmlrpcVersion>
<hibernateVersion>3.3.2.GA</hibernateVersion>
Property changes on: trunk/topia-persistence/src/main/resources/META-INF/services/org.nuiton.eugene.ModelPropertiesUtil$ModelPropertiesProvider
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Modified: trunk/topia-persistence/src/test/java/org/nuiton/topia/generator/TopiaModelPropertiesProviderTest.java
===================================================================
--- trunk/topia-persistence/src/test/java/org/nuiton/topia/generator/TopiaModelPropertiesProviderTest.java 2010-12-12 12:39:34 UTC (rev 2167)
+++ trunk/topia-persistence/src/test/java/org/nuiton/topia/generator/TopiaModelPropertiesProviderTest.java 2010-12-26 15:25:30 UTC (rev 2168)
@@ -1,3 +1,27 @@
+/*
+ * #%L
+ * ToPIA :: Persistence
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2004 - 2010 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
package org.nuiton.topia.generator;
import org.junit.Assert;
Property changes on: trunk/topia-persistence/src/test/java/org/nuiton/topia/generator/TopiaModelPropertiesProviderTest.java
___________________________________________________________________
Modified: svn:keywords
- Author Date Id Revision
+ Author Date Id Revision HeadURL
Copied: trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/AbstractTopiaMigrationCallback.java (from rev 2167, trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/TopiaMigrationCallback.java)
===================================================================
--- trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/AbstractTopiaMigrationCallback.java (rev 0)
+++ trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/AbstractTopiaMigrationCallback.java 2010-12-26 15:25:30 UTC (rev 2168)
@@ -0,0 +1,225 @@
+/*
+ * #%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.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+import java.util.List;
+
+import static org.nuiton.i18n.I18n._;
+
+/**
+ * Abstract migration callback.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @version $Id$
+ * @since 2.5
+ */
+public abstract class AbstractTopiaMigrationCallback {
+
+ /** Logger */
+ static private Log log = LogFactory.getLog(AbstractTopiaMigrationCallback.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);
+
+ protected abstract void migrateForVersion(Version version,
+ TopiaContextImplementor tx,
+ boolean showSql,
+ boolean showProgression) throws Exception;
+
+ /**
+ * 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) {
+ // l'utilisateur a refuse la migration
+ return false;
+ }
+ TopiaContextImplementor tx;
+
+ for (Version v : versions) {
+ // ouverture d'une connexion direct JDBC sur la base
+ try {
+
+ tx = (TopiaContextImplementor) ctxt.beginTransaction();
+
+ try {
+
+ log.info(_("topia.migration.start.migrate", v));
+
+ migrateForVersion(v, 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();
+ // propagation de l'erreur
+ throw eee;
+ } finally {
+ // close database connexion
+ if (tx != null) {
+ tx.closeContext();
+ }
+ }
+
+ } catch (Exception eee) {
+ log.error("Error lors de la tentative de migration", eee);
+ doMigrate = false;
+ // toute erreur arrête la mgration
+ break;
+ }
+ }
+ return doMigrate;
+ }
+
+ 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
Modified: 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 2010-12-12 12:39:34 UTC (rev 2167)
+++ trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/TopiaMigrationCallback.java 2010-12-26 15:25:30 UTC (rev 2168)
@@ -25,23 +25,11 @@
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/>
@@ -50,109 +38,13 @@
* @author tchemit <chemit(a)codelutin.com>
* @version $Id$
* @since 2.3.4
+ * @deprecated since 2.5, use now the {@link TopiaMigrationCallbackByClass} or {@link TopiaMigrationCallbackByMethod}.
+ * <b>will not be replaced and remove before version {@code 2.6}</b>.
*/
-public abstract class TopiaMigrationCallback {
+@Deprecated
+public abstract class TopiaMigrationCallback extends TopiaMigrationCallbackByMethod {
- /** 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) {
- // l'utilisateur a refuse la migration
- return false;
- }
- 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();
- // propagation de l'erreur
- throw eee;
- } finally {
- // close database connexion
- if (tx != null) {
- tx.closeContext();
- }
- }
-
- } catch (Exception eee) {
- log.error("Error lors de la tentative de migration", eee);
- doMigrate = false;
- // toute erreur arrête la mgration
- break;
- }
- }
- return doMigrate;
- }
-
+ @Deprecated
protected Method getMigrationMethod(Version version) throws NoSuchMethodException {
String methodName = "migrateTo_" + version.getValidName();
@@ -164,80 +56,4 @@
);
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
Added: trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/TopiaMigrationCallbackByClass.java
===================================================================
--- trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/TopiaMigrationCallbackByClass.java (rev 0)
+++ trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/TopiaMigrationCallbackByClass.java 2010-12-26 15:25:30 UTC (rev 2168)
@@ -0,0 +1,119 @@
+/*
+ * #%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.nuiton.topia.TopiaException;
+import org.nuiton.topia.framework.TopiaContextImplementor;
+import org.nuiton.util.ObjectUtil;
+import org.nuiton.util.Version;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Migration callback which use a different class for each version to migrate.
+ * <p/>
+ * You must fill in the constructor the mapping for each version of
+ * {@link #getAvailableVersions()} a matching migrator for version which
+ * extends {@link AbstractMigrationCallBackForVersion}.
+ * <p/>
+ * Use the callback when you have a lot of version to migrate and the
+ * {@link TopiaMigrationCallbackByMethod} begins to be messy.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @version $Id$
+ * @since 2.5
+ */
+public abstract class TopiaMigrationCallbackByClass extends AbstractTopiaMigrationCallback {
+
+ protected Map<Version, Class<? extends AbstractMigrationCallBackForVersion>> versionMigrationMapping;
+
+ protected TopiaMigrationCallbackByClass(Map<Version, Class<? extends AbstractMigrationCallBackForVersion>> versionMigrationMapping) {
+
+ this.versionMigrationMapping = versionMigrationMapping;
+
+ // check for each version of migration we have a migrator
+ for (Version version : getAvailableVersions()) {
+ if (!this.versionMigrationMapping.containsKey(version)) {
+ throw new IllegalStateException("It misses a migration class for version " + version);
+ }
+ }
+ }
+
+ @Override
+ protected void migrateForVersion(Version version,
+ TopiaContextImplementor tx,
+ boolean showSql,
+ boolean showProgression) throws Exception {
+ Class<? extends AbstractMigrationCallBackForVersion> migratorClass = versionMigrationMapping.get(version);
+
+ AbstractMigrationCallBackForVersion migrator = ObjectUtil.newInstance(migratorClass, Arrays.asList(this), true);
+
+ String[] queries = migrator.prepareMigration(tx, showSql, showProgression);
+
+ executeSQL(tx, showSql, showProgression, queries);
+
+ }
+
+ /**
+ * La classe de base pour chaque migration de version.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.5
+ */
+ public abstract static class AbstractMigrationCallBackForVersion {
+
+ protected final Version version;
+
+ protected final TopiaMigrationCallbackByClass callBack;
+
+ public AbstractMigrationCallBackForVersion(Version version,
+ TopiaMigrationCallbackByClass callBack) {
+ this.version = version;
+ this.callBack = callBack;
+
+ }
+
+ protected String[] prepareMigration(TopiaContextImplementor tx,
+ boolean showSql,
+ boolean showProgression) throws TopiaException {
+
+ List<String> queries = new ArrayList<String>();
+
+ prepareMigrationScript(tx, queries, showSql, showProgression);
+
+ return queries.toArray(new String[queries.size()]);
+ }
+
+ protected abstract void prepareMigrationScript(TopiaContextImplementor tx,
+ List<String> queries,
+ boolean showSql,
+ boolean showProgression) throws TopiaException;
+
+
+ }
+}
\ No newline at end of file
Property changes on: trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/TopiaMigrationCallbackByClass.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Copied: trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/TopiaMigrationCallbackByMethod.java (from rev 2167, trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/TopiaMigrationCallback.java)
===================================================================
--- trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/TopiaMigrationCallbackByMethod.java (rev 0)
+++ trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/TopiaMigrationCallbackByMethod.java 2010-12-26 15:25:30 UTC (rev 2168)
@@ -0,0 +1,77 @@
+/*
+ * #%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.nuiton.topia.framework.TopiaContextImplementor;
+import org.nuiton.util.Version;
+
+import java.lang.reflect.Method;
+
+/**
+ * Migration callback base on methods.
+ * <p/>
+ * The callback defines for each version of {@link #getAvailableVersions()}
+ * a method named {@code migrate_on_XXX} where {@code XXX} is the version with
+ * all dots replaces by underscores.
+ * <p/>
+ * Replace deprecated implementation {@code TopiaMigrationCallBack}.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @version $Id$
+ * @since 2.5
+ */
+public abstract class TopiaMigrationCallbackByMethod extends AbstractTopiaMigrationCallback {
+
+ /** Logger */
+ static private Log log = LogFactory.getLog(TopiaMigrationCallbackByMethod.class);
+
+ @Override
+ protected void migrateForVersion(Version version,
+ TopiaContextImplementor tx,
+ boolean showSql,
+ boolean showProgression) throws Exception {
+
+ String methodName = "migrateTo_" + version.getValidName();
+
+ Method m = getClass().getMethod(methodName,
+ TopiaContextImplementor.class,
+ boolean.class,
+ boolean.class
+ );
+
+ m.setAccessible(true);
+
+ if (log.isDebugEnabled()) {
+ log.debug("launch method " + m.getName());
+ }
+
+ m.invoke(this, tx, showSql, showProgression);
+
+ }
+
+
+}
\ No newline at end of file
Modified: trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/TopiaMigrationEngine.java
===================================================================
--- trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/TopiaMigrationEngine.java 2010-12-12 12:39:34 UTC (rev 2167)
+++ trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/TopiaMigrationEngine.java 2010-12-26 15:25:30 UTC (rev 2168)
@@ -54,7 +54,7 @@
import static org.nuiton.i18n.I18n._;
/**
- * Le moteur de migration proposé par topia. Il est basé sur un {@link TopiaMigrationCallback}
+ * Le moteur de migration proposé par topia. Il est basé sur un {@link AbstractTopiaMigrationCallback}
* qui donne la version de l'application, les version de mises à jour disponibles.
* <p/>
* Le call back offre aussi les commandes sql à passer pour chaque version de mise à jour.
@@ -92,7 +92,7 @@
protected boolean migrateOnInit;
/** CallbackHandler list (initialise en pre-init) */
- protected TopiaMigrationCallback callback;
+ protected AbstractTopiaMigrationCallback callback;
/** topia root context (initialise en pre-init) */
protected TopiaContextImplementor rootContext;
@@ -215,7 +215,7 @@
// enregistrement du callback
try {
Class<?> clazz = Class.forName(callbackStr);
- callback = (TopiaMigrationCallback) clazz.newInstance();
+ callback = (AbstractTopiaMigrationCallback) clazz.newInstance();
} catch (Exception e) {
log.error("Could not instanciate CallbackHandler [" + callbackStr + "]", e);
}
1
0
r2167 - trunk/topia-persistence/src/main/java/org/nuiton/topia/generator
by tchemit@users.nuiton.org 12 Dec '10
by tchemit@users.nuiton.org 12 Dec '10
12 Dec '10
Author: tchemit
Date: 2010-12-12 13:39:34 +0100 (Sun, 12 Dec 2010)
New Revision: 2167
Url: http://nuiton.org/repositories/revision/topia/2167
Log:
improve logs
Modified:
trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityTransformer.java
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityTransformer.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityTransformer.java 2010-12-11 19:57:49 UTC (rev 2166)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityTransformer.java 2010-12-12 12:39:34 UTC (rev 2167)
@@ -271,7 +271,13 @@
if (fileLocation != null) {
// there is already a existing file in class-path, skip
- log.info("Will not generate [" + fqn + "], found existing file in class-path : " + fileLocation);
+
+ if (isVerbose()) {
+
+ log.info("Will not generate [" + fqn + "], already found in class-path at location : " + fileLocation);
+ } else {
+ log.info("Will not generate [" + fqn + "], already found in class-path.");
+ }
return false;
}
1
0
r2166 - in trunk/topia-persistence/src/main/java/org/nuiton/topia: generator persistence/util
by tchemit@users.nuiton.org 11 Dec '10
by tchemit@users.nuiton.org 11 Dec '10
11 Dec '10
Author: tchemit
Date: 2010-12-11 20:57:49 +0100 (Sat, 11 Dec 2010)
New Revision: 2166
Url: http://nuiton.org/repositories/revision/topia/2166
Log:
add logs + use plexus to detect ModelPropertiesProvider
Modified:
trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/TopiaGeneratorUtil.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/Collector.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/TopiaEntityHelper.java
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/TopiaGeneratorUtil.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/TopiaGeneratorUtil.java 2010-12-06 15:16:55 UTC (rev 2165)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/TopiaGeneratorUtil.java 2010-12-11 19:57:49 UTC (rev 2166)
@@ -102,6 +102,7 @@
*
* @author tchemit <chemit(a)codelutin.com>
* @since 2.3
+ * @plexus.component role="org.nuiton.eugene.ModelPropertiesUtil$ModelPropertiesProvider" role-hint="topia"
*/
public static class TopiaModelPropertiesProvider extends ModelPropertiesUtil.ModelPropertiesProvider {
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/Collector.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/Collector.java 2010-12-06 15:16:55 UTC (rev 2165)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/Collector.java 2010-12-11 19:57:49 UTC (rev 2166)
@@ -124,6 +124,9 @@
}
protected void before(CollectorVisitor visitor, TopiaEntity entity) {
+ if (log.isDebugEnabled()) {
+ log.debug("Will detect "+entity.getTopiaId());
+ }
}
protected void after(CollectorVisitor visitor, TopiaEntity entity) {
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/TopiaEntityHelper.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/TopiaEntityHelper.java 2010-12-06 15:16:55 UTC (rev 2165)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/TopiaEntityHelper.java 2010-12-11 19:57:49 UTC (rev 2166)
@@ -697,7 +697,9 @@
@Override
protected boolean onStarting(TopiaEntity e) {
- log.debug(e.getTopiaId());
+ if (log.isDebugEnabled()) {
+ log.debug(e.getTopiaId());
+ }
if (root == null) {
// start come in start method since
// last clear method invocation
1
0
r2165 - trunk/topia-persistence/src/main/java/org/nuiton/topia/framework
by tchemit@users.nuiton.org 06 Dec '10
by tchemit@users.nuiton.org 06 Dec '10
06 Dec '10
Author: tchemit
Date: 2010-12-06 16:16:55 +0100 (Mon, 06 Dec 2010)
New Revision: 2165
Url: http://nuiton.org/repositories/revision/topia/2165
Log:
Evolution #1131: Can desactivate the flush mode auto
Clean TopiaContextImpl
Modified:
trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaContextImpl.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaContextImplementor.java
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-12-02 13:42:29 UTC (rev 2164)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaContextImpl.java 2010-12-06 15:16:55 UTC (rev 2165)
@@ -101,8 +101,6 @@
import static org.nuiton.i18n.I18n._;
/**
- * TODO-fdesbois-20100507 : Need translation of javadoc.
- * <p/>
* Le TopiaContextImpl est le point d'entre pour acceder aux donnees. Il est
* configurer par un fichier de propriete
* <p/>
@@ -123,10 +121,11 @@
* Created: 23 déc. 2005 16:58:50
*
* @author poussin <poussin(a)codelutin.com>
- * @author tchemit <tchemit(a)codelutin.com>
- * @author fdesbois <fdesbois(a)codelutin.com>
+ * @author tchemit <chemit(a)codelutin.com>
+ * @author fdesbois <desbois(a)codelutin.com>
* @version $Id$
*/
+//TODO-fdesbois-20100507 : Need translation of javadoc.
public class TopiaContextImpl implements TopiaContextImplementor {
/** to use log facility, just put in your code: log.info(\"...\"); */
@@ -159,6 +158,21 @@
/** Indique si le contexte a ete ferme */
protected boolean closed;
+ /**
+ * This flag permits to use (or not) the flush mode when doing queries.
+ *
+ * The normal usage is to says yes (that's why the default value is
+ * {@code true}), in that case whebn doing queries (says in method
+ * {@link #find(String, Object...)} or {@link #find(String, int, int, Object...)})
+ * it will use the flush mode {@link FlushMode#AUTO}).
+ *
+ * But sometimes, when doing a lot of queries (for some imports for example),
+ * we do NOT want the session to be flushed each time we do a find, then you
+ * can set this flag to {@code false} using the method {@link #setUseFlushMode(boolean)}
+ * @since 2.5
+ */
+ protected boolean useFlushMode = true;
+
/** Propriete de configuration */
protected Properties config;
@@ -303,7 +317,7 @@
public Map<String, TopiaService> getServices() {
TopiaContextImplementor parent = getParentContext();
- Map<String, TopiaService> result = null;
+ Map<String, TopiaService> result;
if (parent != null) {
result = parent.getServices();
} else {
@@ -382,7 +396,7 @@
public Set<TopiaContextImplementor> getChildContext() {
// fdesbois-20100421 : Ano #546
// Copy the childContext into a new set
- final Set<TopiaContextImplementor> values;
+ Set<TopiaContextImplementor> values;
// Synchronize copy to be thread-safe during iteration
synchronized (childContext) {
values = new HashSet<TopiaContextImplementor>(childContext);
@@ -424,6 +438,17 @@
return config;
}
+ /**
+ * Change the value of flag {@link #useFlushMode}.
+ *
+ * @param useFlushMode the new value to set
+ * @see #useFlushMode
+ * @since 2.5
+ */
+ public void setUseFlushMode(boolean useFlushMode) {
+ this.useFlushMode = useFlushMode;
+ }
+
/* -------------------- HIBERNATE MANAGMENT -----------------------------*/
@Override
@@ -456,10 +481,6 @@
}
}
- /* (non-Javadoc)
- * @see org.nuiton.topia.TopiaContext#createSchema()
- */
-
@Override
public void updateSchema() throws TopiaException {
try {
@@ -478,12 +499,6 @@
}
}
- /*
- * (non-Javadoc)
- *
- * @see org.nuiton.topia.framework.TopiaContextImplementor#getHibernate()
- */
-
@Override
public Session getHibernate() throws TopiaException {
if (hibernate == null) {
@@ -493,12 +508,6 @@
return hibernate;
}
- /*
- * (non-Javadoc)
- *
- * @see org.nuiton.topia.framework.TopiaContextImplementor#getHibernateFactory()
- */
-
@Override
public SessionFactory getHibernateFactory() throws TopiaNotFoundException {
if (hibernateFactory == null) {
@@ -677,7 +686,7 @@
I18n._("topia.persistence.error.null.param",
"entityClass", "getDAO"));
}
- if (getRootContext() == this) {
+ if (this == getRootContext()) {
throw new TopiaException(
I18n._("topia.persistence.error.rootContext.access"));
}
@@ -725,12 +734,6 @@
return (D) getDAO(entityClass);
}
- /*
- * (non-Javadoc)
- *
- * @see TopiaContext#beginTransaction()
- */
-
@Override
public TopiaContext beginTransaction() throws TopiaException {
checkClosed(I18n._("topia.persistence.error.context.is.closed"));
@@ -743,6 +746,9 @@
// on ne synchronise jamais les données avec la base tant que
// l'utilisateur n'a pas fait de commit du context
result.hibernate.setFlushMode(FlushMode.MANUAL);
+
+ // tchemit 2010-12-06 propagates the value of the flag
+ result.useFlushMode = useFlushMode;
// 20060926 poussin ajouter pour voir si ca regle les problemes de
// deadlock h2. Conclusion, il faut bien ouvrir une transaction
@@ -759,12 +765,6 @@
return result;
}
- /*
- * (non-Javadoc)
- *
- * @see TopiaContext#commitTransaction()
- */
-
@Override
public void commitTransaction() throws TopiaException {
if (getRootContext() == this) {
@@ -813,7 +813,7 @@
@Override
public void rollbackTransaction() throws TopiaException {
- if (this.equals(getRootContext())) {
+ if (equals(getRootContext())) {
throw new TopiaException(I18n._(
"topia.persistence.error.unsupported.operation.on.root.context",
"rollback"));
@@ -887,9 +887,7 @@
}
/**
- * Pour le context root on ferme tous les fils, et la factory hibernate
- *
- * @see Object#finalize()
+ * Pour le context root on ferme tous les fils, et la factory hibernate.
*/
@Override
protected void finalize() throws Throwable {
@@ -939,11 +937,6 @@
return new TopiaQuery((Class<? extends TopiaEntity>)entityClass, alias);
}
- /*
- * (non-Javadoc)
- * @see TopiaContext#find(java.lang.String, java.lang.Object[])
- */
-
@Override
public List find(String hql, Object... args) throws TopiaException {
checkClosed(I18n._(
@@ -962,7 +955,9 @@
}
}
// tchemit 2010-11-30 reproduce the same behaviour than before with the dao legacy
- query.setFlushMode(FlushMode.AUTO);
+ if (useFlushMode) {
+ query.setFlushMode(FlushMode.AUTO);
+ }
List result = query.list();
result = firesSupport.fireEntitiesLoad(this, result);
return result;
@@ -993,7 +988,9 @@
query.setFirstResult(startIndex);
query.setMaxResults(endIndex - startIndex + 1);
// tchemit 2010-11-30 reproduce the same behaviour than before with the dao legacy
- query.setFlushMode(FlushMode.AUTO);
+ if (useFlushMode) {
+ query.setFlushMode(FlushMode.AUTO);
+ }
List result = query.list();
result = firesSupport.fireEntitiesLoad(this, result);
return result;
@@ -1241,11 +1238,13 @@
}
/**
- * Backup database in gzip compressed file Only work for h2 database
+ * Backup database in gzip compressed file.
*
+ * <b>Note: </b> Only works for h2 database.
+ *
* @param file file to write backup
* @param compress if true then use gzip to compress file
- * @see TopiaContext#backup(java.io.File,boolean)
+ * @see TopiaContext#backup(File,boolean)
*/
@Override
public void backup(File file, boolean compress) throws TopiaException {
@@ -1274,7 +1273,7 @@
* <p/>
* Only work for h2 database
*
- * @see org.nuiton.topia.TopiaContext#restore(java.io.File)
+ * @see TopiaContext#restore(File)
*/
@Override
public void restore(File file) throws TopiaException {
@@ -1285,23 +1284,26 @@
"restore"));
String sql = null;
+ String options = "";
try {
// decompresse file in temporary file
InputStream in = new BufferedInputStream(new FileInputStream(file));
+ try {
in.mark(2);
- // read header to see if is compressed file
- int b = in.read();
- // redundant cast : int magic = ((int) in.read() << 8) | b;
- int magic = (in.read() << 8) | b;
- in.reset();
+ // read header to see if is compressed file
+ int b = in.read();
+ // redundant cast : int magic = ((int) in.read() << 8) | b;
+ int magic = (in.read() << 8) | b;
+ in.reset();
- String options = "";
+ if (magic == GZIPInputStream.GZIP_MAGIC) {
+ options += " COMPRESSION GZIP";
+ }
+ } finally {
- if (magic == GZIPInputStream.GZIP_MAGIC) {
- options += " COMPRESSION GZIP";
+ in.close();
}
- in.close();
SQLQuery query = getHibernate().createSQLQuery(
"RUNSCRIPT FROM '" + file.getAbsolutePath() + "'" + options);
@@ -1319,7 +1321,7 @@
/**
* Only h2 supported for now
*
- * @see org.nuiton.topia.TopiaContext#clear(boolean)
+ * @see TopiaContext#clear(boolean)
*/
@Override
public void clear(boolean dropDatabase) throws TopiaException {
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaContextImplementor.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaContextImplementor.java 2010-12-02 13:42:29 UTC (rev 2164)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaContextImplementor.java 2010-12-06 15:16:55 UTC (rev 2165)
@@ -52,11 +52,15 @@
import java.util.Set;
/**
- * TODO-fdesbois-20100507 : Need more javadoc.
+ * Technical contract of a {@link TopiaContext}.
*
+ * Any implementation of the {@link TopiaContext} should also implements this
+ * contract.
+ *
* @author poussin <poussin(a)codelutin.com>
* @version $Id$
*/
+//TODO-fdesbois-20100507 : Need more javadoc.
public interface TopiaContextImplementor extends TopiaContext {
/**
@@ -94,6 +98,16 @@
throws TopiaNotFoundException;
/**
+ * Tells to the context if it has to use a flush mode before each query.
+ *
+ * By default, we use a flush mode, but in some case it costs to much doing
+ * this, that's why you can desactivate it setting the value to {@code false}.
+ *
+ * @param useFlushMode the new value to set
+ * @since 2.5
+ */
+ void setUseFlushMode(boolean useFlushMode);
+ /**
* Detect if the table is created on storage for a given persistant class.
*
* @param clazz the researched class
@@ -106,10 +120,10 @@
* Get DAO for specified class. If Specialized DAO exists then it returned
* otherwize TopiaDAO<entityClass> is returned
*
- * @param <E>
- * @param entityClass
- * @return a doa
- * @throws TopiaException
+ * @param <E> type of entity
+ * @param entityClass type of entity
+ * @return the required dao
+ * @throws TopiaException if any error
*/
<E extends TopiaEntity> TopiaDAO<E> getDAO(Class<E> entityClass)
throws TopiaException;
@@ -118,11 +132,11 @@
* Get DAO for specified class. If Specialized DAO exists then it returned
* otherwize TopiaDAO<entityClass> is returned
*
- * @param <E>
- * @param entityClass
- * @param daoClass
- * @return a doa
- * @throws TopiaException
+ * @param <E> type of entity
+ * @param entityClass type of entity
+ * @param daoClass the concrete dao class to use
+ * @return the required dao
+ * @throws TopiaException if any error
*/
<E extends TopiaEntity, D extends TopiaDAO<E>> D getDAO(Class<E> entityClass,Class<D> daoClass)
throws TopiaException;
1
0
r2164 - trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence
by tchemit@users.nuiton.org 02 Dec '10
by tchemit@users.nuiton.org 02 Dec '10
02 Dec '10
Author: tchemit
Date: 2010-12-02 14:42:29 +0100 (Thu, 02 Dec 2010)
New Revision: 2164
Url: http://nuiton.org/repositories/revision/topia/2164
Log:
Make TopiaEntityEnum Serializable to use it as a key of some maps
Modified:
trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaEntityEnum.java
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaEntityEnum.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaEntityEnum.java 2010-11-30 22:58:21 UTC (rev 2163)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaEntityEnum.java 2010-12-02 13:42:29 UTC (rev 2164)
@@ -25,6 +25,8 @@
package org.nuiton.topia.persistence;
+import java.io.Serializable;
+
/**
* The contract to be realised by the generated enumeration in any DAOHelper.
*
@@ -46,7 +48,7 @@
* @version $Id$
* @since 2.2.0
*/
-public interface TopiaEntityEnum {
+public interface TopiaEntityEnum extends Serializable {
/**
*
1
0