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
October 2013
- 7 participants
- 62 discussions
r2844 - trunk/topia-persistence/src/main/java/org/nuiton/topia
by athimel@users.nuiton.org 11 Oct '13
by athimel@users.nuiton.org 11 Oct '13
11 Oct '13
Author: athimel
Date: 2013-10-12 00:50:35 +0200 (Sat, 12 Oct 2013)
New Revision: 2844
Url: http://nuiton.org/projects/topia/repository/revisions/2844
Log:
code style in AbstractTopiaPersistenceContext
Modified:
trunk/topia-persistence/src/main/java/org/nuiton/topia/AbstractTopiaPersistenceContext.java
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/AbstractTopiaPersistenceContext.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/AbstractTopiaPersistenceContext.java 2013-10-11 22:40:03 UTC (rev 2843)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/AbstractTopiaPersistenceContext.java 2013-10-11 22:50:35 UTC (rev 2844)
@@ -35,7 +35,6 @@
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
import org.nuiton.topia.framework.TopiaFiresSupport;
-import org.nuiton.topia.framework.TopiaHibernateEventListener;
import org.nuiton.topia.persistence.AbstractTopiaDAO;
import org.nuiton.topia.persistence.TopiaDAO;
import org.nuiton.topia.persistence.TopiaEntity;
@@ -243,11 +242,14 @@
hibernateFactory.getClassMetadata(entityClass.getName() + "Impl") == null &&
hibernateFactory.getClassMetadata(entityClass.getName() + "Abstract") == null) {
- log.info(String.format("List of supported persistence classes: %s",
- hibernateFactory.getAllClassMetadata().keySet()));
- throw new TopiaException(
- String.format("The following entity type %s is not managed by this context, you probably forgot to declare it.",
- entityClass.getName()));
+ if (log.isInfoEnabled()) {
+ String format = "List of supported persistence classes: %s";
+ String message = String.format(format, hibernateFactory.getAllClassMetadata().keySet());
+ log.info(message);
+ }
+ String format = "The following entity type %s is not managed by this context, you probably forgot to declare it.";
+ String message = String.format(format, entityClass.getName());
+ throw new TopiaException(message);
}
TopiaDAO<E> dao = (TopiaDAO<E>) daoCache.get(entityClass);
1
0
11 Oct '13
Author: athimel
Date: 2013-10-12 00:40:03 +0200 (Sat, 12 Oct 2013)
New Revision: 2843
Url: http://nuiton.org/projects/topia/repository/revisions/2843
Log:
Migrate tests to the new ToPIa architecture
Added:
trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaHibernateEventListener.java
trunk/topia-persistence/src/test/java/org/nuiton/topia/TopiaJpaSupportTest.java
Removed:
trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/TopiaContextFindTest.java
Modified:
trunk/topia-persistence/src/main/java/org/nuiton/topia/AbstractTopiaApplicationContext.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/AbstractTopiaPersistenceContext.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/HibernateProvider.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/HibernateTopiaJpaSupport.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/HibernateTopiaReplicationSupport.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaJpaSupport.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaPersistenceContext.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaReplicationDestination.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaServiceSupportImpl.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/AbstractTopiaContext.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaFiresSupport.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaUtil.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/ApplicationContextTransformer.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/DAOHelperTransformer.java
trunk/topia-persistence/src/test/java/org/nuiton/topia/TopiaDatabase.java
trunk/topia-persistence/src/test/java/org/nuiton/topia/framework/TopiaConnectionProviderTest.java
trunk/topia-persistence/src/test/java/org/nuiton/topia/framework/TopiaContextReplicateTest.java
trunk/topia-persistence/src/test/java/org/nuiton/topia/framework/TopiaUtilTest.java
trunk/topia-persistence/src/test/java/org/nuiton/topia/generator/TopiaTestCase.java
trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/EntityVisitorExportXmlTest.java
trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/NaturalIdTest.java
trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/TopiaDAOTest.java
trunk/topia-persistence/src/test/java/org/nuiton/topia/test/ano1882/DAOAbstractTransformerTest.java
trunk/topia-persistence/src/test/java/org/nuiton/topiatest/EnumTest.java
trunk/topia-persistence/src/test/java/org/nuiton/topiatest/deletetest/DeleteEntityTest.java
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/AbstractTopiaApplicationContext.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/AbstractTopiaApplicationContext.java 2013-10-11 16:53:04 UTC (rev 2842)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/AbstractTopiaApplicationContext.java 2013-10-11 22:40:03 UTC (rev 2843)
@@ -26,12 +26,16 @@
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.HibernateException;
import org.hibernate.cfg.Configuration;
+import org.hibernate.engine.spi.SessionFactoryImplementor;
+import org.hibernate.service.jdbc.connections.spi.ConnectionProvider;
+import org.hibernate.service.spi.Stoppable;
import org.hibernate.tool.hbm2ddl.SchemaExport;
import org.hibernate.tool.hbm2ddl.SchemaUpdate;
import org.nuiton.topia.event.TopiaEntitiesVetoable;
@@ -40,6 +44,7 @@
import org.nuiton.topia.event.TopiaSchemaListener;
import org.nuiton.topia.event.TopiaTransactionListener;
import org.nuiton.topia.event.TopiaTransactionVetoable;
+import org.nuiton.topia.framework.TopiaContextImplementor;
import org.nuiton.topia.framework.TopiaFiresSupport;
import org.nuiton.topia.framework.TopiaService;
import org.nuiton.topia.framework.TopiaUtil;
@@ -48,6 +53,7 @@
import org.nuiton.topia.persistence.TopiaIdFactory;
import java.beans.PropertyChangeListener;
+import java.lang.ref.WeakReference;
import java.util.List;
import java.util.Map;
import java.util.Properties;
@@ -74,6 +80,10 @@
protected HibernateProvider hibernateProvider;
+ protected boolean closed = false;
+
+ protected List<WeakReference<TopiaPersistenceContext>> persistenceContexts = Lists.newArrayList(); // TODO AThimel 11/10/13 Which implementation ?
+
public abstract K newPersistenceContext();
public AbstractTopiaApplicationContext(Properties properties) {
@@ -89,6 +99,8 @@
}
this.configuration = ImmutableMap.copyOf(configurationCopy);
this.topiaServiceSupport = new TopiaServiceSupportImpl(this);
+ // FIXME AThimel 11/10/13 This is not nice, need a 2-step init because of mutual dependency with hibernateProvider
+ ((TopiaServiceSupportImpl)this.topiaServiceSupport).init();
}
protected abstract Class<? extends TopiaEntity>[] getImplementationClasses();
@@ -101,6 +113,10 @@
return buffer.substring(1);
}
+ protected void registerPersistenceContext(TopiaPersistenceContext persistenceContext) {
+ persistenceContexts.add(new WeakReference<TopiaPersistenceContext>(persistenceContext));
+ }
+
protected HibernateProvider getHibernateProvider() {
if (hibernateProvider == null) {
hibernateProvider = new HibernateProvider(configuration, topiaServiceSupport);
@@ -336,4 +352,29 @@
}
}
+ public void closeContext() throws TopiaException {
+ // Throw exception if context is already closed
+ Preconditions.checkState(!closed, "Context was already closed");
+
+ // TODO AThimel 11/10/13 Implement close on persistence contexts
+// // Remove all children context
+// for (TopiaPersistenceContext child : getChildContext()) {
+// // Avoid to have exception from checkClosed method on child
+// if (!child.isClosed()) {
+// child.close();
+// }
+// }
+
+ hibernateProvider.close();
+ closed = true;
+
+ if (log.isDebugEnabled()) {
+ log.debug("TopiaApplicationContext closed");
+ }
+ }
+
+ public boolean isClosed() {
+ return closed;
+ }
+
}
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/AbstractTopiaPersistenceContext.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/AbstractTopiaPersistenceContext.java 2013-10-11 16:53:04 UTC (rev 2842)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/AbstractTopiaPersistenceContext.java 2013-10-11 22:40:03 UTC (rev 2843)
@@ -35,6 +35,7 @@
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
import org.nuiton.topia.framework.TopiaFiresSupport;
+import org.nuiton.topia.framework.TopiaHibernateEventListener;
import org.nuiton.topia.persistence.AbstractTopiaDAO;
import org.nuiton.topia.persistence.TopiaDAO;
import org.nuiton.topia.persistence.TopiaEntity;
@@ -109,6 +110,7 @@
this.listenableSupport = listenableSupport;
this.topiaIdFactory = topiaIdFactory;
+ this.firesSupport = new TopiaFiresSupport();
// Hibernate support can be created using the given hibernateProvider
this.hibernateSupport = new InternalTopiaHibernateSupport(hibernateProvider);
@@ -117,7 +119,6 @@
startTransaction();
// Create the different supports that may be needed by the DAOs
- this.firesSupport = new TopiaFiresSupport();
this.jpaSupport = new HibernateTopiaJpaSupport(hibernateSupport, firesSupport);
this.sqlSupport = new HibernateTopiaSqlSupport(hibernateSupport);
}
@@ -355,7 +356,7 @@
}
@Override
- public void close() {
+ public void closeContext() {
checkClosed();
closed = true;
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/HibernateProvider.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/HibernateProvider.java 2013-10-11 16:53:04 UTC (rev 2842)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/HibernateProvider.java 2013-10-11 22:40:03 UTC (rev 2843)
@@ -42,7 +42,9 @@
import org.hibernate.event.spi.EventType;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.service.ServiceRegistryBuilder;
-import org.nuiton.topia.framework.TopiaFiresSupport;
+import org.hibernate.service.jdbc.connections.spi.ConnectionProvider;
+import org.hibernate.service.spi.Stoppable;
+import org.nuiton.topia.framework.TopiaHibernateEventListener;
import org.nuiton.topia.framework.TopiaService;
import org.nuiton.topia.framework.TopiaUtil;
@@ -193,6 +195,18 @@
return hibernateConfiguration;
}
+ public void close() {
+ if (hibernateSessionFactory != null) {
+ hibernateSessionFactory.close();
+ // close connection provider if possible (http://nuiton.org/issues/2757)
+ ConnectionProvider service = ((SessionFactoryImplementor) hibernateSessionFactory).getServiceRegistry().getService(ConnectionProvider.class);
+ if (service instanceof Stoppable) {
+ Stoppable stoppable = (Stoppable) service;
+ stoppable.stop();
+ }
+ }
+ }
+
public SessionFactory getSessionFactory() {
if (hibernateSessionFactory == null) {
@@ -208,7 +222,7 @@
ServiceRegistry serviceRegistryInit = ((SessionFactoryImplementor) hibernateSessionFactory).getServiceRegistry();
EventListenerRegistry eventListenerRegistry = serviceRegistryInit.getService(EventListenerRegistry.class);
// TopiaFiresSupport.TopiaHibernateEvent listener = new TopiaFiresSupport.TopiaHibernateEvent(this);
- TopiaFiresSupport.TopiaHibernateEvent listener = new TopiaFiresSupport.TopiaHibernateEvent(null); // FIXME AThimel 11/10/13 Give a correct instance
+ TopiaHibernateEventListener listener = new TopiaHibernateEventListener(null); // FIXME AThimel 11/10/13 Give a correct instance
eventListenerRegistry.appendListeners(EventType.PRE_INSERT, listener);
eventListenerRegistry.appendListeners(EventType.PRE_LOAD, listener);
eventListenerRegistry.appendListeners(EventType.PRE_UPDATE, listener);
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/HibernateTopiaJpaSupport.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/HibernateTopiaJpaSupport.java 2013-10-11 16:53:04 UTC (rev 2842)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/HibernateTopiaJpaSupport.java 2013-10-11 22:40:03 UTC (rev 2843)
@@ -24,6 +24,10 @@
* #L%
*/
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.FlushMode;
@@ -32,10 +36,6 @@
import org.nuiton.topia.framework.TopiaFiresSupport;
import org.nuiton.topia.framework.TopiaUtil;
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
-
/**
* This class is the Hibernate implementation of TopiaJpaSupport. It realizes the bridge between the JPA specification
* and the technical choice made for its implementation : Hibernate.
@@ -119,6 +119,27 @@
}
@Override
+ public <T> T findUnique(String jpaql, Map<String, Object> parameters) {
+
+ // Execute query, and ask for up to 2 results only
+ List<T> results = find(jpaql, 0, 1, parameters);
+
+ // If there is more than 1 result, throw an exception
+ if (results.size() > 1) {
+ String message = String.format(
+ "Query '%s' returns more than 1 unique result", jpaql);
+ throw new TopiaException(message);
+ }
+
+ // otherwise return the first one, or null
+ T result = null;
+ if (!results.isEmpty()) {
+ result = results.get(0);
+ }
+ return result;
+ }
+
+ @Override
public <T> List<T> find(String jpaql, int startIndex, int endIndex, Map<String, Object> parameters) {
try {
Query query = prepareQuery(jpaql, parameters);
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/HibernateTopiaReplicationSupport.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/HibernateTopiaReplicationSupport.java 2013-10-11 16:53:04 UTC (rev 2842)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/HibernateTopiaReplicationSupport.java 2013-10-11 22:40:03 UTC (rev 2843)
@@ -1,5 +1,29 @@
package org.nuiton.topia;
+/*
+ * #%L
+ * ToPIA :: Persistence
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2004 - 2013 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%
+ */
+
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.HibernateException;
Property changes on: trunk/topia-persistence/src/main/java/org/nuiton/topia/HibernateTopiaReplicationSupport.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaJpaSupport.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaJpaSupport.java 2013-10-11 16:53:04 UTC (rev 2842)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaJpaSupport.java 2013-10-11 22:40:03 UTC (rev 2843)
@@ -117,10 +117,25 @@
* support something else than queries on TopiaEntity
*
* @param jpaql the JPA-QL query
+ * @param parameters a map which keys are the attribute names and values are the attributes expected values
+ * @return The result instance or null
+ */
+ <T> T findUnique(String jpaql,
+ Map<String, Object> parameters);
+
+ /**
+ * Allow to do some JPA-QL query and return an unique result. If nothing if
+ * found by the query, will return null. If more than one result is found,
+ * will throw an exception.
+ * <p/>
+ * WARNING : Depending on the registered service, this method may not
+ * support something else than queries on TopiaEntity
+ *
+ * @param jpaql the JPA-QL query
* @param propertyNamesAndValues the query parameters. Arguments are key-value paired :
* [propertyName;value;propertyName;value;...]
* @return The result instance or null
- * @deprecated prefer using {@link #find(String, int, int, java.util.Map)}
+ * @deprecated prefer using {@link #findUnique(String, java.util.Map)}
*/
@Deprecated
<T> T findUnique(String jpaql,
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaPersistenceContext.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaPersistenceContext.java 2013-10-11 16:53:04 UTC (rev 2842)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaPersistenceContext.java 2013-10-11 22:40:03 UTC (rev 2843)
@@ -68,7 +68,7 @@
* Closes the context. All the children contexts will be closed in the same
* time.
*/
- void close();
+ void closeContext();
/**
* Tells if the context is closed
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaReplicationDestination.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaReplicationDestination.java 2013-10-11 16:53:04 UTC (rev 2842)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaReplicationDestination.java 2013-10-11 22:40:03 UTC (rev 2843)
@@ -1,5 +1,29 @@
package org.nuiton.topia;
+/*
+ * #%L
+ * ToPIA :: Persistence
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2004 - 2013 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%
+ */
+
import org.nuiton.topia.persistence.TopiaEntity;
/**
Property changes on: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaReplicationDestination.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaServiceSupportImpl.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaServiceSupportImpl.java 2013-10-11 16:53:04 UTC (rev 2842)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaServiceSupportImpl.java 2013-10-11 22:40:03 UTC (rev 2843)
@@ -49,6 +49,9 @@
public TopiaServiceSupportImpl(AbstractTopiaApplicationContext applicationContext) {
this.applicationContext = applicationContext;
this.services = loadServices(applicationContext.getConfiguration());
+ }
+
+ public void init() {
preInitServices(this.services);
applicationContext.getHibernateProvider().getHibernateConfiguration(); // force mapping loading
postInitServices(this.services);
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/AbstractTopiaContext.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/AbstractTopiaContext.java 2013-10-11 16:53:04 UTC (rev 2842)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/AbstractTopiaContext.java 2013-10-11 22:40:03 UTC (rev 2843)
@@ -579,7 +579,7 @@
// we must call getServiceRegistry on factory to get a working one
ServiceRegistry serviceRegistryInit = ((SessionFactoryImplementor) hibernateFactory).getServiceRegistry();
EventListenerRegistry eventListenerRegistry = serviceRegistryInit.getService(EventListenerRegistry.class);
- TopiaFiresSupport.TopiaHibernateEvent listener = new TopiaFiresSupport.TopiaHibernateEvent(this);
+ TopiaHibernateEventListener listener = new TopiaHibernateEventListener(this);
eventListenerRegistry.appendListeners(EventType.PRE_INSERT, listener);
eventListenerRegistry.appendListeners(EventType.PRE_LOAD, listener);
eventListenerRegistry.appendListeners(EventType.PRE_UPDATE, listener);
@@ -613,7 +613,8 @@
if (log.isDebugEnabled()) {
log.debug("Load persistence from dir : " + dir);
}
- hibernateConfiguration.addDirectory(new File(dir));
+ File dirFile = new File(dir);
+ hibernateConfiguration.addDirectory(dirFile);
}
}
@@ -891,11 +892,6 @@
}
@Override
- public void close() {
- closeContext();
- }
-
- @Override
public void closeContext() throws TopiaException {
// Throw exception if context is already closed
checkClosed("Context was already closed");
@@ -1019,20 +1015,8 @@
checkClosed(String.format("This context is closed, it is not possible to release the operation '%1$s'",
"findUnique"));
- List<E> results = find(jpaql, 0, 1, propertyNamesAndValues);
-
- // If there is more than 1 result, throw an exception
- if (results.size() > 1) {
- String message = String.format(
- "Query '%s' returns more than 1 unique result", jpaql);
- throw new TopiaException(message);
- }
-
- // otherwise return the first one, or null
- E result = null;
- if (!results.isEmpty()) {
- result = results.get(0);
- }
+ Map<String, Object> parameters = TopiaUtil.convertPropertiesArrayToMap(propertyNamesAndValues);
+ E result = findUnique(jpaql, parameters);
return result;
}
@@ -1113,6 +1097,26 @@
}
@Override
+ public <T> T findUnique(String jpaql, Map<String, Object> parameters) {
+
+ List<T> results = find(jpaql, 0, 1, parameters);
+
+ // If there is more than 1 result, throw an exception
+ if (results.size() > 1) {
+ String message = String.format(
+ "Query '%s' returns more than 1 unique result", jpaql);
+ throw new TopiaException(message);
+ }
+
+ // otherwise return the first one, or null
+ T result = null;
+ if (!results.isEmpty()) {
+ result = results.get(0);
+ }
+ return result;
+ }
+
+ @Override
public int execute(String jpaql, Map<String, Object> parameters) {
checkClosed(String.format("This context is closed, it is not possible to release the operation '%1$s'",
"find"));
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaFiresSupport.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaFiresSupport.java 2013-10-11 16:53:04 UTC (rev 2842)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaFiresSupport.java 2013-10-11 22:40:03 UTC (rev 2843)
@@ -25,33 +25,19 @@
package org.nuiton.topia.framework;
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+import java.beans.PropertyChangeSupport;
+import java.beans.VetoableChangeSupport;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
import org.apache.commons.collections.map.IdentityMap;
-import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.hibernate.HibernateException;
-import org.hibernate.Session;
-import org.hibernate.event.spi.PostDeleteEvent;
-import org.hibernate.event.spi.PostDeleteEventListener;
-import org.hibernate.event.spi.PostInsertEvent;
-import org.hibernate.event.spi.PostInsertEventListener;
-import org.hibernate.event.spi.PostLoadEvent;
-import org.hibernate.event.spi.PostLoadEventListener;
-import org.hibernate.event.spi.PostUpdateEvent;
-import org.hibernate.event.spi.PostUpdateEventListener;
-import org.hibernate.event.spi.PreDeleteEvent;
-import org.hibernate.event.spi.PreDeleteEventListener;
-import org.hibernate.event.spi.PreInsertEvent;
-import org.hibernate.event.spi.PreInsertEventListener;
-import org.hibernate.event.spi.PreLoadEvent;
-import org.hibernate.event.spi.PreLoadEventListener;
-import org.hibernate.event.spi.PreUpdateEvent;
-import org.hibernate.event.spi.PreUpdateEventListener;
-import org.hibernate.event.spi.SaveOrUpdateEvent;
-import org.hibernate.event.spi.SaveOrUpdateEventListener;
-import org.nuiton.topia.TopiaContext;
-import org.nuiton.topia.TopiaDAOSupplier;
-import org.nuiton.topia.TopiaException;
import org.nuiton.topia.TopiaJpaSupport;
import org.nuiton.topia.TopiaListenableSupport;
import org.nuiton.topia.TopiaPersistenceContext;
@@ -70,20 +56,9 @@
import org.nuiton.topia.event.TopiaTransactionVetoable;
import org.nuiton.topia.persistence.AbstractTopiaDAO;
import org.nuiton.topia.persistence.TopiaEntity;
-import org.nuiton.topia.persistence.TopiaEntityContextable;
import org.nuiton.util.CategorisedListenerSet;
import org.nuiton.util.ListenerSet;
-import java.beans.PropertyChangeEvent;
-import java.beans.PropertyChangeListener;
-import java.beans.PropertyChangeSupport;
-import java.beans.VetoableChangeSupport;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
/**
* TODO-fdesbois-20100507 : Need translation of javadoc.
* <p/>
@@ -95,44 +70,32 @@
*/
public class TopiaFiresSupport implements TopiaListenableSupport {
- static private Log log = LogFactory.getLog(TopiaFiresSupport.class);
+ private static final Log log = LogFactory.getLog(TopiaFiresSupport.class);
/** used to fire read event */
final static Object NO_CHANGE = new Object();
/** used to collect entity modification during transaction */
- protected Map<TopiaEntity, EntityState> transactionEntities =
- new IdentityMap();
+ protected Map<TopiaEntity, EntityState> transactionEntities = new IdentityMap();
- protected Set<PropertyChangeListener> propertyChangeListeners =
- new HashSet<PropertyChangeListener>();
+ protected Set<PropertyChangeListener> propertyChangeListeners = new HashSet<PropertyChangeListener>();
/* Pour la transaction */
+ protected ListenerSet<TopiaTransactionListener> transactionListeners = new ListenerSet<TopiaTransactionListener>();
- protected ListenerSet<TopiaTransactionListener> transactionListeners =
- new ListenerSet<TopiaTransactionListener>();
+ protected ListenerSet<TopiaTransactionVetoable> transactionVetoables = new ListenerSet<TopiaTransactionVetoable>();
- protected ListenerSet<TopiaTransactionVetoable> transactionVetoables =
- new ListenerSet<TopiaTransactionVetoable>();
-
/* Pour les entités */
+ protected CategorisedListenerSet<TopiaEntityListener> entityListeners = new CategorisedListenerSet<TopiaEntityListener>();
- protected CategorisedListenerSet<TopiaEntityListener> entityListeners =
- new CategorisedListenerSet<TopiaEntityListener>();
+ protected CategorisedListenerSet<TopiaEntityVetoable> entityVetoables = new CategorisedListenerSet<TopiaEntityVetoable>();
- protected CategorisedListenerSet<TopiaEntityVetoable> entityVetoables =
- new CategorisedListenerSet<TopiaEntityVetoable>();
-
/* Pour les listes d'entités */
+ protected ListenerSet<TopiaEntitiesVetoable> entitiesVetoables = new ListenerSet<TopiaEntitiesVetoable>();
- protected ListenerSet<TopiaEntitiesVetoable> entitiesVetoables =
- new ListenerSet<TopiaEntitiesVetoable>();
-
/* Pour les actions du topia context */
+ protected ListenerSet<TopiaSchemaListener> topiaSchemaListeners = new ListenerSet<TopiaSchemaListener>();
- protected ListenerSet<TopiaSchemaListener> topiaSchemaListeners =
- new ListenerSet<TopiaSchemaListener>();
-
/**
* used to register objects loaded during transaction.
*
@@ -239,8 +202,7 @@
if (log.isDebugEnabled()) {
log.debug("fireOnPostCommit");
}
- TopiaTransactionEvent e = new TopiaTransactionEvent(context,
- transactionEntities);
+ TopiaTransactionEvent e = new TopiaTransactionEvent(context, transactionEntities);
for (TopiaTransactionListener listener : transactionListeners) {
try {
listener.commit(e);
@@ -257,8 +219,7 @@
if (log.isDebugEnabled()) {
log.debug("fireOnPostRollback");
}
- TopiaTransactionEvent e = new TopiaTransactionEvent(context,
- transactionEntities);
+ TopiaTransactionEvent e = new TopiaTransactionEvent(context, transactionEntities);
for (TopiaTransactionListener listener : transactionListeners) {
try {
listener.rollback(e);
@@ -273,14 +234,13 @@
/* Fires sur les entités */
- public void fireOnPreCreate(TopiaContextImplementor context,
+ public void fireOnPreCreate(TopiaPersistenceContext context,
TopiaEntity entity, Object[] state) {
if (log.isDebugEnabled()) {
log.debug("fireOnPreCreate");
}
TopiaEntityEvent event = new TopiaEntityEvent(context, entity, state);
- for (Iterator<TopiaEntityVetoable> l = entityVetoables.iterator(entity
- .getClass()); l.hasNext();) {
+ for (Iterator<TopiaEntityVetoable> l = entityVetoables.iterator(entity.getClass()); l.hasNext();) {
try {
l.next().create(event);
} catch (Exception eee) {
@@ -289,34 +249,31 @@
}
}
- public void fireOnPostCreate(TopiaContextImplementor context,
+ public void fireOnPostCreate(TopiaPersistenceContext context,
TopiaEntity entity, Object[] state) {
if (log.isDebugEnabled()) {
log.debug("fireOnPostCreate");
}
warnOnCreateEntity(entity);
TopiaEntityEvent event = new TopiaEntityEvent(context, entity, state);
- for (Iterator<TopiaEntityListener> l = entityListeners.iterator(entity
- .getClass()); l.hasNext();) {
+ for (Iterator<TopiaEntityListener> l = entityListeners.iterator(entity.getClass()); l.hasNext();) {
try {
l.next().create(event);
} catch (Exception eee) {
if (log.isErrorEnabled()) {
- log.error("Can't fireOnPostCreate for entity: " + entity,
- eee);
+ log.error("Can't fireOnPostCreate for entity: " + entity, eee);
}
}
}
}
- public void fireOnPreLoad(TopiaContextImplementor context,
+ public void fireOnPreLoad(TopiaPersistenceContext context,
TopiaEntity entity, Object[] state) {
if (log.isDebugEnabled()) {
log.debug("fireOnPreLoad");
}
TopiaEntityEvent event = new TopiaEntityEvent(context, entity, state);
- for (Iterator<TopiaEntityVetoable> l = entityVetoables.iterator(entity
- .getClass()); l.hasNext();) {
+ for (Iterator<TopiaEntityVetoable> l = entityVetoables.iterator(entity .getClass()); l.hasNext();) {
try {
l.next().load(event);
} catch (Exception eee) {
@@ -332,29 +289,24 @@
}
warnOnLoadEntity(entity);
TopiaEntityEvent event = new TopiaEntityEvent(context, entity, state);
- for (Iterator<TopiaEntityListener> l = entityListeners.iterator(entity
- .getClass()); l.hasNext();) {
+ for (Iterator<TopiaEntityListener> l = entityListeners.iterator(entity.getClass()); l.hasNext();) {
try {
l.next().load(event);
} catch (Exception eee) {
if (log.isErrorEnabled()) {
- log
- .error(
- "Can't fireOnPostLoad for entity: "
- + entity, eee);
+ log.error("Can't fireOnPostLoad for entity: " + entity, eee);
}
}
}
}
- public void fireOnPreUpdate(TopiaContextImplementor context,
+ public void fireOnPreUpdate(TopiaPersistenceContext context,
TopiaEntity entity, Object[] state) {
if (log.isDebugEnabled()) {
log.debug("fireOnPreUpdate");
}
TopiaEntityEvent event = new TopiaEntityEvent(context, entity, state);
- for (Iterator<TopiaEntityVetoable> l = entityVetoables.iterator(entity
- .getClass()); l.hasNext();) {
+ for (Iterator<TopiaEntityVetoable> l = entityVetoables.iterator(entity.getClass()); l.hasNext();) {
try {
l.next().update(event);
} catch (Exception eee) {
@@ -363,34 +315,31 @@
}
}
- public void fireOnPostUpdate(TopiaContextImplementor context,
+ public void fireOnPostUpdate(TopiaPersistenceContext context,
TopiaEntity entity, Object[] state) {
if (log.isDebugEnabled()) {
log.debug("fireOnPostUpdate");
}
warnOnUpdateEntity(entity);
TopiaEntityEvent event = new TopiaEntityEvent(context, entity, state);
- for (Iterator<TopiaEntityListener> l = entityListeners.iterator(entity
- .getClass()); l.hasNext();) {
+ for (Iterator<TopiaEntityListener> l = entityListeners.iterator(entity.getClass()); l.hasNext();) {
try {
l.next().update(event);
} catch (Exception eee) {
if (log.isErrorEnabled()) {
- log.error("Can't fireOnPostUpdate for entity: " + entity,
- eee);
+ log.error("Can't fireOnPostUpdate for entity: " + entity, eee);
}
}
}
}
- public void fireOnPreDelete(TopiaContextImplementor context,
+ public void fireOnPreDelete(TopiaPersistenceContext context,
TopiaEntity entity, Object[] state) {
if (log.isDebugEnabled()) {
log.debug("fireOnPreDelete");
}
TopiaEntityEvent event = new TopiaEntityEvent(context, entity, state);
- for (Iterator<TopiaEntityVetoable> l = entityVetoables.iterator(entity
- .getClass()); l.hasNext();) {
+ for (Iterator<TopiaEntityVetoable> l = entityVetoables.iterator(entity.getClass()); l.hasNext();) {
try {
l.next().delete(event);
} catch (Exception eee) {
@@ -399,21 +348,19 @@
}
}
- public void fireOnPostDelete(TopiaContextImplementor context,
+ public void fireOnPostDelete(TopiaPersistenceContext context,
TopiaEntity entity, Object[] state) {
if (log.isDebugEnabled()) {
log.debug("fireOnPostDelete");
}
warnOnDeleteEntity(entity);
TopiaEntityEvent event = new TopiaEntityEvent(context, entity, state);
- for (Iterator<TopiaEntityListener> l = entityListeners.iterator(entity
- .getClass()); l.hasNext();) {
+ for (Iterator<TopiaEntityListener> l = entityListeners.iterator(entity.getClass()); l.hasNext();) {
try {
l.next().delete(event);
} catch (Exception eee) {
if (log.isErrorEnabled()) {
- log.error("Can't fireOnPostDelete for entity: " + entity,
- eee);
+ log.error("Can't fireOnPostDelete for entity: " + entity, eee);
}
}
}
@@ -465,8 +412,7 @@
}
warnOnReadEntity(entity);
try {
- listeners.fireIndexedPropertyChange(propertyName, index, value,
- NO_CHANGE);
+ listeners.fireIndexedPropertyChange(propertyName, index, value, NO_CHANGE);
} catch (Exception eee) {
if (log.isErrorEnabled()) {
log.error("Can't fireOnPostRead", eee);
@@ -502,15 +448,13 @@
}
warnOnUpdateEntity(entity);
if (propertyChangeListeners.size() > 0) {
- PropertyChangeEvent e = new PropertyChangeEvent(entity,
- propertyName, oldValue, newValue);
+ PropertyChangeEvent e = new PropertyChangeEvent(entity, propertyName, oldValue, newValue);
for (PropertyChangeListener l : propertyChangeListeners) {
try {
l.propertyChange(e);
} catch (Exception eee) {
if (log.isErrorEnabled()) {
- log.error("Can't fire property change for: "
- + propertyName, eee);
+ log.error("Can't fire property change for: " + propertyName, eee);
}
}
}
@@ -536,8 +480,7 @@
}
warnOnUpdateEntity(entity);
try {
- listeners.fireIndexedPropertyChange(propertyName, index, oldValue,
- newValue);
+ listeners.fireIndexedPropertyChange(propertyName, index, oldValue, newValue);
} catch (Exception eee) {
if (log.isErrorEnabled()) {
log.error("Can't fireOnPostWrite", eee);
@@ -546,232 +489,6 @@
}
/**
- * Object permettant de faire le lien entre les events hibernate et topia
- *
- * @author poussin <poussin(a)codelutin.com>
- */
- static public class TopiaHibernateEvent implements PreInsertEventListener,
- PostInsertEventListener, PreLoadEventListener,
- PostLoadEventListener, PreUpdateEventListener,
- PostUpdateEventListener, PreDeleteEventListener,
- PostDeleteEventListener, SaveOrUpdateEventListener {
-
- private static final long serialVersionUID = 7303593133642169218L;
-
- protected TopiaContextImplementor rootContext;
-
- public TopiaHibernateEvent(TopiaContextImplementor rootContext) {
- this.rootContext = rootContext;
- }
-
- /**
- * Recherche le context utilisant la session hibernate passe en
- * parametre
- *
- * @param parent le context parent
- * @param hibernate la session hibernate que doit utiliser le
- * TopiaContext pour etre retourne
- * @return le TopiaContext utilisant cette session hibernate ou null si
- * aucun TopiaContext n'utilise cette session.
- */
- protected TopiaContextImplementor getContext(
- TopiaContextImplementor parent, Session hibernate) {
- TopiaContextImplementor result = null;
-
- // FD-20100421 : Ano #546 : no need to copy childContext, the
- // {@link #getChildContext()} provides a thread-safe copy to iterate
- // on it.
-// Set<TopiaContextImplementor> contextChilds = new HashSet<TopiaContextImplementor>(parent.getChildContext());
- for (TopiaContextImplementor context : parent.getChildContext()) {
-
-// by sletellier 24/09/09 : Fix concurent acces error
-// ArrayList<TopiaContextImplementor> children = new ArrayList(parent.getChildContext());
-// for (TopiaContextImplementor context : children) {
- try {
- if (context.getHibernate() == 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)
- result = getContext(context, hibernate);
- }
- if (result != null) {
- break;
- }
- } catch (TopiaException eee) {
- if (log.isWarnEnabled()) {
- log.warn("Error durant la recherche d'un context pour"
- + " lancer un event", eee);
- }
- }
- }
- return result;
- }
-
- private void attachContext(Object entity,
- TopiaDAOSupplier daoSupplier) {
- if (entity instanceof TopiaEntityContextable) {
- TopiaEntityContextable topiaEntityContextable = (TopiaEntityContextable) entity;
- if (topiaEntityContextable.getTopiaDAOSupplier() == null) {
- try {
- topiaEntityContextable.setTopiaDAOSupplier(daoSupplier);
- } catch (TopiaException eee) {
- if (log.isWarnEnabled()) {
- log.warn("Impossible d'initialiser le TopiaContext"
- + " sur cette entité : " + topiaEntityContextable,
- eee);
- }
- }
- }
- }
- }
-
- /* Création */
-
- @Override
- public boolean onPreInsert(PreInsertEvent event) {
- TopiaContextImplementor context = getContext(rootContext, event
- .getSession());
- if (context != null && event.getEntity() instanceof TopiaEntity) {
- TopiaEntity entity = (TopiaEntity) event.getEntity();
- context.getFiresSupport().fireOnPreCreate(context, entity, event.getState());
-
- // when using composition, hibernate will persist entities by him self
- // entity must have an id in this case.
- if (StringUtils.isBlank(entity.getTopiaId())) {
- if (log.isDebugEnabled()) {
- log.debug("Adding topia id on entity " + entity.getClass().getSimpleName());
- }
- }
- }
-
- return false;
- }
-
- @Override
- public void onPostInsert(PostInsertEvent event) {
- TopiaContextImplementor context = getContext(rootContext, event
- .getSession());
- if (context != null && event.getEntity() instanceof TopiaEntity) {
- context.getFiresSupport().fireOnPostCreate(context,
- (TopiaEntity) event.getEntity(), event.getState());
- }
- }
-
- /* Chargement */
-
- @Override
- public void onPreLoad(PreLoadEvent event) {
- TopiaContextImplementor context = getContext(rootContext, event
- .getSession());
- if (context != null && event.getEntity() instanceof TopiaEntity) {
- // try {
- context.getFiresSupport().fireOnPreLoad(context,
- (TopiaEntity) event.getEntity(), event.getState());
- //TODO (thimel 20071213) On commente pour le moment @see(TopiaDAOHibernate#filterElements)
- // } catch (TopiaVetoException tve) {
- // //On ne fait pas de remontee d'exception
- // vers Hibernate pour le preLoad, on va agir au niveau du DAO
- // }
- }
- }
-
- @Override
- public void onPostLoad(PostLoadEvent event) {
-// TopiaContextImplementor context = getContext(rootContext, event
-// .getSession());
- TopiaDAOSupplier daoSupplier = null; // TODO brendan 30/09/13 Implment
- if (daoSupplier != null && event.getEntity() instanceof TopiaEntity) {
- attachContext(event.getEntity(), daoSupplier);
- TopiaEntity entity = (TopiaEntity)event.getEntity();
- AbstractTopiaDAO<? extends TopiaEntity> dao = (AbstractTopiaDAO)daoSupplier.getDAO(entity.getClass());
- dao.getTopiaFiresSupport().fireOnPostLoad(dao,
- (TopiaEntity) event.getEntity(), new Object[]{});
- }
- }
-
- /* Modification */
-
- @Override
- public boolean onPreUpdate(PreUpdateEvent event) {
- TopiaContextImplementor context = getContext(rootContext, event
- .getSession());
- if (context != null && event.getEntity() instanceof TopiaEntity) {
- context.getFiresSupport().fireOnPreUpdate(context,
- (TopiaEntity) event.getEntity(), event.getOldState());
- }
- return false;
- }
-
- @Override
- public void onPostUpdate(PostUpdateEvent event) {
- TopiaContextImplementor context = getContext(rootContext, event
- .getSession());
- if (context != null && event.getEntity() instanceof TopiaEntity) {
- context.getFiresSupport().fireOnPostUpdate(context,
- (TopiaEntity) event.getEntity(), event.getState());
- }
- // FIXME indexation
- // if (!(entity instanceof NotIndexable) && context.isIndexEnabled()) {
- // context.getIndexEnginImplementor().recordForIndexation(id, event.getState());
- // }
- }
-
- /* Suppression */
-
- @Override
- public boolean onPreDelete(PreDeleteEvent event) {
- TopiaContextImplementor context = getContext(rootContext, event
- .getSession());
- if (context != null && event.getEntity() instanceof TopiaEntity) {
- context.getFiresSupport().fireOnPreDelete(context,
- (TopiaEntity) event.getEntity(),
- event.getDeletedState());
- }
- return false;
- }
-
- @Override
- public void onPostDelete(PostDeleteEvent event) {
- TopiaContextImplementor context = getContext(rootContext, event
- .getSession());
- if (context != null && event.getEntity() instanceof TopiaEntity) {
- context.getFiresSupport().fireOnPostDelete(context,
- (TopiaEntity) event.getEntity(),
- event.getDeletedState());
- }
-// FIXME indexation
-// if (!(entity instanceof NotIndexable) && context.isIndexEnabled()) {
-// context.getIndexEnginImplementor().recordForIndexation(id, null);
-// }
- }
-
- @Override
- public void onSaveOrUpdate(SaveOrUpdateEvent event) throws HibernateException {
- try {
- // this event is called when hibernate try to persist entities
- // using cascade (save)
- TopiaContextImplementor context = getContext(rootContext, event.getSession());
- // warning, event.getEntity() return null here :(
- if (event.getObject() instanceof TopiaEntity) {
- TopiaEntity entity = (TopiaEntity)event.getObject();
- if (StringUtils.isBlank(entity.getTopiaId())) {
- if (log.isDebugEnabled()) {
- log.debug("Adding topiaId into entity " + entity.getClass());
- }
- // FIXME echatellier 20130713 : hack to find interface for current entity class
- // #newTopiaId only accept interface
- Class entityInterface = Class.forName(event.getEntityName().replace("Impl", ""));
- String topiaId = context.getTopiaIdFactory().newTopiaId(entityInterface, entity);
- entity.setTopiaId(topiaId);
- }
- }
- } catch (ClassNotFoundException ex) {
- throw new HibernateException("Can't set id", ex);
- }
- }
- }
-
- /**
* Notify topia context listeners for create schema pre operation
*
* @param context topia context
@@ -852,7 +569,7 @@
*
* @param context topia context
*/
- public void firePreRestoreSchema(TopiaContext context) {
+ public void firePreRestoreSchema(TopiaPersistenceContext context) {
if (log.isDebugEnabled()) {
log.debug("firePreRestoreSchema");
}
@@ -871,7 +588,7 @@
*
* @param context topia context
*/
- public void firePostRestoreSchema(TopiaContext context) {
+ public void firePostRestoreSchema(TopiaPersistenceContext context) {
if (log.isDebugEnabled()) {
log.debug("firePostRestoreSchema");
}
Added: trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaHibernateEventListener.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaHibernateEventListener.java (rev 0)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaHibernateEventListener.java 2013-10-11 22:40:03 UTC (rev 2843)
@@ -0,0 +1,270 @@
+package org.nuiton.topia.framework;
+
+/*
+ * #%L
+ * ToPIA :: Persistence
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2004 - 2013 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%
+ */
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.hibernate.HibernateException;
+import org.hibernate.Session;
+import org.hibernate.event.spi.PostDeleteEvent;
+import org.hibernate.event.spi.PostDeleteEventListener;
+import org.hibernate.event.spi.PostInsertEvent;
+import org.hibernate.event.spi.PostInsertEventListener;
+import org.hibernate.event.spi.PostLoadEvent;
+import org.hibernate.event.spi.PostLoadEventListener;
+import org.hibernate.event.spi.PostUpdateEvent;
+import org.hibernate.event.spi.PostUpdateEventListener;
+import org.hibernate.event.spi.PreDeleteEvent;
+import org.hibernate.event.spi.PreDeleteEventListener;
+import org.hibernate.event.spi.PreInsertEvent;
+import org.hibernate.event.spi.PreInsertEventListener;
+import org.hibernate.event.spi.PreLoadEvent;
+import org.hibernate.event.spi.PreLoadEventListener;
+import org.hibernate.event.spi.PreUpdateEvent;
+import org.hibernate.event.spi.PreUpdateEventListener;
+import org.hibernate.event.spi.SaveOrUpdateEvent;
+import org.hibernate.event.spi.SaveOrUpdateEventListener;
+import org.nuiton.topia.TopiaDAOSupplier;
+import org.nuiton.topia.TopiaException;
+import org.nuiton.topia.persistence.AbstractTopiaDAO;
+import org.nuiton.topia.persistence.TopiaEntity;
+import org.nuiton.topia.persistence.TopiaEntityContextable;
+
+/**
+ * @author Arnaud Thimel <thimel(a)codelutin.com>
+ */
+public class TopiaHibernateEventListener implements PreInsertEventListener, PostInsertEventListener,
+ PreLoadEventListener, PostLoadEventListener, PreUpdateEventListener, PostUpdateEventListener,
+ PreDeleteEventListener, PostDeleteEventListener, SaveOrUpdateEventListener {
+
+ private static final Log log = LogFactory.getLog(TopiaHibernateEventListener.class);
+
+ private static final long serialVersionUID = -9206039888626756924L;
+
+ protected TopiaContextImplementor rootContext;
+
+ public TopiaHibernateEventListener(TopiaContextImplementor rootContext) {
+ this.rootContext = rootContext;
+ }
+
+ /**
+ * Recherche le context utilisant la session hibernate passe en
+ * parametre
+ *
+ * @param parent le context parent
+ * @param hibernate la session hibernate que doit utiliser le
+ * TopiaContext pour etre retourne
+ * @return le TopiaContext utilisant cette session hibernate ou null si
+ * aucun TopiaContext n'utilise cette session.
+ */
+ protected TopiaContextImplementor getContext(
+ TopiaContextImplementor parent, Session hibernate) {
+ TopiaContextImplementor result = null;
+
+ // FD-20100421 : Ano #546 : no need to copy childContext, the
+ // {@link #getChildContext()} provides a thread-safe copy to iterate
+ // on it.
+// Set<TopiaContextImplementor> contextChilds = new HashSet<TopiaContextImplementor>(parent.getChildContext());
+ if (parent != null) { // TODO AThimel 11/10/13 It should never be null, fix it
+ for (TopiaContextImplementor context : parent.getChildContext()) {
+
+ // by sletellier 24/09/09 : Fix concurent acces error
+ // ArrayList<TopiaContextImplementor> children = new ArrayList(parent.getChildContext());
+ // for (TopiaContextImplementor context : children) {
+ try {
+ if (context.getHibernate() == 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)
+ result = getContext(context, hibernate);
+ }
+ if (result != null) {
+ break;
+ }
+ } catch (TopiaException eee) {
+ if (log.isWarnEnabled()) {
+ log.warn("Error durant la recherche d'un context pour"
+ + " lancer un event", eee);
+ }
+ }
+ }
+ }
+ return result;
+ }
+
+ private void attachContext(Object entity,
+ TopiaDAOSupplier daoSupplier) {
+ if (entity instanceof TopiaEntityContextable) {
+ TopiaEntityContextable topiaEntityContextable = (TopiaEntityContextable) entity;
+ if (topiaEntityContextable.getTopiaDAOSupplier() == null) {
+ try {
+ topiaEntityContextable.setTopiaDAOSupplier(daoSupplier);
+ } catch (TopiaException eee) {
+ if (log.isWarnEnabled()) {
+ log.warn("Impossible d'initialiser le TopiaContext"
+ + " sur cette entité : " + topiaEntityContextable,
+ eee);
+ }
+ }
+ }
+ }
+ }
+
+ /* Création */
+
+ @Override
+ public boolean onPreInsert(PreInsertEvent event) {
+ TopiaContextImplementor context = getContext(rootContext, event.getSession());
+ if (context != null && event.getEntity() instanceof TopiaEntity) {
+ TopiaEntity entity = (TopiaEntity) event.getEntity();
+ context.getFiresSupport().fireOnPreCreate(context, entity, event.getState());
+
+ // when using composition, hibernate will persist entities by him self
+ // entity must have an id in this case.
+ if (StringUtils.isBlank(entity.getTopiaId())) {
+ if (log.isDebugEnabled()) {
+ log.debug("Adding topia id on entity " + entity.getClass().getSimpleName());
+ }
+ }
+ }
+
+ return false;
+ }
+
+ @Override
+ public void onPostInsert(PostInsertEvent event) {
+ TopiaContextImplementor context = getContext(rootContext, event
+ .getSession());
+ if (context != null && event.getEntity() instanceof TopiaEntity) {
+ context.getFiresSupport().fireOnPostCreate(context, (TopiaEntity) event.getEntity(), event.getState());
+ }
+ }
+
+ /* Chargement */
+
+ @Override
+ public void onPreLoad(PreLoadEvent event) {
+ TopiaContextImplementor context = getContext(rootContext, event
+ .getSession());
+ if (context != null && event.getEntity() instanceof TopiaEntity) {
+ // try {
+ context.getFiresSupport().fireOnPreLoad(context, (TopiaEntity) event.getEntity(), event.getState());
+ //TODO (thimel 20071213) On commente pour le moment @see(TopiaDAOHibernate#filterElements)
+ // } catch (TopiaVetoException tve) {
+ // //On ne fait pas de remontee d'exception
+ // vers Hibernate pour le preLoad, on va agir au niveau du DAO
+ // }
+ }
+ }
+
+ @Override
+ public void onPostLoad(PostLoadEvent event) {
+// TopiaContextImplementor context = getContext(rootContext, event
+// .getSession());
+ TopiaDAOSupplier daoSupplier = null; // TODO brendan 30/09/13 Implment
+ if (daoSupplier != null && event.getEntity() instanceof TopiaEntity) {
+ attachContext(event.getEntity(), daoSupplier);
+ TopiaEntity entity = (TopiaEntity) event.getEntity();
+ AbstractTopiaDAO<? extends TopiaEntity> dao = (AbstractTopiaDAO) daoSupplier.getDAO(entity.getClass());
+ dao.getTopiaFiresSupport().fireOnPostLoad(dao, (TopiaEntity) event.getEntity(), new Object[]{});
+ }
+ }
+
+ /* Modification */
+
+ @Override
+ public boolean onPreUpdate(PreUpdateEvent event) {
+ TopiaContextImplementor context = getContext(rootContext, event
+ .getSession());
+ if (context != null && event.getEntity() instanceof TopiaEntity) {
+ context.getFiresSupport().fireOnPreUpdate(context, (TopiaEntity) event.getEntity(), event.getOldState());
+ }
+ return false;
+ }
+
+ @Override
+ public void onPostUpdate(PostUpdateEvent event) {
+ TopiaContextImplementor context = getContext(rootContext, event
+ .getSession());
+ if (context != null && event.getEntity() instanceof TopiaEntity) {
+ context.getFiresSupport().fireOnPostUpdate(context, (TopiaEntity) event.getEntity(), event.getState());
+ }
+ // FIXME indexation
+ // if (!(entity instanceof NotIndexable) && context.isIndexEnabled()) {
+ // context.getIndexEnginImplementor().recordForIndexation(id, event.getState());
+ // }
+ }
+
+ /* Suppression */
+
+ @Override
+ public boolean onPreDelete(PreDeleteEvent event) {
+ TopiaContextImplementor context = getContext(rootContext, event
+ .getSession());
+ if (context != null && event.getEntity() instanceof TopiaEntity) {
+ context.getFiresSupport().fireOnPreDelete(context, (TopiaEntity) event.getEntity(), event.getDeletedState());
+ }
+ return false;
+ }
+
+ @Override
+ public void onPostDelete(PostDeleteEvent event) {
+ TopiaContextImplementor context = getContext(rootContext, event
+ .getSession());
+ if (context != null && event.getEntity() instanceof TopiaEntity) {
+ context.getFiresSupport().fireOnPostDelete(context, (TopiaEntity) event.getEntity(), event.getDeletedState());
+ }
+// FIXME indexation
+// if (!(entity instanceof NotIndexable) && context.isIndexEnabled()) {
+// context.getIndexEnginImplementor().recordForIndexation(id, null);
+// }
+ }
+
+ @Override
+ public void onSaveOrUpdate(SaveOrUpdateEvent event) throws HibernateException {
+ try {
+ // this event is called when hibernate try to persist entities
+ // using cascade (save)
+ TopiaContextImplementor context = getContext(rootContext, event.getSession());
+ // warning, event.getEntity() return null here :(
+ if (event.getObject() instanceof TopiaEntity) {
+ TopiaEntity entity = (TopiaEntity) event.getObject();
+ if (StringUtils.isBlank(entity.getTopiaId())) {
+ if (log.isDebugEnabled()) {
+ log.debug("Adding topiaId into entity " + entity.getClass());
+ }
+ // FIXME echatellier 20130713 : hack to find interface for current entity class
+ // #newTopiaId only accept interface
+ Class entityInterface = Class.forName(event.getEntityName().replace("Impl", ""));
+ String topiaId = context.getTopiaIdFactory().newTopiaId(entityInterface, entity);
+ entity.setTopiaId(topiaId);
+ }
+ }
+ } catch (ClassNotFoundException ex) {
+ throw new HibernateException("Can't set id", ex);
+ }
+ }
+}
Property changes on: trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaHibernateEventListener.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaUtil.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaUtil.java 2013-10-11 16:53:04 UTC (rev 2842)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaUtil.java 2013-10-11 22:40:03 UTC (rev 2843)
@@ -68,7 +68,7 @@
public class TopiaUtil {
/** to use log facility, just put in your code: log.info(\"...\"); */
- static private Log log = LogFactory.getLog(TopiaUtil.class);
+ private static final Log log = LogFactory.getLog(TopiaUtil.class);
/**
* Permet de récupérer le fichier de propriété ayant le nom passé en
@@ -81,7 +81,7 @@
* le fichier devant contenir les propriétés
* n'est pas retrouvé.
*/
- static public Properties getProperties(String pathOrUrl)
+ public static Properties getProperties(String pathOrUrl)
throws TopiaNotFoundException {
return getProperties(null, pathOrUrl);
}
@@ -99,7 +99,7 @@
* le fichier devant contenir les propriétés
* n'est pas retrouvé.
*/
- static public Properties getProperties(Properties parent, String pathOrUrl)
+ public static Properties getProperties(Properties parent, String pathOrUrl)
throws TopiaNotFoundException {
Properties result = new RecursiveProperties(parent);
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/ApplicationContextTransformer.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/ApplicationContextTransformer.java 2013-10-11 16:53:04 UTC (rev 2842)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/ApplicationContextTransformer.java 2013-10-11 22:40:03 UTC (rev 2843)
@@ -174,7 +174,10 @@
addAnnotation(output, op, Override.class);
setOperationBody(op, ""
/*{
- return new <%=persistenceContextConcreteName%>(getHibernateProvider(), getTopiaListenableSupport(), getTopiaIdFactory());
+ <%=persistenceContextConcreteName%> newContext = new <%=persistenceContextConcreteName%>(
+ getHibernateProvider(), getTopiaListenableSupport(), getTopiaIdFactory());
+ registerPersistenceContext(newContext);
+ return newContext;
}*/
);
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/DAOHelperTransformer.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/DAOHelperTransformer.java 2013-10-11 16:53:04 UTC (rev 2842)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/DAOHelperTransformer.java 2013-10-11 22:40:03 UTC (rev 2843)
@@ -39,6 +39,7 @@
import org.nuiton.eugene.models.object.xml.ObjectModelAttributeImpl;
import org.nuiton.eugene.models.object.xml.ObjectModelEnumerationImpl;
import org.nuiton.topia.TopiaContext;
+import org.nuiton.topia.TopiaDAOSupplier;
import org.nuiton.topia.TopiaException;
import org.nuiton.topia.persistence.TopiaDAO;
import org.nuiton.topia.persistence.TopiaEntity;
@@ -183,12 +184,12 @@
// specialized getXXXDao method
op = addOperation(daoHelper, "get" + daoClazzName, clazz.getPackageName() + '.' + daoClazzName, ObjectModelJavaModifier.PUBLIC, ObjectModelJavaModifier.STATIC);
- addParameter(op, TopiaContext.class, "context");
+ addParameter(op, TopiaDAOSupplier.class, "supplier");
addImport(daoHelper, clazz);
addException(op, TopiaException.class);
setOperationBody(op, ""
/*{
- <%=daoClazzName%> result = context.getDAO(<%=clazzName%>.class, <%=daoClazzName%>.class);
+ <%=daoClazzName%> result = supplier.getDAO(<%=clazzName%>.class, <%=daoClazzName%>.class);
return result;
}*/
);
Modified: trunk/topia-persistence/src/test/java/org/nuiton/topia/TopiaDatabase.java
===================================================================
--- trunk/topia-persistence/src/test/java/org/nuiton/topia/TopiaDatabase.java 2013-10-11 16:53:04 UTC (rev 2842)
+++ trunk/topia-persistence/src/test/java/org/nuiton/topia/TopiaDatabase.java 2013-10-11 22:40:03 UTC (rev 2843)
@@ -26,6 +26,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.hibernate.cfg.Configuration;
import org.junit.rules.TestWatcher;
import org.junit.runner.Description;
@@ -70,8 +71,10 @@
private Properties dbConfiguration;
- private TopiaContext rootCtxt;
+ private TopiaTestTopiaApplicationContext applicationContext;
+ private Configuration hibernateCfg;
+
private final String configurationPath;
public TopiaDatabase() {
@@ -122,7 +125,15 @@
onDbConfigurationCreate(dbConfiguration, testBasedir, dbPath);
- rootCtxt = TopiaContextFactory.getContext(dbConfiguration);
+// rootCtxt = TopiaContextFactory.getContext(dbConfiguration);
+ applicationContext = new TopiaTestTopiaApplicationContext(dbConfiguration) {
+ @Override
+ protected HibernateProvider getHibernateProvider() {
+ HibernateProvider provider = super.getHibernateProvider();
+ hibernateCfg = provider.getHibernateConfiguration();
+ return provider;
+ }
+ };
} catch (Exception e) {
throw new IllegalStateException(
"Could not start db at " + testBasedir, e);
@@ -132,16 +143,16 @@
@Override
public void finished(Description description) {
- if (rootCtxt != null && !rootCtxt.isClosed()) {
+ if (applicationContext != null && !applicationContext.isClosed()) {
try {
- rootCtxt.closeContext();
+ applicationContext.closeContext();
} catch (TopiaException e) {
if (log.isErrorEnabled()) {
log.error("Could not close topia root context", e);
}
}
}
- rootCtxt = null;
+ applicationContext = null;
dbConfiguration = null;
}
@@ -149,18 +160,22 @@
return testBasedir;
}
- public TopiaContext getRootCtxt() {
- return rootCtxt;
- }
-
public Properties getDbConfiguration() {
return dbConfiguration;
}
- public TopiaContext beginTransaction() throws TopiaException {
- return rootCtxt.beginTransaction();
+ public TopiaTestTopiaApplicationContext getApplicationContext() {
+ return applicationContext;
}
+ public Configuration getHibernateCfg() {
+ return hibernateCfg;
+ }
+
+ public TopiaTestTopiaPersistenceContext beginTransaction() throws TopiaException {
+ return applicationContext.newPersistenceContext();
+ }
+
protected void onDbConfigurationCreate(Properties configuration,
File testDir,
String dbPath) {
Copied: trunk/topia-persistence/src/test/java/org/nuiton/topia/TopiaJpaSupportTest.java (from rev 2842, trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/TopiaContextFindTest.java)
===================================================================
--- trunk/topia-persistence/src/test/java/org/nuiton/topia/TopiaJpaSupportTest.java (rev 0)
+++ trunk/topia-persistence/src/test/java/org/nuiton/topia/TopiaJpaSupportTest.java 2013-10-11 22:40:03 UTC (rev 2843)
@@ -0,0 +1,161 @@
+/*
+ * #%L
+ * ToPIA :: Persistence :: Test Compatibility Kit
+ * $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;
+
+import java.util.List;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.nuiton.topiatest.Address;
+import org.nuiton.topiatest.AddressDAO;
+import org.nuiton.topiatest.Gender;
+import org.nuiton.topiatest.Personne;
+import org.nuiton.topiatest.PersonneDAO;
+
+/**
+ * Tests the TopiaContext#find|findAll|findUnique methods
+ *
+ * @author Arnaud Thimel <thimel(a)codelutin.com>
+ */
+public class TopiaJpaSupportTest {
+
+ @Rule
+ public final TopiaDatabase db = new TopiaDatabase();
+
+ protected TopiaTestTopiaPersistenceContext persistenceContext;
+ protected TopiaJpaSupport jpaSupport;
+ protected AddressDAO addressDAO;
+ protected PersonneDAO personneDAO;
+ protected Address address;
+
+ @Before
+ public void createCompanies() throws TopiaException {
+ persistenceContext = db.beginTransaction();
+ jpaSupport = persistenceContext.jpaSupport;
+
+ personneDAO = persistenceContext.getPersonneDAO();
+ addressDAO = persistenceContext.getAddressDAO();
+
+ address = addressDAO.create(
+ Address.PROPERTY_ADRESS, "17 rue de la Pote Gellée, 44200 NANTES");
+
+ personneDAO.create(
+ Personne.PROPERTY_NAME, "Arnaud",
+ Personne.PROPERTY_GENDER, Gender.MALE);
+ personneDAO.create(
+ Personne.PROPERTY_NAME, "Charlotte",
+ Personne.PROPERTY_GENDER, Gender.FEMALE);
+ personneDAO.create(
+ Personne.PROPERTY_NAME, "Hortense",
+ Personne.PROPERTY_GENDER, Gender.FEMALE);
+ persistenceContext.commitTransaction();
+ }
+
+ @Test
+ public void testFindDAO() throws TopiaException {
+ Assert.assertEquals(3, personneDAO.count());
+
+ Assert.assertEquals(2, personneDAO.findAllByGender(Gender.FEMALE).size());
+ Assert.assertNotNull(personneDAO.findByGender(Gender.FEMALE));
+ Assert.assertNotNull(personneDAO.findByGender(Gender.MALE));
+ Assert.assertNull(personneDAO.findByGender(null));
+
+ Assert.assertEquals(0, personneDAO.findAllByName("nobody").size());
+ }
+
+ @Test
+ public void testFindAll() throws TopiaException {
+ Assert.assertEquals(3, personneDAO.count());
+
+ String query = "from " + Personne.class.getName() +
+ " where " + Personne.PROPERTY_GENDER + "=:g";
+
+ List females = jpaSupport.findAll(query, "g", Gender.FEMALE);
+ Assert.assertEquals(2, females.size());
+
+ List males = jpaSupport.findAll(query, "g", Gender.MALE);
+ Assert.assertEquals(1, males.size());
+
+ List all = jpaSupport.findAll("from " + Personne.class.getName());
+ Assert.assertEquals(3, all.size());
+
+ List none = jpaSupport.findAll("from " + Personne.class.getName() +
+ " where " + Personne.PROPERTY_NAME + "=:pax", "pax", "nobody");
+ Assert.assertEquals(0, none.size());
+ }
+
+ @Test
+ public void testFind() throws TopiaException {
+ Assert.assertEquals(3, personneDAO.count());
+
+ String query = "from " + Personne.class.getName() +
+ " where " + Personne.PROPERTY_GENDER + "=:g";
+
+ List females = jpaSupport.find(query, 0, 100, "g", Gender.FEMALE);
+ Assert.assertEquals(2, females.size());
+
+ females = jpaSupport.find(query, 0, 0, "g", Gender.FEMALE);
+ Assert.assertEquals(1, females.size());
+ Personne charlotte = (Personne)females.get(0);
+
+ females = jpaSupport.find(query, 1, 1, "g", Gender.FEMALE);
+ Assert.assertEquals(1, females.size());
+ Personne hortense = (Personne)females.get(0);
+
+ Assert.assertFalse(hortense.equals(charlotte));
+
+ // endIndex = -1 not supported in ToPIA 2.6, wait for 3.0
+// females = context.find(query, 0, -1, "g", Gender.FEMALE);
+// Assert.assertEquals(2, females.size());
+ }
+
+ @Test
+ public void testFindUnique() throws TopiaException {
+ Assert.assertEquals(3, personneDAO.count());
+
+ String query = "from " + Personne.class.getName() +
+ " where " + Personne.PROPERTY_GENDER + "=:g";
+
+ Object male = jpaSupport.findUnique(query, "g", Gender.MALE);
+ Assert.assertNotNull(male);
+
+ Object none = jpaSupport.findUnique("from " + Personne.class.getName() +
+ " where " + Personne.PROPERTY_NAME + "=:pax", "pax", "nobody");
+ Assert.assertNull(none);
+ }
+
+ @Test(expected = TopiaException.class)
+ public void testFindUniqueOutOfBounds() throws TopiaException {
+ Assert.assertEquals(3, personneDAO.count());
+
+ String query = "from " + Personne.class.getName() +
+ " where " + Personne.PROPERTY_GENDER + "=:g";
+
+ Object female = jpaSupport.findUnique(query, "g", Gender.FEMALE);
+ Assert.assertNotNull(female);
+ }
+
+}
Modified: trunk/topia-persistence/src/test/java/org/nuiton/topia/framework/TopiaConnectionProviderTest.java
===================================================================
--- trunk/topia-persistence/src/test/java/org/nuiton/topia/framework/TopiaConnectionProviderTest.java 2013-10-11 16:53:04 UTC (rev 2842)
+++ trunk/topia-persistence/src/test/java/org/nuiton/topia/framework/TopiaConnectionProviderTest.java 2013-10-11 22:40:03 UTC (rev 2843)
@@ -27,11 +27,11 @@
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.TopiaDatabase;
import org.nuiton.topia.TopiaException;
import org.nuiton.topia.TopiaTestDAOHelper;
+import org.nuiton.topia.TopiaTestTopiaPersistenceContext;
import org.nuiton.topia.test.entities.Person;
import org.nuiton.topia.test.entities.PersonDAO;
import org.nuiton.topiatest.Personne;
@@ -122,7 +122,7 @@
}
private void doStuffOnDb() throws TopiaException {
- TopiaContext transaction = db.beginTransaction();
+ TopiaTestTopiaPersistenceContext transaction = db.beginTransaction();
try {
PersonDAO dao = TopiaTestDAOHelper.getPersonDAO(transaction);
Modified: trunk/topia-persistence/src/test/java/org/nuiton/topia/framework/TopiaContextReplicateTest.java
===================================================================
--- trunk/topia-persistence/src/test/java/org/nuiton/topia/framework/TopiaContextReplicateTest.java 2013-10-11 16:53:04 UTC (rev 2842)
+++ trunk/topia-persistence/src/test/java/org/nuiton/topia/framework/TopiaContextReplicateTest.java 2013-10-11 22:40:03 UTC (rev 2843)
@@ -31,6 +31,7 @@
import org.nuiton.topia.TopiaContextFactory;
import org.nuiton.topia.TopiaDatabase;
import org.nuiton.topia.TopiaTestDAOHelper;
+import org.nuiton.topia.TopiaTestTopiaPersistenceContext;
import org.nuiton.topia.test.entities.Person;
import org.nuiton.topia.test.entities.PersonDAO;
import org.nuiton.topia.test.entities.Pet;
@@ -85,21 +86,19 @@
// "replicateTarget");
//
- TopiaContext contextSource = dbSource.getRootCtxt();
- TopiaContext contextTarget = dbTarget.getRootCtxt();
// try {
// contextSource = TopiaContextFactory.getContext(configSource);
// contextTarget = TopiaContextFactory.getContext(configTarget);
- TopiaContext txSource;
- TopiaContext txTarget;
+ TopiaTestTopiaPersistenceContext txSource;
+ TopiaTestTopiaPersistenceContext txTarget;
PersonDAO daoSource, daoTarget;
PetDAO petDAOSource, petDAOTarget;
Person personSource, personTarget;
Pet petSource, petTarget;
- txSource = contextSource.beginTransaction();
+ txSource = dbSource.beginTransaction();
daoSource = TopiaTestDAOHelper.getPersonDAO(txSource);
petDAOSource = TopiaTestDAOHelper.getPetDAO(txSource);
@@ -126,7 +125,7 @@
Assert.assertEquals(1, personSource.sizePet());
Assert.assertEquals(petSource, personSource.getPet().iterator().next());
- txTarget = contextTarget.beginTransaction();
+ txTarget = dbTarget.beginTransaction();
txSource.replicateEntity(txTarget, petSource);
txSource.replicateEntity(txTarget, personSource);
Modified: trunk/topia-persistence/src/test/java/org/nuiton/topia/framework/TopiaUtilTest.java
===================================================================
--- trunk/topia-persistence/src/test/java/org/nuiton/topia/framework/TopiaUtilTest.java 2013-10-11 16:53:04 UTC (rev 2842)
+++ trunk/topia-persistence/src/test/java/org/nuiton/topia/framework/TopiaUtilTest.java 2013-10-11 22:40:03 UTC (rev 2843)
@@ -25,16 +25,16 @@
package org.nuiton.topia.framework;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.hibernate.cfg.Configuration;
import org.junit.Rule;
import org.junit.Test;
-import org.nuiton.topia.TopiaContext;
import org.nuiton.topia.TopiaDatabase;
import org.nuiton.topia.test.entities.PersonImpl;
import org.nuiton.topiatest.Personne;
-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;
@@ -92,24 +92,22 @@
@Test(expected = IllegalArgumentException.class)
public void testIsSchemaExistFailed() throws Exception {
- TopiaUtil.isSchemaExist(db.getRootCtxt(), "fake");
+ TopiaUtil.isSchemaExist(db.getHibernateCfg(), "fake");
}
@Test
public void testIsSchemaExist() throws Exception {
- TopiaContext rootContext = db.getRootCtxt();
- boolean actual = TopiaUtil.isSchemaExist(rootContext,
- PersonImpl.class.getName());
- // FIXME echatellier 20130315 ce test fail depuis probablement a cause
- // de hibernate.hbm2ddl.auto=update, à confirmer...
- assertTrue(actual);
- TopiaContext tx = rootContext.beginTransaction();
+ String personClassName = PersonImpl.class.getName();
+ Configuration hibernateCfg = db.getHibernateCfg();
- tx.createSchema();
- actual = TopiaUtil.isSchemaExist(rootContext, PersonImpl.class.getName());
+ // First, test before DB is created, the table should not exist
+ assertFalse(TopiaUtil.isSchemaExist(hibernateCfg, personClassName));
- assertTrue(actual);
+ // Create schema
+ db.getApplicationContext().createSchema();
+ // Now table should exist
+ assertTrue(TopiaUtil.isSchemaExist(hibernateCfg, personClassName));
}
}
Modified: trunk/topia-persistence/src/test/java/org/nuiton/topia/generator/TopiaTestCase.java
===================================================================
--- trunk/topia-persistence/src/test/java/org/nuiton/topia/generator/TopiaTestCase.java 2013-10-11 16:53:04 UTC (rev 2842)
+++ trunk/topia-persistence/src/test/java/org/nuiton/topia/generator/TopiaTestCase.java 2013-10-11 22:40:03 UTC (rev 2843)
@@ -34,6 +34,7 @@
import org.nuiton.topia.TopiaDatabase;
import org.nuiton.topia.TopiaException;
import org.nuiton.topia.TopiaTestDAOHelper;
+import org.nuiton.topia.TopiaTestTopiaPersistenceContext;
import org.nuiton.topiatest.Company;
import org.nuiton.topiatest.CompanyDAO;
import org.nuiton.topiatest.Department;
@@ -121,10 +122,10 @@
}
// try {
- TopiaContext newContext = db.beginTransaction();
+ TopiaTestTopiaPersistenceContext newContext = db.beginTransaction();
- CompanyDAO companyDAO = TopiaTestDAOHelper.getCompanyDAO(newContext);
- DepartmentDAO departmentDAO = TopiaTestDAOHelper.getDepartmentDAO(newContext);
+ CompanyDAO companyDAO = newContext.getCompanyDAO();
+ DepartmentDAO departmentDAO = newContext.getDepartmentDAO();
Company company = companyDAO.create();
company.setName("Ma société");
Modified: trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/EntityVisitorExportXmlTest.java
===================================================================
--- trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/EntityVisitorExportXmlTest.java 2013-10-11 16:53:04 UTC (rev 2842)
+++ trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/EntityVisitorExportXmlTest.java 2013-10-11 22:40:03 UTC (rev 2843)
@@ -30,10 +30,9 @@
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
-import org.nuiton.topia.TopiaContext;
import org.nuiton.topia.TopiaDatabase;
import org.nuiton.topia.TopiaException;
-import org.nuiton.topia.TopiaTestDAOHelper;
+import org.nuiton.topia.TopiaTestTopiaPersistenceContext;
import org.nuiton.topiatest.Address;
import org.nuiton.topiatest.AddressDAO;
import org.nuiton.topiatest.Company;
@@ -70,17 +69,17 @@
@Before
public void setUp() throws TopiaException {
- TopiaContext newContext = db.beginTransaction();
+ TopiaTestTopiaPersistenceContext newContext = db.beginTransaction();
try {
// company
- CompanyDAO companyDAO = TopiaTestDAOHelper.getCompanyDAO(newContext);
+ CompanyDAO companyDAO = newContext.getCompanyDAO();
Company clCompany = companyDAO.create(Company.PROPERTY_NAME, "CodeLutin");
// employe
- EmployeDAO employeDAO = TopiaTestDAOHelper.getEmployeDAO(newContext);
+ EmployeDAO employeDAO = newContext.getEmployeDAO();
Employe empl1 = employeDAO.create(Employe.PROPERTY_NAME, "boss", Employe.PROPERTY_SALARY, 30000);
- AddressDAO adressDAO = TopiaTestDAOHelper.getAddressDAO(newContext);
+ AddressDAO adressDAO = newContext.getAddressDAO();
Address addr1 = adressDAO.create(Address.PROPERTY_CITY, "Nantes", Address.PROPERTY_ADRESS, "12 Avenue Jules Vernes");
empl1.setAddress(addr1);
@@ -89,7 +88,7 @@
empl2.setAddress(addr2);
// departement
- DepartmentDAO departmentDAO = TopiaTestDAOHelper.getDepartmentDAO(newContext);
+ DepartmentDAO departmentDAO = newContext.getDepartmentDAO();
Department depComm = departmentDAO.create(Department.PROPERTY_NAME, "Commercial");
depComm.setLeader(empl1);
@@ -116,9 +115,9 @@
@Test
public void testExportXMLDepth() throws TopiaException {
- TopiaContext context = db.beginTransaction();
+ TopiaTestTopiaPersistenceContext context = db.beginTransaction();
- CompanyDAO companyDAO = TopiaTestDAOHelper.getCompanyDAO(context);
+ CompanyDAO companyDAO = context.getCompanyDAO();
Company clCompany = companyDAO.findByName("CodeLutin");
EntityVisitor delegateVisitor = new ExportXMLVisitor();
Modified: trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/NaturalIdTest.java
===================================================================
--- trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/NaturalIdTest.java 2013-10-11 16:53:04 UTC (rev 2842)
+++ trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/NaturalIdTest.java 2013-10-11 22:40:03 UTC (rev 2843)
@@ -34,7 +34,10 @@
import org.nuiton.topia.TopiaContext;
import org.nuiton.topia.TopiaDatabase;
import org.nuiton.topia.TopiaException;
+import org.nuiton.topia.TopiaPersistenceContext;
import org.nuiton.topia.TopiaTestDAOHelper;
+import org.nuiton.topia.TopiaTestTopiaPersistenceContext;
+import org.nuiton.topia.TopiaTransaction;
import org.nuiton.topiatest.NaturalizedEntity;
import org.nuiton.topiatest.NaturalizedEntityDAO;
@@ -59,36 +62,36 @@
@Test
public void testCreateSucessfull() throws Exception {
log.debug("Test naturalId : create succesfull");
- TopiaContext transaction = db.beginTransaction();
+ TopiaTestTopiaPersistenceContext persistenceContext = db.beginTransaction();
NaturalizedEntityDAO dao =
- TopiaTestDAOHelper.getNaturalizedEntityDAO(transaction);
+ persistenceContext.getNaturalizedEntityDAO();
// No exception will be thrown with the two properties
dao.createByNaturalId(5, "str");
- transaction.commitTransaction();
+ persistenceContext.commitTransaction();
// No exception will only the need property
dao.createByNotNull(3);
- transaction.commitTransaction();
+ persistenceContext.commitTransaction();
// No exception will only the need property
dao.create(NaturalizedEntity.PROPERTY_NATURAL_ID_NOT_NULL, 3);
- transaction.commitTransaction();
+ persistenceContext.commitTransaction();
}
@Test
public void testCreateFailed() throws Exception {
log.debug("Test naturalId : create failed");
- TopiaContext transaction = db.beginTransaction();
+ TopiaTestTopiaPersistenceContext persistenceContext = db.beginTransaction();
NaturalizedEntityDAO dao =
- TopiaTestDAOHelper.getNaturalizedEntityDAO(transaction);
+ persistenceContext.getNaturalizedEntityDAO();
// Exception will be throw
try {
dao.create();
- transaction.commitTransaction();
+ persistenceContext.commitTransaction();
// Note : this is possible to create an empty entity if the type
// is primitive like 'int' which have a default value of '0'
@@ -106,19 +109,19 @@
public void testUpdateFailed() throws Exception {
log.debug("Test naturalId : update failed");
- TopiaContext transaction = db.beginTransaction();
+ TopiaTestTopiaPersistenceContext persistenceContext = db.beginTransaction();
NaturalizedEntityDAO dao =
- TopiaTestDAOHelper.getNaturalizedEntityDAO(transaction);
+ persistenceContext.getNaturalizedEntityDAO();
NaturalizedEntity entity =
dao.createByNaturalId(5, "str");
- transaction.commitTransaction();
+ persistenceContext.commitTransaction();
// Exception will be throw : not allowed to modify a naturalId property
try {
entity.setNaturalIdNotNull(8);
- transaction.commitTransaction();
+ persistenceContext.commitTransaction();
} catch (TopiaException eee) {
Assert.assertEquals("org.hibernate.HibernateException",
eee.getCause().getClass().getName());
@@ -128,14 +131,15 @@
@Test
public void testFindByNaturalId() throws Exception {
log.debug("Test naturalId : findByNaturalId");
- TopiaContext transaction = db.beginTransaction();
+ TopiaTestTopiaPersistenceContext persistenceContext = db.beginTransaction();
+
NaturalizedEntityDAO dao =
- TopiaTestDAOHelper.getNaturalizedEntityDAO(transaction);
+ persistenceContext.getNaturalizedEntityDAO();
NaturalizedEntity entity =
dao.createByNaturalId(5, "str");
- transaction.commitTransaction();
+ persistenceContext.commitTransaction();
NaturalizedEntity result = dao.findByNaturalId(5, "str");
@@ -145,13 +149,14 @@
@Test
public void testExistNaturalId() throws Exception {
log.debug("Test naturalId : existNaturalId");
- TopiaContext transaction = db.beginTransaction();
+ TopiaTestTopiaPersistenceContext persistenceContext = db.beginTransaction();
+
NaturalizedEntityDAO dao =
- TopiaTestDAOHelper.getNaturalizedEntityDAO(transaction);
+ persistenceContext.getNaturalizedEntityDAO();
dao.createByNaturalId(5, "str");
- transaction.commitTransaction();
+ persistenceContext.commitTransaction();
boolean result = dao.existByNaturalId(5, "str");
Deleted: trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/TopiaContextFindTest.java
===================================================================
--- trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/TopiaContextFindTest.java 2013-10-11 16:53:04 UTC (rev 2842)
+++ trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/TopiaContextFindTest.java 2013-10-11 22:40:03 UTC (rev 2843)
@@ -1,162 +0,0 @@
-/*
- * #%L
- * ToPIA :: Persistence :: Test Compatibility Kit
- * $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.persistence;
-
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.nuiton.topia.TopiaContext;
-import org.nuiton.topia.TopiaDatabase;
-import org.nuiton.topia.TopiaException;
-import org.nuiton.topia.TopiaTestDAOHelper;
-import org.nuiton.topiatest.Address;
-import org.nuiton.topiatest.AddressDAO;
-import org.nuiton.topiatest.Gender;
-import org.nuiton.topiatest.Personne;
-import org.nuiton.topiatest.PersonneDAO;
-
-import java.util.List;
-
-/**
- * Tests the TopiaContext#find|findAll|findUnique methods
- *
- * @author Arnaud Thimel <thimel(a)codelutin.com>
- */
-public class TopiaContextFindTest {
-
- @Rule
- public final TopiaDatabase db = new TopiaDatabase();
-
- protected TopiaContext context;
- protected AddressDAO addressDAO;
- protected PersonneDAO personneDAO;
- protected Address address;
-
- @Before
- public void createCompanies() throws TopiaException {
- context = db.beginTransaction();
- personneDAO = TopiaTestDAOHelper.getPersonneDAO(context);
- addressDAO = TopiaTestDAOHelper.getAddressDAO(context);
-
- address = addressDAO.create(
- Address.PROPERTY_ADRESS, "17 rue de la Pote Gellée, 44200 NANTES");
-
- personneDAO.create(
- Personne.PROPERTY_NAME, "Arnaud",
- Personne.PROPERTY_GENDER, Gender.MALE);
- personneDAO.create(
- Personne.PROPERTY_NAME, "Charlotte",
- Personne.PROPERTY_GENDER, Gender.FEMALE);
- personneDAO.create(
- Personne.PROPERTY_NAME, "Hortense",
- Personne.PROPERTY_GENDER, Gender.FEMALE);
- context.commitTransaction();
- }
-
- @Test
- public void testFindDAO() throws TopiaException {
- Assert.assertEquals(3, personneDAO.count());
-
- Assert.assertEquals(2, personneDAO.findAllByGender(Gender.FEMALE).size());
- Assert.assertNotNull(personneDAO.findByGender(Gender.FEMALE));
- Assert.assertNotNull(personneDAO.findByGender(Gender.MALE));
- Assert.assertNull(personneDAO.findByGender(null));
-
- Assert.assertEquals(0, personneDAO.findAllByName("nobody").size());
- }
-
- @Test
- public void testFindAll() throws TopiaException {
- Assert.assertEquals(3, personneDAO.count());
-
- String query = "from " + Personne.class.getName() +
- " where " + Personne.PROPERTY_GENDER + "=:g";
-
- List females = context.findAll(query, "g", Gender.FEMALE);
- Assert.assertEquals(2, females.size());
-
- List males = context.findAll(query, "g", Gender.MALE);
- Assert.assertEquals(1, males.size());
-
- List all = context.findAll("from " + Personne.class.getName());
- Assert.assertEquals(3, all.size());
-
- List none = context.findAll("from " + Personne.class.getName() +
- " where " + Personne.PROPERTY_NAME + "=:pax", "pax", "nobody");
- Assert.assertEquals(0, none.size());
- }
-
- @Test
- public void testFind() throws TopiaException {
- Assert.assertEquals(3, personneDAO.count());
-
- String query = "from " + Personne.class.getName() +
- " where " + Personne.PROPERTY_GENDER + "=:g";
-
- List females = context.find(query, 0, 100, "g", Gender.FEMALE);
- Assert.assertEquals(2, females.size());
-
- females = context.find(query, 0, 0, "g", Gender.FEMALE);
- Assert.assertEquals(1, females.size());
- Personne charlotte = (Personne)females.get(0);
-
- females = context.find(query, 1, 1, "g", Gender.FEMALE);
- Assert.assertEquals(1, females.size());
- Personne hortense = (Personne)females.get(0);
-
- Assert.assertFalse(hortense.equals(charlotte));
-
- // endIndex = -1 not supported in ToPIA 2.6, wait for 3.0
-// females = context.find(query, 0, -1, "g", Gender.FEMALE);
-// Assert.assertEquals(2, females.size());
- }
-
- @Test
- public void testFindUnique() throws TopiaException {
- Assert.assertEquals(3, personneDAO.count());
-
- String query = "from " + Personne.class.getName() +
- " where " + Personne.PROPERTY_GENDER + "=:g";
-
- Object male = context.findUnique(query, "g", Gender.MALE);
- Assert.assertNotNull(male);
-
- Object none = context.findUnique("from " + Personne.class.getName() +
- " where " + Personne.PROPERTY_NAME + "=:pax", "pax", "nobody");
- Assert.assertNull(none);
- }
-
- @Test(expected = TopiaException.class)
- public void testFindUniqueOutOfBounds() throws TopiaException {
- Assert.assertEquals(3, personneDAO.count());
-
- String query = "from " + Personne.class.getName() +
- " where " + Personne.PROPERTY_GENDER + "=:g";
-
- Object female = context.findUnique(query, "g", Gender.FEMALE);
- Assert.assertNotNull(female);
- }
-
-}
Modified: trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/TopiaDAOTest.java
===================================================================
--- trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/TopiaDAOTest.java 2013-10-11 16:53:04 UTC (rev 2842)
+++ trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/TopiaDAOTest.java 2013-10-11 22:40:03 UTC (rev 2843)
@@ -31,10 +31,9 @@
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
-import org.nuiton.topia.TopiaContext;
import org.nuiton.topia.TopiaDatabase;
import org.nuiton.topia.TopiaException;
-import org.nuiton.topia.TopiaTestDAOHelper;
+import org.nuiton.topia.TopiaTestTopiaPersistenceContext;
import org.nuiton.topia.test.entities.Person;
import org.nuiton.topia.test.entities.PersonDAO;
@@ -54,7 +53,7 @@
@Rule
public final TopiaDatabase db = new TopiaDatabase();
- protected TopiaContext context;
+ protected TopiaTestTopiaPersistenceContext context;
protected PersonDAO dao;
@@ -62,8 +61,7 @@
public void setup() throws TopiaException {
context = db.beginTransaction();
-
- dao = TopiaTestDAOHelper.getPersonDAO(context);
+ dao = context.getPersonDAO();
}
/**
Modified: trunk/topia-persistence/src/test/java/org/nuiton/topia/test/ano1882/DAOAbstractTransformerTest.java
===================================================================
--- trunk/topia-persistence/src/test/java/org/nuiton/topia/test/ano1882/DAOAbstractTransformerTest.java 2013-10-11 16:53:04 UTC (rev 2842)
+++ trunk/topia-persistence/src/test/java/org/nuiton/topia/test/ano1882/DAOAbstractTransformerTest.java 2013-10-11 22:40:03 UTC (rev 2843)
@@ -29,6 +29,7 @@
import org.nuiton.topia.TopiaContext;
import org.nuiton.topia.TopiaDatabase;
import org.nuiton.topia.TopiaTestDAOHelper;
+import org.nuiton.topia.TopiaTestTopiaPersistenceContext;
import java.util.Arrays;
@@ -39,7 +40,7 @@
@Test
public void testAno1882() throws Exception {
- TopiaContext transaction = db.beginTransaction();
+ TopiaTestTopiaPersistenceContext transaction = db.beginTransaction();
FrenchCompanyDAO dao = TopiaTestDAOHelper.getFrenchCompanyDAO(transaction);
SIRETDAO siretDAO = TopiaTestDAOHelper.getSIRETDAO(transaction);
Modified: trunk/topia-persistence/src/test/java/org/nuiton/topiatest/EnumTest.java
===================================================================
--- trunk/topia-persistence/src/test/java/org/nuiton/topiatest/EnumTest.java 2013-10-11 16:53:04 UTC (rev 2842)
+++ trunk/topia-persistence/src/test/java/org/nuiton/topiatest/EnumTest.java 2013-10-11 22:40:03 UTC (rev 2843)
@@ -31,6 +31,7 @@
import org.nuiton.topia.TopiaDatabase;
import org.nuiton.topia.TopiaException;
import org.nuiton.topia.TopiaTestDAOHelper;
+import org.nuiton.topia.TopiaTestTopiaPersistenceContext;
/**
* Test the support of possibility to have an attribute of type enumeration
@@ -51,7 +52,7 @@
*/
@Test
public void storeEntityWithEnumValue() throws TopiaException {
- TopiaContext transaction = db.beginTransaction();
+ TopiaTestTopiaPersistenceContext transaction = db.beginTransaction();
PersonneDAO dao = TopiaTestDAOHelper.getPersonneDAO(transaction);
Personne personne = new PersonneImpl();
Modified: trunk/topia-persistence/src/test/java/org/nuiton/topiatest/deletetest/DeleteEntityTest.java
===================================================================
--- trunk/topia-persistence/src/test/java/org/nuiton/topiatest/deletetest/DeleteEntityTest.java 2013-10-11 16:53:04 UTC (rev 2842)
+++ trunk/topia-persistence/src/test/java/org/nuiton/topiatest/deletetest/DeleteEntityTest.java 2013-10-11 22:40:03 UTC (rev 2843)
@@ -47,6 +47,7 @@
import org.nuiton.topia.TopiaDatabase;
import org.nuiton.topia.TopiaException;
import org.nuiton.topia.TopiaTestDAOHelper;
+import org.nuiton.topia.TopiaTestTopiaPersistenceContext;
import org.nuiton.topiatest.Gender;
import org.nuiton.topiatest.Personne;
import org.nuiton.topiatest.PersonneDAO;
@@ -81,7 +82,7 @@
public void testDeleteEntityWithInheritance() throws TopiaException {
log.debug("START TEST : testDeleteEntityWithInheritance");
- TopiaContext transaction = db.beginTransaction();
+ TopiaTestTopiaPersistenceContext transaction = db.beginTransaction();
log.debug("DAO : PersonneDAO");
PersonneDAO dao = TopiaTestDAOHelper.getPersonneDAO(transaction);
@@ -132,7 +133,7 @@
public void testDeleteEntityWithManyToManyRelation() throws TopiaException {
log.debug("START TEST : testDeleteEntityWithManyToManyRelation");
- TopiaContext transaction = db.beginTransaction();
+ TopiaTestTopiaPersistenceContext transaction = db.beginTransaction();
PersonneDAO dao = TopiaTestDAOHelper.getPersonneDAO(transaction);
@@ -183,7 +184,7 @@
public void testIsPersisted() {
log.debug("START TEST : testIsPersisted");
- TopiaContext transaction = db.beginTransaction();
+ TopiaTestTopiaPersistenceContext transaction = db.beginTransaction();
PersonneDAO dao = TopiaTestDAOHelper.getPersonneDAO(transaction);
1
0
r2842 - in trunk/topia-persistence/src/main/java/org/nuiton/topia: . framework
by bleny@users.nuiton.org 11 Oct '13
by bleny@users.nuiton.org 11 Oct '13
11 Oct '13
Author: bleny
Date: 2013-10-11 18:53:04 +0200 (Fri, 11 Oct 2013)
New Revision: 2842
Url: http://nuiton.org/projects/topia/repository/revisions/2842
Log:
implements TopiaReplicationSupport and move it on PersitenceContext
Added:
trunk/topia-persistence/src/main/java/org/nuiton/topia/HibernateTopiaReplicationSupport.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaReplicationDestination.java
Modified:
trunk/topia-persistence/src/main/java/org/nuiton/topia/AbstractTopiaApplicationContext.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/AbstractTopiaPersistenceContext.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaContext.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaPersistenceContext.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaReplicationSupport.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/AbstractTopiaContext.java
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/AbstractTopiaApplicationContext.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/AbstractTopiaApplicationContext.java 2013-10-11 16:47:08 UTC (rev 2841)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/AbstractTopiaApplicationContext.java 2013-10-11 16:53:04 UTC (rev 2842)
@@ -60,7 +60,7 @@
* @author Arnaud Thimel <thimel(a)codelutin.com>
* @since 3.0
*/
-public abstract class AbstractTopiaApplicationContext<K extends TopiaPersistenceContext> implements TopiaReplicationSupport, TopiaListenableSupport, TopiaServiceSupport {
+public abstract class AbstractTopiaApplicationContext<K extends TopiaPersistenceContext> implements TopiaListenableSupport, TopiaServiceSupport {
private static final Log log = LogFactory.getLog(AbstractTopiaApplicationContext.class);
@@ -68,8 +68,6 @@
protected ImmutableMap<String, String> configuration;
- protected TopiaReplicationSupport topiaReplicationSupport;
-
protected TopiaFiresSupport topiaFiresSupport = new TopiaFiresSupport();
protected TopiaServiceSupport topiaServiceSupport;
@@ -146,21 +144,6 @@
}
@Override
- public void replicate(TopiaContext destinationContext, Object... entityAndCondition) throws IllegalArgumentException {
- topiaReplicationSupport.replicate(destinationContext, entityAndCondition);
- }
-
- @Override
- public <T extends TopiaEntity> void replicateEntity(TopiaContext destinationContext, T entity) throws IllegalArgumentException {
- topiaReplicationSupport.replicateEntity(destinationContext, entity);
- }
-
- @Override
- public <T extends TopiaEntity> void replicateEntities(TopiaContext destinationContext, List<T> entities) throws IllegalArgumentException {
- topiaReplicationSupport.replicateEntities(destinationContext, entities);
- }
-
- @Override
public void addTopiaEntityListener(TopiaEntityListener listener) {
topiaFiresSupport.addTopiaEntityListener(listener);
}
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/AbstractTopiaPersistenceContext.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/AbstractTopiaPersistenceContext.java 2013-10-11 16:47:08 UTC (rev 2841)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/AbstractTopiaPersistenceContext.java 2013-10-11 16:53:04 UTC (rev 2842)
@@ -24,9 +24,8 @@
* #L%
*/
-import java.lang.reflect.InvocationTargetException;
-import java.util.Map;
-
+import com.google.common.base.Preconditions;
+import com.google.common.collect.Maps;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.FlushMode;
@@ -41,8 +40,9 @@
import org.nuiton.topia.persistence.TopiaEntity;
import org.nuiton.topia.persistence.TopiaIdFactory;
-import com.google.common.base.Preconditions;
-import com.google.common.collect.Maps;
+import java.lang.reflect.InvocationTargetException;
+import java.util.List;
+import java.util.Map;
/**
* Abstract implementation of the TopiaPersistenceContext. This class will be extended by a generated one in order to
@@ -60,6 +60,8 @@
*/
protected Map<Class<? extends TopiaEntity>, TopiaDAO<? extends TopiaEntity>> daoCache = Maps.newConcurrentMap();
+ protected HibernateTopiaReplicationSupport hibernateTopiaReplicationSupport;
+
// TODO AThimel 27/09/13 Javadoc
protected TopiaListenableSupport listenableSupport;
@@ -366,4 +368,30 @@
return closed;
}
+ protected HibernateTopiaReplicationSupport getHibernateTopiaReplicationSupport() {
+ if (hibernateTopiaReplicationSupport == null) {
+ hibernateTopiaReplicationSupport = new HibernateTopiaReplicationSupport(hibernateSupport);
+ }
+ return hibernateTopiaReplicationSupport;
+ }
+
+ @Override
+ public void replicate(TopiaEntity entity) {
+ getHibernateTopiaReplicationSupport().replicate(entity);
+ }
+
+ @Override
+ public <T extends TopiaEntity> void replicateEntities(TopiaReplicationDestination topiaReplicationDestination, List<T> entities) throws IllegalArgumentException {
+ getHibernateTopiaReplicationSupport().replicateEntities(topiaReplicationDestination, entities);
+ }
+
+ @Override
+ public <T extends TopiaEntity> void replicateEntity(TopiaReplicationDestination topiaReplicationDestination, T entity) throws IllegalArgumentException {
+ getHibernateTopiaReplicationSupport().replicateEntity(topiaReplicationDestination, entity);
+ }
+
+ @Override
+ public void replicate(TopiaReplicationDestination topiaReplicationDestination, Object... entityAndCondition) throws IllegalArgumentException {
+ getHibernateTopiaReplicationSupport().replicate(topiaReplicationDestination, entityAndCondition);
+ }
}
Added: trunk/topia-persistence/src/main/java/org/nuiton/topia/HibernateTopiaReplicationSupport.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/HibernateTopiaReplicationSupport.java (rev 0)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/HibernateTopiaReplicationSupport.java 2013-10-11 16:53:04 UTC (rev 2842)
@@ -0,0 +1,156 @@
+package org.nuiton.topia;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.hibernate.HibernateException;
+import org.hibernate.ReplicationMode;
+import org.nuiton.topia.persistence.TopiaEntity;
+
+import java.util.List;
+import java.util.Map;
+
+public class HibernateTopiaReplicationSupport implements TopiaReplicationSupport, TopiaReplicationDestination {
+
+ private static final Log log = LogFactory.getLog(HibernateTopiaReplicationSupport.class);
+
+ protected TopiaHibernateSupport topiaHibernateSupport;
+
+ public HibernateTopiaReplicationSupport(TopiaHibernateSupport topiaHibernateSupport) {
+ this.topiaHibernateSupport = topiaHibernateSupport;
+ }
+
+ @Override
+ public void replicate(
+ TopiaReplicationDestination topiaReplicationDestination,
+ Object... entityAndCondition) throws IllegalArgumentException {
+
+ String[] queries = buildQueries(entityAndCondition);
+
+ try {
+ for (String query : queries) {
+ if (log.isDebugEnabled()) {
+ log.debug("acquire entities " + query);
+ }
+ // acquire data to replicate
+ List<?> entities = topiaHibernateSupport.getHibernateSession().createQuery(query).list();
+ replicate0(topiaReplicationDestination, entities.toArray());
+ if (log.isDebugEnabled()) {
+ log.debug("replication of entities " + query +
+ " was sucessfully done.");
+ }
+ }
+ } catch (HibernateException eee) {
+ throw new TopiaException(String.format("An error occurs while a replication operation: %s",
+ eee.getMessage()), eee);
+ }
+ }
+
+ @Override
+ public <T extends TopiaEntity> void replicateEntity(
+ TopiaReplicationDestination topiaReplicationDestination,
+ T entity) throws IllegalArgumentException {
+
+ replicate0(topiaReplicationDestination, entity);
+
+ }
+
+ @Override
+ public <T extends TopiaEntity> void replicateEntities(
+ TopiaReplicationDestination topiaReplicationDestination,
+ List<T> entities) throws IllegalArgumentException {
+
+ replicate0(topiaReplicationDestination, entities.toArray());
+
+ }
+
+ protected void replicate0(TopiaReplicationDestination topiaReplicationDestination,
+ Object... entities) {
+ try {
+ for (Object entity : entities) {
+ // dettach entity to source session, to make possible copy of
+ // collection without a hibernate exception (list opened in
+ // two session...)
+ topiaHibernateSupport.getHibernateSession().evict(entity);
+ topiaReplicationDestination.replicate((TopiaEntity) entity);
+ }
+
+ } catch (HibernateException eee) {
+ throw new TopiaException(String.format("An error occurs while a replication operation : %s",
+ eee.getMessage()), eee);
+ }
+ }
+
+ /**
+ * Build the list of queries from the given parameter
+ * <code>entityAndCondition</code>.
+ * <p/>
+ * If no parameter is given, then build the queries for all entities is db,
+ * with no condition.
+ *
+ * @param entityAndCondition the list of tuples (Class,String)
+ * @return the list of queries.
+ * @throws TopiaException if any pb of db while getting entities
+ * classes.
+ * @throws IllegalArgumentException if any pb with the given parameter
+ * (mainly ClassCastException).
+ */
+ protected String[] buildQueries(Object... entityAndCondition)
+ throws TopiaException, IllegalArgumentException {
+ Class<?> entityClass;
+ String condition;
+
+ // si entityAndcondition est vide alors il faut le remplir
+ // avec toutes les entités du mapping (class, null)
+ if (entityAndCondition.length == 0) {
+ Map<?, ?> classMetadata = topiaHibernateSupport.getHibernateFactory().getAllClassMetadata();
+ entityAndCondition = new Object[classMetadata.size() * 2];
+ int i = 0;
+ for (Object className : classMetadata.keySet()) {
+ try {
+ entityAndCondition[i++] = Class.forName((String) className);
+ } catch (ClassNotFoundException e) {
+ // should never happen!
+ throw new TopiaException(
+ "class cast exception for entity " + className);
+ }
+ entityAndCondition[i++] = null;
+
+ }
+ }
+
+ // prepare queries to perform beofre opening any transaction
+ if (entityAndCondition.length % 2 != 0) {
+ throw new IllegalArgumentException(
+ "entityAndCondition must be a couple of (Class, String)");
+ }
+ String queries[] = new String[entityAndCondition.length / 2];
+ for (int i = 0; i < entityAndCondition.length; ) {
+ try {
+ entityClass = (Class<?>) entityAndCondition[i++];
+ condition = (String) entityAndCondition[i++];
+ String query = "from " + entityClass.getName();
+ if (condition != null && !condition.isEmpty()) {
+ query += " where " + condition;
+ }
+ queries[(i - 1) / 2] = query;
+ } catch (ClassCastException e) {
+ if (i % 2 == 0) {
+ throw new IllegalArgumentException(
+ "Others arguement must be String not " +
+ entityAndCondition[i - 1], e);
+ } else {
+ throw new IllegalArgumentException(
+ "Others arguement must be Class not " +
+ entityAndCondition[i - 1], e);
+ }
+ }
+ }
+ return queries;
+ }
+
+ @Override
+ public void replicate(TopiaEntity entity) {
+ topiaHibernateSupport.getHibernateSession().replicate(entity, ReplicationMode.EXCEPTION);
+ }
+
+}
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaContext.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaContext.java 2013-10-11 16:47:08 UTC (rev 2841)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaContext.java 2013-10-11 16:53:04 UTC (rev 2842)
@@ -25,10 +25,6 @@
package org.nuiton.topia;
-import java.beans.PropertyChangeListener;
-import java.io.File;
-import java.util.List;
-
import org.nuiton.topia.event.TopiaContextListener;
import org.nuiton.topia.event.TopiaEntitiesVetoable;
import org.nuiton.topia.event.TopiaEntityListener;
@@ -38,6 +34,10 @@
import org.nuiton.topia.framework.TopiaService;
import org.nuiton.topia.persistence.TopiaEntity;
+import java.beans.PropertyChangeListener;
+import java.io.File;
+import java.util.List;
+
/**
* The TopiaContext is the most important class of ToPIA. It contains all the
* methods to manipulate data : transaction management, entities querying, event
@@ -54,7 +54,7 @@
* @version $Id$
*/
public interface TopiaContext extends TopiaTransaction, TopiaListenableSupport, TopiaSqlSupport, TopiaJpaSupport,
- TopiaPersistenceContext, TopiaServiceSupport, TopiaReplicationSupport, TopiaHibernateSupport {
+ TopiaPersistenceContext, TopiaServiceSupport, TopiaReplicationSupport, TopiaReplicationDestination, TopiaHibernateSupport {
/* -------------------- TRANSACTION MANAGEMENT --------------------------*/
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaPersistenceContext.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaPersistenceContext.java 2013-10-11 16:47:08 UTC (rev 2841)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaPersistenceContext.java 2013-10-11 16:53:04 UTC (rev 2842)
@@ -38,7 +38,7 @@
* @author Arnaud Thimel <thimel(a)codelutin.com>
* @since 3.0
*/
-public interface TopiaPersistenceContext extends TopiaDAOSupplier, TopiaTransaction {
+public interface TopiaPersistenceContext extends TopiaReplicationSupport, TopiaReplicationDestination, TopiaDAOSupplier, TopiaTransaction {
/**
* Retrieve {@link org.nuiton.topia.persistence.TopiaEntity} using its unique {@code topiaId}.
Added: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaReplicationDestination.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaReplicationDestination.java (rev 0)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaReplicationDestination.java 2013-10-11 16:53:04 UTC (rev 2842)
@@ -0,0 +1,19 @@
+package org.nuiton.topia;
+
+import org.nuiton.topia.persistence.TopiaEntity;
+
+/**
+ * Represent the destination of a replciation process. The source is
+ * {@link TopiaReplicationSupport}
+ */
+public interface TopiaReplicationDestination {
+
+ /**
+ * Must replicate given entity in current database
+ *
+ * @since 3.0
+ * @param entity
+ */
+ void replicate(TopiaEntity entity);
+
+}
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaReplicationSupport.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaReplicationSupport.java 2013-10-11 16:47:08 UTC (rev 2841)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaReplicationSupport.java 2013-10-11 16:53:04 UTC (rev 2842)
@@ -24,12 +24,12 @@
* #L%
*/
+import org.nuiton.topia.persistence.TopiaEntity;
+
import java.util.List;
-import org.nuiton.topia.persistence.TopiaEntity;
-
/**
- * This API provides methods about entities replication
+ * This API provides methods about entities replication to a destination
*
* @author Arnaud Thimel <thimel(a)codelutin.com>
* @since 3.0
@@ -45,9 +45,9 @@
* <p/>
* <b>Note 2:</b> The simple replication may not be sufficent. You may want
* to replicate only a part of some entities : use the method {@link
- * #replicateEntities(TopiaContext, java.util.List)}.
+ * #replicateEntities(TopiaReplicationDestination, java.util.List)}.
*
- * @param destinationContext the destination context
+ * @param topiaReplicationDestination the destination context
* @param entityAndCondition [key;value;...] parameter which key is the
* entity class to replicate, and value the
* "where" condition to use when querying entities
@@ -55,32 +55,32 @@
* trying to replicate within the same
* database
*/
- void replicate(TopiaContext destinationContext,
+ void replicate(TopiaReplicationDestination topiaReplicationDestination,
Object... entityAndCondition) throws IllegalArgumentException;
/**
* Replicate a given entity from this context to the given context.
*
- * @param destinationContext the destination context
+ * @param topiaReplicationDestination the destination context
* @param entity the entity instance to replicate
* @throws IllegalArgumentException if one of the context is closed or if
* trying to replicate within the same
* database
*/
- <T extends TopiaEntity> void replicateEntity(TopiaContext destinationContext,
+ <T extends TopiaEntity> void replicateEntity(TopiaReplicationDestination topiaReplicationDestination,
T entity) throws IllegalArgumentException;
/**
* Makes a replication of some entities from this context to the given
* context without any entity modification.
*
- * @param destinationContext the destination context
+ * @param topiaReplicationDestination the destination context
* @param entities the list of entities instance to replicate
* @throws IllegalArgumentException if one of the context is closed or if
* trying to replicate within the same
* database
*/
- <T extends TopiaEntity> void replicateEntities(TopiaContext destinationContext,
+ <T extends TopiaEntity> void replicateEntities(TopiaReplicationDestination topiaReplicationDestination,
List<T> entities) throws IllegalArgumentException;
}
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/AbstractTopiaContext.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/AbstractTopiaContext.java 2013-10-11 16:47:08 UTC (rev 2841)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/AbstractTopiaContext.java 2013-10-11 16:53:04 UTC (rev 2842)
@@ -51,6 +51,7 @@
import org.nuiton.topia.TopiaContextFactory;
import org.nuiton.topia.TopiaException;
import org.nuiton.topia.TopiaNotFoundException;
+import org.nuiton.topia.TopiaReplicationDestination;
import org.nuiton.topia.event.TopiaContextListener;
import org.nuiton.topia.event.TopiaEntitiesVetoable;
import org.nuiton.topia.event.TopiaEntityListener;
@@ -1203,6 +1204,26 @@
}
@Override
+ public void replicate(TopiaEntity entity) {
+ getHibernateSession().replicate(entity, ReplicationMode.EXCEPTION);
+ }
+
+ @Override
+ public void replicate(TopiaReplicationDestination topiaReplicationDestination, Object... entityAndCondition) throws IllegalArgumentException {
+ replicate((TopiaContext) topiaReplicationDestination, entityAndCondition);
+ }
+
+ @Override
+ public <T extends TopiaEntity> void replicateEntity(TopiaReplicationDestination topiaReplicationDestination, T entity) throws IllegalArgumentException {
+ replicateEntity((TopiaContext) topiaReplicationDestination, entity);
+ }
+
+ @Override
+ public <T extends TopiaEntity> void replicateEntities(TopiaReplicationDestination topiaReplicationDestination, List<T> entities) throws IllegalArgumentException {
+ replicateEntities((TopiaContext) topiaReplicationDestination, entities);
+ }
+
+ @Override
public TopiaFiresSupport getFiresSupport() {
return firesSupport;
}
1
0
r2841 - trunk/topia-persistence/src/main/java/org/nuiton/topia
by athimel@users.nuiton.org 11 Oct '13
by athimel@users.nuiton.org 11 Oct '13
11 Oct '13
Author: athimel
Date: 2013-10-11 18:47:08 +0200 (Fri, 11 Oct 2013)
New Revision: 2841
Url: http://nuiton.org/projects/topia/repository/revisions/2841
Log:
Implement TopiaServiceSupport and initialize it
Improve AbstractTopiaPersistenceContext documentation and transaction creation
Added:
trunk/topia-persistence/src/main/java/org/nuiton/topia/HibernateTopiaSqlSupport.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaServiceSupportImpl.java
Modified:
trunk/topia-persistence/src/main/java/org/nuiton/topia/AbstractTopiaApplicationContext.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/AbstractTopiaPersistenceContext.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/HibernateTopiaJpaSupport.java
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/AbstractTopiaApplicationContext.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/AbstractTopiaApplicationContext.java 2013-10-11 15:13:30 UTC (rev 2840)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/AbstractTopiaApplicationContext.java 2013-10-11 16:47:08 UTC (rev 2841)
@@ -31,7 +31,6 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.HibernateException;
-import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.hibernate.tool.hbm2ddl.SchemaExport;
import org.hibernate.tool.hbm2ddl.SchemaUpdate;
@@ -84,6 +83,16 @@
this((Map) ImmutableMap.copyOf(properties));
}
+ public AbstractTopiaApplicationContext(Map<String, String> configuration) {
+ Map<String, String> configurationCopy = Maps.newHashMap();
+ configurationCopy.putAll(configuration);
+ if ( ! configuration.containsKey(TopiaContextFactory.CONFIG_PERSISTENCE_CLASSES)) {
+ configurationCopy.put(TopiaContextFactory.CONFIG_PERSISTENCE_CLASSES, getImplementationClassesAsString());
+ }
+ this.configuration = ImmutableMap.copyOf(configurationCopy);
+ this.topiaServiceSupport = new TopiaServiceSupportImpl(this);
+ }
+
protected abstract Class<? extends TopiaEntity>[] getImplementationClasses();
protected String getImplementationClassesAsString() {
@@ -94,15 +103,6 @@
return buffer.substring(1);
}
- public AbstractTopiaApplicationContext(Map<String, String> configuration) {
- Map<String, String> configurationCopy = Maps.newHashMap();
- configurationCopy.putAll(configuration);
- if ( ! configuration.containsKey(TopiaContextFactory.CONFIG_PERSISTENCE_CLASSES)) {
- configurationCopy.put(TopiaContextFactory.CONFIG_PERSISTENCE_CLASSES, getImplementationClassesAsString());
- }
- this.configuration = ImmutableMap.copyOf(configurationCopy);
- }
-
protected HibernateProvider getHibernateProvider() {
if (hibernateProvider == null) {
hibernateProvider = new HibernateProvider(configuration, topiaServiceSupport);
@@ -110,10 +110,6 @@
return hibernateProvider;
}
- protected SessionFactory getSessionFactory() {
- return getHibernateProvider().getSessionFactory();
- }
-
protected TopiaListenableSupport getTopiaListenableSupport() {
return topiaFiresSupport;
}
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/AbstractTopiaPersistenceContext.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/AbstractTopiaPersistenceContext.java 2013-10-11 15:13:30 UTC (rev 2840)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/AbstractTopiaPersistenceContext.java 2013-10-11 16:47:08 UTC (rev 2841)
@@ -58,61 +58,79 @@
/**
* Already loaded DAO cache within this persistence context
*/
- protected Map<Class<? extends TopiaEntity>, TopiaDAO<? extends TopiaEntity>> daoCache = Maps.newHashMap(); // TODO AThimel 27/09/13 Concurrent map ?
+ protected Map<Class<? extends TopiaEntity>, TopiaDAO<? extends TopiaEntity>> daoCache = Maps.newConcurrentMap();
// TODO AThimel 27/09/13 Javadoc
+ protected TopiaListenableSupport listenableSupport;
+
+ /**
+ * Used to affect a new topiaId when create is called.
+ */
+ protected TopiaIdFactory topiaIdFactory;
+
+ // TODO AThimel 27/09/13 Javadoc
protected TopiaFiresSupport firesSupport;
- // TODO AThimel 27/09/13 Javadoc
+ /**
+ * This subclass of TopiaHibernateSupport is made to be used only internally within this persistence context. This
+ * instance is created by the persistence context itself.
+ */
protected InternalTopiaHibernateSupport hibernateSupport;
- // TODO AThimel 27/09/13 Javadoc
+ /**
+ * This instance of TopiaJpaSupport is created by the persistence context itself. It is actually using the
+ * TopiaHibernateSupport instance.
+ */
protected TopiaJpaSupport jpaSupport;
- // TODO AThimel 27/09/13 Javadoc
+ /**
+ * This instance of TopiaSqlSupport is created by the persistence context itself. It is actually using the
+ * TopiaHibernateSupport instance.
+ */
protected TopiaSqlSupport sqlSupport;
- // TODO AThimel 27/09/13 Javadoc
- protected TopiaListenableSupport listenableSupport;
-
/**
- * Used to affect a new topiaId when create is called.
- *
- * @since 3.0
+ * Flog used to check if this persistence context is closed
*/
- protected TopiaIdFactory topiaIdFactory;
-
protected boolean closed = false;
/**
* Creating a new TopiaPersistenceContext is equivalent to creating a new transaction
*
- * @param hibernateProvider
- * @param listenableSupport
- * @param topiaIdFactory // * @param config
+ * @param hibernateProvider holds the Hibernate configuration and session factory
+ * @param listenableSupport the listenableSupport instance to use within this persistence context
+ * @param topiaIdFactory the TopiaIdFactory instance created according to the application's configuration
*/
public AbstractTopiaPersistenceContext(HibernateProvider hibernateProvider,
TopiaListenableSupport listenableSupport,
TopiaIdFactory topiaIdFactory) {
- Session hibernateSession = startTransaction(hibernateProvider);
- this.hibernateSupport = new InternalTopiaHibernateSupport(hibernateProvider, hibernateSession);
- // TODO brendan 11/10/13 init this.sqlSupport
this.listenableSupport = listenableSupport;
this.topiaIdFactory = topiaIdFactory;
+ // Hibernate support can be created using the given hibernateProvider
+ this.hibernateSupport = new InternalTopiaHibernateSupport(hibernateProvider);
+
+ // Now starts the transaction, as this persistenceContext IS the TopiaTransaction
+ startTransaction();
+
+ // Create the different supports that may be needed by the DAOs
this.firesSupport = new TopiaFiresSupport();
this.jpaSupport = new HibernateTopiaJpaSupport(hibernateSupport, firesSupport);
+ this.sqlSupport = new HibernateTopiaSqlSupport(hibernateSupport);
}
+ /**
+ * This subclass of TopiaHibernateSupport is made to be used only internally within this persistence context. This
+ * class only acts as an information container (as a structure does).
+ */
protected class InternalTopiaHibernateSupport implements TopiaHibernateSupport {
protected HibernateProvider hibernateProvider;
protected Session hibernateSession;
- protected InternalTopiaHibernateSupport(HibernateProvider hibernateProvider, Session hibernateSession) {
+ protected InternalTopiaHibernateSupport(HibernateProvider hibernateProvider) {
this.hibernateProvider = hibernateProvider;
- this.hibernateSession = hibernateSession;
}
public void setHibernateSession(Session hibernateSession) {
@@ -121,6 +139,7 @@
@Override
public Session getHibernateSession() {
+ Preconditions.checkState(hibernateSession != null, "Session is not yet initialized");
return hibernateSession;
}
@@ -135,10 +154,11 @@
}
}
- protected Session startTransaction(HibernateProvider hibernateProvider) throws TopiaException {
+ protected void startTransaction() throws TopiaException {
- SessionFactory factory = hibernateProvider.getSessionFactory();
+ SessionFactory factory = hibernateSupport.getHibernateFactory();
Session result = factory.openSession();
+ hibernateSupport.setHibernateSession(result);
// new TopiaInterceptor(result));
// on ne synchronise jamais les données avec la base tant que
@@ -173,7 +193,6 @@
// fire event
getFiresSupport().fireOnBeginTransaction(this);
- return result;
}
protected void checkClosed() throws TopiaException {
@@ -216,10 +235,6 @@
public <E extends TopiaEntity> TopiaDAO<E> getDAO(Class<E> entityClass) {
Preconditions.checkArgument(entityClass != null, "The method 'getDAO' requires a non null 'entityClass' parameter");
-// if (equals(getRootContext())) {
-// throw new TopiaException(
-// "You are on root context, you MUST open a transaction to perform any database access.");
-// }
SessionFactory hibernateFactory = hibernateSupport.getHibernateFactory();
if (hibernateFactory.getClassMetadata(entityClass) == null &&
hibernateFactory.getClassMetadata(entityClass.getName() + "Impl") == null &&
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/HibernateTopiaJpaSupport.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/HibernateTopiaJpaSupport.java 2013-10-11 15:13:30 UTC (rev 2840)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/HibernateTopiaJpaSupport.java 2013-10-11 16:47:08 UTC (rev 2841)
@@ -74,13 +74,6 @@
this.firesSupport = firesSupport;
}
- protected void checkClosed() throws TopiaException {
- // TODO AThimel 27/09/13 IS it still useful ?
-// if (closed) {
-// throw new TopiaException("This jpaSupport is closed, it is not possible to use it anymore");
-// }
- }
-
@Override
public void setUseFlushMode(boolean useFlushMode) {
this.useFlushMode = useFlushMode;
@@ -108,8 +101,6 @@
@Override
public <T> List<T> findAll(String jpaql, Map<String, Object> parameters) {
- checkClosed();
-
try {
Query query = prepareQuery(jpaql, parameters);
@@ -129,8 +120,6 @@
@Override
public <T> List<T> find(String jpaql, int startIndex, int endIndex, Map<String, Object> parameters) {
- checkClosed();
-
try {
Query query = prepareQuery(jpaql, parameters);
@@ -154,8 +143,6 @@
@Override
public int execute(String jpaql, Map<String, Object> parameters) {
- checkClosed();
-
try {
Query query = prepareQuery(jpaql, parameters);
Added: trunk/topia-persistence/src/main/java/org/nuiton/topia/HibernateTopiaSqlSupport.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/HibernateTopiaSqlSupport.java (rev 0)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/HibernateTopiaSqlSupport.java 2013-10-11 16:47:08 UTC (rev 2841)
@@ -0,0 +1,73 @@
+package org.nuiton.topia;
+
+/*
+ * #%L
+ * ToPIA :: Persistence
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2004 - 2013 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%
+ */
+
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+
+import org.hibernate.HibernateException;
+import org.hibernate.jdbc.Work;
+
+/**
+ * @author Arnaud Thimel <thimel(a)codelutin.com>
+ */
+public class HibernateTopiaSqlSupport implements TopiaSqlSupport {
+
+ protected TopiaHibernateSupport hibernateSupport;
+
+ public HibernateTopiaSqlSupport(TopiaHibernateSupport hibernateSupport) {
+ this.hibernateSupport = hibernateSupport;
+ }
+
+ @Override
+ public void executeSQL(String sqlScript) {
+ SQLWork sqlWork = new SQLWork(sqlScript);
+ try {
+ hibernateSupport.getHibernateSession().doWork(sqlWork);
+ } catch (HibernateException e) {
+ throw new TopiaException("Could not execute sql code", e);
+ }
+ }
+
+ public static class SQLWork implements Work {
+ private final String script;
+
+ public SQLWork(String script) {
+ this.script = script;
+ }
+
+ @Override
+ public void execute(Connection connection) throws SQLException {
+ PreparedStatement sta = connection.prepareStatement(script);
+ try {
+ sta.execute();
+ } finally {
+ sta.close();
+ }
+ }
+ }
+
+}
Property changes on: trunk/topia-persistence/src/main/java/org/nuiton/topia/HibernateTopiaSqlSupport.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Added: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaServiceSupportImpl.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaServiceSupportImpl.java (rev 0)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaServiceSupportImpl.java 2013-10-11 16:47:08 UTC (rev 2841)
@@ -0,0 +1,173 @@
+package org.nuiton.topia;
+
+/*
+ * #%L
+ * ToPIA :: Persistence
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2004 - 2013 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%
+ */
+
+import java.lang.reflect.Field;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.nuiton.topia.framework.TopiaService;
+
+import com.google.common.collect.ImmutableMap;
+
+/**
+ * FIXME AThimel 11/10/13 All this life-cycle has to be reviewed
+ *
+ * @author Arnaud Thimel <thimel(a)codelutin.com>
+ */
+public class TopiaServiceSupportImpl implements TopiaServiceSupport {
+
+ private static final Log log = LogFactory.getLog(TopiaServiceSupportImpl.class);
+
+ protected ImmutableMap<String, TopiaService> services;
+ protected AbstractTopiaApplicationContext applicationContext;
+
+ public TopiaServiceSupportImpl(AbstractTopiaApplicationContext applicationContext) {
+ this.applicationContext = applicationContext;
+ this.services = loadServices(applicationContext.getConfiguration());
+ preInitServices(this.services);
+ applicationContext.getHibernateProvider().getHibernateConfiguration(); // force mapping loading
+ postInitServices(this.services);
+ }
+
+ protected void preInitServices(Map<String, TopiaService> services) {
+ for (TopiaService service : services.values()) {
+ if (!service.preInit(null)) { // TODO AThimel 11/10/13 was: this (aka TopiaContext)
+ log.warn(String.format("The service named '%1$s' could not be post-initialized (service not activated)",
+ service.getServiceName()));
+ }
+ }
+ }
+
+ protected void postInitServices(Map<String, TopiaService> services) {
+ for (TopiaService service : services.values()) {
+ if (!service.postInit(null)) { // TODO AThimel 11/10/13 was: this (aka TopiaContext)
+ log.warn(String.format("The service named '%1$s' could not be pre-initialized (service not activated)",
+ service.getServiceName()));
+ }
+ }
+ }
+
+ /**
+ * Retrieve service name using SERVICE_NAME static field on service
+ * interface.
+ *
+ * @param interfaceService class of the service
+ * @param <E> type of the service that extends {@link
+ * TopiaService}
+ * @return the service name
+ * @throws IllegalAccessException if field SERVICE_NAME can't be accessed
+ * @throws NoSuchFieldException if no field SERVICE_NAME is defined
+ */
+ protected <E extends TopiaService> String getServiceName(
+ Class<E> interfaceService)
+ throws IllegalAccessException, NoSuchFieldException {
+ Field f = interfaceService.getField("SERVICE_NAME");
+ String name = (String) f.get(null);
+ return name;
+ }
+
+ protected String getProperExceptionMessage(Throwable eee) {
+ return eee.getClass().getSimpleName() + " : " + eee.getMessage();
+ }
+
+ protected ImmutableMap<String, TopiaService> loadServices(ImmutableMap<String, String> configuration) {
+ Map<String, TopiaService> result = new HashMap<String, TopiaService>();
+ // recherche des services present dans la config
+ for (String key : result.keySet()) {
+ if (key.matches("^topia\\.service\\.\\w+$")) {
+ String serviceClass = configuration.get(key);
+ try {
+ Class<?> forName = Class.forName(serviceClass);
+ Object newInstance = forName.getConstructor().newInstance();
+ TopiaService service = (TopiaService) newInstance;
+ if (key.equals("topia.service." + service.getServiceName())) {
+ result.put(service.getServiceName(), service);
+ log.info(String.format("Service '%1$s' loaded (implementation %2$s)",
+ key, serviceClass));
+ } else {
+ log.warn(String.format("The service with key '%1$s' has a different name '%2$s'! (service not activated)",
+ key, service.getServiceName()));
+ }
+ } catch (Throwable eee) {
+ String message =
+ String.format("The service %1$s of type %2$s was not found.",
+ key, serviceClass);
+ if (log.isDebugEnabled()) {
+ log.debug(message, eee);
+ } else if (log.isErrorEnabled()) {
+ log.error(message);
+ }
+ }
+ }
+ }
+ return ImmutableMap.copyOf(result);
+ }
+
+
+ @Override
+ public <E extends TopiaService> boolean serviceEnabled(Class<E> interfaceService) {
+ boolean result = false;
+ try {
+ String name = getServiceName(interfaceService);
+ result = getServices().containsKey(name);
+ } catch (Exception eee) {
+ String format = "The service named '%1$s' could not be found for following reason: %2$s";
+ String message = String.format(format, interfaceService, getProperExceptionMessage(eee));
+ if (log.isDebugEnabled()) {
+ log.debug(message, eee);
+ } else if (log.isWarnEnabled()) {
+ log.warn(message);
+ }
+ }
+ return result;
+ }
+
+ @Override
+ public <E extends TopiaService> E getService(Class<E> interfaceService) throws TopiaNotFoundException {
+ E result;
+ try {
+ String name = getServiceName(interfaceService);
+ result = (E) getServices().get(name);
+ } catch (Exception eee) {
+ String format = "Could not retreave service %1$s for following reason: %2$s";
+ String message = String.format(format, interfaceService, getProperExceptionMessage(eee));
+ throw new TopiaNotFoundException(message, eee);
+ }
+ if (result == null) {
+ String message = String.format("The service %1$s was not found.", interfaceService);
+ throw new TopiaNotFoundException(message);
+ }
+ return result;
+ }
+
+ @Override
+ public Map<String, TopiaService> getServices() {
+ return services;
+ }
+
+}
Property changes on: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaServiceSupportImpl.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
1
0
r2840 - in trunk: topia-persistence/src/main/java/org/nuiton/topia topia-persistence/src/main/java/org/nuiton/topia/event topia-persistence/src/main/java/org/nuiton/topia/framework topia-service-migration/src/main/java/org/nuiton/topia/migration
by athimel@users.nuiton.org 11 Oct '13
by athimel@users.nuiton.org 11 Oct '13
11 Oct '13
Author: athimel
Date: 2013-10-11 17:13:30 +0200 (Fri, 11 Oct 2013)
New Revision: 2840
Url: http://nuiton.org/projects/topia/repository/revisions/2840
Log:
Implementation Hibernate session open/commit/rollback/close
Modified:
trunk/topia-persistence/src/main/java/org/nuiton/topia/AbstractTopiaPersistenceContext.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaPersistenceContext.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaTransaction.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/event/TopiaTransactionEvent.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/AbstractTopiaContext.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaFiresSupport.java
trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/TopiaMigrationEngine.java
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/AbstractTopiaPersistenceContext.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/AbstractTopiaPersistenceContext.java 2013-10-11 15:10:28 UTC (rev 2839)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/AbstractTopiaPersistenceContext.java 2013-10-11 15:13:30 UTC (rev 2840)
@@ -24,28 +24,25 @@
* #L%
*/
-import com.google.common.base.Preconditions;
-import com.google.common.collect.Lists;
-import com.google.common.collect.Maps;
+import java.lang.reflect.InvocationTargetException;
+import java.util.Map;
+
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.hibernate.FlushMode;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
+import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
-import org.hibernate.tool.hbm2ddl.SchemaExport;
-import org.hibernate.tool.hbm2ddl.SchemaUpdate;
import org.nuiton.topia.framework.TopiaFiresSupport;
-import org.nuiton.topia.framework.TopiaUtil;
import org.nuiton.topia.persistence.AbstractTopiaDAO;
import org.nuiton.topia.persistence.TopiaDAO;
import org.nuiton.topia.persistence.TopiaEntity;
import org.nuiton.topia.persistence.TopiaIdFactory;
-import java.lang.reflect.InvocationTargetException;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
+import com.google.common.base.Preconditions;
+import com.google.common.collect.Maps;
/**
* Abstract implementation of the TopiaPersistenceContext. This class will be extended by a generated one in order to
@@ -85,46 +82,46 @@
*/
protected TopiaIdFactory topiaIdFactory;
-// /**
-// * Current context configuration
-// */
-// protected Properties config;
+ protected boolean closed = false;
/**
* Creating a new TopiaPersistenceContext is equivalent to creating a new transaction
*
* @param hibernateProvider
- * @param sqlSupport
* @param listenableSupport
- * @param topiaIdFactory
-// * @param config
+ * @param topiaIdFactory // * @param config
*/
public AbstractTopiaPersistenceContext(HibernateProvider hibernateProvider,
TopiaListenableSupport listenableSupport,
TopiaIdFactory topiaIdFactory) {
- this.hibernateSupport = new InternalTopiaHibernateSupport(hibernateProvider);
+ Session hibernateSession = startTransaction(hibernateProvider);
+ this.hibernateSupport = new InternalTopiaHibernateSupport(hibernateProvider, hibernateSession);
// TODO brendan 11/10/13 init this.sqlSupport
this.listenableSupport = listenableSupport;
this.topiaIdFactory = topiaIdFactory;
-// this.config = config;
this.firesSupport = new TopiaFiresSupport();
this.jpaSupport = new HibernateTopiaJpaSupport(hibernateSupport, firesSupport);
-
}
protected class InternalTopiaHibernateSupport implements TopiaHibernateSupport {
protected HibernateProvider hibernateProvider;
+ protected Session hibernateSession;
- protected InternalTopiaHibernateSupport(HibernateProvider hibernateProvider) {
+ protected InternalTopiaHibernateSupport(HibernateProvider hibernateProvider, Session hibernateSession) {
this.hibernateProvider = hibernateProvider;
+ this.hibernateSession = hibernateSession;
}
+ public void setHibernateSession(Session hibernateSession) {
+ this.hibernateSession = hibernateSession;
+ }
+
@Override
public Session getHibernateSession() {
- return null;
+ return hibernateSession;
}
@Override
@@ -138,11 +135,51 @@
}
}
+ protected Session startTransaction(HibernateProvider hibernateProvider) throws TopiaException {
+
+ SessionFactory factory = hibernateProvider.getSessionFactory();
+ Session result = factory.openSession();
+
+ // new TopiaInterceptor(result));
+ // on ne synchronise jamais les données avec la base tant que
+ // l'utilisateur n'a pas fait de commit du context
+ result.setFlushMode(FlushMode.MANUAL);
+
+ // tchemit 2010-12-06 propagates the value of the flag
+// result.useFlushMode = useFlushMode;
+
+ // 20060926 poussin ajouter pour voir si ca regle les problemes de
+ // deadlock h2. Conclusion, il faut bien ouvrir une transaction
+ // maintenant, sinon lorsque l'on fait des acces a la base, une
+ // transaction par defaut est utilisé mais elle n'est jamais vraiment
+ // fermé ce qui pose des problemes de lock sur les tables.
+ try {
+ result.beginTransaction();
+ } catch (Exception eee) {
+
+ // on a pas pu ouvrir la transaction, on faut donc tout fermer
+ // et declancher une exception
+ try {
+ result.close();
+ } catch (HibernateException e1) {
+ if (log.isErrorEnabled()) {
+ log.error("Could not close hibernate session", e1);
+ }
+ }
+
+ String message = String.format("An error occurs while asking a new transaction: %1$s", eee.getMessage());
+ throw new TopiaException(message, eee);
+ }
+
+ // fire event
+ getFiresSupport().fireOnBeginTransaction(this);
+ return result;
+ }
+
protected void checkClosed() throws TopiaException {
- // TODO AThimel 27/09/13 IS it still useful ?
-// if (closed) {
-// throw new TopiaException("This context is closed, it is not possible to use it anymore");
-// }
+ if (closed) {
+ throw new TopiaException("This context is closed, it is not possible to use it anymore");
+ }
}
protected TopiaFiresSupport getFiresSupport() {
@@ -175,11 +212,6 @@
return topiaIdFactory;
}
-// @Override
-// public Properties getConfig() {
-// return config;
-// }
-
@Override
public <E extends TopiaEntity> TopiaDAO<E> getDAO(Class<E> entityClass) {
Preconditions.checkArgument(entityClass != null, "The method 'getDAO' requires a non null 'entityClass' parameter");
@@ -245,21 +277,78 @@
@Override
public void commitTransaction() {
- //To change body of implemented methods use File | Settings | File Templates.
+ checkClosed();
+
+ try {
+
+ Session hibernateSession = hibernateSupport.getHibernateSession();
+
+ Transaction tx = hibernateSession.getTransaction();
+ hibernateSession.flush();
+ tx.commit();
+
+ getFiresSupport().fireOnPostCommit(this);
+// TopiaContextImplementor parent = getParentContext();
+// if (parent != null) {
+// parent.getFiresSupport().fireOnPostCommit(this);
+// }
+
+ hibernateSession.beginTransaction();
+
+ // 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.setFlushMode(FlushMode.NEVER);
+ } catch (Exception eee) {
+ String message = String.format("An error occurred during commit operation: %1$s", eee.getMessage());
+ throw new TopiaException(message, eee);
+ }
}
@Override
public void rollbackTransaction() {
- //To change body of implemented methods use File | Settings | File Templates.
+ checkClosed();
+ try {
+ Session hibernateSession = hibernateSupport.getHibernateSession();
+
+ Transaction tx = hibernateSession.getTransaction();
+ hibernateSession.clear();
+ tx.rollback();
+ hibernateSession.close();
+
+ // it's very important to change the session after rollback
+ // otherwise there are many error during next Entity's modification
+ hibernateSession = hibernateSupport.getHibernateFactory().openSession();
+ hibernateSupport.setHibernateSession(hibernateSession);
+ hibernateSession.setFlushMode(FlushMode.MANUAL);
+
+ hibernateSession.beginTransaction();
+
+ getFiresSupport().fireOnPostRollback(this);
+// TopiaContextImplementor parent = getParentContext();
+// if (parent != null) {
+// parent.getFiresSupport().fireOnPostRollback(this);
+// }
+
+ } catch (HibernateException eee) {
+ String message = String.format("An error occurred during rollback operation: %1$s", eee.getMessage());
+ throw new TopiaException(message, eee);
+ }
}
@Override
- public void closeContext() {
- //To change body of implemented methods use File | Settings | File Templates.
+ public void close() {
+ checkClosed();
+ closed = true;
+
+ // Now close the current Hibernate session
+ hibernateSupport.getHibernateSession().close();
}
@Override
public boolean isClosed() {
- return false; //To change body of implemented methods use File | Settings | File Templates.
+ return closed;
}
+
}
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaPersistenceContext.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaPersistenceContext.java 2013-10-11 15:10:28 UTC (rev 2839)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaPersistenceContext.java 2013-10-11 15:13:30 UTC (rev 2840)
@@ -64,4 +64,17 @@
*/
TopiaIdFactory getTopiaIdFactory();
+ /**
+ * Closes the context. All the children contexts will be closed in the same
+ * time.
+ */
+ void close();
+
+ /**
+ * Tells if the context is closed
+ *
+ * @return {@code true} if the context is closed, {@code false} otherwise
+ */
+ boolean isClosed();
+
}
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaTransaction.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaTransaction.java 2013-10-11 15:10:28 UTC (rev 2839)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaTransaction.java 2013-10-11 15:13:30 UTC (rev 2840)
@@ -45,17 +45,4 @@
*/
void rollbackTransaction();
- /**
- * Closes the context. All the children contexts will be closed in the same
- * time.
- */
- void closeContext();
-
- /**
- * Tells if the context is closed
- *
- * @return {@code true} if the context is closed, {@code false} otherwise
- */
- boolean isClosed();
-
}
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/event/TopiaTransactionEvent.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/event/TopiaTransactionEvent.java 2013-10-11 15:10:28 UTC (rev 2839)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/event/TopiaTransactionEvent.java 2013-10-11 15:13:30 UTC (rev 2840)
@@ -27,6 +27,7 @@
import org.apache.commons.collections.map.IdentityMap;
import org.nuiton.topia.TopiaContext;
+import org.nuiton.topia.TopiaTransaction;
import org.nuiton.topia.framework.EntityState;
import org.nuiton.topia.persistence.TopiaEntity;
@@ -47,11 +48,11 @@
private Map<TopiaEntity, EntityState> entities = new IdentityMap();
- public TopiaTransactionEvent(TopiaContext source) {
+ public TopiaTransactionEvent(TopiaTransaction source) {
super(source);
}
- public TopiaTransactionEvent(TopiaContext source,
+ public TopiaTransactionEvent(TopiaTransaction source,
Map<TopiaEntity, EntityState> entities) {
this(source);
this.entities.putAll(entities);
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/AbstractTopiaContext.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/AbstractTopiaContext.java 2013-10-11 15:10:28 UTC (rev 2839)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/AbstractTopiaContext.java 2013-10-11 15:13:30 UTC (rev 2840)
@@ -890,6 +890,11 @@
}
@Override
+ public void close() {
+ closeContext();
+ }
+
+ @Override
public void closeContext() throws TopiaException {
// Throw exception if context is already closed
checkClosed("Context was already closed");
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaFiresSupport.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaFiresSupport.java 2013-10-11 15:10:28 UTC (rev 2839)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaFiresSupport.java 2013-10-11 15:13:30 UTC (rev 2840)
@@ -55,6 +55,7 @@
import org.nuiton.topia.TopiaJpaSupport;
import org.nuiton.topia.TopiaListenableSupport;
import org.nuiton.topia.TopiaPersistenceContext;
+import org.nuiton.topia.TopiaTransaction;
import org.nuiton.topia.TopiaVetoException;
import org.nuiton.topia.event.TopiaContextEvent;
import org.nuiton.topia.event.TopiaContextListener;
@@ -220,7 +221,7 @@
/* Fires sur les transactions */
- public void fireOnBeginTransaction(TopiaContextImplementor context) {
+ public void fireOnBeginTransaction(TopiaTransaction context) {
if (log.isDebugEnabled()) {
log.debug("fireOnBeginTransaction");
}
@@ -234,7 +235,7 @@
}
}
- public void fireOnPostCommit(TopiaContextImplementor context) {
+ public void fireOnPostCommit(TopiaTransaction context) {
if (log.isDebugEnabled()) {
log.debug("fireOnPostCommit");
}
@@ -252,7 +253,7 @@
transactionEntities.clear();
}
- public void fireOnPostRollback(TopiaContextImplementor context) {
+ public void fireOnPostRollback(TopiaTransaction context) {
if (log.isDebugEnabled()) {
log.debug("fireOnPostRollback");
}
Modified: trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/TopiaMigrationEngine.java
===================================================================
--- trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/TopiaMigrationEngine.java 2013-10-11 15:10:28 UTC (rev 2839)
+++ trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/TopiaMigrationEngine.java 2013-10-11 15:13:30 UTC (rev 2840)
@@ -38,6 +38,7 @@
import org.nuiton.topia.event.TopiaContextListener;
import org.nuiton.topia.event.TopiaTransactionEvent;
import org.nuiton.topia.event.TopiaTransactionVetoable;
+import org.nuiton.topia.framework.AbstractTopiaContext;
import org.nuiton.topia.framework.TopiaContextImplementor;
import org.nuiton.topia.framework.TopiaUtil;
import org.nuiton.topia.migration.mappings.TMSVersion;
@@ -197,7 +198,7 @@
public boolean preInit(TopiaContext context) {
rootContext = context;
- Properties config = context.getConfig();
+ Properties config = ((AbstractTopiaContext)context).getConfig();
String callbackStr = getSafeParameter(config, MIGRATION_CALLBACK);
if (log.isDebugEnabled()) {
@@ -657,7 +658,7 @@
* @since 2.5.3
*/
protected Configuration createHibernateConfiguration(Configuration configuration) {
- Properties config = rootContext.getConfig();
+ Properties config = ((AbstractTopiaContext)rootContext).getConfig();
Properties prop = new Properties();
prop.putAll(configuration.getProperties());
1
0
r2839 - trunk/topia-persistence/src/main/java/org/nuiton/topia/generator
by bleny@users.nuiton.org 11 Oct '13
by bleny@users.nuiton.org 11 Oct '13
11 Oct '13
Author: bleny
Date: 2013-10-11 17:10:28 +0200 (Fri, 11 Oct 2013)
New Revision: 2839
Url: http://nuiton.org/projects/topia/repository/revisions/2839
Log:
remove usused generated code
Modified:
trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/ApplicationContextTransformer.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/PersistenceContextTransformer.java
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/ApplicationContextTransformer.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/ApplicationContextTransformer.java 2013-10-11 14:42:42 UTC (rev 2838)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/ApplicationContextTransformer.java 2013-10-11 15:10:28 UTC (rev 2839)
@@ -241,18 +241,6 @@
}*/
);
- // getImplementationClassesAsString method
- op = addOperation(output, "getImplementationClassesAsString", "String", ObjectModelJavaModifier.PUBLIC);
- setOperationBody(op, ""
-/*{
- StringBuilder buffer = new StringBuilder();
- for (Class<? extends TopiaEntity> aClass : getImplementationClasses()) {
- buffer.append(',').append(aClass.getName());
- }
- return buffer.substring(1);
- }*/
- );
-
// getContracts method
op = addOperation(output, "getContracts", entityEnumName + "[]", ObjectModelJavaModifier.PUBLIC);
setOperationBody(op, ""
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/PersistenceContextTransformer.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/PersistenceContextTransformer.java 2013-10-11 14:42:42 UTC (rev 2838)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/PersistenceContextTransformer.java 2013-10-11 15:10:28 UTC (rev 2839)
@@ -236,18 +236,6 @@
}*/
);
- // getImplementationClassesAsString method
- op = addOperation(output, "getImplementationClassesAsString", "String", ObjectModelJavaModifier.PUBLIC, ObjectModelJavaModifier.STATIC);
- setOperationBody(op, ""
-/*{
- StringBuilder buffer = new StringBuilder();
- for (Class<? extends TopiaEntity> aClass : getImplementationClasses()) {
- buffer.append(',').append(aClass.getName());
- }
- return buffer.substring(1);
- }*/
- );
-
// getContracts method
op = addOperation(output, "getContracts", entityEnumName + "[]", ObjectModelJavaModifier.PUBLIC, ObjectModelJavaModifier.STATIC);
setOperationBody(op, ""
1
0
r2838 - trunk/topia-persistence/src/main/java/org/nuiton/topia
by athimel@users.nuiton.org 11 Oct '13
by athimel@users.nuiton.org 11 Oct '13
11 Oct '13
Author: athimel
Date: 2013-10-11 16:42:42 +0200 (Fri, 11 Oct 2013)
New Revision: 2838
Url: http://nuiton.org/projects/topia/repository/revisions/2838
Log:
Implement TopiaApplicationContextgetPersistenceClasses()
Modified:
trunk/topia-persistence/src/main/java/org/nuiton/topia/AbstractTopiaApplicationContext.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/HibernateProvider.java
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/AbstractTopiaApplicationContext.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/AbstractTopiaApplicationContext.java 2013-10-11 14:40:39 UTC (rev 2837)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/AbstractTopiaApplicationContext.java 2013-10-11 14:42:42 UTC (rev 2838)
@@ -270,7 +270,7 @@
}
public List<Class<?>> getPersistenceClasses() {
- return null; // TODO AThimel 27/09/13 May be moved to TopiaHibernateSupport ?
+ return getHibernateProvider().getPersistentClasses();
}
public boolean isSchemaEmpty() {
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/HibernateProvider.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/HibernateProvider.java 2013-10-11 14:40:39 UTC (rev 2837)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/HibernateProvider.java 2013-10-11 14:42:42 UTC (rev 2838)
@@ -84,6 +84,14 @@
return result;
}
+ public List<Class<?>> getPersistentClasses() {
+ if (persistentClasses.isEmpty()) {
+ // Force configuration load
+ getHibernateConfiguration();
+ }
+ return persistentClasses;
+ }
+
public Configuration getHibernateConfiguration() {
if (hibernateConfiguration == null) {
hibernateConfiguration = new Configuration();
1
0
r2837 - in trunk/topia-persistence/src/main/java/org/nuiton/topia: . framework generator
by bleny@users.nuiton.org 11 Oct '13
by bleny@users.nuiton.org 11 Oct '13
11 Oct '13
Author: bleny
Date: 2013-10-11 16:40:39 +0200 (Fri, 11 Oct 2013)
New Revision: 2837
Url: http://nuiton.org/projects/topia/repository/revisions/2837
Log:
move some methods around ApplicationContext and PersistenceContext recode instanciation of business PersistenceContext
Modified:
trunk/topia-persistence/src/main/java/org/nuiton/topia/AbstractTopiaApplicationContext.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/AbstractTopiaPersistenceContext.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaPersistenceContext.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/AbstractTopiaContext.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaFiresSupport.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/ApplicationContextTransformer.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/PersistenceContextTransformer.java
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/AbstractTopiaApplicationContext.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/AbstractTopiaApplicationContext.java 2013-10-11 14:18:51 UTC (rev 2836)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/AbstractTopiaApplicationContext.java 2013-10-11 14:40:39 UTC (rev 2837)
@@ -28,14 +28,22 @@
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps;
import org.apache.commons.lang3.StringUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.hibernate.HibernateException;
import org.hibernate.SessionFactory;
+import org.hibernate.cfg.Configuration;
+import org.hibernate.tool.hbm2ddl.SchemaExport;
+import org.hibernate.tool.hbm2ddl.SchemaUpdate;
import org.nuiton.topia.event.TopiaEntitiesVetoable;
import org.nuiton.topia.event.TopiaEntityListener;
import org.nuiton.topia.event.TopiaEntityVetoable;
import org.nuiton.topia.event.TopiaSchemaListener;
import org.nuiton.topia.event.TopiaTransactionListener;
import org.nuiton.topia.event.TopiaTransactionVetoable;
+import org.nuiton.topia.framework.TopiaFiresSupport;
import org.nuiton.topia.framework.TopiaService;
+import org.nuiton.topia.framework.TopiaUtil;
import org.nuiton.topia.persistence.DefaultTopiaIdFactory;
import org.nuiton.topia.persistence.TopiaEntity;
import org.nuiton.topia.persistence.TopiaIdFactory;
@@ -55,13 +63,15 @@
*/
public abstract class AbstractTopiaApplicationContext<K extends TopiaPersistenceContext> implements TopiaReplicationSupport, TopiaListenableSupport, TopiaServiceSupport {
+ private static final Log log = LogFactory.getLog(AbstractTopiaApplicationContext.class);
+
protected TopiaIdFactory topiaIdFactory;
protected ImmutableMap<String, String> configuration;
protected TopiaReplicationSupport topiaReplicationSupport;
- protected TopiaListenableSupport topiaListenableSupport;
+ protected TopiaFiresSupport topiaFiresSupport = new TopiaFiresSupport();
protected TopiaServiceSupport topiaServiceSupport;
@@ -105,8 +115,7 @@
}
protected TopiaListenableSupport getTopiaListenableSupport() {
- // TODO brendan 11/10/13 instancier
- return topiaListenableSupport;
+ return topiaFiresSupport;
}
protected ImmutableMap<String, String> getConfiguration() {
@@ -157,92 +166,92 @@
@Override
public void addTopiaEntityListener(TopiaEntityListener listener) {
- topiaListenableSupport.addTopiaEntityListener(listener);
+ topiaFiresSupport.addTopiaEntityListener(listener);
}
@Override
public void addTopiaEntityListener(Class<? extends TopiaEntity> entityClass, TopiaEntityListener listener) {
- topiaListenableSupport.addTopiaEntityListener(entityClass, listener);
+ topiaFiresSupport.addTopiaEntityListener(entityClass, listener);
}
@Override
public void removeTopiaEntityListener(TopiaEntityListener listener) {
- topiaListenableSupport.removeTopiaEntityListener(listener);
+ topiaFiresSupport.removeTopiaEntityListener(listener);
}
@Override
public void removeTopiaEntityListener(Class<? extends TopiaEntity> entityClass, TopiaEntityListener listener) {
- topiaListenableSupport.removeTopiaEntityListener(entityClass, listener);
+ topiaFiresSupport.removeTopiaEntityListener(entityClass, listener);
}
@Override
public void addTopiaEntityVetoable(TopiaEntityVetoable vetoable) {
- topiaListenableSupport.addTopiaEntityVetoable(vetoable);
+ topiaFiresSupport.addTopiaEntityVetoable(vetoable);
}
@Override
public void addTopiaEntityVetoable(Class<? extends TopiaEntity> entityClass, TopiaEntityVetoable vetoable) {
- topiaListenableSupport.addTopiaEntityVetoable(entityClass, vetoable);
+ topiaFiresSupport.addTopiaEntityVetoable(entityClass, vetoable);
}
@Override
public void removeTopiaEntityVetoable(TopiaEntityVetoable vetoable) {
- topiaListenableSupport.removeTopiaEntityVetoable(vetoable);
+ topiaFiresSupport.removeTopiaEntityVetoable(vetoable);
}
@Override
public void removeTopiaEntityVetoable(Class<? extends TopiaEntity> entityClass, TopiaEntityVetoable vetoable) {
- topiaListenableSupport.removeTopiaEntityVetoable(entityClass, vetoable);
+ topiaFiresSupport.removeTopiaEntityVetoable(entityClass, vetoable);
}
@Override
public void addTopiaEntitiesVetoable(TopiaEntitiesVetoable vetoable) {
- topiaListenableSupport.addTopiaEntitiesVetoable(vetoable);
+ topiaFiresSupport.addTopiaEntitiesVetoable(vetoable);
}
@Override
public void removeTopiaEntitiesVetoable(TopiaEntitiesVetoable vetoable) {
- topiaListenableSupport.removeTopiaEntitiesVetoable(vetoable);
+ topiaFiresSupport.removeTopiaEntitiesVetoable(vetoable);
}
@Override
public void addTopiaTransactionListener(TopiaTransactionListener listener) {
- topiaListenableSupport.addTopiaTransactionListener(listener);
+ topiaFiresSupport.addTopiaTransactionListener(listener);
}
@Override
public void removeTopiaTransactionListener(TopiaTransactionListener listener) {
- topiaListenableSupport.removeTopiaTransactionListener(listener);
+ topiaFiresSupport.removeTopiaTransactionListener(listener);
}
@Override
public void addTopiaTransactionVetoable(TopiaTransactionVetoable vetoable) {
- topiaListenableSupport.addTopiaTransactionVetoable(vetoable);
+ topiaFiresSupport.addTopiaTransactionVetoable(vetoable);
}
@Override
public void removeTopiaTransactionVetoable(TopiaTransactionVetoable vetoable) {
- topiaListenableSupport.removeTopiaTransactionVetoable(vetoable);
+ topiaFiresSupport.removeTopiaTransactionVetoable(vetoable);
}
@Override
public void addPropertyChangeListener(PropertyChangeListener listener) {
- topiaListenableSupport.addPropertyChangeListener(listener);
+ topiaFiresSupport.addPropertyChangeListener(listener);
}
@Override
public void removePropertyChangeListener(PropertyChangeListener listener) {
- topiaListenableSupport.removePropertyChangeListener(listener);
+ topiaFiresSupport.removePropertyChangeListener(listener);
}
@Override
public void addTopiaSchemaListener(TopiaSchemaListener listener) {
- topiaListenableSupport.addTopiaSchemaListener(listener);
+ topiaFiresSupport.addTopiaSchemaListener(listener);
}
@Override
public void removeTopiaSchemaListener(TopiaSchemaListener listener) {
- topiaListenableSupport.removeTopiaSchemaListener(listener);
+ topiaFiresSupport.removeTopiaSchemaListener(listener);
}
@Override
@@ -259,4 +268,93 @@
public Map<String, TopiaService> getServices() {
return topiaServiceSupport.getServices();
}
+
+ public List<Class<?>> getPersistenceClasses() {
+ return null; // TODO AThimel 27/09/13 May be moved to TopiaHibernateSupport ?
+ }
+
+ public boolean isSchemaEmpty() {
+ Configuration configuration = getHibernateProvider().getHibernateConfiguration();
+ boolean result = TopiaUtil.isSchemaEmpty(configuration);
+ return result;
+ }
+
+ public boolean isTableExists(Class<?> clazz) {
+ Configuration configuration = getHibernateProvider().getHibernateConfiguration();
+ boolean result = TopiaUtil.isSchemaExist(configuration, clazz.getName());
+ return result;
+ }
+
+ public String getSchemaName() {
+ // TODO AThimel 02/08/13 I absolutely don't know if it works
+ return getConfiguration().get(TopiaContextFactory.CONFIG_DEFAULT_SCHEMA);
+ }
+
+ public void createSchema() {
+ try {
+ boolean showSchema = false;
+ if (log.isDebugEnabled()) {
+ showSchema = true;
+ }
+ // TODO brendan 11/10/13 reable event
+ // topiaFiresSupport.firePreCreateSchema(this);
+ new SchemaExport(getHibernateProvider().getHibernateConfiguration()).execute(showSchema, true, false, true);
+ // TODO brendan 11/10/13 reable event
+ // topiaFiresSupport.firePostCreateSchema(this);
+ } catch (HibernateException eee) {
+ throw new TopiaException(
+ String.format("Could not create schema for reason: %s",
+ eee.getMessage()), eee);
+ }
+ }
+
+ public void showCreateSchema() {
+ try {
+ new SchemaExport(getHibernateProvider().getHibernateConfiguration()).
+ execute(true, false, false, true);
+ } catch (HibernateException eee) {
+ throw new TopiaException(
+ String.format("Could not show create schema for reason: %s",
+ eee.getMessage()), eee);
+ }
+
+ }
+
+ public void updateSchema() {
+ try {
+ boolean showSchema = false;
+ if (log.isDebugEnabled()) {
+ showSchema = true;
+ }
+
+ // TODO brendan 11/10/13 reable event
+ // topiaFiresSupport.firePreUpdateSchema(this);
+ new SchemaUpdate(getHibernateProvider().getHibernateConfiguration()).execute(showSchema,
+ true);
+ // topiaFiresSupport.firePostUpdateSchema(this);
+ } catch (HibernateException eee) {
+ throw new TopiaException(
+ String.format("Could not update schema for reason: %s",
+ eee.getMessage()), eee);
+ }
+ }
+
+ public void dropSchema() {
+ try {
+ boolean showSchema = false;
+ if (log.isDebugEnabled()) {
+ showSchema = true;
+ }
+
+ // TODO brendan 11/10/13 reable event
+ // topiaFiresSupport.firePreDropSchema(this);
+ new SchemaExport(getHibernateProvider().getHibernateConfiguration()).execute(showSchema, true, true, false);
+// topiaFiresSupport.firePostDropSchema(this);
+ } catch (HibernateException eee) {
+ throw new TopiaException(
+ String.format("Could not drop schema for reason: %s",
+ eee.getMessage()), eee);
+ }
+ }
+
}
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/AbstractTopiaPersistenceContext.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/AbstractTopiaPersistenceContext.java 2013-10-11 14:18:51 UTC (rev 2836)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/AbstractTopiaPersistenceContext.java 2013-10-11 14:40:39 UTC (rev 2837)
@@ -59,11 +59,6 @@
private static final Log log = LogFactory.getLog(AbstractTopiaPersistenceContext.class);
/**
- * List of persistent classes
- */
- protected List<Class<?>> persistenceClasses = Lists.newArrayList();
-
- /**
* Already loaded DAO cache within this persistence context
*/
protected Map<Class<? extends TopiaEntity>, TopiaDAO<? extends TopiaEntity>> daoCache = Maps.newHashMap(); // TODO AThimel 27/09/13 Concurrent map ?
@@ -105,12 +100,11 @@
// * @param config
*/
public AbstractTopiaPersistenceContext(HibernateProvider hibernateProvider,
- TopiaSqlSupport sqlSupport,
TopiaListenableSupport listenableSupport,
TopiaIdFactory topiaIdFactory) {
this.hibernateSupport = new InternalTopiaHibernateSupport(hibernateProvider);
- this.sqlSupport = sqlSupport;
+ // TODO brendan 11/10/13 init this.sqlSupport
this.listenableSupport = listenableSupport;
this.topiaIdFactory = topiaIdFactory;
// this.config = config;
@@ -181,11 +175,6 @@
return topiaIdFactory;
}
- @Override
- public List<Class<?>> getPersistenceClasses() {
- return null; // TODO AThimel 27/09/13 May be moved to TopiaHibernateSupport ?
- }
-
// @Override
// public Properties getConfig() {
// return config;
@@ -255,94 +244,6 @@
}
@Override
- public boolean isSchemaEmpty() {
- Configuration configuration = hibernateSupport.getHibernateConfiguration();
- boolean result = TopiaUtil.isSchemaEmpty(configuration);
- return result;
- }
-
- @Override
- public boolean isTableExists(Class<?> clazz) {
- checkClosed();
-
- Configuration configuration = hibernateSupport.getHibernateConfiguration();
- boolean result = TopiaUtil.isSchemaExist(configuration, clazz.getName());
- return result;
- }
-
- @Override
- public String getSchemaName() {
- // TODO AThimel 02/08/13 I absolutely don't know if it works
- return getConfig().getProperty(TopiaContextFactory.CONFIG_DEFAULT_SCHEMA);
- }
-
- @Override
- public void createSchema() {
- try {
- boolean showSchema = false;
- if (log.isDebugEnabled()) {
- showSchema = true;
- }
- getFiresSupport().firePreCreateSchema(this);
- new SchemaExport(hibernateSupport.getHibernateConfiguration()).execute(showSchema, true, false, true);
- getFiresSupport().firePostCreateSchema(this);
- } catch (HibernateException eee) {
- throw new TopiaException(
- String.format("Could not create schema for reason: %s",
- eee.getMessage()), eee);
- }
-
- }
-
- @Override
- public void showCreateSchema() {
- try {
- new SchemaExport(hibernateSupport.getHibernateConfiguration()).
- execute(true, false, false, true);
- } catch (HibernateException eee) {
- throw new TopiaException(
- String.format("Could not show create schema for reason: %s",
- eee.getMessage()), eee);
- }
-
- }
-
- @Override
- public void updateSchema() {
- try {
- boolean showSchema = false;
- if (log.isDebugEnabled()) {
- showSchema = true;
- }
- getFiresSupport().firePreUpdateSchema(this);
- new SchemaUpdate(hibernateSupport.getHibernateConfiguration()).execute(showSchema,
- true);
- getFiresSupport().firePostUpdateSchema(this);
- } catch (HibernateException eee) {
- throw new TopiaException(
- String.format("Could not update schema for reason: %s",
- eee.getMessage()), eee);
- }
- }
-
- @Override
- public void dropSchema() {
- try {
- boolean showSchema = false;
- if (log.isDebugEnabled()) {
- showSchema = true;
- }
- getFiresSupport().firePreDropSchema(this);
- new SchemaExport(hibernateSupport.getHibernateConfiguration()).execute(showSchema, true, true, false);
- getFiresSupport().firePostDropSchema(this);
- } catch (HibernateException eee) {
- throw new TopiaException(
- String.format("Could not drop schema for reason: %s",
- eee.getMessage()), eee);
- }
- }
-
- @Override
public void commitTransaction() {
//To change body of implemented methods use File | Settings | File Templates.
}
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaPersistenceContext.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaPersistenceContext.java 2013-10-11 14:18:51 UTC (rev 2836)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaPersistenceContext.java 2013-10-11 14:40:39 UTC (rev 2837)
@@ -27,9 +27,6 @@
import org.nuiton.topia.persistence.TopiaEntity;
import org.nuiton.topia.persistence.TopiaIdFactory;
-import java.util.List;
-import java.util.Properties;
-
/**
* This API provides all methods related to persistence :
* <ul>
@@ -67,61 +64,4 @@
*/
TopiaIdFactory getTopiaIdFactory();
- /**
- * @return the list of classes managed by this TopiaPersistenceContext
- */
- List<Class<?>> getPersistenceClasses();
-
- /**
- * @return Returns the config.
- */
- Properties getConfig(); // TODO AThimel 02/08/13 Change type ?
-
- /**
- * Detects if the db associated to the current context contains at least one
- * entity table.
- *
- * @return {@code true} if there is no schema for any of the dealed entities,
- * {@code false} otherwise.
- * @since 3.0
- */
- boolean isSchemaEmpty();
-
- /**
- * Detects if the table is created on storage for a given persistent class.
- *
- * @param clazz the researched class
- * @return true if the table exists on storage
- * @since 3.0
- */
- boolean isTableExists(Class<?> clazz);
-
- /**
- * @return the current schema name
- * @since 3.0
- */
- String getSchemaName();
-
- /**
- * Triggers database schema creation
- */
- void createSchema();
-
- /**
- * Displays the SQL queries that would be used for a schema creation
- */
- void showCreateSchema();
-
- /**
- * Triggers database schema update
- */
- void updateSchema();
-
- /**
- * Triggers database schema drop
- *
- * @since 3.0
- */
- void dropSchema();
-
}
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/AbstractTopiaContext.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/AbstractTopiaContext.java 2013-10-11 14:18:51 UTC (rev 2836)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/AbstractTopiaContext.java 2013-10-11 14:40:39 UTC (rev 2837)
@@ -539,7 +539,6 @@
}
}
- @Override
public void dropSchema() throws TopiaException {
try {
boolean showSchema = false;
@@ -1329,13 +1328,11 @@
return isTableExists(clazz);
}
- @Override
public boolean isSchemaEmpty() {
// TODO AThimel 02/08/13 Implement
throw new UnsupportedOperationException("Not yet implemented");
}
- @Override
public boolean isTableExists(Class<?> clazz) {
checkClosed(String.format("This context is closed, it is not possible to release the operation '%1$s'",
"replicateEntity"));
@@ -1343,7 +1340,6 @@
return result;
}
- @Override
public String getSchemaName() {
// TODO AThimel 02/08/13 I absolutely don't know if it works
return getConfig().getProperty(TopiaContextFactory.CONFIG_DEFAULT_SCHEMA);
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaFiresSupport.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaFiresSupport.java 2013-10-11 14:18:51 UTC (rev 2836)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaFiresSupport.java 2013-10-11 14:40:39 UTC (rev 2837)
@@ -25,16 +25,6 @@
package org.nuiton.topia.framework;
-import java.beans.PropertyChangeEvent;
-import java.beans.PropertyChangeListener;
-import java.beans.PropertyChangeSupport;
-import java.beans.VetoableChangeSupport;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
import org.apache.commons.collections.map.IdentityMap;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log;
@@ -63,6 +53,7 @@
import org.nuiton.topia.TopiaDAOSupplier;
import org.nuiton.topia.TopiaException;
import org.nuiton.topia.TopiaJpaSupport;
+import org.nuiton.topia.TopiaListenableSupport;
import org.nuiton.topia.TopiaPersistenceContext;
import org.nuiton.topia.TopiaVetoException;
import org.nuiton.topia.event.TopiaContextEvent;
@@ -82,6 +73,16 @@
import org.nuiton.util.CategorisedListenerSet;
import org.nuiton.util.ListenerSet;
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+import java.beans.PropertyChangeSupport;
+import java.beans.VetoableChangeSupport;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
/**
* TODO-fdesbois-20100507 : Need translation of javadoc.
* <p/>
@@ -91,7 +92,7 @@
* @author jruchaud <jruchaud(a)codelutin.com>
* @version $Id$
*/
-public class TopiaFiresSupport {
+public class TopiaFiresSupport implements TopiaListenableSupport {
static private Log log = LogFactory.getLog(TopiaFiresSupport.class);
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/ApplicationContextTransformer.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/ApplicationContextTransformer.java 2013-10-11 14:18:51 UTC (rev 2836)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/ApplicationContextTransformer.java 2013-10-11 14:40:39 UTC (rev 2837)
@@ -174,7 +174,7 @@
addAnnotation(output, op, Override.class);
setOperationBody(op, ""
/*{
- return new <%=persistenceContextConcreteName%>();
+ return new <%=persistenceContextConcreteName%>(getHibernateProvider(), getTopiaListenableSupport(), getTopiaIdFactory());
}*/
);
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/PersistenceContextTransformer.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/PersistenceContextTransformer.java 2013-10-11 14:18:51 UTC (rev 2836)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/PersistenceContextTransformer.java 2013-10-11 14:40:39 UTC (rev 2837)
@@ -35,8 +35,10 @@
import org.nuiton.eugene.models.object.ObjectModelJavaModifier;
import org.nuiton.eugene.models.object.ObjectModelOperation;
import org.nuiton.topia.AbstractTopiaPersistenceContext;
-import org.nuiton.topia.TopiaContext;
+import org.nuiton.topia.HibernateProvider;
+import org.nuiton.topia.TopiaListenableSupport;
import org.nuiton.topia.persistence.TopiaEntity;
+import org.nuiton.topia.persistence.TopiaIdFactory;
import org.nuiton.topia.persistence.util.EntityOperator;
import org.nuiton.topia.persistence.util.EntityOperatorStore;
@@ -140,19 +142,16 @@
addImport(output, EntityOperatorStore.class);
}
- // add context field
- addAttribute(output, "context", TopiaContext.class, null,
- ObjectModelJavaModifier.PROTECTED);
-
// add public constructor
ObjectModelOperation constructor = addConstructor(
output,
ObjectModelJavaModifier.PUBLIC);
- addParameter(constructor, TopiaContext.class, "context");
+ addParameter(constructor, HibernateProvider.class, "hibernateProvider");
+ addParameter(constructor, TopiaListenableSupport.class, "listenableSupport");
+ addParameter(constructor, TopiaIdFactory.class, "topiaIdFactory");
setOperationBody(constructor, ""
/*{
- super(context, context, context, context.getTopiaIdFactory(), context.getConfig());
- this.context = context;
+ super(hibernateProvider, listenableSupport, topiaIdFactory);
}*/
);
@@ -282,10 +281,12 @@
ObjectModelOperation constructor = addConstructor(
output,
ObjectModelJavaModifier.PUBLIC);
- addParameter(constructor, TopiaContext.class, "context");
+ addParameter(constructor, HibernateProvider.class, "hibernateProvider");
+ addParameter(constructor, TopiaListenableSupport.class, "listenableSupport");
+ addParameter(constructor, TopiaIdFactory.class, "topiaIdFactory");
setOperationBody(constructor, ""
- /*{
- super(context);
+/*{
+ super(hibernateProvider, listenableSupport, topiaIdFactory);
}*/
);
1
0
r2836 - trunk/topia-persistence/src/main/java/org/nuiton/topia
by athimel@users.nuiton.org 11 Oct '13
by athimel@users.nuiton.org 11 Oct '13
11 Oct '13
Author: athimel
Date: 2013-10-11 16:18:51 +0200 (Fri, 11 Oct 2013)
New Revision: 2836
Url: http://nuiton.org/projects/topia/repository/revisions/2836
Log:
Add missing hibernateProvider constructor
Modified:
trunk/topia-persistence/src/main/java/org/nuiton/topia/AbstractTopiaApplicationContext.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/HibernateProvider.java
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/AbstractTopiaApplicationContext.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/AbstractTopiaApplicationContext.java 2013-10-11 14:16:48 UTC (rev 2835)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/AbstractTopiaApplicationContext.java 2013-10-11 14:18:51 UTC (rev 2836)
@@ -95,7 +95,7 @@
protected HibernateProvider getHibernateProvider() {
if (hibernateProvider == null) {
- hibernateProvider = new HibernateProvider();
+ hibernateProvider = new HibernateProvider(configuration, topiaServiceSupport);
}
return hibernateProvider;
}
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/HibernateProvider.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/HibernateProvider.java 2013-10-11 14:16:48 UTC (rev 2835)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/HibernateProvider.java 2013-10-11 14:18:51 UTC (rev 2836)
@@ -28,6 +28,7 @@
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
+import java.util.Map;
import java.util.Properties;
import java.util.Set;
@@ -45,7 +46,6 @@
import org.nuiton.topia.framework.TopiaService;
import org.nuiton.topia.framework.TopiaUtil;
-import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
/**
@@ -58,7 +58,7 @@
protected SessionFactory hibernateSessionFactory;
protected Configuration hibernateConfiguration;
- protected ImmutableMap<String, String> configuration;
+ protected Map<String, String> configuration;
protected TopiaServiceSupport topiaServiceSupport;
/**
@@ -66,6 +66,11 @@
*/
protected List<Class<?>> persistentClasses = Lists.newArrayList();
+ public HibernateProvider(Map<String, String> configuration, TopiaServiceSupport topiaServiceSupport) {
+ this.configuration = configuration;
+ this.topiaServiceSupport = topiaServiceSupport;
+ }
+
protected String getProperty(String key) {
return getProperty(key, null);
}
1
0
r2835 - in trunk/topia-persistence/src: main/java/org/nuiton/topia main/java/org/nuiton/topia/persistence test/java/org/nuiton/topia test/java/org/nuiton/topia/persistence
by athimel@users.nuiton.org 11 Oct '13
by athimel@users.nuiton.org 11 Oct '13
11 Oct '13
Author: athimel
Date: 2013-10-11 16:16:48 +0200 (Fri, 11 Oct 2013)
New Revision: 2835
Url: http://nuiton.org/projects/topia/repository/revisions/2835
Log:
Introduce HibernateProvider in order to create Hibernate's Configuration and SessionFactory
Added:
trunk/topia-persistence/src/main/java/org/nuiton/topia/HibernateProvider.java
trunk/topia-persistence/src/test/java/org/nuiton/topia/AbstractEmployeTopiaDao.java
trunk/topia-persistence/src/test/java/org/nuiton/topia/AbstractPersonneTopiaDao.java
trunk/topia-persistence/src/test/java/org/nuiton/topia/EmployeTopiaDao.java
trunk/topia-persistence/src/test/java/org/nuiton/topia/EmployeeDao.java
trunk/topia-persistence/src/test/java/org/nuiton/topia/GeneratedEmployeeTopiaDao.java
trunk/topia-persistence/src/test/java/org/nuiton/topia/GeneratedPersonneTopiaDao.java
trunk/topia-persistence/src/test/java/org/nuiton/topia/PersonneDao.java
trunk/topia-persistence/src/test/java/org/nuiton/topia/PersonneTopiaDao.java
Modified:
trunk/topia-persistence/src/main/java/org/nuiton/topia/AbstractTopiaApplicationContext.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/AbstractTopiaPersistenceContext.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaDAOSupplier.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/HqlAndParametersBuilder.java
trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/HqlAndParametersBuilderTest.java
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/AbstractTopiaApplicationContext.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/AbstractTopiaApplicationContext.java 2013-10-11 13:46:24 UTC (rev 2834)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/AbstractTopiaApplicationContext.java 2013-10-11 14:16:48 UTC (rev 2835)
@@ -65,10 +65,10 @@
protected TopiaServiceSupport topiaServiceSupport;
+ protected HibernateProvider hibernateProvider;
+
public abstract K newPersistenceContext();
- public abstract Properties getConfig();
-
public AbstractTopiaApplicationContext(Properties properties) {
// TODO arnaud 11/10/13 vérifier le comportement
this((Map) ImmutableMap.copyOf(properties));
@@ -93,8 +93,15 @@
this.configuration = ImmutableMap.copyOf(configurationCopy);
}
+ protected HibernateProvider getHibernateProvider() {
+ if (hibernateProvider == null) {
+ hibernateProvider = new HibernateProvider();
+ }
+ return hibernateProvider;
+ }
+
protected SessionFactory getSessionFactory() {
- throw new UnsupportedOperationException();
+ return getHibernateProvider().getSessionFactory();
}
protected TopiaListenableSupport getTopiaListenableSupport() {
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/AbstractTopiaPersistenceContext.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/AbstractTopiaPersistenceContext.java 2013-10-11 13:46:24 UTC (rev 2834)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/AbstractTopiaPersistenceContext.java 2013-10-11 14:16:48 UTC (rev 2835)
@@ -30,6 +30,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.HibernateException;
+import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.hibernate.tool.hbm2ddl.SchemaExport;
@@ -71,7 +72,7 @@
protected TopiaFiresSupport firesSupport;
// TODO AThimel 27/09/13 Javadoc
- protected TopiaHibernateSupport hibernateSupport;
+ protected InternalTopiaHibernateSupport hibernateSupport;
// TODO AThimel 27/09/13 Javadoc
protected TopiaJpaSupport jpaSupport;
@@ -89,27 +90,60 @@
*/
protected TopiaIdFactory topiaIdFactory;
+// /**
+// * Current context configuration
+// */
+// protected Properties config;
+
/**
- * Current context configuration
+ * Creating a new TopiaPersistenceContext is equivalent to creating a new transaction
+ *
+ * @param hibernateProvider
+ * @param sqlSupport
+ * @param listenableSupport
+ * @param topiaIdFactory
+// * @param config
*/
- protected Properties config;
-
- public AbstractTopiaPersistenceContext(TopiaHibernateSupport hibernateSupport,
+ public AbstractTopiaPersistenceContext(HibernateProvider hibernateProvider,
TopiaSqlSupport sqlSupport,
TopiaListenableSupport listenableSupport,
- TopiaIdFactory topiaIdFactory,
- Properties config) {
- this.hibernateSupport = hibernateSupport;
+ TopiaIdFactory topiaIdFactory) {
+
+ this.hibernateSupport = new InternalTopiaHibernateSupport(hibernateProvider);
this.sqlSupport = sqlSupport;
this.listenableSupport = listenableSupport;
this.topiaIdFactory = topiaIdFactory;
- this.config = config;
+// this.config = config;
this.firesSupport = new TopiaFiresSupport();
this.jpaSupport = new HibernateTopiaJpaSupport(hibernateSupport, firesSupport);
}
+ protected class InternalTopiaHibernateSupport implements TopiaHibernateSupport {
+
+ protected HibernateProvider hibernateProvider;
+
+ protected InternalTopiaHibernateSupport(HibernateProvider hibernateProvider) {
+ this.hibernateProvider = hibernateProvider;
+ }
+
+ @Override
+ public Session getHibernateSession() {
+ return null;
+ }
+
+ @Override
+ public SessionFactory getHibernateFactory() {
+ return hibernateProvider.getSessionFactory();
+ }
+
+ @Override
+ public Configuration getHibernateConfiguration() {
+ return hibernateProvider.getHibernateConfiguration();
+ }
+ }
+
protected void checkClosed() throws TopiaException {
// TODO AThimel 27/09/13 IS it still useful ?
// if (closed) {
@@ -152,10 +186,10 @@
return null; // TODO AThimel 27/09/13 May be moved to TopiaHibernateSupport ?
}
- @Override
- public Properties getConfig() {
- return config;
- }
+// @Override
+// public Properties getConfig() {
+// return config;
+// }
@Override
public <E extends TopiaEntity> TopiaDAO<E> getDAO(Class<E> entityClass) {
Added: trunk/topia-persistence/src/main/java/org/nuiton/topia/HibernateProvider.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/HibernateProvider.java (rev 0)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/HibernateProvider.java 2013-10-11 14:16:48 UTC (rev 2835)
@@ -0,0 +1,214 @@
+package org.nuiton.topia;
+
+/*
+ * #%L
+ * ToPIA :: Persistence
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2004 - 2013 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%
+ */
+
+import java.io.File;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Properties;
+import java.util.Set;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.hibernate.SessionFactory;
+import org.hibernate.cfg.Configuration;
+import org.hibernate.engine.spi.SessionFactoryImplementor;
+import org.hibernate.event.service.spi.EventListenerRegistry;
+import org.hibernate.event.spi.EventType;
+import org.hibernate.service.ServiceRegistry;
+import org.hibernate.service.ServiceRegistryBuilder;
+import org.nuiton.topia.framework.TopiaFiresSupport;
+import org.nuiton.topia.framework.TopiaService;
+import org.nuiton.topia.framework.TopiaUtil;
+
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Lists;
+
+/**
+ * @author Arnaud Thimel <thimel(a)codelutin.com>
+ */
+public class HibernateProvider {
+
+ private static final Log log = LogFactory.getLog(HibernateProvider.class);
+
+ protected SessionFactory hibernateSessionFactory;
+ protected Configuration hibernateConfiguration;
+
+ protected ImmutableMap<String, String> configuration;
+ protected TopiaServiceSupport topiaServiceSupport;
+
+ /**
+ * List of persistent classes
+ */
+ protected List<Class<?>> persistentClasses = Lists.newArrayList();
+
+ protected String getProperty(String key) {
+ return getProperty(key, null);
+ }
+
+ protected String getProperty(String key, String defaultValue) {
+ String result = defaultValue;
+ if (configuration.containsKey(key)) {
+ result = configuration.get(key);
+ }
+
+ return result;
+ }
+
+ public Configuration getHibernateConfiguration() {
+ if (hibernateConfiguration == null) {
+ hibernateConfiguration = new Configuration();
+
+ // ajout des repertoires contenant les mappings hibernate
+ String[] dirs = getProperty(
+ TopiaContextFactory.CONFIG_PERSISTENCE_DIRECTORIES, "").split(",");
+ for (String dir : dirs) {
+ dir = dir.trim();
+ if (StringUtils.isNotEmpty(dir)) {
+ if (log.isDebugEnabled()) {
+ log.debug("Load persistence from dir : " + dir);
+ }
+ hibernateConfiguration.addDirectory(new File(dir));
+ }
+ }
+
+ // ajout des classes dites persistentes
+ Set<Class<?>> hibernatePersistanceClasses = new HashSet<Class<?>>();
+ for (TopiaService service : topiaServiceSupport.getServices().values()) {
+ Class<?>[] classes = service.getPersistenceClasses();
+
+ // certains service n'ont pas de classe persistantes
+ if (classes != null) {
+ // sletellier 20110411 : http://www.nuiton.org/issues/show/1454
+ hibernatePersistanceClasses.addAll(Arrays.asList(classes));
+// for (Class<?> clazz : classes) {
+// hibernateConfiguration.addClass(clazz);
+// }
+ }
+ }
+
+ String listPersistenceClasses = getProperty(
+ TopiaContextFactory.CONFIG_PERSISTENCE_CLASSES, "");
+
+ String[] classes = listPersistenceClasses.split(",");
+ for (String classname : classes) {
+ classname = classname.trim();
+ if (StringUtils.isNotEmpty(classname)) {
+ if (log.isDebugEnabled()) {
+ log.debug("Load persistent class : " + classname);
+ }
+
+ // XXX echatellier 20111007 ce qui est dommage ici, c'est
+ // la definition de cette classe ne sert a rien (apart security)
+ // car pour hibernate hibernateConfiguration.addClass(persistanceClass)
+ // il ne se sert pas de la classe en fait et fait seulement
+ // un classname.replace( '.', '/' ) + ".hbm.xml";
+ // pour obtenir le mapping et la reinstancier ensuite
+
+ Class<?> clazz;
+ try {
+ clazz = Class.forName(classname);
+ } catch (ClassNotFoundException eee) {
+ if (log.isDebugEnabled()) {
+ log.debug("Class " + classname + " not found");
+ }
+ throw new TopiaNotFoundException(
+ String.format("Persistence class %1$s not found",
+ classname));
+ }
+ persistentClasses.add(clazz);
+
+ // sletellier 20110411 : http://www.nuiton.org/issues/show/1454
+// hibernateConfiguration.addClass(clazz);
+ hibernatePersistanceClasses.add(clazz);
+ }
+ }
+
+ // sletellier 20110411 : http://www.nuiton.org/issues/show/1454
+ // Add persistance classes in hibernate config
+ for (Class<?> persistanceClass : hibernatePersistanceClasses) {
+ hibernateConfiguration.addClass(persistanceClass);
+ }
+
+ Properties prop = new Properties();
+ prop.putAll(hibernateConfiguration.getProperties());
+ prop.putAll(configuration);
+
+ // Strange behavior, all properties are already loaded from
+ // constructor. Difficult to use this behavior, need to have
+ // TOPIA_PERSISTENCE_PROPERTIES_FILE in config.
+ Properties propertiesFromClasspath =
+ TopiaUtil.getProperties(getProperty(TopiaContextFactory.CONFIG_PERSISTENCE_PROPERTIES_FILE));
+
+ if (!propertiesFromClasspath.isEmpty()) {
+ if (log.isDebugEnabled()) {
+ log.debug("Load properties from file : " +
+ propertiesFromClasspath);
+ }
+ prop.putAll(propertiesFromClasspath);
+ }
+
+ hibernateConfiguration.setProperties(prop);
+
+ // tchemit 2011-05-26 When using hibernate > 3.3, need to make sure all mappings are loaded (the one from directory files are not still done).
+ hibernateConfiguration.buildMappings();
+ }
+ return hibernateConfiguration;
+ }
+
+ public SessionFactory getSessionFactory() {
+
+ if (hibernateSessionFactory == null) {
+
+ // init service registry
+ ServiceRegistry serviceRegistry = new ServiceRegistryBuilder().applySettings(
+ getHibernateConfiguration().getProperties()).buildServiceRegistry();
+
+ hibernateSessionFactory = getHibernateConfiguration().buildSessionFactory(serviceRegistry);
+
+ // we can't reuse original serviceRegistry instance
+ // we must call getServiceRegistry on factory to get a working one
+ ServiceRegistry serviceRegistryInit = ((SessionFactoryImplementor) hibernateSessionFactory).getServiceRegistry();
+ EventListenerRegistry eventListenerRegistry = serviceRegistryInit.getService(EventListenerRegistry.class);
+// TopiaFiresSupport.TopiaHibernateEvent listener = new TopiaFiresSupport.TopiaHibernateEvent(this);
+ TopiaFiresSupport.TopiaHibernateEvent listener = new TopiaFiresSupport.TopiaHibernateEvent(null); // FIXME AThimel 11/10/13 Give a correct instance
+ eventListenerRegistry.appendListeners(EventType.PRE_INSERT, listener);
+ eventListenerRegistry.appendListeners(EventType.PRE_LOAD, listener);
+ eventListenerRegistry.appendListeners(EventType.PRE_UPDATE, listener);
+ eventListenerRegistry.appendListeners(EventType.PRE_DELETE, listener);
+ eventListenerRegistry.appendListeners(EventType.POST_INSERT, listener);
+ eventListenerRegistry.appendListeners(EventType.POST_LOAD, listener);
+ eventListenerRegistry.appendListeners(EventType.POST_UPDATE, listener);
+ eventListenerRegistry.appendListeners(EventType.POST_DELETE, listener);
+
+ // following listeners must be called before hibernate
+ eventListenerRegistry.prependListeners(EventType.SAVE_UPDATE, listener);
+ }
+ return hibernateSessionFactory;
+ }
+
+}
Property changes on: trunk/topia-persistence/src/main/java/org/nuiton/topia/HibernateProvider.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaDAOSupplier.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaDAOSupplier.java 2013-10-11 13:46:24 UTC (rev 2834)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaDAOSupplier.java 2013-10-11 14:16:48 UTC (rev 2835)
@@ -1,5 +1,29 @@
package org.nuiton.topia;
+/*
+ * #%L
+ * ToPIA :: Persistence
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2004 - 2013 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%
+ */
+
import org.nuiton.topia.persistence.TopiaDAO;
import org.nuiton.topia.persistence.TopiaEntity;
Property changes on: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaDAOSupplier.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/HqlAndParametersBuilder.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/HqlAndParametersBuilder.java 2013-10-11 13:46:24 UTC (rev 2834)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/HqlAndParametersBuilder.java 2013-10-11 14:16:48 UTC (rev 2835)
@@ -1,5 +1,29 @@
package org.nuiton.topia.persistence;
+/*
+ * #%L
+ * ToPIA :: Persistence
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2004 - 2013 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%
+ */
+
import com.google.common.base.Preconditions;
import com.google.common.collect.Iterables;
import com.google.common.collect.Maps;
Property changes on: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/HqlAndParametersBuilder.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Added: trunk/topia-persistence/src/test/java/org/nuiton/topia/AbstractEmployeTopiaDao.java
===================================================================
--- trunk/topia-persistence/src/test/java/org/nuiton/topia/AbstractEmployeTopiaDao.java (rev 0)
+++ trunk/topia-persistence/src/test/java/org/nuiton/topia/AbstractEmployeTopiaDao.java 2013-10-11 14:16:48 UTC (rev 2835)
@@ -0,0 +1,33 @@
+package org.nuiton.topia;
+
+/*
+ * #%L
+ * ToPIA :: Persistence
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2004 - 2013 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%
+ */
+
+import org.nuiton.topiatest.Employe;
+
+/**
+ * @author Arnaud Thimel <thimel(a)codelutin.com>
+ */
+public abstract class AbstractEmployeTopiaDao<E extends Employe> extends GeneratedEmployeeTopiaDao<E> {
+}
Property changes on: trunk/topia-persistence/src/test/java/org/nuiton/topia/AbstractEmployeTopiaDao.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Added: trunk/topia-persistence/src/test/java/org/nuiton/topia/AbstractPersonneTopiaDao.java
===================================================================
--- trunk/topia-persistence/src/test/java/org/nuiton/topia/AbstractPersonneTopiaDao.java (rev 0)
+++ trunk/topia-persistence/src/test/java/org/nuiton/topia/AbstractPersonneTopiaDao.java 2013-10-11 14:16:48 UTC (rev 2835)
@@ -0,0 +1,34 @@
+package org.nuiton.topia;
+
+/*
+ * #%L
+ * ToPIA :: Persistence
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2004 - 2013 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%
+ */
+
+import org.nuiton.topiatest.Personne;
+
+/**
+ * @author Arnaud Thimel <thimel(a)codelutin.com>
+ */
+public abstract class AbstractPersonneTopiaDao<E extends Personne> extends GeneratedPersonneTopiaDao<E> {
+
+}
Property changes on: trunk/topia-persistence/src/test/java/org/nuiton/topia/AbstractPersonneTopiaDao.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Added: trunk/topia-persistence/src/test/java/org/nuiton/topia/EmployeTopiaDao.java
===================================================================
--- trunk/topia-persistence/src/test/java/org/nuiton/topia/EmployeTopiaDao.java (rev 0)
+++ trunk/topia-persistence/src/test/java/org/nuiton/topia/EmployeTopiaDao.java 2013-10-11 14:16:48 UTC (rev 2835)
@@ -0,0 +1,42 @@
+package org.nuiton.topia;
+
+/*
+ * #%L
+ * ToPIA :: Persistence
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2004 - 2013 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%
+ */
+
+import java.util.List;
+
+import org.nuiton.topiatest.Employe;
+import org.nuiton.topiatest.Personne;
+
+/**
+ * @author Arnaud Thimel <thimel(a)codelutin.com>
+ */
+public class EmployeTopiaDao extends AbstractEmployeTopiaDao<Employe> {
+
+ @Override
+ public List<Personne> findAllPersonnesByXAndY(int x, int y) {
+ return null;
+ }
+
+}
Property changes on: trunk/topia-persistence/src/test/java/org/nuiton/topia/EmployeTopiaDao.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Added: trunk/topia-persistence/src/test/java/org/nuiton/topia/EmployeeDao.java
===================================================================
--- trunk/topia-persistence/src/test/java/org/nuiton/topia/EmployeeDao.java (rev 0)
+++ trunk/topia-persistence/src/test/java/org/nuiton/topia/EmployeeDao.java 2013-10-11 14:16:48 UTC (rev 2835)
@@ -0,0 +1,31 @@
+package org.nuiton.topia;
+
+/*
+ * #%L
+ * ToPIA :: Persistence
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2004 - 2013 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%
+ */
+
+/**
+ * @author Arnaud Thimel <thimel(a)codelutin.com>
+ */
+public interface EmployeeDao {
+}
Property changes on: trunk/topia-persistence/src/test/java/org/nuiton/topia/EmployeeDao.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Added: trunk/topia-persistence/src/test/java/org/nuiton/topia/GeneratedEmployeeTopiaDao.java
===================================================================
--- trunk/topia-persistence/src/test/java/org/nuiton/topia/GeneratedEmployeeTopiaDao.java (rev 0)
+++ trunk/topia-persistence/src/test/java/org/nuiton/topia/GeneratedEmployeeTopiaDao.java 2013-10-11 14:16:48 UTC (rev 2835)
@@ -0,0 +1,33 @@
+package org.nuiton.topia;
+
+/*
+ * #%L
+ * ToPIA :: Persistence
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2004 - 2013 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%
+ */
+
+import org.nuiton.topiatest.Employe;
+
+/**
+ * @author Arnaud Thimel <thimel(a)codelutin.com>
+ */
+public abstract class GeneratedEmployeeTopiaDao<E extends Employe> extends AbstractPersonneTopiaDao<E> {
+}
Property changes on: trunk/topia-persistence/src/test/java/org/nuiton/topia/GeneratedEmployeeTopiaDao.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Added: trunk/topia-persistence/src/test/java/org/nuiton/topia/GeneratedPersonneTopiaDao.java
===================================================================
--- trunk/topia-persistence/src/test/java/org/nuiton/topia/GeneratedPersonneTopiaDao.java (rev 0)
+++ trunk/topia-persistence/src/test/java/org/nuiton/topia/GeneratedPersonneTopiaDao.java 2013-10-11 14:16:48 UTC (rev 2835)
@@ -0,0 +1,60 @@
+package org.nuiton.topia;
+
+/*
+ * #%L
+ * ToPIA :: Persistence
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2004 - 2013 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%
+ */
+
+import java.util.List;
+import java.util.Map;
+
+import org.nuiton.topia.persistence.AbstractTopiaDAO;
+import org.nuiton.topia.persistence.TopiaEntity;
+import org.nuiton.topia.persistence.TopiaEntityEnum;
+import org.nuiton.topiatest.Personne;
+
+/**
+ * @author Arnaud Thimel <thimel(a)codelutin.com>
+ */
+public abstract class GeneratedPersonneTopiaDao<E extends Personne> extends AbstractTopiaDAO<E> implements PersonneDao {
+
+ @Override
+ public TopiaEntityEnum getTopiaEntityEnum() {
+ return null;
+ }
+
+ @Override
+ public <R extends TopiaEntity> List<R> findUsages(Class<R> type, E entity) throws TopiaException {
+ return null;
+ }
+
+ @Override
+ public Map<Class<? extends TopiaEntity>, List<? extends TopiaEntity>> findAllUsages(E entity) throws TopiaException {
+ return null;
+ }
+
+ @Override
+ public Class<E> getEntityClass() {
+ return null;
+ }
+
+}
Property changes on: trunk/topia-persistence/src/test/java/org/nuiton/topia/GeneratedPersonneTopiaDao.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Added: trunk/topia-persistence/src/test/java/org/nuiton/topia/PersonneDao.java
===================================================================
--- trunk/topia-persistence/src/test/java/org/nuiton/topia/PersonneDao.java (rev 0)
+++ trunk/topia-persistence/src/test/java/org/nuiton/topia/PersonneDao.java 2013-10-11 14:16:48 UTC (rev 2835)
@@ -0,0 +1,38 @@
+package org.nuiton.topia;
+
+/*
+ * #%L
+ * ToPIA :: Persistence
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2004 - 2013 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%
+ */
+
+import java.util.List;
+
+import org.nuiton.topiatest.Personne;
+
+/**
+ * @author Arnaud Thimel <thimel(a)codelutin.com>
+ */
+public interface PersonneDao {
+
+ List<Personne> findAllPersonnesByXAndY(int x, int y);
+
+}
Property changes on: trunk/topia-persistence/src/test/java/org/nuiton/topia/PersonneDao.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Added: trunk/topia-persistence/src/test/java/org/nuiton/topia/PersonneTopiaDao.java
===================================================================
--- trunk/topia-persistence/src/test/java/org/nuiton/topia/PersonneTopiaDao.java (rev 0)
+++ trunk/topia-persistence/src/test/java/org/nuiton/topia/PersonneTopiaDao.java 2013-10-11 14:16:48 UTC (rev 2835)
@@ -0,0 +1,41 @@
+package org.nuiton.topia;
+
+/*
+ * #%L
+ * ToPIA :: Persistence
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2004 - 2013 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%
+ */
+
+import java.util.List;
+
+import org.nuiton.topiatest.Personne;
+
+/**
+ * @author Arnaud Thimel <thimel(a)codelutin.com>
+ */
+public class PersonneTopiaDao extends AbstractPersonneTopiaDao<Personne> {
+
+ @Override
+ public List<Personne> findAllPersonnesByXAndY(int x, int y) {
+ return null;
+ }
+
+}
Property changes on: trunk/topia-persistence/src/test/java/org/nuiton/topia/PersonneTopiaDao.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Modified: trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/HqlAndParametersBuilderTest.java
===================================================================
--- trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/HqlAndParametersBuilderTest.java 2013-10-11 13:46:24 UTC (rev 2834)
+++ trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/HqlAndParametersBuilderTest.java 2013-10-11 14:16:48 UTC (rev 2835)
@@ -1,5 +1,29 @@
package org.nuiton.topia.persistence;
+/*
+ * #%L
+ * ToPIA :: Persistence
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2004 - 2013 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%
+ */
+
import org.junit.Assert;
import org.junit.Test;
Property changes on: trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/HqlAndParametersBuilderTest.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
1
0