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
May 2012
- 4 participants
- 135 discussions
Author: tchemit
Date: 2012-05-23 15:11:56 +0200 (Wed, 23 May 2012)
New Revision: 2500
Url: http://nuiton.org/repositories/revision/topia/2500
Log:
use correct eugene configuration since http://nuiton.org/issues/1617 is fixed
Modified:
trunk/topia-persistence-tck/pom.xml
Modified: trunk/topia-persistence-tck/pom.xml
===================================================================
--- trunk/topia-persistence-tck/pom.xml 2012-05-23 13:11:18 UTC (rev 2499)
+++ trunk/topia-persistence-tck/pom.xml 2012-05-23 13:11:56 UTC (rev 2500)
@@ -160,11 +160,11 @@
<artifactId>geronimo-jpa_2.0_spec</artifactId>
<version>${geronimoJpaSpecVersion}</version>
</dependency>
- <!--dependency>
+ <dependency>
<groupId>${project.groupId}</groupId>
<artifactId>topia-persistence</artifactId>
<version>${project.version}</version>
- </dependency-->
+ </dependency>
</dependencies>
</plugin>
</plugins>
1
0
Author: tchemit
Date: 2012-05-23 15:11:18 +0200 (Wed, 23 May 2012)
New Revision: 2499
Url: http://nuiton.org/repositories/revision/topia/2499
Log:
use next eugene version
Modified:
trunk/pom.xml
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2012-05-23 13:00:47 UTC (rev 2498)
+++ trunk/pom.xml 2012-05-23 13:11:18 UTC (rev 2499)
@@ -68,7 +68,7 @@
<projectId>topia</projectId>
<!-- libs version -->
- <eugeneVersion>2.4.2</eugeneVersion>
+ <eugeneVersion>2.4.3-SNAPSHOT</eugeneVersion>
<nuitonUtilsVersion>2.4.8</nuitonUtilsVersion>
<processorPluginVersion>1.2.2</processorPluginVersion>
<nuitonI18nVersion>2.4.1</nuitonI18nVersion>
1
0
r2498 - in trunk: topia-persistence topia-persistence/src/main/java/org/nuiton/topia topia-persistence/src/main/java/org/nuiton/topia/framework topia-persistence/src/main/resources/i18n topia-persistence-hibernate/src/main/java/org/nuiton/topia/persistence topia-persistence-tck/src/test/java/org/nuiton/topia/framework
by athimel@users.nuiton.org 23 May '12
by athimel@users.nuiton.org 23 May '12
23 May '12
Author: athimel
Date: 2012-05-23 15:00:47 +0200 (Wed, 23 May 2012)
New Revision: 2498
Url: http://nuiton.org/repositories/revision/topia/2498
Log:
TopiaContextImpl cleaning and commented code reactivation
Depreciate import/exportXML and move to TopiaSpecificUtil
Create a H2 specific util for backup/restore/clean
Added:
trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaH2Util.java
Modified:
trunk/topia-persistence-hibernate/src/main/java/org/nuiton/topia/persistence/TopiaHibernateSpecificUtil.java
trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/framework/TopiaContextImplTest.java
trunk/topia-persistence/pom.xml
trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaContext.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaContextImpl.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaSpecificUtil.java
trunk/topia-persistence/src/main/resources/i18n/topia-persistence_en_GB.properties
trunk/topia-persistence/src/main/resources/i18n/topia-persistence_es_ES.properties
trunk/topia-persistence/src/main/resources/i18n/topia-persistence_fr_FR.properties
Modified: trunk/topia-persistence/pom.xml
===================================================================
--- trunk/topia-persistence/pom.xml 2012-05-23 09:18:09 UTC (rev 2497)
+++ trunk/topia-persistence/pom.xml 2012-05-23 13:00:47 UTC (rev 2498)
@@ -122,6 +122,12 @@
<scope>test</scope>
</dependency>
+ <!-- TODO AThimel 23/05/2012 Remove when import/exportXML are removed from TopiaContextImpl -->
+ <dependency>
+ <groupId>dom4j</groupId>
+ <artifactId>dom4j</artifactId>
+ </dependency>
+
</dependencies>
<build>
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaContext.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaContext.java 2012-05-23 09:18:09 UTC (rev 2497)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaContext.java 2012-05-23 13:00:47 UTC (rev 2498)
@@ -31,6 +31,7 @@
import org.nuiton.topia.event.TopiaEntityVetoable;
import org.nuiton.topia.event.TopiaTransactionListener;
import org.nuiton.topia.event.TopiaTransactionVetoable;
+import org.nuiton.topia.framework.TopiaH2Util;
import org.nuiton.topia.framework.TopiaQuery;
import org.nuiton.topia.framework.TopiaService;
import org.nuiton.topia.persistence.TopiaEntity;
@@ -211,6 +212,9 @@
/**
* Permet de faire une requete HQL hibernate directement sur la base.
*
+ * WARNING : Depending on the registered service, this method may not
+ * support something else than queries on TopiaEntity
+ *
* @param hql la requete a faire
* @param args les arguments de la requete
* @return La liste des resultats
@@ -223,6 +227,9 @@
* precisant la fenetre des elements a remonter avec les parametres {@code
* startIndex} et {@code endIndex}.
*
+ * WARNING : Depending on the registered service, this method may not
+ * support something else than queries on TopiaEntity
+ *
* @param hql la requete a faire
* @param startIndex la position du premier element a remonter
* @param endIndex la position du dernier element a remonter
@@ -257,7 +264,9 @@
*
* @param xml le flux XML
* @throws TopiaException si une erreur survient durant l'import
+ * @deprecated nobody uses it, will be removed in future versions
*/
+ @Deprecated
void importXML(Reader xml) throws TopiaException;
/**
@@ -272,7 +281,9 @@
* where que doit respecter l'objet pour etre
* exporter (entityClass, condition)
* @throws TopiaException si une erreur survient durant l'export
+ * @deprecated nobody uses it, will be removed in future versions
*/
+ @Deprecated
void exportXML(Writer xml, Object... entityAndCondition)
throws TopiaException;
@@ -331,6 +342,29 @@
throws TopiaException, IllegalArgumentException;
/**
+ * Closes the context. All the child contexts will be closed in the same
+ * time.
+ *
+ * @throws TopiaException if any exception
+ */
+ void closeContext() throws TopiaException;
+
+ /**
+ * Indique si le contexte a ete fermé.
+ *
+ * @return {@code true} si le context est fermé, {@code false} autrement
+ */
+ boolean isClosed();
+
+ /**
+ * Execute a given sql code inside this transaction.
+ *
+ * @param sqlScript the sql script to execute
+ * @throws TopiaException if any problem occurs while executing the sql script.
+ */
+ void executeSQL(String sqlScript) throws TopiaException;
+
+ /**
* Sauve la base de données dans un format natif a la base, la
* representation n'est pas portable d'une base a l'autre. Cette methode ne
* doit être utilisé que pour un stockage temporaire utile à une
@@ -339,7 +373,10 @@
* @param file le nom du fichier ou stocker les informations
* @param compress si vrai compress le fichier avec gzip
* @throws TopiaException if any exception
+ * @deprecated use database specific class : {@link TopiaH2Util}
+ * @see TopiaH2Util#backup(File, boolean)
*/
+ @Deprecated
void backup(File file, boolean compress) throws TopiaException;
/**
@@ -348,7 +385,10 @@
* @param file le fichier ou prendre les informations, il peut-etre
* compressé avec gzip ou non.
* @throws TopiaException if any exception
+ * @deprecated use database specific class : {@link TopiaH2Util}
+ * @see TopiaH2Util#restore(File)
*/
+ @Deprecated
void restore(File file) throws TopiaException;
/**
@@ -359,30 +399,10 @@
* supprimé (ex: h2) ou sera fait sur la base
* (postgresql)
* @throws TopiaException if any exception
+ * @deprecated use database specific class : {@link TopiaH2Util}
+ * @see TopiaH2Util#clear(boolean)
*/
+ @Deprecated
void clear(boolean dropDatabase) throws TopiaException;
- /**
- * Closes the context. All the child contexts will be closed in the same
- * time.
- *
- * @throws TopiaException if any exception
- */
- void closeContext() throws TopiaException;
-
- /**
- * Indique si le contexte a ete fermé.
- *
- * @return {@code true} si le context est fermé, {@code false} autrement
- */
- boolean isClosed();
-
- /**
- * Execute a given sql code inside this transaction.
- *
- * @param sqlScript the sql script to execute
- * @throws TopiaException if any problem occurs while executing the sql script.
- */
- void executeSQL(String sqlScript) throws TopiaException;
-
} //TopiaContext
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 2012-05-23 09:18:09 UTC (rev 2497)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaContextImpl.java 2012-05-23 13:00:47 UTC (rev 2498)
@@ -25,12 +25,21 @@
package org.nuiton.topia.framework;
+import com.google.common.base.Predicate;
import com.google.common.base.Splitter;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.dom4j.Document;
+import org.dom4j.DocumentException;
+import org.dom4j.DocumentFactory;
+import org.dom4j.Element;
+import org.dom4j.io.OutputFormat;
+import org.dom4j.io.SAXReader;
+import org.dom4j.io.XMLWriter;
import org.nuiton.topia.TopiaContext;
import org.nuiton.topia.TopiaContextFactory;
import org.nuiton.topia.TopiaException;
@@ -56,15 +65,16 @@
import javax.persistence.Query;
import javax.persistence.metamodel.EntityType;
import java.beans.PropertyChangeListener;
-import java.io.BufferedInputStream;
import java.io.File;
-import java.io.FileInputStream;
-import java.io.InputStream;
+import java.io.IOException;
import java.io.Reader;
import java.io.Writer;
import java.lang.reflect.Field;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Collections;
+import java.util.Date;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.HashSet;
@@ -74,22 +84,7 @@
import java.util.Properties;
import java.util.Set;
import java.util.WeakHashMap;
-import java.util.zip.GZIPInputStream;
-
-//import org.hibernate.EntityMode;
-//import org.hibernate.ReplicationMode;
-//import org.hibernate.event.PostDeleteEventListener;
-//import org.hibernate.event.PostInsertEventListener;
-//import org.hibernate.event.PostLoadEventListener;
-//import org.hibernate.event.PostUpdateEventListener;
-//import org.hibernate.event.PreDeleteEventListener;
-//import org.hibernate.event.PreInsertEventListener;
-//import org.hibernate.event.PreLoadEventListener;
-//import org.hibernate.event.PreUpdateEventListener;
-//import org.hibernate.tool.hbm2ddl.SchemaExport;
-//import org.hibernate.tool.hbm2ddl.SchemaUpdate;
-
/**
* Le TopiaContextImpl est le point d'entrée pour accéder aux données. Il est
* configuré par un fichier de propriétés.
@@ -122,6 +117,17 @@
private static final Log log = LogFactory.getLog(TopiaContextImpl.class);
/**
+ * Predicate to know if the given context is the root context
+ */
+ protected final static Predicate<TopiaContextImplementor> IS_ROOT_CONTEXT =
+ new Predicate<TopiaContextImplementor>() {
+ @Override
+ public boolean apply(TopiaContextImplementor context) {
+ return context.getParentContext() == null;
+ }
+ };
+
+ /**
* This context's parent. Root contexts does not have a parent context
*/
protected TopiaContextImplementor parentContext;
@@ -467,9 +473,6 @@
// hibernateConfiguration.addDirectory(new File(dir));
// }
// }
-
-// // tchemit 2011-05-26 When using hibernate > 3.3, need to make sure all mappings are loaded (the one from directory files are not still done).
-// hibernateConfiguration.buildMappings();
// }
// }
// return hibernateConfiguration;
@@ -477,7 +480,6 @@
/* -------------------- CHILD CONTEXT AND DAOS --------------------------*/
- @SuppressWarnings({"unchecked"})
@Override
public <E extends TopiaEntity> TopiaDAO<E> getDAO(Class<E> entityClass)
throws TopiaException {
@@ -487,12 +489,12 @@
"getDAO", "entityClass");
throw new IllegalArgumentException(message);
}
- if (equals(getRootContext())) {
+ if (IS_ROOT_CONTEXT.apply(this)) {
throw new TopiaException(
"You are on root context, you MUST open a transaction to perform any database access.");
}
Set<EntityType<?>> entities = getEntityManagerFactory().getMetamodel().getEntities();
- boolean found;
+ boolean found = false;
for (EntityType<?> entityType : entities) {
String entityName = entityType.getName();
found =
@@ -503,13 +505,17 @@
break;
}
}
-// if (!found) {
-// log.info(_("topia.persistence.supported.classes.for.context",
-// getEntityManagerFactory().getMetamodel().getEntities()));
-// throw new TopiaException(String.format(
-// "Entity type '%s' not managed by this context, you probably forgot to declare it.",
-// entityClass.getName()));
-// }
+ if (!found) {
+ if (log.isInfoEnabled()) {
+ String logMessage = String.format(
+ "List of supported persistence classes : %s", entities);
+ log.info(logMessage);
+ }
+ String exceptionMessage = String.format(
+ "Entity type '%s' not managed by this context, you probably forgot to declare it.",
+ entityClass.getName());
+ throw new TopiaException(exceptionMessage);
+ }
TopiaDAO<E> result = (TopiaDAO<E>) daoCache.get(entityClass);
if (result == null) {
@@ -521,8 +527,7 @@
try {
Class<TopiaDAO<E>> daoClass =
(Class<TopiaDAO<E>>) Class.forName(daoClassname);
- TopiaDAO<E> spe = daoClass.getConstructor().newInstance();
- result = spe;
+ result = daoClass.getConstructor().newInstance();
} catch (Exception eee) {
log.warn("specialized DAO " + daoClassname +
" not found, use default TopiaDAOHibernate");
@@ -535,7 +540,6 @@
return result;
}
- @SuppressWarnings({"unchecked"})
@Override
public <E extends TopiaEntity, D extends TopiaDAO<E>> D getDAO(
Class<E> entityClass, Class<D> daoClass) throws TopiaException {
@@ -582,7 +586,7 @@
}
throw new TopiaException(
- "An error occured while getting a new transaction : "
+ "An error occurred while getting a new transaction : "
+ eee.getMessage(), eee);
}
@@ -596,18 +600,13 @@
@Override
public void commitTransaction() throws TopiaException {
- boolean isRootContext = equals(getRootContext());
- if (isRootContext) {
+ if (IS_ROOT_CONTEXT.apply(this)) {
String message = String.format("Operation '%s' is not permitted on root context", "commitTransaction");
throw new TopiaException(message);
}
checkClosed("commitTransaction");
try {
-// for (TopiaDAO<? extends TopiaEntity> dao : daoCache.values()) {
-// // TODO-fdesbois-20100507 : need to be removed for 2.5 version
-// dao.commitTransaction();
-// }
EntityTransaction tx = entityManager.getTransaction();
entityManager.flush();
tx.commit();
@@ -618,34 +617,23 @@
parent.getFiresSupport().fireOnPostCommit(this);
}
-// hibernate.beginTransaction();
entityManager.getTransaction().begin();
- // it's seem necessary to change session after commit
- // NON, NON, NON, il ne faut surtout pas le faire, ca pose plein de
- // probleme
- // hibernate = getEntityManagerFactory().openSession();
- // hibernate.setFlushMode(FlushMode.NEVER);
} catch (Exception eee) {
-
throw new TopiaException(
- "An error occured during commit operation : " +
+ "An error occurred during commit operation : " +
eee.getMessage(), eee);
}
}
@Override
public void rollbackTransaction() throws TopiaException {
- if (equals(getRootContext())) {
+ if (IS_ROOT_CONTEXT.apply(this)) {
String message = String.format("Operation '%s' is not permitted on root context", "rollbackTransaction");
throw new TopiaException(message);
}
checkClosed("rollbackTransaction");
try {
-// for (TopiaDAO<? extends TopiaEntity> dao : daoCache.values()) {
-// // TODO-fdesbois-20100507 : need to be removed for 2.5 version
-// dao.rollbackTransaction();
-// }
EntityTransaction tx = entityManager.getTransaction();
entityManager.clear();
tx.rollback();
@@ -655,7 +643,6 @@
entityManager = getEntityManagerFactory().createEntityManager();
entityManager.setFlushMode(FlushModeType.COMMIT); // TODO AThimel 07/05/2012 Was MANUAL
-// hibernate.beginTransaction();
entityManager.getTransaction().begin();
getFiresSupport().fireOnPostRollback(this);
@@ -666,22 +653,15 @@
} catch (PersistenceException eee) {
throw new TopiaException(
- "An error occured during rollback operation : " +
+ "An error occurred during rollback operation : " +
eee.getMessage(), eee);
}
}
@Override
public void closeContext() throws TopiaException {
- // Throw exception if context is already closed
checkClosed("closeContext");
- // FD-20100421 : Ano #546 : no need to copy childContexts, the
- // {@link #getChildContext()} provides a thread-safe copy to iterate
- // on it.
-// TopiaContextImplementor[] children = childContexts.toArray(
-// new TopiaContextImplementor[childContexts.size()]);
-
// Remove all children context
for (TopiaContextImplementor child : getChildContexts()) {
// Avoid to have exception from checkClosed method on child
@@ -690,19 +670,19 @@
}
}
- // on se desenregistre du context pere et on ferme les connexions si
- // on est pas le root context
- if (!equals(getRootContext())) {
- closed = true;
- entityManager.close();
- getParentContext().removeChildContext(this);
- } else {
+ if (IS_ROOT_CONTEXT.apply(this)) {
if (entityManagerFactory != null) {
entityManagerFactory.close();
closed = true;
TopiaContextFactory.removeContext(this);
log.debug("TopiaContext removed");
}
+ } else {
+ // on se desenregistre du context pere et on ferme les connexions si
+ // on est pas le root context
+ closed = true;
+ entityManager.close();
+ getParentContext().removeChildContext(this);
}
}
@@ -711,10 +691,8 @@
*/
@Override
protected void finalize() throws Throwable {
- if (entityManagerFactory != null) {
+ if (!isClosed()) {
closeContext();
- entityManagerFactory.close();
- closed = true;
log.debug("TopiaContext finalized");
}
}
@@ -726,7 +704,9 @@
protected void checkClosed(String method) throws TopiaException {
if (closed) {
- String message = String.format("This context is closed, unable to perform operation '%s'", method);
+ String message = String.format(
+ "This context is closed, unable to perform operation '%s'",
+ method);
throw new TopiaException(message);
}
}
@@ -848,7 +828,6 @@
/* -------------------- GLOBAL OPERATIONS ON SCHEMA ----------------------*/
- @SuppressWarnings({"unchecked"})
@Override
public TopiaEntity findByTopiaId(String id) throws TopiaException {
checkClosed("findByTopiaId");
@@ -864,7 +843,6 @@
return query.execute(this);
}
- @SuppressWarnings({"unchecked"})
@Override
public TopiaQuery createQuery(Class<?> entityClass, String alias) {
return new TopiaQuery((Class<? extends TopiaEntity>)entityClass, alias);
@@ -872,34 +850,16 @@
@Override
public List<?> find(String hql, Object... args) throws TopiaException {
- checkClosed("find");
+ List<?> result = find(hql, 0, -1, args);
+ return result;
+ }
- try {
- Query query = getEntityManager().createQuery(hql);
- for (int j = 0; j < args.length; j += 2) {
- String name = (String) args[j];
- Object value = args[j + 1];
- if (value.getClass().isArray()) {
- List<Object> values = Arrays.asList((Object[]) value);
- query.setParameter(name, values);
-// query.setParameterList(name, value);
-// } else if (value instanceof Collection<?>) {
-// query.setParameterList(name, (Collection<?>) value);
- } else {
- query.setParameter(name, value);
- }
- }
- // tchemit 2010-11-30 reproduce the same behaviour than before with the dao legacy
- if (useFlushMode) {
- query.setFlushMode(FlushModeType.AUTO);
- }
- List result = query.getResultList();
- result = firesSupport.fireEntitiesLoad(this, result);
- return result;
- } catch (PersistenceException eee) {
- String message = String.format("An error occured (%s) during a query operation : %s", eee.getMessage(), hql);
- throw new TopiaException(message, eee);
+ protected Object transformArrayToCollection(Object value) {
+ Object result = value;
+ if (value.getClass().isArray()) {
+ result = Arrays.asList((Object[]) value);
}
+ return result;
}
@Override
@@ -911,15 +871,13 @@
Query query = getEntityManager().createQuery(hql);
for (int j = 0; j < args.length; j += 2) {
String name = (String) args[j];
- Object value = args[j + 1];
-// if (value.getClass().isArray()) {
-// query.setParameterList(name, (Object[]) value);
-// } else {
- query.setParameter(name, value);
-// }
+ Object value = transformArrayToCollection(args[j + 1]);
+ query.setParameter(name, value);
}
query.setFirstResult(startIndex);
- query.setMaxResults(endIndex - startIndex + 1);
+ if (endIndex >= 0) {
+ query.setMaxResults(endIndex - startIndex + 1);
+ }
// tchemit 2010-11-30 reproduce the same behaviour than before with the dao legacy
if (useFlushMode) {
query.setFlushMode(FlushModeType.AUTO);
@@ -928,7 +886,9 @@
result = firesSupport.fireEntitiesLoad(this, result);
return result;
} catch (PersistenceException eee) {
- String message = String.format("An error occured (%s) during a query operation : %s", eee.getMessage(), hql);
+ String message = String.format(
+ "An error occurred (%s) during a query operation : %s",
+ eee.getMessage(), hql);
throw new TopiaException(message, eee);
}
}
@@ -948,12 +908,16 @@
try {
Query query = getEntityManager().createQuery(hql);
for (int j = 0; j < args.length; j += 2) {
- query.setParameter((String) args[j], args[j + 1]);
+ String name = (String) args[j];
+ Object value = transformArrayToCollection(args[j + 1]);
+ query.setParameter(name, value);
}
int result = query.executeUpdate();
return result;
} catch (PersistenceException eee) {
- String message = String.format("An error occured (%s) during a query operation : %s", eee.getMessage(), hql);
+ String message = String.format(
+ "An error occurred (%s) during a query operation : %s",
+ eee.getMessage(), hql);
throw new TopiaException(message, eee);
}
}
@@ -978,6 +942,7 @@
}
}
+ // TODO AThimel 23/05/2012 Work not supported anymore ?
// public static class SQLWork implements Work {
// private final String script;
//
@@ -1012,15 +977,13 @@
@Override
public void createSchema() throws TopiaException {
try {
- boolean showSchema = false;
- if (log.isDebugEnabled()) {
- showSchema = true;
- }
+ boolean showSchema = log.isDebugEnabled();
getFiresSupport().firePreCreateSchema(this);
getSpecificUtil().createSchema(showSchema);
getFiresSupport().firePostCreateSchema(this);
} catch (PersistenceException eee) {
- throw new TopiaException("Schema could not be created for the following reason : "
+ throw new TopiaException(
+ "Schema could not be created for the following reason : "
+ eee.getMessage(), eee);
}
}
@@ -1030,7 +993,8 @@
try {
getSpecificUtil().showCreateSchema();
} catch (PersistenceException eee) {
- throw new TopiaException("Schema creation could not be displayed for the following reason : "
+ throw new TopiaException(
+ "Schema creation could not be displayed for the following reason : "
+ eee.getMessage(), eee);
}
}
@@ -1038,15 +1002,13 @@
@Override
public void updateSchema() throws TopiaException {
try {
- boolean showSchema = false;
- if (log.isDebugEnabled()) {
- showSchema = true;
- }
+ boolean showSchema = log.isDebugEnabled();
getFiresSupport().firePreUpdateSchema(this);
getSpecificUtil().updateSchema(showSchema);
getFiresSupport().firePostUpdateSchema(this);
} catch (PersistenceException eee) {
- throw new TopiaException("Schema could not be updated for the following reason : "
+ throw new TopiaException(
+ "Schema could not be updated for the following reason : "
+ eee.getMessage(), eee);
}
}
@@ -1055,12 +1017,16 @@
/* -------------------- SERVICES MANAGMENT -------------------------------*/
protected String getProperExceptionMessage(Throwable eee) {
- return eee.getClass().getSimpleName() + " : " +
- eee.getMessage();
+ String exceptionName = eee.getClass().getSimpleName();
+ String exceptionMessage = eee.getMessage();
+ String result = exceptionName + " : " + exceptionMessage;
+ return result;
}
protected Map<String, TopiaService> loadServices(Properties config) {
+
Map<String, TopiaService> result = new HashMap<String, TopiaService>();
+
// recherche des services present dans la config
for (Enumeration<?> e = config.propertyNames(); e.hasMoreElements();) {
String key = (String) e.nextElement();
@@ -1121,16 +1087,11 @@
return result;
}
- protected boolean serviceEnabled(String name) {
- boolean result = getServices().containsKey(name);
- return result;
- }
-
/**
* Retrieve service name using SERVICE_NAME static field on service
* interface.
*
- * @param interfaceService class of the service
+ * @param serviceInterface class of the service
* @param <E> type of the service that extends {@link
* TopiaService}
* @return the service name
@@ -1138,9 +1099,9 @@
* @throws NoSuchFieldException if no field SERVICE_NAME is defined
*/
protected <E extends TopiaService> String getServiceName(
- Class<E> interfaceService)
+ Class<E> serviceInterface)
throws IllegalAccessException, NoSuchFieldException {
- Field f = interfaceService.getField("SERVICE_NAME");
+ Field f = serviceInterface.getField("SERVICE_NAME");
String name = (String) f.get(null);
return name;
}
@@ -1159,19 +1120,21 @@
}
@Override
- public <E extends TopiaService> E getService(Class<E> interfaceService)
+ public <E extends TopiaService> E getService(Class<E> serviceInterface)
throws TopiaNotFoundException {
E result;
try {
- String name = getServiceName(interfaceService);
+ String name = getServiceName(serviceInterface);
result = (E) getService(name);
} catch (Exception eee) {
- String message = String.format("Could not retrieve service '%s' for following reason : %s", interfaceService, getProperExceptionMessage(eee));
+ String message = String.format(
+ "Could not retrieve service '%s' for following reason : %s",
+ serviceInterface, getProperExceptionMessage(eee));
throw new TopiaNotFoundException(message, eee);
}
if (result == null) {
throw new TopiaNotFoundException(
- String.format("The service '%s' not found.", interfaceService));
+ String.format("Service '%s' not found.", serviceInterface));
}
return result;
}
@@ -1182,7 +1145,7 @@
boolean result = false;
try {
String name = getServiceName(interfaceService);
- result = serviceEnabled(name);
+ result = isServiceEnabled(name);
} catch (Exception eee) {
String message = String.format(
"The service named '%s' could not be found for following reason : %s",
@@ -1196,116 +1159,78 @@
return result;
}
+ protected boolean isServiceEnabled(String name) {
+ boolean result = getServices().containsKey(name);
+ return result;
+ }
+
/* ------------------ IMPORT / EXPORT / REPLICATION ---------------------*/
@Override
public void importXML(Reader xml) throws TopiaException {
-// checkClosed(String.format("This context is closed, it is not possible to perform the operation '%s'",
-// "importXML"));
-//
-// Document doc;
-//
-// SAXReader xmlReader = new SAXReader();
-// try {
-// doc = xmlReader.read(xml);
-// if (log.isDebugEnabled()) {
-// log.debug("Lecture du document terminee");
-// }
-// } catch (DocumentException de) {
-// throw new TopiaException(
-// "Could not read XML document for following reason : %s" +
-// de.getMessage(), de);
-// }
-//
-// if (doc != null) {
-// Session sessionDom4j = getEntityManager().getSession(EntityMode.DOM4J);
-// Element rootElement = doc.getRootElement();
-// Iterator<?> it = rootElement.elementIterator();
-// while (it.hasNext()) {
-// Element entity = (Element) it.next();
-// try {
-// sessionDom4j.replicate(entity, ReplicationMode.EXCEPTION);
-// } catch (PersistenceException he) {
-// log.warn(String.format(
-// "Could not replicate entity '%s' pour following reason : %s",
-// entity, he.getMessage()), he);
-// }
-// }
-// // must commit data, otherwise : no effects...
-// sessionDom4j.flush();
-// } else {
-// throw new TopiaException("Empty document");
-// }
+ checkClosed("importXML");
+
+ Document doc;
+
+ SAXReader xmlReader = new SAXReader();
+ try {
+ doc = xmlReader.read(xml);
+ if (log.isDebugEnabled()) {
+ log.debug("Lecture du document terminee");
+ }
+ } catch (DocumentException de) {
+ throw new TopiaException(
+ "Could not read XML document for following reason : %s" +
+ de.getMessage(), de);
+ }
+
+ if (doc != null) {
+ Element rootElement = doc.getRootElement();
+ List<Element> elements = Lists.newArrayList(rootElement.elementIterator());
+
+ getSpecificUtil().importXML(this, elements);
+ } else {
+ throw new TopiaException("Empty document");
+ }
}
@Override
- public void exportXML(Writer xml, Object... entityAndcondition)
+ public void exportXML(Writer xml, Object... entityAndCondition)
throws TopiaException {
-// checkClosed(String.format("This context is closed, it is not possible to perform the operation '%s'",
-// "exportXML"));
-//
-// String[] queries = buildQueries(entityAndcondition);
-//
-// // performs queries
-// try {
-// Session sessionDom4j = getEntityManager().getSession(EntityMode.DOM4J);
-//
-// Document doc = DocumentFactory.getInstance().createDocument();
-// Element rootElement = doc.addElement("topiaExport");
-// DateFormat format = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
-// String date = format.format(new Date(System.currentTimeMillis()));
-// rootElement.addAttribute("date", date);
-//
-// for (String query : queries) {
-// List<?> list = sessionDom4j.createQuery(query).list();
-// for (Object o : list) {
-// rootElement.add((Element) o);
-// }
-// }
-//
-// /*for (int i = 0; i < entityAndcondition.length;) {
-// try {
-// entityClass = (Class) entityAndcondition[i++];
-// condition = (String) entityAndcondition[i++];
-//
-// String query = "from " + entityClass.getName();
-// if (condition != null && !condition.isEmpty()) {
-// query += " where " + condition;
-// }
-//
-// for (Object o : sessionDom4j.createQuery(query).list()) {
-// rootElement.add((Element) o);
-// }
-// } catch (ClassCastException eee) {
-// if (i % 2 == 0) {
-// throw new IllegalArgumentException(
-// "Others arguement must be String not "
-// + entityAndcondition[i - 1], eee);
-// } else {
-// throw new IllegalArgumentException(
-// "Others arguement must be Class not "
-// + entityAndcondition[i - 1], eee);
-// }
-// } catch (IndexOutOfBoundsException eee) {
-// throw new IllegalArgumentException(
-// "Others arguement must be couple of (Class, String)",
-// eee);
-// }
-// }*/
-//
-// XMLWriter result = new XMLWriter(xml,
-// OutputFormat.createPrettyPrint());
-// result.write(doc);
-// result.close();
-//
-// } catch (PersistenceException eee) {
-// throw new TopiaException("An error occurred during export operation : %s" +
-// eee.getMessage(), eee);
-// } catch (IOException eee) {
-// throw new TopiaException("An error occurred during export operation : %s" +
-// eee.getMessage(), eee);
-// }
+ checkClosed("exportXML");
+
+ List<String> queries = buildQueries(entityAndCondition);
+
+ // performs queries
+ try {
+
+ Document doc = DocumentFactory.getInstance().createDocument();
+ Element rootElement = doc.addElement("topiaExport");
+ DateFormat format = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
+ String date = format.format(new Date(System.currentTimeMillis()));
+ rootElement.addAttribute("date", date);
+
+ List<Element> elements = getSpecificUtil().exportXML(this, queries);
+
+ for (Element element : elements) {
+ rootElement.add(element);
+ }
+
+ OutputFormat prettyPrint = OutputFormat.createPrettyPrint();
+ XMLWriter result = new XMLWriter(xml, prettyPrint);
+ result.write(doc);
+ result.close();
+
+ } catch (PersistenceException eee) {
+ throw new TopiaException(
+ "An error occurred during export operation : %s" +
+ eee.getMessage(), eee);
+ } catch (IOException eee) {
+ throw new TopiaException(
+ "An error occurred during export operation : %s" +
+ eee.getMessage(), eee);
+ }
}
@Override
@@ -1320,7 +1245,7 @@
throw new IllegalArgumentException("Can not perform a replication operation on same database.");
}
- String[] queries = buildQueries(entityAndCondition);
+ List<String> queries = buildQueries(entityAndCondition);
try {
for (String query : queries) {
if (log.isDebugEnabled()) {
@@ -1346,7 +1271,6 @@
throws TopiaException, IllegalArgumentException {
checkClosed("replicateEntity");
-
TopiaContextImpl destinationContextImpl = (TopiaContextImpl) destinationContext;
destinationContextImpl.checkClosed("replicateEntity");
@@ -1372,108 +1296,6 @@
}
/**
- * 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(File,boolean)
- */
- @Override
- public void backup(File file, boolean compress) throws TopiaException {
- checkClosed("backup");
- try {
- String options = "";
- if (compress) {
- options += " COMPRESSION GZIP";
- }
-
- Query query = getEntityManager().createNativeQuery(
- "SCRIPT TO '" + file.getAbsolutePath() + "'" + options);
- query.getResultList();
-
- } catch (Exception eee) {
- throw new TopiaException(
- "Unable to backup to file : " + eee.getMessage(), eee);
- }
- }
-
- /**
- * Read database from gzip compressed file
- * <p/>
- * Only work for h2 database
- *
- * @see TopiaContext#restore(File)
- */
- @Override
- public void restore(File file) throws TopiaException {
- // send event
- getFiresSupport().firePreRestoreSchema(this);
- checkClosed("restore");
-
- String sql = null;
- String options = "";
- try {
- // decompresse file in temporary file
- InputStream in = new BufferedInputStream(new FileInputStream(file));
- try {
- in.mark(2);
-
- // read header to see if is compressed file
- int b = in.read();
- // redundant cast : int magic = ((int) in.read() << 8) | b;
- int magic = in.read() << 8 | b;
- in.reset();
-
- if (magic == GZIPInputStream.GZIP_MAGIC) {
- options += " COMPRESSION GZIP";
- }
- } finally {
-
- in.close();
- }
-
- Query query = getEntityManager().createNativeQuery(
- "RUNSCRIPT FROM '" + file.getAbsolutePath() + "'" + options);
-
- query.executeUpdate();
-
- // send event AFTER restore
- getFiresSupport().firePostRestoreSchema(this);
- } catch (Exception eee) {
- throw new TopiaException(
- "Unable to restore from file : " + eee.getMessage() + ". " +
- "SQL is " + sql, eee);
- }
- }
-
- /**
- * Only h2 supported for now
- *
- * @see TopiaContext#clear(boolean)
- */
- @Override
- public void clear(boolean dropDatabase) throws TopiaException {
- try {
- TopiaContextImpl root = (TopiaContextImpl) getRootContext();
- TopiaContextImpl tx = (TopiaContextImpl) root.beginTransaction();
-
- String sql = "DROP ALL OBJECTS";
- if (dropDatabase) {
- sql += " DELETE FILES";
- }
- Query query = tx.getEntityManager().createNativeQuery(sql);
- query.executeUpdate();
- tx.closeContext();
- root.finalize();
- } catch (Throwable eee) {
- throw new TopiaException(
- "Unable to perform clear operation : " + eee.getMessage(), eee);
- }
- }
-
- /**
* Build the list of queries from the given parameter
* <code>entityAndCondition</code>.
* <p/>
@@ -1487,7 +1309,7 @@
* @throws IllegalArgumentException if any pb with the given parameter
* (mainly ClassCastException).
*/
- protected String[] buildQueries(Object... entityAndCondition)
+ protected List<String> buildQueries(Object... entityAndCondition)
throws TopiaException, IllegalArgumentException {
Class<?> entityClass;
String condition;
@@ -1495,7 +1317,6 @@
// si entityAndcondition est vide alors il faut le remplir
// avec toutes les entités du mapping (class, null)
if (entityAndCondition.length == 0) {
-// Map<?,?> classMetadata = getEntityManagerFactory().getAllClassMetadata();
Set<EntityType<?>> classMetadata = getEntityManagerFactory().getMetamodel().getEntities();
entityAndCondition = new Object[classMetadata.size() * 2];
int i = 0;
@@ -1518,7 +1339,7 @@
throw new IllegalArgumentException(
"entityAndCondition must be a couple of (Class, String)");
}
- String queries[] = new String[entityAndCondition.length / 2];
+ List<String> queries = Lists.newArrayList();
for (int i = 0; i < entityAndCondition.length;) {
try {
entityClass = (Class<?>) entityAndCondition[i++];
@@ -1527,15 +1348,15 @@
if (condition != null && !condition.isEmpty()) {
query += " where " + condition;
}
- queries[(i - 1) / 2] = query;
+ queries.add(query);
} catch (ClassCastException e) {
if (i % 2 == 0) {
throw new IllegalArgumentException(
- "Others arguement must be String not " +
+ "Others argument must be String not " +
entityAndCondition[i - 1], e);
} else {
throw new IllegalArgumentException(
- "Others arguement must be Class not " +
+ "Others argument must be Class not " +
entityAndCondition[i - 1], e);
}
}
@@ -1543,7 +1364,6 @@
return queries;
}
-
protected void replicateOnDestinationContext(
TopiaContextImplementor destinationContext,
Object... entities) throws TopiaException {
@@ -1567,5 +1387,19 @@
getSpecificUtil().receiveReplicatedEntity(this, entity);
}
-} //TopiaContextImpl
+ @Override
+ public void backup(File file, boolean compress) throws TopiaException {
+ new TopiaH2Util(this).backup(file, compress);
+ }
+ @Override
+ public void restore(File file) throws TopiaException {
+ new TopiaH2Util(this).restore(file);
+ }
+
+ @Override
+ public void clear(boolean dropDatabase) throws TopiaException {
+ new TopiaH2Util(this).clear(dropDatabase);
+ }
+
+} //TopiaContextImpl
Added: trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaH2Util.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaH2Util.java (rev 0)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaH2Util.java 2012-05-23 13:00:47 UTC (rev 2498)
@@ -0,0 +1,122 @@
+package org.nuiton.topia.framework;
+
+import org.nuiton.topia.TopiaException;
+
+import javax.persistence.Query;
+import java.io.BufferedInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStream;
+import java.util.zip.GZIPInputStream;
+
+/**
+ * @author Arnaud Thimel <thimel(a)codelutin.com>
+ */
+public class TopiaH2Util {
+
+ protected TopiaContextImpl context;
+
+ public TopiaH2Util(TopiaContextImpl context) {
+ this.context = context;
+ }
+
+ /**
+ * 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 org.nuiton.topia.TopiaContext#backup(java.io.File,boolean)
+ */
+ public void backup(File file, boolean compress) throws TopiaException {
+ context.checkClosed("backup");
+ try {
+ String options = "";
+ if (compress) {
+ options += " COMPRESSION GZIP";
+ }
+
+ Query query = context.getEntityManager().createNativeQuery(
+ "SCRIPT TO '" + file.getAbsolutePath() + "'" + options);
+ query.getResultList();
+
+ } catch (Exception eee) {
+ throw new TopiaException(
+ "Unable to backup to file : " + eee.getMessage(), eee);
+ }
+ }
+
+ /**
+ * Read database from gzip compressed file
+ * <p/>
+ * Only work for h2 database
+ *
+ * @see org.nuiton.topia.TopiaContext#restore(File)
+ */
+ public void restore(File file) throws TopiaException {
+ // send event
+ context.getFiresSupport().firePreRestoreSchema(context);
+ context.checkClosed("restore");
+
+ String sql = null;
+ String options = "";
+ try {
+ // decompresse file in temporary file
+ InputStream in = new BufferedInputStream(new FileInputStream(file));
+ try {
+ in.mark(2);
+
+ // read header to see if is compressed file
+ int b = in.read();
+ // redundant cast : int magic = ((int) in.read() << 8) | b;
+ int magic = in.read() << 8 | b;
+ in.reset();
+
+ if (magic == GZIPInputStream.GZIP_MAGIC) {
+ options += " COMPRESSION GZIP";
+ }
+ } finally {
+
+ in.close();
+ }
+
+ Query query = context.getEntityManager().createNativeQuery(
+ "RUNSCRIPT FROM '" + file.getAbsolutePath() + "'" + options);
+
+ query.executeUpdate();
+
+ // send event AFTER restore
+ context.getFiresSupport().firePostRestoreSchema(context);
+ } catch (Exception eee) {
+ throw new TopiaException(
+ "Unable to restore from file : " + eee.getMessage() + ". " +
+ "SQL is " + sql, eee);
+ }
+ }
+
+ /**
+ * Only h2 supported for now
+ *
+ * @see org.nuiton.topia.TopiaContext#clear(boolean)
+ */
+ public void clear(boolean dropDatabase) throws TopiaException {
+ try {
+ TopiaContextImpl root = (TopiaContextImpl) context.getRootContext();
+ TopiaContextImpl tx = (TopiaContextImpl) root.beginTransaction();
+
+ String sql = "DROP ALL OBJECTS";
+ if (dropDatabase) {
+ sql += " DELETE FILES";
+ }
+ Query query = tx.getEntityManager().createNativeQuery(sql);
+ query.executeUpdate();
+ tx.closeContext();
+ root.finalize();
+ } catch (Throwable eee) {
+ throw new TopiaException(
+ "Unable to perform clear operation : " + eee.getMessage(), eee);
+ }
+ }
+
+}
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaSpecificUtil.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaSpecificUtil.java 2012-05-23 09:18:09 UTC (rev 2497)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaSpecificUtil.java 2012-05-23 13:00:47 UTC (rev 2498)
@@ -1,9 +1,12 @@
package org.nuiton.topia.framework;
+import org.dom4j.Element;
import org.nuiton.topia.TopiaContext;
import org.nuiton.topia.persistence.TopiaEntity;
+import java.util.List;
+
/**
* Provides all non-JPA standard methods (specific to an implementation) needed
* by ToPIA
@@ -59,4 +62,27 @@
*/
void receiveReplicatedEntity(TopiaContextImplementor context, Object entity);
+ /**
+ * Export the given queries result to XML
+ *
+ * @param context the context on which entities are exported
+ * @param queries the list of queries that will be fetched for export
+ * @return a list of XML elements
+ * @deprecated nobody uses it and probably not supported by the
+ * implementation, will be removed in future version
+ */
+ @Deprecated
+ List<Element> exportXML(TopiaContextImplementor context, List<String> queries);
+
+ /**
+ * Imports from a list of XML elements
+ *
+ * @param context the context on which entities are exported
+ * @param elements the list of elements to import
+ * @deprecated nobody uses it and probably not supported by the
+ * implementation, will be removed in future version
+ */
+ @Deprecated
+ void importXML(TopiaContextImplementor context, List<Element> elements);
+
}
Modified: trunk/topia-persistence/src/main/resources/i18n/topia-persistence_en_GB.properties
===================================================================
--- trunk/topia-persistence/src/main/resources/i18n/topia-persistence_en_GB.properties 2012-05-23 09:18:09 UTC (rev 2497)
+++ trunk/topia-persistence/src/main/resources/i18n/topia-persistence_en_GB.properties 2012-05-23 13:00:47 UTC (rev 2498)
@@ -1 +0,0 @@
-topia.persistence.supported.classes.for.context=List of supported persistence classes \: %1$s
Modified: trunk/topia-persistence/src/main/resources/i18n/topia-persistence_es_ES.properties
===================================================================
--- trunk/topia-persistence/src/main/resources/i18n/topia-persistence_es_ES.properties 2012-05-23 09:18:09 UTC (rev 2497)
+++ trunk/topia-persistence/src/main/resources/i18n/topia-persistence_es_ES.properties 2012-05-23 13:00:47 UTC (rev 2498)
@@ -1 +0,0 @@
-topia.persistence.supported.classes.for.context=List of supported persistence classes \: %1$s
Modified: trunk/topia-persistence/src/main/resources/i18n/topia-persistence_fr_FR.properties
===================================================================
--- trunk/topia-persistence/src/main/resources/i18n/topia-persistence_fr_FR.properties 2012-05-23 09:18:09 UTC (rev 2497)
+++ trunk/topia-persistence/src/main/resources/i18n/topia-persistence_fr_FR.properties 2012-05-23 13:00:47 UTC (rev 2498)
@@ -1 +0,0 @@
-topia.persistence.supported.classes.for.context=Classes supportées par ce TopiaContext \: %1$s
Modified: trunk/topia-persistence-hibernate/src/main/java/org/nuiton/topia/persistence/TopiaHibernateSpecificUtil.java
===================================================================
--- trunk/topia-persistence-hibernate/src/main/java/org/nuiton/topia/persistence/TopiaHibernateSpecificUtil.java 2012-05-23 09:18:09 UTC (rev 2497)
+++ trunk/topia-persistence-hibernate/src/main/java/org/nuiton/topia/persistence/TopiaHibernateSpecificUtil.java 2012-05-23 13:00:47 UTC (rev 2498)
@@ -2,6 +2,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.dom4j.Element;
import org.hibernate.ReplicationMode;
import org.hibernate.Session;
import org.hibernate.cfg.AvailableSettings;
@@ -24,6 +25,7 @@
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Iterator;
+import java.util.List;
/**
* Hibernate implementation of the {@link TopiaSpecificUtil}.
@@ -137,4 +139,57 @@
throw new TopiaRuntimeException("Unable to receive replicated entity", te);
}
}
+
+ @Override
+ public List<Element> exportXML(TopiaContextImplementor context,
+ List<String> queries) {
+
+ throw new UnsupportedOperationException("Not supported anymore in Hibernate : https://hibernate.onjira.com/browse/HHH-6330");
+// try {
+// List<Element> elements = Lists.newArrayList();
+//
+// EntityManager entityManager = context.getEntityManager();
+// if (entityManager instanceof EntityManagerImpl) {
+// Session sessionDom4j = ((EntityManagerImpl) entityManager).getSession(EntityMode.DOM4J);
+// for (String query : queries) {
+//
+// List<?> list = sessionDom4j.createQuery(query).list();
+// for (Object o : list) {
+// elements.add((Element) o);
+// }
+//
+// }
+// }
+//
+// return elements;
+// } catch (TopiaException te) {
+// throw new TopiaRuntimeException("Unable to export elements to XML", te);
+// }
+ }
+
+ @Override
+ public void importXML(TopiaContextImplementor context, List<Element> elements) {
+
+ throw new UnsupportedOperationException("Not supported anymore in Hibernate : https://hibernate.onjira.com/browse/HHH-6330");
+// try {
+//
+// EntityManager entityManager = context.getEntityManager();
+// if (entityManager instanceof EntityManagerImpl) {
+// Session sessionDom4j = ((EntityManagerImpl) entityManager).getSession(EntityMode.DOM4J);
+// for (Element entity : elements) {
+// try {
+// sessionDom4j.replicate(entity, ReplicationMode.EXCEPTION);
+// } catch (PersistenceException he) {
+// log.warn(String.format(
+// "Could not replicate entity '%s' pour following reason : %s",
+// entity, he.getMessage()), he);
+// }
+// }
+// // must commit data, otherwise : no effects...
+// sessionDom4j.flush();
+// }
+// } catch (TopiaException te) {
+// throw new TopiaRuntimeException("Unable to export elements to XML", te);
+// }
+ }
}
Modified: trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/framework/TopiaContextImplTest.java
===================================================================
--- trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/framework/TopiaContextImplTest.java 2012-05-23 09:18:09 UTC (rev 2497)
+++ trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/framework/TopiaContextImplTest.java 2012-05-23 13:00:47 UTC (rev 2498)
@@ -151,7 +151,7 @@
if (log.isInfoEnabled()) {
log.info("test 2 : test serviceEnabled method");
}
- boolean test2 = child.serviceEnabled("test");
+ boolean test2 = child.isServiceEnabled("test");
Assert.assertTrue(test2);
if (log.isInfoEnabled()) {
@@ -176,8 +176,8 @@
log.info("test 6 : test serviceEnabled error with class FakeService");
}
// FakeService doesn't contains property SERVICE_NAME used by
- // serviceEnabled method
- // Even it's properly loaded the serviceEnabled method will return false
+ // isServiceEnabled method
+ // Even it's properly loaded the isServiceEnabled method will return false
properties.clear();
properties.setProperty("topia.service.fake",
FakeService.class.getName());
1
0
Author: tchemit
Date: 2012-05-23 11:18:09 +0200 (Wed, 23 May 2012)
New Revision: 2497
Url: http://nuiton.org/repositories/revision/topia/2497
Log:
updates some dependencies + use mavenpom on SNAPSHOT
Modified:
trunk/pom.xml
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2012-05-23 08:24:34 UTC (rev 2496)
+++ trunk/pom.xml 2012-05-23 09:18:09 UTC (rev 2497)
@@ -32,7 +32,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>mavenpom4redmineAndCentral</artifactId>
- <version>3.3.1</version>
+ <version>3.3.2-SNAPSHOT</version>
</parent>
<artifactId>topia</artifactId>
@@ -69,14 +69,14 @@
<!-- libs version -->
<eugeneVersion>2.4.2</eugeneVersion>
- <nuitonUtilsVersion>2.4.6</nuitonUtilsVersion>
- <processorPluginVersion>1.2.1</processorPluginVersion>
+ <nuitonUtilsVersion>2.4.8</nuitonUtilsVersion>
+ <processorPluginVersion>1.2.2</processorPluginVersion>
<nuitonI18nVersion>2.4.1</nuitonI18nVersion>
<xmlrpcVersion>3.1.2</xmlrpcVersion>
<!--<hibernateVersion>3.6.10.Final</hibernateVersion>-->
<hibernateVersion>4.1.3.Final</hibernateVersion>
<sl4jVersion>1.6.4</sl4jVersion>
- <h2Version>1.3.165</h2Version>
+ <h2Version>1.3.166</h2Version>
<geronimoJpaSpecVersion>1.1</geronimoJpaSpecVersion>
<!-- i18n configuration -->
1
0
r2496 - in trunk: topia-persistence/src/main/java/org/nuiton/topia/framework topia-persistence-tck/src/main/java/org/nuiton/topia/tck topia-persistence-tck/src/main/java/org/nuiton/topia/tck/it/events topia-persistence-tck/src/main/java/org/nuiton/topia/tck/legacy/ano1991
by athimel@users.nuiton.org 23 May '12
by athimel@users.nuiton.org 23 May '12
23 May '12
Author: athimel
Date: 2012-05-23 10:24:34 +0200 (Wed, 23 May 2012)
New Revision: 2496
Url: http://nuiton.org/repositories/revision/topia/2496
Log:
Fix TopiaQuery array's setParameter
Added:
trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/legacy/ano1991/TopiaQueryAnno1991Test.java
Removed:
trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/legacy/ano1991/TopiaQueryTest.java
Modified:
trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/TopiaTckItTestSuite.java
trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/TopiaTckLegacyTestSuite.java
trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/it/events/VetoableEventTest.java
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 2012-05-22 16:19:02 UTC (rev 2495)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaContextImpl.java 2012-05-23 08:24:34 UTC (rev 2496)
@@ -879,13 +879,15 @@
for (int j = 0; j < args.length; j += 2) {
String name = (String) args[j];
Object value = args[j + 1];
-// if (value.getClass().isArray()) {
-// query.setParameterList(name, (Object[]) value);
+ if (value.getClass().isArray()) {
+ List<Object> values = Arrays.asList((Object[]) value);
+ query.setParameter(name, values);
+// query.setParameterList(name, value);
// } else if (value instanceof Collection<?>) {
// query.setParameterList(name, (Collection<?>) value);
-// } else {
+ } else {
query.setParameter(name, value);
-// }
+ }
}
// tchemit 2010-11-30 reproduce the same behaviour than before with the dao legacy
if (useFlushMode) {
Modified: trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/TopiaTckItTestSuite.java
===================================================================
--- trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/TopiaTckItTestSuite.java 2012-05-22 16:19:02 UTC (rev 2495)
+++ trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/TopiaTckItTestSuite.java 2012-05-23 08:24:34 UTC (rev 2496)
@@ -3,17 +3,16 @@
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.nuiton.topia.TopiaContextFactoryTest;
+import org.nuiton.topia.tck.it.EnumTest;
+import org.nuiton.topia.tck.it.deletetest.DeleteEntityTest;
import org.nuiton.topia.tck.it.events.VetoableEventTest;
+import org.nuiton.topia.tck.it.generator.CompositeAssociationTest;
+import org.nuiton.topia.tck.it.persistence.EntityVisitorExportXmlTest;
+import org.nuiton.topia.tck.it.persistence.NaturalIdTest;
import org.nuiton.topia.tck.legacy.ano1882.DAOAbstractTransformerTest;
-import org.nuiton.topia.tck.legacy.ano1991.TopiaQueryTest;
import org.nuiton.topia.tck.legacy.evo1912.EntityDTOTransformerTest;
import org.nuiton.topia.tck.legacy.framework.TopiaContextReplicateTest;
import org.nuiton.topia.tck.legacy.framework.TopiaUtilTest;
-import org.nuiton.topia.tck.it.generator.CompositeAssociationTest;
-import org.nuiton.topia.tck.it.EnumTest;
-import org.nuiton.topia.tck.it.deletetest.DeleteEntityTest;
-import org.nuiton.topia.tck.it.persistence.EntityVisitorExportXmlTest;
-import org.nuiton.topia.tck.it.persistence.NaturalIdTest;
/**
* @author Arnaud Thimel <thimel(a)codelutin.com>
@@ -21,7 +20,6 @@
@RunWith(Suite.class)
@Suite.SuiteClasses({
DAOAbstractTransformerTest.class,
- TopiaQueryTest.class,
EntityDTOTransformerTest.class,
TopiaContextReplicateTest.class,
TopiaUtilTest.class,
Modified: trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/TopiaTckLegacyTestSuite.java
===================================================================
--- trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/TopiaTckLegacyTestSuite.java 2012-05-22 16:19:02 UTC (rev 2495)
+++ trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/TopiaTckLegacyTestSuite.java 2012-05-23 08:24:34 UTC (rev 2496)
@@ -2,14 +2,11 @@
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
-import org.nuiton.topia.tck.it.generator.CompositeAssociationTest;
import org.nuiton.topia.tck.legacy.ano1882.DAOAbstractTransformerTest;
-import org.nuiton.topia.tck.legacy.ano1991.TopiaQueryTest;
+import org.nuiton.topia.tck.legacy.ano1991.TopiaQueryAnno1991Test;
import org.nuiton.topia.tck.legacy.evo1912.EntityDTOTransformerTest;
import org.nuiton.topia.tck.legacy.framework.TopiaContextReplicateTest;
import org.nuiton.topia.tck.legacy.framework.TopiaUtilTest;
-import org.nuiton.topia.tck.it.persistence.EntityVisitorExportXmlTest;
-import org.nuiton.topia.tck.it.persistence.NaturalIdTest;
/**
* Test suite for {@code mapping} model.
@@ -22,7 +19,7 @@
@RunWith(Suite.class)
@Suite.SuiteClasses(
{DAOAbstractTransformerTest.class,
- TopiaQueryTest.class,
+ TopiaQueryAnno1991Test.class,
EntityDTOTransformerTest.class,
TopiaContextReplicateTest.class,
TopiaUtilTest.class
Modified: trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/it/events/VetoableEventTest.java
===================================================================
--- trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/it/events/VetoableEventTest.java 2012-05-22 16:19:02 UTC (rev 2495)
+++ trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/it/events/VetoableEventTest.java 2012-05-23 08:24:34 UTC (rev 2496)
@@ -18,8 +18,6 @@
import org.nuiton.topia.tck.it.TopiaDatabaseIt;
import org.nuiton.topia.tck.it.TopiaTckItDAOHelper;
-import static org.junit.Assert.assertNotNull;
-
/**
* @author Arnaud Thimel <thimel(a)codelutin.com>
*/
Copied: trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/legacy/ano1991/TopiaQueryAnno1991Test.java (from rev 2492, trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/legacy/ano1991/TopiaQueryTest.java)
===================================================================
--- trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/legacy/ano1991/TopiaQueryAnno1991Test.java (rev 0)
+++ trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/legacy/ano1991/TopiaQueryAnno1991Test.java 2012-05-23 08:24:34 UTC (rev 2496)
@@ -0,0 +1,131 @@
+/*
+ * #%L
+ * ToPIA :: Persistence
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2004 - 2012 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.tck.legacy.ano1991;
+
+import org.junit.Assert;
+import org.junit.Rule;
+import org.junit.Test;
+import org.nuiton.topia.TopiaContext;
+import org.nuiton.topia.TopiaException;
+import org.nuiton.topia.framework.TopiaQuery;
+import org.nuiton.topia.tck.TopiaDatabase;
+import org.nuiton.topia.tck.legacy.TopiaDatabaseLegacy;
+import org.nuiton.topia.tck.legacy.TopiaTckLegacyDAOHelper;
+import org.nuiton.topia.tck.legacy.entities.Person;
+import org.nuiton.topia.tck.legacy.entities.PersonDAO;
+import org.nuiton.topia.tck.legacy.entities.Pet;
+import org.nuiton.topia.tck.legacy.entities.PetDAO;
+
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ * Prevent regression of http://nuiton.org/issues/1991.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.6.8
+ */
+public class TopiaQueryAnno1991Test {
+
+ @Rule
+ public final TopiaDatabase db = new TopiaDatabaseLegacy();
+
+ @Test
+ public void testInOperatorForIds() throws TopiaException {
+
+ TopiaContext context = db.beginTransaction();
+
+ PersonDAO personDAO = TopiaTckLegacyDAOHelper.getPersonDAO(context);
+
+ // appel 1 find all
+ Person toto = personDAO.create(Person.PROPERTY_NAME, "toto");
+ Person titi = personDAO.create(Person.PROPERTY_NAME, "titi");
+
+ TopiaQuery query;
+
+ query = personDAO.createQuery().addWhere(
+ Person.PROPERTY_NAME, TopiaQuery.Op.IN, new String[]{"toto"}
+ );
+
+ List<Person> result;
+ result = personDAO.findAllByQuery(query);
+ Assert.assertNotNull(result);
+ Assert.assertEquals(1, result.size());
+ Assert.assertEquals(toto, result.get(0));
+
+ query = personDAO.createQuery().addWhere(
+ Person.PROPERTY_NAME, TopiaQuery.Op.NOT_IN, new String[]{"toto"}
+ );
+
+ result = personDAO.findAllByQuery(query);
+ Assert.assertNotNull(result);
+ Assert.assertEquals(1, result.size());
+ Assert.assertEquals(titi, result.get(0));
+ }
+
+ @Test
+ public void testInOperatorForEntities() throws TopiaException {
+
+ TopiaContext context = db.beginTransaction();
+
+ PetDAO petDAO = TopiaTckLegacyDAOHelper.getPetDAO(context);
+ PersonDAO personDAO = TopiaTckLegacyDAOHelper.getPersonDAO(context);
+
+ Pet bernard = petDAO.create(Pet.PROPERTY_NAME, "bernard");
+ Pet bianca = petDAO.create(Pet.PROPERTY_NAME, "bianca");
+ Pet minou = petDAO.create(Pet.PROPERTY_NAME, "minou");
+ Person toto = personDAO.create(Person.PROPERTY_NAME, "toto");
+ toto.addPet(bernard);
+
+ Person titi = personDAO.create(Person.PROPERTY_NAME, "titi");
+ titi.addPet(bianca);
+
+ Person tutu = personDAO.create(Person.PROPERTY_NAME, "tutu");
+ tutu.addPet(minou);
+
+ TopiaQuery query;
+
+ query = petDAO.createQuery("p").addWhere(
+ "p." + Pet.PROPERTY_PERSON, TopiaQuery.Op.IN, Arrays.asList(toto, titi)
+ );
+
+ List<Pet> result;
+ result = petDAO.findAllByQuery(query);
+ Assert.assertNotNull(result);
+ Assert.assertEquals(2, result.size());
+ Assert.assertTrue(result.contains(bernard));
+ Assert.assertTrue(result.contains(bianca));
+
+ query = petDAO.createQuery("p").addWhere(
+ "p." + Pet.PROPERTY_PERSON, TopiaQuery.Op.NOT_IN, Arrays.asList(toto, titi)
+ );
+
+ result = petDAO.findAllByQuery(query);
+ Assert.assertNotNull(result);
+ Assert.assertEquals(1, result.size());
+ Assert.assertTrue(result.contains(minou));
+ }
+
+}
Property changes on: trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/legacy/ano1991/TopiaQueryAnno1991Test.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Deleted: trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/legacy/ano1991/TopiaQueryTest.java
===================================================================
--- trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/legacy/ano1991/TopiaQueryTest.java 2012-05-22 16:19:02 UTC (rev 2495)
+++ trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/legacy/ano1991/TopiaQueryTest.java 2012-05-23 08:24:34 UTC (rev 2496)
@@ -1,131 +0,0 @@
-/*
- * #%L
- * ToPIA :: Persistence
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2004 - 2012 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.tck.legacy.ano1991;
-
-import org.junit.Assert;
-import org.junit.Rule;
-import org.junit.Test;
-import org.nuiton.topia.TopiaContext;
-import org.nuiton.topia.tck.TopiaDatabase;
-import org.nuiton.topia.TopiaException;
-import org.nuiton.topia.framework.TopiaQuery;
-import org.nuiton.topia.tck.legacy.TopiaDatabaseLegacy;
-import org.nuiton.topia.tck.legacy.TopiaTckLegacyDAOHelper;
-import org.nuiton.topia.tck.legacy.entities.Person;
-import org.nuiton.topia.tck.legacy.entities.PersonDAO;
-import org.nuiton.topia.tck.legacy.entities.Pet;
-import org.nuiton.topia.tck.legacy.entities.PetDAO;
-
-import java.util.Arrays;
-import java.util.List;
-
-/**
- * Prevent regression of http://nuiton.org/issues/1991.
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @since 2.6.8
- */
-public class TopiaQueryTest {
-
- @Rule
- public final TopiaDatabase db = new TopiaDatabaseLegacy();
-
- @Test
- public void testInOperatorForIds() throws TopiaException {
-
- TopiaContext context = db.beginTransaction();
-
- PersonDAO personDAO = TopiaTckLegacyDAOHelper.getPersonDAO(context);
-
- // appel 1 find all
- Person toto = personDAO.create(Person.PROPERTY_NAME, "toto");
- Person titi = personDAO.create(Person.PROPERTY_NAME, "titi");
-
- TopiaQuery query;
-
- query = personDAO.createQuery().addWhere(
- Person.PROPERTY_NAME, TopiaQuery.Op.IN, new String[]{"toto"}
- );
-
- List<Person> result;
- result = personDAO.findAllByQuery(query);
- Assert.assertNotNull(result);
- Assert.assertEquals(1, result.size());
- Assert.assertEquals(toto, result.get(0));
-
- query = personDAO.createQuery().addWhere(
- Person.PROPERTY_NAME, TopiaQuery.Op.NOT_IN, new String[]{"toto"}
- );
-
- result = personDAO.findAllByQuery(query);
- Assert.assertNotNull(result);
- Assert.assertEquals(1, result.size());
- Assert.assertEquals(titi, result.get(0));
- }
-
- @Test
- public void testInOperatorForEntities() throws TopiaException {
-
- TopiaContext context = db.beginTransaction();
-
- PetDAO petDAO = TopiaTckLegacyDAOHelper.getPetDAO(context);
- PersonDAO personDAO = TopiaTckLegacyDAOHelper.getPersonDAO(context);
-
- Pet bernard = petDAO.create(Pet.PROPERTY_NAME, "bernard");
- Pet bianca = petDAO.create(Pet.PROPERTY_NAME, "bianca");
- Pet minou = petDAO.create(Pet.PROPERTY_NAME, "minou");
- Person toto = personDAO.create(Person.PROPERTY_NAME, "toto");
- toto.addPet(bernard);
-
- Person titi = personDAO.create(Person.PROPERTY_NAME, "titi");
- titi.addPet(bianca);
-
- Person tutu = personDAO.create(Person.PROPERTY_NAME, "tutu");
- tutu.addPet(minou);
-
- TopiaQuery query;
-
- query = petDAO.createQuery("p").addWhere(
- "p." + Pet.PROPERTY_PERSON, TopiaQuery.Op.IN, Arrays.asList(toto, titi)
- );
-
- List<Pet> result;
- result = petDAO.findAllByQuery(query);
- Assert.assertNotNull(result);
- Assert.assertEquals(2, result.size());
- Assert.assertTrue(result.contains(bernard));
- Assert.assertTrue(result.contains(bianca));
-
- query = petDAO.createQuery("p").addWhere(
- "p." + Pet.PROPERTY_PERSON, TopiaQuery.Op.NOT_IN, Arrays.asList(toto, titi)
- );
-
- result = petDAO.findAllByQuery(query);
- Assert.assertNotNull(result);
- Assert.assertEquals(1, result.size());
- Assert.assertTrue(result.contains(minou));
- }
-
-}
1
0
r2495 - trunk/topia-persistence/src/main/java/org/nuiton/topia/generator
by athimel@users.nuiton.org 22 May '12
by athimel@users.nuiton.org 22 May '12
22 May '12
Author: athimel
Date: 2012-05-22 18:19:02 +0200 (Tue, 22 May 2012)
New Revision: 2495
Url: http://nuiton.org/repositories/revision/topia/2495
Log:
discriminator-column was not necessary, but inheritance strategy was
Modified:
trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityJPAMappingGenerator.java
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityJPAMappingGenerator.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityJPAMappingGenerator.java 2012-05-22 15:38:56 UTC (rev 2494)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityJPAMappingGenerator.java 2012-05-22 16:19:02 UTC (rev 2495)
@@ -18,6 +18,7 @@
import javax.persistence.AccessType;
import javax.persistence.EnumType;
import javax.persistence.FetchType;
+import javax.persistence.InheritanceType;
import java.beans.Introspector;
import java.io.File;
import java.io.IOException;
@@ -55,7 +56,7 @@
public static final String TAG_TABLE = "table";
- public static final String TAG_DISCRIMINATOR_COLUMN = "discriminator-column";
+ public static final String TAG_INHERITANCE = "inheritance";
public static final String TAG_UNIQUE_CONTRAINT = "unique-constraint";
@@ -255,10 +256,12 @@
}*/
}
- // -- tag 'discriminator-column'
+ // -- tag 'inheritance'
- addAttribute(xmlAttributes, ATTRIBUTE_LENGTH, "255");
-/*{<%=flushTag(TAG_DISCRIMINATOR_COLUMN, true, xmlAttributes)%>
+ // TODO AThimel 22/05/2012 Is the strategy choosable ?
+ // TODO AThimel 22/05/2012 May only be specified on parent entities ?
+ addAttribute(xmlAttributes, ATTRIBUTE_STRATEGY, InheritanceType.TABLE_PER_CLASS.name());
+/*{<%=flushTag(TAG_INHERITANCE, true, xmlAttributes)%>
}*/
1
0
r2494 - in trunk: topia-persistence/src/main/java/org/nuiton/topia/generator topia-persistence-tck/src/main/java/org/nuiton/topia/tck/it
by athimel@users.nuiton.org 22 May '12
by athimel@users.nuiton.org 22 May '12
22 May '12
Author: athimel
Date: 2012-05-22 17:38:56 +0200 (Tue, 22 May 2012)
New Revision: 2494
Url: http://nuiton.org/repositories/revision/topia/2494
Log:
Fix generation about naturalId
Added:
trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/it/naturalId.java
Modified:
trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityJPAMappingGenerator.java
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityJPAMappingGenerator.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityJPAMappingGenerator.java 2012-05-22 14:15:30 UTC (rev 2493)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityJPAMappingGenerator.java 2012-05-22 15:38:56 UTC (rev 2494)
@@ -55,6 +55,8 @@
public static final String TAG_TABLE = "table";
+ public static final String TAG_DISCRIMINATOR_COLUMN = "discriminator-column";
+
public static final String TAG_UNIQUE_CONTRAINT = "unique-constraint";
public static final String TAG_COLUMN_NAME = "column-name";
@@ -253,6 +255,13 @@
}*/
}
+ // -- tag 'discriminator-column'
+
+ addAttribute(xmlAttributes, ATTRIBUTE_LENGTH, "255");
+/*{<%=flushTag(TAG_DISCRIMINATOR_COLUMN, true, xmlAttributes)%>
+}*/
+
+
/*{<%=closeTag(TAG_ENTITY)%>
}*/
Added: trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/it/naturalId.java
===================================================================
--- trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/it/naturalId.java (rev 0)
+++ trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/it/naturalId.java 2012-05-22 15:38:56 UTC (rev 2494)
@@ -0,0 +1,32 @@
+package org.nuiton.topia.tck.it;
+
+/**
+ * Class that contains the natural ids of NaturalizedEntity.
+ * TODO AThimel 22/05/2012 This has to be generated ? To discuss
+ * TODO AThimel 22/05/2012 Find a better name
+ *
+ * @author Arnaud Thimel <thimel(a)codelutin.com>
+ */
+public class naturalId {
+
+ protected Integer naturalIdNotNull;
+
+ protected String naturalIdNull;
+
+ public Integer getNaturalIdNotNull() {
+ return naturalIdNotNull;
+ }
+
+ public void setNaturalIdNotNull(Integer naturalIdNotNull) {
+ this.naturalIdNotNull = naturalIdNotNull;
+ }
+
+ public String getNaturalIdNull() {
+ return naturalIdNull;
+ }
+
+ public void setNaturalIdNull(String naturalIdNull) {
+ this.naturalIdNull = naturalIdNull;
+ }
+
+}
1
0
r2493 - in trunk: topia-persistence/src/main/java/org/nuiton/topia/persistence topia-persistence/src/main/resources/org/nuiton/topia/persistence topia-persistence-hibernate/src/main/java/org/nuiton/topia/framework topia-persistence-hibernate/src/main/java/org/nuiton/topia/persistence topia-persistence-hibernate/src/test/resources
by athimel@users.nuiton.org 22 May '12
by athimel@users.nuiton.org 22 May '12
22 May '12
Author: athimel
Date: 2012-05-22 16:15:30 +0200 (Tue, 22 May 2012)
New Revision: 2493
Url: http://nuiton.org/repositories/revision/topia/2493
Log:
Disable JPA based ID generation and let Topia do it as initialy
Modified:
trunk/topia-persistence-hibernate/src/main/java/org/nuiton/topia/framework/TopiaHibernateEntityListener.java
trunk/topia-persistence-hibernate/src/main/java/org/nuiton/topia/persistence/TopiaHibernatePersistenceProvider.java
trunk/topia-persistence-hibernate/src/test/resources/TopiaContext-it.properties
trunk/topia-persistence-hibernate/src/test/resources/TopiaContext-legacy.properties
trunk/topia-persistence-hibernate/src/test/resources/TopiaContext-mapping.properties
trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAOImpl.java
trunk/topia-persistence/src/main/resources/org/nuiton/topia/persistence/TopiaEntityAbstract-orm.xml
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 2012-05-16 22:59:11 UTC (rev 2492)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAOImpl.java 2012-05-22 14:15:30 UTC (rev 2493)
@@ -186,7 +186,7 @@
// entityAbstract.setTopiaContext(getContext());
//
// // save entity
-// getSession().persist(entity);
+// getEntityManager().persist(entity);
// getContext().getFiresSupport().warnOnUpdateEntity(entity);
// return entity;
// } catch (PersistenceException eee) {
@@ -258,16 +258,20 @@
// // on fait un save maintenant, car puisqu'on a creer l'entity au
// // travers du DAO, on s'attend a l'avoir a disposition tout de
// // suite pour les requetes sans avoir a faire un update dessus
-// getSession().persist(result);
+// getEntityManager().persist(result);
// getContext().getFiresSupport().warnOnCreateEntity(result);
// return result;
}
protected E create0(E result) throws TopiaException {
+ // XXX AThimel 22/05/2012 Add it back here because it does not work in PrePersist event
+ String topiaId = TopiaId.create(entityClass);
+ result.setTopiaId(topiaId);
+
// on fait un save maintenant, car puisqu'on a creer l'entity au
// travers du DAO, on s'attend a l'avoir a disposition tout de
// suite pour les requetes sans avoir a faire un update dessus
- getSession().persist(result);
+ getEntityManager().persist(result);
getContext().getFiresSupport().warnOnCreateEntity(result);
return result;
}
@@ -275,7 +279,7 @@
@Override
public E update(E e) throws TopiaException {
try {
- getSession().merge(e);
+ getEntityManager().merge(e);
getContext().getFiresSupport().warnOnUpdateEntity(e);
return e;
} catch (PersistenceException eee) {
@@ -286,7 +290,7 @@
@Override
public void delete(E e) throws TopiaException {
try {
- getSession().remove(e);
+ getEntityManager().remove(e);
getContext().getFiresSupport().warnOnDeleteEntity(e);
} catch (PersistenceException eee) {
throw new TopiaException(eee);
@@ -576,12 +580,12 @@
}
/**
- * Renvoie la Session contenue dans le contexte
+ * Renvoie l'EntityManager fournit par le context
*
* @return jpa session
* @throws TopiaException if any pb
*/
- EntityManager getSession() throws TopiaException {
+ EntityManager getEntityManager() throws TopiaException {
return getContext().getEntityManager();
}
Modified: trunk/topia-persistence/src/main/resources/org/nuiton/topia/persistence/TopiaEntityAbstract-orm.xml
===================================================================
--- trunk/topia-persistence/src/main/resources/org/nuiton/topia/persistence/TopiaEntityAbstract-orm.xml 2012-05-16 22:59:11 UTC (rev 2492)
+++ trunk/topia-persistence/src/main/resources/org/nuiton/topia/persistence/TopiaEntityAbstract-orm.xml 2012-05-22 14:15:30 UTC (rev 2493)
@@ -2,9 +2,7 @@
<entity-mappings version="2.0" xmlns="http://java.sun.com/xml/ns/persistence/orm" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm http://java.sun.com/xml/ns/persistence/orm_2_0.xsd">
<mapped-superclass class="org.nuiton.topia.persistence.TopiaEntityAbstract" access="FIELD">
<attributes>
- <id name="topiaId" access="FIELD">
- <generated-value strategy="IDENTITY"/>
- </id>
+ <id name="topiaId" access="FIELD"/>
<basic name="topiaCreateDate">
<temporal>TIMESTAMP</temporal>
</basic>
Modified: trunk/topia-persistence-hibernate/src/main/java/org/nuiton/topia/framework/TopiaHibernateEntityListener.java
===================================================================
--- trunk/topia-persistence-hibernate/src/main/java/org/nuiton/topia/framework/TopiaHibernateEntityListener.java 2012-05-16 22:59:11 UTC (rev 2492)
+++ trunk/topia-persistence-hibernate/src/main/java/org/nuiton/topia/framework/TopiaHibernateEntityListener.java 2012-05-22 14:15:30 UTC (rev 2493)
@@ -168,10 +168,11 @@
TopiaEntity entity = castToTopiaEntityOrNull(event.getEntity());
TopiaContextImplementor entityContext = findContext(entity);
- // Using JPA mapping, must generate id here
- Class<?> entityInterface = TopiaPersistenceUtil.getEntityContract(entity.getClass());
- String topiaId = TopiaId.create(entityInterface);
- entity.setTopiaId(topiaId);
+ // TODO AThimel 22/05/2012 Is it really necessary ? It fails for me
+// // Using JPA mapping, must generate id here
+// Class<?> entityInterface = TopiaPersistenceUtil.getEntityContract(entity.getClass());
+// String topiaId = TopiaId.create(entityInterface);
+// entity.setTopiaId(topiaId);
if (entityContext != null && entity != null) {
Object[] entityState = event.getState();
Modified: trunk/topia-persistence-hibernate/src/main/java/org/nuiton/topia/persistence/TopiaHibernatePersistenceProvider.java
===================================================================
--- trunk/topia-persistence-hibernate/src/main/java/org/nuiton/topia/persistence/TopiaHibernatePersistenceProvider.java 2012-05-16 22:59:11 UTC (rev 2492)
+++ trunk/topia-persistence-hibernate/src/main/java/org/nuiton/topia/persistence/TopiaHibernatePersistenceProvider.java 2012-05-22 14:15:30 UTC (rev 2493)
@@ -155,7 +155,8 @@
TopiaHibernateEntityListener.class.getName();
for (EventType type : EVENT_TYPES) {
- String key = AvailableSettings.EVENT_LISTENER_PREFIX + "." + type.eventName();
+ String typeName = type.eventName();
+ String key = AvailableSettings.EVENT_LISTENER_PREFIX + "." + typeName;
hibernateProperties.put(key, entityListenerFQN);
}
Modified: trunk/topia-persistence-hibernate/src/test/resources/TopiaContext-it.properties
===================================================================
--- trunk/topia-persistence-hibernate/src/test/resources/TopiaContext-it.properties 2012-05-16 22:59:11 UTC (rev 2492)
+++ trunk/topia-persistence-hibernate/src/test/resources/TopiaContext-it.properties 2012-05-22 14:15:30 UTC (rev 2493)
@@ -4,7 +4,7 @@
hibernate.dialect=org.hibernate.dialect.H2Dialect
-topia.use.hibernate.mapping.files=true
+topia.use.hibernate.mapping.files=false
topia.connection.username=sa
topia.connection.password=sa
topia.connection.driver_class=org.h2.Driver
Modified: trunk/topia-persistence-hibernate/src/test/resources/TopiaContext-legacy.properties
===================================================================
--- trunk/topia-persistence-hibernate/src/test/resources/TopiaContext-legacy.properties 2012-05-16 22:59:11 UTC (rev 2492)
+++ trunk/topia-persistence-hibernate/src/test/resources/TopiaContext-legacy.properties 2012-05-22 14:15:30 UTC (rev 2493)
@@ -4,7 +4,7 @@
hibernate.dialect=org.hibernate.dialect.H2Dialect
-topia.use.hibernate.mapping.files=true
+topia.use.hibernate.mapping.files=false
topia.connection.username=sa
topia.connection.password=sa
topia.connection.driver_class=org.h2.Driver
Modified: trunk/topia-persistence-hibernate/src/test/resources/TopiaContext-mapping.properties
===================================================================
--- trunk/topia-persistence-hibernate/src/test/resources/TopiaContext-mapping.properties 2012-05-16 22:59:11 UTC (rev 2492)
+++ trunk/topia-persistence-hibernate/src/test/resources/TopiaContext-mapping.properties 2012-05-22 14:15:30 UTC (rev 2493)
@@ -4,7 +4,7 @@
hibernate.dialect=org.hibernate.dialect.H2Dialect
-topia.use.hibernate.mapping.files=true
+topia.use.hibernate.mapping.files=false
topia.connection.username=sa
topia.connection.password=sa
topia.connection.driver_class=org.h2.Driver
1
0
Author: tchemit
Date: 2012-05-17 00:59:11 +0200 (Thu, 17 May 2012)
New Revision: 2492
Url: http://nuiton.org/repositories/revision/topia/2492
Log:
try to improve eugene configuration, but there is a bug with eugene...
Modified:
trunk/topia-persistence-tck/pom.xml
Modified: trunk/topia-persistence-tck/pom.xml
===================================================================
--- trunk/topia-persistence-tck/pom.xml 2012-05-16 22:54:07 UTC (rev 2491)
+++ trunk/topia-persistence-tck/pom.xml 2012-05-16 22:59:11 UTC (rev 2492)
@@ -77,11 +77,6 @@
<plugin>
<groupId>org.nuiton.eugene</groupId>
<artifactId>maven-eugene-plugin</artifactId>
- <configuration>
- <resolver>org.nuiton.util.FasterCachedResourceResolver</resolver>
- <fullPackagePath>org.nuiton.topia.tck</fullPackagePath>
- <defaultPackage>org.nuiton.topia.tck</defaultPackage>
- </configuration>
<executions>
<execution>
<id>generate-objectmodel</id>
@@ -89,6 +84,9 @@
<configuration>
<skipInputs>model</skipInputs>
<inputs>zargo</inputs>
+ <resolver>org.nuiton.util.FasterCachedResourceResolver</resolver>
+ <fullPackagePath>org.nuiton.topia.tck</fullPackagePath>
+ <defaultPackage>org.nuiton.topia.tck</defaultPackage>
</configuration>
<goals>
<goal>smart-generate</goal>
@@ -98,7 +96,8 @@
<id>Test Generator (itk)</id>
<phase>generate-sources</phase>
<configuration>
- <inputs>target/generated-sources/models:topia-tck-it.objectmodel
+ <inputs>
+ target/generated-sources/models:topia-tck-it.objectmodel
</inputs>
<templates>
org.nuiton.topia.generator.TopiaMetaTransformer,
@@ -161,6 +160,11 @@
<artifactId>geronimo-jpa_2.0_spec</artifactId>
<version>${geronimoJpaSpecVersion}</version>
</dependency>
+ <!--dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>topia-persistence</artifactId>
+ <version>${project.version}</version>
+ </dependency-->
</dependencies>
</plugin>
</plugins>
1
0
r2491 - trunk/topia-persistence-hibernate/src/main/java/org/nuiton/topia/framework
by tchemit@users.nuiton.org 16 May '12
by tchemit@users.nuiton.org 16 May '12
16 May '12
Author: tchemit
Date: 2012-05-17 00:54:07 +0200 (Thu, 17 May 2012)
New Revision: 2491
Url: http://nuiton.org/repositories/revision/topia/2491
Log:
let's create id on PreInstert event
Modified:
trunk/topia-persistence-hibernate/src/main/java/org/nuiton/topia/framework/TopiaHibernateEntityListener.java
Modified: trunk/topia-persistence-hibernate/src/main/java/org/nuiton/topia/framework/TopiaHibernateEntityListener.java
===================================================================
--- trunk/topia-persistence-hibernate/src/main/java/org/nuiton/topia/framework/TopiaHibernateEntityListener.java 2012-05-16 22:51:43 UTC (rev 2490)
+++ trunk/topia-persistence-hibernate/src/main/java/org/nuiton/topia/framework/TopiaHibernateEntityListener.java 2012-05-16 22:54:07 UTC (rev 2491)
@@ -2,9 +2,6 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.hibernate.Session;
-import org.hibernate.ejb.AbstractEntityManagerImpl;
-import org.hibernate.event.spi.AbstractEvent;
import org.hibernate.event.spi.PostDeleteEvent;
import org.hibernate.event.spi.PostDeleteEventListener;
import org.hibernate.event.spi.PostInsertEvent;
@@ -25,6 +22,8 @@
import org.nuiton.topia.TopiaException;
import org.nuiton.topia.persistence.TopiaEntity;
import org.nuiton.topia.persistence.TopiaEntityAbstract;
+import org.nuiton.topia.persistence.TopiaId;
+import org.nuiton.topia.persistence.TopiaPersistenceUtil;
/**
* @author Arnaud Thimel <thimel(a)codelutin.com>
@@ -90,7 +89,7 @@
// }
protected void attachContext(TopiaEntity entity,
- TopiaContextImplementor context) {
+ TopiaContextImplementor context) {
// FIXME AThimel 14/05/2012 http://nuiton.org/issues/2078
if (entity instanceof TopiaEntityAbstract) {
TopiaEntityAbstract entityAbstract = (TopiaEntityAbstract) entity;
@@ -100,8 +99,8 @@
} catch (TopiaException eee) {
if (log.isWarnEnabled()) {
log.warn("Impossible d'initialiser le TopiaContext"
- + " sur cette entité : " + entityAbstract,
- eee);
+ + " sur cette entité : " + entityAbstract,
+ eee);
}
}
}
@@ -120,7 +119,7 @@
// FIXME AThimel 14/05/2012 http://nuiton.org/issues/2078
if (entity instanceof TopiaEntityAbstract) {
TopiaContext enitytContext =
- ((TopiaEntityAbstract)entity).getTopiaContext();
+ ((TopiaEntityAbstract) entity).getTopiaContext();
if (enitytContext instanceof TopiaContextImplementor) {
result = (TopiaContextImplementor) enitytContext;
}
@@ -169,6 +168,11 @@
TopiaEntity entity = castToTopiaEntityOrNull(event.getEntity());
TopiaContextImplementor entityContext = findContext(entity);
+ // Using JPA mapping, must generate id here
+ Class<?> entityInterface = TopiaPersistenceUtil.getEntityContract(entity.getClass());
+ String topiaId = TopiaId.create(entityInterface);
+ entity.setTopiaId(topiaId);
+
if (entityContext != null && entity != null) {
Object[] entityState = event.getState();
entityContext.getFiresSupport().fireOnPreCreate(
1
0