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
November 2013
- 7 participants
- 43 discussions
Author: echatellier
Date: 2013-11-28 10:41:24 +0100 (Thu, 28 Nov 2013)
New Revision: 2904
Url: http://nuiton.org/projects/topia/repository/revisions/2904
Log:
fixes #2950: Update hibernate to 4.2.7.SP1
Modified:
trunk/pom.xml
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2013-11-28 08:43:39 UTC (rev 2903)
+++ trunk/pom.xml 2013-11-28 09:41:24 UTC (rev 2904)
@@ -6,7 +6,7 @@
$Id$
$HeadURL$
%%
- Copyright (C) 2004 - 2010 CodeLutin
+ Copyright (C) 2004 - 2013 CodeLutin, Chatellier Eric
%%
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as
@@ -240,7 +240,7 @@
<nuitonI18nVersion>2.5.2</nuitonI18nVersion>
<processorPluginVersion>1.3</processorPluginVersion>
<xmlrpcVersion>3.1.2</xmlrpcVersion>
- <hibernateVersion>4.2.3.Final</hibernateVersion>
+ <hibernateVersion>4.2.7.SP1</hibernateVersion>
<sl4jVersion>1.7.5</sl4jVersion>
<h2Version>1.3.172</h2Version>
<hamcrestVersion>1.3</hamcrestVersion>
1
0
r2903 - trunk/topia-templates/src/main/java/org/nuiton/topia/templates
by sbavencoff@users.nuiton.org 28 Nov '13
by sbavencoff@users.nuiton.org 28 Nov '13
28 Nov '13
Author: sbavencoff
Date: 2013-11-28 09:43:39 +0100 (Thu, 28 Nov 2013)
New Revision: 2903
Url: http://nuiton.org/projects/topia/repository/revisions/2903
Log:
refs #2923 : change call deprecated functions
Modified:
trunk/topia-templates/src/main/java/org/nuiton/topia/templates/EntityDaoTransformer.java
Modified: trunk/topia-templates/src/main/java/org/nuiton/topia/templates/EntityDaoTransformer.java
===================================================================
--- trunk/topia-templates/src/main/java/org/nuiton/topia/templates/EntityDaoTransformer.java 2013-11-28 08:42:15 UTC (rev 2902)
+++ trunk/topia-templates/src/main/java/org/nuiton/topia/templates/EntityDaoTransformer.java 2013-11-28 08:43:39 UTC (rev 2903)
@@ -768,9 +768,9 @@
String methodName;
if (TopiaGeneratorUtil.isNMultiplicity(attr)) {
- methodName = getJavaBeanMethodName("findAllContains", attrName);
+ methodName = getJavaBeanMethodName("for", attrName , "Contains");
} else {
- methodName = getJavaBeanMethodName("findAllBy", attrName);
+ methodName = getJavaBeanMethodName("for", attrName, "Equals");
}
String daoName = TopiaGeneratorUtil.getConcreteDaoName(usageClass);
@@ -779,9 +779,9 @@
buffer.append(""
/*{
if (type == <%=usageSimpleType%>.class) {
- <%=daoName%> dao = (<%=daoName%>)
- topiaDaoSupplier.getDao(<%=usageSimpleType%>.class);
- tmp = dao.<%=methodName%>(entity);
+ <%=daoName%> dao =
+ topiaDaoSupplier.getDao(<%=usageSimpleType%>.class, <%=daoName%>.class);
+ tmp = dao.<%=methodName%>(entity).findAll();
result.addAll(tmp);
}
}*/
1
0
r2902 - trunk/topia-persistence/src/main/java/org/nuiton/topia/framework
by athimel@users.nuiton.org 28 Nov '13
by athimel@users.nuiton.org 28 Nov '13
28 Nov '13
Author: athimel
Date: 2013-11-28 09:42:15 +0100 (Thu, 28 Nov 2013)
New Revision: 2902
Url: http://nuiton.org/projects/topia/repository/revisions/2902
Log:
Syntax
Modified:
trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaHibernateEventListener.java
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaHibernateEventListener.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaHibernateEventListener.java 2013-11-28 08:39:47 UTC (rev 2901)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaHibernateEventListener.java 2013-11-28 08:42:15 UTC (rev 2902)
@@ -131,7 +131,8 @@
public void onPostInsert(PostInsertEvent event) {
TopiaPersistenceContext context = getContext(event);
if (context != null && event.getEntity() instanceof TopiaEntity) {
- context.getTopiaFiresSupport().fireOnPostCreate(context, (TopiaEntity) event.getEntity(), event.getState());
+ TopiaEntity entity = (TopiaEntity) event.getEntity();
+ context.getTopiaFiresSupport().fireOnPostCreate(context, entity, event.getState());
}
}
@@ -142,7 +143,8 @@
TopiaPersistenceContext context = getContext(event);
if (context != null && event.getEntity() instanceof TopiaEntity) {
// try {
- context.getTopiaFiresSupport().fireOnPreLoad(context, (TopiaEntity) event.getEntity(), event.getState());
+ TopiaEntity entity = (TopiaEntity) event.getEntity();
+ context.getTopiaFiresSupport().fireOnPreLoad(context, entity, event.getState());
//TODO (thimel 20071213) On commente pour le moment @see(TopiaDAOHibernate#filterElements)
// } catch (TopiaVetoException tve) {
// //On ne fait pas de remontee d'exception
@@ -157,7 +159,7 @@
if (context != null && event.getEntity() instanceof TopiaEntity) {
attachContext(event.getEntity(), context);
TopiaEntity entity = (TopiaEntity) event.getEntity();
- context.getTopiaFiresSupport().fireOnPostLoad(context, (TopiaEntity) event.getEntity(), new Object[]{});
+ context.getTopiaFiresSupport().fireOnPostLoad(context, entity, new Object[]{});
}
}
@@ -167,7 +169,8 @@
public boolean onPreUpdate(PreUpdateEvent event) {
TopiaPersistenceContext context = getContext(event);
if (context != null && event.getEntity() instanceof TopiaEntity) {
- context.getTopiaFiresSupport().fireOnPreUpdate(context, (TopiaEntity) event.getEntity(), event.getOldState());
+ TopiaEntity entity = (TopiaEntity) event.getEntity();
+ context.getTopiaFiresSupport().fireOnPreUpdate(context, entity, event.getOldState());
}
return false;
}
@@ -176,7 +179,8 @@
public void onPostUpdate(PostUpdateEvent event) {
TopiaPersistenceContext context = getContext(event);
if (context != null && event.getEntity() instanceof TopiaEntity) {
- context.getTopiaFiresSupport().fireOnPostUpdate(context, (TopiaEntity) event.getEntity(), event.getState());
+ TopiaEntity entity = (TopiaEntity) event.getEntity();
+ context.getTopiaFiresSupport().fireOnPostUpdate(context, entity, event.getState());
}
// FIXME indexation
// if (!(entity instanceof NotIndexable) && context.isIndexEnabled()) {
@@ -190,7 +194,8 @@
public boolean onPreDelete(PreDeleteEvent event) {
TopiaPersistenceContext context = getContext(event);
if (context != null && event.getEntity() instanceof TopiaEntity) {
- context.getTopiaFiresSupport().fireOnPreDelete(context, (TopiaEntity) event.getEntity(), event.getDeletedState());
+ TopiaEntity entity = (TopiaEntity) event.getEntity();
+ context.getTopiaFiresSupport().fireOnPreDelete(context, entity, event.getDeletedState());
}
return false;
}
@@ -199,7 +204,8 @@
public void onPostDelete(PostDeleteEvent event) {
TopiaPersistenceContext context = getContext(event);
if (context != null && event.getEntity() instanceof TopiaEntity) {
- context.getTopiaFiresSupport().fireOnPostDelete(context, (TopiaEntity) event.getEntity(), event.getDeletedState());
+ TopiaEntity entity = (TopiaEntity) event.getEntity();
+ context.getTopiaFiresSupport().fireOnPostDelete(context, entity, event.getDeletedState());
}
// FIXME indexation
// if (!(entity instanceof NotIndexable) && context.isIndexEnabled()) {
1
0
r2901 - in trunk: topia-it/src/test/java/org/nuiton/topia/it/legacy topia-persistence/src/main/java/org/nuiton/topia topia-service-replication/src/test/java/org/nuiton/topia/replication
by athimel@users.nuiton.org 28 Nov '13
by athimel@users.nuiton.org 28 Nov '13
28 Nov '13
Author: athimel
Date: 2013-11-28 09:39:47 +0100 (Thu, 28 Nov 2013)
New Revision: 2901
Url: http://nuiton.org/projects/topia/repository/revisions/2901
Log:
refs #2923 Extract the cache functionnality from TopiaContextFactory. New class is TopiaApplicationContextCache
Added:
trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/TopiaApplicationContextCacheTest.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaApplicationContextCache.java
Removed:
trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/TopiaContextFactoryTest.java
Modified:
trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/TestHelper.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaContextFactory.java
trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/TopiaReplicationOperationTest.java
trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/TopiaReplicationServiceImplAllTest.java
trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/TopiaReplicationServiceImplTest.java
Modified: trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/TestHelper.java
===================================================================
--- trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/TestHelper.java 2013-11-28 00:43:28 UTC (rev 2900)
+++ trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/TestHelper.java 2013-11-28 08:39:47 UTC (rev 2901)
@@ -30,6 +30,7 @@
import org.hibernate.cfg.Environment;
import org.junit.Ignore;
import org.nuiton.topia.AbstractTopiaApplicationContext;
+import org.nuiton.topia.TopiaApplicationContextCache;
import org.nuiton.topia.TopiaContextFactory;
import org.nuiton.topia.TopiaNotFoundException;
import org.nuiton.util.FileUtil;
@@ -117,7 +118,7 @@
testDirectory,
dbPropertiesPath,
dbname);
- return TopiaContextFactory.getContext(configuration, CREATE_TOPIA_TEST_CONTEXT);
+ return TopiaApplicationContextCache.getContext(configuration, CREATE_TOPIA_TEST_CONTEXT);
}
public static Properties initTopiaContextConfiguration(File testDirectory,
Copied: trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/TopiaApplicationContextCacheTest.java (from rev 2899, trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/TopiaContextFactoryTest.java)
===================================================================
--- trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/TopiaApplicationContextCacheTest.java (rev 0)
+++ trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/TopiaApplicationContextCacheTest.java 2013-11-28 08:39:47 UTC (rev 2901)
@@ -0,0 +1,205 @@
+/*
+ * #%L
+ * ToPIA :: Persistence
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2004 - 2010 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
+package org.nuiton.topia.it.legacy;
+
+import org.apache.commons.lang3.reflect.FieldUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.nuiton.topia.AbstractTopiaApplicationContext;
+import org.nuiton.topia.TopiaApplicationContextCache;
+import org.nuiton.topia.junit.ConfigurationHelper;
+
+import java.io.File;
+import java.io.IOException;
+import java.lang.reflect.Field;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+
+import com.google.common.base.Function;
+
+/**
+ * Created: 8 mai 2010
+ *
+ * @author fdesbois <fdesbois(a)codelutin.com>
+ * @version $Id$
+ */
+public class TopiaApplicationContextCacheTest {
+
+ private static final Log log =
+ LogFactory.getLog(TopiaApplicationContextCacheTest.class);
+
+ protected static final Function<Properties,AbstractTopiaApplicationContext> CREATE_TOPIA_TEST_CONTEXT = new Function<Properties, AbstractTopiaApplicationContext>() {
+ @Override
+ public AbstractTopiaApplicationContext apply(Properties input) {
+ return new TopiaTestTopiaApplicationContext(input);
+ }
+ };
+
+ protected static Map<Properties, AbstractTopiaApplicationContext> contextCache;
+
+ protected static File testBasedir;
+
+ protected Properties properties;
+
+ @BeforeClass
+ public static void init() throws IOException, IllegalAccessException {
+
+ testBasedir = ConfigurationHelper.getTestSpecificDirectory(TopiaApplicationContextCacheTest.class, "dummy");
+ Field field = FieldUtils.getField(TopiaApplicationContextCache.class, "contextCache", true);
+ contextCache = (Map<Properties, AbstractTopiaApplicationContext>) field.get(null);
+ }
+
+ @Before
+ public void setUp() throws Exception {
+ properties = new Properties();
+ properties.setProperty("prop1", "value1");
+ properties.setProperty("prop2", "value2");
+ contextCache.clear();
+ }
+
+ @Test
+ public void testGetRegisteredContextUrls() throws Exception {
+ log.debug("## testGetRegisteredContextUrls");
+
+ /** PREPARE DATA **/
+ String databaseName = "h2data-testGetContextByProperties";
+ File dbDirectory = new File(testBasedir, databaseName);
+ String url = "jdbc:h2:file:" + dbDirectory;
+ properties.setProperty("hibernate.connection.url", url);
+
+ TopiaTestTopiaApplicationContext test = new TopiaTestTopiaApplicationContext(properties);
+ contextCache.put(properties, test);
+
+ /** EXEC METHOD **/
+ List<String> result = TopiaApplicationContextCache.getRegisteredContextUrls();
+ Assert.assertEquals(1, result.size());
+ Assert.assertEquals(url, result.get(0));
+ }
+
+ @Test
+ public void testRemoveContext() throws Exception {
+ log.debug("## testRemoveContext");
+
+ /** PREPARE DATA **/
+ TopiaTestTopiaApplicationContext test = new TopiaTestTopiaApplicationContext(properties);
+ contextCache.put(properties, test);
+
+ /** EXEC METHOD **/
+ TopiaApplicationContextCache.removeContext(test);
+ Assert.assertEquals(0, contextCache.size());
+ }
+
+ //@Test
+
+ public void testGetContext() throws Exception {
+ // TODO-fdesbois-20100508 : only used TopiaUtil.getProperties, need tests for this method
+ }
+
+ @Test
+ public void testGetContextByProperties() throws Exception {
+ log.debug("## testGetContextByProperties");
+
+ /** PREPARE DATA **/
+ Properties propertiesParent = new Properties(properties);
+ propertiesParent.setProperty("prop3", "value3");
+
+ Properties propertiesAll = new Properties();
+ propertiesAll.setProperty("prop1", "value1");
+ propertiesAll.setProperty("prop2", "value2");
+ propertiesAll.setProperty("prop3", "value3");
+
+ /** EXEC METHOD **/
+
+ log.info("test 0 : add null properties");
+ try {
+ TopiaApplicationContextCache.getContext(null, CREATE_TOPIA_TEST_CONTEXT);
+ } catch (Exception eee) {
+ Assert.assertEquals(NullPointerException.class, eee.getClass());
+ }
+
+ log.info("test 1 : add new properties, will instantiate a new" +
+ " TopiaContext");
+ AbstractTopiaApplicationContext test1 = TopiaApplicationContextCache.getContext(propertiesParent, CREATE_TOPIA_TEST_CONTEXT);
+ Assert.assertNotNull(test1);
+ Assert.assertEquals(1, contextCache.size());
+
+ log.info("test 2 : with same properties, will retrieve existing" +
+ " TopiaContext");
+ AbstractTopiaApplicationContext test2 = TopiaApplicationContextCache.getContext(propertiesParent, CREATE_TOPIA_TEST_CONTEXT);
+ Assert.assertEquals(test1, test2);
+ Assert.assertEquals(1, contextCache.size());
+
+ log.info("test 3 : use other properties, will instantiate a different" +
+ "TopiaContext");
+ AbstractTopiaApplicationContext test3 = TopiaApplicationContextCache.getContext(properties, CREATE_TOPIA_TEST_CONTEXT);
+ log.debug("cache size : " + contextCache.size());
+ log.debug("result : " + test1);
+ log.debug("result3 : " + test3);
+ Assert.assertNotSame(test1, test3);
+ Assert.assertEquals(2, contextCache.size());
+
+ log.info("test 4 : use other properties but equivalent to existing " +
+ "TopiaContext");
+ // Test flating of properties
+ AbstractTopiaApplicationContext test4 = TopiaApplicationContextCache.getContext(propertiesAll, CREATE_TOPIA_TEST_CONTEXT);
+ Assert.assertEquals(test1, test4);
+ Assert.assertEquals(2, contextCache.size());
+
+ log.info("test5a : reinstantiate new TopiaContext after one is closed.");
+ // TEST
+ // Strange behavior the closed flag of context stay true if
+ // hibernateFactory is not loaded from real properties
+// test1.closeContext();
+// Assert.assertTrue(test1.isClosed());
+
+ // Add properties for Hibernate to have real opened topiaContext
+ String databaseName = "h2data-testGetContextByPropertie";
+ File f = new File(testBasedir, databaseName);
+
+ properties.setProperty("hibernate.connection.username", "sa");
+ properties.setProperty("hibernate.connection.password", "");
+ properties.setProperty("hibernate.connection.driver_class", "org.h2.Driver");
+ properties.setProperty("hibernate.connection.url",
+ "jdbc:h2:file:" + f.getAbsolutePath());
+
+
+ AbstractTopiaApplicationContext test5 = TopiaApplicationContextCache.getContext(properties, CREATE_TOPIA_TEST_CONTEXT);
+ Assert.assertNotSame(test1, test5);
+ Assert.assertEquals(3, contextCache.size());
+
+ log.info("test5b : beginTransaction to properly close the context");
+ test5.newPersistenceContext();
+ test5.closeContext();
+
+ AbstractTopiaApplicationContext test5b = TopiaApplicationContextCache.getContext(properties, CREATE_TOPIA_TEST_CONTEXT);
+ Assert.assertNotSame(test5, test5b);
+ Assert.assertEquals(3, contextCache.size());
+ }
+}
Deleted: trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/TopiaContextFactoryTest.java
===================================================================
--- trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/TopiaContextFactoryTest.java 2013-11-28 00:43:28 UTC (rev 2900)
+++ trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/TopiaContextFactoryTest.java 2013-11-28 08:39:47 UTC (rev 2901)
@@ -1,205 +0,0 @@
-/*
- * #%L
- * ToPIA :: Persistence
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2004 - 2010 CodeLutin
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>.
- * #L%
- */
-package org.nuiton.topia.it.legacy;
-
-import org.apache.commons.lang3.reflect.FieldUtils;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.nuiton.topia.AbstractTopiaApplicationContext;
-import org.nuiton.topia.TopiaContextFactory;
-import org.nuiton.topia.junit.ConfigurationHelper;
-
-import java.io.File;
-import java.io.IOException;
-import java.lang.reflect.Field;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-
-import com.google.common.base.Function;
-
-/**
- * Created: 8 mai 2010
- *
- * @author fdesbois <fdesbois(a)codelutin.com>
- * @version $Id$
- */
-public class TopiaContextFactoryTest {
-
- private static final Log log =
- LogFactory.getLog(TopiaContextFactoryTest.class);
-
- protected static final Function<Properties,AbstractTopiaApplicationContext> CREATE_TOPIA_TEST_CONTEXT = new Function<Properties, AbstractTopiaApplicationContext>() {
- @Override
- public AbstractTopiaApplicationContext apply(Properties input) {
- return new TopiaTestTopiaApplicationContext(input);
- }
- };
-
- protected static Map<Properties, AbstractTopiaApplicationContext> contextCache;
-
- protected static File testBasedir;
-
- protected Properties properties;
-
- @BeforeClass
- public static void init() throws IOException, IllegalAccessException {
-
- testBasedir = ConfigurationHelper.getTestSpecificDirectory(TopiaContextFactoryTest.class, "dummy");
- Field field = FieldUtils.getField(TopiaContextFactory.class, "contextCache", true);
- contextCache = (Map<Properties, AbstractTopiaApplicationContext>) field.get(null);
- }
-
- @Before
- public void setUp() throws Exception {
- properties = new Properties();
- properties.setProperty("prop1", "value1");
- properties.setProperty("prop2", "value2");
- contextCache.clear();
- }
-
- @Test
- public void testGetContextOpened() throws Exception {
- log.debug("## testGetContextOpened");
-
- /** PREPARE DATA **/
- String databaseName = "h2data-testGetContextByProperties";
- File dbDirectory = new File(testBasedir, databaseName);
- String url = "jdbc:h2:file:" + dbDirectory;
- properties.setProperty("hibernate.connection.url", url);
-
- TopiaTestTopiaApplicationContext test = new TopiaTestTopiaApplicationContext(properties);
- contextCache.put(properties, test);
-
- /** EXEC METHOD **/
- List<String> result = TopiaContextFactory.getContextOpened();
- Assert.assertEquals(1, result.size());
- Assert.assertEquals(url, result.get(0));
- }
-
- @Test
- public void testRemoveContext() throws Exception {
- log.debug("## testRemoveContext");
-
- /** PREPARE DATA **/
- TopiaTestTopiaApplicationContext test = new TopiaTestTopiaApplicationContext(properties);
- contextCache.put(properties, test);
-
- /** EXEC METHOD **/
- TopiaContextFactory.removeContext(test);
- Assert.assertEquals(0, contextCache.size());
- }
-
- //@Test
-
- public void testGetContext() throws Exception {
- // TODO-fdesbois-20100508 : only used TopiaUtil.getProperties, need tests for this method
- }
-
- @Test
- public void testGetContextByProperties() throws Exception {
- log.debug("## testGetContextByProperties");
-
- /** PREPARE DATA **/
- Properties propertiesParent = new Properties(properties);
- propertiesParent.setProperty("prop3", "value3");
-
- Properties propertiesAll = new Properties();
- propertiesAll.setProperty("prop1", "value1");
- propertiesAll.setProperty("prop2", "value2");
- propertiesAll.setProperty("prop3", "value3");
-
- /** EXEC METHOD **/
-
- log.info("test 0 : add null properties");
- try {
- TopiaContextFactory.getContext(null, CREATE_TOPIA_TEST_CONTEXT);
- } catch (Exception eee) {
- Assert.assertEquals(NullPointerException.class, eee.getClass());
- }
-
- log.info("test 1 : add new properties, will instantiate a new" +
- " TopiaContext");
- AbstractTopiaApplicationContext test1 = TopiaContextFactory.getContext(propertiesParent, CREATE_TOPIA_TEST_CONTEXT);
- Assert.assertNotNull(test1);
- Assert.assertEquals(1, contextCache.size());
-
- log.info("test 2 : with same properties, will retrieve existing" +
- " TopiaContext");
- AbstractTopiaApplicationContext test2 = TopiaContextFactory.getContext(propertiesParent, CREATE_TOPIA_TEST_CONTEXT);
- Assert.assertEquals(test1, test2);
- Assert.assertEquals(1, contextCache.size());
-
- log.info("test 3 : use other properties, will instantiate a different" +
- "TopiaContext");
- AbstractTopiaApplicationContext test3 = TopiaContextFactory.getContext(properties, CREATE_TOPIA_TEST_CONTEXT);
- log.debug("cache size : " + contextCache.size());
- log.debug("result : " + test1);
- log.debug("result3 : " + test3);
- Assert.assertNotSame(test1, test3);
- Assert.assertEquals(2, contextCache.size());
-
- log.info("test 4 : use other properties but equivalent to existing " +
- "TopiaContext");
- // Test flating of properties
- AbstractTopiaApplicationContext test4 = TopiaContextFactory.getContext(propertiesAll, CREATE_TOPIA_TEST_CONTEXT);
- Assert.assertEquals(test1, test4);
- Assert.assertEquals(2, contextCache.size());
-
- log.info("test5a : reinstantiate new TopiaContext after one is closed.");
- // TEST
- // Strange behavior the closed flag of context stay true if
- // hibernateFactory is not loaded from real properties
-// test1.closeContext();
-// Assert.assertTrue(test1.isClosed());
-
- // Add properties for Hibernate to have real opened topiaContext
- String databaseName = "h2data-testGetContextByPropertie";
- File f = new File(testBasedir, databaseName);
-
- properties.setProperty("hibernate.connection.username", "sa");
- properties.setProperty("hibernate.connection.password", "");
- properties.setProperty("hibernate.connection.driver_class", "org.h2.Driver");
- properties.setProperty("hibernate.connection.url",
- "jdbc:h2:file:" + f.getAbsolutePath());
-
-
- AbstractTopiaApplicationContext test5 = TopiaContextFactory.getContext(properties, CREATE_TOPIA_TEST_CONTEXT);
- Assert.assertNotSame(test1, test5);
- Assert.assertEquals(3, contextCache.size());
-
- log.info("test5b : beginTransaction to properly close the context");
- test5.newPersistenceContext();
- test5.closeContext();
-
- AbstractTopiaApplicationContext test5b = TopiaContextFactory.getContext(properties, CREATE_TOPIA_TEST_CONTEXT);
- Assert.assertNotSame(test5, test5b);
- Assert.assertEquals(3, contextCache.size());
- }
-}
Added: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaApplicationContextCache.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaApplicationContextCache.java (rev 0)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaApplicationContextCache.java 2013-11-28 08:39:47 UTC (rev 2901)
@@ -0,0 +1,133 @@
+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.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+
+import org.apache.commons.collections.map.AbstractReferenceMap;
+import org.apache.commons.collections.map.ReferenceMap;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import com.google.common.base.Function;
+import com.google.common.collect.Lists;
+
+/**
+ * This class will provide a TopiaApplicationContext cache. Its usage is not necessary, contexts can be directly created
+ * outside of this cache, then the cache will not contain any reference to the created ApplicationContexts.
+ * <p/>
+ * This class is 'inspired' from the TopiaContextFactory of ToPIA 2.x
+ *
+ * @author Arnaud Thimel <thimel(a)codelutin.com>
+ * @since 3.0
+ */
+public class TopiaApplicationContextCache {
+
+ private static final Log log = LogFactory.getLog(TopiaApplicationContextCache.class);
+
+ /**
+ * Cache that contains all some already registered caches
+ */
+ protected static Map<Properties, AbstractTopiaApplicationContext> contextCache =
+ new ReferenceMap(AbstractReferenceMap.HARD,
+ AbstractReferenceMap.SOFT);
+
+ /**
+ * Static method that can provide an ApplicationContext. If the found context is closed, or if it does not exist, a
+ * new one is created using the given Function<Properties, C>.
+ *
+ * @param <C> the type of TopiaApplicationContext you expect
+ * @param config the configuration of the context
+ * @param createContextFunction the function that will be in charge of the context creation. It might not be used
+ * inside the method if the context is found and still opened
+ * @return an opened instance of XyzTopiaApplicationContext
+ * @throws TopiaNotFoundException if any pb
+ */
+ public static <C extends AbstractTopiaApplicationContext> C getContext(
+ Properties config, Function<Properties, C> createContextFunction)
+ throws TopiaNotFoundException {
+ // Put all properties from a hierarchy in the current properties object.
+ // Resolve problem with hibernate which used iterator to get properties
+ // and so only values from the current properties object and not all
+ // hierarchy
+ Properties cloned = new Properties();
+ for (String key : config.stringPropertyNames()) {
+ cloned.setProperty(key, config.getProperty(key));
+ }
+ C result = (C) contextCache.get(cloned);
+ if (result == null || result.isClosed()) {
+ if (createContextFunction == null) {
+ throw new TopiaException(
+ "Function<Properties, AbstractTopiaApplicationContext> is required to create context");
+ } else {
+ result = createContextFunction.apply(cloned);
+ }
+ if (log.isDebugEnabled()) {
+ log.debug("New context created : " + result);
+ }
+ contextCache.put(cloned, result);
+ } else if (log.isDebugEnabled()) {
+ log.debug("Context found : " + result);
+ }
+ return result;
+ }
+
+ /**
+ * Method to get the list of contexts in memory (each context is identified by its URL).
+ * <p/>
+ * To be used for debugging purpose only.
+ *
+ * @return a list of contexts URLs
+ */
+ public static List<String> getRegisteredContextUrls() {
+ List<String> result = Lists.newArrayList();
+ for (Properties e : contextCache.keySet()) {
+ result.add(e.getProperty(TopiaContextFactory.CONFIG_URL));
+ }
+ return result;
+ }
+
+ /**
+ * Remove the given TopiaApplicationContext from the registered ones
+ *
+ * @param context the context instance to remove
+ */
+ public static void removeContext(AbstractTopiaApplicationContext context) {
+
+ Iterator<AbstractTopiaApplicationContext> it = contextCache.values().iterator();
+
+ while (it.hasNext()) {
+ AbstractTopiaApplicationContext curr = it.next();
+ if (curr == context) {
+ it.remove();
+ break;
+ }
+ }
+ }
+
+}
Property changes on: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaApplicationContextCache.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaContextFactory.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaContextFactory.java 2013-11-28 00:43:28 UTC (rev 2900)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaContextFactory.java 2013-11-28 08:39:47 UTC (rev 2901)
@@ -58,11 +58,6 @@
private static final String DEFAULT_CONFIG_PROPERTIES =
"TopiaContextImpl.properties";
- /** Cache contenant tous les contexts deja créé. */
- protected static Map<Properties, AbstractTopiaApplicationContext> contextCache =
- new ReferenceMap(AbstractReferenceMap.HARD,
- AbstractReferenceMap.SOFT);
-
public final static String CONFIG_DEFAULT_SCHEMA = Environment.DEFAULT_SCHEMA;
public final static String CONFIG_USER = Environment.USER;
@@ -111,103 +106,4 @@
public final static String CONFIG_PERSISTENCE_TOPIA_ID_FACTORY_CLASS_NAME =
"topia.persistence.topiaIdFactoryClassName";
- /**
- * Permet de connaitre la liste des contexts encore en memoire, utile pour
- * du debuggage.
- *
- * @return la liste des urls de connexion
- */
- public static List<String> getContextOpened() {
- List<String> result = new ArrayList<String>();
- for (Properties e : contextCache.keySet()) {
- // Useless test : will never happened that e.getValue() is null,
- // not allowed for {@link AbstractReferenceMap#SOFT}.
-// if (e.getValue() != null) {
- result.add(e.getProperty(CONFIG_URL));
-// }
- }
- return result;
- }
-
- /**
- * Used when TopiaContext root is closed
- *
- * @param context closed
- */
- public static void removeContext(AbstractTopiaApplicationContext context) {
-// Properties key = null;
-// for (Entry<Properties, AbstractTopiaContext> e : contextCache.entrySet()) {
-// if (e.getValue() == context) {
-// key = e.getKey();
-// break;
-// }
-// }
-// if (key != null) {
-// contextCache.remove(key);
-// }
-
- // Replaced by more powerful algorithm using iterator to remove context
-
- Iterator<AbstractTopiaApplicationContext> it = contextCache.values().iterator();
-
- while (it.hasNext()) {
- AbstractTopiaApplicationContext curr = it.next();
- if (curr == context) {
- it.remove();
- break;
- }
- }
- }
-
- /**
- * Utilise par defaut le fichier de propriete AbstractTopiaContext.properties
- *
- * @return the context using the default configuration file
- * @throws TopiaNotFoundException Si le fichier de configuration par defaut
- * n'est pas retrouvé.
- */
- public static AbstractTopiaApplicationContext getContext() throws TopiaNotFoundException {
- Properties config = TopiaUtil.getProperties(DEFAULT_CONFIG_PROPERTIES);
- AbstractTopiaApplicationContext result = getContext(config, null);
- return result;
- }
-
- /**
- * Methode static permettant de recuperer un context. Si on donne plusieurs
- * fois le meme objet config, on obtient la meme instance de
- * AbstractTopiaContext. Si le context qui devrait etre retourné est ferme,
- * alors un nouveau est creer et retourné.
- *
- * @param config the configuration of the context
- * @return Un TopiaContext ouvert
- * @throws TopiaNotFoundException if any pb
- */
- public static <C extends AbstractTopiaApplicationContext> C getContext(
- Properties config, Function<Properties, C> createContextFunction)
- throws TopiaNotFoundException {
- // Put all properties from a hierarchy in the current properties object.
- // Resolve problem with hibernate which used iterator to get properties
- // and so only values from the current properties object and not all
- // hierarchy
- Properties cloned = new Properties();
- for (String key : config.stringPropertyNames()) {
- cloned.setProperty(key, config.getProperty(key));
- }
- C result = (C)contextCache.get(cloned);
- if (result == null || result.isClosed()) {
- if (createContextFunction == null) {
- throw new TopiaException("Function<Properties, AbstractTopiaApplicationContext> is needed to create context");
- } else {
- result = createContextFunction.apply(cloned);
- }
- if (log.isDebugEnabled()) {
- log.debug("instantiate new topiaContext : " + result);
- }
- contextCache.put(cloned, result);
- } else if (log.isDebugEnabled()) {
- log.debug("topiaContext found : " + result);
- }
- return result;
- }
-
}
Modified: trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/TopiaReplicationOperationTest.java
===================================================================
--- trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/TopiaReplicationOperationTest.java 2013-11-28 00:43:28 UTC (rev 2900)
+++ trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/TopiaReplicationOperationTest.java 2013-11-28 08:39:47 UTC (rev 2901)
@@ -33,7 +33,7 @@
import org.junit.BeforeClass;
import org.junit.Test;
import org.nuiton.topia.AbstractTopiaApplicationContext;
-import org.nuiton.topia.TopiaContextFactory;
+import org.nuiton.topia.TopiaApplicationContextCache;
import org.nuiton.topia.TopiaPersistenceContext;
import org.nuiton.topia.it.TopiaConfigurationHelper;
import org.nuiton.topia.it.legacy.TopiaTestEntityEnum;
@@ -285,7 +285,7 @@
Properties config = getH2Properties(name);
- sourceContext = TopiaContextFactory.getContext(config, CREATE_TOPIA_TEST_APPLICATION_CONTEXT);
+ sourceContext = TopiaApplicationContextCache.getContext(config, CREATE_TOPIA_TEST_APPLICATION_CONTEXT);
TopiaPersistenceContext tx = sourceContext.newPersistenceContext();
Modified: trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/TopiaReplicationServiceImplAllTest.java
===================================================================
--- trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/TopiaReplicationServiceImplAllTest.java 2013-11-28 00:43:28 UTC (rev 2900)
+++ trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/TopiaReplicationServiceImplAllTest.java 2013-11-28 08:39:47 UTC (rev 2901)
@@ -33,7 +33,7 @@
import org.junit.BeforeClass;
import org.junit.Test;
import org.nuiton.topia.AbstractTopiaApplicationContext;
-import org.nuiton.topia.TopiaContextFactory;
+import org.nuiton.topia.TopiaApplicationContextCache;
import org.nuiton.topia.TopiaException;
import org.nuiton.topia.TopiaPersistenceContext;
import org.nuiton.topia.it.TopiaConfigurationHelper;
@@ -232,7 +232,7 @@
Properties config = getH2Properties(name);
- sourceContext = TopiaContextFactory.getContext(config, CREATE_TOPIA_TEST_APPLICATION_CONTEXT);
+ sourceContext = TopiaApplicationContextCache.getContext(config, CREATE_TOPIA_TEST_APPLICATION_CONTEXT);
TopiaPersistenceContext tx = sourceContext.newPersistenceContext();
@@ -259,7 +259,7 @@
Properties config = getH2Properties(name);
- return TopiaContextFactory.getContext(config, CREATE_TOPIA_TEST_APPLICATION_CONTEXT);
+ return TopiaApplicationContextCache.getContext(config, CREATE_TOPIA_TEST_APPLICATION_CONTEXT);
}
@Override
Modified: trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/TopiaReplicationServiceImplTest.java
===================================================================
--- trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/TopiaReplicationServiceImplTest.java 2013-11-28 00:43:28 UTC (rev 2900)
+++ trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/TopiaReplicationServiceImplTest.java 2013-11-28 08:39:47 UTC (rev 2901)
@@ -33,7 +33,7 @@
import org.junit.BeforeClass;
import org.junit.Test;
import org.nuiton.topia.AbstractTopiaApplicationContext;
-import org.nuiton.topia.TopiaContextFactory;
+import org.nuiton.topia.TopiaApplicationContextCache;
import org.nuiton.topia.TopiaException;
import org.nuiton.topia.TopiaPersistenceContext;
import org.nuiton.topia.it.TopiaConfigurationHelper;
@@ -391,7 +391,7 @@
Properties config = getH2Properties(name);
- sourceContext = TopiaContextFactory.getContext(config, CREATE_TOPIA_TEST_APPLICATION_CONTEXT);
+ sourceContext = TopiaApplicationContextCache.getContext(config, CREATE_TOPIA_TEST_APPLICATION_CONTEXT);
TopiaPersistenceContext tx = sourceContext.newPersistenceContext();
@@ -420,7 +420,7 @@
Properties config = getH2Properties(name);
- return TopiaContextFactory.getContext(config, CREATE_TOPIA_TEST_APPLICATION_CONTEXT);
+ return TopiaApplicationContextCache.getContext(config, CREATE_TOPIA_TEST_APPLICATION_CONTEXT);
}
@Override
1
0
r2900 - in trunk/topia-persistence/src/main/java/org/nuiton/topia: . persistence/util
by athimel@users.nuiton.org 28 Nov '13
by athimel@users.nuiton.org 28 Nov '13
28 Nov '13
Author: athimel
Date: 2013-11-28 01:43:28 +0100 (Thu, 28 Nov 2013)
New Revision: 2900
Url: http://nuiton.org/projects/topia/repository/revisions/2900
Log:
fixes #2923 Fix the latests impacts of deprecated code removal
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/HibernateTopiaSqlSupport.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaVetoException.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/DBMapping.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-11-27 18:18:10 UTC (rev 2899)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/AbstractTopiaApplicationContext.java 2013-11-28 00:43:28 UTC (rev 2900)
@@ -119,7 +119,7 @@
persistenceContexts.add(persistenceContext);
}
- // TODO AThimel 25/11/13 I don't like it to be public, but necessary for services. Review it
+ // FIXME AThimel 25/11/13 I don't like it to be public, but necessary for services. Review it
public HibernateProvider getHibernateProvider() {
if (hibernateProvider == null) {
hibernateProvider = new HibernateProvider(configuration, topiaServiceSupport, sessionRegistry);
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/AbstractTopiaPersistenceContext.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/AbstractTopiaPersistenceContext.java 2013-11-27 18:18:10 UTC (rev 2899)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/AbstractTopiaPersistenceContext.java 2013-11-28 00:43:28 UTC (rev 2900)
@@ -131,6 +131,28 @@
this.sqlSupport = new HibernateTopiaSqlSupport(hibernateSupport);
}
+ protected TopiaFiresSupport getFiresSupport() {
+ return firesSupport;
+ }
+
+ public TopiaHibernateSupport getHibernateSupport() {
+ return hibernateSupport;
+ }
+
+ public TopiaSqlSupport getSqlSupport() {
+ return sqlSupport;
+ }
+
+ @Override
+ public TopiaIdFactory getTopiaIdFactory() {
+ return topiaIdFactory;
+ }
+
+ @Override
+ public TopiaFiresSupport getTopiaFiresSupport() {
+ return firesSupport;
+ }
+
/**
* 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).
@@ -215,14 +237,6 @@
}
}
- protected TopiaFiresSupport getFiresSupport() {
- return firesSupport;
- }
-
- public TopiaHibernateSupport getHibernateSupport() {
- return hibernateSupport;
- }
-
@Override
public <E extends TopiaEntity> E findByTopiaId(String topiaId) {
checkClosed();
@@ -245,16 +259,6 @@
}
@Override
- public TopiaIdFactory getTopiaIdFactory() {
- return topiaIdFactory;
- }
-
- @Override
- public TopiaFiresSupport getTopiaFiresSupport() {
- return firesSupport;
- }
-
- @Override
public <E extends TopiaEntity> TopiaDao<E> getDao(Class<E> entityClass) {
Preconditions.checkArgument(entityClass != null, "The method 'getDao' requires a non null 'entityClass' parameter");
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/HibernateTopiaSqlSupport.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/HibernateTopiaSqlSupport.java 2013-11-27 18:18:10 UTC (rev 2899)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/HibernateTopiaSqlSupport.java 2013-11-28 00:43:28 UTC (rev 2900)
@@ -45,10 +45,11 @@
this.hibernateSupport = hibernateSupport;
}
- public static class SQLWork implements Work {
- private final String script;
+ public static class HibernateSqlWork implements Work {
- public SQLWork(String script) {
+ protected final String script;
+
+ public HibernateSqlWork(String script) {
this.script = script;
}
@@ -63,12 +64,11 @@
}
}
- // FIXME AThimel 22/11/2013 WTF name ?
- public static class TopiaSQLWorkWork implements Work {
+ public static class HibernateTopiaSqlWork implements Work {
- final TopiaSqlWork work;
+ protected final TopiaSqlWork work;
- public TopiaSQLWorkWork(TopiaSqlWork work) {
+ public HibernateTopiaSqlWork(TopiaSqlWork work) {
this.work = work;
}
@@ -78,15 +78,15 @@
}
}
- public static class TopiaSqlQueryWork<O> implements Work {
+ public static class HibernateTopiaSqlQueryWork<O> implements Work {
- final TopiaSqlQuery<O> query;
+ protected final TopiaSqlQuery<O> query;
- final boolean multipleResult;
+ protected final boolean multipleResult;
- final List<O> result = new ArrayList<O>();
+ protected final List<O> result = new ArrayList<O>();
- public TopiaSqlQueryWork(TopiaSqlQuery<O> query, boolean multipleResult) {
+ public HibernateTopiaSqlQueryWork(TopiaSqlQuery<O> query, boolean multipleResult) {
this.query = query;
this.multipleResult = multipleResult;
}
@@ -129,7 +129,7 @@
@Override
public void executeSql(String sqlScript) {
- SQLWork work = new SQLWork(sqlScript);
+ HibernateSqlWork work = new HibernateSqlWork(sqlScript);
try {
hibernateSupport.getHibernateSession().doWork(work);
} catch (HibernateException e) {
@@ -139,7 +139,7 @@
@Override
public void doSqlWork(TopiaSqlWork sqlWork) {
- TopiaSQLWorkWork work = new TopiaSQLWorkWork(sqlWork);
+ HibernateTopiaSqlWork work = new HibernateTopiaSqlWork(sqlWork);
try {
hibernateSupport.getHibernateSession().doWork(work);
} catch (HibernateException e) {
@@ -150,7 +150,7 @@
@Override
public <O> O findSingleResult(final TopiaSqlQuery<O> query) throws TopiaException {
- TopiaSqlQueryWork<O> work = new TopiaSqlQueryWork<O>(query, false);
+ HibernateTopiaSqlQueryWork<O> work = new HibernateTopiaSqlQueryWork<O>(query, false);
hibernateSupport.getHibernateSession().doWork(work);
final List<O> result = work.getResult();
return result.isEmpty() ? null : result.get(0);
@@ -159,7 +159,7 @@
@Override
public <O> List<O> findMultipleResult(final TopiaSqlQuery<O> query) throws TopiaException {
- TopiaSqlQueryWork<O> work = new TopiaSqlQueryWork<O>(query, true);
+ HibernateTopiaSqlQueryWork<O> work = new HibernateTopiaSqlQueryWork<O>(query, true);
hibernateSupport.getHibernateSession().doWork(work);
final List<O> result = work.getResult();
return result;
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaVetoException.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaVetoException.java 2013-11-27 18:18:10 UTC (rev 2899)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaVetoException.java 2013-11-28 00:43:28 UTC (rev 2900)
@@ -33,10 +33,8 @@
* @author poussin <poussin(a)codelutin.com>
* @version $Id$
*/
-// TODO AThimel 03/08/13 Extends TopiaException ?
-public class TopiaVetoException extends RuntimeException {
+public class TopiaVetoException extends TopiaException {
- /** Version UID */
private static final long serialVersionUID = 6809613247516488399L;
/**
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/DBMapping.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/DBMapping.java 2013-11-27 18:18:10 UTC (rev 2899)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/DBMapping.java 2013-11-28 00:43:28 UTC (rev 2900)
@@ -29,6 +29,7 @@
import org.apache.commons.logging.LogFactory;
import org.hibernate.exception.SQLGrammarException;
import org.nuiton.topia.AbstractTopiaApplicationContext;
+import org.nuiton.topia.AbstractTopiaPersistenceContext;
import org.nuiton.topia.TopiaException;
import org.nuiton.topia.TopiaPersistenceContext;
import org.nuiton.topia.TopiaSqlQuery;
@@ -122,7 +123,7 @@
}
String firstSequenceKey = sequences.keySet().iterator().next();
TopiaPersistenceContext newContext = ctxt.newPersistenceContext();
- TopiaSqlSupport sqlSupport = null; // TODO AThimel 23/11/13 Get an instance of TopiaSqlSupprt
+ TopiaSqlSupport sqlSupport = ((AbstractTopiaPersistenceContext)newContext).getSqlSupport();
boolean exists = existSequence(firstSequenceKey, sqlSupport);
if (!exists) {
1
0
r2899 - in trunk: topia-persistence/src/main/java/org/nuiton/topia topia-persistence/src/main/java/org/nuiton/topia/persistence topia-templates/src/main/java/org/nuiton/topia/templates
by athimel@users.nuiton.org 27 Nov '13
by athimel@users.nuiton.org 27 Nov '13
27 Nov '13
Author: athimel
Date: 2013-11-27 19:18:10 +0100 (Wed, 27 Nov 2013)
New Revision: 2899
Url: http://nuiton.org/projects/topia/repository/revisions/2899
Log:
fixes #2925 AbstractTopiaDao is not dependent anymore of the JPA implementation choosen
Modified:
trunk/topia-persistence/src/main/java/org/nuiton/topia/AbstractTopiaPersistenceContext.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/HibernateTopiaJpaSupport.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaJpaSupport.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/AbstractTopiaDao.java
trunk/topia-templates/src/main/java/org/nuiton/topia/templates/EntityDaoTransformer.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-11-27 17:13:23 UTC (rev 2898)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/AbstractTopiaPersistenceContext.java 2013-11-27 18:18:10 UTC (rev 2899)
@@ -301,7 +301,7 @@
if (dao instanceof AbstractTopiaDao) {
AbstractTopiaDao abstractTopiaDao = (AbstractTopiaDao) dao;
- abstractTopiaDao.init(hibernateSupport, jpaSupport, sqlSupport, listenableSupport, topiaIdFactory, firesSupport, this);
+ abstractTopiaDao.init(jpaSupport, sqlSupport, listenableSupport, topiaIdFactory, firesSupport, this);
}
daoCache.put(entityClass, dao);
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/HibernateTopiaJpaSupport.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/HibernateTopiaJpaSupport.java 2013-11-27 17:13:23 UTC (rev 2898)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/HibernateTopiaJpaSupport.java 2013-11-27 18:18:10 UTC (rev 2899)
@@ -58,7 +58,7 @@
* <p/>
* The normal usage is to says yes (that's why the default value is
* {@code true}), in that case whebn doing queries (says in method
- * {@link #findAll(String, Object...)} or {@link #find(String, int, int, Object...)})
+ * {@link #findAll(String, Map<String, Object>)} or {@link #find(String, int, int, Map<String, Object>)})
* it will use the flush mode {@link FlushMode#AUTO}).
* <p/>
* But sometimes, when doing a lot of queries (for some imports for example),
@@ -74,6 +74,10 @@
this.firesSupport = firesSupport;
}
+ public TopiaHibernateSupport getHibernateSupport() {
+ return hibernateSupport;
+ }
+
@Override
public void setUseFlushMode(boolean useFlushMode) {
this.useFlushMode = useFlushMode;
@@ -180,4 +184,40 @@
}
}
+ @Override
+ public void save(Object object) {
+ try {
+ hibernateSupport.getHibernateSession().save(object);
+ } catch (HibernateException eee) {
+ throw new TopiaException("Unable to 'save' instance", eee);
+ }
+ }
+
+ @Override
+ public void update(Object object) {
+ try {
+ hibernateSupport.getHibernateSession().update(object);
+ } catch (HibernateException eee) {
+ throw new TopiaException("Unable to 'update' instance", eee);
+ }
+ }
+
+ @Override
+ public void saveOrUpdate(Object object) {
+ try {
+ hibernateSupport.getHibernateSession().saveOrUpdate(object);
+ } catch (HibernateException eee) {
+ throw new TopiaException("Unable to 'saveOrUpdate' instance", eee);
+ }
+ }
+
+ @Override
+ public void delete(Object object) {
+ try {
+ hibernateSupport.getHibernateSession().delete(object);
+ } catch (HibernateException eee) {
+ throw new TopiaException("Unable to 'delete' instance", eee);
+ }
+ }
+
} // HibernateTopiaJpaSupport
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaJpaSupport.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaJpaSupport.java 2013-11-27 17:13:23 UTC (rev 2898)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaJpaSupport.java 2013-11-27 18:18:10 UTC (rev 2899)
@@ -33,7 +33,6 @@
* @author Arnaud Thimel <thimel(a)codelutin.com>
* @since 3.0
*/
-// TODO AThimel 02/08/13 I think we need another name
public interface TopiaJpaSupport {
/**
@@ -103,6 +102,45 @@
* @param useFlushMode the new value to set
* @since 2.5
*/
- void setUseFlushMode(boolean useFlushMode); // XXX AThimel 27/09/13 Maybe this method has to be renamed
+ void setUseFlushMode(boolean useFlushMode);
+ /**
+ * Persist the given transient instance, first assigning a generated identifier. This method is JPA implementation
+ * independent.
+ * <p/>
+ * This method is "inspired" of the Hibernate's Session#save method.
+ *
+ * @param object a transient instance of a persistent class
+ */
+ void save(Object object);
+
+ /**
+ * Update the persistent instance with the identifier of the given detached instance.
+ * <p/>
+ * This method is "inspired" of the Hibernate's Session#update method.
+ *
+ * @param object a detached instance containing updated state
+ */
+ void update(Object object);
+
+ /**
+ * Either {@link #save(Object)} or {@link #update(Object)} the given instance.
+ * <p/>
+ * This method is "inspired" of the Hibernate's Session#saveOrUpdate method.
+ *
+ * @param object a transient or detached instance containing new or updated state
+ * @see #save(java.lang.Object)
+ * @see #update(Object object)
+ */
+ void saveOrUpdate(Object object);
+
+ /**
+ * Remove a persistent instance.
+ * <p/>
+ * This method is "inspired" of the Hibernate's Session#delete method.
+ *
+ * @param object the instance to be removed
+ */
+ void delete(Object object);
+
}
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/AbstractTopiaDao.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/AbstractTopiaDao.java 2013-11-27 17:13:23 UTC (rev 2898)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/AbstractTopiaDao.java 2013-11-27 18:18:10 UTC (rev 2899)
@@ -45,12 +45,9 @@
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.metadata.ClassMetadata;
import org.nuiton.topia.QueryMissingOrderException;
import org.nuiton.topia.TopiaDaoSupplier;
import org.nuiton.topia.TopiaException;
-import org.nuiton.topia.TopiaHibernateSupport;
import org.nuiton.topia.TopiaJpaSupport;
import org.nuiton.topia.TopiaListenableSupport;
import org.nuiton.topia.TopiaNoResultException;
@@ -72,21 +69,20 @@
import java.util.Set;
/**
- * Cette classe permet d'avoir un ensemble de méthode implantée de façon
- * standard et plus spécifiquement pour Hibernate.
+ * This class has the common methods usable for each Dao managed by Topia. It is not JPA implementation dependent, it
+ * only relies on {@link TopiaJpaSupport}.
* <p/>
- * Certains accès à Hibernate sont tout de même fait ici, car on a pris le choix
- * de se baser entièrement sur hibernate pour la persistence, et il est ainsi
- * possible d'accèder au meta information hibernate sur les classes lorque l'on
- * en a besoin.
+ * This class is directly extended by the GeneratedXyzTopiaDao which groups all the Xyz specific methods.
+ * <p/>
+ * Instances are created bt the model's specific {@link org.nuiton.topia.TopiaPersistenceContext}, which implements the
+ * {@link TopiaDaoSupplier} contract.
*
- * @param <E> le type de l'entite
+ * @param <E> the managed entity type
* @author bpoussin <poussin(a)codelutin.com>
- * @version $Id$
+ * @author Arnaud Thimel <thimel(a)codelutin.com>
*/
public abstract class AbstractTopiaDao<E extends TopiaEntity> implements TopiaDao<E> {
- /** to use log facility, just put in your code: log.info(\"...\"); */
private static Log log = LogFactory.getLog(AbstractTopiaDao.class);
/**
@@ -96,9 +92,6 @@
*/
protected int batchSize = 1000;
- @Deprecated // Should not be used here, cf http://nuiton.org/issues/2925
- protected TopiaHibernateSupport topiaHibernateSupport;
-
protected TopiaJpaSupport topiaJpaSupport;
protected TopiaSqlSupport topiaSqlSupport;
@@ -120,7 +113,6 @@
* method just after.
*/
public void init(
- TopiaHibernateSupport topiaHibernateSupport,
TopiaJpaSupport topiaJpaSupport,
TopiaSqlSupport topiaSqlSupport,
TopiaListenableSupport topiaListenableSupport,
@@ -130,7 +122,6 @@
if (log.isDebugEnabled()) {
log.debug("init dao for " + getEntityClass());
}
- this.topiaHibernateSupport = topiaHibernateSupport;
this.topiaJpaSupport = topiaJpaSupport;
this.topiaSqlSupport = topiaSqlSupport;
this.topiaListenableSupport = topiaListenableSupport;
@@ -204,27 +195,23 @@
@Override
public E create(E entity) {
- try {
- // first set topiaId
- if (StringUtils.isBlank(entity.getTopiaId())) {
+ // first set topiaId
+ if (StringUtils.isBlank(entity.getTopiaId())) {
- // only set id if not already on
- String topiaId = topiaIdFactory.newTopiaId(getEntityClass(), entity);
- entity.setTopiaId(topiaId);
- }
+ // only set id if not already on
+ String topiaId = topiaIdFactory.newTopiaId(getEntityClass(), entity);
+ entity.setTopiaId(topiaId);
+ }
- if (entity instanceof TopiaEntityContextable) {
- TopiaEntityContextable contextable = (TopiaEntityContextable) entity;
- contextable.setTopiaDAOSupplier(this.topiaDaoSupplier);
- }
-
- // save entity
- topiaHibernateSupport.getHibernateSession().save(entity);
- topiaFiresSupport.warnOnCreateEntity(entity);
- return entity;
- } catch (HibernateException eee) {
- throw new TopiaException(eee);
+ if (entity instanceof TopiaEntityContextable) {
+ TopiaEntityContextable contextable = (TopiaEntityContextable) entity;
+ contextable.setTopiaDAOSupplier(this.topiaDaoSupplier);
}
+
+ // save entity
+ topiaJpaSupport.save(entity);
+ topiaFiresSupport.warnOnCreateEntity(entity);
+ return entity;
}
@Override
@@ -279,13 +266,9 @@
@Override
public E update(E entity) {
- try {
- topiaHibernateSupport.getHibernateSession().saveOrUpdate(entity);
- topiaFiresSupport.warnOnUpdateEntity(entity);
- return entity;
- } catch (HibernateException eee) {
- throw new TopiaException(eee);
- }
+ topiaJpaSupport.saveOrUpdate(entity);
+ topiaFiresSupport.warnOnUpdateEntity(entity);
+ return entity;
}
@Override
@@ -298,13 +281,9 @@
@Override
public void delete(E entity) {
- try {
- topiaHibernateSupport.getHibernateSession().delete(entity);
- entity.notifyDeleted();
- topiaFiresSupport.warnOnDeleteEntity(entity);
- } catch (HibernateException eee) {
- throw new TopiaException(eee);
- }
+ topiaJpaSupport.delete(entity);
+ entity.notifyDeleted();
+ topiaFiresSupport.warnOnDeleteEntity(entity);
}
@Override
@@ -672,22 +651,21 @@
return result;
}
- /**
- * package locale method because this is hibernate specific method and
- * we don't want expose it.
- *
- * @return the meta-data of the entity
- * @throws org.nuiton.topia.TopiaException if any pb
- */
- protected ClassMetadata getClassMetadata() {
- ClassMetadata meta = topiaHibernateSupport.getHibernateFactory()
- .getClassMetadata(getEntityClass());
- if (meta == null) {
- meta = topiaHibernateSupport.getHibernateFactory().getClassMetadata(
- getTopiaEntityEnum().getImplementationFQN());
- }
- return meta;
- }
+// /**
+// * package locale method because this is hibernate specific method and
+// * we don't want expose it.
+// *
+// * @return the meta-data of the entity
+// * @throws org.nuiton.topia.TopiaException if any pb
+// */
+// protected ClassMetadata getClassMetadata() {
+// ClassMetadata meta = topiaHibernateSupport.getHibernateFactory().getClassMetadata(getEntityClass());
+// if (meta == null) {
+// String implementationFQN = getTopiaEntityEnum().getImplementationFQN();
+// meta = topiaHibernateSupport.getHibernateFactory().getClassMetadata(implementationFQN);
+// }
+// return meta;
+// }
public static class FindAllIterator<E extends TopiaEntity, R> implements Iterator<R> {
@@ -1032,14 +1010,12 @@
@Override
public List<String> findAllIds() {
- // XXX brendan 30/09/13 does this truely work ?
String hqlWithSelectClause = "select topiaId " + hql;
return topiaDAO.findAll(hqlWithSelectClause, hqlParameters, String.class);
}
@Override
public List<String> findIds(int startIndex, int endIndex) {
- // XXX brendan 30/09/13 does this truely work ?
String hqlWithSelectClause = "select topiaId " + hql;
return topiaDAO.find(hqlWithSelectClause, hqlParameters, String.class, startIndex, endIndex);
}
Modified: trunk/topia-templates/src/main/java/org/nuiton/topia/templates/EntityDaoTransformer.java
===================================================================
--- trunk/topia-templates/src/main/java/org/nuiton/topia/templates/EntityDaoTransformer.java 2013-11-27 17:13:23 UTC (rev 2898)
+++ trunk/topia-templates/src/main/java/org/nuiton/topia/templates/EntityDaoTransformer.java 2013-11-27 18:18:10 UTC (rev 2899)
@@ -33,6 +33,7 @@
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.hibernate.Session;
import org.nuiton.eugene.GeneratorUtil;
import org.nuiton.eugene.java.JavaGeneratorUtil;
import org.nuiton.eugene.java.ObjectModelTransformerToJava;
@@ -45,7 +46,8 @@
import org.nuiton.eugene.models.object.ObjectModelInterface;
import org.nuiton.eugene.models.object.ObjectModelJavaModifier;
import org.nuiton.eugene.models.object.ObjectModelOperation;
-import org.nuiton.topia.TopiaException;
+import org.nuiton.topia.HibernateTopiaJpaSupport;
+import org.nuiton.topia.TopiaHibernateSupport;
import org.nuiton.topia.persistence.TopiaEntity;
import org.nuiton.topia.persistence.TopiaQueryBuilderAddCriteriaOrRunQueryStep;
@@ -417,7 +419,6 @@
addImport(daoAbstractClass, Set.class);
}
addImport(daoAbstractClass, List.class);
- addImport(daoAbstractClass, TopiaException.class);
addImport(daoAbstractClass, TopiaQueryBuilderAddCriteriaOrRunQueryStep.class);
ObjectModelOperation op;
@@ -495,6 +496,8 @@
PROP_DEFAULT_PACKAGE) + '.' + modelName +
"DAOHelper.getImplementationClass";
+ boolean hibernateSupportGenerated = false;
+
for (ObjectModelAttribute attr : clazz.getAttributes()) {
String attrType = GeneratorUtil.getSimpleName(attr.getType());
@@ -559,16 +562,31 @@
// System.out.println("Query : " + query);
// List<<%=attrType%>> list = dao.findAllByQuery(query);
+ if (!hibernateSupportGenerated) {
+ hibernateSupportGenerated = true;
+ addImport(result, TopiaHibernateSupport.class);
+ addImport(result, HibernateTopiaJpaSupport.class);
+ addImport(result, Session.class);
+ body.append(""
+/*{
+ TopiaHibernateSupport hibernateSupport = ((HibernateTopiaJpaSupport) topiaJpaSupport).getHibernateSupport();
+ Session hibernateSession = hibernateSupport.getHibernateSession();
+}*/
+ );
+ }
+
String removeName = getJavaBeanMethodName("remove", reverseAttrName);
body.append(""
/*{
{
- List<<%=attrType%>> list = topiaHibernateSupport.getHibernateSession().createSQLQuery(
- "SELECT main.topiaid " +
- "from <%=attrClassifierDBName%> main, <%=attrJoinTableName%> secondary " +
- "where main.topiaid=secondary.<%=attrDBName%>" +
- " and secondary.<%=attrReverseDBName%>='" + entity.getTopiaId() + "'")
- .addEntity("main", <%=entityEnumName%>.<%=attrType%>.getImplementation()).list();
+ String sql = "SELECT main.topiaid " +
+ " FROM <%=attrClassifierDBName%> main, <%=attrJoinTableName%> secondary " +
+ " WHERE main.topiaid=secondary.<%=attrDBName%> " +
+ " AND secondary.<%=attrReverseDBName%>='" + entity.getTopiaId() + "'";
+ List<<%=attrType%>> list = hibernateSession
+ .createSQLQuery(sql)
+ .addEntity("main", <%=entityEnumName%>.<%=attrType%>.getImplementation())
+ .list();
for (<%=attrType%> item : list) {
item.<%=removeName%>(entity);
1
0
r2898 - trunk/topia-templates/src/main/java/org/nuiton/topia/templates
by athimel@users.nuiton.org 27 Nov '13
by athimel@users.nuiton.org 27 Nov '13
27 Nov '13
Author: athimel
Date: 2013-11-27 18:13:23 +0100 (Wed, 27 Nov 2013)
New Revision: 2898
Url: http://nuiton.org/projects/topia/repository/revisions/2898
Log:
Let PersistenceContextTransformer delegate to XyzEntityEnum as much as possible
Modified:
trunk/topia-templates/src/main/java/org/nuiton/topia/templates/EntityEnumTransformer.java
trunk/topia-templates/src/main/java/org/nuiton/topia/templates/PersistenceContextTransformer.java
Modified: trunk/topia-templates/src/main/java/org/nuiton/topia/templates/EntityEnumTransformer.java
===================================================================
--- trunk/topia-templates/src/main/java/org/nuiton/topia/templates/EntityEnumTransformer.java 2013-11-27 11:11:51 UTC (rev 2897)
+++ trunk/topia-templates/src/main/java/org/nuiton/topia/templates/EntityEnumTransformer.java 2013-11-27 17:13:23 UTC (rev 2898)
@@ -90,7 +90,9 @@
}
entityEnum = createEnumeration(entityEnumName, packageName);
addImport(entityEnum, TopiaEntity.class);
- addImport(entityEnum, EntityOperatorStore.class);
+ if (generateOperator) {
+ addImport(entityEnum, EntityOperatorStore.class);
+ }
addImport(entityEnum, Arrays.class);
addImport(entityEnum, ArrayUtils.class);
Modified: trunk/topia-templates/src/main/java/org/nuiton/topia/templates/PersistenceContextTransformer.java
===================================================================
--- trunk/topia-templates/src/main/java/org/nuiton/topia/templates/PersistenceContextTransformer.java 2013-11-27 11:11:51 UTC (rev 2897)
+++ trunk/topia-templates/src/main/java/org/nuiton/topia/templates/PersistenceContextTransformer.java 2013-11-27 17:13:23 UTC (rev 2898)
@@ -42,7 +42,6 @@
import org.nuiton.topia.persistence.util.EntityOperator;
import org.nuiton.topia.persistence.util.EntityOperatorStore;
-import java.lang.reflect.Array;
import java.util.List;
/**
@@ -131,15 +130,11 @@
//
// }
-// addImport(output, TopiaDAO.class);
addImport(output, TopiaEntity.class);
-// addImport(output, TopiaContext.class);
- addImport(output, Array.class);
- addImport(output, Array.class);
if (generateOperator) {
addImport(output, EntityOperator.class);
- addImport(output, EntityOperatorStore.class);
+// addImport(output, EntityOperatorStore.class);
}
// add public constructor
@@ -194,23 +189,20 @@
}
- // getContractClass method
- op = addOperation(output, "getContractClass", "<T extends TopiaEntity> Class<T>", ObjectModelJavaModifier.PUBLIC, ObjectModelJavaModifier.STATIC);
- addParameter(op, "Class<T>", "klass");
+ // getContracts method
+ op = addOperation(output, "getContracts", entityEnumName + "[]", ObjectModelJavaModifier.PUBLIC, ObjectModelJavaModifier.STATIC);
setOperationBody(op, ""
/*{
- <%=entityEnumName%> constant = <%=entityEnumName%>.valueOf(klass);
- return (Class<T>) constant.getContract();
+ return <%=entityEnumName%>.getContracts();
}*/
);
- // getImplementationClass method
- op = addOperation(output, "getImplementationClass", "<T extends TopiaEntity> Class<T>", ObjectModelJavaModifier.PUBLIC, ObjectModelJavaModifier.STATIC);
+ // getContractClass method
+ op = addOperation(output, "getContractClass", "<T extends TopiaEntity> Class<T>", ObjectModelJavaModifier.PUBLIC, ObjectModelJavaModifier.STATIC);
addParameter(op, "Class<T>", "klass");
setOperationBody(op, ""
/*{
- <%=entityEnumName%> constant = <%=entityEnumName%>.valueOf(klass);
- return (Class<T>) constant.getImplementation();
+ return <%=entityEnumName%>.getContractClass(klass);
}*/
);
@@ -218,33 +210,32 @@
op = addOperation(output, "getContractClasses", "Class<? extends TopiaEntity>[]", ObjectModelJavaModifier.PUBLIC, ObjectModelJavaModifier.STATIC);
setOperationBody(op, ""
/*{
- <%=entityEnumName%>[] values = <%=entityEnumName%>.values();
- Class<? extends TopiaEntity>[] result = (Class<? extends TopiaEntity>[]) Array.newInstance(Class.class, values.length);
- for (int i = 0; i < values.length; i++) {
- result[i] = values[i].getContract();
- }
- return result;
+ return <%=entityEnumName%>.getContractClasses();
}*/
);
+ // getImplementationClass method
+ op = addOperation(output, "getImplementationClass", "<T extends TopiaEntity> Class<T>", ObjectModelJavaModifier.PUBLIC, ObjectModelJavaModifier.STATIC);
+ addParameter(op, "Class<T>", "klass");
+ setOperationBody(op, ""
+/*{
+ return <%=entityEnumName%>.getImplementationClass(klass);
+ }*/
+ );
+
// getImplementationClasses method
op = addOperation(output, "getImplementationClasses", "Class<? extends TopiaEntity>[]", ObjectModelJavaModifier.PUBLIC, ObjectModelJavaModifier.STATIC);
setOperationBody(op, ""
/*{
- <%=entityEnumName%>[] values = <%=entityEnumName%>.values();
- Class<? extends TopiaEntity>[] result = (Class<? extends TopiaEntity>[]) Array.newInstance(Class.class, values.length);
- for (int i = 0; i < values.length; i++) {
- result[i] = values[i].getImplementation();
- }
- return result;
+ return <%=entityEnumName%>.getImplementationClasses();
}*/
);
- // getContracts method
- op = addOperation(output, "getContracts", entityEnumName + "[]", ObjectModelJavaModifier.PUBLIC, ObjectModelJavaModifier.STATIC);
+ // getImplementationClassesAsString method
+ op = addOperation(output, "getImplementationClassesAsString", "String", ObjectModelJavaModifier.PUBLIC, ObjectModelJavaModifier.STATIC);
setOperationBody(op, ""
/*{
- return <%=entityEnumName%>.values();
+ return <%=entityEnumName%>.getImplementationClassesAsString();
}*/
);
@@ -254,8 +245,7 @@
addParameter(op, "Class<T>", "klass");
setOperationBody(op, ""
/*{
- <%=entityEnumName%> constant = <%=entityEnumName%>.valueOf(klass);
- return EntityOperatorStore.getOperator(constant);
+ return <%=entityEnumName%>.getOperator(klass);
}*/
);
}
1
0
27 Nov '13
Author: athimel
Date: 2013-11-27 12:11:51 +0100 (Wed, 27 Nov 2013)
New Revision: 2897
Url: http://nuiton.org/projects/topia/repository/revisions/2897
Log:
Introduce TopiaHibernateSessionRegistry in order to make possible to get the PersistenceContext from Hibernate's events
(this will be reused for Topia's event firing)
Move some internal classes to o.n.t.persistence
Added:
trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/topiatest/CascadeSaveTest.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/HibernateProvider.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaHibernateSessionRegistry.java
Removed:
trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/topiatest/beangen/
trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/topiatest/persistence/
trunk/topia-persistence/src/main/java/org/nuiton/topia/HibernateProvider.java
Modified:
trunk/topia-junit/src/main/java/org/nuiton/topia/junit/AbstractDatabaseResource.java
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/framework/TopiaHibernateEventListener.java
trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/TopiaMigrationEngine.java
trunk/topia-templates/src/main/java/org/nuiton/topia/templates/ApplicationContextTransformer.java
trunk/topia-templates/src/main/java/org/nuiton/topia/templates/PersistenceContextTransformer.java
Added: trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/topiatest/CascadeSaveTest.java
===================================================================
--- trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/topiatest/CascadeSaveTest.java (rev 0)
+++ trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/topiatest/CascadeSaveTest.java 2013-11-27 11:11:51 UTC (rev 2897)
@@ -0,0 +1,64 @@
+package org.nuiton.topia.it.legacy.topiatest;
+
+/*
+ * #%L
+ * ToPIA :: IT
+ * $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.Rule;
+import org.junit.Test;
+import org.nuiton.topia.TopiaException;
+import org.nuiton.topia.it.legacy.TopiaDatabase;
+import org.nuiton.topia.it.legacy.TopiaTestTopiaPersistenceContext;
+
+/**
+ * @author Arnaud Thimel <thimel(a)codelutin.com>
+ */
+public class CascadeSaveTest {
+
+ @Rule
+ public final TopiaDatabase db = new TopiaDatabase();
+
+ /**
+ * The following test will fail if no topiaId is injected on cascade save. This will test code within this method :
+ * org.nuiton.topia.framework.TopiaHibernateEventListener#onSaveOrUpdate(org.hibernate.event.spi.SaveOrUpdateEvent)
+ *
+ * @throws TopiaException
+ */
+ @Test
+ public void testSaveCascade() {
+
+ TopiaTestTopiaPersistenceContext persistenceContext = db.beginTransaction();
+
+ CompanyTopiaDao companyDao = persistenceContext.getCompanyDao();
+ DepartmentTopiaDao departmentDao = persistenceContext.getDepartmentDao();
+ Company company = companyDao.newInstance();
+ company.setName("Toto corp.");
+ Department department = departmentDao.newInstance();
+ department.setName("Jokes");
+ company.addDepartment(department);
+
+ companyDao.create(company);
+
+ }
+
+}
Property changes on: trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/topiatest/CascadeSaveTest.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Modified: trunk/topia-junit/src/main/java/org/nuiton/topia/junit/AbstractDatabaseResource.java
===================================================================
--- trunk/topia-junit/src/main/java/org/nuiton/topia/junit/AbstractDatabaseResource.java 2013-11-27 07:38:49 UTC (rev 2896)
+++ trunk/topia-junit/src/main/java/org/nuiton/topia/junit/AbstractDatabaseResource.java 2013-11-27 11:11:51 UTC (rev 2897)
@@ -31,7 +31,7 @@
import org.junit.rules.TestWatcher;
import org.junit.runner.Description;
import org.nuiton.topia.AbstractTopiaApplicationContext;
-import org.nuiton.topia.HibernateProvider;
+import org.nuiton.topia.persistence.HibernateProvider;
import org.nuiton.topia.TopiaContextFactory;
import org.nuiton.topia.TopiaException;
import org.nuiton.topia.TopiaPersistenceContext;
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/AbstractTopiaApplicationContext.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/AbstractTopiaApplicationContext.java 2013-11-27 07:38:49 UTC (rev 2896)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/AbstractTopiaApplicationContext.java 2013-11-27 11:11:51 UTC (rev 2897)
@@ -44,7 +44,9 @@
import org.nuiton.topia.framework.TopiaService;
import org.nuiton.topia.framework.TopiaUtil;
import org.nuiton.topia.persistence.DefaultTopiaIdFactory;
+import org.nuiton.topia.persistence.HibernateProvider;
import org.nuiton.topia.persistence.TopiaEntity;
+import org.nuiton.topia.persistence.TopiaHibernateSessionRegistry;
import org.nuiton.topia.persistence.TopiaIdFactory;
import java.beans.PropertyChangeListener;
@@ -77,6 +79,8 @@
protected HibernateProvider hibernateProvider;
+ protected TopiaHibernateSessionRegistry sessionRegistry = new TopiaHibernateSessionRegistry();
+
protected boolean closed = false;
protected Set<TopiaPersistenceContext> persistenceContexts = Collections.newSetFromMap(
@@ -118,7 +122,7 @@
// TODO AThimel 25/11/13 I don't like it to be public, but necessary for services. Review it
public HibernateProvider getHibernateProvider() {
if (hibernateProvider == null) {
- hibernateProvider = new HibernateProvider(configuration, topiaServiceSupport);
+ hibernateProvider = new HibernateProvider(configuration, topiaServiceSupport, sessionRegistry);
}
return hibernateProvider;
}
@@ -158,6 +162,10 @@
return topiaIdFactory;
}
+ public TopiaHibernateSessionRegistry getSessionRegistry() {
+ return sessionRegistry;
+ }
+
@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-11-27 07:38:49 UTC (rev 2896)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/AbstractTopiaPersistenceContext.java 2013-11-27 11:11:51 UTC (rev 2897)
@@ -36,8 +36,10 @@
import org.hibernate.cfg.Configuration;
import org.nuiton.topia.framework.TopiaFiresSupport;
import org.nuiton.topia.persistence.AbstractTopiaDao;
+import org.nuiton.topia.persistence.HibernateProvider;
import org.nuiton.topia.persistence.TopiaDao;
import org.nuiton.topia.persistence.TopiaEntity;
+import org.nuiton.topia.persistence.TopiaHibernateSessionRegistry;
import org.nuiton.topia.persistence.TopiaIdFactory;
import java.lang.reflect.InvocationTargetException;
@@ -70,6 +72,11 @@
*/
protected TopiaIdFactory topiaIdFactory;
+ /**
+ * The shared instance of TopiaHibernateSessionRegistry
+ */
+ protected TopiaHibernateSessionRegistry sessionRegistry;
+
// TODO AThimel 27/09/13 Javadoc
protected TopiaFiresSupport firesSupport;
@@ -105,10 +112,12 @@
*/
public AbstractTopiaPersistenceContext(HibernateProvider hibernateProvider,
TopiaListenableSupport listenableSupport,
- TopiaIdFactory topiaIdFactory) {
+ TopiaIdFactory topiaIdFactory,
+ TopiaHibernateSessionRegistry sessionRegistry) {
this.listenableSupport = listenableSupport;
this.topiaIdFactory = topiaIdFactory;
+ this.sessionRegistry = sessionRegistry;
this.firesSupport = new TopiaFiresSupport();
// Hibernate support can be created using the given hibernateProvider
@@ -170,6 +179,8 @@
// tchemit 2010-12-06 propagates the value of the flag
// result.useFlushMode = useFlushMode;
+ sessionRegistry.register(result, this);
+
// 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
@@ -183,6 +194,7 @@
// et declancher une exception
try {
result.close();
+ sessionRegistry.unregister(result);
} catch (HibernateException e1) {
if (log.isErrorEnabled()) {
log.error("Could not close hibernate session", e1);
@@ -314,9 +326,9 @@
Session hibernateSession = hibernateSupport.getHibernateSession();
- Transaction tx = hibernateSession.getTransaction();
+ Transaction transaction = hibernateSession.getTransaction();
hibernateSession.flush();
- tx.commit();
+ transaction.commit();
getFiresSupport().fireOnPostCommit(this);
// TopiaContextImplementor parent = getParentContext();
@@ -343,17 +355,21 @@
try {
Session hibernateSession = hibernateSupport.getHibernateSession();
- Transaction tx = hibernateSession.getTransaction();
+ Transaction transaction = hibernateSession.getTransaction();
hibernateSession.clear();
- tx.rollback();
+ transaction.rollback();
hibernateSession.close();
+ sessionRegistry.unregister(hibernateSession);
+
// 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);
+ sessionRegistry.register(hibernateSession, this);
+
hibernateSession.beginTransaction();
getFiresSupport().fireOnPostRollback(this);
@@ -374,7 +390,10 @@
closed = true;
// Now close the current Hibernate session
- hibernateSupport.getHibernateSession().close();
+ Session hibernateSession = hibernateSupport.getHibernateSession();
+ hibernateSession.close();
+
+ sessionRegistry.unregister(hibernateSession);
}
@Override
Deleted: trunk/topia-persistence/src/main/java/org/nuiton/topia/HibernateProvider.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/HibernateProvider.java 2013-11-27 07:38:49 UTC (rev 2896)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/HibernateProvider.java 2013-11-27 11:11:51 UTC (rev 2897)
@@ -1,241 +0,0 @@
-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.Map;
-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.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;
-
-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 Map<String, String> configuration;
- protected TopiaServiceSupport topiaServiceSupport;
-
- /**
- * List of persistent classes
- */
- 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);
- }
-
- protected String getProperty(String key, String defaultValue) {
- String result = defaultValue;
- if (configuration.containsKey(key)) {
- result = configuration.get(key);
- }
-
- return result;
- }
-
- public List<Class<?>> getPersistentClasses() {
- if (persistentClasses.isEmpty()) {
- // Force configuration load
- getHibernateConfiguration();
- }
- return persistentClasses;
- }
-
- 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 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) {
-
- // 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);
- 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);
- 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;
- }
-
-}
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaHibernateEventListener.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaHibernateEventListener.java 2013-11-27 07:38:49 UTC (rev 2896)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaHibernateEventListener.java 2013-11-27 11:11:51 UTC (rev 2897)
@@ -28,7 +28,8 @@
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.AbstractEvent;
+import org.hibernate.event.spi.EventSource;
import org.hibernate.event.spi.PostDeleteEvent;
import org.hibernate.event.spi.PostDeleteEventListener;
import org.hibernate.event.spi.PostInsertEvent;
@@ -47,14 +48,15 @@
import org.hibernate.event.spi.PreUpdateEventListener;
import org.hibernate.event.spi.SaveOrUpdateEvent;
import org.hibernate.event.spi.SaveOrUpdateEventListener;
-import org.nuiton.topia.AbstractTopiaApplicationContext;
import org.nuiton.topia.TopiaDaoSupplier;
import org.nuiton.topia.TopiaException;
+import org.nuiton.topia.persistence.TopiaHibernateSessionRegistry;
import org.nuiton.topia.TopiaPersistenceContext;
-import org.nuiton.topia.persistence.AbstractTopiaDao;
import org.nuiton.topia.persistence.TopiaEntity;
import org.nuiton.topia.persistence.TopiaEntityContextable;
+import com.google.common.base.Preconditions;
+
/**
* @author Arnaud Thimel <thimel(a)codelutin.com>
*/
@@ -66,55 +68,22 @@
private static final long serialVersionUID = -9206039888626756924L;
- protected AbstractTopiaApplicationContext rootContext;
+ protected TopiaHibernateSessionRegistry registry;
- public TopiaHibernateEventListener(AbstractTopiaApplicationContext rootContext) {
- this.rootContext = rootContext;
+ public TopiaHibernateEventListener(TopiaHibernateSessionRegistry registry) {
+ Preconditions.checkArgument(registry != null);
+ this.registry = registry;
}
/**
- * Recherche le context utilisant la session hibernate passe en
- * parametre
+ * Look for the TopiaPersistenceContext based on the given Hibernate session
*
- * @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.
+ * @param event the Hibernate event that contains the Session to use
+ * @return the TopiaPersistenceContext using this Session, or null if not found
*/
- protected TopiaPersistenceContext getContext(
- AbstractTopiaApplicationContext parent, Session hibernate) {
- TopiaPersistenceContext result = null;
- // FIXME AThimel 23/11/13 Find a way to implement it
-
-// // 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 (TopiaPersistenceContext 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);
-// }
-// }
-// }
-// }
+ protected TopiaPersistenceContext getContext(AbstractEvent event) {
+ EventSource session = event.getSession();
+ TopiaPersistenceContext result = registry.getPersistenceContext(session);
return result;
}
@@ -140,10 +109,10 @@
@Override
public boolean onPreInsert(PreInsertEvent event) {
- TopiaPersistenceContext context = getContext(rootContext, event.getSession());
+ TopiaPersistenceContext context = getContext(event);
if (context != null && event.getEntity() instanceof TopiaEntity) {
TopiaEntity entity = (TopiaEntity) event.getEntity();
-
+
context.getTopiaFiresSupport().fireOnPreCreate(context, entity, event.getState());
// when using composition, hibernate will persist entities by him self
@@ -160,7 +129,7 @@
@Override
public void onPostInsert(PostInsertEvent event) {
- TopiaPersistenceContext context = getContext(rootContext, event.getSession());
+ TopiaPersistenceContext context = getContext(event);
if (context != null && event.getEntity() instanceof TopiaEntity) {
context.getTopiaFiresSupport().fireOnPostCreate(context, (TopiaEntity) event.getEntity(), event.getState());
}
@@ -170,7 +139,7 @@
@Override
public void onPreLoad(PreLoadEvent event) {
- TopiaPersistenceContext context = getContext(rootContext, event.getSession());
+ TopiaPersistenceContext context = getContext(event);
if (context != null && event.getEntity() instanceof TopiaEntity) {
// try {
context.getTopiaFiresSupport().fireOnPreLoad(context, (TopiaEntity) event.getEntity(), event.getState());
@@ -184,7 +153,7 @@
@Override
public void onPostLoad(PostLoadEvent event) {
- TopiaPersistenceContext context = getContext(rootContext, event.getSession());
+ TopiaPersistenceContext context = getContext(event);
if (context != null && event.getEntity() instanceof TopiaEntity) {
attachContext(event.getEntity(), context);
TopiaEntity entity = (TopiaEntity) event.getEntity();
@@ -196,7 +165,7 @@
@Override
public boolean onPreUpdate(PreUpdateEvent event) {
- TopiaPersistenceContext context = getContext(rootContext, event.getSession());
+ TopiaPersistenceContext context = getContext(event);
if (context != null && event.getEntity() instanceof TopiaEntity) {
context.getTopiaFiresSupport().fireOnPreUpdate(context, (TopiaEntity) event.getEntity(), event.getOldState());
}
@@ -205,7 +174,7 @@
@Override
public void onPostUpdate(PostUpdateEvent event) {
- TopiaPersistenceContext context = getContext(rootContext, event.getSession());
+ TopiaPersistenceContext context = getContext(event);
if (context != null && event.getEntity() instanceof TopiaEntity) {
context.getTopiaFiresSupport().fireOnPostUpdate(context, (TopiaEntity) event.getEntity(), event.getState());
}
@@ -219,7 +188,7 @@
@Override
public boolean onPreDelete(PreDeleteEvent event) {
- TopiaPersistenceContext context = getContext(rootContext, event.getSession());
+ TopiaPersistenceContext context = getContext(event);
if (context != null && event.getEntity() instanceof TopiaEntity) {
context.getTopiaFiresSupport().fireOnPreDelete(context, (TopiaEntity) event.getEntity(), event.getDeletedState());
}
@@ -228,7 +197,7 @@
@Override
public void onPostDelete(PostDeleteEvent event) {
- TopiaPersistenceContext context = getContext(rootContext, event.getSession());
+ TopiaPersistenceContext context = getContext(event);
if (context != null && event.getEntity() instanceof TopiaEntity) {
context.getTopiaFiresSupport().fireOnPostDelete(context, (TopiaEntity) event.getEntity(), event.getDeletedState());
}
@@ -241,12 +210,13 @@
@Override
public void onSaveOrUpdate(SaveOrUpdateEvent event) throws HibernateException {
try {
- // this event is called when hibernate try to persist entities
- // using cascade (save)
- TopiaPersistenceContext context = getContext(rootContext, event.getSession());
+ // this event is called when hibernate try to persist entities using cascade (save)
+ TopiaPersistenceContext context = getContext(event);
// 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());
Copied: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/HibernateProvider.java (from rev 2895, trunk/topia-persistence/src/main/java/org/nuiton/topia/HibernateProvider.java)
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/HibernateProvider.java (rev 0)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/HibernateProvider.java 2013-11-27 11:11:51 UTC (rev 2897)
@@ -0,0 +1,248 @@
+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 java.io.File;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+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.hibernate.service.jdbc.connections.spi.ConnectionProvider;
+import org.hibernate.service.spi.Stoppable;
+import org.nuiton.topia.TopiaContextFactory;
+import org.nuiton.topia.TopiaNotFoundException;
+import org.nuiton.topia.TopiaServiceSupport;
+import org.nuiton.topia.framework.TopiaHibernateEventListener;
+import org.nuiton.topia.framework.TopiaService;
+import org.nuiton.topia.framework.TopiaUtil;
+
+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 Map<String, String> configuration;
+ protected TopiaServiceSupport topiaServiceSupport;
+ protected TopiaHibernateSessionRegistry sessionRegistry;
+
+ /**
+ * List of persistent classes
+ */
+ protected List<Class<?>> persistentClasses = Lists.newArrayList();
+
+ public HibernateProvider(Map<String, String> configuration,
+ TopiaServiceSupport topiaServiceSupport,
+ TopiaHibernateSessionRegistry sessionRegistry) {
+ this.configuration = configuration;
+ this.topiaServiceSupport = topiaServiceSupport;
+ this.sessionRegistry = sessionRegistry;
+ }
+
+ 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 List<Class<?>> getPersistentClasses() {
+ if (persistentClasses.isEmpty()) {
+ // Force configuration load
+ getHibernateConfiguration();
+ }
+ return persistentClasses;
+ }
+
+ 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 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) {
+
+ // 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);
+
+ TopiaHibernateEventListener listener = new TopiaHibernateEventListener(sessionRegistry);
+ 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;
+ }
+
+}
Added: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaHibernateSessionRegistry.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaHibernateSessionRegistry.java (rev 0)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaHibernateSessionRegistry.java 2013-11-27 11:11:51 UTC (rev 2897)
@@ -0,0 +1,95 @@
+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 java.lang.ref.WeakReference;
+import java.util.WeakHashMap;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.hibernate.Session;
+import org.nuiton.topia.TopiaPersistenceContext;
+
+import com.google.common.base.Preconditions;
+
+/**
+ * Class used to keep an association between an Hibernate Session and a TopiaPersistenceContext
+ *
+ * @author Arnaud Thimel <thimel(a)codelutin.com>
+ * @since 3.0
+ */
+public class TopiaHibernateSessionRegistry {
+
+ private static final Log log = LogFactory.getLog(TopiaHibernateSessionRegistry.class);
+
+ protected WeakHashMap<Session, WeakReference<TopiaPersistenceContext>> registry =
+ new WeakHashMap<Session, WeakReference<TopiaPersistenceContext>>();
+
+ /**
+ * Register the Session<->TopiaPersistenceContext couple
+ *
+ * @param session the currently used Session
+ * @param persistenceContext the current TopiaPersistenceContext using this Session
+ */
+ public void register(Session session, TopiaPersistenceContext persistenceContext) {
+ if (log.isDebugEnabled()) {
+ log.debug("New Session<->TopiaPersistenceContext registration");
+ }
+ Preconditions.checkArgument(session != null);
+ Preconditions.checkArgument(persistenceContext != null);
+ WeakReference<TopiaPersistenceContext> reference = new WeakReference<TopiaPersistenceContext>(persistenceContext);
+ registry.put(session, reference);
+ }
+
+ /**
+ * Look for the TopiaPersistenceContext based on the given Hibernate session
+ *
+ * @param session the Hibernate Session to use
+ * @return the TopiaPersistenceContext using this Session, or null if not found
+ */
+ public TopiaPersistenceContext getPersistenceContext(Session session) {
+ Preconditions.checkArgument(session != null);
+ WeakReference<TopiaPersistenceContext> reference = registry.get(session);
+ TopiaPersistenceContext result = reference.get();
+ if (log.isDebugEnabled()) {
+ log.debug("Get TopiaPersistenceContext from Session : " + (result == null ? "Not found" : "HIT !"));
+ }
+ return result;
+ }
+
+ /**
+ * Removes the Session<->TopiaPersistenceContext association from the registry
+ *
+ * @param session the Hibernate Session to remove
+ */
+ public void unregister(Session session) {
+ Preconditions.checkArgument(session != null);
+ WeakReference<TopiaPersistenceContext> reference = registry.remove(session);
+ if (log.isDebugEnabled()) {
+ log.debug("Remove TopiaPersistenceContext from Session : " + (reference != null));
+ }
+ }
+
+}
Property changes on: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaHibernateSessionRegistry.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
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-11-27 07:38:49 UTC (rev 2896)
+++ trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/TopiaMigrationEngine.java 2013-11-27 11:11:51 UTC (rev 2897)
@@ -34,7 +34,7 @@
import org.hibernate.cfg.Configuration;
import org.nuiton.topia.AbstractTopiaApplicationContext;
import org.nuiton.topia.AbstractTopiaPersistenceContext;
-import org.nuiton.topia.HibernateProvider;
+import org.nuiton.topia.persistence.HibernateProvider;
import org.nuiton.topia.TopiaException;
import org.nuiton.topia.TopiaHibernateSupport;
import org.nuiton.topia.TopiaNotFoundException;
Modified: trunk/topia-templates/src/main/java/org/nuiton/topia/templates/ApplicationContextTransformer.java
===================================================================
--- trunk/topia-templates/src/main/java/org/nuiton/topia/templates/ApplicationContextTransformer.java 2013-11-27 07:38:49 UTC (rev 2896)
+++ trunk/topia-templates/src/main/java/org/nuiton/topia/templates/ApplicationContextTransformer.java 2013-11-27 11:11:51 UTC (rev 2897)
@@ -167,7 +167,7 @@
setOperationBody(op, ""
/*{
<%=persistenceContextConcreteName%> newContext = new <%=persistenceContextConcreteName%>(
- getHibernateProvider(), getTopiaListenableSupport(), getTopiaIdFactory());
+ getHibernateProvider(), getTopiaListenableSupport(), getTopiaIdFactory(), getSessionRegistry());
registerPersistenceContext(newContext);
return newContext;
}*/
Modified: trunk/topia-templates/src/main/java/org/nuiton/topia/templates/PersistenceContextTransformer.java
===================================================================
--- trunk/topia-templates/src/main/java/org/nuiton/topia/templates/PersistenceContextTransformer.java 2013-11-27 07:38:49 UTC (rev 2896)
+++ trunk/topia-templates/src/main/java/org/nuiton/topia/templates/PersistenceContextTransformer.java 2013-11-27 11:11:51 UTC (rev 2897)
@@ -34,7 +34,8 @@
import org.nuiton.eugene.models.object.ObjectModelJavaModifier;
import org.nuiton.eugene.models.object.ObjectModelOperation;
import org.nuiton.topia.AbstractTopiaPersistenceContext;
-import org.nuiton.topia.HibernateProvider;
+import org.nuiton.topia.persistence.HibernateProvider;
+import org.nuiton.topia.persistence.TopiaHibernateSessionRegistry;
import org.nuiton.topia.TopiaListenableSupport;
import org.nuiton.topia.persistence.TopiaEntity;
import org.nuiton.topia.persistence.TopiaIdFactory;
@@ -148,9 +149,10 @@
addParameter(constructor, HibernateProvider.class, "hibernateProvider");
addParameter(constructor, TopiaListenableSupport.class, "listenableSupport");
addParameter(constructor, TopiaIdFactory.class, "topiaIdFactory");
+ addParameter(constructor, TopiaHibernateSessionRegistry.class, "sessionRegistry");
setOperationBody(constructor, ""
/*{
- super(hibernateProvider, listenableSupport, topiaIdFactory);
+ super(hibernateProvider, listenableSupport, topiaIdFactory, sessionRegistry);
}*/
);
@@ -274,9 +276,10 @@
addParameter(constructor, HibernateProvider.class, "hibernateProvider");
addParameter(constructor, TopiaListenableSupport.class, "listenableSupport");
addParameter(constructor, TopiaIdFactory.class, "topiaIdFactory");
+ addParameter(constructor, TopiaHibernateSessionRegistry.class, "sessionRegistry");
setOperationBody(constructor, ""
/*{
- super(hibernateProvider, listenableSupport, topiaIdFactory);
+ super(hibernateProvider, listenableSupport, topiaIdFactory, sessionRegistry);
}*/
);
1
0
r2896 - in trunk: topia-it/src/test/java/org/nuiton/topia/it/legacy topia-persistence/src/main/java/org/nuiton/topia
by athimel@users.nuiton.org 27 Nov '13
by athimel@users.nuiton.org 27 Nov '13
27 Nov '13
Author: athimel
Date: 2013-11-27 08:38:49 +0100 (Wed, 27 Nov 2013)
New Revision: 2896
Url: http://nuiton.org/projects/topia/repository/revisions/2896
Log:
refs #2923 Remove deprecated code from TopiaJpaSupport
Modified:
trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/TopiaJpaSupportTest.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/HibernateTopiaJpaSupport.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaJpaSupport.java
Modified: trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/TopiaJpaSupportTest.java
===================================================================
--- trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/TopiaJpaSupportTest.java 2013-11-26 17:19:25 UTC (rev 2895)
+++ trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/TopiaJpaSupportTest.java 2013-11-27 07:38:49 UTC (rev 2896)
@@ -40,7 +40,10 @@
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.util.List;
+import java.util.Map;
+import com.google.common.collect.Maps;
+
/**
* Tests the TopiaContext#find|findAll|findUnique methods
*
@@ -105,17 +108,24 @@
String query = "from " + Personne.class.getName() +
" where " + Personne.PROPERTY_GENDER + "=:g";
- List females = jpaSupport.findAll(query, "g", Gender.FEMALE);
+ Map<String, Object> args = Maps.newHashMap();
+ args.put("g", Gender.FEMALE);
+ List females = jpaSupport.findAll(query, args);
Assert.assertEquals(2, females.size());
- List males = jpaSupport.findAll(query, "g", Gender.MALE);
+ args = Maps.newHashMap();
+ args.put("g", Gender.MALE);
+ List males = jpaSupport.findAll(query, args);
Assert.assertEquals(1, males.size());
- List all = jpaSupport.findAll("from " + Personne.class.getName());
+ args = Maps.newHashMap();
+ List all = jpaSupport.findAll("from " + Personne.class.getName(), args);
Assert.assertEquals(3, all.size());
+ args = Maps.newHashMap();
+ args.put("pax", "nobody");
List none = jpaSupport.findAll("from " + Personne.class.getName() +
- " where " + Personne.PROPERTY_NAME + "=:pax", "pax", "nobody");
+ " where " + Personne.PROPERTY_NAME + "=:pax", args);
Assert.assertEquals(0, none.size());
}
@@ -126,14 +136,17 @@
String query = "from " + Personne.class.getName() +
" where " + Personne.PROPERTY_GENDER + "=:g";
- List females = jpaSupport.find(query, 0, 100, "g", Gender.FEMALE);
+
+ Map<String, Object> args = Maps.newHashMap();
+ args.put("g", Gender.FEMALE);
+ List females = jpaSupport.find(query, 0, 100, args);
Assert.assertEquals(2, females.size());
- females = jpaSupport.find(query, 0, 0, "g", Gender.FEMALE);
+ females = jpaSupport.find(query, 0, 0, args);
Assert.assertEquals(1, females.size());
Personne charlotte = (Personne) females.get(0);
- females = jpaSupport.find(query, 1, 1, "g", Gender.FEMALE);
+ females = jpaSupport.find(query, 1, 1, args);
Assert.assertEquals(1, females.size());
Personne hortense = (Personne) females.get(0);
@@ -151,11 +164,15 @@
String query = "from " + Personne.class.getName() +
" where " + Personne.PROPERTY_GENDER + "=:g";
- Object male = jpaSupport.findUnique(query, "g", Gender.MALE);
+ Map<String, Object> args = Maps.newHashMap();
+ args.put("g", Gender.MALE);
+ Object male = jpaSupport.findUnique(query, args);
Assert.assertNotNull(male);
+ args = Maps.newHashMap();
+ args.put("pax", "nobody");
Object none = jpaSupport.findUnique("from " + Personne.class.getName() +
- " where " + Personne.PROPERTY_NAME + "=:pax", "pax", "nobody");
+ " where " + Personne.PROPERTY_NAME + "=:pax", args);
Assert.assertNull(none);
}
@@ -166,7 +183,9 @@
String query = "from " + Personne.class.getName() +
" where " + Personne.PROPERTY_GENDER + "=:g";
- Object female = jpaSupport.findUnique(query, "g", Gender.FEMALE);
+ Map<String, Object> args = Maps.newHashMap();
+ args.put("g", Gender.FEMALE);
+ Object female = jpaSupport.findUnique(query, args);
Assert.assertNotNull(female);
}
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/HibernateTopiaJpaSupport.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/HibernateTopiaJpaSupport.java 2013-11-26 17:19:25 UTC (rev 2895)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/HibernateTopiaJpaSupport.java 2013-11-27 07:38:49 UTC (rev 2896)
@@ -180,32 +180,4 @@
}
}
- @Override
- public <T> List<T> findAll(String jpaql, Object... propertyNamesAndValues) {
- Map<String, Object> parameters = TopiaUtil.convertPropertiesArrayToMap(propertyNamesAndValues);
- List<T> result = findAll(jpaql, parameters);
- return result;
- }
-
- @Override
- public <T> List<T> find(String jpaql, int startIndex, int endIndex, Object... propertyNamesAndValues) {
- Map<String, Object> parameters = TopiaUtil.convertPropertiesArrayToMap(propertyNamesAndValues);
- List<T> result = find(jpaql, startIndex, endIndex, parameters);
- return result;
- }
-
- @Override
- public <T> T findUnique(String jpaql, Object... propertyNamesAndValues) {
- Map<String, Object> parameters = TopiaUtil.convertPropertiesArrayToMap(propertyNamesAndValues);
- T result = findUnique(jpaql, parameters);
- return result;
- }
-
- @Override
- public int execute(String jpaql, Object... propertyNamesAndValues) {
- Map<String, Object> parameters = TopiaUtil.convertPropertiesArrayToMap(propertyNamesAndValues);
- int result = execute(jpaql, parameters);
- return result;
- }
-
} // HibernateTopiaJpaSupport
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaJpaSupport.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaJpaSupport.java 2013-11-26 17:19:25 UTC (rev 2895)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaJpaSupport.java 2013-11-27 07:38:49 UTC (rev 2896)
@@ -50,22 +50,6 @@
Map<String, Object> parameters);
/**
- * Allow to do some JPA-QL query
- * <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 list
- * @deprecated prefer using {@link #findAll(String, java.util.Map)}
- */
- @Deprecated
- <T> List<T> findAll(String jpaql,
- Object... propertyNamesAndValues);
-
- /**
* Allow to do some JPA-QL query using the given bounds.
* <p/>
* No lower bound : <code>startIndex</code> = 0.<br/>
@@ -74,9 +58,9 @@
* WARNING : Depending on the registered service, this method may not
* support something else than queries on TopiaEntity
*
- * @param jpaql the JPA-QL query
- * @param startIndex first index of entity to return
- * @param endIndex last index of entity to return
+ * @param jpaql the JPA-QL query
+ * @param startIndex first index of entity to return
+ * @param endIndex last index of entity to return
* @param parameters a map which keys are the attribute names and values are the attributes expected values
* @return The result list
*/
@@ -86,29 +70,6 @@
Map<String, Object> parameters);
/**
- * Allow to do some JPA-QL query using the given bounds.
- * <p/>
- * No lower bound : <code>startIndex</code> = 0.<br/>
- * No upper bound : <code>endIndex</code> = -1.
- * <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 startIndex first index of entity to return
- * @param endIndex last index of entity to return
- * @param propertyNamesAndValues the query parameters. Arguments are key-value paired :
- * [propertyName;value;propertyName;value;...]
- * @return The result list
- * @deprecated prefer using {@link #find(String, int, int, java.util.Map)}
- */
- @Deprecated
- <T> List<T> find(String jpaql,
- int startIndex,
- int endIndex,
- Object... propertyNamesAndValues);
-
- /**
* 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.
@@ -116,7 +77,7 @@
* WARNING : Depending on the registered service, this method may not
* support something else than queries on TopiaEntity
*
- * @param jpaql the JPA-QL query
+ * @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
*/
@@ -124,27 +85,9 @@
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 #findUnique(String, java.util.Map)}
- */
- @Deprecated
- <T> T findUnique(String jpaql,
- Object... propertyNamesAndValues);
-
- /**
* Execute JPA-QL operation on data (Update, Delete).
*
- * @param jpaql the JPA-QL query
+ * @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 number of entities updated or deleted.
*/
@@ -152,19 +95,6 @@
Map<String, Object> parameters);
/**
- * Execute JPA-QL operation on data (Update, Delete).
- *
- * @param jpaql the JPA-QL query
- * @param propertyNamesAndValues the query parameters. Arguments are key-value paired :
- * [propertyName;value;propertyName;value;...]
- * @return The number of entities updated or deleted.
- * @deprecated prefer using {@link #execute(String, java.util.Map)}
- */
- @Deprecated
- int execute(String jpaql,
- Object... propertyNamesAndValues);
-
- /**
* Tells to the context if it has to use a flush mode before each query.
* <p/>
* By default, we use a flush mode, but in some case it costs to much doing
1
0
r2895 - in trunk: src/site/rst topia-persistence/src/main/java/org/nuiton/topia topia-persistence/src/main/java/org/nuiton/topia/persistence
by athimel@users.nuiton.org 26 Nov '13
by athimel@users.nuiton.org 26 Nov '13
26 Nov '13
Author: athimel
Date: 2013-11-26 18:19:25 +0100 (Tue, 26 Nov 2013)
New Revision: 2895
Url: http://nuiton.org/projects/topia/repository/revisions/2895
Log:
refs #2923 TopiaContextFactory is adapted
refs #299 Documentation on migration
Modified:
trunk/src/site/rst/migrate_to_3.0.rst
trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaContextFactory.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/AbstractTopiaDao.java
Modified: trunk/src/site/rst/migrate_to_3.0.rst
===================================================================
--- trunk/src/site/rst/migrate_to_3.0.rst 2013-11-26 15:51:34 UTC (rev 2894)
+++ trunk/src/site/rst/migrate_to_3.0.rst 2013-11-26 17:19:25 UTC (rev 2895)
@@ -40,10 +40,32 @@
* Hibernate >= 4.2.1.Final
+Configuration du plugin Maven
+=============================
+
+|MANDATORY|
+
+Les templates sont contenus dans un modules à part, il faut désormais utiliser
+cette dépendance dans le plugin eugene.
+
+::
+
+ <dependency>
+ <groupId>org.nuiton.topia</groupId>
+ <artifactId>topia-templates</artifactId>
+ <version>3.0</version>
+ </dependency>
+
+De plus les templates ont changé de package, le nouveau package est le suivant :
+
+::
+
+ org.nuiton.topia.templates
+
+
Code déprécié
=============
-
La migration vers ToPIA 3.0 voit un certain nombre de classes et attributs dépréciés.
Gérer les impacts n'est pas *nécessaire* pour passer à ToPIA 3.0, mais c'est fortement recommandé. En effet, ce code
@@ -144,7 +166,7 @@
|RECOMMENDED|
Si vous utilisiez explicitement le Transformer de DAO dans la configuration de votre plugin Eugene, il faut maintenant
-changer le nouveau Transformer : org.nuiton.topia.generator.EntityDaoTransformer
+changer le nouveau Transformer : org.nuiton.topia.templates.EntityDaoTransformer
Exemple de configuration :
@@ -161,7 +183,7 @@
<inputs>classpath:model:/:myProject.objectmodel</inputs>
<defaultPackage>org.project.entities</defaultPackage>
<templates>
- org.nuiton.topia.generator.EntityDaoTransformer
+ org.nuiton.topia.templates.EntityDaoTransformer
</templates>
</configuration>
<goals>
@@ -220,26 +242,6 @@
méthodes les remplacer. S'il n'y pas de documentation, il faut remplacer le code appellant par le corps de la méthode dépréciée
(fonctionnalité « inline » dans l'IDE).
-Utilisation des templates de générations
-----------------------------------------
-
-Les templates sont contenues dans un modules à part, il faut désormais utiliser
-cette dépendance dans le plugin eugene.
-
-::
-
- <dependency>
- <groupId>org.nuiton.topia</groupId>
- <artifactId>topia-templates</artifactId>
- <version>3.0</version>
- </dependency>
-
-De plus les templates ont changé de paquetage, le nouveau paquetage est le suivant :
-
-::
-
- org.nuiton.topia.templates
-
Amélioration du code sql
------------------------
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaContextFactory.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaContextFactory.java 2013-11-26 15:51:34 UTC (rev 2894)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaContextFactory.java 2013-11-26 17:19:25 UTC (rev 2895)
@@ -182,8 +182,8 @@
* @return Un TopiaContext ouvert
* @throws TopiaNotFoundException if any pb
*/
- public static AbstractTopiaApplicationContext getContext(
- Properties config, Function<Properties, AbstractTopiaApplicationContext> createContextFunction)
+ public static <C extends AbstractTopiaApplicationContext> C getContext(
+ Properties config, Function<Properties, C> createContextFunction)
throws TopiaNotFoundException {
// Put all properties from a hierarchy in the current properties object.
// Resolve problem with hibernate which used iterator to get properties
@@ -193,7 +193,7 @@
for (String key : config.stringPropertyNames()) {
cloned.setProperty(key, config.getProperty(key));
}
- AbstractTopiaApplicationContext result = contextCache.get(cloned);
+ C result = (C)contextCache.get(cloned);
if (result == null || result.isClosed()) {
if (createContextFunction == null) {
throw new TopiaException("Function<Properties, AbstractTopiaApplicationContext> is needed to create context");
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/AbstractTopiaDao.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/AbstractTopiaDao.java 2013-11-26 15:51:34 UTC (rev 2894)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/AbstractTopiaDao.java 2013-11-26 17:19:25 UTC (rev 2895)
@@ -475,7 +475,7 @@
}
protected <R> R findUniqueOrNull(String hql, Map<String, Object> hqlParameters, Class<R> type) throws TopiaNonUniqueResultException {
- List<R> results = findAll(hql, hqlParameters, type, 0, 1);
+ List<R> results = find(hql, hqlParameters, type, 0, 1);
// If there is more than 1 result, throw an exception
if (results.size() > 1) {
throw new TopiaNonUniqueResultException(hql, hqlParameters);
@@ -524,7 +524,7 @@
protected <R> R findAnyOrNull(String hql, Map<String, Object> hqlParameters, Class<R> type) {
Preconditions.checkNotNull(hql);
Preconditions.checkNotNull(hqlParameters);
- List<R> results = findAll(hql, hqlParameters, type, 0, 0);
+ List<R> results = find(hql, hqlParameters, type, 0, 0);
R result = Iterables.getOnlyElement(results, null);
return result;
}
@@ -536,15 +536,15 @@
return result;
}
- protected List<E> findAll(String hql, Map<String, Object> hqlParameters, int startIndex, int endIndex) {
+ protected List<E> find(String hql, Map<String, Object> hqlParameters, int startIndex, int endIndex) {
Preconditions.checkNotNull(hql);
Preconditions.checkNotNull(hqlParameters);
List<E> result = topiaJpaSupport.find(hql, startIndex, endIndex, hqlParameters);
return result;
}
- protected List<E> findAll(String hql, Map<String, Object> hqlParameters, TopiaPagerBean pager) {
- List<E> result = findAll(hql, hqlParameters, getEntityClass(), pager);
+ protected List<E> find(String hql, Map<String, Object> hqlParameters, TopiaPagerBean pager) {
+ List<E> result = find(hql, hqlParameters, getEntityClass(), pager);
return result;
}
@@ -556,7 +556,7 @@
return result;
}
- protected <R> List<R> findAll(String hql, Map<String, Object> hqlParameters, Class<R> type, int startIndex, int endIndex) {
+ protected <R> List<R> find(String hql, Map<String, Object> hqlParameters, Class<R> type, int startIndex, int endIndex) {
Preconditions.checkNotNull(hql);
Preconditions.checkNotNull(hqlParameters);
Preconditions.checkNotNull(type);
@@ -564,7 +564,7 @@
return result;
}
- protected <R> List<R> findAll(String hql, Map<String, Object> hqlParameters, Class<R> type, TopiaPagerBean pager) {
+ protected <R> List<R> find(String hql, Map<String, Object> hqlParameters, Class<R> type, TopiaPagerBean pager) {
Preconditions.checkNotNull(hql);
Preconditions.checkNotNull(hqlParameters);
Preconditions.checkNotNull(type);
@@ -753,7 +753,7 @@
PagerBeanUtil.computeRecordIndexesAndPagesNumber(pager);
// load new window of data
- data = dao.findAll(hql, params, type, pager).iterator();
+ data = dao.find(hql, params, type, pager).iterator();
}
@@ -1027,7 +1027,7 @@
@Override
public List<E> find(int startIndex, int endIndex) {
- return topiaDAO.findAll(hql, hqlParameters, startIndex, endIndex);
+ return topiaDAO.find(hql, hqlParameters, startIndex, endIndex);
}
@Override
@@ -1041,7 +1041,7 @@
public List<String> findIds(int startIndex, int endIndex) {
// XXX brendan 30/09/13 does this truely work ?
String hqlWithSelectClause = "select topiaId " + hql;
- return topiaDAO.findAll(hqlWithSelectClause, hqlParameters, String.class, startIndex, endIndex);
+ return topiaDAO.find(hqlWithSelectClause, hqlParameters, String.class, startIndex, endIndex);
}
}
1
0