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
- 4806 discussions
r2769 - in trunk: . topia-persistence topia-persistence/src/main/java/org/nuiton/topia topia-persistence/src/main/java/org/nuiton/topia/event topia-persistence/src/main/java/org/nuiton/topia/framework topia-persistence/src/site/rst/user topia-persistence/src/test/java/org/nuiton/topia/framework
by tchemit@users.nuiton.org 14 Jul '13
by tchemit@users.nuiton.org 14 Jul '13
14 Jul '13
Author: tchemit
Date: 2013-07-14 21:41:45 +0200 (Sun, 14 Jul 2013)
New Revision: 2769
Url: http://nuiton.org/projects/topia/repository/revisions/2769
Log:
refs #2088: remove i18n from ToPIA
refs #2748: Improve TopiaContext if necessary (add a dropSchema operation + event on listener for this too)
Modified:
trunk/pom.xml
trunk/topia-persistence/pom.xml
trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaContext.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/event/TopiaContextAdapter.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/event/TopiaContextListener.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaContextImpl.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaFiresSupport.java
trunk/topia-persistence/src/site/rst/user/start_using_api.rst
trunk/topia-persistence/src/test/java/org/nuiton/topia/framework/TopiaContextImplTest.java
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2013-07-14 19:40:12 UTC (rev 2768)
+++ trunk/pom.xml 2013-07-14 19:41:45 UTC (rev 2769)
@@ -61,6 +61,7 @@
<!-- libs version -->
<eugeneVersion>2.6.4-SNAPSHOT</eugeneVersion>
<nuitonUtilsVersion>2.6.12</nuitonUtilsVersion>
+ <nuitonI18nVersion>2.5.1</nuitonI18nVersion>
<processorPluginVersion>1.3</processorPluginVersion>
<xmlrpcVersion>3.1.2</xmlrpcVersion>
<hibernateVersion>4.2.2.Final</hibernateVersion>
@@ -118,6 +119,12 @@
</dependency>
<dependency>
+ <groupId>org.nuiton.i18n</groupId>
+ <artifactId>nuiton-i18n</artifactId>
+ <version>${nuitonI18nVersion}</version>
+ </dependency>
+
+ <dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>${hibernateVersion}</version>
Modified: trunk/topia-persistence/pom.xml
===================================================================
--- trunk/topia-persistence/pom.xml 2013-07-14 19:40:12 UTC (rev 2768)
+++ trunk/topia-persistence/pom.xml 2013-07-14 19:41:45 UTC (rev 2769)
@@ -54,6 +54,11 @@
</dependency>
<dependency>
+ <groupId>org.nuiton.i18n</groupId>
+ <artifactId>nuiton-i18n</artifactId>
+ </dependency>
+
+ <dependency>
<groupId>org.nuiton.eugene</groupId>
<artifactId>eugene</artifactId>
</dependency>
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaContext.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaContext.java 2013-07-14 19:40:12 UTC (rev 2768)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaContext.java 2013-07-14 19:41:45 UTC (rev 2769)
@@ -141,6 +141,14 @@
void updateSchema() throws TopiaException;
/**
+ * Permet de supprimer le schema de la base de données.
+ *
+ * @throws TopiaException if any exception
+ * @since 3.0
+ */
+ void dropSchema() throws TopiaException;
+
+ /**
* Return a new context containing his own transaction.
*
* @return new context with transaction
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/event/TopiaContextAdapter.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/event/TopiaContextAdapter.java 2013-07-14 19:40:12 UTC (rev 2768)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/event/TopiaContextAdapter.java 2013-07-14 19:41:45 UTC (rev 2769)
@@ -34,7 +34,16 @@
* @since 2.3.4
*/
public class TopiaContextAdapter implements TopiaContextListener {
+
@Override
+ public void preDropSchema(TopiaContextEvent event) {
+ }
+
+ @Override
+ public void postDropSchema(TopiaContextEvent event) {
+ }
+
+ @Override
public void preCreateSchema(TopiaContextEvent event) {
}
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/event/TopiaContextListener.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/event/TopiaContextListener.java 2013-07-14 19:40:12 UTC (rev 2768)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/event/TopiaContextListener.java 2013-07-14 19:41:45 UTC (rev 2769)
@@ -34,7 +34,7 @@
* <ul>
* <li>createSchema</li>
* <li>updateSchema</li>
- * <li>...</li>
+ * <li>...</li>
* </ul>
*
* @author chatellier <chatellier(a)codelutin.com>
@@ -43,9 +43,25 @@
public interface TopiaContextListener extends EventListener {
/**
+ * Called before dropSchema call
+ *
+ * @param event event
+ * @since 3.0
+ */
+ void preDropSchema(TopiaContextEvent event);
+
+ /**
+ * Called after dropSchema call
+ *
+ * @param event event
+ * @since 3.0
+ */
+ void postDropSchema(TopiaContextEvent event);
+
+ /**
* Called before createSchema call
*
- * @param event evet
+ * @param event event
*/
void preCreateSchema(TopiaContextEvent event);
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaContextImpl.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaContextImpl.java 2013-07-14 19:40:12 UTC (rev 2768)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaContextImpl.java 2013-07-14 19:41:45 UTC (rev 2769)
@@ -86,8 +86,6 @@
import java.util.WeakHashMap;
import java.util.zip.GZIPInputStream;
-import static org.nuiton.i18n.I18n._;
-
/**
* Le TopiaContextImpl est le point d'entre pour acceder aux donnees. Il est
* configurer par un fichier de propriete
@@ -259,15 +257,15 @@
TopiaService service = (TopiaService) newInstance;
if (key.equals("topia.service." + service.getServiceName())) {
result.put(service.getServiceName(), service);
- log.info(_("topia.persistence.service.loaded",
+ log.info(String.format("Service '%1$s' loaded (implementation %2$s)",
key, classService));
} else {
- log.warn(_("topia.persistence.warn.service.not.loaded",
+ log.warn(String.format("The service with key '%1$s' has a different name '%2$s'! (service not activated)",
key, service.getServiceName()));
}
} catch (Throwable eee) {
String message =
- _("topia.persistence.error.service.unknown",
+ String.format("The service %1$s of type %2$s was not found.",
key, classService);
if (log.isDebugEnabled()) {
log.debug(message, eee);
@@ -283,7 +281,7 @@
protected void preInitServices(Map<String, TopiaService> services) {
for (TopiaService service : services.values()) {
if (!service.preInit(this)) {
- log.warn(_("topia.persistence.warn.service.not.preInit",
+ log.warn(String.format("The service named '%1$s' could not be post-initialized (service not activated)",
service.getServiceName()));
}
}
@@ -292,7 +290,7 @@
protected void postInitServices(Map<String, TopiaService> services) {
for (TopiaService service : services.values()) {
if (!service.postInit(this)) {
- log.warn(_("topia.persistence.warn.service.not.postInit",
+ log.warn(String.format("The service named '%1$s' could not be pre-initialized (service not activated)",
service.getServiceName()));
}
}
@@ -357,13 +355,13 @@
result = (E) getService(name);
} catch (Exception eee) {
throw new TopiaNotFoundException(
- _("topia.persistence.error.service.not.retreaved",
+ String.format("Could not retreave service %1$s for following reason: %2$s",
interfaceService, getProperExceptionMessage(eee)),
eee);
}
if (result == null) {
throw new TopiaNotFoundException(
- _("topia.persistence.error.service.not.found",
+ String.format("The service %1$s was not found.",
interfaceService));
}
return result;
@@ -377,7 +375,7 @@
String name = getServiceName(interfaceService);
result = serviceEnabled(name);
} catch (Exception eee) {
- String message = _("topia.persistence.warn.service.not.found",
+ String message = String.format("The service named '%1$s' could not be found for following reason: %2$s",
interfaceService, getProperExceptionMessage(eee));
if (log.isDebugEnabled()) {
log.debug(message, eee);
@@ -479,7 +477,7 @@
getFiresSupport().firePostCreateSchema(this);
} catch (HibernateException eee) {
throw new TopiaException(
- _("topia.persistence.error.create.schema",
+ String.format("Could not create schema for reason: %s",
eee.getMessage()), eee);
}
}
@@ -491,7 +489,7 @@
execute(true, false, false, true);
} catch (HibernateException eee) {
throw new TopiaException(
- _("topia.persistence.error.create.schema",
+ String.format("Could not show create schema for reason: %s",
eee.getMessage()), eee);
}
}
@@ -509,16 +507,32 @@
getFiresSupport().firePostUpdateSchema(this);
} catch (HibernateException eee) {
throw new TopiaException(
- _("topia.persistence.error.update.schema",
+ String.format("Could not update schema for reason: %s",
eee.getMessage()), eee);
}
}
@Override
+ public void dropSchema() throws TopiaException {
+ try {
+ boolean showSchema = false;
+ if (log.isDebugEnabled()) {
+ showSchema = true;
+ }
+ getFiresSupport().firePreCreateSchema(this);
+ new SchemaExport(getHibernateConfiguration()).execute(showSchema, true, true, false);
+ getFiresSupport().firePostCreateSchema(this);
+ } catch (HibernateException eee) {
+ throw new TopiaException(
+ String.format("Could not drop schema for reason: %s",
+ eee.getMessage()), eee);
+ }
+ }
+
+ @Override
public Session getHibernate() throws TopiaException {
if (hibernate == null) {
- throw new TopiaException(
- _("topia.persistence.error.no.hibernate.session"));
+ throw new TopiaException("No hibernate session");
}
return hibernate;
}
@@ -1209,8 +1223,8 @@
getFiresSupport().firePostRestoreSchema(this);
} catch (Exception eee) {
throw new TopiaException(String.format(
- "An error occurs while restore operation: %1$s",
- sql, eee.getMessage()), eee);
+ String.format("An error occurs while restore operation: %1$s : %2$s",
+ sql, eee.getMessage())), eee);
}
}
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaFiresSupport.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaFiresSupport.java 2013-07-14 19:40:12 UTC (rev 2768)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaFiresSupport.java 2013-07-14 19:41:45 UTC (rev 2769)
@@ -838,6 +838,47 @@
}
/**
+ * Notify topia context listeners for drop schema pre operation
+ *
+ * @param context topia context
+ * @since 3.0
+ */
+ public void firePreDropSchema(TopiaContext context) {
+ if (log.isDebugEnabled()) {
+ log.debug("firePreDropSchema");
+ }
+ TopiaContextEvent event = new TopiaContextEvent(context);
+ for (TopiaContextListener topiaContextListener : topiaContextListeners) {
+ try {
+ topiaContextListener.preDropSchema(event);
+ } catch (Exception eee) {
+ throw new TopiaVetoException(eee);
+ }
+ }
+ }
+
+ /**
+ * Notify topia context listeners for drop schema post operation
+ *
+ * @param context topia context
+ * @since 3.0
+ */
+ public void firePostDropSchema(TopiaContext context) {
+ if (log.isDebugEnabled()) {
+ log.debug("firePostDropSchema");
+ }
+ TopiaContextEvent event = new TopiaContextEvent(context);
+ for (TopiaContextListener topiaContextListener : topiaContextListeners) {
+ try {
+ topiaContextListener.postDropSchema(event);
+ } catch (Exception eee) {
+ throw new TopiaVetoException(eee);
+ }
+ }
+ }
+
+
+ /**
* Notify entities listeners for load operation
*
* @param <E> type of entities
Modified: trunk/topia-persistence/src/site/rst/user/start_using_api.rst
===================================================================
--- trunk/topia-persistence/src/site/rst/user/start_using_api.rst 2013-07-14 19:40:12 UTC (rev 2768)
+++ trunk/topia-persistence/src/site/rst/user/start_using_api.rst 2013-07-14 19:41:45 UTC (rev 2769)
@@ -150,45 +150,6 @@
Suppression d'une entité.
-Configuration I18n
-------------------
-
-ToPIA contient une internationnalisation des messages utilisateurs (logs).
-Il est préférable d'initialiser I18n pour accélérer la recherche des messages.
-
-Au démarrage de l'application ::
-
- I18nInitializer i18nInitializer = new DefaultI18nInitializer("library-bundle");
- I18n.init(i18nInitializer, new Locale("fr", "FR"));
-
-Configuration maven ::
-
- <!-- Plugin i18n pour gérer le bundle de messages -->
- <plugin>
- <groupId>org.nuiton.i18n</groupId>
- <artifactId>i18n-maven-plugin</artifactId>
- <version>${nuitonI18nVersion}</version>
- <executions>
- <!-- Cette exécution permet de rassembler tous les messages i18n
- dans un seul 'properties bundle' nommé library-bundle
- -->
- <execution>
- <id>make-bundle</id>
- <configuration>
- <bundleOutputName>library-bundle</bundleOutputName>
- </configuration>
- <goals>
- <goal>bundle</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
-
-Vous pourrez également utiliser `nuiton-i18n`_ pour l'internationnalisation de
-votre application.
-
-.. _nuiton-i18n: http://maven-site.nuiton.org/i18n/
-
Exemple complet
---------------
Modified: trunk/topia-persistence/src/test/java/org/nuiton/topia/framework/TopiaContextImplTest.java
===================================================================
--- trunk/topia-persistence/src/test/java/org/nuiton/topia/framework/TopiaContextImplTest.java 2013-07-14 19:40:12 UTC (rev 2768)
+++ trunk/topia-persistence/src/test/java/org/nuiton/topia/framework/TopiaContextImplTest.java 2013-07-14 19:41:45 UTC (rev 2769)
@@ -34,7 +34,6 @@
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
-import org.nuiton.i18n.I18n;
import org.nuiton.topia.TopiaContextFactory;
import org.nuiton.topia.TopiaDatabase;
import org.nuiton.topia.TopiaNotFoundException;
@@ -45,7 +44,6 @@
import java.io.File;
import java.util.HashMap;
-import java.util.Locale;
import java.util.Map;
import java.util.Properties;
@@ -68,7 +66,6 @@
public static void setUpClass() throws Exception {
testBasedir = TopiaDatabase.getTestSpecificDirectory(TopiaContextImplTest.class, "dummy");
- I18n.init(null, Locale.FRENCH);
}
@Before
1
0
14 Jul '13
Author: tchemit
Date: 2013-07-14 21:40:12 +0200 (Sun, 14 Jul 2013)
New Revision: 2768
Url: http://nuiton.org/projects/topia/repository/revisions/2768
Log:
refs #2088: remove i18n from ToPIA
optimize dependencies
Modified:
trunk/topia-service-migration/pom.xml
trunk/topia-service-replication/src/main/java/org/nuiton/topia/replication/operation/AttachAssociation.java
trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/AbstractTopiaReplicationServiceTest.java
trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/operation/UncreatableOperation.java
trunk/topia-service-security/pom.xml
trunk/topia-service-security/src/test/java/org/nuiton/topia/security/TopiaSecurityTest.java
Modified: trunk/topia-service-migration/pom.xml
===================================================================
--- trunk/topia-service-migration/pom.xml 2013-07-14 06:57:56 UTC (rev 2767)
+++ trunk/topia-service-migration/pom.xml 2013-07-14 19:40:12 UTC (rev 2768)
@@ -70,6 +70,11 @@
</dependency>
<dependency>
+ <groupId>com.google.guava</groupId>
+ <artifactId>guava</artifactId>
+ </dependency>
+
+ <dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</dependency>
Modified: trunk/topia-service-replication/src/main/java/org/nuiton/topia/replication/operation/AttachAssociation.java
===================================================================
--- trunk/topia-service-replication/src/main/java/org/nuiton/topia/replication/operation/AttachAssociation.java 2013-07-14 06:57:56 UTC (rev 2767)
+++ trunk/topia-service-replication/src/main/java/org/nuiton/topia/replication/operation/AttachAssociation.java 2013-07-14 19:40:12 UTC (rev 2768)
@@ -43,8 +43,6 @@
import java.util.Collections;
import java.util.List;
-import static org.nuiton.i18n.I18n._;
-
/**
* Pour attacher une association.
* <p/>
@@ -154,8 +152,7 @@
if (ownerIds == null || ownerIds.isEmpty()) {
// pas de donnees a traiter
- log.info(_("topia.replication.attachAssociation.nothing.to.do",
- ownerOperator));
+ log.info("Nothing to attach...");
return;
}
Modified: trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/AbstractTopiaReplicationServiceTest.java
===================================================================
--- trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/AbstractTopiaReplicationServiceTest.java 2013-07-14 06:57:56 UTC (rev 2767)
+++ trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/AbstractTopiaReplicationServiceTest.java 2013-07-14 19:40:12 UTC (rev 2768)
@@ -27,7 +27,6 @@
import org.apache.commons.logging.Log;
import org.junit.Assert;
-import org.nuiton.i18n.I18n;
import org.nuiton.topia.TopiaContext;
import org.nuiton.topia.TopiaException;
import org.nuiton.topia.framework.TopiaContextImplementor;
@@ -49,7 +48,6 @@
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
-import java.util.Locale;
import java.util.Set;
/**
@@ -92,8 +90,6 @@
if (!init) {
- I18n.setDefaultLocale(Locale.FRANCE);
-
try {
context = createDb("source");
} catch (Exception e) {
@@ -620,9 +616,9 @@
}
protected void createSupportedBeforeOperation(TopiaEntityEnum contract,
- TopiaEntity entity,
- Class<? extends TopiaReplicationOperation> operationClass,
- Object... parameters) throws Exception {
+ TopiaEntity entity,
+ Class<? extends TopiaReplicationOperation> operationClass,
+ Object... parameters) throws Exception {
getLog().info("entity " + entity.getTopiaId());
prepareModel(entity.getTopiaId());
Modified: trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/operation/UncreatableOperation.java
===================================================================
--- trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/operation/UncreatableOperation.java 2013-07-14 06:57:56 UTC (rev 2767)
+++ trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/operation/UncreatableOperation.java 2013-07-14 19:40:12 UTC (rev 2768)
@@ -37,8 +37,6 @@
import java.util.List;
-import static org.nuiton.i18n.I18n._;
-
/**
* @author tchemit <chemit(a)codelutin.com>
* @since 2.2.0
@@ -52,7 +50,8 @@
Object... parameters) {
throw new UnsupportedOperationException(
- _("topia.replication.error.operation.uncreatable", getClass()));
+ String.format("The operation %1$s is internal and can not be added using the api.",
+ getClass()));
}
@Override
Modified: trunk/topia-service-security/pom.xml
===================================================================
--- trunk/topia-service-security/pom.xml 2013-07-14 06:57:56 UTC (rev 2767)
+++ trunk/topia-service-security/pom.xml 2013-07-14 19:40:12 UTC (rev 2768)
@@ -68,6 +68,11 @@
</dependency>
<dependency>
+ <groupId>com.google.guava</groupId>
+ <artifactId>guava</artifactId>
+ </dependency>
+
+ <dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
</dependency>
Modified: trunk/topia-service-security/src/test/java/org/nuiton/topia/security/TopiaSecurityTest.java
===================================================================
--- trunk/topia-service-security/src/test/java/org/nuiton/topia/security/TopiaSecurityTest.java 2013-07-14 06:57:56 UTC (rev 2767)
+++ trunk/topia-service-security/src/test/java/org/nuiton/topia/security/TopiaSecurityTest.java 2013-07-14 19:40:12 UTC (rev 2768)
@@ -34,7 +34,6 @@
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
-import org.nuiton.i18n.I18n;
import org.nuiton.topia.TestHelper;
import org.nuiton.topia.TopiaContext;
import org.nuiton.topia.TopiaContextFactory;
@@ -68,7 +67,6 @@
import java.security.PrivilegedExceptionAction;
import java.util.ArrayList;
import java.util.List;
-import java.util.Locale;
import java.util.Properties;
import static org.nuiton.topia.security.util.TopiaSecurityUtil.LOAD;
@@ -84,7 +82,7 @@
private static final Log log = LogFactory.getLog(TopiaSecurityTest.class);
- protected String dbPath;
+ protected String dbPath;
protected TopiaContext context;
@@ -106,7 +104,6 @@
@BeforeClass
public static void init() throws Exception {
- I18n.init(null, Locale.FRANCE);
tesDir = TestHelper.getTestBasedir(TopiaSecurityTest.class);
}
@@ -301,6 +298,7 @@
context.closeContext();
}
}
+
@Test
public void testLoginThimel() throws Exception {
/* Authentification de l'utilisateur Thimel */
1
0
r2767 - trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence
by tchemit@users.nuiton.org 14 Jul '13
by tchemit@users.nuiton.org 14 Jul '13
14 Jul '13
Author: tchemit
Date: 2013-07-14 08:57:56 +0200 (Sun, 14 Jul 2013)
New Revision: 2767
Url: http://nuiton.org/projects/topia/repository/revisions/2767
Log:
refs #2751: Improve TopiaDAO create methods (test if id is not blanck instead of just not null)
Modified:
trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAOImpl.java
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAOImpl.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAOImpl.java 2013-07-14 06:57:07 UTC (rev 2766)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAOImpl.java 2013-07-14 06:57:56 UTC (rev 2767)
@@ -317,7 +317,7 @@
try {
// first set topiaId
- if (entity.getTopiaId() == null) {
+ if (StringUtils.isBlank(entity.getTopiaId())) {
// only set id if not already on
String topiaId = getContext().getTopiaIdFactory().newTopiaId(entityClass, entity);
1
0
r2766 - trunk/topia-persistence/src/main/java/org/nuiton/topia/framework
by tchemit@users.nuiton.org 14 Jul '13
by tchemit@users.nuiton.org 14 Jul '13
14 Jul '13
Author: tchemit
Date: 2013-07-14 08:57:07 +0200 (Sun, 14 Jul 2013)
New Revision: 2766
Url: http://nuiton.org/projects/topia/repository/revisions/2766
Log:
refs #552: Clean api
Modified:
trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/EntityFilter.java
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/EntityFilter.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/EntityFilter.java 2013-07-13 22:05:49 UTC (rev 2765)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/EntityFilter.java 2013-07-14 06:57:07 UTC (rev 2766)
@@ -31,7 +31,9 @@
*
* @author fdesbois <fdesbois(a)codelutin.com>
* @version $Id$
+ * @deprecated since 3.0
*/
+@Deprecated
public interface EntityFilter {
String PROPERTY_START_INDEX = "startIndex";
1
0
Author: tchemit
Date: 2013-07-14 00:05:49 +0200 (Sun, 14 Jul 2013)
New Revision: 2765
Url: http://nuiton.org/projects/topia/repository/revisions/2765
Log:
fixes #2088: remove i18n from ToPIA
Removed:
trunk/topia-persistence/src/main/resources/i18n/
trunk/topia-service-migration/src/main/resources/i18n/
trunk/topia-service-replication/src/main/resources/i18n/
Modified:
trunk/pom.xml
trunk/topia-persistence/pom.xml
trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaContextImpl.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/TopiaEntityHelper.java
trunk/topia-service-migration/pom.xml
trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/AbstractTopiaMigrationCallback.java
trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/TopiaMigrationEngine.java
trunk/topia-service-replication/pom.xml
trunk/topia-service-replication/src/main/java/org/nuiton/topia/replication/TopiaReplicationModelBuilder.java
trunk/topia-service-replication/src/main/java/org/nuiton/topia/replication/operation/AttachLink.java
trunk/topia-service-replication/src/main/java/org/nuiton/topia/replication/operation/LoadLink.java
trunk/topia-service-security/pom.xml
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2013-07-13 21:18:30 UTC (rev 2764)
+++ trunk/pom.xml 2013-07-13 22:05:49 UTC (rev 2765)
@@ -62,16 +62,12 @@
<eugeneVersion>2.6.4-SNAPSHOT</eugeneVersion>
<nuitonUtilsVersion>2.6.12</nuitonUtilsVersion>
<processorPluginVersion>1.3</processorPluginVersion>
- <nuitonI18nVersion>2.5.1</nuitonI18nVersion>
<xmlrpcVersion>3.1.2</xmlrpcVersion>
<hibernateVersion>4.2.2.Final</hibernateVersion>
<sl4jVersion>1.7.5</sl4jVersion>
<h2Version>1.3.172</h2Version>
<hamcrestVersion>1.3</hamcrestVersion>
- <!-- i18n configuration -->
- <i18n.bundles>fr_FR,en_GB,es_ES</i18n.bundles>
-
</properties>
<!-- ************************************************************* -->
@@ -122,12 +118,6 @@
</dependency>
<dependency>
- <groupId>org.nuiton.i18n</groupId>
- <artifactId>nuiton-i18n</artifactId>
- <version>${nuitonI18nVersion}</version>
- </dependency>
-
- <dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>${hibernateVersion}</version>
@@ -398,12 +388,6 @@
</plugin>
<plugin>
- <groupId>org.nuiton.i18n</groupId>
- <artifactId>i18n-maven-plugin</artifactId>
- <version>${nuitonI18nVersion}</version>
- </plugin>
-
- <plugin>
<artifactId>maven-site-plugin</artifactId>
<dependencies>
<dependency>
Modified: trunk/topia-persistence/pom.xml
===================================================================
--- trunk/topia-persistence/pom.xml 2013-07-13 21:18:30 UTC (rev 2764)
+++ trunk/topia-persistence/pom.xml 2013-07-13 22:05:49 UTC (rev 2765)
@@ -54,11 +54,6 @@
</dependency>
<dependency>
- <groupId>org.nuiton.i18n</groupId>
- <artifactId>nuiton-i18n</artifactId>
- </dependency>
-
- <dependency>
<groupId>org.nuiton.eugene</groupId>
<artifactId>eugene</artifactId>
</dependency>
@@ -188,32 +183,6 @@
<artifactId>processor-maven-plugin</artifactId>
</plugin>
- <plugin>
- <groupId>org.nuiton.i18n</groupId>
- <artifactId>i18n-maven-plugin</artifactId>
- <executions>
- <execution>
- <goals>
- <goal>parserJava</goal>
- <goal>gen</goal>
- </goals>
- <!-- restrict parsing beacause this is expensive -->
- <!-- if you want to parse more, add your package in includes -->
- <configuration>
- <treateDefaultEntry>false</treateDefaultEntry>
- <entries>
- <entry>
- <basedir>${maven.src.dir}/main/java</basedir>
- <includes>
- <include>org/nuiton/topia/framework/*.java</include>
- </includes>
- </entry>
- </entries>
- </configuration>
- </execution>
- </executions>
- </plugin>
-
<!-- expose new plexus components -->
<plugin>
<groupId>org.codehaus.plexus</groupId>
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaContextImpl.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaContextImpl.java 2013-07-13 21:18:30 UTC (rev 2764)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaContextImpl.java 2013-07-13 22:05:49 UTC (rev 2765)
@@ -618,7 +618,7 @@
log.debug("Class " + classname + " not found");
}
throw new TopiaNotFoundException(
- _("topia.persistence.error.class.not.found",
+ String.format("Persistence class %1$s not found",
classname));
}
persistenceClasses.add(clazz);
@@ -671,12 +671,12 @@
throws TopiaException {
if (entityClass == null) {
throw new IllegalArgumentException(
- _("topia.persistence.error.null.param",
+ String.format("The method '%1$s' requires a non null parameter '%2$s'.",
"entityClass", "getDAO"));
}
if (equals(getRootContext())) {
throw new TopiaException(
- _("topia.persistence.error.rootContext.access"));
+ "You are on root context, you MUST open a transaction to perform any database access.");
}
if (getHibernateFactory().getClassMetadata(entityClass) == null &&
getHibernateFactory().getClassMetadata(
@@ -684,10 +684,10 @@
getHibernateFactory().getClassMetadata(
entityClass.getName() + "Abstract") == null) {
- log.info(_("topia.persistence.supported.classes.for.context",
+ log.info(String.format("List of supported persistence classes: %1$s",
getHibernateFactory().getAllClassMetadata().keySet()));
throw new TopiaException(
- _("topia.persistence.error.unsupported.class",
+ String.format("The following entity type %1$s is not managed by this context, you probably forgot to declare it.",
entityClass.getName()));
}
@@ -724,7 +724,7 @@
@Override
public TopiaContext beginTransaction() throws TopiaException {
- checkClosed(_("topia.persistence.error.context.is.closed"));
+ checkClosed("Context is closed, no operation is possible.");
TopiaContextImpl result = new TopiaContextImpl(this);
SessionFactory factory = getHibernateFactory();
@@ -758,7 +758,7 @@
}
throw new TopiaException(
- _("topia.persistence.error.open.transaction.failed",
+ String.format("An error occurs while asking a new transaction: %1$s",
eee.getMessage()),
eee);
}
@@ -774,10 +774,10 @@
@Override
public void commitTransaction() throws TopiaException {
if (equals(getRootContext())) {
- throw new TopiaException(_("topia.persistence.error.unsupported.operation.on.root.context",
+ throw new TopiaException(String.format("Unsupported operation %s on root context",
"commit"));
}
- checkClosed(_("topia.persistence.error.unsupported.operation.on.closed.context",
+ checkClosed(String.format("This context is closed, it is not possible to release the operation '%1$s'",
"commit"));
try {
@@ -804,7 +804,7 @@
// hibernate = getHibernateFactory().openSession();
// hibernate.setFlushMode(FlushMode.NEVER);
} catch (Exception eee) {
- throw new TopiaException(_("topia.persistence.error.on.commit",
+ throw new TopiaException(String.format("An error occurs while commit operation: %1$s",
eee.getMessage()), eee);
}
}
@@ -812,10 +812,10 @@
@Override
public void rollbackTransaction() throws TopiaException {
if (equals(getRootContext())) {
- throw new TopiaException(_("topia.persistence.error.unsupported.operation.on.root.context",
+ throw new TopiaException(String.format("Unsupported operation %s on root context",
"rollback"));
}
- checkClosed(_("topia.persistence.error.unsupported.operation.on.closed.context",
+ checkClosed(String.format("This context is closed, it is not possible to release the operation '%1$s'",
"rollback"));
try {
// for (TopiaDAO<? extends TopiaEntity> dao : daoCache.values()) {
@@ -842,7 +842,7 @@
} catch (HibernateException eee) {
throw new TopiaException(
- _("topia.persistence.error.on.rollback",
+ String.format("An error occurs while rollback operation: %1$s",
eee.getMessage()), eee);
}
}
@@ -850,7 +850,7 @@
@Override
public void closeContext() throws TopiaException {
// Throw exception if context is already closed
- checkClosed(_("topia.persistence.error.context.already.closed"));
+ checkClosed("Context was already closed");
// FD-20100421 : Ano #546 : no need to copy childContext, the
// {@link #getChildContext()} provides a thread-safe copy to iterate
@@ -926,7 +926,7 @@
@Override
public <E extends TopiaEntity> E findByTopiaId(String id) throws TopiaException {
- checkClosed(_("topia.persistence.error.unsupported.operation.on.closed.context",
+ checkClosed(String.format("This context is closed, it is not possible to release the operation '%1$s'",
"findById"));
Class<E> entityClass = getTopiaIdFactory().getClassName(id);
@@ -937,7 +937,7 @@
@Override
public <E> List<E> findAll(String hql, Object... args) throws TopiaException {
- checkClosed(_("topia.persistence.error.unsupported.operation.on.closed.context",
+ checkClosed(String.format("This context is closed, it is not possible to release the operation '%1$s'",
"findAll"));
try {
@@ -961,7 +961,7 @@
result = firesSupport.fireEntitiesLoad(this, result);
return result;
} catch (HibernateException eee) {
- throw new TopiaException(_("topia.persistence.error.on.query",
+ throw new TopiaException(String.format("An error occurs while query operation: %1$s : %2$s",
hql, eee.getMessage()), eee);
}
}
@@ -969,7 +969,7 @@
@Override
public <E> List<E> find(String hql, int startIndex, int endIndex, Object... args)
throws TopiaException {
- checkClosed(_("topia.persistence.error.unsupported.operation.on.closed.context",
+ checkClosed(String.format("This context is closed, it is not possible to release the operation '%1$s'",
"find"));
try {
@@ -995,7 +995,7 @@
result = firesSupport.fireEntitiesLoad(this, result);
return result;
} catch (HibernateException eee) {
- throw new TopiaException(_("topia.persistence.error.on.query",
+ throw new TopiaException(String.format("An error occurs while query operation: %1$s : %2$s",
hql, eee.getMessage()), eee);
}
}
@@ -1003,7 +1003,7 @@
@Override
public <E> E findUnique(String hql, Object... paramNamesAndValues)
throws TopiaException {
- checkClosed(_("topia.persistence.error.unsupported.operation.on.closed.context",
+ checkClosed(String.format("This context is closed, it is not possible to release the operation '%1$s'",
"findUnique"));
List<E> results = find(hql, 0, 1, paramNamesAndValues);
@@ -1033,7 +1033,7 @@
*/
@Override
public int execute(String hql, Object... args) throws TopiaException {
- checkClosed(_("topia.persistence.error.unsupported.operation.on.closed.context",
+ checkClosed(String.format("This context is closed, it is not possible to release the operation '%1$s'",
"find"));
try {
@@ -1044,14 +1044,14 @@
int result = query.executeUpdate();
return result;
} catch (HibernateException eee) {
- throw new TopiaException(_("topia.persistence.error.on.query",
+ throw new TopiaException(String.format("An error occurs while query operation: %1$s : %2$s",
hql, eee.getMessage()), eee);
}
}
@Override
public void add(TopiaEntity e) throws TopiaException {
- checkClosed(_("topia.persistence.error.unsupported.operation.on.closed.context",
+ checkClosed(String.format("This context is closed, it is not possible to release the operation '%1$s'",
"add"));
String id = e.getTopiaId();
@@ -1063,17 +1063,16 @@
@Override
public void replicate(TopiaContext dstCtxt, Object... entityAndCondition)
throws TopiaException, IllegalArgumentException {
- checkClosed(_("topia.persistence.error.unsupported.operation.on.closed.context",
+ checkClosed(String.format("This context is closed, it is not possible to release the operation '%1$s'",
"replicate"));
TopiaContextImpl dstContextImpl = (TopiaContextImpl) dstCtxt;
dstContextImpl.checkClosed(
- _("topia.persistence.error.unsupported.operation.on.closed.context",
+ String.format("This context is closed, it is not possible to release the operation '%1$s'",
"replicate"));
if (getRootContext().equals(dstContextImpl.getRootContext())) {
- throw new IllegalArgumentException(
- _("topia.persistence.error.replicate.on.same.context"));
+ throw new IllegalArgumentException("Can not do a replication operation on same database.");
}
String[] queries = buildQueries(entityAndCondition);
@@ -1091,7 +1090,7 @@
}
}
} catch (HibernateException eee) {
- throw new TopiaException(_("topia.persistence.error.on.replicate",
+ throw new TopiaException(String.format("An error occurs while a replication operation: %s",
eee.getMessage()), eee);
}
}
@@ -1100,16 +1099,15 @@
public <T extends TopiaEntity> void replicateEntity(TopiaContext dstCtxt,
T entity)
throws TopiaException, IllegalArgumentException {
- checkClosed(_("topia.persistence.error.unsupported.operation.on.closed.context",
+ checkClosed(String.format("This context is closed, it is not possible to release the operation '%1$s'",
"replicateEntity"));
TopiaContextImpl dstContextImpl = (TopiaContextImpl) dstCtxt;
- dstContextImpl.checkClosed(_("topia.persistence.error.unsupported.operation.on.closed.context",
+ dstContextImpl.checkClosed(String.format("This context is closed, it is not possible to release the operation '%1$s'",
"replicateEntity"));
if (getRootContext().equals(dstContextImpl.getRootContext())) {
- throw new IllegalArgumentException(_(
- "topia.persistence.error.replicate.on.same.context"));
+ throw new IllegalArgumentException("Can not do a replication operation on same database.");
}
replicate0(dstContextImpl, entity);
}
@@ -1118,15 +1116,15 @@
public <T extends TopiaEntity> void replicateEntities(TopiaContext dstCtxt,
List<T> entities)
throws TopiaException, IllegalArgumentException {
- checkClosed(_("topia.persistence.error.unsupported.operation.on.closed.context",
+ checkClosed(String.format("This context is closed, it is not possible to release the operation '%1$s'",
"replicateEntities"));
TopiaContextImpl dstContextImpl = (TopiaContextImpl) dstCtxt;
- dstContextImpl.checkClosed(_("topia.persistence.error.unsupported.operation.on.closed.context",
+ dstContextImpl.checkClosed(String.format("This context is closed, it is not possible to release the operation '%1$s'",
"replicateEntities"));
if (getRootContext().equals(dstContextImpl.getRootContext())) {
- throw new IllegalArgumentException(_("topia.persistence.error.replicate.on.same.context"));
+ throw new IllegalArgumentException("Can not do a replication operation on same database.");
}
replicate0(dstContextImpl, entities.toArray());
}
@@ -1147,7 +1145,7 @@
*/
@Override
public void backup(File file, boolean compress) throws TopiaException {
- checkClosed(_("topia.persistence.error.unsupported.operation.on.closed.context",
+ checkClosed(String.format("This context is closed, it is not possible to release the operation '%1$s'",
"backup"));
try {
String options = "";
@@ -1160,8 +1158,8 @@
query.list();
} catch (Exception eee) {
- throw new TopiaException(_(
- "topia.persistence.error.on.backup",
+ throw new TopiaException(String.format(
+ "An error occurs while backup operation: %1$s",
eee.getMessage()), eee);
}
}
@@ -1177,7 +1175,7 @@
public void restore(File file) throws TopiaException {
// send event
getFiresSupport().firePreRestoreSchema(this);
- checkClosed(_("topia.persistence.error.unsupported.operation.on.closed.context",
+ checkClosed(String.format("This context is closed, it is not possible to release the operation '%1$s'",
"restore"));
String sql = null;
@@ -1210,8 +1208,8 @@
// send event AFTER restore
getFiresSupport().firePostRestoreSchema(this);
} catch (Exception eee) {
- throw new TopiaException(_(
- "topia.persistence.error.on.restore",
+ throw new TopiaException(String.format(
+ "An error occurs while restore operation: %1$s",
sql, eee.getMessage()), eee);
}
}
@@ -1237,7 +1235,7 @@
root.finalize();
} catch (Throwable eee) {
throw new TopiaException(
- _("topia.persistence.error.on.clear", eee.getMessage()), eee);
+ String.format("Error %s on clear operation", eee.getMessage()), eee);
}
}
@@ -1259,7 +1257,7 @@
@Override
public boolean isSchemaExist(Class<?> clazz)
throws TopiaException {
- checkClosed(_("topia.persistence.error.unsupported.operation.on.closed.context",
+ checkClosed(String.format("This context is closed, it is not possible to release the operation '%1$s'",
"replicateEntity"));
boolean result = TopiaUtil.isSchemaExist(this, clazz.getName());
return result;
@@ -1452,7 +1450,7 @@
}
} catch (HibernateException eee) {
- throw new TopiaException(_("topia.persistence.error.on.replicate",
+ throw new TopiaException(String.format("An error occurs while a replication operation : %s",
eee.getMessage()), eee);
}
}
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 2013-07-13 21:18:30 UTC (rev 2764)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/TopiaEntityHelper.java 2013-07-13 22:05:49 UTC (rev 2765)
@@ -25,7 +25,7 @@
package org.nuiton.topia.persistence.util;
-import com.google.common.base.Function;
+import com.google.common.base.Preconditions;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.nuiton.topia.TopiaContext;
@@ -57,8 +57,6 @@
import java.util.SortedMap;
import java.util.TreeMap;
-import static org.nuiton.i18n.I18n._;
-
/**
* Une classe avec des méthodes utiles sur les entités.
*
@@ -109,10 +107,8 @@
TopiaDAO<E> dao, String topiaId) throws TopiaException,
IllegalArgumentException {
E entity = dao.findByTopiaId(topiaId);
- if (entity == null) {
- throw new IllegalArgumentException(
- "could not find entity with topiaId " + topiaId);
- }
+ Preconditions.checkArgument(entity != null,
+ "could not find entity with topiaId " + topiaId);
return entity;
}
@@ -150,14 +146,9 @@
public static <E extends TopiaEntity> void checkNotNullAndExistingEntity(
String paramName, E bean) throws IllegalStateException,
NullPointerException {
- if (bean == null) {
- throw new NullPointerException(paramName + " can not be null");
- }
- if (bean.getTopiaId() == null) {
- // can not create bean here
- throw new IllegalStateException(
- "can not create " + bean.getClass() + " here...");
- }
+ Preconditions.checkNotNull(bean, paramName + " can not be null");
+ Preconditions.checkState(bean.getTopiaId() != null,
+ "can not create " + bean.getClass() + " here...");
}
/**
@@ -172,14 +163,9 @@
public static <E extends TopiaEntity> void checkNotNullAndNoneExistingEntity(
String paramName, E bean) throws NullPointerException,
IllegalStateException {
- if (bean == null) {
- throw new NullPointerException(paramName + " can not be null");
- }
- if (bean.getTopiaId() != null) {
- // can not create bean here
- throw new IllegalStateException(
- "can not update " + bean.getClass() + " here...");
- }
+ Preconditions.checkNotNull(bean, paramName + " can not be null");
+ Preconditions.checkState(bean.getTopiaId() == null,
+ "can not update " + bean.getClass() + " here...");
}
/**
@@ -197,15 +183,9 @@
TopiaContext topiaContext,
URI resource) throws IOException,
TopiaException, NullPointerException {
- if (dbDirectory == null) {
- throw new NullPointerException("dbDirectory can not be null");
- }
- if (topiaContext == null) {
- throw new NullPointerException("topiaContext can not be null");
- }
- if (resource == null) {
- throw new NullPointerException("resource can not be null");
- }
+ Preconditions.checkNotNull(dbDirectory, dbDirectory + " can not be null");
+ Preconditions.checkNotNull(topiaContext, topiaContext + " can not be null");
+ Preconditions.checkNotNull(resource, resource + " can not be null");
File databaseDump;
if (resource.isOpaque()) {
@@ -265,12 +245,9 @@
public static void saveDB(
File gzipFile, TopiaContext topiaContext)
throws TopiaException, IOException, NullPointerException {
- if (gzipFile == null) {
- throw new NullPointerException("gzipFile can not be null");
- }
- if (topiaContext == null) {
- throw new NullPointerException("topiaContext can not be null");
- }
+ Preconditions.checkNotNull(gzipFile, gzipFile + " can not be null");
+ Preconditions.checkNotNull(topiaContext, topiaContext + " can not be null");
+
if (!gzipFile.getParentFile().exists()) {
if (!gzipFile.getParentFile().mkdirs()) {
throw new IOException("could not create directory " +
@@ -674,7 +651,9 @@
List<String> ids = Arrays.asList(expressions);
/** le dictionnaire des références détectées indexées par leur type */
- SortedMap<TopiaEntity, List<TopiaEntityRef>> refs;{
+ SortedMap<TopiaEntity, List<TopiaEntityRef>> refs;
+
+ {
refs = new TreeMap<TopiaEntity, List<TopiaEntityRef>>(
getTopiaIdComparator());
}
@@ -1145,11 +1124,8 @@
public static void checkNotNull(String methodName,
String parameterName,
Object value) {
- if (value == null) {
- throw new NullPointerException(
- _("topia.persistence.error.null.param",
- methodName, parameterName));
- }
+ Preconditions.checkNotNull(value,
+ String.format("The method '%1$s' requires a non null parameter '%2$s'.", methodName, parameterName));
}
public static void checkParameters(Class<?>[] paramsType,
@@ -1161,10 +1137,7 @@
}
public static void checkSize(int size, Object[] params) {
- if (params.length != size) {
- throw new IllegalArgumentException(
- _("topia.persistence.error.invalid.size", size, params.length));
- }
+ Preconditions.checkArgument(params.length == size, String.format("Invalid parameters size. Expected:%d but was:%d", size, params.length));
}
public static void checkType(Class<?>[] paramsType,
@@ -1172,17 +1145,11 @@
Object[] params) {
Class<?> requiredType = paramsType[index];
Object value = params[index];
- if (value == null) {
- throw new IllegalArgumentException(
- _("topia.persistence.error.null.param.in.array", index));
- }
- Class<?> foundType = value.getClass();
+ Preconditions.checkArgument(value != null, String.format("The parameter at index %d must not be null", index));
- if (!requiredType.isAssignableFrom(foundType)) {
- throw new IllegalArgumentException(
- _("topia.persistence.error.invalid.type.in.array",
- index, requiredType, foundType));
- }
+ Class<?> foundType = value.getClass();
+ Preconditions.checkArgument(requiredType.isAssignableFrom(foundType), String.format("The parameter at index %d is not the expected type. Expected:%s but was:%s",
+ index, requiredType, foundType));
}
/**
Modified: trunk/topia-service-migration/pom.xml
===================================================================
--- trunk/topia-service-migration/pom.xml 2013-07-13 21:18:30 UTC (rev 2764)
+++ trunk/topia-service-migration/pom.xml 2013-07-13 22:05:49 UTC (rev 2765)
@@ -65,11 +65,6 @@
</dependency>
<dependency>
- <groupId>org.nuiton.i18n</groupId>
- <artifactId>nuiton-i18n</artifactId>
- </dependency>
-
- <dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
@@ -129,19 +124,6 @@
<plugins>
- <plugin>
- <groupId>org.nuiton.i18n</groupId>
- <artifactId>i18n-maven-plugin</artifactId>
- <executions>
- <execution>
- <goals>
- <goal>parserJava</goal>
- <goal>gen</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
-
</plugins>
</build>
</project>
Modified: trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/AbstractTopiaMigrationCallback.java
===================================================================
--- trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/AbstractTopiaMigrationCallback.java 2013-07-13 21:18:30 UTC (rev 2764)
+++ trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/AbstractTopiaMigrationCallback.java 2013-07-13 22:05:49 UTC (rev 2765)
@@ -38,8 +38,6 @@
import java.sql.SQLException;
import java.util.List;
-import static org.nuiton.i18n.I18n._;
-
/**
* Abstract migration callback.
*
@@ -115,7 +113,7 @@
try {
- log.info(_("topia.migration.start.migrate", v));
+ log.info(String.format("Start migration to version %s", v));
migrateForVersion(v, tx, showSql, showProgression);
@@ -124,7 +122,7 @@
} catch (Exception eee) {
// en cas d'erreur
- log.error("Migration impossible de la base", eee);
+ log.error("Could not migrate database", eee);
// rollback du travail en cours
tx.rollbackTransaction();
// propagation de l'erreur
@@ -168,7 +166,7 @@
if (log.isInfoEnabled()) {
- log.info(_("topia.migration.start.sqls", sqls.length));
+ log.info(String.format("Will execute %1$s requests...", sqls.length));
}
if (showSql) {
StringBuilder buffer = new StringBuilder();
@@ -196,7 +194,7 @@
String message = "";
if (showProgression) {
- message = _("topia.migration.start.sql", index, max);
+ message = String.format("Executing request [%1$-4s/%2$-4s]", index, max);
}
if (showSql) {
message += "\n" + sql;
@@ -214,7 +212,7 @@
}
if (log.isDebugEnabled()) {
String message;
- message = _("topia.migration.end.sql", index, max, StringUtil.convertTime(System.nanoTime() - t0));
+ message = String.format("Request [%1$-4s/%2$-4s] executed in %3$s.", index, max, StringUtil.convertTime(System.nanoTime() - t0));
log.debug(message);
}
}
Modified: trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/TopiaMigrationEngine.java
===================================================================
--- trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/TopiaMigrationEngine.java 2013-07-13 21:18:30 UTC (rev 2764)
+++ trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/TopiaMigrationEngine.java 2013-07-13 22:05:49 UTC (rev 2765)
@@ -25,6 +25,7 @@
package org.nuiton.topia.migration;
+import com.google.common.base.Preconditions;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -51,8 +52,6 @@
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 AbstractTopiaMigrationCallback}
* qui donne la version de l'application, les version de mises à jour disponibles.
@@ -278,9 +277,9 @@
boolean complete = migrateSchema();
if (!complete) {
if (log.isErrorEnabled()) {
- log.error(_("topia.migration.migration.incomplete"));
+ log.error("Database migration not succesfully ended!");
}
- throw new TopiaException(_("topia.migration.migration.incomplete"));
+ throw new TopiaException("Database migration not succesfully ended!");
}
}
@@ -297,9 +296,9 @@
Version version = callback.getApplicationVersion();
- log.info(_("topia.migration.start.migration",
- version.getVersion(),
- dbVersion.getVersion())
+ log.info(String.format("Starting Topia Migration Service - Application version \\: %1$s, Database version \\: %2$s",
+ version.getVersion(),
+ dbVersion.getVersion())
);
if (log.isDebugEnabled()) {
@@ -317,7 +316,7 @@
if (versionTableExist && dbVersion.equals(version)) {
if (log.isInfoEnabled()) {
- log.info(_("topia.migration.skip.migration.db.is.up.to.date"));
+ log.info("Database is up to date, no migration needed.");
}
// la base est a jour
return true;
@@ -325,7 +324,7 @@
// Aucune version existante, la base de données est vierge
if (versionTableExist && dbNotVersioned && migrateOnInit) {
- log.info(_("topia.migration.skip.migration.db.is.empty"));
+ log.info("Database is empty, no migration needed.");
// la base est vierge, aucune migration nécessaire
// mise à jour de la table tmsversion
saveApplicationVersion();
@@ -337,7 +336,7 @@
// on a trouvee une table depreciee tmsVersion avec la bonne version de base
// il suffit donc d'enregister la version dans la nouvelle table
if (log.isInfoEnabled()) {
- log.info(_("topia.migration.skip.migration.db.is.up.to.date"));
+ log.info("Database is up to date, no migration needed.");
}
// la base est a jour mais il faut migrer la table
saveApplicationVersion();
@@ -348,7 +347,7 @@
new TreeSet<Version>(new VersionComparator());
allVersions.addAll(Arrays.asList(callback.getAvailableVersions()));
if (log.isInfoEnabled()) {
- log.info(_("topia.migration.available.versions", allVersions));
+ log.info(String.format("Available versions: %1$s", allVersions));
}
// tell if migration is needed
@@ -367,11 +366,11 @@
if (versionsToApply.isEmpty()) {
if (log.isInfoEnabled()) {
- log.info(_("topia.migration.skip.migration.no.version.to.apply"));
+ log.info("No version to apply, no migration needed.");
}
} else {
if (log.isInfoEnabled()) {
- log.info(_("topia.migration.migrate.versions", versionsToApply));
+ log.info(String.format("Versions to apply: %1$s", versionsToApply));
}
// perform the migration
@@ -457,14 +456,14 @@
TMSVersionDAO.deleteAll(tx);
if (log.isInfoEnabled()) {
- log.info(_("topia.migration.saving.db.version", version));
+ log.info(String.format("Saving new database version: %1$s", version));
}
// create new version and store it in table
TMSVersion tmsVersion =
TMSVersionDAO.create(tx, version.getVersion());
if (log.isDebugEnabled()) {
- log.debug("Created version : " + tmsVersion.getVersion());
+ log.debug("Created version: " + tmsVersion.getVersion());
}
tx.commitTransaction();
@@ -572,7 +571,7 @@
if (v != null) {
if (log.isDebugEnabled()) {
- log.debug("Legacy : " + _("topia.migration.detected.db.version", v));
+ log.debug(String.format("Legacy : detected database version: %1$s", v));
}
}
}
@@ -585,9 +584,9 @@
// etre detenu en local
v = Version.VZERO;
dbNotVersioned = true;
- log.info(_("topia.migration.db.not.versionned"));
+ log.info("Database version not found, so database schema is considered as V0");
} else {
- log.info(_("topia.migration.detected.db.version", v));
+ log.info(String.format("detected database version: %1$s", v));
}
dbVersion = v;
versionDetected = true;
@@ -642,16 +641,12 @@
protected String getSafeParameter(Properties config, String key) {
String value = config.getProperty(key, null);
- if (StringUtils.isEmpty(value)) {
- throw new IllegalStateException("'" + key + "' not set.");
- }
+ Preconditions.checkState(StringUtils.isNotEmpty(value), "'" + key + "' not set.");
return value;
}
protected void checkInit() {
- if (!init) {
- throw new IllegalStateException("le service n'est pas initialisé!");
- }
+ Preconditions.checkState(init, "Service was not initialized!");
}
/**
Modified: trunk/topia-service-replication/pom.xml
===================================================================
--- trunk/topia-service-replication/pom.xml 2013-07-13 21:18:30 UTC (rev 2764)
+++ trunk/topia-service-replication/pom.xml 2013-07-13 22:05:49 UTC (rev 2765)
@@ -60,11 +60,6 @@
</dependency>
<dependency>
- <groupId>org.nuiton.i18n</groupId>
- <artifactId>nuiton-i18n</artifactId>
- </dependency>
-
- <dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
</dependency>
@@ -118,18 +113,6 @@
<build>
<plugins>
- <plugin>
- <groupId>org.nuiton.i18n</groupId>
- <artifactId>i18n-maven-plugin</artifactId>
- <executions>
- <execution>
- <goals>
- <goal>parserJava</goal>
- <goal>gen</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
@@ -207,7 +190,7 @@
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
- <version>2.4</version>
+ <version>${coberturaPluginVersion}</version>
</plugin>
</plugins>
</reporting>
Modified: trunk/topia-service-replication/src/main/java/org/nuiton/topia/replication/TopiaReplicationModelBuilder.java
===================================================================
--- trunk/topia-service-replication/src/main/java/org/nuiton/topia/replication/TopiaReplicationModelBuilder.java 2013-07-13 21:18:30 UTC (rev 2764)
+++ trunk/topia-service-replication/src/main/java/org/nuiton/topia/replication/TopiaReplicationModelBuilder.java 2013-07-13 22:05:49 UTC (rev 2765)
@@ -38,8 +38,6 @@
import java.util.Arrays;
import java.util.Set;
-import static org.nuiton.i18n.I18n._;
-
/**
* Builder of {@link ReplicationModel}.
*
@@ -128,7 +126,7 @@
if (operation == null) {
throw new IllegalArgumentException(
- _("topia.replication.error.unkown.operation",
+ String.format("The operation %1$s is unknown, known operations are: %2$s",
operationClass.getSimpleName(),
Arrays.toString(getOperationProvider().getOperations()))
);
@@ -137,7 +135,7 @@
ReplicationNode node = model.getNode(type);
if (node == null) {
throw new IllegalArgumentException(
- _("topia.replication.error.unkown.owner.node",
+ String.format("The target node (of type %1$s) for operation %2$s is unknown, known nodes are: %3$s",
type,
operationClass.getSimpleName(),
model.getNodes())
Modified: trunk/topia-service-replication/src/main/java/org/nuiton/topia/replication/operation/AttachLink.java
===================================================================
--- trunk/topia-service-replication/src/main/java/org/nuiton/topia/replication/operation/AttachLink.java 2013-07-13 21:18:30 UTC (rev 2764)
+++ trunk/topia-service-replication/src/main/java/org/nuiton/topia/replication/operation/AttachLink.java 2013-07-13 22:05:49 UTC (rev 2765)
@@ -44,8 +44,6 @@
import java.util.Collections;
import java.util.List;
-import static org.nuiton.i18n.I18n._;
-
/**
* Pour attacher une association.
* <p/>
@@ -132,8 +130,7 @@
if (ownerIds == null || ownerIds.isEmpty()) {
// pas de donnees a traiter
- log.info(_("topia.replication.attachAssociation.nothing.to.do",
- ownerOperator));
+ log.info("Nothing to attach...");
return;
}
Modified: trunk/topia-service-replication/src/main/java/org/nuiton/topia/replication/operation/LoadLink.java
===================================================================
--- trunk/topia-service-replication/src/main/java/org/nuiton/topia/replication/operation/LoadLink.java 2013-07-13 21:18:30 UTC (rev 2764)
+++ trunk/topia-service-replication/src/main/java/org/nuiton/topia/replication/operation/LoadLink.java 2013-07-13 22:05:49 UTC (rev 2765)
@@ -41,8 +41,6 @@
import java.util.List;
-import static org.nuiton.i18n.I18n._;
-
/**
* Pour charger une association sur le noeud de l'operation.
* <p/>
@@ -84,8 +82,8 @@
if (!ownerNode.equals(operationDef.getNode())) {
throw new IllegalStateException(
- _("topia.replication.error.operation.loadLink.illegalSource",
- operationDef.getNode(), ownerNode));
+ String.format("The source node of loading association requires the node %1$s, but was %2$s.",
+ operationDef.getNode(), ownerNode));
}
if (log.isDebugEnabled()) {
Modified: trunk/topia-service-security/pom.xml
===================================================================
--- trunk/topia-service-security/pom.xml 2013-07-13 21:18:30 UTC (rev 2764)
+++ trunk/topia-service-security/pom.xml 2013-07-13 22:05:49 UTC (rev 2765)
@@ -63,11 +63,6 @@
</dependency>
<dependency>
- <groupId>org.nuiton.i18n</groupId>
- <artifactId>nuiton-i18n</artifactId>
- </dependency>
-
- <dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
1
0
r2764 - in trunk: topia-persistence/src/main/java/org/nuiton/topia/framework topia-persistence/src/test/java/org/nuiton/topia/framework topia-service-migration/src/main/java/org/nuiton/topia/migration
by tchemit@users.nuiton.org 13 Jul '13
by tchemit@users.nuiton.org 13 Jul '13
13 Jul '13
Author: tchemit
Date: 2013-07-13 23:18:30 +0200 (Sat, 13 Jul 2013)
New Revision: 2764
Url: http://nuiton.org/projects/topia/repository/revisions/2764
Log:
fixes #2759: Fix back behaviour before version 2.8 around TopiaUtil.isSchemaExist
Modified:
trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaUtil.java
trunk/topia-persistence/src/test/java/org/nuiton/topia/framework/TopiaUtilTest.java
trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/TopiaMigrationEngine.java
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaUtil.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaUtil.java 2013-07-13 21:09:40 UTC (rev 2763)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaUtil.java 2013-07-13 21:18:30 UTC (rev 2764)
@@ -24,10 +24,12 @@
*/
package org.nuiton.topia.framework;
+import com.google.common.base.Supplier;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.cfg.Configuration;
import org.hibernate.dialect.Dialect;
+import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.mapping.PersistentClass;
import org.hibernate.mapping.Table;
import org.hibernate.service.ServiceRegistry;
@@ -42,6 +44,8 @@
import org.nuiton.util.RecursiveProperties;
import org.nuiton.util.Resource;
+import java.io.Closeable;
+import java.io.IOException;
import java.net.URL;
import java.sql.Connection;
import java.sql.SQLException;
@@ -164,11 +168,16 @@
public static boolean isSchemaExist(TopiaContext tx,
String entityName) {
+ TopiaContextImplementor txi = (TopiaContextImplementor) tx;
+
+ ConnectionProviderSupplier connectionProviderSupplier =
+ new ConnectionProviderSupplier(((SessionFactoryImplementor) txi.getHibernateFactory()).getServiceRegistry());
+
boolean exist = false;
try {
- TopiaContextImplementor txi = (TopiaContextImplementor) tx;
+
Configuration configuration = txi.getHibernateConfiguration();
PersistentClass classMapping =
configuration.getClassMapping(entityName);
@@ -190,7 +199,7 @@
}
ConnectionProvider connectionProvider =
- getConnectionProvider(configuration);
+ connectionProviderSupplier.get();
Dialect dialect = Dialect.getDialect(configuration.getProperties());
@@ -198,7 +207,7 @@
try {
connection = connectionProvider.getConnection();
- DatabaseMetadata meta = new DatabaseMetadata(connection, dialect);
+ DatabaseMetadata meta = new DatabaseMetadata(connection, dialect, configuration);
TableMetadata tmd = meta.getTableMetadata(
testTable.getName(), testTable.getSchema(),
@@ -209,9 +218,7 @@
exist = true;
}
} finally {
- if (connection != null) {
- connection.close();
- }
+ connectionProvider.closeConnection(connection);
}
} catch (SQLException e) {
@@ -234,6 +241,9 @@
public static boolean isSchemaExist(Configuration configuration,
String entityName) {
+ ConnectionProviderSupplier connectionProviderSupplier =
+ new ConnectionProviderSupplier(configuration);
+
boolean exist = false;
try {
@@ -257,7 +267,7 @@
}
ConnectionProvider connectionProvider =
- getConnectionProvider(configuration);
+ connectionProviderSupplier.get();
Dialect dialect = Dialect.getDialect(configuration.getProperties());
@@ -265,7 +275,7 @@
try {
connection = connectionProvider.getConnection();
- DatabaseMetadata meta = new DatabaseMetadata(connection, dialect);
+ DatabaseMetadata meta = new DatabaseMetadata(connection, dialect, configuration);
TableMetadata tmd = meta.getTableMetadata(
testTable.getName(), testTable.getSchema(),
@@ -276,15 +286,20 @@
exist = true;
}
} finally {
- if (connection != null) {
- connection.close();
- }
+ connectionProvider.closeConnection(connection);
}
} catch (SQLException e) {
log.error("Cant connect to database", e);
}
+ // close connectionProviderSupplier
+ try {
+ connectionProviderSupplier.close();
+ } catch (IOException e) {
+ log.error("Cant close connection provider", e);
+ }
+
return exist;
}
@@ -299,10 +314,13 @@
*/
public static boolean isSchemaEmpty(Configuration configuration) {
+ ConnectionProviderSupplier connectionProviderSupplier =
+ new ConnectionProviderSupplier(configuration);
+
try {
ConnectionProvider connectionProvider =
- getConnectionProvider(configuration);
+ connectionProviderSupplier.get();
Dialect dialect = Dialect.getDialect(configuration.getProperties());
@@ -344,18 +362,109 @@
}
} finally {
- if (connection != null) {
- connection.close();
+ connectionProvider.closeConnection(connection);
+ }
+
+ } catch (SQLException e) {
+ log.error("Cant connect to database", e);
+ }
+
+ // close connectionProviderSupplier
+ try {
+ connectionProviderSupplier.close();
+ } catch (IOException e) {
+ log.error("Cant close connection provider", e);
+ }
+
+ return true;
+ }
+
+ /**
+ * Test if the db associated to the given {@code configuration} contaisn any of
+ * the dealed entities.
+ *
+ * @param tx topia context
+ * @return {@code true} if there is no schema for any of the dealed entities,
+ * {@code false} otherwise.
+ * @since 2.5.3
+ */
+ public static boolean isSchemaEmpty(TopiaContext tx) {
+
+
+ TopiaContextImplementor txi = (TopiaContextImplementor) tx;
+
+ Configuration configuration = txi.getHibernateConfiguration();
+
+ ConnectionProviderSupplier connectionProviderSupplier =
+ new ConnectionProviderSupplier(((SessionFactoryImplementor) txi.getHibernateFactory()).getServiceRegistry());
+
+ try {
+
+ ConnectionProvider connectionProvider =
+ connectionProviderSupplier.get();
+
+ Dialect dialect = Dialect.getDialect(configuration.getProperties());
+
+ Connection connection = null;
+ try {
+ connection = connectionProvider.getConnection();
+
+ DatabaseMetadata meta = new DatabaseMetadata(connection, dialect, configuration);
+
+ Iterator<?> itr = configuration.getClassMappings();
+ while (itr.hasNext()) {
+ PersistentClass classMapping = (PersistentClass) itr.next();
+ Table testTable = classMapping.getTable();
+
+ if (testTable == null) {
+ throw new IllegalArgumentException(
+ "could not find entity with name " +
+ classMapping.getClassName());
+ }
+
+
+ TableMetadata tmd = meta.getTableMetadata(
+ testTable.getName(), testTable.getSchema(),
+ testTable.getCatalog(), testTable.isQuoted());
+
+ if (tmd != null) {
+ //table exist
+
+ if (log.isDebugEnabled()) {
+ log.debug("Existing table found " +
+ testTable.getName() + " for entity " +
+ classMapping.getClassName() +
+ ", db is not empty.");
+ }
+
+ return false;
+ }
}
+
+ } finally {
+ connectionProvider.closeConnection(connection);
}
} catch (SQLException e) {
log.error("Cant connect to database", e);
}
+ // close connectionProviderSupplier
+ try {
+ connectionProviderSupplier.close();
+ } catch (IOException e) {
+ log.error("Cant close connection provider", e);
+ }
+
return true;
}
+ /**
+ * @param configuration
+ * @return
+ * @deprecated since 3.0, will be remove soon, do not use it, prefer use {@link ConnectionProviderSupplier}.
+ */
+ @Deprecated
protected static ConnectionProvider getConnectionProvider(Configuration configuration) {
ServiceRegistry serviceRegistry = new ServiceRegistryBuilder().applySettings(
configuration.getProperties()).buildServiceRegistry();
@@ -371,4 +480,39 @@
public static String getSchemaName(Configuration config) {
return config.getProperty(TopiaContextFactory.CONFIG_DEFAULT_SCHEMA);
}
+
+ public static class ConnectionProviderSupplier implements Supplier<ConnectionProvider>, Closeable {
+
+ protected ServiceRegistry serviceRegistry;
+
+ protected ConnectionProvider connectionProvider;
+
+ protected final boolean inlineRegistry;
+
+ public ConnectionProviderSupplier(ServiceRegistry serviceRegistry) {
+ inlineRegistry = false;
+ this.serviceRegistry = serviceRegistry;
+ }
+
+ public ConnectionProviderSupplier(Configuration configuration) {
+ inlineRegistry = true;
+ this.serviceRegistry = new ServiceRegistryBuilder().applySettings(
+ configuration.getProperties()).buildServiceRegistry();
+ }
+
+ @Override
+ public ConnectionProvider get() {
+ if (connectionProvider == null) {
+ connectionProvider = serviceRegistry.getService(ConnectionProvider.class);
+ }
+ return connectionProvider;
+ }
+
+ @Override
+ public void close() throws IOException {
+ if (inlineRegistry) {
+ ServiceRegistryBuilder.destroy(serviceRegistry);
+ }
+ }
+ }
}
Modified: trunk/topia-persistence/src/test/java/org/nuiton/topia/framework/TopiaUtilTest.java
===================================================================
--- trunk/topia-persistence/src/test/java/org/nuiton/topia/framework/TopiaUtilTest.java 2013-07-13 21:09:40 UTC (rev 2763)
+++ trunk/topia-persistence/src/test/java/org/nuiton/topia/framework/TopiaUtilTest.java 2013-07-13 21:18:30 UTC (rev 2764)
@@ -103,7 +103,7 @@
// FIXME echatellier 20130315 ce test fail depuis probablement a cause
// de hibernate.hbm2ddl.auto=update, à confirmer...
- assertFalse(actual);
+ assertTrue(actual);
TopiaContext tx = rootContext.beginTransaction();
tx.createSchema();
Modified: trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/TopiaMigrationEngine.java
===================================================================
--- trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/TopiaMigrationEngine.java 2013-07-13 21:09:40 UTC (rev 2763)
+++ trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/TopiaMigrationEngine.java 2013-07-13 21:18:30 UTC (rev 2764)
@@ -608,10 +608,10 @@
try {
boolean result;
// get db real hibernate configuration
- Configuration rootConfiguration =
- rootContext.getHibernateConfiguration();
+// Configuration rootConfiguration =
+// rootContext.getHibernateConfiguration();
- result = TopiaUtil.isSchemaEmpty(rootConfiguration);
+ result = TopiaUtil.isSchemaEmpty(rootContext);
return result;
} catch (TopiaNotFoundException e) {
throw new RuntimeException(e);
1
0
r2763 - trunk/topia-persistence/src/main/java/org/nuiton/topia/generator
by tchemit@users.nuiton.org 13 Jul '13
by tchemit@users.nuiton.org 13 Jul '13
13 Jul '13
Author: tchemit
Date: 2013-07-13 23:09:40 +0200 (Sat, 13 Jul 2013)
New Revision: 2763
Url: http://nuiton.org/projects/topia/repository/revisions/2763
Log:
fixes #2341: Add warning about 'analyze' keyword
Modified:
trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/TopiaMetaTransformer.java
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/TopiaMetaTransformer.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/TopiaMetaTransformer.java 2013-07-13 21:08:38 UTC (rev 2762)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/TopiaMetaTransformer.java 2013-07-13 21:09:40 UTC (rev 2763)
@@ -76,6 +76,8 @@
AttributeNamesValidator attrValidator = new AttributeNamesValidator(
model);
+ attrValidator.addNameAndReason("analyze",
+ "Le nom d'attribut \"analyze\" est incompatible avec certains SGBD");
attrValidator.addNameAndReason("next",
"Le nom d'attribut \"next\" est incompatible avec HSQL");
attrValidator.addNameAndReason("value",
1
0
r2762 - trunk/topia-persistence/src/main/java/org/nuiton/topia/framework
by tchemit@users.nuiton.org 13 Jul '13
by tchemit@users.nuiton.org 13 Jul '13
13 Jul '13
Author: tchemit
Date: 2013-07-13 23:08:38 +0200 (Sat, 13 Jul 2013)
New Revision: 2762
Url: http://nuiton.org/projects/topia/repository/revisions/2762
Log:
fixes #2758: Improved TopiaConnectionProvider
Modified:
trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaConnectionProvider.java
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaConnectionProvider.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaConnectionProvider.java 2013-07-13 21:07:58 UTC (rev 2761)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaConnectionProvider.java 2013-07-13 21:08:38 UTC (rev 2762)
@@ -24,6 +24,18 @@
*/
package org.nuiton.topia.framework;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.hibernate.HibernateException;
+import org.hibernate.cfg.Environment;
+import org.hibernate.internal.util.ReflectHelper;
+import org.hibernate.internal.util.config.ConfigurationHelper;
+import org.hibernate.service.UnknownUnwrapTypeException;
+import org.hibernate.service.jdbc.connections.internal.ConnectionProviderInitiator;
+import org.hibernate.service.jdbc.connections.spi.ConnectionProvider;
+import org.hibernate.service.spi.Configurable;
+import org.hibernate.service.spi.Stoppable;
+
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
@@ -32,15 +44,6 @@
import java.util.Map;
import java.util.Properties;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.hibernate.HibernateException;
-import org.hibernate.cfg.Environment;
-import org.hibernate.internal.util.ReflectHelper;
-import org.hibernate.internal.util.config.ConfigurationHelper;
-import org.hibernate.service.jdbc.connections.internal.ConnectionProviderInitiator;
-import org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl;
-
/**
* Customized connection provider.
* <p/>
@@ -62,22 +65,24 @@
* @author tchemit <chemit(a)codelutin.com>
* @since 2.5.3
*/
-public class TopiaConnectionProvider extends DriverManagerConnectionProviderImpl {
+public class TopiaConnectionProvider implements ConnectionProvider, Configurable, Stoppable {//}, ServiceRegistryAwareService {
/** Logger. */
private static final Log log =
LogFactory.getLog(TopiaConnectionProvider.class);
+ private static final long serialVersionUID = -8190835231054317644L;
+
/**
* JDBC url of connection.
* <p/>
* This is a mandatory hibernate configuration vi the property
* {@link Environment#URL}.
*/
- private String url;
+ protected String url;
/** All grabbed connection properties */
- private Properties connectionProps;
+ protected Properties connectionProps;
/**
* Sql isolation level to use in connection.
@@ -86,7 +91,7 @@
*
* @see Connection#getTransactionIsolation()
*/
- private Integer isolation;
+ protected Integer isolation;
/**
* auto commit connection state.
@@ -95,7 +100,7 @@
*
* @see Connection#getAutoCommit()
*/
- private boolean autocommit;
+ protected boolean autocommit;
/**
* Size of connection pool.
@@ -103,18 +108,22 @@
* By default use {@code 20}, can be specify by using the hibernate
* configuration property {@link Environment#POOL_SIZE}.
*/
- private int poolSize;
+ protected int poolSize;
+ private boolean stopped;
+
/** Our pool of connections which are not closed and availables. */
- private final List<Connection> pool;
+ protected final List<Connection> pool;
+// protected ServiceRegistryImplementor serviceRegistry;
+
public TopiaConnectionProvider() {
pool = new ArrayList<Connection>();
}
@Override
public void configure(Map configurationValues) throws HibernateException {
- String driverClass = (String)configurationValues.get(Environment.DRIVER);
+ String driverClass = (String) configurationValues.get(Environment.DRIVER);
poolSize = ConfigurationHelper.getInt(Environment.POOL_SIZE, configurationValues, 20); //default pool size 20
if (log.isDebugEnabled()) {
@@ -129,7 +138,7 @@
if (isolation != null) {
if (log.isDebugEnabled()) {
log.debug("JDBC isolation level: " +
- Environment.isolationLevelToString(isolation));
+ Environment.isolationLevelToString(isolation));
}
}
@@ -154,7 +163,7 @@
}
}
- url = (String)configurationValues.get(Environment.URL);
+ url = (String) configurationValues.get(Environment.URL);
if (url == null) {
String msg = "JDBC URL was not specified by property " +
Environment.URL;
@@ -175,7 +184,7 @@
log.debug("connection properties: " + connectionProps);
} else if (log.isDebugEnabled()) {
log.debug("connection properties: " +
- ConfigurationHelper.maskOut(connectionProps, "password"));
+ ConfigurationHelper.maskOut(connectionProps, "password"));
}
}
@@ -272,8 +281,10 @@
@Override
protected void finalize() throws Throwable {
+ if (!stopped) {
+ stop();
+ }
super.finalize();
- stop();
}
@Override
@@ -293,7 +304,7 @@
}
}
pool.clear();
-
+ stopped = true;
}
@Override
@@ -325,4 +336,25 @@
return autocommit;
}
+// @Override
+// public void injectServices(ServiceRegistryImplementor serviceRegistry) {
+// this.serviceRegistry = serviceRegistry;
+// }
+
+ @Override
+ public boolean isUnwrappableAs(Class unwrapType) {
+ return ConnectionProvider.class.equals(unwrapType) ||
+ getClass().isAssignableFrom(unwrapType);
+ }
+
+ @Override
+ @SuppressWarnings({"unchecked"})
+ public <T> T unwrap(Class<T> unwrapType) {
+ if (ConnectionProvider.class.equals(unwrapType) ||
+ getClass().isAssignableFrom(unwrapType)) {
+ return (T) this;
+ } else {
+ throw new UnknownUnwrapTypeException(unwrapType);
+ }
+ }
}
1
0
r2761 - trunk/topia-persistence/src/main/java/org/nuiton/topia/framework
by tchemit@users.nuiton.org 13 Jul '13
by tchemit@users.nuiton.org 13 Jul '13
13 Jul '13
Author: tchemit
Date: 2013-07-13 23:07:58 +0200 (Sat, 13 Jul 2013)
New Revision: 2761
Url: http://nuiton.org/projects/topia/repository/revisions/2761
Log:
fixes #2757: ConnectionProvider is not closed when closing root context
Modified:
trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaContextImpl.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 2013-07-13 13:16:04 UTC (rev 2760)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaContextImpl.java 2013-07-13 21:07:58 UTC (rev 2761)
@@ -43,6 +43,8 @@
import org.hibernate.jdbc.Work;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.service.ServiceRegistryBuilder;
+import org.hibernate.service.jdbc.connections.spi.ConnectionProvider;
+import org.hibernate.service.spi.Stoppable;
import org.hibernate.tool.hbm2ddl.SchemaExport;
import org.hibernate.tool.hbm2ddl.SchemaUpdate;
import org.nuiton.topia.TopiaContext;
@@ -873,6 +875,12 @@
} else {
if (hibernateFactory != null) {
hibernateFactory.close();
+ // close connection provider if possible (http://nuiton.org/issues/2757)
+ ConnectionProvider service = ((SessionFactoryImplementor) hibernateFactory).getServiceRegistry().getService(ConnectionProvider.class);
+ if (service instanceof Stoppable) {
+ Stoppable stoppable = (Stoppable) service;
+ stoppable.stop();
+ }
closed = true;
TopiaContextFactory.removeContext(this);
log.debug("TopiaContext removed");
1
0
r2760 - trunk/topia-persistence/src/main/java/org/nuiton/topia/framework
by tchemit@users.nuiton.org 13 Jul '13
by tchemit@users.nuiton.org 13 Jul '13
13 Jul '13
Author: tchemit
Date: 2013-07-13 15:16:04 +0200 (Sat, 13 Jul 2013)
New Revision: 2760
Url: http://nuiton.org/projects/topia/repository/revisions/2760
Log:
fixes #2755: Creating a schema should not droping it just before
fixes #2756: Does not use hardcoded cast to hibernate implementation
Modified:
trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaContextImpl.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 2013-07-13 13:11:07 UTC (rev 2759)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaContextImpl.java 2013-07-13 13:16:04 UTC (rev 2760)
@@ -37,9 +37,9 @@
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
+import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.event.service.spi.EventListenerRegistry;
import org.hibernate.event.spi.EventType;
-import org.hibernate.internal.SessionFactoryImpl;
import org.hibernate.jdbc.Work;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.service.ServiceRegistryBuilder;
@@ -106,7 +106,7 @@
* <p/>
* Created: 23 déc. 2005 16:58:50
*
- * @author poussin <poussin(a)codelutin.com>
+ * @author bpoussin <poussin(a)codelutin.com>
* @author tchemit <chemit(a)codelutin.com>
* @author fdesbois <desbois(a)codelutin.com>
* @version $Id$
@@ -473,8 +473,7 @@
showSchema = true;
}
getFiresSupport().firePreCreateSchema(this);
- new SchemaExport(getHibernateConfiguration()).create(showSchema,
- true);
+ new SchemaExport(getHibernateConfiguration()).execute(showSchema, true, false, true);
getFiresSupport().firePostCreateSchema(this);
} catch (HibernateException eee) {
throw new TopiaException(
@@ -537,7 +536,7 @@
// we can't reuse original serviceRegistry instance
// we must call getServiceRegistry on factory to get a working one
- ServiceRegistry serviceRegistryInit = ((SessionFactoryImpl)hibernateFactory).getServiceRegistry();
+ ServiceRegistry serviceRegistryInit = ((SessionFactoryImplementor) hibernateFactory).getServiceRegistry();
EventListenerRegistry eventListenerRegistry = serviceRegistryInit.getService(EventListenerRegistry.class);
TopiaFiresSupport.TopiaHibernateEvent listener =
new TopiaFiresSupport.TopiaHibernateEvent(this);
1
0