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
r2460 - trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/legacy/persistence
by athimel@users.nuiton.org 09 May '12
by athimel@users.nuiton.org 09 May '12
09 May '12
Author: athimel
Date: 2012-05-09 18:57:24 +0200 (Wed, 09 May 2012)
New Revision: 2460
Url: http://nuiton.org/repositories/revision/topia/2460
Log:
Fix test : don't use obsolete exception
Modified:
trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/legacy/persistence/NaturalIdTest.java
Modified: trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/legacy/persistence/NaturalIdTest.java
===================================================================
--- trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/legacy/persistence/NaturalIdTest.java 2012-05-09 16:52:50 UTC (rev 2459)
+++ trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/legacy/persistence/NaturalIdTest.java 2012-05-09 16:57:24 UTC (rev 2460)
@@ -37,6 +37,8 @@
import org.nuiton.topia.tck.it.NaturalizedEntity;
import org.nuiton.topia.tck.it.NaturalizedEntityDAO;
+import javax.persistence.PersistenceException;
+
/**
* NaturalIdTest
* <p/>
@@ -114,7 +116,7 @@
entity.setNaturalIdNotNull(8);
transaction.commitTransaction();
} catch (TopiaException eee) {
- Assert.assertEquals("org.hibernate.HibernateException",
+ Assert.assertEquals(PersistenceException.class.getName(),
eee.getCause().getClass().getName());
}
}
1
0
r2459 - in trunk/topia-persistence-tck/src/main: java/org/nuiton/topia/tck resources
by athimel@users.nuiton.org 09 May '12
by athimel@users.nuiton.org 09 May '12
09 May '12
Author: athimel
Date: 2012-05-09 18:52:50 +0200 (Wed, 09 May 2012)
New Revision: 2459
Url: http://nuiton.org/repositories/revision/topia/2459
Log:
Fix test configuration
Modified:
trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/TestHelper.java
trunk/topia-persistence-tck/src/main/resources/TopiaConnectionProviderHardcoded.properties
Modified: trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/TestHelper.java
===================================================================
--- trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/TestHelper.java 2012-05-09 16:50:54 UTC (rev 2458)
+++ trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/TestHelper.java 2012-05-09 16:52:50 UTC (rev 2459)
@@ -125,8 +125,7 @@
log.info("dbPath = " + dbPath);
}
configuration.setProperty(
-// Environment.URL,
- "hibernate.connection.url",
+ "topia.connection.url",
"jdbc:h2:file:" + dbPath);
return configuration;
Modified: trunk/topia-persistence-tck/src/main/resources/TopiaConnectionProviderHardcoded.properties
===================================================================
--- trunk/topia-persistence-tck/src/main/resources/TopiaConnectionProviderHardcoded.properties 2012-05-09 16:50:54 UTC (rev 2458)
+++ trunk/topia-persistence-tck/src/main/resources/TopiaConnectionProviderHardcoded.properties 2012-05-09 16:52:50 UTC (rev 2459)
@@ -27,9 +27,11 @@
hibernate.show_sql=false
hibernate.dialect=org.hibernate.dialect.H2Dialect
-hibernate.connection.username=sa
-hibernate.connection.password=
-hibernate.connection.driver_class=org.h2.Driver
+
+topia.connection.username=sa
+topia.connection.password=
+topia.connection.driver_class=org.h2.Driver
+
hibernate.connection.provider_class=org.nuiton.topia.framework.TopiaConnectionProviderHardCoded
# tchemit 2010-11-28 : comment this line, each test must define his own db path
#hibernate.connection.url=jdbc:h2:file:target/surefire-workdir/h2data
\ No newline at end of file
1
0
Author: athimel
Date: 2012-05-09 18:50:54 +0200 (Wed, 09 May 2012)
New Revision: 2458
Url: http://nuiton.org/repositories/revision/topia/2458
Log:
Improve TopiaContextImpl configuration
Modified:
trunk/topia-persistence-hibernate/src/main/java/org/nuiton/topia/persistence/hibernate/TopiaHibernatePersistenceProvider.java
trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/TopiaContextFactoryTest.java
trunk/topia-persistence-tck/src/main/resources/TopiaContextImpl.properties
trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaContextFactory.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaContextImpl.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaContextImplementor.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaFiresSupport.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaPersistenceProvider.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaSQLQuery.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityDAOTransformer.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAOImpl.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/DBMapping.java
trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/AbstractTopiaMigrationCallback.java
trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/mappings/TMSVersionDAO.java
trunk/topia-service-replication/src/main/java/org/nuiton/topia/replication/operation/Duplicate.java
trunk/topia-service-security/src/main/java/org/nuiton/topia/taas/TaasService.java
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaContextFactory.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaContextFactory.java 2012-05-09 16:33:14 UTC (rev 2457)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaContextFactory.java 2012-05-09 16:50:54 UTC (rev 2458)
@@ -61,13 +61,7 @@
AbstractReferenceMap.SOFT);
// public final static String CONFIG_DEFAULT_SCHEMA = Environment.DEFAULT_SCHEMA;
-//
-// public final static String CONFIG_USER = Environment.USER;
-//
-// public final static String CONFIG_PASS = Environment.PASS;
-//
-// public final static String CONFIG_DRIVER = Environment.DRIVER;
-//
+
// public final static String CONFIG_DIALECT = Environment.DIALECT;
//
// public final static String CONFIG_CONNECTION_PROVIDER = Environment.CONNECTION_PROVIDER;
@@ -86,8 +80,14 @@
//
// public final static String CONFIG_SHOW_SQL = Environment.SHOW_SQL;
- public final static String CONFIG_URL = "hibernate.connection.url";//Environment.URL;
+ public final static String CONFIG_USER = "topia.connection.username";
+ public final static String CONFIG_PASS = "topia.connection.password";
+
+ public final static String CONFIG_DRIVER = "topia.connection.driver_class";
+
+ public final static String CONFIG_URL = "topia.connection.url";
+
public final static String CONFIG_PERSISTENCE_DIRECTORIES =
"topia.persistence.directories";
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-09 16:33:14 UTC (rev 2457)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaContextImpl.java 2012-05-09 16:50:54 UTC (rev 2458)
@@ -28,13 +28,6 @@
import org.apache.commons.lang3.StringUtils;
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.hibernate.EntityMode;
//import org.hibernate.FlushMode;
//import org.hibernate.ReplicationMode;
@@ -53,7 +46,6 @@
import org.nuiton.topia.TopiaContextFactory;
import org.nuiton.topia.TopiaException;
import org.nuiton.topia.TopiaNotFoundException;
-import org.nuiton.topia.TopiaRuntimeException;
import org.nuiton.topia.event.TopiaContextListener;
import org.nuiton.topia.event.TopiaEntitiesVetoable;
import org.nuiton.topia.event.TopiaEntityListener;
@@ -64,7 +56,6 @@
import org.nuiton.topia.persistence.TopiaDAOImpl;
import org.nuiton.topia.persistence.TopiaEntity;
import org.nuiton.topia.persistence.TopiaId;
-import org.nuiton.util.ArrayUtil;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
@@ -78,22 +69,15 @@
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
-import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;
import java.io.Writer;
import java.lang.reflect.Field;
-import java.text.DateFormat;
-import java.text.SimpleDateFormat;
-import java.util.ArrayList;
import java.util.Arrays;
-import java.util.Collection;
import java.util.Collections;
-import java.util.Date;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.HashSet;
-import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
@@ -139,13 +123,13 @@
protected TopiaContextImplementor parentContext;
/** L'objet configuration utilisé pour la creation de la factory JPA */
- protected Map jpaConfiguration;
+ protected Map<String, Object> jpaConfiguration;
/**
* la factory permettant de recuperer la session hibernate. Seul les
- * TopiaContextImpl initiaux contiennent un hibernateFactory
+ * TopiaContextImpl initiaux contiennent un entityManagerFactory
*/
- protected EntityManagerFactory hibernateFactory;
+ protected EntityManagerFactory entityManagerFactory;
/** La session utilisé par le TopiaContextImpl */
protected EntityManager hibernate;
@@ -489,7 +473,7 @@
}
@Override
- public EntityManager getHibernate() throws TopiaException {
+ public EntityManager getEntityManager() throws TopiaException {
if (hibernate == null) {
throw new TopiaException(
_("topia.persistence.error.no.hibernate.session"));
@@ -498,33 +482,30 @@
}
@Override
- public EntityManagerFactory getHibernateFactory() throws TopiaNotFoundException {
- if (hibernateFactory == null) {
+ public EntityManagerFactory getEntityManagerFactory() throws TopiaNotFoundException {
+ if (entityManagerFactory == null) {
if (getParentContext() != null) {
- hibernateFactory = getParentContext().getHibernateFactory();
+ entityManagerFactory = getParentContext().getEntityManagerFactory();
} else {
-// hibernateFactory = getHibernateConfiguration().buildSessionFactory();
Map params = getJPAConfiguration();
-
- hibernateFactory = Persistence.createEntityManagerFactory("topia", params); // FIXME AThimel 07/05/2012 Map will probably contain Configuration
+ entityManagerFactory = Persistence.createEntityManagerFactory("topia", params);
}
}
- return hibernateFactory;
+ return entityManagerFactory;
}
- public Map getJPAConfiguration() throws TopiaNotFoundException {
+ public Map<String, Object> getJPAConfiguration() throws TopiaNotFoundException {
if (jpaConfiguration == null) {
if (getParentContext() != null) {
jpaConfiguration = getParentContext().getJPAConfiguration();
} else {
- jpaConfiguration = new HashMap();
+ jpaConfiguration = new HashMap<String, Object>();
-
- // ajout des classes dites persistentes
+ // Ajout des classes persistantes
for (TopiaService service : getServices().values()) {
Class<?>[] classes = service.getPersistenceClasses();
- // certains service n'ont pas de classe persistantes
+ // Certains services n'ont pas de classe persistantes
if (classes != null) {
// sletellier 20110411 : http://www.nuiton.org/issues/show/1454
this.persistenceClasses.addAll(Arrays.asList(classes));
@@ -566,6 +547,13 @@
jpaConfiguration.put("topia.entities", this.persistenceClasses);
+ for (Map.Entry<Object, Object> entry : getConfig().entrySet()) {
+ Object key = entry.getKey();
+ if (key instanceof String) {
+ jpaConfiguration.put((String)key, entry.getValue());
+ }
+ }
+
}
}
return jpaConfiguration;
@@ -764,7 +752,7 @@
throw new TopiaException(
_("topia.persistence.error.rootContext.access"));
}
- Set<EntityType<?>> entities = getHibernateFactory().getMetamodel().getEntities();
+ Set<EntityType<?>> entities = getEntityManagerFactory().getMetamodel().getEntities();
boolean found = false;
for (EntityType<?> entityType : entities) {
String entityName = entityType.getName();
@@ -778,7 +766,7 @@
}
// if (!found) {
// log.info(_("topia.persistence.supported.classes.for.context",
-// getHibernateFactory().getMetamodel().getEntities()));
+// getEntityManagerFactory().getMetamodel().getEntities()));
// throw new TopiaException(
// _("topia.persistence.error.unsupported.class",
// entityClass.getName()));
@@ -820,7 +808,7 @@
checkClosed(_("topia.persistence.error.context.is.closed"));
TopiaContextImpl result = new TopiaContextImpl(this);
- EntityManagerFactory factory = getHibernateFactory();
+ EntityManagerFactory factory = getEntityManagerFactory();
result.hibernate = factory.createEntityManager(); // TODO AThimel 07/05/2012 Maybe provide a Map ? cf Configuration
// new TopiaInterceptor(result));
@@ -895,7 +883,7 @@
// it's seem necessary to change session after commit
// NON, NON, NON, il ne faut surtout pas le faire, ca pose plein de
// probleme
- // hibernate = getHibernateFactory().openSession();
+ // hibernate = getEntityManagerFactory().openSession();
// hibernate.setFlushMode(FlushMode.NEVER);
} catch (Exception eee) {
throw new TopiaException(_("topia.persistence.error.on.commit",
@@ -922,7 +910,7 @@
hibernate.close();
// it's very important to change the session after rollback
// otherwize there are many error during next Entity's modification
- hibernate = getHibernateFactory().createEntityManager(); // TODO AThimel 07/05/2012 Maybe provide a Map ? cf Configuration
+ hibernate = getEntityManagerFactory().createEntityManager(); // TODO AThimel 07/05/2012 Maybe provide a Map ? cf Configuration
hibernate.setFlushMode(FlushModeType.COMMIT); // TODO AThimel 07/05/2012 Was MANUAL
// hibernate.beginTransaction();
@@ -967,8 +955,8 @@
hibernate.close();
getParentContext().removeChildContext(this);
} else {
- if (hibernateFactory != null) {
- hibernateFactory.close();
+ if (entityManagerFactory != null) {
+ entityManagerFactory.close();
closed = true;
TopiaContextFactory.removeContext(this);
log.debug("TopiaContext removed");
@@ -981,9 +969,9 @@
*/
@Override
protected void finalize() throws Throwable {
- if (hibernateFactory != null) {
+ if (entityManagerFactory != null) {
closeContext();
- hibernateFactory.close();
+ entityManagerFactory.close();
closed = true;
log.debug("TopiaContext finalized");
}
@@ -997,7 +985,7 @@
@Override
public void executeSQL(String sqlScript) throws TopiaException {
try {
- Query nativeQuery = getHibernate().createNativeQuery(sqlScript);
+ Query nativeQuery = getEntityManager().createNativeQuery(sqlScript);
nativeQuery.executeUpdate();
} catch (PersistenceException e) {
throw new TopiaException("Could not execute sql code", e);
@@ -1042,7 +1030,7 @@
"find"));
try {
- Query query = getHibernate().createQuery(hql);
+ Query query = getEntityManager().createQuery(hql);
for (int j = 0; j < args.length; j += 2) {
String name = (String) args[j];
Object value = args[j + 1];
@@ -1074,7 +1062,7 @@
"find"));
try {
- Query query = getHibernate().createQuery(hql);
+ Query query = getEntityManager().createQuery(hql);
for (int j = 0; j < args.length; j += 2) {
String name = (String) args[j];
Object value = args[j + 1];
@@ -1113,7 +1101,7 @@
"find"));
try {
- Query query = getHibernate().createQuery(hql);
+ Query query = getEntityManager().createQuery(hql);
for (int j = 0; j < args.length; j += 2) {
query.setParameter((String) args[j], args[j + 1]);
}
@@ -1156,7 +1144,7 @@
// }
//
// if (doc != null) {
-// Session sessionDom4j = getHibernate().getSession(EntityMode.DOM4J);
+// Session sessionDom4j = getEntityManager().getSession(EntityMode.DOM4J);
// Element rootElement = doc.getRootElement();
// Iterator<?> it = rootElement.elementIterator();
// while (it.hasNext()) {
@@ -1186,7 +1174,7 @@
//
// // performs queries
// try {
-// Session sessionDom4j = getHibernate().getSession(EntityMode.DOM4J);
+// Session sessionDom4j = getEntityManager().getSession(EntityMode.DOM4J);
//
// Document doc = DocumentFactory.getInstance().createDocument();
// Element rootElement = doc.addElement("topiaExport");
@@ -1340,7 +1328,7 @@
options += " COMPRESSION GZIP";
}
- Query query = getHibernate().createNativeQuery(
+ Query query = getEntityManager().createNativeQuery(
"SCRIPT TO '" + file.getAbsolutePath() + "'" + options);
query.getResultList();
@@ -1387,7 +1375,7 @@
in.close();
}
- Query query = getHibernate().createNativeQuery(
+ Query query = getEntityManager().createNativeQuery(
"RUNSCRIPT FROM '" + file.getAbsolutePath() + "'" + options);
query.executeUpdate();
@@ -1416,7 +1404,7 @@
if (dropDatabase) {
sql += " DELETE FILES";
}
- Query query = tx.getHibernate().createNativeQuery(sql);
+ Query query = tx.getEntityManager().createNativeQuery(sql);
query.executeUpdate();
tx.closeContext();
root.finalize();
@@ -1568,8 +1556,8 @@
// si entityAndcondition est vide alors il faut le remplir
// avec toutes les entités du mapping (class, null)
if (entityAndCondition.length == 0) {
-// Map<?,?> classMetadata = getHibernateFactory().getAllClassMetadata();
- Set<EntityType<?>> classMetadata = getHibernateFactory().getMetamodel().getEntities();
+// Map<?,?> classMetadata = getEntityManagerFactory().getAllClassMetadata();
+ Set<EntityType<?>> classMetadata = getEntityManagerFactory().getMetamodel().getEntities();
entityAndCondition = new Object[classMetadata.size() * 2];
int i = 0;
for (EntityType entityType : classMetadata) {
@@ -1623,8 +1611,8 @@
// // dettach entity to source session, to make possible copy of
// // collection without a hibernate exception (list opened in
// // two session...)
-// getHibernate().detach(entity);
-// dstContextImpl.getHibernate().replicate(entity,
+// getEntityManager().detach(entity);
+// dstContextImpl.getEntityManager().replicate(entity,
// ReplicationMode.EXCEPTION);
// }
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaContextImplementor.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaContextImplementor.java 2012-05-09 16:33:14 UTC (rev 2457)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaContextImplementor.java 2012-05-09 16:50:54 UTC (rev 2458)
@@ -67,26 +67,23 @@
Properties getConfig();
/**
- * @return Returns the hibernate.
+ * @return Returns the EntityManager.
* @throws TopiaException si aucune transaction n'est ouverte
*/
- EntityManager getHibernate() throws TopiaException;
+ EntityManager getEntityManager() throws TopiaException;
/**
- * @return Returns the hibernateFactory.
+ * @return Returns the EntityManagerFactory.
* @throws TopiaNotFoundException
*/
- EntityManagerFactory getHibernateFactory() throws TopiaNotFoundException;
+ EntityManagerFactory getEntityManagerFactory() throws TopiaNotFoundException;
-// /**
-// * @return Returns the hibernate configuration
-// * @throws TopiaNotFoundException
-// */
-// Configuration getHibernateConfiguration()
-// throws TopiaNotFoundException;
+ /**
+ * @return Returns the JPA configuration
+ * @throws TopiaNotFoundException
+ */
+ Map<String, Object> getJPAConfiguration() throws TopiaNotFoundException;
- Map getJPAConfiguration() throws TopiaNotFoundException;
-
/**
* Tells to the context if it has to use a flush mode before each query.
*
@@ -97,6 +94,7 @@
* @since 2.5
*/
void setUseFlushMode(boolean useFlushMode);
+
/**
* Detect if the table is created on storage for a given persistant class.
*
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 2012-05-09 16:33:14 UTC (rev 2457)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaFiresSupport.java 2012-05-09 16:50:54 UTC (rev 2458)
@@ -580,7 +580,7 @@
// ArrayList<TopiaContextImplementor> children = new ArrayList(parent.getChildContext());
// for (TopiaContextImplementor context : children) {
try {
- if (context.getHibernate() == hibernate) {
+ if (context.getEntityManager() == hibernate) {
result = context;
} else {
// TODO: poussin 20090706 on pourrait ameliorer en ne faisant pas un parcours recursif, en utilisant la liste children (sans doute a transformer en stack)
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaPersistenceProvider.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaPersistenceProvider.java 2012-05-09 16:33:14 UTC (rev 2457)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaPersistenceProvider.java 2012-05-09 16:50:54 UTC (rev 2458)
@@ -9,6 +9,7 @@
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
@@ -19,41 +20,35 @@
*/
public abstract class TopiaPersistenceProvider implements PersistenceProvider {
- public abstract EntityManagerFactory configureSpecific(String emName, Map map, Set<Class<?>> entities);
+ public abstract EntityManagerFactory configureSpecific(String emName, Map<String, Object> map, Set<Class<?>> entities);
@Override
public EntityManagerFactory createEntityManagerFactory(String emName, Map map) {
- System.out.println("createEntityManagerFactory " + emName);
EntityManagerFactory result = null;
if ("topia".equals(emName)) {
// Use PersistenceProvider of the underlying JPA library
+ Map<String, Object> properties = (Map<String, Object>)map;
- map.put("javax.persistence.jdbc.driver", "org.h2.Driver");
- map.put("javax.persistence.jdbc.url", "jdbc:h2:file:target/surefire-workdir/h2data");
- map.put("javax.persistence.jdbc.user", "sa");
- map.put("javax.persistence.jdbc.password", "");
-
Set<Class<?>> entityClasses = (Set<Class<?>>) map.get("topia.entities");
if (entityClasses == null) {
throw new TopiaRuntimeException("topia.entities list must be provided");
}
- result = configureSpecific(emName, map, entityClasses);
+ result = configureSpecific(emName, properties, entityClasses);
}
return result;
}
@Override
public EntityManagerFactory createContainerEntityManagerFactory(PersistenceUnitInfo info, Map map) {
- System.out.println("createContainerEntityManagerFactory " + info);
- return null;
+ throw new UnsupportedOperationException("Not yet implemented : TopiaPersistenceProvider#createContainerEntityManagerFactory");
}
@Override
public ProviderUtil getProviderUtil() {
- System.out.println("getProviderUtil");
- return null;
+ throw new UnsupportedOperationException("Not yet implemented : TopiaPersistenceProvider#getProviderUtil");
}
+
}
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaSQLQuery.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaSQLQuery.java 2012-05-09 16:33:14 UTC (rev 2457)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaSQLQuery.java 2012-05-09 16:50:54 UTC (rev 2458)
@@ -75,7 +75,7 @@
public O findSingleResult(TopiaContextImplementor tx) throws TopiaException {
final List<O> result = new ArrayList<O>();
-// tx.getHibernate().doWork(new Work() {
+// tx.getEntityManager().doWork(new Work() {
//
// @Override
// public void execute(Connection connection) throws SQLException {
@@ -107,7 +107,7 @@
public List<O> findMultipleResult(TopiaContextImplementor tx) throws TopiaException {
final List<O> result = new ArrayList<O>();
-// tx.getHibernate().doWork(new Work() {
+// tx.getEntityManager().doWork(new Work() {
//
// @Override
// public void execute(Connection connection) throws SQLException {
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityDAOTransformer.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityDAOTransformer.java 2012-05-09 16:33:14 UTC (rev 2457)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityDAOTransformer.java 2012-05-09 16:50:54 UTC (rev 2458)
@@ -611,7 +611,7 @@
body.append(""
/*{
{
- List<<%=attrType%>> list = getContext().getHibernate().createNativeQuery(
+ List<<%=attrType%>> list = getContext().getEntityManager().createNativeQuery(
"SELECT main.topiaid " +
"from <%=attrClassifierDBName%> main, <%=attrJoinTableName%> secondary " +
"where main.topiaid=secondary.<%=attrDBName%>" +
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-09 16:33:14 UTC (rev 2457)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAOImpl.java 2012-05-09 16:50:54 UTC (rev 2458)
@@ -559,7 +559,7 @@
* @throws TopiaException if any pb
*/
EntityManager getSession() throws TopiaException {
- return getContext().getHibernate();
+ return getContext().getEntityManager();
}
/**
@@ -570,7 +570,7 @@
* @throws TopiaException if any pb
*/
EntityType<E> getClassMetadata() throws TopiaException {
- Metamodel metamodel = getContext().getHibernateFactory()
+ Metamodel metamodel = getContext().getEntityManagerFactory()
.getMetamodel();
EntityType<E> meta = metamodel.entity(getEntityClass());
// TODO AThimel 07/05/2012 Maybe there is no need to call this ?
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/DBMapping.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/DBMapping.java 2012-05-09 16:33:14 UTC (rev 2457)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/DBMapping.java 2012-05-09 16:50:54 UTC (rev 2458)
@@ -39,9 +39,6 @@
import java.io.IOException;
import java.io.InputStream;
import java.math.BigInteger;
-import java.sql.Connection;
-import java.sql.SQLException;
-import java.sql.Statement;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
@@ -331,7 +328,7 @@
BigInteger size = defaultSize;
if (ctxt != null) {
try {
- Query query = ((TopiaContextImpl) ctxt).getHibernate().createNativeQuery(sql);
+ Query query = ((TopiaContextImpl) ctxt).getEntityManager().createNativeQuery(sql);
size = (BigInteger) query.getResultList().get(0);
// } catch (SQLGrammarException e) {
} catch (Exception e) {
Modified: trunk/topia-persistence-hibernate/src/main/java/org/nuiton/topia/persistence/hibernate/TopiaHibernatePersistenceProvider.java
===================================================================
--- trunk/topia-persistence-hibernate/src/main/java/org/nuiton/topia/persistence/hibernate/TopiaHibernatePersistenceProvider.java 2012-05-09 16:33:14 UTC (rev 2457)
+++ trunk/topia-persistence-hibernate/src/main/java/org/nuiton/topia/persistence/hibernate/TopiaHibernatePersistenceProvider.java 2012-05-09 16:50:54 UTC (rev 2458)
@@ -8,6 +8,7 @@
import javax.persistence.EntityManagerFactory;
import java.io.InputStream;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
@@ -19,39 +20,18 @@
public class TopiaHibernatePersistenceProvider extends TopiaPersistenceProvider {
@Override
- public EntityManagerFactory configureSpecific(String entityManagerName, Map map, Set<Class<?>> entities) {
+ public EntityManagerFactory configureSpecific(String entityManagerName, Map<String, Object> properties, Set<Class<?>> entities) {
- map.put("hibernate.connection.driver", "org.h2.Driver");
- map.put("hibernate.connection.url", "jdbc:h2:file:target/surefire-workdir/h2data");
- map.put("hibernate.connection.user", "sa");
- map.put("hibernate.connection.password", "");
+ Map<String, Object> hibernateProperties = new HashMap<String, Object>(properties);
+ // On convertit tout ce qui est en topia.connection.* vers hibernate.connection.*
+ for (String key : properties.keySet()) {
+ if (key.startsWith("topia.connection.")) {
+ Object value = properties.get(key);
+ String hibernateKey = "hibernate." + key.substring(6);
+ hibernateProperties.put(hibernateKey, value);
+ }
+ }
- map.put("hibernate.dialect", "org.hibernate.dialect.H2Dialect");
- map.put("hibernate.hbm2ddl.auto", "create-drop");
- map.put("hibernate.show_sql", "false");
-
-// map.put("hibernate.connection.provider_class", "org.nuiton.topia.framework.TopiaConnectionProviderHardCoded");
-// Set<Class<?>> entities = new HashSet<Class<?>>();
-// entities.add(PersonImpl.class);
-// entities.add(PetImpl.class);
-// entities.add(RaceImpl.class);
-// entities.add(NaturalizedEntityImpl.class);
-// entities.add(CompanyImpl.class);
-// entities.add(EmployeImpl.class);
-// entities.add(PersonneImpl.class);
-// entities.add(DepartmentImpl.class);
-// entities.add(BillImpl.class);
-// entities.add(ProductImpl.class);
-// entities.add(StoreImpl.class);
-// entities.add(Contact2Impl.class);
-// entities.add(Party2Impl.class);
-// entities.add(Telephone2Impl.class);
-// entities.add(AddressImpl.class);
-// entities.add(ExtraDAOEntityImpl.class);
-// entities.add(GeneralizedNaturalizedEntityImpl.class);
-// entities.add(QueriedEntityImpl.class);
-// entities.add(TypeImpl.class);
-
List<String> entitiesNames = new ArrayList<String>();
List<NamedInputStream> entitiesHbmFiles = new ArrayList<NamedInputStream>();
@@ -67,7 +47,6 @@
entitiesHbmFiles.add(entityHbmNIS);
}
-
Ejb3Configuration cfg = new Ejb3Configuration();
PersistenceMetadata metadata = new PersistenceMetadata();
metadata.setName(entityManagerName);
@@ -75,7 +54,7 @@
metadata.setClasses(entitiesNames);
metadata.setHbmfiles(entitiesHbmFiles);
- Ejb3Configuration configured = cfg.configure(metadata, map);
+ Ejb3Configuration configured = cfg.configure(metadata, hibernateProperties);
EntityManagerFactory result = null;
if (configured != null) {
result = configured.buildEntityManagerFactory();
Modified: trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/TopiaContextFactoryTest.java
===================================================================
--- trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/TopiaContextFactoryTest.java 2012-05-09 16:33:14 UTC (rev 2457)
+++ trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/TopiaContextFactoryTest.java 2012-05-09 16:50:54 UTC (rev 2458)
@@ -159,7 +159,7 @@
log.info("test5a : reinstantiate new TopiaContext after one is closed.");
// TEST
// Strange behavior the closed flag of context stay true if
- // hibernateFactory is not loaded from real properties
+ // entityManagerFactory is not loaded from real properties
// test1.closeContext();
// Assert.assertTrue(test1.isClosed());
Modified: trunk/topia-persistence-tck/src/main/resources/TopiaContextImpl.properties
===================================================================
--- trunk/topia-persistence-tck/src/main/resources/TopiaContextImpl.properties 2012-05-09 16:33:14 UTC (rev 2457)
+++ trunk/topia-persistence-tck/src/main/resources/TopiaContextImpl.properties 2012-05-09 16:50:54 UTC (rev 2458)
@@ -27,8 +27,9 @@
hibernate.show_sql=false
hibernate.dialect=org.hibernate.dialect.H2Dialect
-hibernate.connection.username=sa
-hibernate.connection.password=
-hibernate.connection.driver_class=org.h2.Driver
+
+topia.connection.username=sa
+topia.connection.password=
+topia.connection.driver_class=org.h2.Driver
# tchemit 2010-11-28 : comment this line, each test must define his own db path
#hibernate.connection.url=jdbc:h2:file:target/surefire-workdir/h2data
\ No newline at end of file
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 2012-05-09 16:33:14 UTC (rev 2457)
+++ trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/AbstractTopiaMigrationCallback.java 2012-05-09 16:50:54 UTC (rev 2458)
@@ -183,7 +183,7 @@
"--------------------------------------------------------------------------------\n"
);
}
- tx.getHibernate().doWork(new Work() {
+ tx.getEntityManager().doWork(new Work() {
@Override
public void execute(Connection connection) throws SQLException {
Modified: trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/mappings/TMSVersionDAO.java
===================================================================
--- trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/mappings/TMSVersionDAO.java 2012-05-09 16:33:14 UTC (rev 2457)
+++ trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/mappings/TMSVersionDAO.java 2012-05-09 16:50:54 UTC (rev 2458)
@@ -64,7 +64,7 @@
public static TMSVersion get(TopiaContext tx) throws TopiaException {
try {
- Session session = ((TopiaContextImplementor) tx).getHibernate();
+ Session session = ((TopiaContextImplementor) tx).getEntityManager();
Criteria criteria = session.createCriteria(TMSVersion.class);
List<?> list = criteria.list();
TMSVersion result = list.isEmpty() ? null : (TMSVersion) list.get(0);
@@ -91,7 +91,7 @@
public static TMSVersion create(TopiaContext tx, String version) throws TopiaException {
try {
- Session session = ((TopiaContextImplementor) tx).getHibernate();
+ Session session = ((TopiaContextImplementor) tx).getEntityManager();
TMSVersion result = TMSVersion.valueOf(version);
// save entity
@@ -104,7 +104,7 @@
public static void update(TopiaContext tx, TMSVersion version) throws TopiaException {
try {
- Session session = ((TopiaContextImplementor) tx).getHibernate();
+ Session session = ((TopiaContextImplementor) tx).getEntityManager();
session.saveOrUpdate(version);
tx.commitTransaction();
} catch (HibernateException e) {
@@ -114,7 +114,7 @@
public static void deleteAll(TopiaContext tx) throws TopiaException {
try {
- Session session = ((TopiaContextImplementor) tx).getHibernate();
+ Session session = ((TopiaContextImplementor) tx).getEntityManager();
Criteria criteria = session.createCriteria(TMSVersion.class);
List<?> list = criteria.list();
for (Object o : list) {
@@ -143,7 +143,7 @@
String schemaName = TopiaUtil.getSchemaName(hibernateConfiguration);
GetVersionWork work = new GetVersionWork(schemaName, tableName);
- txImpl.getHibernate().doWork(work);
+ txImpl.getEntityManager().doWork(work);
Version v = work.getVersion();
return v;
} catch (TopiaException e) {
Modified: trunk/topia-service-replication/src/main/java/org/nuiton/topia/replication/operation/Duplicate.java
===================================================================
--- trunk/topia-service-replication/src/main/java/org/nuiton/topia/replication/operation/Duplicate.java 2012-05-09 16:33:14 UTC (rev 2457)
+++ trunk/topia-service-replication/src/main/java/org/nuiton/topia/replication/operation/Duplicate.java 2012-05-09 16:50:54 UTC (rev 2458)
@@ -71,7 +71,7 @@
//FIXME tchemit-2011-06-03 : while using hibernate 3.5.6, while duplicating entities we can have some associations in double sessions
//FIXME This hack works but it should be better to resolve the bug :( perharps this is not possible
//FIXME since we can not have a fresh empty hibernate session...
- srcCtxt.getHibernate().clear();
+ srcCtxt.getEntityManager().clear();
// replication des donnees vers la destination
srcCtxt.replicateEntities(dstCtxt, entities);
Modified: trunk/topia-service-security/src/main/java/org/nuiton/topia/taas/TaasService.java
===================================================================
--- trunk/topia-service-security/src/main/java/org/nuiton/topia/taas/TaasService.java 2012-05-09 16:33:14 UTC (rev 2457)
+++ trunk/topia-service-security/src/main/java/org/nuiton/topia/taas/TaasService.java 2012-05-09 16:50:54 UTC (rev 2458)
@@ -200,7 +200,7 @@
* @param context context topia en cours
*/
private void initSecurity(TopiaContext context) {
- List<Class<?>> entitiesClasses = rootContext.getPersistenceClasses();
+ Set<Class<?>> entitiesClasses = rootContext.getPersistenceClasses();
for (Class<?> clazz : entitiesClasses) {
context.addTopiaEntityVetoable((Class) clazz, accessEntity);
}
1
0
r2457 - in trunk/topia-persistence-tck/src/main: java/org/nuiton/topia/tck/mapping/test9 xmi
by tchemit@users.nuiton.org 09 May '12
by tchemit@users.nuiton.org 09 May '12
09 May '12
Author: tchemit
Date: 2012-05-09 18:33:14 +0200 (Wed, 09 May 2012)
New Revision: 2457
Url: http://nuiton.org/repositories/revision/topia/2457
Log:
fix mapping model
Added:
trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/mapping/test9/E9.java
Modified:
trunk/topia-persistence-tck/src/main/xmi/topia-tck-mapping.zargo
Added: trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/mapping/test9/E9.java
===================================================================
--- trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/mapping/test9/E9.java (rev 0)
+++ trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/mapping/test9/E9.java 2012-05-09 16:33:14 UTC (rev 2457)
@@ -0,0 +1,12 @@
+package org.nuiton.topia.tck.mapping.test9;
+
+/**
+ * TODO
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since TODO
+ */
+public enum E9 {
+ LITERAL1,
+ LITERAL2
+}
Modified: trunk/topia-persistence-tck/src/main/xmi/topia-tck-mapping.zargo
===================================================================
(Binary files differ)
1
0
r2456 - in trunk: topia-persistence-hibernate/src/test/java/org/nuiton/topia/framework topia-persistence-hibernate/src/test/java/org/nuiton/topia/tck topia-persistence-tck/src/main/java/org/nuiton/topia/tck/legacy/framework
by athimel@users.nuiton.org 09 May '12
by athimel@users.nuiton.org 09 May '12
09 May '12
Author: athimel
Date: 2012-05-09 18:17:33 +0200 (Wed, 09 May 2012)
New Revision: 2456
Url: http://nuiton.org/repositories/revision/topia/2456
Log:
Fix TopiaTck Hibernate's TestSuite name
Added:
trunk/topia-persistence-hibernate/src/test/java/org/nuiton/topia/tck/TopiaTckHibernateTest.java
Removed:
trunk/topia-persistence-hibernate/src/test/java/org/nuiton/topia/tck/TopiaTckHibernateTestSuite.java
Modified:
trunk/topia-persistence-hibernate/src/test/java/org/nuiton/topia/framework/TopiaConnectionProviderTest.java
trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/legacy/framework/TopiaUtilTest.java
Modified: trunk/topia-persistence-hibernate/src/test/java/org/nuiton/topia/framework/TopiaConnectionProviderTest.java
===================================================================
--- trunk/topia-persistence-hibernate/src/test/java/org/nuiton/topia/framework/TopiaConnectionProviderTest.java 2012-05-09 16:08:01 UTC (rev 2455)
+++ trunk/topia-persistence-hibernate/src/test/java/org/nuiton/topia/framework/TopiaConnectionProviderTest.java 2012-05-09 16:17:33 UTC (rev 2456)
@@ -25,6 +25,7 @@
package org.nuiton.topia.framework;
import org.junit.Assert;
+import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.nuiton.topia.TopiaContext;
@@ -85,6 +86,7 @@
};
@Test
+ @Ignore // FIXME AThimel 09/05/2012 Remove @Ignore
public void testWithHardcoded() throws Exception {
// Properties dbProperties = TestHelper.loadHibernateConfiguration(
Copied: trunk/topia-persistence-hibernate/src/test/java/org/nuiton/topia/tck/TopiaTckHibernateTest.java (from rev 2454, trunk/topia-persistence-hibernate/src/test/java/org/nuiton/topia/tck/TopiaTckHibernateTestSuite.java)
===================================================================
--- trunk/topia-persistence-hibernate/src/test/java/org/nuiton/topia/tck/TopiaTckHibernateTest.java (rev 0)
+++ trunk/topia-persistence-hibernate/src/test/java/org/nuiton/topia/tck/TopiaTckHibernateTest.java 2012-05-09 16:17:33 UTC (rev 2456)
@@ -0,0 +1,10 @@
+package org.nuiton.topia.tck;
+
+/**
+ * Do not remove event if empty : this class represents the TCK IT tests
+ * for topia-persistence-hibernate module
+ *
+ * @author Arnaud Thimel <thimel(a)codelutin.com>
+ */
+public class TopiaTckHibernateTest extends TopiaTckTestSuite {
+}
Deleted: trunk/topia-persistence-hibernate/src/test/java/org/nuiton/topia/tck/TopiaTckHibernateTestSuite.java
===================================================================
--- trunk/topia-persistence-hibernate/src/test/java/org/nuiton/topia/tck/TopiaTckHibernateTestSuite.java 2012-05-09 16:08:01 UTC (rev 2455)
+++ trunk/topia-persistence-hibernate/src/test/java/org/nuiton/topia/tck/TopiaTckHibernateTestSuite.java 2012-05-09 16:17:33 UTC (rev 2456)
@@ -1,14 +0,0 @@
-package org.nuiton.topia.tck;
-
-import org.junit.runners.Suite;
-import org.nuiton.topia.tck.TopiaTckTestSuite;
-import org.nuiton.topia.tck.ano1882.DAOAbstractTransformerTest;
-
-/**
- * Do not remove event if empty : this class represents the TCK IT tests
- * for topia-persistence-hibernate module
- *
- * @author Arnaud Thimel <thimel(a)codelutin.com>
- */
-public class TopiaTckHibernateTestSuite extends TopiaTckTestSuite {
-}
Modified: trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/legacy/framework/TopiaUtilTest.java
===================================================================
--- trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/legacy/framework/TopiaUtilTest.java 2012-05-09 16:08:01 UTC (rev 2455)
+++ trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/legacy/framework/TopiaUtilTest.java 2012-05-09 16:17:33 UTC (rev 2456)
@@ -51,9 +51,9 @@
*/
public class TopiaUtilTest {
- protected static final String PERSON_ID = "org.nuiton.topiatest.Personne#1226701039001#0.6502325993664224";
+ protected static final String PERSON_ID = "org.nuiton.topia.tck.it.Personne#1226701039001#0.6502325993664224";
- protected static final String PERSON_ID2 = "org.nuiton.topiatest.Personne#1226701039001#0.6502325993664999";
+ protected static final String PERSON_ID2 = "org.nuiton.topia.tck.it.Personne#1226701039001#0.6502325993664999";
@Rule
public final TopiaDatabase db = new TopiaDatabase();
@@ -63,7 +63,7 @@
String expected;
String actual;
- expected = "org\\.nuiton\\.topiatest\\.Personne#(?:\\d+?)#(?:\\d+)\\.(?:\\d+)";
+ expected = "org\\.nuiton\\.topia\\.tck\\.it\\.Personne#(?:\\d+?)#(?:\\d+)\\.(?:\\d+)";
actual = TopiaUtil.getTopiaIdPattern(Personne.class);
assertEquals(expected, actual);
}
@@ -73,7 +73,7 @@
String expected;
Pattern pattern;
- expected = "(\\d+)-(org\\.nuiton\\.topiatest\\.Personne#(?:\\d+?)#(?:\\d+)\\.(?:\\d+))-(org\\.nuiton\\.topiatest\\.Personne#(?:\\d+?)#(?:\\d+)\\.(?:\\d+))(.*)";
+ expected = "(\\d+)-(org\\.nuiton\\.topia\\.tck\\.it\\.Personne#(?:\\d+?)#(?:\\d+)\\.(?:\\d+))-(org\\.nuiton\\.topia\\.tck\\.it\\.Personne#(?:\\d+?)#(?:\\d+)\\.(?:\\d+))(.*)";
pattern = TopiaUtil.getTopiaPattern("(\\d+)-%1$s-%1$s(.*)", Personne.class);
assertEquals(expected, pattern.toString());
1
0
Author: tchemit
Date: 2012-05-09 18:08:01 +0200 (Wed, 09 May 2012)
New Revision: 2455
Url: http://nuiton.org/repositories/revision/topia/2455
Log:
add new generator for jpa mapping
move all legacy tests to a legacy package
add a unit test model for mapping
Added:
trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/legacy/
trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/legacy/ano1882/
trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/legacy/ano1991/
trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/legacy/evo1912/
trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/legacy/framework/
trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/legacy/generator/
trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/legacy/persistence/
trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/mapping/
trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/mapping/test1/
trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/mapping/test10/
trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/mapping/test11/
trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/mapping/test2/
trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/mapping/test3/
trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/mapping/test4/
trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/mapping/test5/
trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/mapping/test6/
trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/mapping/test7/
trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/mapping/test8/
trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/mapping/test9/
trunk/topia-persistence-tck/src/main/xmi/topia-tck-mapping.properties
trunk/topia-persistence-tck/src/main/xmi/topia-tck-mapping.zargo
trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityJPAMappingGenerator.java
Removed:
trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/ano1882/
trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/ano1991/
trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/evo1912/
trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/framework/
trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/generator/
trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/persistence/
Modified:
trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/TopiaTckTestSuite.java
trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/legacy/ano1882/DAOAbstractTransformerTest.java
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/evo1912/EntityDTOTransformerTest.java
trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/legacy/framework/TopiaContextReplicateTest.java
trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/legacy/framework/TopiaUtilTest.java
trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/legacy/generator/TopiaTestCase.java
trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/legacy/persistence/EntityVisitorExportXmlTest.java
trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/legacy/persistence/ExportXMLVisitor.java
trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/legacy/persistence/NaturalIdTest.java
trunk/topia-persistence/pom.xml
trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/TopiaMetaTransformer.java
Modified: trunk/topia-persistence/pom.xml
===================================================================
--- trunk/topia-persistence/pom.xml 2012-05-09 16:07:09 UTC (rev 2454)
+++ trunk/topia-persistence/pom.xml 2012-05-09 16:08:01 UTC (rev 2455)
@@ -78,6 +78,11 @@
</dependency>
<dependency>
+ <groupId>com.google.guava</groupId>
+ <artifactId>guava</artifactId>
+ </dependency>
+
+ <dependency>
<groupId>dom4j</groupId>
<artifactId>dom4j</artifactId>
</dependency>
Added: trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityJPAMappingGenerator.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityJPAMappingGenerator.java (rev 0)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityJPAMappingGenerator.java 2012-05-09 16:08:01 UTC (rev 2455)
@@ -0,0 +1,873 @@
+package org.nuiton.topia.generator;
+
+import com.google.common.base.Strings;
+import com.google.common.collect.ArrayListMultimap;
+import com.google.common.collect.LinkedHashMultimap;
+import com.google.common.collect.Maps;
+import com.google.common.collect.Multimap;
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.collections.MapUtils;
+import org.apache.commons.lang3.BooleanUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.nuiton.eugene.models.object.ObjectModelAttribute;
+import org.nuiton.eugene.models.object.ObjectModelClass;
+import org.nuiton.eugene.models.object.ObjectModelGenerator;
+import org.nuiton.topia.persistence.TopiaEntity;
+
+import javax.persistence.AccessType;
+import javax.persistence.EnumType;
+import javax.persistence.FetchType;
+import java.beans.Introspector;
+import java.io.File;
+import java.io.IOException;
+import java.io.Writer;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeMap;
+
+import static org.nuiton.topia.generator.TopiaGeneratorUtil.hasUnidirectionalRelationOnAbstractType;
+
+/**
+ * To generate entity jpa mapping files for entities.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @plexus.component role="org.nuiton.eugene.Template" role-hint="org.nuiton.topia.generator.EntityJPAMappingGenerator"
+ * @since 3.0
+ */
+public class EntityJPAMappingGenerator extends ObjectModelGenerator {
+
+ /** Logger. */
+ private static final Log log = LogFactory
+ .getLog(EntityJPAMappingGenerator.class);
+
+ public static final String TAG_ENTITY_MAPPINGS = "entity-mappings";
+
+ public static final String TAG_PACKAGE = "package";
+
+ public static final String TAG_ENTITY = "entity";
+
+ public static final String TAG_TABLE = "table";
+
+ public static final String TAG_UNIQUE_CONTRAINT = "unique-constraint";
+
+ public static final String TAG_COLUMN_NAME = "column-name";
+
+ public static final String TAG_ATTRIBUTES = "attributes";
+
+ public static final String TAG_ID = "id";
+
+ public static final String TAG_VERSION = "version";
+
+ public static final String TAG_MANY_TO_ONE = "many-to-one";
+
+ public static final String TAG_ONE_TO_MANY = "one-to-many";
+
+ public static final String TAG_ONE_TO_ONE = "one-to-one";
+
+ public static final String TAG_MANY_TO_MANY = "many-to-many";
+
+ public static final String TAG_ELEMENT_COLLECTION = "element-collection";
+
+ public static final String TAG_BASIC = "basic";
+
+ public static final String TAG_EMBEDDED = "embedded";
+
+ public static final String TAG_EMBEDDABLE = "embeddable";
+
+ public static final String TAG_ENUMERATED = "enumerated";
+
+ public static final String TAG_TEMPORAL = "temporal";
+
+ public static final String TAG_COLUMN = "column";
+
+ public static final String TAG_JOIN_COLUMN = "join-column";
+
+ public static final String TAG_JOIN_TABLE = "join-table";
+
+ public static final String TAG_GENERATED_VALUE = "generated-value";
+
+ public static final String TAG_CASCADE = "cascade";
+
+ public static final String TAG_CASCADE_ALL = "cascade-all";
+
+ public static final String TAG_CASCADE_REMOVE = "cascade-remove";
+
+ public static final String ATTRIBUTE_CLASS = "class";
+
+ public static final String ATTRIBUTE_GENERATOR = "generator";
+
+ public static final String ATTRIBUTE_STRATEGY = "strategy";
+
+ public static final String ATTRIBUTE_ACCESS = "access";
+
+ public static final String ATTRIBUTE_METADATA_COMPLETE = "metadata-complete";
+
+ public static final String ATTRIBUTE_NAME = "name";
+
+ public static final String ATTRIBUTE_CACHEABLE = "cacheable";
+
+ public static final String ATTRIBUTE_SCHEMA = "schema";
+
+ public static final String ATTRIBUTE_CATALOG = "catalog";
+
+ public static final String ATTRIBUTE_OPTIONAL = "optional";
+
+ public static final String ATTRIBUTE_FETCH = "fetch";
+
+ private static final String ATTRIBUTE_ORPHAN_REMOVAL = "orphan-removal";
+
+ public static final String ATTRIBUTE_COLUMN_DEFINITION = "column-definition";
+
+ public static final String ATTRIBUTE_INSERTABLE = "insertable";
+
+ public static final String ATTRIBUTE_LENGTH = "length";
+
+ public static final String ATTRIBUTE_NULLABLE = "nullable";
+
+ public static final String ATTRIBUTE_PRECISION = "precision";
+
+ public static final String ATTRIBUTE_SCALE = "scale";
+
+ public static final String ATTRIBUTE_TABLE = "table";
+
+ public static final String ATTRIBUTE_UNIQUE = "unique";
+
+ public static final String ATTRIBUTE_UPDATABLE = "updatable";
+
+ public static final String ATTRIBUTE_REFERENCE_COLUMN_NAME = "referencedColumnName";
+
+ private Map<String, String[]> columnNamesMap = new HashMap<String, String[]>();
+
+ @Override
+ public String getFilenameForClass(ObjectModelClass clazz) {
+ String result = TopiaGeneratorUtil.getDOType(clazz, model);
+ return result.replace('.', File.separatorChar) + "-orm.xml";
+ }
+
+
+ protected Multimap<String, ObjectModelAttribute> splitAttributes(
+ ObjectModelClass input,
+ List<ObjectModelAttribute> normalAttributes) {
+ Multimap<String, ObjectModelAttribute> result = ArrayListMultimap.create();
+ for (ObjectModelAttribute attribute : input.getAttributes()) {
+ if (TopiaGeneratorUtil.isNaturalId(attribute)) {
+ result.put("naturalId", attribute);
+ } else {
+ normalAttributes.add(attribute);
+ }
+ }
+ return result;
+ }
+
+ @Override
+ public void generateFromClass(Writer output,
+ ObjectModelClass input) throws IOException {
+
+ xmlLevel=0;
+
+ String persistenceType = TopiaGeneratorUtil.getPersistenceType(input);
+ if (!TopiaGeneratorUtil.isEntity(input) &&
+ TopiaGeneratorUtil.PERSISTENCE_TYPE_HIBERNATE.equals(persistenceType)) {
+ return;
+ }
+/*{<?xml version="1.0" encoding="UTF-8"?>
+}*/
+ Map<String, String> xmlAttributes = new TreeMap<String, String>();
+
+ // -- tag 'entity-mappings'
+
+ addAttribute(xmlAttributes, "xmlns", "http://java.sun.com/xml/ns/persistence/orm");
+ addAttribute(xmlAttributes, "xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
+ addAttribute(xmlAttributes, "xsi:schemaLocation", "http://java.sun.com/xml/ns/persistence/orm http://java.sun.com/xml/ns/persistence/orm_2_0.xsd");
+ addAttribute(xmlAttributes, "version", "2.0");
+/*{<%=flushTag(TAG_ENTITY_MAPPINGS, xmlAttributes)%>
+}*/
+
+ // -- tag 'package'
+
+/*{<%=flushTag(TAG_PACKAGE, input.getPackageName())%><%=closeStrictTag(TAG_PACKAGE)%>
+}*/
+
+ // -- tag 'entity'
+
+ String clazzFQN = input.getQualifiedName();
+
+
+ addAttribute(xmlAttributes, ATTRIBUTE_NAME, clazzFQN);
+ addAttribute(xmlAttributes, ATTRIBUTE_CLASS, input.getName() + "Impl");
+ addAttribute(xmlAttributes, ATTRIBUTE_ACCESS, AccessType.FIELD);
+ addAttribute(xmlAttributes, ATTRIBUTE_METADATA_COMPLETE, true);
+//NOTUSED addAttribute(xmlAttributes, ATTRIBUTE_CACHEABLE, true);
+//NOTUSED addAttribute(xmlAttributes, ATTRIBUTE_NAME, "");
+/*{<%=flushTag(TAG_ENTITY, xmlAttributes)%>
+}*/
+
+ boolean haveSuper = input.getSuperclasses().size() > 0;
+
+ // la liste des autres attributs
+ List<ObjectModelAttribute> attributes =
+ new ArrayList<ObjectModelAttribute>();
+
+ // Split attributes for each embeddable
+ Multimap<String, ObjectModelAttribute> embeddableAttributes =
+ splitAttributes(input, attributes);
+
+ // get all unique constraints to add
+ Multimap<String, String> uniqueContraints = getUniqueConstraints(
+ input, attributes, embeddableAttributes);
+
+ String tableName = TopiaGeneratorUtil.getDbName(input);
+ String isAbstract = BooleanUtils.toStringTrueFalse(input.isAbstract());
+ String clazzDOType = TopiaGeneratorUtil.getDOType(input, model);
+
+ // -- tag 'table'
+
+ addAttribute(xmlAttributes, ATTRIBUTE_NAME, tableName);
+ String schema = TopiaGeneratorUtil.getDbSchemaNameTagValue(input, model);
+ if (schema != null) {
+ addAttribute(xmlAttributes, ATTRIBUTE_SCHEMA, schema);
+ }
+//NOTUSED addAttribute(attributes, ATTRIBUTE_CATALOG, "");
+/*{<%=flushTag(TAG_TABLE, uniqueContraints.isEmpty(), xmlAttributes)%>
+}*/
+ if (!uniqueContraints.isEmpty()) {
+ for (String uniqueContraintName : uniqueContraints.keySet()) {
+ addAttribute(xmlAttributes, ATTRIBUTE_NAME, uniqueContraintName);
+/*{<%=flushTag(TAG_UNIQUE_CONTRAINT, xmlAttributes)%>
+}*/
+ for (String uniqueContraint :
+ uniqueContraints.get(uniqueContraintName)) {
+/*{<%=flushTag(TAG_COLUMN_NAME, uniqueContraint)%>
+}*/
+ }
+/*{<%=closeTag(TAG_UNIQUE_CONTRAINT)%>
+}*/
+ }
+/*{<%=closeTag(TAG_TABLE)%>
+}*/
+ }
+
+ // generate attributes for the entity
+
+ generateAttributes(output, input, attributes, true);
+
+/*{<%=closeTag(TAG_ENTITY)%>
+}*/
+
+ // generate embeddable if necessary
+
+ Set<String> embeddebaleNames = embeddableAttributes.keySet();
+
+ if (CollectionUtils.isNotEmpty(embeddebaleNames)) {
+
+ for (String embeddebaleName : embeddebaleNames) {
+
+ // -- tag 'embeddable'
+
+ addAttribute(xmlAttributes, ATTRIBUTE_CLASS, embeddebaleName);
+//NOTUSED addAttribute(xmlAttributes, ATTRIBUTE_ACCESS, AccessType.FIELD);
+
+/*{<%=flushTag(TAG_EMBEDDABLE, xmlAttributes)%>
+}*/
+ Collection<ObjectModelAttribute> attrs =
+ embeddableAttributes.get(embeddebaleName);
+
+ generateAttributes(output, input, attrs, false);
+
+/*{<%=closeTag(TAG_EMBEDDABLE)%>
+}*/
+ // -- tag 'embeddable'
+ }
+ }
+
+/*{<%=closeTag(TAG_ENTITY_MAPPINGS)%>
+}*/
+ }
+
+ private void generateAttributes(Writer output,
+ ObjectModelClass input,
+ Collection<ObjectModelAttribute> attributes,
+ boolean mainEntity) throws IOException {
+
+ // split attributes by their mapping type
+ Multimap<PROPERTY_TYPE, ObjectModelAttribute> attributesByType =
+ splitAttributesByType(attributes);
+
+ Map<String, String> xmlAttributes = Maps.newTreeMap();
+
+ // -- tag 'attributes'
+
+/*{<%=flushTag(TAG_ATTRIBUTES)%>
+}*/
+ if (mainEntity) {
+
+ // add id tag
+
+ addAttribute(xmlAttributes, ATTRIBUTE_NAME, TopiaEntity.TOPIA_ID);
+//NOTUSED addAttribute(xmlAttributes, ATTRIBUTE_ACCESS, AccessType.FIELD);
+/*{<%=flushTag(TAG_ID, xmlAttributes)%>
+}*/
+//NOTUSED addAttribute(xmlAttributes, ATTRIBUTE_GENERATOR, "generatorFQN");
+//NOTUSED addAttribute(xmlAttributes, ATTRIBUTE_STRATEGY, GenerationType.AUTO);
+
+/*{<%=flushTag(TAG_GENERATED_VALUE, true, xmlAttributes)%>
+<%=closeTag(TAG_ID)%>
+}*/
+ // add topiaCreateDate
+ /**
+ * <property name="topiaCreateDate" type="timestamp" node="@topiaCreateDate"/>
+ */
+ addAttribute(xmlAttributes, ATTRIBUTE_NAME, TopiaEntity.TOPIA_CREATE_DATE);
+
+ }
+
+ // generate basic attributes
+ Collection<ObjectModelAttribute> basicAttributes =
+ attributesByType.get(PROPERTY_TYPE.BASIC);
+ for (ObjectModelAttribute attribute : basicAttributes) {
+ generateBasicAttribute(output, input, attribute, xmlAttributes);
+ }
+
+ if (mainEntity) {
+
+ // add version tag
+ addAttribute(xmlAttributes, ATTRIBUTE_NAME, TopiaEntity.TOPIA_VERSION);
+//NOTUSED addAttribute(xmlAttributes, ATTRIBUTE_ACCESS, AccessType.FIELD);
+/*{<%=flushTag(TAG_VERSION, true, xmlAttributes)%>
+}*/
+ }
+ // generate many-to-one attributes
+ Collection<ObjectModelAttribute> manyToOneAttributes =
+ attributesByType.get(PROPERTY_TYPE.MANY_TO_ONE);
+ for (ObjectModelAttribute attribute : manyToOneAttributes) {
+ generateManyToOneAttribute(output, input, attribute, false);
+ }
+ // generate one-to-many attributes
+ Collection<ObjectModelAttribute> oneToManyAttributes =
+ attributesByType.get(PROPERTY_TYPE.ONE_TO_MANY);
+ for (ObjectModelAttribute attribute : oneToManyAttributes) {
+ generateOneToManyAttribute(output, input, attribute);
+ }
+
+ // generate one-to-one attributes
+ Collection<ObjectModelAttribute> oneToOneAttributes =
+ attributesByType.get(PROPERTY_TYPE.ONE_TO_ONE);
+ for (ObjectModelAttribute attribute : oneToOneAttributes) {
+ generateOneToOneAttribute(output, input, attribute);
+ }
+
+ // generate many-to-many attributes
+ Collection<ObjectModelAttribute> manyToManyAttributes =
+ attributesByType.get(PROPERTY_TYPE.MANY_TO_MANY);
+ for (ObjectModelAttribute attribute : manyToManyAttributes) {
+ generateManyToManyAttribute(output, input, attribute);
+ }
+
+ // generate element-collection attributes
+ Collection<ObjectModelAttribute> elementCollectionAttributes =
+ attributesByType.get(PROPERTY_TYPE.ELEMENT_COLLECTION);
+ for (ObjectModelAttribute attribute : elementCollectionAttributes) {
+ generateElementCollectionAttribute(output, input, attribute);
+ }
+
+/*{<%=closeTag(TAG_ATTRIBUTES)%>
+}*/
+ }
+
+ private void generateBasicAttribute(Writer output,
+ ObjectModelClass input,
+ ObjectModelAttribute attr,
+ Map<String, String> xmlAttributes) throws IOException {
+
+ Map<String, String> columnAttributes = Maps.newTreeMap();
+ String attrType = getType(attr);
+ String attrName = attr.getName();
+ String declaringElementDBName =
+ TopiaGeneratorUtil.getDbName(attr.getDeclaringElement());
+ String tableName = declaringElementDBName + "_" + attrName;
+ boolean attrIsEnumeration = attr.getClassifier() != null
+ && attr.getClassifier().isEnum();
+
+ addAttribute(xmlAttributes, ATTRIBUTE_NAME, attrName);
+ if (attrType.trim().endsWith("[]")) {
+
+ //FIXME :( (perharps should use a element-collection instead ?
+
+ } else {
+ if (TopiaGeneratorUtil.hasUniqueStereotype(attr)) {
+ addAttribute(columnAttributes, ATTRIBUTE_UNIQUE, true);
+ }
+
+ if (StringUtils.isNotEmpty(attr.getDefaultValue())) {
+ //TC-20100129 with a default value we must use the column child tag
+
+ //FIXME :(
+// String defaultValue = attr.getDefaultValue().trim();
+// columnAttributes.put(HIBERNATE_ATTRIBUTE_DEFAULT, defaultValue);
+ }
+ String sqlType = TopiaGeneratorUtil.getSqlTypeTagValue(attr);
+ if (!StringUtils.isEmpty(sqlType)) {
+
+ //FIXME :(
+// // an specific sql type was specified for the attribute, use it
+// columnAttributes.put(HIBERNATE_ATTRIBUTE_SQL_TYPE, sqlType);
+ }
+
+ String lengthTagValue = TopiaGeneratorUtil.getLengthTagValue(attr);
+ if (!StringUtils.isEmpty(lengthTagValue)) {
+
+ addAttribute(columnAttributes, ATTRIBUTE_LENGTH, lengthTagValue);
+ }
+ String notNullTagValue = TopiaGeneratorUtil.getNotNullTagValue(attr);
+ if ("true".equals(notNullTagValue)) {
+
+ // not optional
+ addAttribute(xmlAttributes, ATTRIBUTE_OPTIONAL, false);
+ addAttribute(columnAttributes, ATTRIBUTE_NULLABLE, false);
+ }
+
+ String[] columnNames = columnNamesMap.get(attrType);
+
+ // to know if specific column name mapping is given
+ boolean noSpecifiedColumn = columnNames == null || columnNames.length == 0;
+
+ if (noSpecifiedColumn) {
+
+/*{<%=flushTag(TAG_BASIC, xmlAttributes)%>
+}*/
+ String attrColumn = TopiaGeneratorUtil.getDbName(attr);
+
+ if (!attrName.equals(attrColumn)) {
+
+ // override column name
+ addAttribute(columnAttributes, ATTRIBUTE_NAME, attrColumn);
+ }
+
+ // add column if required
+
+ if (MapUtils.isNotEmpty(columnAttributes)) {
+
+/*{<%=flushTag(TAG_COLUMN, true, columnAttributes)%>
+}*/
+ }
+
+ if (attrIsEnumeration) {
+
+ // if the user tuned the model to use name instead of
+ // ordinal to store the values, we must add a clause
+ boolean useEnumerationName =
+ TopiaGeneratorUtil.hasUseEnumerationNameTagValue(
+ attr, model);
+ EnumType type = useEnumerationName ? EnumType.STRING :
+ EnumType.ORDINAL;
+/*{<%=flushTag(TAG_ENUMERATED, true, type.name())%>
+}*/
+ }
+/*{<%=closeTag(TAG_BASIC)%>
+}*/
+ } else {
+
+ // there is a colum name mapping specified, must use it
+ //FIXME :(
+ }
+ }
+ }
+
+ private void generateManyToOneAttribute(Writer output,
+ ObjectModelClass input,
+ ObjectModelAttribute attr,
+ boolean unique) throws IOException {
+
+ Map<String, String> xmlAttributes = Maps.newTreeMap();
+ Map<String, String> columnAttributes = Maps.newTreeMap();
+
+ String attrName = getName(attr);
+ addAttribute(xmlAttributes, ATTRIBUTE_NAME, attrName);
+
+ String attrColumn = TopiaGeneratorUtil.getDbName(attr);
+
+ if ("true".equals(TopiaGeneratorUtil.getNotNullTagValue(attr))) {
+
+ // not-null property
+ addAttribute(xmlAttributes, ATTRIBUTE_OPTIONAL, false);
+ addAttribute(columnAttributes, ATTRIBUTE_NULLABLE, false);
+ }
+
+ if ("true".equals(TopiaGeneratorUtil.getLazyTagValue(attr))) {
+
+ // lazy property
+ addAttribute(xmlAttributes, ATTRIBUTE_FETCH, FetchType.LAZY);
+ }
+
+ if (unique) {
+ addAttribute(columnAttributes, ATTRIBUTE_UNIQUE, true);
+ }
+
+ if (!attrName.equals(attrColumn)) {
+ addAttribute(columnAttributes, ATTRIBUTE_NAME, attrColumn);
+ }
+
+//NOTUSED addAttribute(columnAttributes, ATTRIBUTE_REFERENCE_COLUMN_NAME, TopiaEntity.TOPIA_ID);
+
+ boolean withDeleteCascade = false;
+ if (attr.isComposite() || attr.hasAssociationClass()) {
+ withDeleteCascade = true;
+ }
+
+ // Pour le test suivant, on verifie d'abord que l'attribut a un reverse.
+ // S'il n'en a pas, cela signifie qu'il ne s'agit pas d'un entite
+ // (au sens stereotype entity), donc a donc pas besoin de faire un access=field.
+ if (attr.getReverseAttribute() != null &&
+ hasUnidirectionalRelationOnAbstractType(attr.getReverseAttribute(), model)) {
+ addAttribute(xmlAttributes, ATTRIBUTE_ACCESS, AccessType.FIELD);
+ }
+
+/*{<%=flushTag(TAG_MANY_TO_ONE, xmlAttributes)%>
+}*/
+ if (MapUtils.isNotEmpty(columnAttributes)) {
+/*{<%=flushTag(TAG_JOIN_COLUMN, true, columnAttributes)%>
+}*/
+ }
+ if (withDeleteCascade) {
+/*{<%=flushTag(TAG_CASCADE)%>
+<%=flushTag(TAG_CASCADE_REMOVE, true)%>
+<%=closeTag(TAG_CASCADE)%>
+}*/
+ }
+/*{<%=closeTag(TAG_MANY_TO_ONE)%>
+}*/
+ }
+
+ private void generateOneToManyAttribute(Writer output,
+ ObjectModelClass input,
+ ObjectModelAttribute attr) throws IOException {
+ Map<String, String> xmlAttributes = Maps.newTreeMap();
+ boolean needsIndex = TopiaGeneratorUtil.hasIndexedStereotype(attr);
+ boolean isInverse = attr.getReverseAttribute().isNavigable();
+ isInverse |= hasUnidirectionalRelationOnAbstractType(attr, model);
+
+ Map<String, String> columnAttributes = Maps.newTreeMap();
+
+ String attrName = getName(attr);
+ addAttribute(xmlAttributes, ATTRIBUTE_NAME, attrName);
+
+ String reverseAttrDBName = TopiaGeneratorUtil.getReverseDbName(attr);
+ String orderBy = TopiaGeneratorUtil.getOrderByTagValue(attr);
+
+ if ("true".equals(TopiaGeneratorUtil.getLazyTagValue(attr))) {
+
+ // lazy property
+ addAttribute(xmlAttributes, ATTRIBUTE_FETCH, FetchType.LAZY);
+ }
+ if (attr.isComposite() || attr.hasAssociationClass()) {
+ addAttribute(xmlAttributes, ATTRIBUTE_ORPHAN_REMOVAL, true);
+ }
+
+ addAttribute(columnAttributes, ATTRIBUTE_NAME, reverseAttrDBName);
+
+/*{<%=flushTag(TAG_ONE_TO_MANY, xmlAttributes)%>
+}*/
+
+ if (StringUtils.isNotBlank(orderBy)) {
+ //TODO Order-by or order-column ?
+ }
+
+ if (needsIndex) {
+ } else {
+ }
+
+ if (MapUtils.isNotEmpty(columnAttributes)) {
+/*{<%=flushTag(TAG_JOIN_COLUMN, true, columnAttributes)%>
+}*/
+ }
+
+/*{<%=flushTag(TAG_CASCADE)%>
+<%=flushTag(TAG_CASCADE_ALL, true)%>
+<%=closeTag(TAG_CASCADE)%>
+}*/
+/*{<%=closeTag(TAG_ONE_TO_MANY)%>
+}*/
+ }
+
+ private void generateOneToOneAttribute(Writer output,
+ ObjectModelClass input,
+ ObjectModelAttribute attr) throws IOException {
+
+
+ // for hibernate many-to-one with unique="true" => one-to-one
+ // but if it is one-to-zero-or-one unique contraints is violated
+ // with null values
+ boolean unique = TopiaGeneratorUtil.isOneMultiplicity(attr);
+ generateManyToOneAttribute(output, input, attr, unique);
+ }
+
+ private void generateManyToManyAttribute(Writer output,
+ ObjectModelClass input,
+ ObjectModelAttribute attr) throws IOException {
+ Map<String, String> xmlAttributes = Maps.newTreeMap();
+ }
+
+ private void generateElementCollectionAttribute(Writer output,
+ ObjectModelClass input,
+ ObjectModelAttribute attr) throws IOException {
+ Map<String, String> xmlAttributes = Maps.newTreeMap();
+ }
+
+ private void addAttribute(Map<String, String> attributes,
+ String attributeName,
+ boolean attributeValue) {
+ attributes.put(attributeName, String.valueOf(attributeValue));
+ }
+
+ private void addAttribute(Map<String, String> attributes,
+ String attributeName,
+ String attributeValue) {
+ attributes.put(attributeName, attributeValue);
+ }
+
+ private void addAttribute(Map<String, String> attributes,
+ String attributeName,
+ Enum attributeValue) {
+ attributes.put(attributeName, attributeValue.name());
+ }
+
+ private void addAttributeFromTagValue(Map<String, String> attributes,
+ String attributeName, String tagValue) {
+ addAttributeFromTagValue(attributes,
+ attributeName, tagValue, null);
+ }
+
+ /**
+ * Generate hibernate xml attribute with a final space.
+ *
+ * @param attributeName
+ * @param tagValue
+ * @param defaultValue
+ * @return
+ */
+ private void addAttributeFromTagValue(Map<String, String> attributes,
+ String attributeName,
+ String tagValue,
+ String defaultValue) {
+ if (StringUtils.isNotEmpty(tagValue)) {
+ attributes.put(attributeName, tagValue);
+ } else if (defaultValue != null) {
+ attributes.put(attributeName, defaultValue);
+ }
+ }
+
+ private int xmlLevel = 0;
+
+ private String flushTag(String tagName) {
+ return flushTag(tagName, false, null, null);
+ }
+
+ private String flushTag(String tagName, boolean autoClose) {
+ return flushTag(tagName, autoClose, null, null);
+ }
+
+ private String flushTag(String tagName, String textValue) {
+ return flushTag(tagName, false, null, textValue);
+ }
+
+ private String flushTag(String tagName, boolean autoClose,
+ String textValue) {
+ return flushTag(tagName, autoClose, null, textValue);
+ }
+
+ private String flushTag(String tagName,
+ Map<String, String> attributes,
+ String textValue) {
+ return flushTag(tagName, false, attributes, textValue);
+ }
+
+ private String flushTag(String tagName,
+ boolean autoClose,
+ Map<String, String> attributes) {
+ return flushTag(tagName, autoClose, attributes, null);
+ }
+
+ private String flushTag(String tagName,
+ Map<String, String> attributes) {
+ return flushTag(tagName, false, attributes, null);
+ }
+
+
+ private String flushTag(String tagName,
+ boolean autoClose,
+ Map<String, String> attributes,
+ String textValue) {
+
+ if (log.isInfoEnabled()) {
+ log.info("flushTag <" + tagName + "> : level " + xmlLevel);
+ }
+ StringBuilder builder = new StringBuilder(getXmlPrefix());
+ xmlLevel++;
+ builder.append("<").append(tagName);
+ if (MapUtils.isNotEmpty(attributes)) {
+ for (Map.Entry<String, String> e : attributes.entrySet()) {
+ String attrName = e.getKey();
+ String attrValue = e.getValue();
+ builder.append(' ');
+ builder.append(attrName);
+ builder.append("=\"");
+ builder.append(attrValue);
+ builder.append('\"');
+ }
+ attributes.clear();
+ }
+ if (autoClose) {
+ builder.append("/>");
+ xmlLevel--;
+ } else {
+ builder.append(">");
+ if (textValue != null) {
+ builder.append(textValue);
+ }
+ }
+ return builder.toString();
+ }
+
+ private String closeStrictTag(String tagName) {
+ xmlLevel--;
+ String result = "</" + tagName + ">";
+ if (log.isInfoEnabled()) {
+ log.info("closeStrictTag <" + tagName + "> : level " + xmlLevel);
+ }
+ return result;
+ }
+
+ private String closeTag(String tagName) {
+ xmlLevel--;
+ String result = getXmlPrefix() + "</" + tagName + ">";
+ if (log.isInfoEnabled()) {
+ log.info("closeTag <" + tagName + "> : level " + xmlLevel);
+ }
+ return result;
+ }
+
+ private String getXmlPrefix() {
+ String result = Strings.padStart("", xmlLevel * 2, ' ');
+ return result;
+ }
+
+
+ public enum PROPERTY_TYPE {
+ BASIC,
+ MANY_TO_ONE,
+ MANY_TO_MANY,
+ ONE_TO_ONE,
+ ONE_TO_MANY,
+ ELEMENT_COLLECTION
+ }
+
+ private Multimap<PROPERTY_TYPE, ObjectModelAttribute> splitAttributesByType(
+ Collection<ObjectModelAttribute> attributes) {
+
+ Multimap<PROPERTY_TYPE, ObjectModelAttribute> result =
+ LinkedHashMultimap.create();
+
+ for (ObjectModelAttribute attr : attributes) {
+ ObjectModelAttribute reverse = attr.getReverseAttribute();
+
+ // pour les asso quoi qu'il arrive il faut les lier des 2 cotes
+ // pour pouvoir supprimer en cascade l'asso lors de la suppression
+ // d'un des cotes
+ if (attr.isNavigable()
+ || hasUnidirectionalRelationOnAbstractType(reverse, model)
+ || attr.hasAssociationClass()) {
+ if (!TopiaGeneratorUtil.isNMultiplicity(attr)) {
+ if (attr.getClassifier() != null && TopiaGeneratorUtil.isEntity(attr.getClassifier())) {
+ if (TopiaGeneratorUtil.isNMultiplicity(attr.getReverseMaxMultiplicity()) && !attr.hasAssociationClass()) {
+
+ result.put(PROPERTY_TYPE.MANY_TO_ONE, attr);
+ } else {
+ result.put(PROPERTY_TYPE.ONE_TO_ONE, attr);
+ }
+ } else {
+ result.put(PROPERTY_TYPE.BASIC, attr);
+ }
+ } else {
+ if (attr.getClassifier() != null && TopiaGeneratorUtil.isEntity(attr.getClassifier())) {
+ if (TopiaGeneratorUtil.isNMultiplicity(attr.getReverseMaxMultiplicity()) && !attr.hasAssociationClass()) {
+ result.put(PROPERTY_TYPE.MANY_TO_MANY, attr);
+ } else {
+ result.put(PROPERTY_TYPE.ONE_TO_MANY, attr);
+ }
+ } else {
+ result.put(PROPERTY_TYPE.ELEMENT_COLLECTION, attr);
+ }
+ }
+ }
+ }
+
+ return result;
+ }
+
+ private Multimap<String, String> getUniqueConstraints(ObjectModelClass input,
+ List<ObjectModelAttribute> attributes,
+ Multimap<String, ObjectModelAttribute> embeddableAttributes) {
+ Multimap<String, String> result = ArrayListMultimap.create();
+ return result;
+ }
+
+ protected String getName(ObjectModelAttribute attr) {
+ return getName(attr, false);
+ }
+
+ protected String getName(ObjectModelAttribute attr, boolean isAssoc) {
+ String result = Introspector.decapitalize(attr.getName());
+ if (attr.hasAssociationClass() && !isAssoc) {
+ result = TopiaGeneratorUtil.getAssocAttrName(attr);
+ }
+ return result;
+ }
+
+ protected String getType(ObjectModelAttribute attr) {
+ return getType(attr, false);
+ }
+
+ protected String getType(ObjectModelAttribute attr, boolean isAssoc) {
+ String type = attr.getType();
+ String attrType = TopiaGeneratorUtil.getTypeTagValue(attr);
+ if (StringUtils.isNotEmpty(attrType)) {
+
+ // tag value detected of the attribute
+ type = attrType;
+ } else {
+
+ //FIXME :(
+ String modelType = model.getTagValue(type);
+ if (StringUtils.isNotEmpty(modelType)) {
+
+ // tag value detected of the model
+
+ //TODO tchemit 20100507 Explain What todes it do ? Dont understand the story of columnNamesMap
+ int bracketIndex = modelType.indexOf('(');
+ if (bracketIndex != -1) {
+ type = modelType.substring(0, bracketIndex);
+ int bracketEndIndex = modelType.indexOf(')', bracketIndex + 1);
+ String colmunList;
+ if (bracketEndIndex != -1) {
+ colmunList = modelType.substring(bracketIndex + 1, bracketEndIndex);
+ } else {
+ colmunList = modelType.substring(bracketIndex);
+ }
+ columnNamesMap.put(type, colmunList.split(","));
+ } else {
+ type = modelType;
+ }
+ }
+ }
+ if (attr.hasAssociationClass() && !isAssoc) {
+ type = attr.getAssociationClass().getQualifiedName();
+ }
+ return TopiaGeneratorUtil.getDOType(type, model);
+ }
+}
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 2012-05-09 16:07:09 UTC (rev 2454)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/TopiaMetaTransformer.java 2012-05-09 16:08:01 UTC (rev 2455)
@@ -67,7 +67,8 @@
// DAOImplTransformer.class,
// DAOAbstractTransformer.class,
DAOHelperTransformer.class,
- EntityHibernateMappingGenerator.class
+ EntityHibernateMappingGenerator.class,
+ EntityJPAMappingGenerator.class
);
}
Modified: trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/TopiaTckTestSuite.java
===================================================================
--- trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/TopiaTckTestSuite.java 2012-05-09 16:07:09 UTC (rev 2454)
+++ trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/TopiaTckTestSuite.java 2012-05-09 16:08:01 UTC (rev 2455)
@@ -3,16 +3,16 @@
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.nuiton.topia.TopiaContextFactoryTest;
-import org.nuiton.topia.tck.ano1882.DAOAbstractTransformerTest;
-import org.nuiton.topia.tck.ano1991.TopiaQueryTest;
-import org.nuiton.topia.tck.evo1912.EntityDTOTransformerTest;
-import org.nuiton.topia.tck.framework.TopiaContextReplicateTest;
-import org.nuiton.topia.tck.framework.TopiaUtilTest;
-import org.nuiton.topia.tck.generator.TopiaTestCase;
+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.legacy.generator.TopiaTestCase;
import org.nuiton.topia.tck.it.EnumTest;
import org.nuiton.topia.tck.it.deletetest.DeleteEntityTest;
-import org.nuiton.topia.tck.persistence.EntityVisitorExportXmlTest;
-import org.nuiton.topia.tck.persistence.NaturalIdTest;
+import org.nuiton.topia.tck.legacy.persistence.EntityVisitorExportXmlTest;
+import org.nuiton.topia.tck.legacy.persistence.NaturalIdTest;
/**
* @author Arnaud Thimel <thimel(a)codelutin.com>
Modified: trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/legacy/ano1882/DAOAbstractTransformerTest.java
===================================================================
--- trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/ano1882/DAOAbstractTransformerTest.java 2012-05-09 15:48:05 UTC (rev 2453)
+++ trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/legacy/ano1882/DAOAbstractTransformerTest.java 2012-05-09 16:08:01 UTC (rev 2455)
@@ -22,7 +22,7 @@
* <http://www.gnu.org/licenses/lgpl-3.0.html>.
* #L%
*/
-package org.nuiton.topia.tck.ano1882;
+package org.nuiton.topia.tck.legacy.ano1882;
import org.junit.Rule;
import org.junit.Test;
Modified: 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/ano1991/TopiaQueryTest.java 2012-05-09 15:48:05 UTC (rev 2453)
+++ trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/legacy/ano1991/TopiaQueryTest.java 2012-05-09 16:08:01 UTC (rev 2455)
@@ -22,7 +22,7 @@
* <http://www.gnu.org/licenses/lgpl-3.0.html>.
* #L%
*/
-package org.nuiton.topia.tck.ano1991;
+package org.nuiton.topia.tck.legacy.ano1991;
import org.junit.Assert;
import org.junit.Rule;
Modified: trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/legacy/evo1912/EntityDTOTransformerTest.java
===================================================================
--- trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/evo1912/EntityDTOTransformerTest.java 2012-05-09 15:48:05 UTC (rev 2453)
+++ trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/legacy/evo1912/EntityDTOTransformerTest.java 2012-05-09 16:08:01 UTC (rev 2455)
@@ -22,7 +22,7 @@
* <http://www.gnu.org/licenses/lgpl-3.0.html>.
* #L%
*/
-package org.nuiton.topia.tck.evo1912;
+package org.nuiton.topia.tck.legacy.evo1912;
import org.junit.Assert;
import org.junit.Test;
Modified: trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/legacy/framework/TopiaContextReplicateTest.java
===================================================================
--- trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/framework/TopiaContextReplicateTest.java 2012-05-09 15:48:05 UTC (rev 2453)
+++ trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/legacy/framework/TopiaContextReplicateTest.java 2012-05-09 16:08:01 UTC (rev 2455)
@@ -22,7 +22,7 @@
* <http://www.gnu.org/licenses/lgpl-3.0.html>.
* #L%
*/
-package org.nuiton.topia.tck.framework;
+package org.nuiton.topia.tck.legacy.framework;
import org.junit.Assert;
import org.junit.Rule;
Modified: trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/legacy/framework/TopiaUtilTest.java
===================================================================
--- trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/framework/TopiaUtilTest.java 2012-05-09 15:48:05 UTC (rev 2453)
+++ trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/legacy/framework/TopiaUtilTest.java 2012-05-09 16:08:01 UTC (rev 2455)
@@ -23,7 +23,7 @@
* #L%
*/
-package org.nuiton.topia.tck.framework;
+package org.nuiton.topia.tck.legacy.framework;
import org.junit.Rule;
import org.junit.Test;
Modified: trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/legacy/generator/TopiaTestCase.java
===================================================================
--- trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/generator/TopiaTestCase.java 2012-05-09 15:48:05 UTC (rev 2453)
+++ trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/legacy/generator/TopiaTestCase.java 2012-05-09 16:08:01 UTC (rev 2455)
@@ -23,7 +23,7 @@
* #L%
*/
-package org.nuiton.topia.tck.generator;
+package org.nuiton.topia.tck.legacy.generator;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
Modified: trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/legacy/persistence/EntityVisitorExportXmlTest.java
===================================================================
--- trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/persistence/EntityVisitorExportXmlTest.java 2012-05-09 15:48:05 UTC (rev 2453)
+++ trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/legacy/persistence/EntityVisitorExportXmlTest.java 2012-05-09 16:08:01 UTC (rev 2455)
@@ -23,7 +23,7 @@
* #L%
*/
-package org.nuiton.topia.tck.persistence;
+package org.nuiton.topia.tck.legacy.persistence;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
Modified: trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/legacy/persistence/ExportXMLVisitor.java
===================================================================
--- trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/persistence/ExportXMLVisitor.java 2012-05-09 15:48:05 UTC (rev 2453)
+++ trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/legacy/persistence/ExportXMLVisitor.java 2012-05-09 16:08:01 UTC (rev 2455)
@@ -23,7 +23,7 @@
* #L%
*/
-package org.nuiton.topia.tck.persistence;
+package org.nuiton.topia.tck.legacy.persistence;
import org.apache.commons.logging.Log;
Modified: trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/legacy/persistence/NaturalIdTest.java
===================================================================
--- trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/persistence/NaturalIdTest.java 2012-05-09 15:48:05 UTC (rev 2453)
+++ trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/legacy/persistence/NaturalIdTest.java 2012-05-09 16:08:01 UTC (rev 2455)
@@ -23,7 +23,7 @@
* #L%
*/
-package org.nuiton.topia.tck.persistence;
+package org.nuiton.topia.tck.legacy.persistence;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
Added: trunk/topia-persistence-tck/src/main/xmi/topia-tck-mapping.properties
===================================================================
--- trunk/topia-persistence-tck/src/main/xmi/topia-tck-mapping.properties (rev 0)
+++ trunk/topia-persistence-tck/src/main/xmi/topia-tck-mapping.properties 2012-05-09 16:08:01 UTC (rev 2455)
@@ -0,0 +1,24 @@
+###
+# #%L
+# ToPIA :: Persistence
+#
+# $Id: topiatest.properties 2445 2012-05-09 13:48:32Z athimel $
+# $HeadURL: http://svn.nuiton.org/svn/topia/trunk/topia-persistence-tck/src/main/xmi/to… $
+# %%
+# Copyright (C) 2004 - 2010 CodeLutin
+# %%
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Lesser General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Lesser Public License for more details.
+#
+# You should have received a copy of the GNU General Lesser Public
+# License along with this program. If not, see
+# <http://www.gnu.org/licenses/lgpl-3.0.html>.
+# #L%
+###
Added: trunk/topia-persistence-tck/src/main/xmi/topia-tck-mapping.zargo
===================================================================
(Binary files differ)
Property changes on: trunk/topia-persistence-tck/src/main/xmi/topia-tck-mapping.zargo
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
1
0
09 May '12
Author: athimel
Date: 2012-05-09 18:07:09 +0200 (Wed, 09 May 2012)
New Revision: 2454
Url: http://nuiton.org/repositories/revision/topia/2454
Log:
Fix TopiaPersistenceProvider common impl
Added:
trunk/topia-persistence-tck/src/main/resources/TopiaConnectionProviderHardcoded.properties
trunk/topia-persistence-tck/src/main/resources/TopiaContextImpl.properties
trunk/topia-persistence-tck/src/main/resources/log4j.properties
Removed:
trunk/topia-persistence-tck/src/test/resources/TopiaConnectionProviderHardcoded.properties
trunk/topia-persistence-tck/src/test/resources/TopiaContextImpl.properties
trunk/topia-persistence-tck/src/test/resources/log4j.properties
Modified:
trunk/topia-persistence-hibernate/src/main/java/org/nuiton/topia/persistence/hibernate/TopiaHibernatePersistenceProvider.java
trunk/topia-persistence-hibernate/src/main/resources/META-INF/services/javax.persistence.spi.PersistenceProvider
trunk/topia-persistence-hibernate/src/test/java/org/nuiton/topia/tck/TopiaTckHibernateTestSuite.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaContextImpl.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaContextImplementor.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaPersistenceProvider.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-09 15:48:05 UTC (rev 2453)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaContextImpl.java 2012-05-09 16:07:09 UTC (rev 2454)
@@ -94,6 +94,7 @@
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
+import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Properties;
@@ -197,7 +198,7 @@
protected TopiaFiresSupport firesSupport = new TopiaFiresSupport();
/** Liste des classes perssitance */
- protected List<Class<?>> persistenceClasses = new ArrayList<Class<?>>();
+ protected Set<Class<?>> persistenceClasses = new LinkedHashSet<Class<?>>();
/** Default constructor, useful for tests. */
protected TopiaContextImpl() {
@@ -1426,7 +1427,7 @@
}
@Override
- public List<Class<?>> getPersistenceClasses() {
+ public Set<Class<?>> getPersistenceClasses() {
return persistenceClasses;
}
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaContextImplementor.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaContextImplementor.java 2012-05-09 15:48:05 UTC (rev 2453)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaContextImplementor.java 2012-05-09 16:07:09 UTC (rev 2454)
@@ -137,6 +137,7 @@
Map<String, TopiaService> getServices();
- List<Class<?>> getPersistenceClasses();
+ Set<Class<?>> getPersistenceClasses();
+
} //TopiaContextImplementor
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaPersistenceProvider.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaPersistenceProvider.java 2012-05-09 15:48:05 UTC (rev 2453)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaPersistenceProvider.java 2012-05-09 16:07:09 UTC (rev 2454)
@@ -24,6 +24,8 @@
@Override
public EntityManagerFactory createEntityManagerFactory(String emName, Map map) {
System.out.println("createEntityManagerFactory " + emName);
+
+ EntityManagerFactory result = null;
if ("topia".equals(emName)) {
// Use PersistenceProvider of the underlying JPA library
@@ -38,9 +40,9 @@
throw new TopiaRuntimeException("topia.entities list must be provided");
}
- configureSpecific(emName, map, entityClasses);
+ result = configureSpecific(emName, map, entityClasses);
}
- return null;
+ return result;
}
@Override
Modified: trunk/topia-persistence-hibernate/src/main/java/org/nuiton/topia/persistence/hibernate/TopiaHibernatePersistenceProvider.java
===================================================================
--- trunk/topia-persistence-hibernate/src/main/java/org/nuiton/topia/persistence/hibernate/TopiaHibernatePersistenceProvider.java 2012-05-09 15:48:05 UTC (rev 2453)
+++ trunk/topia-persistence-hibernate/src/main/java/org/nuiton/topia/persistence/hibernate/TopiaHibernatePersistenceProvider.java 2012-05-09 16:07:09 UTC (rev 2454)
@@ -28,7 +28,7 @@
map.put("hibernate.dialect", "org.hibernate.dialect.H2Dialect");
map.put("hibernate.hbm2ddl.auto", "create-drop");
- map.put("hibernate.show_sql", "true");
+ map.put("hibernate.show_sql", "false");
// map.put("hibernate.connection.provider_class", "org.nuiton.topia.framework.TopiaConnectionProviderHardCoded");
// Set<Class<?>> entities = new HashSet<Class<?>>();
@@ -76,6 +76,10 @@
metadata.setHbmfiles(entitiesHbmFiles);
Ejb3Configuration configured = cfg.configure(metadata, map);
- return configured != null ? configured.buildEntityManagerFactory() : null;
+ EntityManagerFactory result = null;
+ if (configured != null) {
+ result = configured.buildEntityManagerFactory();
+ }
+ return result;
}
}
Modified: trunk/topia-persistence-hibernate/src/main/resources/META-INF/services/javax.persistence.spi.PersistenceProvider
===================================================================
--- trunk/topia-persistence-hibernate/src/main/resources/META-INF/services/javax.persistence.spi.PersistenceProvider 2012-05-09 15:48:05 UTC (rev 2453)
+++ trunk/topia-persistence-hibernate/src/main/resources/META-INF/services/javax.persistence.spi.PersistenceProvider 2012-05-09 16:07:09 UTC (rev 2454)
@@ -1 +1 @@
-org.nuiton.topia.framework.TopiaHibernatePersistenceProvider
+org.nuiton.topia.persistence.hibernate.TopiaHibernatePersistenceProvider
Modified: trunk/topia-persistence-hibernate/src/test/java/org/nuiton/topia/tck/TopiaTckHibernateTestSuite.java
===================================================================
--- trunk/topia-persistence-hibernate/src/test/java/org/nuiton/topia/tck/TopiaTckHibernateTestSuite.java 2012-05-09 15:48:05 UTC (rev 2453)
+++ trunk/topia-persistence-hibernate/src/test/java/org/nuiton/topia/tck/TopiaTckHibernateTestSuite.java 2012-05-09 16:07:09 UTC (rev 2454)
@@ -1,6 +1,8 @@
package org.nuiton.topia.tck;
+import org.junit.runners.Suite;
import org.nuiton.topia.tck.TopiaTckTestSuite;
+import org.nuiton.topia.tck.ano1882.DAOAbstractTransformerTest;
/**
* Do not remove event if empty : this class represents the TCK IT tests
Copied: trunk/topia-persistence-tck/src/main/resources/TopiaConnectionProviderHardcoded.properties (from rev 2453, trunk/topia-persistence-tck/src/test/resources/TopiaConnectionProviderHardcoded.properties)
===================================================================
--- trunk/topia-persistence-tck/src/main/resources/TopiaConnectionProviderHardcoded.properties (rev 0)
+++ trunk/topia-persistence-tck/src/main/resources/TopiaConnectionProviderHardcoded.properties 2012-05-09 16:07:09 UTC (rev 2454)
@@ -0,0 +1,35 @@
+###
+# #%L
+# ToPIA :: Persistence
+#
+# $Id$
+# $HeadURL$
+# %%
+# Copyright (C) 2004 - 2010 CodeLutin
+# %%
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Lesser General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Lesser Public License for more details.
+#
+# You should have received a copy of the GNU General Lesser Public
+# License along with this program. If not, see
+# <http://www.gnu.org/licenses/lgpl-3.0.html>.
+# #L%
+###
+# Proprietes par defaut pour une base de donnees de type H2
+hibernate.hbm2ddl.auto=update
+hibernate.show_sql=false
+
+hibernate.dialect=org.hibernate.dialect.H2Dialect
+hibernate.connection.username=sa
+hibernate.connection.password=
+hibernate.connection.driver_class=org.h2.Driver
+hibernate.connection.provider_class=org.nuiton.topia.framework.TopiaConnectionProviderHardCoded
+# tchemit 2010-11-28 : comment this line, each test must define his own db path
+#hibernate.connection.url=jdbc:h2:file:target/surefire-workdir/h2data
\ No newline at end of file
Property changes on: trunk/topia-persistence-tck/src/main/resources/TopiaConnectionProviderHardcoded.properties
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Copied: trunk/topia-persistence-tck/src/main/resources/TopiaContextImpl.properties (from rev 2453, trunk/topia-persistence-tck/src/test/resources/TopiaContextImpl.properties)
===================================================================
--- trunk/topia-persistence-tck/src/main/resources/TopiaContextImpl.properties (rev 0)
+++ trunk/topia-persistence-tck/src/main/resources/TopiaContextImpl.properties 2012-05-09 16:07:09 UTC (rev 2454)
@@ -0,0 +1,34 @@
+###
+# #%L
+# ToPIA :: Persistence
+#
+# $Id$
+# $HeadURL$
+# %%
+# Copyright (C) 2004 - 2010 CodeLutin
+# %%
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Lesser General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Lesser Public License for more details.
+#
+# You should have received a copy of the GNU General Lesser Public
+# License along with this program. If not, see
+# <http://www.gnu.org/licenses/lgpl-3.0.html>.
+# #L%
+###
+# Proprietes par defaut pour une base de donnees de type H2
+hibernate.hbm2ddl.auto=update
+hibernate.show_sql=false
+
+hibernate.dialect=org.hibernate.dialect.H2Dialect
+hibernate.connection.username=sa
+hibernate.connection.password=
+hibernate.connection.driver_class=org.h2.Driver
+# tchemit 2010-11-28 : comment this line, each test must define his own db path
+#hibernate.connection.url=jdbc:h2:file:target/surefire-workdir/h2data
\ No newline at end of file
Property changes on: trunk/topia-persistence-tck/src/main/resources/TopiaContextImpl.properties
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Copied: trunk/topia-persistence-tck/src/main/resources/log4j.properties (from rev 2453, trunk/topia-persistence-tck/src/test/resources/log4j.properties)
===================================================================
--- trunk/topia-persistence-tck/src/main/resources/log4j.properties (rev 0)
+++ trunk/topia-persistence-tck/src/main/resources/log4j.properties 2012-05-09 16:07:09 UTC (rev 2454)
@@ -0,0 +1,36 @@
+###
+# #%L
+# ToPIA :: Persistence
+#
+# $Id$
+# $HeadURL$
+# %%
+# Copyright (C) 2004 - 2010 CodeLutin
+# %%
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Lesser General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Lesser Public License for more details.
+#
+# You should have received a copy of the GNU General Lesser Public
+# License along with this program. If not, see
+# <http://www.gnu.org/licenses/lgpl-3.0.html>.
+# #L%
+###
+#\u00a0This log is used to display trace in generation
+
+# Global logging configuration
+log4j.rootLogger=WARN, stdout
+# Console output...
+log4j.appender.stdout=org.apache.log4j.ConsoleAppender
+log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
+log4j.appender.stdout.layout.ConversionPattern=%5p [%t] (%F:%L) %M - %m%n
+# package level
+log4j.logger.org.nuiton.topia=INFO
+#log4j.logger.org.nuiton.topiatest=DEBUG
+log4j.logger.org.nuiton.topia.persistence.util=INFO
Property changes on: trunk/topia-persistence-tck/src/main/resources/log4j.properties
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Deleted: trunk/topia-persistence-tck/src/test/resources/TopiaConnectionProviderHardcoded.properties
===================================================================
--- trunk/topia-persistence-tck/src/test/resources/TopiaConnectionProviderHardcoded.properties 2012-05-09 15:48:05 UTC (rev 2453)
+++ trunk/topia-persistence-tck/src/test/resources/TopiaConnectionProviderHardcoded.properties 2012-05-09 16:07:09 UTC (rev 2454)
@@ -1,35 +0,0 @@
-###
-# #%L
-# ToPIA :: Persistence
-#
-# $Id$
-# $HeadURL$
-# %%
-# Copyright (C) 2004 - 2010 CodeLutin
-# %%
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU Lesser General Public License as
-# published by the Free Software Foundation, either version 3 of the
-# License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Lesser Public License for more details.
-#
-# You should have received a copy of the GNU General Lesser Public
-# License along with this program. If not, see
-# <http://www.gnu.org/licenses/lgpl-3.0.html>.
-# #L%
-###
-# Proprietes par defaut pour une base de donnees de type H2
-hibernate.hbm2ddl.auto=update
-hibernate.show_sql=false
-
-hibernate.dialect=org.hibernate.dialect.H2Dialect
-hibernate.connection.username=sa
-hibernate.connection.password=
-hibernate.connection.driver_class=org.h2.Driver
-hibernate.connection.provider_class=org.nuiton.topia.framework.TopiaConnectionProviderHardCoded
-# tchemit 2010-11-28 : comment this line, each test must define his own db path
-#hibernate.connection.url=jdbc:h2:file:target/surefire-workdir/h2data
\ No newline at end of file
Deleted: trunk/topia-persistence-tck/src/test/resources/TopiaContextImpl.properties
===================================================================
--- trunk/topia-persistence-tck/src/test/resources/TopiaContextImpl.properties 2012-05-09 15:48:05 UTC (rev 2453)
+++ trunk/topia-persistence-tck/src/test/resources/TopiaContextImpl.properties 2012-05-09 16:07:09 UTC (rev 2454)
@@ -1,34 +0,0 @@
-###
-# #%L
-# ToPIA :: Persistence
-#
-# $Id$
-# $HeadURL$
-# %%
-# Copyright (C) 2004 - 2010 CodeLutin
-# %%
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU Lesser General Public License as
-# published by the Free Software Foundation, either version 3 of the
-# License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Lesser Public License for more details.
-#
-# You should have received a copy of the GNU General Lesser Public
-# License along with this program. If not, see
-# <http://www.gnu.org/licenses/lgpl-3.0.html>.
-# #L%
-###
-# Proprietes par defaut pour une base de donnees de type H2
-hibernate.hbm2ddl.auto=update
-hibernate.show_sql=false
-
-hibernate.dialect=org.hibernate.dialect.H2Dialect
-hibernate.connection.username=sa
-hibernate.connection.password=
-hibernate.connection.driver_class=org.h2.Driver
-# tchemit 2010-11-28 : comment this line, each test must define his own db path
-#hibernate.connection.url=jdbc:h2:file:target/surefire-workdir/h2data
\ No newline at end of file
Deleted: trunk/topia-persistence-tck/src/test/resources/log4j.properties
===================================================================
--- trunk/topia-persistence-tck/src/test/resources/log4j.properties 2012-05-09 15:48:05 UTC (rev 2453)
+++ trunk/topia-persistence-tck/src/test/resources/log4j.properties 2012-05-09 16:07:09 UTC (rev 2454)
@@ -1,36 +0,0 @@
-###
-# #%L
-# ToPIA :: Persistence
-#
-# $Id$
-# $HeadURL$
-# %%
-# Copyright (C) 2004 - 2010 CodeLutin
-# %%
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU Lesser General Public License as
-# published by the Free Software Foundation, either version 3 of the
-# License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Lesser Public License for more details.
-#
-# You should have received a copy of the GNU General Lesser Public
-# License along with this program. If not, see
-# <http://www.gnu.org/licenses/lgpl-3.0.html>.
-# #L%
-###
-#\u00a0This log is used to display trace in generation
-
-# Global logging configuration
-log4j.rootLogger=WARN, stdout
-# Console output...
-log4j.appender.stdout=org.apache.log4j.ConsoleAppender
-log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
-log4j.appender.stdout.layout.ConversionPattern=%5p [%t] (%F:%L) %M - %m%n
-# package level
-log4j.logger.org.nuiton.topia=INFO
-#log4j.logger.org.nuiton.topiatest=DEBUG
-log4j.logger.org.nuiton.topia.persistence.util=INFO
1
0
r2453 - in trunk: topia-persistence-hibernate/src/test/java/org/nuiton/topia topia-persistence-hibernate/src/test/java/org/nuiton/topia/tck topia-persistence-tck/src/main/java/org/nuiton/topia/tck topia-persistence-tck/src/main/java/org/nuiton/topia/tck/it topia-persistence-tck/src/test/java/org/nuiton
by athimel@users.nuiton.org 09 May '12
by athimel@users.nuiton.org 09 May '12
09 May '12
Author: athimel
Date: 2012-05-09 17:48:05 +0200 (Wed, 09 May 2012)
New Revision: 2453
Url: http://nuiton.org/repositories/revision/topia/2453
Log:
Add all tests in TCK test suite
Added:
trunk/topia-persistence-hibernate/src/test/java/org/nuiton/topia/tck/TopiaTckHibernateTestSuite.java
trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/TopiaTckTestSuite.java
Removed:
trunk/topia-persistence-hibernate/src/test/java/org/nuiton/topia/persistence/
trunk/topia-persistence-hibernate/src/test/java/org/nuiton/topia/tck/it/
trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/it/TopiaTckItTestSuite.java
trunk/topia-persistence-tck/src/test/java/org/nuiton/topiatest/
Copied: trunk/topia-persistence-hibernate/src/test/java/org/nuiton/topia/tck/TopiaTckHibernateTestSuite.java (from rev 2452, trunk/topia-persistence-hibernate/src/test/java/org/nuiton/topia/tck/it/TopiaTckItHibernateTestSuite.java)
===================================================================
--- trunk/topia-persistence-hibernate/src/test/java/org/nuiton/topia/tck/TopiaTckHibernateTestSuite.java (rev 0)
+++ trunk/topia-persistence-hibernate/src/test/java/org/nuiton/topia/tck/TopiaTckHibernateTestSuite.java 2012-05-09 15:48:05 UTC (rev 2453)
@@ -0,0 +1,12 @@
+package org.nuiton.topia.tck;
+
+import org.nuiton.topia.tck.TopiaTckTestSuite;
+
+/**
+ * Do not remove event if empty : this class represents the TCK IT tests
+ * for topia-persistence-hibernate module
+ *
+ * @author Arnaud Thimel <thimel(a)codelutin.com>
+ */
+public class TopiaTckHibernateTestSuite extends TopiaTckTestSuite {
+}
Copied: trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/TopiaTckTestSuite.java (from rev 2452, trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/it/TopiaTckItTestSuite.java)
===================================================================
--- trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/TopiaTckTestSuite.java (rev 0)
+++ trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/TopiaTckTestSuite.java 2012-05-09 15:48:05 UTC (rev 2453)
@@ -0,0 +1,35 @@
+package org.nuiton.topia.tck;
+
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+import org.nuiton.topia.TopiaContextFactoryTest;
+import org.nuiton.topia.tck.ano1882.DAOAbstractTransformerTest;
+import org.nuiton.topia.tck.ano1991.TopiaQueryTest;
+import org.nuiton.topia.tck.evo1912.EntityDTOTransformerTest;
+import org.nuiton.topia.tck.framework.TopiaContextReplicateTest;
+import org.nuiton.topia.tck.framework.TopiaUtilTest;
+import org.nuiton.topia.tck.generator.TopiaTestCase;
+import org.nuiton.topia.tck.it.EnumTest;
+import org.nuiton.topia.tck.it.deletetest.DeleteEntityTest;
+import org.nuiton.topia.tck.persistence.EntityVisitorExportXmlTest;
+import org.nuiton.topia.tck.persistence.NaturalIdTest;
+
+/**
+ * @author Arnaud Thimel <thimel(a)codelutin.com>
+ */
+(a)RunWith(Suite.class)
+(a)Suite.SuiteClasses({
+ DAOAbstractTransformerTest.class,
+ TopiaQueryTest.class,
+ EntityDTOTransformerTest.class,
+ TopiaContextReplicateTest.class,
+ TopiaUtilTest.class,
+ TopiaTestCase.class,
+ DeleteEntityTest.class,
+ EntityVisitorExportXmlTest.class,
+ NaturalIdTest.class,
+ TopiaContextFactoryTest.class,
+ EnumTest.class}) // TODO AThimel 09/05/2012 Add all TCK IT tests
+public abstract class TopiaTckTestSuite {
+
+}
Deleted: trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/it/TopiaTckItTestSuite.java
===================================================================
--- trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/it/TopiaTckItTestSuite.java 2012-05-09 15:07:53 UTC (rev 2452)
+++ trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/it/TopiaTckItTestSuite.java 2012-05-09 15:48:05 UTC (rev 2453)
@@ -1,13 +0,0 @@
-package org.nuiton.topia.tck.it;
-
-import org.junit.runner.RunWith;
-import org.junit.runners.Suite;
-
-/**
- * @author Arnaud Thimel <thimel(a)codelutin.com>
- */
-(a)RunWith(Suite.class)
-(a)Suite.SuiteClasses({EnumTest.class}) // TODO AThimel 09/05/2012 Add all TCK IT tests
-public abstract class TopiaTckItTestSuite {
-
-}
1
0
Author: athimel
Date: 2012-05-09 17:07:53 +0200 (Wed, 09 May 2012)
New Revision: 2452
Url: http://nuiton.org/repositories/revision/topia/2452
Log:
Database dependent tests now in src/main/java of t-p-tck
Added:
trunk/topia-persistence-hibernate/src/test/java/org/nuiton/topia/tck/
trunk/topia-persistence-hibernate/src/test/java/org/nuiton/topia/tck/it/
trunk/topia-persistence-hibernate/src/test/java/org/nuiton/topia/tck/it/TopiaTckItHibernateTestSuite.java
trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/TopiaContextFactoryTest.java
trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/ano1882/
trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/ano1991/
trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/evo1912/
trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/framework/
trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/framework/TopiaContextReplicateTest.java
trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/framework/TopiaUtilTest.java
trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/generator/
trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/generator/TopiaTestCase.java
trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/it/TopiaTckItTestSuite.java
trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/persistence/
trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/persistence/EntityVisitorExportXmlTest.java
trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/persistence/ExportXMLVisitor.java
trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/persistence/NaturalIdTest.java
Removed:
trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/TopiaContextFactoryTest.java
trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/framework/TopiaContextReplicateTest.java
trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/framework/TopiaUtilTest.java
trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/generator/
trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/persistence/EntityVisitorExportXmlTest.java
trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/persistence/ExportXMLVisitor.java
trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/persistence/NaturalIdTest.java
trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/test/ano1882/
trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/test/ano1991/
trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/test/evo1912/
Modified:
trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/ano1882/DAOAbstractTransformerTest.java
trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/ano1991/TopiaQueryTest.java
trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/evo1912/EntityDTOTransformerTest.java
trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/framework/TopiaQueryTest.java
Added: trunk/topia-persistence-hibernate/src/test/java/org/nuiton/topia/tck/it/TopiaTckItHibernateTestSuite.java
===================================================================
--- trunk/topia-persistence-hibernate/src/test/java/org/nuiton/topia/tck/it/TopiaTckItHibernateTestSuite.java (rev 0)
+++ trunk/topia-persistence-hibernate/src/test/java/org/nuiton/topia/tck/it/TopiaTckItHibernateTestSuite.java 2012-05-09 15:07:53 UTC (rev 2452)
@@ -0,0 +1,10 @@
+package org.nuiton.topia.tck.it;
+
+/**
+ * Do not remove event if empty : this class represents the TCK IT tests
+ * for topia-persistence-hibernate module
+ *
+ * @author Arnaud Thimel <thimel(a)codelutin.com>
+ */
+public class TopiaTckItHibernateTestSuite extends TopiaTckItTestSuite {
+}
Copied: trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/TopiaContextFactoryTest.java (from rev 2450, trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/TopiaContextFactoryTest.java)
===================================================================
--- trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/TopiaContextFactoryTest.java (rev 0)
+++ trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/TopiaContextFactoryTest.java 2012-05-09 15:07:53 UTC (rev 2452)
@@ -0,0 +1,190 @@
+/*
+ * #%L
+ * ToPIA :: Persistence
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2004 - 2010 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
+package org.nuiton.topia;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.nuiton.topia.framework.TopiaContextImpl;
+import org.nuiton.topia.tck.TopiaDatabase;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.List;
+import java.util.Properties;
+
+/**
+ * Created: 8 mai 2010
+ *
+ * @author fdesbois <fdesbois(a)codelutin.com>
+ * @version $Id$
+ */
+public class TopiaContextFactoryTest {
+
+ private static final Log log =
+ LogFactory.getLog(TopiaContextFactoryTest.class);
+
+ protected static File testBasedir;
+
+ protected Properties properties;
+
+ @BeforeClass
+ public static void init() throws IOException {
+
+ testBasedir = TopiaDatabase.getTestSpecificDirectory(TopiaContextFactoryTest.class, "dummy");
+
+ }
+
+ @Before
+ public void setUp() throws Exception {
+ properties = new Properties();
+ properties.setProperty("prop1", "value1");
+ properties.setProperty("prop2", "value2");
+ TopiaContextFactory.contextCache.clear();
+ }
+
+ @Test
+ public void testGetContextOpened() throws Exception {
+ log.debug("## testGetContextOpened");
+
+ /** PREPARE DATA **/
+ String databaseName = "h2data-testGetContextByPropertie";
+ File dbDirectory = new File(testBasedir, databaseName);
+ String url = "jdbc:h2:file:" + dbDirectory;
+ properties.setProperty("hibernate.connection.url", url);
+
+ TopiaContextImpl test = new TopiaContextImpl(properties);
+ TopiaContextFactory.contextCache.put(properties, test);
+
+ /** EXEC METHOD **/
+ List<String> result = TopiaContextFactory.getContextOpened();
+ Assert.assertEquals(1, result.size());
+ Assert.assertEquals(url, result.get(0));
+ }
+
+ @Test
+ public void testRemoveContext() throws Exception {
+ log.debug("## testRemoveContext");
+
+ /** PREPARE DATA **/
+ TopiaContextImpl test = new TopiaContextImpl(properties);
+ TopiaContextFactory.contextCache.put(properties, test);
+
+ /** EXEC METHOD **/
+ TopiaContextFactory.removeContext(test);
+ Assert.assertEquals(0, TopiaContextFactory.contextCache.size());
+ }
+
+ //@Test
+
+ public void testGetContext() throws Exception {
+ // TODO-fdesbois-20100508 : only used TopiaUtil.getProperties, need tests for this method
+ }
+
+ @Test
+ public void testGetContextByProperties() throws Exception {
+ log.debug("## testGetContextByProperties");
+
+ /** PREPARE DATA **/
+ Properties propertiesParent = new Properties(properties);
+ propertiesParent.setProperty("prop3", "value3");
+
+ Properties propertiesAll = new Properties();
+ propertiesAll.setProperty("prop1", "value1");
+ propertiesAll.setProperty("prop2", "value2");
+ propertiesAll.setProperty("prop3", "value3");
+
+ /** EXEC METHOD **/
+
+ log.info("test 0 : add null properties");
+ try {
+ TopiaContextFactory.getContext(null);
+ } catch (Exception eee) {
+ Assert.assertEquals(NullPointerException.class, eee.getClass());
+ }
+
+ log.info("test 1 : add new properties, will instantiate a new" +
+ " TopiaContext");
+ TopiaContext test1 = TopiaContextFactory.getContext(propertiesParent);
+ Assert.assertNotNull(test1);
+ Assert.assertEquals(1, TopiaContextFactory.contextCache.size());
+
+ log.info("test 2 : with same properties, will retrieve existing" +
+ " TopiaContext");
+ TopiaContext test2 = TopiaContextFactory.getContext(propertiesParent);
+ Assert.assertEquals(test1, test2);
+ Assert.assertEquals(1, TopiaContextFactory.contextCache.size());
+
+ log.info("test 3 : use other properties, will instantiate a different" +
+ "TopiaContext");
+ TopiaContext test3 = TopiaContextFactory.getContext(properties);
+ log.debug("cache size : " + TopiaContextFactory.contextCache.size());
+ log.debug("result : " + test1);
+ log.debug("result3 : " + test3);
+ Assert.assertNotSame(test1, test3);
+ Assert.assertEquals(2, TopiaContextFactory.contextCache.size());
+
+ log.info("test 4 : use other properties but equivalent to existing " +
+ "TopiaContext");
+ // Test flating of properties
+ TopiaContext test4 = TopiaContextFactory.getContext(propertiesAll);
+ Assert.assertEquals(test1, test4);
+ Assert.assertEquals(2, TopiaContextFactory.contextCache.size());
+
+ log.info("test5a : reinstantiate new TopiaContext after one is closed.");
+ // TEST
+ // Strange behavior the closed flag of context stay true if
+ // hibernateFactory is not loaded from real properties
+// test1.closeContext();
+// Assert.assertTrue(test1.isClosed());
+
+ // Add properties for Hibernate to have real opened topiaContext
+ String databaseName = "h2data-testGetContextByPropertie";
+ File f = new File(testBasedir, databaseName);
+
+ properties.setProperty("hibernate.connection.username", "sa");
+ properties.setProperty("hibernate.connection.password", "");
+ properties.setProperty("hibernate.connection.driver_class", "org.h2.Driver");
+ properties.setProperty("hibernate.connection.url",
+ "jdbc:h2:file:" + f.getAbsolutePath());
+
+
+ TopiaContext test5 = TopiaContextFactory.getContext(properties);
+ Assert.assertNotSame(test1, test5);
+ Assert.assertEquals(3, TopiaContextFactory.contextCache.size());
+
+ log.info("test5b : beginTransaction to properly close the context");
+ test5.beginTransaction();
+
+ test5.closeContext();
+
+ TopiaContext result = TopiaContextFactory.getContext(properties);
+ Assert.assertNotSame(test5, result);
+ Assert.assertEquals(3, TopiaContextFactory.contextCache.size());
+ }
+}
Property changes on: trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/TopiaContextFactoryTest.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Modified: trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/ano1882/DAOAbstractTransformerTest.java
===================================================================
--- trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/test/ano1882/DAOAbstractTransformerTest.java 2012-05-09 14:32:00 UTC (rev 2450)
+++ trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/ano1882/DAOAbstractTransformerTest.java 2012-05-09 15:07:53 UTC (rev 2452)
@@ -22,13 +22,17 @@
* <http://www.gnu.org/licenses/lgpl-3.0.html>.
* #L%
*/
-package org.nuiton.topia.test.ano1882;
+package org.nuiton.topia.tck.ano1882;
import org.junit.Rule;
import org.junit.Test;
import org.nuiton.topia.TopiaContext;
import org.nuiton.topia.tck.TopiaDatabase;
import org.nuiton.topia.TopiaTckItDAOHelper;
+import org.nuiton.topia.test.ano1882.FrenchCompany;
+import org.nuiton.topia.test.ano1882.FrenchCompanyDAO;
+import org.nuiton.topia.test.ano1882.SIRET;
+import org.nuiton.topia.test.ano1882.SIRETDAO;
import java.util.Arrays;
Modified: trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/ano1991/TopiaQueryTest.java
===================================================================
--- trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/test/ano1991/TopiaQueryTest.java 2012-05-09 14:32:00 UTC (rev 2450)
+++ trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/ano1991/TopiaQueryTest.java 2012-05-09 15:07:53 UTC (rev 2452)
@@ -22,7 +22,7 @@
* <http://www.gnu.org/licenses/lgpl-3.0.html>.
* #L%
*/
-package org.nuiton.topia.test.ano1991;
+package org.nuiton.topia.tck.ano1991;
import org.junit.Assert;
import org.junit.Rule;
Modified: trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/evo1912/EntityDTOTransformerTest.java
===================================================================
--- trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/test/evo1912/EntityDTOTransformerTest.java 2012-05-09 14:32:00 UTC (rev 2450)
+++ trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/evo1912/EntityDTOTransformerTest.java 2012-05-09 15:07:53 UTC (rev 2452)
@@ -22,7 +22,7 @@
* <http://www.gnu.org/licenses/lgpl-3.0.html>.
* #L%
*/
-package org.nuiton.topia.test.evo1912;
+package org.nuiton.topia.tck.evo1912;
import org.junit.Assert;
import org.junit.Test;
Copied: trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/framework/TopiaContextReplicateTest.java (from rev 2450, trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/framework/TopiaContextReplicateTest.java)
===================================================================
--- trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/framework/TopiaContextReplicateTest.java (rev 0)
+++ trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/framework/TopiaContextReplicateTest.java 2012-05-09 15:07:53 UTC (rev 2452)
@@ -0,0 +1,157 @@
+/*
+ * #%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.framework;
+
+import org.junit.Assert;
+import org.junit.Rule;
+import org.junit.Test;
+import org.nuiton.topia.TopiaContext;
+import org.nuiton.topia.TopiaContextFactory;
+import org.nuiton.topia.tck.TopiaDatabase;
+import org.nuiton.topia.TopiaTckItDAOHelper;
+import org.nuiton.topia.test.entities.Person;
+import org.nuiton.topia.test.entities.PersonDAO;
+import org.nuiton.topia.test.entities.Pet;
+import org.nuiton.topia.test.entities.PetDAO;
+
+import java.io.File;
+import java.util.Properties;
+
+/**
+ * To test replication sugin TopiaContext.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.6.8
+ */
+public class TopiaContextReplicateTest {
+
+ @Rule
+ public final TopiaDatabase dbSource =
+ new TopiaDatabase() {
+
+ @Override
+ protected void onDbConfigurationCreate(Properties configuration, File testDir, String dbPath) {
+ configuration.setProperty(
+ TopiaContextFactory.CONFIG_URL, "jdbc:h2:file:" + dbPath + "-source");
+
+ }
+ };
+
+ @Rule
+ public final TopiaDatabase dbTarget =
+ new TopiaDatabase() {
+
+ @Override
+ protected void onDbConfigurationCreate(Properties configuration, File testDir, String dbPath) {
+ configuration.setProperty(
+ TopiaContextFactory.CONFIG_URL, "jdbc:h2:file:" + dbPath + "-target");
+
+ }
+ };
+
+ @Test
+ public void replicateEntity() throws Exception {
+//
+// Properties configSource = TestHelper.initTopiaContextConfiguration(
+// testBasedir,
+// "/TopiaContextImpl.properties",
+// "replicateSource");
+//
+// Properties configTarget = TestHelper.initTopiaContextConfiguration(
+// testBasedir,
+// "/TopiaContextImpl.properties",
+// "replicateTarget");
+//
+
+ TopiaContext contextSource = dbSource.getRootCtxt();
+ TopiaContext contextTarget = dbTarget.getRootCtxt();
+
+// try {
+// contextSource = TopiaContextFactory.getContext(configSource);
+// contextTarget = TopiaContextFactory.getContext(configTarget);
+
+ TopiaContext txSource;
+ TopiaContext txTarget;
+ PersonDAO daoSource, daoTarget;
+ PetDAO petDAOSource, petDAOTarget;
+ Person personSource, personTarget;
+ Pet petSource, petTarget;
+
+ txSource = contextSource.beginTransaction();
+ daoSource = TopiaTckItDAOHelper.getPersonDAO(txSource);
+ petDAOSource = TopiaTckItDAOHelper.getPetDAO(txSource);
+
+ personSource = daoSource.create(Person.PROPERTY_FIRSTNAME, " firstName",
+ Person.PROPERTY_NAME, " name"
+ );
+
+ petSource = petDAOSource.create(Pet.PROPERTY_NAME, "name",
+ Pet.PROPERTY_TYPE, "type",
+ Pet.PROPERTY_PERSON, personSource
+ );
+
+ personSource.addPet(petSource);
+
+ txSource.commitTransaction();
+
+ daoSource = TopiaTckItDAOHelper.getPersonDAO(txSource);
+
+ personSource = daoSource.findByTopiaId(personSource.getTopiaId());
+ Assert.assertNotNull(personSource);
+
+ petSource = petDAOSource.findByTopiaId(petSource.getTopiaId());
+ Assert.assertNotNull(petSource);
+ Assert.assertEquals(1, personSource.sizePet());
+ Assert.assertEquals(petSource, personSource.getPet().iterator().next());
+
+ txTarget = contextTarget.beginTransaction();
+
+ txSource.replicateEntity(txTarget, petSource);
+ txSource.replicateEntity(txTarget, personSource);
+
+ txTarget.commitTransaction();
+
+ daoTarget = TopiaTckItDAOHelper.getPersonDAO(txTarget);
+ petDAOTarget = TopiaTckItDAOHelper.getPetDAO(txTarget);
+
+ personTarget = daoTarget.findByTopiaId(personSource.getTopiaId());
+ Assert.assertNotNull(personTarget);
+ Assert.assertEquals(personSource, personTarget);
+ Assert.assertEquals(1, personTarget.sizePet());
+
+ petTarget = petDAOTarget.findByTopiaId(petSource.getTopiaId());
+ Assert.assertNotNull(petTarget);
+ Assert.assertEquals(petSource, petTarget);
+
+ Assert.assertEquals(petTarget, personTarget.getPet().iterator().next());
+
+
+// } finally {
+// closeDb(contextSource);
+// closeDb(contextTarget);
+// }
+
+ }
+}
Property changes on: trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/framework/TopiaContextReplicateTest.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Copied: trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/framework/TopiaUtilTest.java (from rev 2450, trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/framework/TopiaUtilTest.java)
===================================================================
--- trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/framework/TopiaUtilTest.java (rev 0)
+++ trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/framework/TopiaUtilTest.java 2012-05-09 15:07:53 UTC (rev 2452)
@@ -0,0 +1,114 @@
+/*
+ * #%L
+ * ToPIA :: Persistence
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2004 - 2010 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
+
+package org.nuiton.topia.tck.framework;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.nuiton.topia.TopiaContext;
+import org.nuiton.topia.framework.TopiaUtil;
+import org.nuiton.topia.tck.TopiaDatabase;
+import org.nuiton.topia.tck.it.Personne;
+import org.nuiton.topia.test.entities.PersonImpl;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * Test pour les methodes de {@link org.nuiton.topia.framework.TopiaUtil}.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @version $Revision$
+ * <p/>
+ * Last update: $Date$
+ * by : $Author$
+ */
+public class TopiaUtilTest {
+
+ protected static final String PERSON_ID = "org.nuiton.topiatest.Personne#1226701039001#0.6502325993664224";
+
+ protected static final String PERSON_ID2 = "org.nuiton.topiatest.Personne#1226701039001#0.6502325993664999";
+
+ @Rule
+ public final TopiaDatabase db = new TopiaDatabase();
+
+ @Test
+ public void testGetTopiaIdPattern() throws Exception {
+ String expected;
+ String actual;
+
+ expected = "org\\.nuiton\\.topiatest\\.Personne#(?:\\d+?)#(?:\\d+)\\.(?:\\d+)";
+ actual = TopiaUtil.getTopiaIdPattern(Personne.class);
+ assertEquals(expected, actual);
+ }
+
+ @Test
+ public void testGetTopiaPattern() throws Exception {
+ String expected;
+ Pattern pattern;
+
+ expected = "(\\d+)-(org\\.nuiton\\.topiatest\\.Personne#(?:\\d+?)#(?:\\d+)\\.(?:\\d+))-(org\\.nuiton\\.topiatest\\.Personne#(?:\\d+?)#(?:\\d+)\\.(?:\\d+))(.*)";
+ pattern = TopiaUtil.getTopiaPattern("(\\d+)-%1$s-%1$s(.*)", Personne.class);
+ assertEquals(expected, pattern.toString());
+
+ String expression = 123 + "-" + PERSON_ID + "-" + PERSON_ID2 + "-afterall";
+
+ Matcher matcher = pattern.matcher(expression);
+
+ assertTrue(matcher.matches());
+
+ assertTrue(matcher.matches());
+ assertEquals(4, matcher.groupCount());
+ assertEquals("123", matcher.group(1));
+ assertEquals(PERSON_ID, matcher.group(2));
+ assertEquals(PERSON_ID2, matcher.group(3));
+ assertEquals("-afterall", matcher.group(4));
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testIsSchemaExistFailed() throws Exception {
+ TopiaUtil.isSchemaExist(db.getRootCtxt(), "fake");
+ }
+
+ @Test
+ public void testIsSchemaExist() throws Exception {
+ TopiaContext rootContext = db.getRootCtxt();
+ boolean actual = TopiaUtil.isSchemaExist(rootContext,
+ PersonImpl.class.getName());
+
+ assertFalse(actual);
+ TopiaContext tx = rootContext.beginTransaction();
+
+ tx.createSchema();
+ actual = TopiaUtil.isSchemaExist(rootContext, PersonImpl.class.getName());
+
+ assertTrue(actual);
+
+ }
+}
Property changes on: trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/framework/TopiaUtilTest.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Copied: trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/generator/TopiaTestCase.java (from rev 2450, trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/generator/TopiaTestCase.java)
===================================================================
--- trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/generator/TopiaTestCase.java (rev 0)
+++ trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/generator/TopiaTestCase.java 2012-05-09 15:07:53 UTC (rev 2452)
@@ -0,0 +1,170 @@
+/*
+ * #%L
+ * ToPIA :: Persistence
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2004 - 2010 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
+
+package org.nuiton.topia.tck.generator;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+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.TopiaTckItDAOHelper;
+import org.nuiton.topia.tck.it.Company;
+import org.nuiton.topia.tck.it.CompanyDAO;
+import org.nuiton.topia.tck.it.Department;
+import org.nuiton.topia.tck.it.DepartmentDAO;
+
+/**
+ * TopiaTestCase.
+ *
+ * @author chatellier
+ * @version $Revision$
+ * <p/>
+ * Last update : $Date$
+ * By : $Author$
+ */
+public class TopiaTestCase {
+
+ /** Logger */
+ private final static Log log = LogFactory.getLog(TopiaTestCase.class);
+
+ @Rule
+ public final TopiaDatabase db = new TopiaDatabase();
+
+// /** Proprietes */
+// protected static Properties config;
+//
+// /** TopiaContext */
+// protected static TopiaContext context;
+
+// /**
+// * Init les proprietes de connection a la base
+// *
+// * @throws IOException for any IO error while getting configuration.
+// */
+// @BeforeClass
+// public static void init() throws IOException {
+//
+// File testBasedir = TestHelper.getTestBasedir(TopiaTestCase.class);
+//
+// config = TestHelper.initTopiaContextConfiguration(
+// testBasedir,
+// "/TopiaContextImpl.properties",
+// "TopiaTestCaseDb");
+//// config = new Properties();
+//// config.setProperty("topia.persistence.classes", TopiaTckItDAOHelper.getImplementationClassesAsString());
+////
+//// config.setProperty(Environment.USER, "sa");
+//// config.setProperty(Environment.PASS, "");
+//// config.setProperty(Environment.CURRENT_SESSION_CONTEXT_CLASS, "thread");
+//// config.setProperty(Environment.DIALECT, "org.hibernate.dialect.H2Dialect");
+//// config.setProperty(Environment.DRIVER, "org.h2.Driver");
+//// config.setProperty(Environment.URL, "jdbc:h2:file:" + testBasedir + "/db/data_" + System.currentTimeMillis());
+// }
+//
+// @AfterClass
+// public static void after() throws TopiaException {
+// // destroy database
+// context.clear(false);
+// }
+
+// /** Create base with schema created. */
+// @Before
+// public void setUp() {
+//
+// if (log.isDebugEnabled()) {
+// log.debug("Junit beforeTest");
+// }
+//
+// try {
+// context = TopiaContextFactory.getContext(config);
+//
+// try {
+// context.createSchema();
+// } catch (TopiaException e) {
+// log.error("Erreur à la creation du schema", e);
+// }
+// } catch (TopiaNotFoundException e) {
+// log.error("Erreur à la creation du topia context", e);
+// }
+// }
+
+ @Test
+ public void testCompositeAssociations() throws TopiaException {
+ if (log.isDebugEnabled()) {
+ log.debug("Junit Test testCompositeAssociations");
+ }
+
+// try {
+ TopiaContext newContext = db.beginTransaction();
+
+ CompanyDAO companyDAO = TopiaTckItDAOHelper.getCompanyDAO(newContext);
+ DepartmentDAO departmentDAO = TopiaTckItDAOHelper.getDepartmentDAO(newContext);
+
+ Company company = companyDAO.create();
+ company.setName("Ma société");
+
+
+ Department dep1 = departmentDAO.create();
+ dep1.setName("Departement 1");
+ Department dep2 = departmentDAO.create();
+ dep2.setName("Departement 2");
+ Department dep3 = departmentDAO.create();
+ dep3.setName("Departement 3");
+ Department dep4 = departmentDAO.create();
+ dep4.setName("Departement 7");
+
+ departmentDAO.update(dep1);
+ departmentDAO.update(dep2);
+ departmentDAO.update(dep3);
+ departmentDAO.update(dep4);
+
+ company.addDepartment(dep1);
+ company.addDepartment(dep2);
+ company.addDepartment(dep3);
+ company.addDepartment(dep4);
+
+ companyDAO.update(company);
+ newContext.commitTransaction();
+
+ newContext = db.beginTransaction();
+
+ companyDAO = TopiaTckItDAOHelper.getCompanyDAO(newContext);
+
+ company = companyDAO.findByTopiaId(company.getTopiaId());
+
+ Assert.assertEquals(company.getName(), "Ma société");
+ Assert.assertEquals(company.getDepartment().size(), 4);
+
+ newContext.commitTransaction();
+// newContext.closeContext();
+// } catch (TopiaException e) {
+// log.error("Erreur pendant le test testCompositeAssociations", e);
+// }
+ }
+}
Property changes on: trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/generator/TopiaTestCase.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Added: trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/it/TopiaTckItTestSuite.java
===================================================================
--- trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/it/TopiaTckItTestSuite.java (rev 0)
+++ trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/it/TopiaTckItTestSuite.java 2012-05-09 15:07:53 UTC (rev 2452)
@@ -0,0 +1,13 @@
+package org.nuiton.topia.tck.it;
+
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+
+/**
+ * @author Arnaud Thimel <thimel(a)codelutin.com>
+ */
+(a)RunWith(Suite.class)
+(a)Suite.SuiteClasses({EnumTest.class}) // TODO AThimel 09/05/2012 Add all TCK IT tests
+public abstract class TopiaTckItTestSuite {
+
+}
Copied: trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/persistence/EntityVisitorExportXmlTest.java (from rev 2450, trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/persistence/EntityVisitorExportXmlTest.java)
===================================================================
--- trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/persistence/EntityVisitorExportXmlTest.java (rev 0)
+++ trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/persistence/EntityVisitorExportXmlTest.java 2012-05-09 15:07:53 UTC (rev 2452)
@@ -0,0 +1,134 @@
+/*
+ * #%L
+ * ToPIA :: Persistence
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2004 - 2010 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
+
+package org.nuiton.topia.tck.persistence;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.nuiton.topia.TopiaContext;
+import org.nuiton.topia.persistence.DepthEntityVisitor;
+import org.nuiton.topia.persistence.EntityVisitor;
+import org.nuiton.topia.tck.TopiaDatabase;
+import org.nuiton.topia.TopiaException;
+import org.nuiton.topia.TopiaTckItDAOHelper;
+import org.nuiton.topia.tck.it.Address;
+import org.nuiton.topia.tck.it.AddressDAO;
+import org.nuiton.topia.tck.it.Company;
+import org.nuiton.topia.tck.it.CompanyDAO;
+import org.nuiton.topia.tck.it.Department;
+import org.nuiton.topia.tck.it.DepartmentDAO;
+import org.nuiton.topia.tck.it.Employe;
+import org.nuiton.topia.tck.it.EmployeDAO;
+
+/**
+ * Test de visitor.
+ *
+ * @author chatellier
+ * @version $Revision$
+ * <p/>
+ * Last update : $Date$
+ * By : $Author$
+ */
+public class EntityVisitorExportXmlTest {
+
+ private static final Log log =
+ LogFactory.getLog(EntityVisitorExportXmlTest.class);
+
+ @Rule
+ public final TopiaDatabase db = new TopiaDatabase();
+
+ /**
+ * Prepare test.
+ * <p/>
+ * Add all tests commons data
+ *
+ * @throws TopiaException if could not create datas
+ */
+ @Before
+ public void setUp() throws TopiaException {
+
+ TopiaContext newContext = db.beginTransaction();
+ try {
+ // company
+ CompanyDAO companyDAO = TopiaTckItDAOHelper.getCompanyDAO(newContext);
+ Company clCompany = companyDAO.create(Company.PROPERTY_NAME, "CodeLutin");
+
+ // employe
+ EmployeDAO employeDAO = TopiaTckItDAOHelper.getEmployeDAO(newContext);
+ Employe empl1 = employeDAO.create(Employe.PROPERTY_NAME, "boss", Employe.PROPERTY_SALARY, 30000);
+
+ AddressDAO adressDAO = TopiaTckItDAOHelper.getAddressDAO(newContext);
+ Address addr1 = adressDAO.create(Address.PROPERTY_CITY, "Nantes", Address.PROPERTY_ADRESS, "12 Avenue Jules Vernes");
+ empl1.setAddress(addr1);
+
+ Employe empl2 = employeDAO.create(Employe.PROPERTY_NAME, "boss2", Employe.PROPERTY_SALARY, 29000);
+ Address addr2 = adressDAO.create(Address.PROPERTY_CITY, "Nantes", Address.PROPERTY_ADRESS, "12 Avenue Jules Vernes");
+ empl2.setAddress(addr2);
+
+ // departement
+ DepartmentDAO departmentDAO = TopiaTckItDAOHelper.getDepartmentDAO(newContext);
+ Department depComm = departmentDAO.create(Department.PROPERTY_NAME, "Commercial");
+ depComm.setLeader(empl1);
+
+ Department depDev = departmentDAO.create(Department.PROPERTY_NAME, "Dev");
+ depDev.setLeader(empl2);
+ clCompany.addDepartment(depComm);
+ clCompany.addDepartment(depDev);
+
+ newContext.commitTransaction();
+ } finally {
+
+ newContext.closeContext();
+ }
+ }
+
+
+ /**
+ * Test l'export XML via un visiteur.
+ * <p/>
+ * Parcourt en profondeur.
+ *
+ * @throws TopiaException
+ */
+ @Test
+ public void testExportXMLDepth() throws TopiaException {
+
+ TopiaContext context = db.beginTransaction();
+
+ CompanyDAO companyDAO = TopiaTckItDAOHelper.getCompanyDAO(context);
+ Company clCompany = companyDAO.findByName("CodeLutin");
+
+ EntityVisitor delegateVisitor = new ExportXMLVisitor();
+ EntityVisitor visitor = new DepthEntityVisitor(delegateVisitor);
+ clCompany.accept(visitor);
+
+ if (log.isInfoEnabled()) {
+ log.info("Export XML = \n" + delegateVisitor.toString());
+ }
+ }
+}
Property changes on: trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/persistence/EntityVisitorExportXmlTest.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Copied: trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/persistence/ExportXMLVisitor.java (from rev 2450, trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/persistence/ExportXMLVisitor.java)
===================================================================
--- trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/persistence/ExportXMLVisitor.java (rev 0)
+++ trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/persistence/ExportXMLVisitor.java 2012-05-09 15:07:53 UTC (rev 2452)
@@ -0,0 +1,109 @@
+/*
+ * #%L
+ * ToPIA :: Persistence
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2004 - 2010 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
+
+package org.nuiton.topia.tck.persistence;
+
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.junit.Ignore;
+import org.nuiton.topia.persistence.EntityVisitor;
+import org.nuiton.topia.persistence.TopiaEntity;
+
+/**
+ * Visitor pour export xml.
+ *
+ * @author chatellier
+ * @version $Revision$
+ * <p/>
+ * Last update : $Date$
+ * By : $Author$
+ */
+@Ignore
+public class ExportXMLVisitor implements EntityVisitor {
+
+ /** log. */
+ private static Log log = LogFactory.getLog(ExportXMLVisitor.class);
+
+ protected StringBuffer buffer;
+
+ public ExportXMLVisitor() {
+ buffer = new StringBuffer();
+ }
+
+ @Override
+ public void start(TopiaEntity e) {
+ if (log.isDebugEnabled()) {
+ log.debug("start : " + e);
+ }
+
+ buffer.append("<").append(e.getClass().getName());
+ buffer.append(" topiaId=\"").append(e.getTopiaId()).append("\"");
+ buffer.append(" topiaCreateDate=\"").append(e.getTopiaCreateDate()).append("\"");
+ buffer.append(" topiaVersion=\"").append(e.getTopiaVersion()).append("\"");
+ buffer.append(">\n");
+ }
+
+ @Override
+ public void visit(TopiaEntity e, String name, Class<?> type, Object value) {
+ if (log.isDebugEnabled()) {
+ log.debug("visit : " + e);
+ }
+
+ buffer.append("<").append(type.getName()).append(">").append(value).append("</").append(type.getName()).append(">\n");
+ }
+
+ @Override
+ public void visit(TopiaEntity e, String name, Class<?> collectionType, Class<?> type,
+ Object value) {
+ }
+
+ @Override
+ public void visit(TopiaEntity e, String name, Class<?> collectionType, Class<?> type, int index, Object value) {
+ visit(e, name, type, value);
+ }
+
+ @Override
+ public void end(TopiaEntity e) {
+ if (log.isDebugEnabled()) {
+ log.debug("end : " + e);
+ }
+
+ buffer.append("</").append(e.getClass().getName()).append(">\n");
+ }
+
+ @Override
+ public String toString() {
+ String content = buffer.toString();
+ return content;
+ }
+
+ @Override
+ public void clear() {
+ // do nothing
+ }
+
+
+}
Property changes on: trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/persistence/ExportXMLVisitor.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Copied: trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/persistence/NaturalIdTest.java (from rev 2450, trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/persistence/NaturalIdTest.java)
===================================================================
--- trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/persistence/NaturalIdTest.java (rev 0)
+++ trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/persistence/NaturalIdTest.java 2012-05-09 15:07:53 UTC (rev 2452)
@@ -0,0 +1,177 @@
+/*
+ * #%L
+ * ToPIA :: Persistence
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2004 - 2010 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
+
+package org.nuiton.topia.tck.persistence;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+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.TopiaTckItDAOHelper;
+import org.nuiton.topia.tck.it.NaturalizedEntity;
+import org.nuiton.topia.tck.it.NaturalizedEntityDAO;
+
+/**
+ * NaturalIdTest
+ * <p/>
+ * Created: 18 févr. 2010
+ *
+ * @author fdesbois
+ * @version $Revision$
+ * <p/>
+ * Mise a jour: $Date$
+ * par : $Author$
+ */
+public class NaturalIdTest {
+
+ private static final Log log = LogFactory.getLog(NaturalIdTest.class);
+
+ @Rule
+ public final TopiaDatabase db = new TopiaDatabase();
+
+ @Test
+ public void testCreateSucessfull() throws Exception {
+ log.debug("Test naturalId : create succesfull");
+ TopiaContext transaction = db.beginTransaction();
+
+ NaturalizedEntityDAO dao =
+ TopiaTckItDAOHelper.getNaturalizedEntityDAO(transaction);
+
+ // No exception will be thrown with the two properties
+ dao.createByNaturalId(5, "str");
+ transaction.commitTransaction();
+
+ // No exception will only the need property
+ dao.createByNotNull(3);
+ transaction.commitTransaction();
+
+ // No exception will only the need property
+ dao.create(NaturalizedEntity.PROPERTY_NATURAL_ID_NOT_NULL, 3);
+ transaction.commitTransaction();
+ }
+
+ @Test
+ public void testCreateFailed() throws Exception {
+ log.debug("Test naturalId : create failed");
+ TopiaContext transaction = db.beginTransaction();
+
+ NaturalizedEntityDAO dao =
+ TopiaTckItDAOHelper.getNaturalizedEntityDAO(transaction);
+
+ // Exception will be throw
+// try {
+ dao.create();
+ transaction.commitTransaction();
+
+ // Note : this is possible to create an empty entity if the type
+ // is primitive like 'int' which have a default value of '0'
+// } catch (PropertyValueException eee) {
+// Assert.assertEquals("naturalIdNotNull", eee.getPropertyName());
+// }
+ }
+
+ @Test
+ public void testUpdateFailed() throws Exception {
+ log.debug("Test naturalId : update failed");
+
+ TopiaContext transaction = db.beginTransaction();
+
+ NaturalizedEntityDAO dao =
+ TopiaTckItDAOHelper.getNaturalizedEntityDAO(transaction);
+
+ NaturalizedEntity entity =
+ dao.createByNaturalId(5, "str");
+ transaction.commitTransaction();
+
+ // Exception will be throw : not allowed to modify a naturalId property
+ try {
+ entity.setNaturalIdNotNull(8);
+ transaction.commitTransaction();
+ } catch (TopiaException eee) {
+ Assert.assertEquals("org.hibernate.HibernateException",
+ eee.getCause().getClass().getName());
+ }
+ }
+
+ @Test
+ public void testFindByNaturalId() throws Exception {
+ log.debug("Test naturalId : findByNaturalId");
+ TopiaContext transaction = db.beginTransaction();
+
+ NaturalizedEntityDAO dao =
+ TopiaTckItDAOHelper.getNaturalizedEntityDAO(transaction);
+
+ NaturalizedEntity entity =
+ dao.createByNaturalId(5, "str");
+ transaction.commitTransaction();
+
+ NaturalizedEntity result = dao.findByNaturalId(5, "str");
+
+ Assert.assertEquals(entity, result);
+ }
+
+ @Test
+ public void testExistNaturalId() throws Exception {
+ log.debug("Test naturalId : existNaturalId");
+ TopiaContext transaction = db.beginTransaction();
+
+ NaturalizedEntityDAO dao =
+ TopiaTckItDAOHelper.getNaturalizedEntityDAO(transaction);
+
+ dao.createByNaturalId(5, "str");
+ transaction.commitTransaction();
+
+ boolean result = dao.existByNaturalId(5, "str");
+
+ Assert.assertTrue(result);
+
+ // not find with only one correct property
+ result = dao.existByNaturalId(8, "str");
+
+ Assert.assertFalse(result);
+ }
+
+ @Test
+ public void testNaturalIdAreGeneralized() throws Exception {
+
+ // test that natural ids are generalized
+ String[] generalizedNaturalizedNaturalIds = TopiaTckItDAOHelper.TopiaTckItEntityEnum.GeneralizedNaturalizedEntity.getNaturalIds();
+ String[] naturalizedNaturalIds = TopiaTckItDAOHelper.TopiaTckItEntityEnum.NaturalizedEntity.getNaturalIds();
+ Assert.assertArrayEquals(generalizedNaturalizedNaturalIds, naturalizedNaturalIds);
+ }
+
+ @Test
+ public void testNotNullsAreGeneralized() throws Exception {
+
+ // test that not nulls are generalized
+ String[] generalizedNaturalizedNotNulls = TopiaTckItDAOHelper.TopiaTckItEntityEnum.GeneralizedNaturalizedEntity.getNotNulls();
+ String[] naturalizedNotNulls = TopiaTckItDAOHelper.TopiaTckItEntityEnum.NaturalizedEntity.getNotNulls();
+ Assert.assertArrayEquals(generalizedNaturalizedNotNulls, naturalizedNotNulls);
+ }
+}
Property changes on: trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/persistence/NaturalIdTest.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Deleted: trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/TopiaContextFactoryTest.java
===================================================================
--- trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/TopiaContextFactoryTest.java 2012-05-09 14:37:49 UTC (rev 2451)
+++ trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/TopiaContextFactoryTest.java 2012-05-09 15:07:53 UTC (rev 2452)
@@ -1,190 +0,0 @@
-/*
- * #%L
- * ToPIA :: Persistence
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2004 - 2010 CodeLutin
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>.
- * #L%
- */
-package org.nuiton.topia;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.nuiton.topia.framework.TopiaContextImpl;
-import org.nuiton.topia.tck.TopiaDatabase;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.List;
-import java.util.Properties;
-
-/**
- * Created: 8 mai 2010
- *
- * @author fdesbois <fdesbois(a)codelutin.com>
- * @version $Id$
- */
-public class TopiaContextFactoryTest {
-
- private static final Log log =
- LogFactory.getLog(TopiaContextFactoryTest.class);
-
- protected static File testBasedir;
-
- protected Properties properties;
-
- @BeforeClass
- public static void init() throws IOException {
-
- testBasedir = TopiaDatabase.getTestSpecificDirectory(TopiaContextFactoryTest.class, "dummy");
-
- }
-
- @Before
- public void setUp() throws Exception {
- properties = new Properties();
- properties.setProperty("prop1", "value1");
- properties.setProperty("prop2", "value2");
- TopiaContextFactory.contextCache.clear();
- }
-
- @Test
- public void testGetContextOpened() throws Exception {
- log.debug("## testGetContextOpened");
-
- /** PREPARE DATA **/
- String databaseName = "h2data-testGetContextByPropertie";
- File dbDirectory = new File(testBasedir, databaseName);
- String url = "jdbc:h2:file:" + dbDirectory;
- properties.setProperty("hibernate.connection.url", url);
-
- TopiaContextImpl test = new TopiaContextImpl(properties);
- TopiaContextFactory.contextCache.put(properties, test);
-
- /** EXEC METHOD **/
- List<String> result = TopiaContextFactory.getContextOpened();
- Assert.assertEquals(1, result.size());
- Assert.assertEquals(url, result.get(0));
- }
-
- @Test
- public void testRemoveContext() throws Exception {
- log.debug("## testRemoveContext");
-
- /** PREPARE DATA **/
- TopiaContextImpl test = new TopiaContextImpl(properties);
- TopiaContextFactory.contextCache.put(properties, test);
-
- /** EXEC METHOD **/
- TopiaContextFactory.removeContext(test);
- Assert.assertEquals(0, TopiaContextFactory.contextCache.size());
- }
-
- //@Test
-
- public void testGetContext() throws Exception {
- // TODO-fdesbois-20100508 : only used TopiaUtil.getProperties, need tests for this method
- }
-
- @Test
- public void testGetContextByProperties() throws Exception {
- log.debug("## testGetContextByProperties");
-
- /** PREPARE DATA **/
- Properties propertiesParent = new Properties(properties);
- propertiesParent.setProperty("prop3", "value3");
-
- Properties propertiesAll = new Properties();
- propertiesAll.setProperty("prop1", "value1");
- propertiesAll.setProperty("prop2", "value2");
- propertiesAll.setProperty("prop3", "value3");
-
- /** EXEC METHOD **/
-
- log.info("test 0 : add null properties");
- try {
- TopiaContextFactory.getContext(null);
- } catch (Exception eee) {
- Assert.assertEquals(NullPointerException.class, eee.getClass());
- }
-
- log.info("test 1 : add new properties, will instantiate a new" +
- " TopiaContext");
- TopiaContext test1 = TopiaContextFactory.getContext(propertiesParent);
- Assert.assertNotNull(test1);
- Assert.assertEquals(1, TopiaContextFactory.contextCache.size());
-
- log.info("test 2 : with same properties, will retrieve existing" +
- " TopiaContext");
- TopiaContext test2 = TopiaContextFactory.getContext(propertiesParent);
- Assert.assertEquals(test1, test2);
- Assert.assertEquals(1, TopiaContextFactory.contextCache.size());
-
- log.info("test 3 : use other properties, will instantiate a different" +
- "TopiaContext");
- TopiaContext test3 = TopiaContextFactory.getContext(properties);
- log.debug("cache size : " + TopiaContextFactory.contextCache.size());
- log.debug("result : " + test1);
- log.debug("result3 : " + test3);
- Assert.assertNotSame(test1, test3);
- Assert.assertEquals(2, TopiaContextFactory.contextCache.size());
-
- log.info("test 4 : use other properties but equivalent to existing " +
- "TopiaContext");
- // Test flating of properties
- TopiaContext test4 = TopiaContextFactory.getContext(propertiesAll);
- Assert.assertEquals(test1, test4);
- Assert.assertEquals(2, TopiaContextFactory.contextCache.size());
-
- log.info("test5a : reinstantiate new TopiaContext after one is closed.");
- // TEST
- // Strange behavior the closed flag of context stay true if
- // hibernateFactory is not loaded from real properties
-// test1.closeContext();
-// Assert.assertTrue(test1.isClosed());
-
- // Add properties for Hibernate to have real opened topiaContext
- String databaseName = "h2data-testGetContextByPropertie";
- File f = new File(testBasedir, databaseName);
-
- properties.setProperty("hibernate.connection.username", "sa");
- properties.setProperty("hibernate.connection.password", "");
- properties.setProperty("hibernate.connection.driver_class", "org.h2.Driver");
- properties.setProperty("hibernate.connection.url",
- "jdbc:h2:file:" + f.getAbsolutePath());
-
-
- TopiaContext test5 = TopiaContextFactory.getContext(properties);
- Assert.assertNotSame(test1, test5);
- Assert.assertEquals(3, TopiaContextFactory.contextCache.size());
-
- log.info("test5b : beginTransaction to properly close the context");
- test5.beginTransaction();
-
- test5.closeContext();
-
- TopiaContext result = TopiaContextFactory.getContext(properties);
- Assert.assertNotSame(test5, result);
- Assert.assertEquals(3, TopiaContextFactory.contextCache.size());
- }
-}
Deleted: trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/framework/TopiaContextReplicateTest.java
===================================================================
--- trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/framework/TopiaContextReplicateTest.java 2012-05-09 14:37:49 UTC (rev 2451)
+++ trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/framework/TopiaContextReplicateTest.java 2012-05-09 15:07:53 UTC (rev 2452)
@@ -1,157 +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.framework;
-
-import org.junit.Assert;
-import org.junit.Rule;
-import org.junit.Test;
-import org.nuiton.topia.TopiaContext;
-import org.nuiton.topia.TopiaContextFactory;
-import org.nuiton.topia.tck.TopiaDatabase;
-import org.nuiton.topia.TopiaTckItDAOHelper;
-import org.nuiton.topia.test.entities.Person;
-import org.nuiton.topia.test.entities.PersonDAO;
-import org.nuiton.topia.test.entities.Pet;
-import org.nuiton.topia.test.entities.PetDAO;
-
-import java.io.File;
-import java.util.Properties;
-
-/**
- * To test replication sugin TopiaContext.
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @since 2.6.8
- */
-public class TopiaContextReplicateTest {
-
- @Rule
- public final TopiaDatabase dbSource =
- new TopiaDatabase() {
-
- @Override
- protected void onDbConfigurationCreate(Properties configuration, File testDir, String dbPath) {
- configuration.setProperty(
- TopiaContextFactory.CONFIG_URL, "jdbc:h2:file:" + dbPath + "-source");
-
- }
- };
-
- @Rule
- public final TopiaDatabase dbTarget =
- new TopiaDatabase() {
-
- @Override
- protected void onDbConfigurationCreate(Properties configuration, File testDir, String dbPath) {
- configuration.setProperty(
- TopiaContextFactory.CONFIG_URL, "jdbc:h2:file:" + dbPath + "-target");
-
- }
- };
-
- @Test
- public void replicateEntity() throws Exception {
-//
-// Properties configSource = TestHelper.initTopiaContextConfiguration(
-// testBasedir,
-// "/TopiaContextImpl.properties",
-// "replicateSource");
-//
-// Properties configTarget = TestHelper.initTopiaContextConfiguration(
-// testBasedir,
-// "/TopiaContextImpl.properties",
-// "replicateTarget");
-//
-
- TopiaContext contextSource = dbSource.getRootCtxt();
- TopiaContext contextTarget = dbTarget.getRootCtxt();
-
-// try {
-// contextSource = TopiaContextFactory.getContext(configSource);
-// contextTarget = TopiaContextFactory.getContext(configTarget);
-
- TopiaContext txSource;
- TopiaContext txTarget;
- PersonDAO daoSource, daoTarget;
- PetDAO petDAOSource, petDAOTarget;
- Person personSource, personTarget;
- Pet petSource, petTarget;
-
- txSource = contextSource.beginTransaction();
- daoSource = TopiaTckItDAOHelper.getPersonDAO(txSource);
- petDAOSource = TopiaTckItDAOHelper.getPetDAO(txSource);
-
- personSource = daoSource.create(Person.PROPERTY_FIRSTNAME, " firstName",
- Person.PROPERTY_NAME, " name"
- );
-
- petSource = petDAOSource.create(Pet.PROPERTY_NAME, "name",
- Pet.PROPERTY_TYPE, "type",
- Pet.PROPERTY_PERSON, personSource
- );
-
- personSource.addPet(petSource);
-
- txSource.commitTransaction();
-
- daoSource = TopiaTckItDAOHelper.getPersonDAO(txSource);
-
- personSource = daoSource.findByTopiaId(personSource.getTopiaId());
- Assert.assertNotNull(personSource);
-
- petSource = petDAOSource.findByTopiaId(petSource.getTopiaId());
- Assert.assertNotNull(petSource);
- Assert.assertEquals(1, personSource.sizePet());
- Assert.assertEquals(petSource, personSource.getPet().iterator().next());
-
- txTarget = contextTarget.beginTransaction();
-
- txSource.replicateEntity(txTarget, petSource);
- txSource.replicateEntity(txTarget, personSource);
-
- txTarget.commitTransaction();
-
- daoTarget = TopiaTckItDAOHelper.getPersonDAO(txTarget);
- petDAOTarget = TopiaTckItDAOHelper.getPetDAO(txTarget);
-
- personTarget = daoTarget.findByTopiaId(personSource.getTopiaId());
- Assert.assertNotNull(personTarget);
- Assert.assertEquals(personSource, personTarget);
- Assert.assertEquals(1, personTarget.sizePet());
-
- petTarget = petDAOTarget.findByTopiaId(petSource.getTopiaId());
- Assert.assertNotNull(petTarget);
- Assert.assertEquals(petSource, petTarget);
-
- Assert.assertEquals(petTarget, personTarget.getPet().iterator().next());
-
-
-// } finally {
-// closeDb(contextSource);
-// closeDb(contextTarget);
-// }
-
- }
-}
Modified: trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/framework/TopiaQueryTest.java
===================================================================
--- trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/framework/TopiaQueryTest.java 2012-05-09 14:37:49 UTC (rev 2451)
+++ trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/framework/TopiaQueryTest.java 2012-05-09 15:07:53 UTC (rev 2452)
@@ -45,7 +45,7 @@
TopiaQuery query = new TopiaQuery(QueriedEntity.class);
query.addEquals(QueriedEntity.PROPERTY_TEST_ADD, value);
Assert.assertEquals(
- "FROM org.nuiton.topiatest.QueriedEntity " +
+ "FROM org.nuiton.topia.tck.it.QueriedEntity " +
"WHERE testAdd = :testAdd",
query.fullQuery());
@@ -54,7 +54,7 @@
query = new TopiaQuery(QueriedEntity.class);
query.addEquals(QueriedEntity.PROPERTY_TEST_ADD, new Object[]{null});
Assert.assertEquals(
- "FROM org.nuiton.topiatest.QueriedEntity " +
+ "FROM org.nuiton.topia.tck.it.QueriedEntity " +
"WHERE testAdd IS NULL",
query.fullQuery());
@@ -63,7 +63,7 @@
query = new TopiaQuery(QueriedEntity.class);
query.addEquals(QueriedEntity.PROPERTY_TEST_ADD, value, value2);
Assert.assertEquals(
- "FROM org.nuiton.topiatest.QueriedEntity " +
+ "FROM org.nuiton.topia.tck.it.QueriedEntity " +
"WHERE testAdd IN (:testAdd1, :testAdd2)",
query.fullQuery());
@@ -71,7 +71,7 @@
query = new TopiaQuery(QueriedEntity.class);
query.addEquals(QueriedEntity.PROPERTY_TEST_ADD, value, value2, null);
Assert.assertEquals(
- "FROM org.nuiton.topiatest.QueriedEntity " +
+ "FROM org.nuiton.topia.tck.it.QueriedEntity " +
"WHERE testAdd IN (:testAdd1, :testAdd2) OR testAdd IS NULL",
query.fullQuery());
}
Deleted: trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/framework/TopiaUtilTest.java
===================================================================
--- trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/framework/TopiaUtilTest.java 2012-05-09 14:37:49 UTC (rev 2451)
+++ trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/framework/TopiaUtilTest.java 2012-05-09 15:07:53 UTC (rev 2452)
@@ -1,113 +0,0 @@
-/*
- * #%L
- * ToPIA :: Persistence
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2004 - 2010 CodeLutin
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>.
- * #L%
- */
-
-package org.nuiton.topia.framework;
-
-import org.junit.Rule;
-import org.junit.Test;
-import org.nuiton.topia.TopiaContext;
-import org.nuiton.topia.tck.TopiaDatabase;
-import org.nuiton.topia.tck.it.Personne;
-import org.nuiton.topia.test.entities.PersonImpl;
-
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
-/**
- * Test pour les methodes de {@link TopiaUtil}.
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @version $Revision$
- * <p/>
- * Last update: $Date$
- * by : $Author$
- */
-public class TopiaUtilTest {
-
- protected static final String PERSON_ID = "org.nuiton.topiatest.Personne#1226701039001#0.6502325993664224";
-
- protected static final String PERSON_ID2 = "org.nuiton.topiatest.Personne#1226701039001#0.6502325993664999";
-
- @Rule
- public final TopiaDatabase db = new TopiaDatabase();
-
- @Test
- public void testGetTopiaIdPattern() throws Exception {
- String expected;
- String actual;
-
- expected = "org\\.nuiton\\.topiatest\\.Personne#(?:\\d+?)#(?:\\d+)\\.(?:\\d+)";
- actual = TopiaUtil.getTopiaIdPattern(Personne.class);
- assertEquals(expected, actual);
- }
-
- @Test
- public void testGetTopiaPattern() throws Exception {
- String expected;
- Pattern pattern;
-
- expected = "(\\d+)-(org\\.nuiton\\.topiatest\\.Personne#(?:\\d+?)#(?:\\d+)\\.(?:\\d+))-(org\\.nuiton\\.topiatest\\.Personne#(?:\\d+?)#(?:\\d+)\\.(?:\\d+))(.*)";
- pattern = TopiaUtil.getTopiaPattern("(\\d+)-%1$s-%1$s(.*)", Personne.class);
- assertEquals(expected, pattern.toString());
-
- String expression = 123 + "-" + PERSON_ID + "-" + PERSON_ID2 + "-afterall";
-
- Matcher matcher = pattern.matcher(expression);
-
- assertTrue(matcher.matches());
-
- assertTrue(matcher.matches());
- assertEquals(4, matcher.groupCount());
- assertEquals("123", matcher.group(1));
- assertEquals(PERSON_ID, matcher.group(2));
- assertEquals(PERSON_ID2, matcher.group(3));
- assertEquals("-afterall", matcher.group(4));
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void testIsSchemaExistFailed() throws Exception {
- TopiaUtil.isSchemaExist(db.getRootCtxt(), "fake");
- }
-
- @Test
- public void testIsSchemaExist() throws Exception {
- TopiaContext rootContext = db.getRootCtxt();
- boolean actual = TopiaUtil.isSchemaExist(rootContext,
- PersonImpl.class.getName());
-
- assertFalse(actual);
- TopiaContext tx = rootContext.beginTransaction();
-
- tx.createSchema();
- actual = TopiaUtil.isSchemaExist(rootContext, PersonImpl.class.getName());
-
- assertTrue(actual);
-
- }
-}
Deleted: trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/persistence/EntityVisitorExportXmlTest.java
===================================================================
--- trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/persistence/EntityVisitorExportXmlTest.java 2012-05-09 14:37:49 UTC (rev 2451)
+++ trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/persistence/EntityVisitorExportXmlTest.java 2012-05-09 15:07:53 UTC (rev 2452)
@@ -1,132 +0,0 @@
-/*
- * #%L
- * ToPIA :: Persistence
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2004 - 2010 CodeLutin
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>.
- * #L%
- */
-
-package org.nuiton.topia.persistence;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.junit.Before;
-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.TopiaTckItDAOHelper;
-import org.nuiton.topia.tck.it.Address;
-import org.nuiton.topia.tck.it.AddressDAO;
-import org.nuiton.topia.tck.it.Company;
-import org.nuiton.topia.tck.it.CompanyDAO;
-import org.nuiton.topia.tck.it.Department;
-import org.nuiton.topia.tck.it.DepartmentDAO;
-import org.nuiton.topia.tck.it.Employe;
-import org.nuiton.topia.tck.it.EmployeDAO;
-
-/**
- * Test de visitor.
- *
- * @author chatellier
- * @version $Revision$
- * <p/>
- * Last update : $Date$
- * By : $Author$
- */
-public class EntityVisitorExportXmlTest {
-
- private static final Log log =
- LogFactory.getLog(EntityVisitorExportXmlTest.class);
-
- @Rule
- public final TopiaDatabase db = new TopiaDatabase();
-
- /**
- * Prepare test.
- * <p/>
- * Add all tests commons data
- *
- * @throws TopiaException if could not create datas
- */
- @Before
- public void setUp() throws TopiaException {
-
- TopiaContext newContext = db.beginTransaction();
- try {
- // company
- CompanyDAO companyDAO = TopiaTckItDAOHelper.getCompanyDAO(newContext);
- Company clCompany = companyDAO.create(Company.PROPERTY_NAME, "CodeLutin");
-
- // employe
- EmployeDAO employeDAO = TopiaTckItDAOHelper.getEmployeDAO(newContext);
- Employe empl1 = employeDAO.create(Employe.PROPERTY_NAME, "boss", Employe.PROPERTY_SALARY, 30000);
-
- AddressDAO adressDAO = TopiaTckItDAOHelper.getAddressDAO(newContext);
- Address addr1 = adressDAO.create(Address.PROPERTY_CITY, "Nantes", Address.PROPERTY_ADRESS, "12 Avenue Jules Vernes");
- empl1.setAddress(addr1);
-
- Employe empl2 = employeDAO.create(Employe.PROPERTY_NAME, "boss2", Employe.PROPERTY_SALARY, 29000);
- Address addr2 = adressDAO.create(Address.PROPERTY_CITY, "Nantes", Address.PROPERTY_ADRESS, "12 Avenue Jules Vernes");
- empl2.setAddress(addr2);
-
- // departement
- DepartmentDAO departmentDAO = TopiaTckItDAOHelper.getDepartmentDAO(newContext);
- Department depComm = departmentDAO.create(Department.PROPERTY_NAME, "Commercial");
- depComm.setLeader(empl1);
-
- Department depDev = departmentDAO.create(Department.PROPERTY_NAME, "Dev");
- depDev.setLeader(empl2);
- clCompany.addDepartment(depComm);
- clCompany.addDepartment(depDev);
-
- newContext.commitTransaction();
- } finally {
-
- newContext.closeContext();
- }
- }
-
-
- /**
- * Test l'export XML via un visiteur.
- * <p/>
- * Parcourt en profondeur.
- *
- * @throws TopiaException
- */
- @Test
- public void testExportXMLDepth() throws TopiaException {
-
- TopiaContext context = db.beginTransaction();
-
- CompanyDAO companyDAO = TopiaTckItDAOHelper.getCompanyDAO(context);
- Company clCompany = companyDAO.findByName("CodeLutin");
-
- EntityVisitor delegateVisitor = new ExportXMLVisitor();
- EntityVisitor visitor = new DepthEntityVisitor(delegateVisitor);
- clCompany.accept(visitor);
-
- if (log.isInfoEnabled()) {
- log.info("Export XML = \n" + delegateVisitor.toString());
- }
- }
-}
Deleted: trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/persistence/ExportXMLVisitor.java
===================================================================
--- trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/persistence/ExportXMLVisitor.java 2012-05-09 14:37:49 UTC (rev 2451)
+++ trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/persistence/ExportXMLVisitor.java 2012-05-09 15:07:53 UTC (rev 2452)
@@ -1,107 +0,0 @@
-/*
- * #%L
- * ToPIA :: Persistence
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2004 - 2010 CodeLutin
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>.
- * #L%
- */
-
-package org.nuiton.topia.persistence;
-
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.junit.Ignore;
-
-/**
- * Visitor pour export xml.
- *
- * @author chatellier
- * @version $Revision$
- * <p/>
- * Last update : $Date$
- * By : $Author$
- */
-@Ignore
-public class ExportXMLVisitor implements EntityVisitor {
-
- /** log. */
- private static Log log = LogFactory.getLog(ExportXMLVisitor.class);
-
- protected StringBuffer buffer;
-
- public ExportXMLVisitor() {
- buffer = new StringBuffer();
- }
-
- @Override
- public void start(TopiaEntity e) {
- if (log.isDebugEnabled()) {
- log.debug("start : " + e);
- }
-
- buffer.append("<").append(e.getClass().getName());
- buffer.append(" topiaId=\"").append(e.getTopiaId()).append("\"");
- buffer.append(" topiaCreateDate=\"").append(e.getTopiaCreateDate()).append("\"");
- buffer.append(" topiaVersion=\"").append(e.getTopiaVersion()).append("\"");
- buffer.append(">\n");
- }
-
- @Override
- public void visit(TopiaEntity e, String name, Class<?> type, Object value) {
- if (log.isDebugEnabled()) {
- log.debug("visit : " + e);
- }
-
- buffer.append("<").append(type.getName()).append(">").append(value).append("</").append(type.getName()).append(">\n");
- }
-
- @Override
- public void visit(TopiaEntity e, String name, Class<?> collectionType, Class<?> type,
- Object value) {
- }
-
- @Override
- public void visit(TopiaEntity e, String name, Class<?> collectionType, Class<?> type, int index, Object value) {
- visit(e, name, type, value);
- }
-
- @Override
- public void end(TopiaEntity e) {
- if (log.isDebugEnabled()) {
- log.debug("end : " + e);
- }
-
- buffer.append("</").append(e.getClass().getName()).append(">\n");
- }
-
- @Override
- public String toString() {
- String content = buffer.toString();
- return content;
- }
-
- @Override
- public void clear() {
- // do nothing
- }
-
-
-}
Deleted: trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/persistence/NaturalIdTest.java
===================================================================
--- trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/persistence/NaturalIdTest.java 2012-05-09 14:37:49 UTC (rev 2451)
+++ trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/persistence/NaturalIdTest.java 2012-05-09 15:07:53 UTC (rev 2452)
@@ -1,177 +0,0 @@
-/*
- * #%L
- * ToPIA :: Persistence
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2004 - 2010 CodeLutin
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>.
- * #L%
- */
-
-package org.nuiton.topia.persistence;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-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.TopiaTckItDAOHelper;
-import org.nuiton.topia.tck.it.NaturalizedEntity;
-import org.nuiton.topia.tck.it.NaturalizedEntityDAO;
-
-/**
- * NaturalIdTest
- * <p/>
- * Created: 18 févr. 2010
- *
- * @author fdesbois
- * @version $Revision$
- * <p/>
- * Mise a jour: $Date$
- * par : $Author$
- */
-public class NaturalIdTest {
-
- private static final Log log = LogFactory.getLog(NaturalIdTest.class);
-
- @Rule
- public final TopiaDatabase db = new TopiaDatabase();
-
- @Test
- public void testCreateSucessfull() throws Exception {
- log.debug("Test naturalId : create succesfull");
- TopiaContext transaction = db.beginTransaction();
-
- NaturalizedEntityDAO dao =
- TopiaTckItDAOHelper.getNaturalizedEntityDAO(transaction);
-
- // No exception will be thrown with the two properties
- dao.createByNaturalId(5, "str");
- transaction.commitTransaction();
-
- // No exception will only the need property
- dao.createByNotNull(3);
- transaction.commitTransaction();
-
- // No exception will only the need property
- dao.create(NaturalizedEntity.PROPERTY_NATURAL_ID_NOT_NULL, 3);
- transaction.commitTransaction();
- }
-
- @Test
- public void testCreateFailed() throws Exception {
- log.debug("Test naturalId : create failed");
- TopiaContext transaction = db.beginTransaction();
-
- NaturalizedEntityDAO dao =
- TopiaTckItDAOHelper.getNaturalizedEntityDAO(transaction);
-
- // Exception will be throw
-// try {
- dao.create();
- transaction.commitTransaction();
-
- // Note : this is possible to create an empty entity if the type
- // is primitive like 'int' which have a default value of '0'
-// } catch (PropertyValueException eee) {
-// Assert.assertEquals("naturalIdNotNull", eee.getPropertyName());
-// }
- }
-
- @Test
- public void testUpdateFailed() throws Exception {
- log.debug("Test naturalId : update failed");
-
- TopiaContext transaction = db.beginTransaction();
-
- NaturalizedEntityDAO dao =
- TopiaTckItDAOHelper.getNaturalizedEntityDAO(transaction);
-
- NaturalizedEntity entity =
- dao.createByNaturalId(5, "str");
- transaction.commitTransaction();
-
- // Exception will be throw : not allowed to modify a naturalId property
- try {
- entity.setNaturalIdNotNull(8);
- transaction.commitTransaction();
- } catch (TopiaException eee) {
- Assert.assertEquals("org.hibernate.HibernateException",
- eee.getCause().getClass().getName());
- }
- }
-
- @Test
- public void testFindByNaturalId() throws Exception {
- log.debug("Test naturalId : findByNaturalId");
- TopiaContext transaction = db.beginTransaction();
-
- NaturalizedEntityDAO dao =
- TopiaTckItDAOHelper.getNaturalizedEntityDAO(transaction);
-
- NaturalizedEntity entity =
- dao.createByNaturalId(5, "str");
- transaction.commitTransaction();
-
- NaturalizedEntity result = dao.findByNaturalId(5, "str");
-
- Assert.assertEquals(entity, result);
- }
-
- @Test
- public void testExistNaturalId() throws Exception {
- log.debug("Test naturalId : existNaturalId");
- TopiaContext transaction = db.beginTransaction();
-
- NaturalizedEntityDAO dao =
- TopiaTckItDAOHelper.getNaturalizedEntityDAO(transaction);
-
- dao.createByNaturalId(5, "str");
- transaction.commitTransaction();
-
- boolean result = dao.existByNaturalId(5, "str");
-
- Assert.assertTrue(result);
-
- // not find with only one correct property
- result = dao.existByNaturalId(8, "str");
-
- Assert.assertFalse(result);
- }
-
- @Test
- public void testNaturalIdAreGeneralized() throws Exception {
-
- // test that natural ids are generalized
- String[] generalizedNaturalizedNaturalIds = TopiaTckItDAOHelper.TopiaTckItEntityEnum.GeneralizedNaturalizedEntity.getNaturalIds();
- String[] naturalizedNaturalIds = TopiaTckItDAOHelper.TopiaTckItEntityEnum.NaturalizedEntity.getNaturalIds();
- Assert.assertArrayEquals(generalizedNaturalizedNaturalIds, naturalizedNaturalIds);
- }
-
- @Test
- public void testNotNullsAreGeneralized() throws Exception {
-
- // test that not nulls are generalized
- String[] generalizedNaturalizedNotNulls = TopiaTckItDAOHelper.TopiaTckItEntityEnum.GeneralizedNaturalizedEntity.getNotNulls();
- String[] naturalizedNotNulls = TopiaTckItDAOHelper.TopiaTckItEntityEnum.NaturalizedEntity.getNotNulls();
- Assert.assertArrayEquals(generalizedNaturalizedNotNulls, naturalizedNotNulls);
- }
-}
1
0
Author: athimel
Date: 2012-05-09 16:37:49 +0200 (Wed, 09 May 2012)
New Revision: 2451
Url: http://nuiton.org/repositories/revision/topia/2451
Log:
Fix package name in <model>.properties file
Modified:
trunk/topia-persistence-tck/src/main/xmi/topia-tck-it.properties
Modified: trunk/topia-persistence-tck/src/main/xmi/topia-tck-it.properties
===================================================================
--- trunk/topia-persistence-tck/src/main/xmi/topia-tck-it.properties 2012-05-09 14:32:00 UTC (rev 2450)
+++ trunk/topia-persistence-tck/src/main/xmi/topia-tck-it.properties 2012-05-09 14:37:49 UTC (rev 2451)
@@ -27,13 +27,13 @@
model.tagvalue.constantPrefix=PROPERTY_
model.tagvalue.generateDTOTopiaId=true
-#org.nuiton.topiatest.Company.class.tagvalue.naturalIdMutable=false
-#org.nuiton.topiatest.Company.attribute.siret.tagvalue.naturalId=true
-#org.nuiton.topiatest.Company.attribute.name.tagvalue.naturalId=true
-#org.nuiton.topiatest.Company.attribute.name.tagvalue.notNull=false
+#org.nuiton.topia.tck.it.Company.class.tagvalue.naturalIdMutable=false
+#org.nuiton.topia.tck.it.Company.attribute.siret.tagvalue.naturalId=true
+#org.nuiton.topia.tck.it.Company.attribute.name.tagvalue.naturalId=true
+#org.nuiton.topia.tck.it.Company.attribute.name.tagvalue.notNull=false
-org.nuiton.topiatest.NaturalizedEntity.attribute.naturalIdNotNull.tagvalue.naturalId=true
-org.nuiton.topiatest.NaturalizedEntity.attribute.naturalIdNull.tagvalue.naturalId=true
-org.nuiton.topiatest.NaturalizedEntity.attribute.naturalIdNull.tagvalue.notNull=false
+org.nuiton.topia.tck.it.NaturalizedEntity.attribute.naturalIdNotNull.tagvalue.naturalId=true
+org.nuiton.topia.tck.it.NaturalizedEntity.attribute.naturalIdNull.tagvalue.naturalId=true
+org.nuiton.topia.tck.it.NaturalizedEntity.attribute.naturalIdNull.tagvalue.notNull=false
-org.nuiton.topiatest.Personne.attribute.otherGender.tagValue.useEnumerationName=true
\ No newline at end of file
+org.nuiton.topia.tck.it.Personne.attribute.otherGender.tagValue.useEnumerationName=true
\ No newline at end of file
1
0