Topia-commits
Threads by month
- ----- 2026 -----
- June
- May
- April
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2006 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2005 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2004 -----
- December
- November
- October
- September
- August
- July
- June
- May
May 2010
- 4 participants
- 68 discussions
r1955 - in trunk/topia-persistence/src: main/java/org/nuiton/topia/framework test/java/org/nuiton/topia/framework test/java/org/nuiton/topiatest test/java/org/nuiton/topiatest/persistence
by fdesbois@users.nuiton.org 12 May '10
by fdesbois@users.nuiton.org 12 May '10
12 May '10
Author: fdesbois
Date: 2010-05-12 11:38:43 +0200 (Wed, 12 May 2010)
New Revision: 1955
Url: http://nuiton.org/repositories/revision/topia/1955
Log:
Add tests for TopiaContextImpl (problem testing with maven, but idea works)
Added:
trunk/topia-persistence/src/test/java/org/nuiton/topiatest/persistence/
trunk/topia-persistence/src/test/java/org/nuiton/topiatest/persistence/Entity1.java
trunk/topia-persistence/src/test/java/org/nuiton/topiatest/persistence/Entity1Abstract.java
trunk/topia-persistence/src/test/java/org/nuiton/topiatest/persistence/Entity1Impl.hbm.xml
trunk/topia-persistence/src/test/java/org/nuiton/topiatest/persistence/Entity1Impl.java
trunk/topia-persistence/src/test/java/org/nuiton/topiatest/persistence/package-info.java
Modified:
trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaContextImpl.java
trunk/topia-persistence/src/test/java/org/nuiton/topia/framework/TopiaContextImplTest.java
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaContextImpl.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaContextImpl.java 2010-05-11 12:09:48 UTC (rev 1954)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaContextImpl.java 2010-05-12 09:38:43 UTC (rev 1955)
@@ -25,6 +25,7 @@
package org.nuiton.topia.framework;
+import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.dom4j.Document;
@@ -456,7 +457,6 @@
/* (non-Javadoc)
* @see org.nuiton.topia.TopiaContext#createSchema()
*/
-
@Override
public void updateSchema() throws TopiaException {
try {
@@ -592,15 +592,15 @@
TOPIA_PERSISTENCE_DIRECTORIES, "").split(",");
for (String dir : dirs) {
dir = dir.trim();
- if (!"".equals(dir)) {
+ if (StringUtils.isNotEmpty(dir)) {
+ if (log.isDebugEnabled()) {
+ log.debug("Load persistence from dir : " + dir);
+ }
hibernateConfiguration.addDirectory(new File(dir));
}
}
// ajout des classes dites persistentes
- String listPersistenceClasses = getConfig().getProperty(
- TOPIA_PERSISTENCE_CLASSES, "");
-
for (TopiaService service : getServices().values()) {
Class<?>[] classes = service.getPersistenceClasses();
@@ -612,10 +612,16 @@
}
}
+ String listPersistenceClasses = getConfig().getProperty(
+ TOPIA_PERSISTENCE_CLASSES, "");
+
String[] classes = listPersistenceClasses.split(",");
for (String classname : classes) {
classname = classname.trim();
- if (!"".equals(classname)) {
+ if (StringUtils.isNotEmpty(classname)) {
+ if (log.isDebugEnabled()) {
+ log.debug("Load persistent class : " + classname);
+ }
Class<?> clazz;
try {
clazz = Class.forName(classname);
@@ -632,8 +638,22 @@
Properties prop = new Properties();
prop.putAll(hibernateConfiguration.getProperties());
prop.putAll(getConfig());
- prop.putAll(TopiaUtil.getProperties(getConfig().getProperty(
- TOPIA_PERSISTENCE_PROPERTIES_FILE)));
+
+ // 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(getConfig().
+ getProperty(TOPIA_PERSISTENCE_PROPERTIES_FILE));
+
+ if (!propertiesFromClasspath.isEmpty()) {
+ if (log.isDebugEnabled()) {
+ log.debug("Load properties from file : " +
+ propertiesFromClasspath);
+ }
+ prop.putAll(propertiesFromClasspath);
+ }
+
hibernateConfiguration.setProperties(prop);
}
}
@@ -998,7 +1018,6 @@
/* (non-Javadoc)
* @see org.nuiton.topia.TopiaContext#add(org.nuiton.topia.persistence.TopiaEntity)
*/
-
@Override
public void add(TopiaEntity e) throws TopiaException {
checkClosed(I18n._(
Modified: trunk/topia-persistence/src/test/java/org/nuiton/topia/framework/TopiaContextImplTest.java
===================================================================
--- trunk/topia-persistence/src/test/java/org/nuiton/topia/framework/TopiaContextImplTest.java 2010-05-11 12:09:48 UTC (rev 1954)
+++ trunk/topia-persistence/src/test/java/org/nuiton/topia/framework/TopiaContextImplTest.java 2010-05-12 09:38:43 UTC (rev 1955)
@@ -1,18 +1,29 @@
package org.nuiton.topia.framework;
+import org.apache.commons.lang.time.DurationFormatUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.h2.Driver;
+import org.hibernate.cfg.Configuration;
+import org.hibernate.mapping.PersistentClass;
+import org.hibernate.mapping.RootClass;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.nuiton.i18n.I18n;
+import org.nuiton.topia.TopiaContext;
import org.nuiton.topia.TopiaNotFoundException;
+import org.nuiton.topiatest.persistence.Entity1;
+import org.nuiton.topiatest.persistence.Entity1Impl;
import org.nuiton.topiatest.service.FakeService;
import org.nuiton.topiatest.service.TestService;
-import java.util.Collection;
+import java.io.File;
+import java.net.URL;
+import java.util.HashMap;
+import java.util.Iterator;
import java.util.Locale;
import java.util.Map;
import java.util.Properties;
@@ -50,7 +61,7 @@
/** PREPARE DATA **/
properties.setProperty("topia.service.test",
- TestService.class.getName());
+ TestService.class.getName());
TopiaContextImpl context = new TopiaContextImpl();
@@ -66,7 +77,7 @@
properties.clear();
properties.setProperty("topia.service.fake",
- TestService.class.getName());
+ TestService.class.getName());
results = context.loadServices(properties);
Assert.assertEquals(0, results.size());
@@ -90,7 +101,7 @@
/** PREPARE DATA **/
properties.setProperty("topia.service.test",
- TestService.class.getName());
+ TestService.class.getName());
// Calling the constructor with properties will load the services
TopiaContextImpl context = new TopiaContextImpl(properties);
@@ -126,7 +137,7 @@
// Even it's properly loaded the serviceEnabled method will return false
properties.clear();
properties.setProperty("topia.service.fake",
- FakeService.class.getName());
+ FakeService.class.getName());
TopiaContextImpl otherContext = new TopiaContextImpl(properties);
boolean test6 = otherContext.serviceEnabled(FakeService.class);
@@ -136,7 +147,7 @@
" : service not loaded");
// TestService is not loaded in otherContext
try {
- TestService test7 = otherContext.getService(TestService.class);
+ TestService test7 = otherContext.getService(TestService.class);
} catch (Exception eee) {
log.error(eee.getClass().getSimpleName() + " : " + eee.getMessage());
Assert.assertEquals(TopiaNotFoundException.class, eee.getClass());
@@ -198,9 +209,90 @@
// public void testGetHibernate() throws Exception {
// }
//
-// @Test
-// public void testGetHibernateFactory() throws Exception {
-// }
+
+ @Test
+ public void testGetHibernateFactory() throws Exception {
+ log.info("## testGetHibernateFactory");
+
+ /** PREPARE DATA **/
+ TopiaContextImpl context = new TopiaContextImpl();
+ context.services = new HashMap<String, TopiaService>();
+
+ String basedir = System.getenv("basedir");
+ if (basedir == null) {
+
+ // says basedir is where we start tests.
+ basedir = new File("").getAbsolutePath();
+ }
+
+ log.debug("baseDir : " + basedir);
+ File persistenceDir = new File(basedir,
+ "src" + File.separator +
+ "test" + File.separator +
+ "java" + File.separator +
+ "org" + File.separator +
+ "nuiton" + File.separator +
+ "topiatest" + File.separator +
+ "persistence");
+ log.debug("persistenceDir : " + persistenceDir);
+ File resourcesDir = new File(basedir,
+ "src" + File.separator +
+ "test" + File.separator +
+ "resources");
+
+ /** EXEC METHOD **/
+ log.info("test 1 : load mappings from directory");
+
+ properties.setProperty(TopiaContextImpl.TOPIA_PERSISTENCE_DIRECTORIES,
+ persistenceDir.getAbsolutePath());
+ context.config = properties;
+
+ Configuration test1 = context.getHibernateConfiguration();
+ PersistentClass persistentClass =
+ test1.getClassMapping(Entity1Impl.class.getName());
+ Assert.assertNotNull(persistentClass);
+ Assert.assertEquals(Entity1.class, persistentClass.getProxyInterface());
+
+// for (Iterator<RootClass> it = test1.getClassMappings(); it.hasNext();) {
+// RootClass o = it.next();
+// log.debug("entity : " + o.getEntityName());
+// }
+
+ log.info("test 2 : load mappings for all entities");
+ //reset from previous test
+ context = new TopiaContextImpl();
+ context.services = new HashMap<String, TopiaService>();
+ properties.clear();
+
+ // use property TOPIA_PERSISTENCE_CLASSES
+ properties.setProperty(TopiaContextImpl.TOPIA_PERSISTENCE_CLASSES,
+ Entity1Impl.class.getName());
+ context.config = properties;
+
+ Configuration test2 = context.getHibernateConfiguration();
+ persistentClass = test2.getClassMapping(Entity1Impl.class.getName());
+ Assert.assertNotNull(persistentClass);
+ Assert.assertEquals(Entity1.class, persistentClass.getProxyInterface());
+
+ log.info("test 3 : add properties from file");
+ //reset from previous test
+ context = new TopiaContextImpl();
+ context.services = new HashMap<String, TopiaService>();
+ properties.clear();
+
+ // use property TOPIA_PERSISTENCE_PROPERTIES_FILE to add default
+ // properties from file
+ properties.setProperty(TopiaContextImpl.TOPIA_PERSISTENCE_PROPERTIES_FILE,
+ resourcesDir + File.separator + "TopiaContextImpl.properties");
+ context.config = properties;
+
+ Configuration test3 = context.getHibernateConfiguration();
+ Assert.assertEquals(
+ test3.getProperty("hibernate.connection.driver_class"),
+ Driver.class.getName());
+
+ // Note : maybe add a test to load classes from services
+ }
//
// @Test
// public void testGetHibernateConfiguration() throws Exception {
Added: trunk/topia-persistence/src/test/java/org/nuiton/topiatest/persistence/Entity1.java
===================================================================
--- trunk/topia-persistence/src/test/java/org/nuiton/topiatest/persistence/Entity1.java (rev 0)
+++ trunk/topia-persistence/src/test/java/org/nuiton/topiatest/persistence/Entity1.java 2010-05-12 09:38:43 UTC (rev 1955)
@@ -0,0 +1,25 @@
+package org.nuiton.topiatest.persistence;
+
+import org.nuiton.topia.persistence.TopiaEntity;
+
+/**
+ * Created: 11 mai 2010
+ *
+ * @author fdesbois <fdesbois(a)codelutin.com>
+ * @version $Id$
+ */
+public interface Entity1 extends TopiaEntity {
+
+ String ATTR_1 = "attr1";
+
+ String ATTR_2 = "attr2";
+
+ String getAttr1();
+
+ void setAttr1(String attr1);
+
+ String getAttr2();
+
+ void setAttr2(String attr2);
+
+}
Property changes on: trunk/topia-persistence/src/test/java/org/nuiton/topiatest/persistence/Entity1.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: trunk/topia-persistence/src/test/java/org/nuiton/topiatest/persistence/Entity1Abstract.java
===================================================================
--- trunk/topia-persistence/src/test/java/org/nuiton/topiatest/persistence/Entity1Abstract.java (rev 0)
+++ trunk/topia-persistence/src/test/java/org/nuiton/topiatest/persistence/Entity1Abstract.java 2010-05-12 09:38:43 UTC (rev 1955)
@@ -0,0 +1,59 @@
+package org.nuiton.topiatest.persistence;
+
+import org.nuiton.topia.TopiaException;
+import org.nuiton.topia.persistence.EntityVisitor;
+import org.nuiton.topia.persistence.TopiaEntityAbstract;
+
+/**
+ * Created: 11 mai 2010
+ *
+ * @author fdesbois <fdesbois(a)codelutin.com>
+ * @version $Id$
+ */
+public abstract class Entity1Abstract extends TopiaEntityAbstract
+ implements Entity1 {
+
+ protected String attr1;
+
+ protected String attr2;
+
+ @Override
+ public String getAttr1() {
+ fireOnPreRead(ATTR_1, attr1);
+ String result = attr1;
+ fireOnPostRead(ATTR_1, attr1);
+ return result;
+ }
+
+ @Override
+ public void setAttr1(String attr1) {
+ String _oldValue = this.attr1;
+ fireOnPreWrite(ATTR_1, _oldValue, attr1);
+ this.attr1 = attr1;
+ fireOnPostWrite(ATTR_1, _oldValue, attr1);
+ }
+
+ @Override
+ public String getAttr2() {
+ fireOnPreRead(ATTR_2, attr2);
+ String result = attr2;
+ fireOnPostRead(ATTR_2, attr2);
+ return result;
+ }
+
+ @Override
+ public void setAttr2(String attr2) {
+ String _oldValue = this.attr2;
+ fireOnPreWrite(ATTR_2, _oldValue, attr2);
+ this.attr2 = attr2;
+ fireOnPostWrite(ATTR_2, _oldValue, attr2);
+ }
+
+ @Override
+ public void accept(EntityVisitor visitor) throws TopiaException {
+ visitor.start(this);
+ visitor.visit(this, ATTR_1, String.class, attr1);
+ visitor.visit(this, ATTR_2, String.class, attr2);
+ visitor.end(this);
+ }
+}
Property changes on: trunk/topia-persistence/src/test/java/org/nuiton/topiatest/persistence/Entity1Abstract.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: trunk/topia-persistence/src/test/java/org/nuiton/topiatest/persistence/Entity1Impl.hbm.xml
===================================================================
--- trunk/topia-persistence/src/test/java/org/nuiton/topiatest/persistence/Entity1Impl.hbm.xml (rev 0)
+++ trunk/topia-persistence/src/test/java/org/nuiton/topiatest/persistence/Entity1Impl.hbm.xml 2010-05-12 09:38:43 UTC (rev 1955)
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
+<hibernate-mapping default-access="field" auto-import="true" package="org.nuiton.topiatest">
+ <class name="org.nuiton.topiatest.persistence.Entity1Impl" table="entity1" node="org.nuiton.topiatest.persistence.Entity1Impl" abstract="false" proxy="org.nuiton.topiatest.persistence.Entity1" >
+ <id name="topiaId" type="string" length="255" node="@topiaId"/>
+ <version name="topiaVersion" type="long" node="@topiaVersion"/>
+ <property name="topiaCreateDate" type="timestamp" node="@topiaCreateDate"/>
+ <property name="attr1" type="java.lang.String" access="field" column="attr1" node="attr1"/>
+ <property name="attr2" type="java.lang.String" access="field" column="attr2" node="attr2"/>
+ </class>
+</hibernate-mapping>
Property changes on: trunk/topia-persistence/src/test/java/org/nuiton/topiatest/persistence/Entity1Impl.hbm.xml
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: trunk/topia-persistence/src/test/java/org/nuiton/topiatest/persistence/Entity1Impl.java
===================================================================
--- trunk/topia-persistence/src/test/java/org/nuiton/topiatest/persistence/Entity1Impl.java (rev 0)
+++ trunk/topia-persistence/src/test/java/org/nuiton/topiatest/persistence/Entity1Impl.java 2010-05-12 09:38:43 UTC (rev 1955)
@@ -0,0 +1,13 @@
+package org.nuiton.topiatest.persistence;
+
+import org.nuiton.topia.TopiaException;
+import org.nuiton.topia.persistence.EntityVisitor;
+
+/**
+ * Created: 11 mai 2010
+ *
+ * @author fdesbois <fdesbois(a)codelutin.com>
+ * @version $Id$
+ */
+public class Entity1Impl extends Entity1Abstract {
+}
Property changes on: trunk/topia-persistence/src/test/java/org/nuiton/topiatest/persistence/Entity1Impl.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: trunk/topia-persistence/src/test/java/org/nuiton/topiatest/persistence/package-info.java
===================================================================
--- trunk/topia-persistence/src/test/java/org/nuiton/topiatest/persistence/package-info.java (rev 0)
+++ trunk/topia-persistence/src/test/java/org/nuiton/topiatest/persistence/package-info.java 2010-05-12 09:38:43 UTC (rev 1955)
@@ -0,0 +1,4 @@
+/**
+ * Contains persistent entities for Tests.
+ */
+package org.nuiton.topiatest.persistence;
\ No newline at end of file
Property changes on: trunk/topia-persistence/src/test/java/org/nuiton/topiatest/persistence/package-info.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
1
0
Author: tchemit
Date: 2010-05-11 14:09:48 +0200 (Tue, 11 May 2010)
New Revision: 1954
Url: http://nuiton.org/repositories/revision/topia/1954
Log:
use stable of nuiton-utils
Modified:
trunk/pom.xml
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2010-05-10 21:48:34 UTC (rev 1953)
+++ trunk/pom.xml 2010-05-11 12:09:48 UTC (rev 1954)
@@ -23,287 +23,296 @@
<http://www.gnu.org/licenses/lgpl-3.0.html>.
#L%
-->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
+ <modelVersion>4.0.0</modelVersion>
- <!-- ************************************************************* -->
- <!-- *** POM Relationships *************************************** -->
- <!-- ************************************************************* -->
- <parent>
- <groupId>org.nuiton</groupId>
- <artifactId>mavenpom4redmine</artifactId>
- <version>2.1.4</version>
- </parent>
+ <!-- ************************************************************* -->
+ <!-- *** POM Relationships *************************************** -->
+ <!-- ************************************************************* -->
+ <parent>
+ <groupId>org.nuiton</groupId>
+ <artifactId>mavenpom4redmine</artifactId>
+ <version>2.1.4</version>
+ </parent>
- <artifactId>topia</artifactId>
- <version>2.4-SNAPSHOT</version>
+ <artifactId>topia</artifactId>
+ <version>2.4-SNAPSHOT</version>
- <modules>
- <module>topia-persistence</module>
- <module>topia-service-replication</module>
- <module>topia-service-migration</module>
- <module>topia-service-security</module>
- <!--
- TC-20100403 (see Evolution #440)
- since version 2.3.2, those modules are not included until
- they are ready for production and fully useable
- -->
- <!--module>topia-soa</module-->
- <!--module>topia-service-index</module-->
- <!--module>topia-service-history</module-->
- </modules>
+ <modules>
+ <module>topia-persistence</module>
+ <module>topia-service-replication</module>
+ <module>topia-service-migration</module>
+ <module>topia-service-security</module>
+ <!--
+ TC-20100403 (see Evolution #440)
+ since version 2.3.2, those modules are not included until
+ they are ready for production and fully useable
+ -->
+ <!--module>topia-soa</module-->
+ <!--module>topia-service-index</module-->
+ <!--module>topia-service-history</module-->
+ </modules>
- <dependencyManagement>
- <dependencies>
+ <dependencyManagement>
+ <dependencies>
- <dependency>
- <groupId>org.nuiton.eugene</groupId>
- <artifactId>eugene</artifactId>
- <version>${eugene.version}</version>
- <scope>provided</scope>
- </dependency>
+ <dependency>
+ <groupId>log4j</groupId>
+ <artifactId>log4j</artifactId>
+ <version>1.2.16</version>
+ <scope>test</scope>
+ </dependency>
- <dependency>
- <groupId>org.nuiton</groupId>
- <artifactId>nuiton-utils</artifactId>
- <version>${lutinutil.version}</version>
- <scope>compile</scope>
- </dependency>
+ <dependency>
+ <groupId>org.nuiton.eugene</groupId>
+ <artifactId>eugene</artifactId>
+ <version>${eugene.version}</version>
+ <scope>provided</scope>
+ </dependency>
-
+ <dependency>
+ <groupId>org.nuiton</groupId>
+ <artifactId>nuiton-utils</artifactId>
+ <version>${lutinutil.version}</version>
+ <scope>compile</scope>
+ </dependency>
- <dependency>
- <groupId>commons-collections</groupId>
- <artifactId>commons-collections</artifactId>
- <version>3.2.1</version>
- <scope>compile</scope>
- </dependency>
- <dependency>
- <groupId>commons-lang</groupId>
- <artifactId>commons-lang</artifactId>
- <version>2.4</version>
- <scope>compile</scope>
- </dependency>
+ <dependency>
+ <groupId>commons-collections</groupId>
+ <artifactId>commons-collections</artifactId>
+ <version>3.2.1</version>
+ <scope>compile</scope>
+ </dependency>
- <dependency>
- <groupId>org.hibernate</groupId>
- <artifactId>hibernate-core</artifactId>
- <version>${hibernate.version}</version>
- <scope>compile</scope>
- </dependency>
+ <dependency>
+ <groupId>commons-lang</groupId>
+ <artifactId>commons-lang</artifactId>
+ <version>2.4</version>
+ <scope>compile</scope>
+ </dependency>
- <dependency>
- <groupId>org.hibernate</groupId>
- <artifactId>hibernate-ehcache</artifactId>
- <version>${hibernate.version}</version>
- <scope>runtime</scope>
- </dependency>
+ <dependency>
+ <groupId>org.hibernate</groupId>
+ <artifactId>hibernate-core</artifactId>
+ <version>${hibernate.version}</version>
+ <scope>compile</scope>
+ </dependency>
- <dependency>
- <groupId>javassist</groupId>
- <artifactId>javassist</artifactId>
- <version>3.8.0.GA</version>
- <scope>runtime</scope>
- </dependency>
+ <dependency>
+ <groupId>org.hibernate</groupId>
+ <artifactId>hibernate-ehcache</artifactId>
+ <version>${hibernate.version}</version>
+ <scope>runtime</scope>
+ </dependency>
- <!-- hibernate-core only include api, need core -->
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-log4j12</artifactId>
- <version>1.5.8</version>
- <scope>test</scope>
- </dependency>
+ <dependency>
+ <groupId>javassist</groupId>
+ <artifactId>javassist</artifactId>
+ <version>3.8.0.GA</version>
+ <scope>runtime</scope>
+ </dependency>
- <!-- BD H2 for testing -->
- <dependency>
- <groupId>com.h2database</groupId>
- <artifactId>h2</artifactId>
- <version>1.2.128</version>
- <scope>test</scope>
- </dependency>
+ <!-- hibernate-core only include api, need core -->
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-log4j12</artifactId>
+ <version>1.5.8</version>
+ <scope>test</scope>
+ </dependency>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <version>4.8.1</version>
- <scope>test</scope>
- </dependency>
+ <!-- BD H2 for testing -->
+ <dependency>
+ <groupId>com.h2database</groupId>
+ <artifactId>h2</artifactId>
+ <version>1.2.128</version>
+ <scope>test</scope>
+ </dependency>
- <!-- All theses dependancies are no more used
- Keep them for topia-soa and topia-service-XXX
- -->
-
- <!--dependency>
- <groupId>org.apache.xmlrpc</groupId>
- <artifactId>xmlrpc-server</artifactId>
- <version>${xmlrpc.version}</version>
- <scope>compile</scope>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.8.1</version>
+ <scope>test</scope>
+ </dependency>
- </dependency>
- <dependency>
- <groupId>org.apache.xmlrpc</groupId>
- <artifactId>xmlrpc-client</artifactId>
- <version>${xmlrpc.version}</version>
- <scope>compile</scope>
- </dependency-->
+ <!-- All theses dependancies are no more used
+ Keep them for topia-soa and topia-service-XXX
+ -->
- <!-- Dependencies for class generation -->
- <!--dependency>
- <groupId>org.nuiton.thirdparty</groupId>
- <artifactId>asm</artifactId>
- <version>1.5.4-snapshot</version>
- <scope>compile</scope>
- </dependency>
- <dependency>
- <groupId>xom</groupId>
- <artifactId>xom</artifactId>
- <version>1.1</version>
- </dependency-->
-
- <!--dependency>
- <groupId>org.codehaus.xfire</groupId>
- <artifactId>xfire-java5</artifactId>
- <version>1.2.6</version>
- <scope>compile</scope>
- <exclusions-->
- <!-- Fix org.apache.ant conflict) -->
- <!--exclusion>
- <groupId>ant</groupId>
- <artifactId>ant</artifactId>
- </exclusion>
- </exclusions>
- </dependency>
+ <!--dependency>
+ <groupId>org.apache.xmlrpc</groupId>
+ <artifactId>xmlrpc-server</artifactId>
+ <version>${xmlrpc.version}</version>
+ <scope>compile</scope>
- <dependency>
- <groupId>commons-httpclient</groupId>
- <artifactId>commons-httpclient</artifactId>
- <version>3.1</version>
- <scope>runtime</scope>
- </dependency-->
+ </dependency>
+ <dependency>
+ <groupId>org.apache.xmlrpc</groupId>
+ <artifactId>xmlrpc-client</artifactId>
+ <version>${xmlrpc.version}</version>
+ <scope>compile</scope>
+ </dependency-->
+ <!-- Dependencies for class generation -->
+ <!--dependency>
+ <groupId>org.nuiton.thirdparty</groupId>
+ <artifactId>asm</artifactId>
+ <version>1.5.4-snapshot</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>xom</groupId>
+ <artifactId>xom</artifactId>
+ <version>1.1</version>
+ </dependency-->
- <!-- branch 5.1 : ne fonctionne pas en 6+ -->
- <!--dependency>
- <groupId>jetty</groupId>
- <artifactId>jetty</artifactId>
- <version>5.1.10</version>
- <scope>test</scope>
- </dependency>
+ <!--dependency>
+ <groupId>org.codehaus.xfire</groupId>
+ <artifactId>xfire-java5</artifactId>
+ <version>1.2.6</version>
+ <scope>compile</scope>
+ <exclusions-->
+ <!-- Fix org.apache.ant conflict) -->
+ <!--exclusion>
+ <groupId>ant</groupId>
+ <artifactId>ant</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
- <dependency>
- <groupId>org.apache.lucene</groupId>
- <artifactId>lucene-core</artifactId>
- <version>3.0.1</version>
- <scope>compile</scope>
- </dependency-->
+ <dependency>
+ <groupId>commons-httpclient</groupId>
+ <artifactId>commons-httpclient</artifactId>
+ <version>3.1</version>
+ <scope>runtime</scope>
+ </dependency-->
- </dependencies>
- </dependencyManagement>
- <!-- ************************************************************* -->
- <!-- *** Project Information ************************************* -->
- <!-- ************************************************************* -->
- <name>ToPIA</name>
- <description>
- Tools for Portable and Independent Architecture :
- Framework de persistance et de distribution d'application.
- </description>
- <inceptionYear>2004</inceptionYear>
- <url>http://maven-site.nuiton.org/topia</url>
+ <!-- branch 5.1 : ne fonctionne pas en 6+ -->
+ <!--dependency>
+ <groupId>jetty</groupId>
+ <artifactId>jetty</artifactId>
+ <version>5.1.10</version>
+ <scope>test</scope>
+ </dependency>
- <!-- ************************************************************* -->
- <!-- *** Build Settings ****************************************** -->
- <!-- ************************************************************* -->
+ <dependency>
+ <groupId>org.apache.lucene</groupId>
+ <artifactId>lucene-core</artifactId>
+ <version>3.0.1</version>
+ <scope>compile</scope>
+ </dependency-->
- <packaging>pom</packaging>
+ </dependencies>
+ </dependencyManagement>
- <properties>
- <!-- pour un muli module on doit fixer le projectId -->
- <projectId>topia</projectId>
+ <!-- ************************************************************* -->
+ <!-- *** Project Information ************************************* -->
+ <!-- ************************************************************* -->
+ <name>ToPIA</name>
+ <description>
+ Tools for Portable and Independent Architecture :
+ Framework de persistance et de distribution d'application.
+ </description>
+ <inceptionYear>2004</inceptionYear>
+ <url>http://maven-site.nuiton.org/topia</url>
- <!-- libs version -->
- <eugene.version>2.0.2-SNAPSHOT</eugene.version>
- <lutinutil.version>1.3-SNAPSHOT</lutinutil.version>
- <processor.version>1.0.3</processor.version>
- <i18n.version>1.2.2</i18n.version>
- <xmlrpc.version>3.1.2</xmlrpc.version>
- <hibernate.version>3.3.2.GA</hibernate.version>
- </properties>
+ <!-- ************************************************************* -->
+ <!-- *** Build Settings ****************************************** -->
+ <!-- ************************************************************* -->
- <build>
+ <packaging>pom</packaging>
- <pluginManagement>
- <plugins>
+ <properties>
+ <!-- pour un muli module on doit fixer le projectId -->
+ <projectId>topia</projectId>
- <plugin>
- <groupId>org.nuiton.processor</groupId>
- <artifactId>maven-processor-plugin</artifactId>
- <version>${processor.version}</version>
- <executions>
- <execution>
- <phase>generate-sources</phase>
- <goals>
- <goal>process</goal>
- </goals>
- </execution>
- </executions>
- <configuration>
- <includes>**/*.java</includes>
- <filters>
- org.nuiton.processor.filters.GeneratorTemplatesFilter,
- org.nuiton.processor.filters.ActiveLogsCodeFilter
- </filters>
- </configuration>
- </plugin>
+ <!-- libs version -->
+ <eugene.version>2.0.2-SNAPSHOT</eugene.version>
+ <lutinutil.version>1.3</lutinutil.version>
+ <processor.version>1.0.3</processor.version>
+ <i18n.version>1.2.2</i18n.version>
+ <xmlrpc.version>3.1.2</xmlrpc.version>
+ <hibernate.version>3.3.2.GA</hibernate.version>
+ </properties>
- <plugin>
- <groupId>org.nuiton.eugene</groupId>
- <artifactId>maven-eugene-plugin</artifactId>
- <version>${eugene.version}</version>
- <configuration>
- <inputs>zargo</inputs>
- <resolver>org.nuiton.util.FasterCachedResourceResolver</resolver>
- </configuration>
- </plugin>
+ <build>
- <plugin>
- <groupId>org.nuiton.i18n</groupId>
- <artifactId>maven-i18n-plugin</artifactId>
- <version>${i18n.version}</version>
- </plugin>
+ <pluginManagement>
+ <plugins>
- <plugin>
- <artifactId>maven-site-plugin</artifactId>
- <dependencies>
- <dependency>
- <groupId>org.nuiton.jrst</groupId>
- <artifactId>doxia-module-jrst</artifactId>
- <version>${jrst.version}</version>
- </dependency>
- </dependencies>
- </plugin>
+ <plugin>
+ <groupId>org.nuiton.processor</groupId>
+ <artifactId>maven-processor-plugin</artifactId>
+ <version>${processor.version}</version>
+ <executions>
+ <execution>
+ <phase>generate-sources</phase>
+ <goals>
+ <goal>process</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+ <includes>**/*.java</includes>
+ <filters>
+ org.nuiton.processor.filters.GeneratorTemplatesFilter,
+ org.nuiton.processor.filters.ActiveLogsCodeFilter
+ </filters>
+ </configuration>
+ </plugin>
- </plugins>
- </pluginManagement>
+ <plugin>
+ <groupId>org.nuiton.eugene</groupId>
+ <artifactId>maven-eugene-plugin</artifactId>
+ <version>${eugene.version}</version>
+ <configuration>
+ <inputs>zargo</inputs>
+ <resolver>org.nuiton.util.FasterCachedResourceResolver</resolver>
+ </configuration>
+ </plugin>
- </build>
+ <plugin>
+ <groupId>org.nuiton.i18n</groupId>
+ <artifactId>maven-i18n-plugin</artifactId>
+ <version>${i18n.version}</version>
+ </plugin>
- <reporting>
- <!--TC-20100413 : by default do nothing except documentation -->
- <excludeDefaults>true</excludeDefaults>
- </reporting>
+ <plugin>
+ <artifactId>maven-site-plugin</artifactId>
+ <dependencies>
+ <dependency>
+ <groupId>org.nuiton.jrst</groupId>
+ <artifactId>doxia-module-jrst</artifactId>
+ <version>${jrst.version}</version>
+ </dependency>
+ </dependencies>
+ </plugin>
- <!-- ************************************************************* -->
- <!-- *** Build Environment ************************************** -->
- <!-- ************************************************************* -->
+ </plugins>
+ </pluginManagement>
- <!-- Source control management. -->
- <scm>
- <connection>scm:svn:http://svn.nuiton.org/svn/topia/trunk</connection>
- <developerConnection>scm:svn:http://svn.nuiton.org/svn/topia/trunk</developerConnection>
- <url>http://www.nuiton.org/repositories/browse/topia/trunk</url>
- </scm>
+ </build>
+ <reporting>
+ <!--TC-20100413 : by default do nothing except documentation -->
+ <excludeDefaults>true</excludeDefaults>
+ </reporting>
+
+ <!-- ************************************************************* -->
+ <!-- *** Build Environment ************************************** -->
+ <!-- ************************************************************* -->
+
+ <!-- Source control management. -->
+ <scm>
+ <connection>scm:svn:http://svn.nuiton.org/svn/topia/trunk</connection>
+ <developerConnection>scm:svn:http://svn.nuiton.org/svn/topia/trunk
+ </developerConnection>
+ <url>http://www.nuiton.org/repositories/browse/topia/trunk</url>
+ </scm>
+
</project>
1
0
r1953 - trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util
by tchemit@users.nuiton.org 10 May '10
by tchemit@users.nuiton.org 10 May '10
10 May '10
Author: tchemit
Date: 2010-05-10 23:48:34 +0200 (Mon, 10 May 2010)
New Revision: 1953
Url: http://nuiton.org/repositories/revision/topia/1953
Log:
open Deletor api
Modified:
trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/Deletor.java
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/Deletor.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/Deletor.java 2010-05-10 17:21:46 UTC (rev 1952)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/Deletor.java 2010-05-10 21:48:34 UTC (rev 1953)
@@ -25,6 +25,8 @@
package org.nuiton.topia.persistence.util;
+import org.nuiton.topia.TopiaContext;
+
/**
* A simple contract to hook the deletion of an entity.
*
@@ -38,8 +40,9 @@
/**
* Hook to delete an entity from a prent entity.
*
+ * @param tx current transaction
* @param parent the parent of the entity
* @param from the entity to delete.
*/
- void delete(P parent, E from);
+ void delete(TopiaContext tx, P parent, E from);
}
1
0
r1952 - in trunk/topia-persistence/src: main/java/org/nuiton/topia/framework test/java/org/nuiton/topia/framework
by fdesbois@users.nuiton.org 10 May '10
by fdesbois@users.nuiton.org 10 May '10
10 May '10
Author: fdesbois
Date: 2010-05-10 19:21:46 +0200 (Mon, 10 May 2010)
New Revision: 1952
Url: http://nuiton.org/repositories/revision/topia/1952
Log:
Continue testing TopiaContextImpl
Modified:
trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaContextImpl.java
trunk/topia-persistence/src/test/java/org/nuiton/topia/framework/TopiaContextImplTest.java
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaContextImpl.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaContextImpl.java 2010-05-10 16:40:22 UTC (rev 1951)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaContextImpl.java 2010-05-10 17:21:46 UTC (rev 1952)
@@ -320,7 +320,7 @@
@Override
public <E extends TopiaService> E getService(Class<E> interfaceService)
throws TopiaNotFoundException {
- E result = null;
+ E result;
try {
String name = getServiceName(interfaceService);
result = (E) getService(name);
Modified: trunk/topia-persistence/src/test/java/org/nuiton/topia/framework/TopiaContextImplTest.java
===================================================================
--- trunk/topia-persistence/src/test/java/org/nuiton/topia/framework/TopiaContextImplTest.java 2010-05-10 16:40:22 UTC (rev 1951)
+++ trunk/topia-persistence/src/test/java/org/nuiton/topia/framework/TopiaContextImplTest.java 2010-05-10 17:21:46 UTC (rev 1952)
@@ -86,7 +86,7 @@
@Test
public void testGetServices() throws Exception {
- log.info("## testGetServices");
+ log.info("## testGetServices");
/** PREPARE DATA **/
properties.setProperty("topia.service.test",
@@ -142,32 +142,47 @@
Assert.assertEquals(TopiaNotFoundException.class, eee.getClass());
}
}
+
+ @Test
+ public void testContextHierarchy() throws Exception {
+ log.info("## testContextHierarchy");
+
+ /** PREPARE DATA **/
+ TopiaContextImpl context = new TopiaContextImpl(properties);
+
+ /** EXEC METHODS **/
+ log.info("test 1 : constructor with parent context");
+ TopiaContextImpl test1 = new TopiaContextImpl(context);
+ Assert.assertEquals(context, test1.parentContext);
+
+ log.info("test 2 : addChildContext");
+ TopiaContextImpl test2 = new TopiaContextImpl(properties);
+ TopiaContextImpl child2 = new TopiaContextImpl();
+ test2.addChildContext(child2);
+ Assert.assertEquals(1, test2.childContext.size());
+
+ log.info("test 3 : removeChildContext");
+ TopiaContextImpl test3 = new TopiaContextImpl(properties);
+ TopiaContextImpl child3 = new TopiaContextImpl(test3);
+ test3.childContext.add(child3);
+ test3.removeChildContext(child3);
+ Assert.assertEquals(0, test3.childContext.size());
+
+ // No remove if context is closed
+ test3.childContext.add(child3);
+ test3.closed = true;
+ test3.removeChildContext(child3);
+ Assert.assertEquals(1, test3.childContext.size());
+
+ log.info("test 4 : getRootContext");
+ TopiaContextImplementor test4 = child3.getRootContext();
+ Assert.assertEquals(test3, test4);
+
+ // Note : existing test is already done for concurrency problem on
+ // getChildContext(). Go to : http://www.nuiton.org/repositories/browse/sandbox/testTopiaPostgresError/tr…
+ }
//
// @Test
-// public void testGetAllServices() throws Exception {
-// }
-//
-// @Test
-// public void testGetChildContext() throws Exception {
-// }
-//
-// @Test
-// public void testRemoveChildContext() throws Exception {
-// }
-//
-// @Test
-// public void testGetParentContext() throws Exception {
-// }
-//
-// @Test
-// public void testGetRootContext() throws Exception {
-// }
-//
-// @Test
-// public void testGetConfig() throws Exception {
-// }
-//
-// @Test
// public void testCreateSchema() throws Exception {
// }
//
1
0
r1951 - in trunk/topia-persistence/src: main/java/org/nuiton/topia main/java/org/nuiton/topia/framework main/resources/i18n test/java/org/nuiton/topia/framework test/java/org/nuiton/topiatest test/java/org/nuiton/topiatest/service
by fdesbois@users.nuiton.org 10 May '10
by fdesbois@users.nuiton.org 10 May '10
10 May '10
Author: fdesbois
Date: 2010-05-10 18:40:22 +0200 (Mon, 10 May 2010)
New Revision: 1951
Url: http://nuiton.org/repositories/revision/topia/1951
Log:
- TopiaContextImplTest : All tests done for Services
- Clean javadocs + improve some errors managment
Added:
trunk/topia-persistence/src/test/java/org/nuiton/topiatest/service/
trunk/topia-persistence/src/test/java/org/nuiton/topiatest/service/FakeService.java
trunk/topia-persistence/src/test/java/org/nuiton/topiatest/service/TestService.java
trunk/topia-persistence/src/test/java/org/nuiton/topiatest/service/package-info.java
Removed:
trunk/topia-persistence/src/test/java/org/nuiton/topia/framework/TestService.java
Modified:
trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaContext.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaContextImpl.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaContextImplementor.java
trunk/topia-persistence/src/main/resources/i18n/topia-persistence-fr_FR.properties
trunk/topia-persistence/src/test/java/org/nuiton/topia/framework/TopiaContextImplTest.java
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaContext.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaContext.java 2010-05-10 14:33:00 UTC (rev 1950)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaContext.java 2010-05-10 16:40:22 UTC (rev 1951)
@@ -108,12 +108,13 @@
Class<E> interfaceService);
/**
- * Return the service.
+ * Return the service. This service must be valid with public static final
+ * SERVICE_NAME property.
*
* @param <E> type of service
- * @param interfaceService fqn of the service
+ * @param interfaceService class of the service
* @return the service
- * @throws TopiaNotFoundException if service is can't be retrieved
+ * @throws TopiaNotFoundException if service can't be retrieved
*/
<E extends TopiaService> E getService(Class<E> interfaceService)
throws TopiaNotFoundException;
@@ -167,10 +168,21 @@
* @param topiaId l'id de l'entite recherche
* @return l'entite trouvee (ou null si non trouve)
* @throws TopiaException if any exception
+ * @deprecated since 2.4, use {@link #findById(String)} instead
*/
+ @Deprecated
TopiaEntity findByTopiaId(String topiaId) throws TopiaException;
/**
+ * Retrieve {@link TopiaEntity} using its unique {@code id}.
+ *
+ * @param id unique identifier of the entity in all the application.
+ * @return the entity found or null if not
+ * @throws TopiaException for errors on retrieving the entity
+ */
+ TopiaEntity findById(String id) throws TopiaException;
+
+ /**
* Permet de faire une requete HQL hibernate directement sur la base.
*
* @param hql la requete a faire
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaContextImpl.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaContextImpl.java 2010-05-10 14:33:00 UTC (rev 1950)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaContextImpl.java 2010-05-10 16:40:22 UTC (rev 1951)
@@ -188,11 +188,17 @@
/** Liste des classes perssitance */
protected List<Class<?>> persistenceClasses = new ArrayList<Class<?>>();
+ /** Default constructor, useful for tests. */
+ protected TopiaContextImpl() {
+ }
+
/**
- * constructeur utilisé par la factory pour creer les contexts initiaux
+ * Constructor used by {@link TopiaContextFactory} to initialize rootContext
+ * using {@code config}.
*
- * @param config
- * @throws TopiaNotFoundException
+ * @param config for the new root context
+ * @throws TopiaNotFoundException if one of persistent class from
+ * configuration is not found
*/
public TopiaContextImpl(Properties config) throws TopiaNotFoundException {
this.config = config;
@@ -202,13 +208,13 @@
postInitServices(services);
}
- /**
- * Default constructor, useful for tests.
- */
- protected TopiaContextImpl() {
-
+ protected String getProperExceptionMessage(Throwable eee) {
+ return eee.getClass().getSimpleName() + " : " +
+ eee.getMessage();
}
+ /* -------------------- SERVICES MANAGMENT -------------------------------*/
+
protected Map<String, TopiaService> loadServices(Properties config) {
Map<String, TopiaService> result = new HashMap<String, TopiaService>();
// recherche des services present dans la config
@@ -231,7 +237,7 @@
} catch (Throwable eee) {
String message =
I18n._("topia.persistence.error.service.unknown",
- key, classService);
+ key, classService);
if (log.isDebugEnabled()) {
log.debug(message, eee);
} else if (log.isErrorEnabled()) {
@@ -261,16 +267,8 @@
}
}
- @Override
- public Map<String, TopiaService> getServices() {
- TopiaContextImplementor parent = getParentContext();
-
- Map<String, TopiaService> result = null;
- if (parent != null) {
- result = parent.getServices();
- } else {
- result = services;
- }
+ protected TopiaService getService(String name) {
+ TopiaService result = getServices().get(name);
return result;
}
@@ -279,24 +277,34 @@
return result;
}
- protected TopiaService getService(String name) {
- TopiaService result = getServices().get(name);
- return result;
+ /**
+ * Retrieve service name using SERVICE_NAME static field on service
+ * interface.
+ *
+ * @param interfaceService class of the service
+ * @param <E> type of the service that extends {@link
+ * TopiaService}
+ * @return the service name
+ * @throws IllegalAccessException if field SERVICE_NAME can't be accessed
+ * @throws NoSuchFieldException if no field SERVICE_NAME is defined
+ */
+ protected <E extends TopiaService> String getServiceName(
+ Class<E> interfaceService)
+ throws IllegalAccessException, NoSuchFieldException {
+ Field f = interfaceService.getField("SERVICE_NAME");
+ String name = (String) f.get(null);
+ return name;
}
@Override
- public <E extends TopiaService> boolean serviceEnabled(
- Class<E> interfaceService) {
- boolean result = false;
- try {
- Field f = interfaceService.getField("SERVICE_NAME");
- String name = (String) f.get(null);
- result = serviceEnabled(name);
- } catch (Exception eee) {
- if (log.isWarnEnabled()) {
- log.warn(I18n._("topia.persistence.warn.service.not.found",
- interfaceService, eee.getMessage()), eee);
- }
+ public Map<String, TopiaService> getServices() {
+ TopiaContextImplementor parent = getParentContext();
+
+ Map<String, TopiaService> result = null;
+ if (parent != null) {
+ result = parent.getServices();
+ } else {
+ result = services;
}
return result;
}
@@ -305,50 +313,71 @@
* Take one service, this service must be valid service interface with
* public static final SERVICE_NAME declaration.
*
- * @param <E>
- * @throws TopiaNotFoundException
+ * @param <E> type of the service that extends {@link TopiaService}
+ * @throws TopiaNotFoundException if an error appears or service not found.
+ * @see #getServiceName(Class)
*/
@Override
public <E extends TopiaService> E getService(Class<E> interfaceService)
throws TopiaNotFoundException {
+ E result = null;
try {
- Field f = interfaceService.getField("SERVICE_NAME");
- String name = (String) f.get(null);
- E result = (E) getService(name);
- if (result == null) {
- throw new TopiaNotFoundException(
- I18n._("topia.persistence.error.service.not.found",
- interfaceService));
- }
- return result;
+ String name = getServiceName(interfaceService);
+ result = (E) getService(name);
} catch (Exception eee) {
throw new TopiaNotFoundException(
I18n._("topia.persistence.error.service.not.retreaved",
- interfaceService, eee.getMessage()), eee);
+ interfaceService, getProperExceptionMessage(eee)),
+ eee);
}
+ if (result == null) {
+ throw new TopiaNotFoundException(
+ I18n._("topia.persistence.error.service.not.found",
+ interfaceService));
+ }
+ return result;
}
@Override
+ public <E extends TopiaService> boolean serviceEnabled(
+ Class<E> interfaceService) {
+ boolean result = false;
+ try {
+ String name = getServiceName(interfaceService);
+ result = serviceEnabled(name);
+ } catch (Exception eee) {
+ String message = I18n._("topia.persistence.warn.service.not.found",
+ interfaceService, getProperExceptionMessage(eee));
+ if (log.isDebugEnabled()) {
+ log.debug(message, eee);
+ } else if (log.isWarnEnabled()) {
+ log.warn(message);
+ }
+ }
+ return result;
+ }
+
+ @Override
public Collection<TopiaService> getAllServices() {
Collection<TopiaService> result = getServices().values();
return result;
}
+ /* -------------------- CONTEXT HIERARCHY MANAGMENT ----------------------*/
+
/**
- * Constructeur utilisé par le beginTransaction pour créer le context fils.
+ * Constructor used by {@link #beginTransaction()} to instantiate child from
+ * {@code parentContext}.
*
- * @param parentContext
- * @throws HibernateException
- * @throws TopiaNotFoundException
+ * @param parentContext context parent of the new TopiaContext child
*/
- protected TopiaContextImpl(TopiaContextImplementor parentContext)
- throws HibernateException, TopiaNotFoundException {
+ protected TopiaContextImpl(TopiaContextImplementor parentContext) {
this.parentContext = parentContext;
}
@Override
public Set<TopiaContextImplementor> getChildContext() {
- // FD-20100421 : Ano #546
+ // fdesbois-20100421 : Ano #546
// Copy the childContext into a new set
final Set<TopiaContextImplementor> values;
// Synchronize copy to be thread-safe during iteration
@@ -364,8 +393,7 @@
@Override
public void removeChildContext(TopiaContextImplementor child) {
- // On ne retire les fils que si ce contexte n'est pas deja ferme.
- // Permet d'eviter les acces concurrentiels
+ // Remove child only if this context is not already closed.
if (!closed) {
childContext.remove(child);
}
@@ -393,6 +421,8 @@
return config;
}
+ /* -------------------- HIBERNATE MANAGMENT -----------------------------*/
+
@Override
public void createSchema() throws TopiaException {
try {
@@ -571,7 +601,7 @@
String listPersistenceClasses = getConfig().getProperty(
TOPIA_PERSISTENCE_CLASSES, "");
- for (TopiaService service : getAllServices()) {
+ for (TopiaService service : getServices().values()) {
Class<?>[] classes = service.getPersistenceClasses();
// certains service n'ont pas de classe persistantes
@@ -610,6 +640,8 @@
return hibernateConfiguration;
}
+ /* -------------------- CHILD CONTEXT AND DAOS --------------------------*/
+
/*
* (non-Javadoc)
*
@@ -668,7 +700,7 @@
/*
* (non-Javadoc)
*
- * @see org.nuiton.topia.TopiaContext#beginTransaction()
+ * @see TopiaContext#beginTransaction()
*/
@Override
@@ -702,7 +734,7 @@
/*
* (non-Javadoc)
*
- * @see org.nuiton.topia.TopiaContext#commitTransaction()
+ * @see TopiaContext#commitTransaction()
*/
@Override
@@ -748,7 +780,7 @@
/*
* (non-Javadoc)
*
- * @see org.nuiton.topia.TopiaContext#rollbackTransaction()
+ * @see TopiaContext#rollbackTransaction()
*/
@Override
@@ -829,7 +861,7 @@
/**
* Pour le context root on ferme tous les fils, et la factory hibernate
*
- * @see java.lang.Object#finalize()
+ * @see Object#finalize()
*/
@Override
protected void finalize() throws Throwable {
@@ -852,26 +884,33 @@
}
}
+ /* -------------------- GLOBAL OPERATIONS ON SCHEMA ----------------------*/
+
/* (non-Javadoc)
- * @see org.nuiton.topia.TopiaContext#findByTopiaId(java.lang.String)
+ * @see TopiaContext#findByTopiaId(java.lang.String)
*/
@Override
public TopiaEntity findByTopiaId(String topiaId) throws TopiaException {
+ TopiaEntity result = findById(topiaId);
+ return result;
+ }
+
+ @Override
+ public TopiaEntity findById(String id) throws TopiaException {
checkClosed(I18n._(
"topia.persistence.error.unsupported.operation.on.closed.context",
- "findByTopiaId"));
+ "findById"));
- TopiaEntity result;
- Class<TopiaEntity> entityClass = TopiaId.getClassName(topiaId);
+ Class<TopiaEntity> entityClass = TopiaId.getClassName(id);
TopiaDAO<TopiaEntity> dao = getDAO(entityClass);
- result = dao.findByTopiaId(topiaId);
+ TopiaEntity result = dao.findById(id);
return result;
}
/*
* (non-Javadoc)
- * @see org.nuiton.topia.TopiaContext#find(java.lang.String, java.lang.Object[])
+ * @see TopiaContext#find(java.lang.String, java.lang.Object[])
*/
@Override
@@ -932,7 +971,7 @@
/**
* Execute HQL operation on data (Update, Delete)
*
- * @param hql HQL query
+ * @param hql HQL query
* @param args arguments for query
* @return The number of entities updated or deleted.
* @throws TopiaException
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaContextImplementor.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaContextImplementor.java 2010-05-10 14:33:00 UTC (rev 1950)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaContextImplementor.java 2010-05-10 16:40:22 UTC (rev 1951)
@@ -120,6 +120,11 @@
Map<String, TopiaService> getServices();
+ /**
+ * @return a collection of {@link TopiaService}
+ * @deprecated since 2.4 : useless method, use {@link #getServices()} instead
+ */
+ @Deprecated
Collection<TopiaService> getAllServices();
List<Class<?>> getPersistenceClasses();
Modified: trunk/topia-persistence/src/main/resources/i18n/topia-persistence-fr_FR.properties
===================================================================
--- trunk/topia-persistence/src/main/resources/i18n/topia-persistence-fr_FR.properties 2010-05-10 14:33:00 UTC (rev 1950)
+++ trunk/topia-persistence/src/main/resources/i18n/topia-persistence-fr_FR.properties 2010-05-10 16:40:22 UTC (rev 1951)
@@ -20,14 +20,14 @@
topia.persistence.error.rootContext.access=Vous \u00EAtes sur le root context, vous devez ouvrir une transaction pour pouvoir acc\u00E9der aux donn\u00E9es.
topia.persistence.error.service.not.found=Le service %1$s n'est pas disponible
topia.persistence.error.service.not.retreaved=La service %1$s n'a pas pu \u00EAtre r\u00E9cup\u00E9r\u00E9 pour la raison suivante \: %2$s
-topia.persistence.error.service.unknown=Le service de clef %1$s et de classe %2$s n'est pas connu
+topia.persistence.error.service.unknown=Le service '%1$s' ayant pour classe '%2$s' n'est pas connu
topia.persistence.error.unsupported.class=La classe %1$s n'est pas support\u00E9e par ce TopiaContext, vous avez sans doute oubli\u00E9 d'ajouter son mapping
topia.persistence.error.unsupported.operation.on.closed.context=Ce contexte a \u00E9t\u00E9 ferm\u00E9, impossible de r\u00E9aliser l'op\u00E9ration %1$s
topia.persistence.error.unsupported.operation.on.root.context=Vous \u00EAtes sur le root context l'op\u00E9ration %1$s est impossible
topia.persistence.error.update.schema=Le sch\u00E9ma n'a pas pu \u00EAtre mis \u00E0 jour pour la raison suivante \: %2$s
-topia.persistence.service.loaded=Le service %1$s charg\u00E9 par %2$s
+topia.persistence.service.loaded=Service '%1$s' charg\u00E9 par '%2$s'
topia.persistence.supported.classes.for.context=Classes support\u00E9es par ce TopiaContext \: %1$s
-topia.persistence.warn.service.not.found=Le nom du service %1$s n'a pas \u00E9t\u00E9 trouv\u00E9 pour la raison suivante \: %2$s
-topia.persistence.warn.service.not.loaded=Le service de clef %1$s a un nom de service %2$ diff\u00E9rent\! (service d\u00E9sactiv\u00E9)
-topia.persistence.warn.service.not.postInit=Le service %1$s n'a pas pu \u00EAtre initialis\u00E9 (service d\u00E9sactiv\u00E9)
-topia.persistence.warn.service.not.preInit=Le service %1$s n'a pas pu \u00EAtre finalis\u00E9 (service d\u00E9sactiv\u00E9)
+topia.persistence.warn.service.not.found=Le nom du service '%1$s' n'a pas \u00E9t\u00E9 trouv\u00E9 pour la raison suivante \: %2$s
+topia.persistence.warn.service.not.loaded=Le service de cl\u00E9 '%1$s' a un nom de service '%2$s' diff\u00E9rent \! (service d\u00E9sactiv\u00E9)
+topia.persistence.warn.service.not.postInit=Le service '%1$s' n'a pas pu \u00EAtre initialis\u00E9 (service d\u00E9sactiv\u00E9)
+topia.persistence.warn.service.not.preInit=Le service '%1$s' n'a pas pu \u00EAtre finalis\u00E9 (service d\u00E9sactiv\u00E9)
Deleted: trunk/topia-persistence/src/test/java/org/nuiton/topia/framework/TestService.java
===================================================================
--- trunk/topia-persistence/src/test/java/org/nuiton/topia/framework/TestService.java 2010-05-10 14:33:00 UTC (rev 1950)
+++ trunk/topia-persistence/src/test/java/org/nuiton/topia/framework/TestService.java 2010-05-10 16:40:22 UTC (rev 1951)
@@ -1,36 +0,0 @@
-package org.nuiton.topia.framework;
-
-import org.junit.Ignore;
-
-/**
- * TestService which implements {@link TopiaService} to test loading from
- * {@link TopiaContextImplTest#testLoadServices()}.
- *
- * Created: 10 mai 2010
- *
- * @author fdesbois <fdesbois(a)codelutin.com>
- * @version $Id$
- */
-@Ignore
-public class TestService implements TopiaService {
-
- @Override
- public String getServiceName() {
- return "test";
- }
-
- @Override
- public Class<?>[] getPersistenceClasses() {
- return new Class<?>[0];
- }
-
- @Override
- public boolean preInit(TopiaContextImplementor context) {
- return true;
- }
-
- @Override
- public boolean postInit(TopiaContextImplementor context) {
- return true;
- }
-}
Modified: trunk/topia-persistence/src/test/java/org/nuiton/topia/framework/TopiaContextImplTest.java
===================================================================
--- trunk/topia-persistence/src/test/java/org/nuiton/topia/framework/TopiaContextImplTest.java 2010-05-10 14:33:00 UTC (rev 1950)
+++ trunk/topia-persistence/src/test/java/org/nuiton/topia/framework/TopiaContextImplTest.java 2010-05-10 16:40:22 UTC (rev 1951)
@@ -8,7 +8,11 @@
import org.junit.BeforeClass;
import org.junit.Test;
import org.nuiton.i18n.I18n;
+import org.nuiton.topia.TopiaNotFoundException;
+import org.nuiton.topiatest.service.FakeService;
+import org.nuiton.topiatest.service.TestService;
+import java.util.Collection;
import java.util.Locale;
import java.util.Map;
import java.util.Properties;
@@ -80,19 +84,66 @@
// TODO-fdesbois-20100510 : need integration tests for all existing topia services
}
-// @Test
-// public void testGetServices() throws Exception {
-// }
+ @Test
+ public void testGetServices() throws Exception {
+ log.info("## testGetServices");
+
+ /** PREPARE DATA **/
+ properties.setProperty("topia.service.test",
+ TestService.class.getName());
+
+ // Calling the constructor with properties will load the services
+ TopiaContextImpl context = new TopiaContextImpl(properties);
+
+ // Instantiate a child context and set its parent
+ TopiaContextImpl child = new TopiaContextImpl(context);
+
+ /** EXEC METHOD **/
+ log.info("test 1 : with child context");
+ Map<String, TopiaService> test1 = child.getServices();
+ Assert.assertEquals(1, test1.size());
+ Assert.assertTrue(test1.containsKey("test"));
+
+ log.info("test 2 : test serviceEnabled method");
+ boolean test2 = child.serviceEnabled("test");
+ Assert.assertTrue(test2);
+
+ log.info("test 3 : test getService method");
+ TopiaService test3 = child.getService("test");
+ Assert.assertEquals(TestService.class, test3.getClass());
+
+ log.info("test 4 : test serviceEnabled from class TestService");
+ boolean test4 = child.serviceEnabled(TestService.class);
+ Assert.assertTrue(test4);
+
+ log.info("test 5 : test getService from class TestService");
+ TestService test5 = child.getService(TestService.class);
+ Assert.assertNotNull(test5);
+
+ log.info("test 6 : test serviceEnabled error with class FakeService");
+ // FakeService doesn't contains property SERVICE_NAME used by
+ // serviceEnabled method
+ // Even it's properly loaded the serviceEnabled method will return false
+ properties.clear();
+ properties.setProperty("topia.service.fake",
+ FakeService.class.getName());
+ TopiaContextImpl otherContext = new TopiaContextImpl(properties);
+
+ boolean test6 = otherContext.serviceEnabled(FakeService.class);
+ Assert.assertFalse(test6);
+
+ log.info("test 7 : test getService with error TopiaNotFoundException" +
+ " : service not loaded");
+ // TestService is not loaded in otherContext
+ try {
+ TestService test7 = otherContext.getService(TestService.class);
+ } catch (Exception eee) {
+ log.error(eee.getClass().getSimpleName() + " : " + eee.getMessage());
+ Assert.assertEquals(TopiaNotFoundException.class, eee.getClass());
+ }
+ }
//
// @Test
-// public void testServiceEnabled() throws Exception {
-// }
-//
-// @Test
-// public void testGetService() throws Exception {
-// }
-//
-// @Test
// public void testGetAllServices() throws Exception {
// }
//
Added: trunk/topia-persistence/src/test/java/org/nuiton/topiatest/service/FakeService.java
===================================================================
--- trunk/topia-persistence/src/test/java/org/nuiton/topiatest/service/FakeService.java (rev 0)
+++ trunk/topia-persistence/src/test/java/org/nuiton/topiatest/service/FakeService.java 2010-05-10 16:40:22 UTC (rev 1951)
@@ -0,0 +1,40 @@
+package org.nuiton.topiatest.service;
+
+import org.nuiton.topia.framework.TopiaContextImpl;
+import org.nuiton.topia.framework.TopiaContextImplTest;
+import org.nuiton.topia.framework.TopiaContextImplementor;
+import org.nuiton.topia.framework.TopiaService;
+
+/**
+ * FakeService which implements {@link TopiaService} to test existing service
+ * from {@link TopiaContextImplTest#testGetServices()}. This fake service
+ * doesn't contains property SERVICE_NAME used by {@link
+ * TopiaContextImpl#serviceEnabled(Class)}.
+ * <p/>
+ * Created: 10 mai 2010
+ *
+ * @author fdesbois <fdesbois(a)codelutin.com>
+ * @version $Id$
+ */
+public class FakeService implements TopiaService {
+
+ @Override
+ public String getServiceName() {
+ return "fake";
+ }
+
+ @Override
+ public Class<?>[] getPersistenceClasses() {
+ return new Class<?>[0];
+ }
+
+ @Override
+ public boolean preInit(TopiaContextImplementor context) {
+ return true;
+ }
+
+ @Override
+ public boolean postInit(TopiaContextImplementor context) {
+ return true;
+ }
+}
Property changes on: trunk/topia-persistence/src/test/java/org/nuiton/topiatest/service/FakeService.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Copied: trunk/topia-persistence/src/test/java/org/nuiton/topiatest/service/TestService.java (from rev 1950, trunk/topia-persistence/src/test/java/org/nuiton/topia/framework/TestService.java)
===================================================================
--- trunk/topia-persistence/src/test/java/org/nuiton/topiatest/service/TestService.java (rev 0)
+++ trunk/topia-persistence/src/test/java/org/nuiton/topiatest/service/TestService.java 2010-05-10 16:40:22 UTC (rev 1951)
@@ -0,0 +1,43 @@
+package org.nuiton.topiatest.service;
+
+import org.junit.Ignore;
+import org.nuiton.topia.TopiaContext;
+import org.nuiton.topia.framework.TopiaContextImplTest;
+import org.nuiton.topia.framework.TopiaContextImplementor;
+import org.nuiton.topia.framework.TopiaService;
+
+/**
+ * TestService which implements {@link TopiaService} to test loading from {@link
+ * TopiaContextImplTest#testLoadServices()}.
+ * <p/>
+ * Created: 10 mai 2010
+ *
+ * @author fdesbois <fdesbois(a)codelutin.com>
+ * @version $Id$
+ */
+@Ignore
+public class TestService implements TopiaService {
+
+ /** Needed field to use {@link TopiaContext#serviceEnabled(Class)} * */
+ public static final String SERVICE_NAME = "test";
+
+ @Override
+ public String getServiceName() {
+ return SERVICE_NAME;
+ }
+
+ @Override
+ public Class<?>[] getPersistenceClasses() {
+ return new Class<?>[0];
+ }
+
+ @Override
+ public boolean preInit(TopiaContextImplementor context) {
+ return true;
+ }
+
+ @Override
+ public boolean postInit(TopiaContextImplementor context) {
+ return true;
+ }
+}
Property changes on: trunk/topia-persistence/src/test/java/org/nuiton/topiatest/service/TestService.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: trunk/topia-persistence/src/test/java/org/nuiton/topiatest/service/package-info.java
===================================================================
--- trunk/topia-persistence/src/test/java/org/nuiton/topiatest/service/package-info.java (rev 0)
+++ trunk/topia-persistence/src/test/java/org/nuiton/topiatest/service/package-info.java 2010-05-10 16:40:22 UTC (rev 1951)
@@ -0,0 +1,5 @@
+/**
+ * This package contains classes which implements {@link
+ * org.nuiton.topia.framework.TopiaService} to test services API.
+ */
+package org.nuiton.topiatest.service;
\ No newline at end of file
Property changes on: trunk/topia-persistence/src/test/java/org/nuiton/topiatest/service/package-info.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
1
0
r1950 - in trunk/topia-persistence/src: main/java/org/nuiton/topia/framework test/java/org/nuiton/topia/framework
by fdesbois@users.nuiton.org 10 May '10
by fdesbois@users.nuiton.org 10 May '10
10 May '10
Author: fdesbois
Date: 2010-05-10 16:33:00 +0200 (Mon, 10 May 2010)
New Revision: 1950
Url: http://nuiton.org/repositories/revision/topia/1950
Log:
Start test for TopiaContextImpl
Added:
trunk/topia-persistence/src/test/java/org/nuiton/topia/framework/TestService.java
trunk/topia-persistence/src/test/java/org/nuiton/topia/framework/TopiaContextImplTest.java
Modified:
trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaContextImpl.java
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaContextImpl.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaContextImpl.java 2010-05-10 13:21:44 UTC (rev 1949)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaContextImpl.java 2010-05-10 14:33:00 UTC (rev 1950)
@@ -202,6 +202,13 @@
postInitServices(services);
}
+ /**
+ * Default constructor, useful for tests.
+ */
+ protected TopiaContextImpl() {
+
+ }
+
protected Map<String, TopiaService> loadServices(Properties config) {
Map<String, TopiaService> result = new HashMap<String, TopiaService>();
// recherche des services present dans la config
@@ -222,12 +229,13 @@
key, service.getServiceName()));
}
} catch (Throwable eee) {
- if (log.isErrorEnabled()) {
- log.error(I18n._("topia.persistence.error.service.unknown",
- key, classService));
- }
+ String message =
+ I18n._("topia.persistence.error.service.unknown",
+ key, classService);
if (log.isDebugEnabled()) {
- log.debug(eee);
+ log.debug(message, eee);
+ } else if (log.isErrorEnabled()) {
+ log.error(message);
}
}
}
Added: trunk/topia-persistence/src/test/java/org/nuiton/topia/framework/TestService.java
===================================================================
--- trunk/topia-persistence/src/test/java/org/nuiton/topia/framework/TestService.java (rev 0)
+++ trunk/topia-persistence/src/test/java/org/nuiton/topia/framework/TestService.java 2010-05-10 14:33:00 UTC (rev 1950)
@@ -0,0 +1,36 @@
+package org.nuiton.topia.framework;
+
+import org.junit.Ignore;
+
+/**
+ * TestService which implements {@link TopiaService} to test loading from
+ * {@link TopiaContextImplTest#testLoadServices()}.
+ *
+ * Created: 10 mai 2010
+ *
+ * @author fdesbois <fdesbois(a)codelutin.com>
+ * @version $Id$
+ */
+@Ignore
+public class TestService implements TopiaService {
+
+ @Override
+ public String getServiceName() {
+ return "test";
+ }
+
+ @Override
+ public Class<?>[] getPersistenceClasses() {
+ return new Class<?>[0];
+ }
+
+ @Override
+ public boolean preInit(TopiaContextImplementor context) {
+ return true;
+ }
+
+ @Override
+ public boolean postInit(TopiaContextImplementor context) {
+ return true;
+ }
+}
Property changes on: trunk/topia-persistence/src/test/java/org/nuiton/topia/framework/TestService.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: trunk/topia-persistence/src/test/java/org/nuiton/topia/framework/TopiaContextImplTest.java
===================================================================
--- trunk/topia-persistence/src/test/java/org/nuiton/topia/framework/TopiaContextImplTest.java (rev 0)
+++ trunk/topia-persistence/src/test/java/org/nuiton/topia/framework/TopiaContextImplTest.java 2010-05-10 14:33:00 UTC (rev 1950)
@@ -0,0 +1,230 @@
+package org.nuiton.topia.framework;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.nuiton.i18n.I18n;
+
+import java.util.Locale;
+import java.util.Map;
+import java.util.Properties;
+
+/**
+ * Created: 10 mai 2010
+ *
+ * @author fdesbois <fdesbois(a)codelutin.com>
+ * @version $Id$
+ */
+public class TopiaContextImplTest {
+
+ private static final Log log =
+ LogFactory.getLog(TopiaContextImplTest.class);
+
+ protected Properties properties = new Properties();
+
+ @BeforeClass
+ public static void setUpClass() throws Exception {
+ I18n.init(Locale.FRENCH);
+ }
+
+ @Before
+ public void setUp() throws Exception {
+ properties.clear();
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ }
+
+ @Test
+ public void testLoadServices() throws Exception {
+ log.info("## testLoadServices");
+
+ /** PREPARE DATA **/
+ properties.setProperty("topia.service.test",
+ TestService.class.getName());
+
+ TopiaContextImpl context = new TopiaContextImpl();
+
+ /** EXEC METHOD **/
+ log.info("test 1 : load a simple TestService from properties");
+ Map<String, TopiaService> results = context.loadServices(properties);
+ Assert.assertEquals(1, results.size());
+ Assert.assertTrue(results.containsKey("test"));
+ TopiaService service = results.get("test");
+ Assert.assertEquals(TestService.class, service.getClass());
+
+ log.info("test 2 : load with wrong key : will display a WARN");
+ properties.clear();
+
+ properties.setProperty("topia.service.fake",
+ TestService.class.getName());
+
+ results = context.loadServices(properties);
+ Assert.assertEquals(0, results.size());
+ Assert.assertFalse(results.containsKey("fake"));
+
+ log.info("test 3 : load with fake service name : will display an ERROR");
+ properties.clear();
+
+ properties.setProperty("topia.service.test", "FAKE");
+
+ results = context.loadServices(properties);
+ Assert.assertEquals(0, results.size());
+ Assert.assertFalse(results.containsKey("test"));
+
+ // TODO-fdesbois-20100510 : need integration tests for all existing topia services
+ }
+
+// @Test
+// public void testGetServices() throws Exception {
+// }
+//
+// @Test
+// public void testServiceEnabled() throws Exception {
+// }
+//
+// @Test
+// public void testGetService() throws Exception {
+// }
+//
+// @Test
+// public void testGetAllServices() throws Exception {
+// }
+//
+// @Test
+// public void testGetChildContext() throws Exception {
+// }
+//
+// @Test
+// public void testRemoveChildContext() throws Exception {
+// }
+//
+// @Test
+// public void testGetParentContext() throws Exception {
+// }
+//
+// @Test
+// public void testGetRootContext() throws Exception {
+// }
+//
+// @Test
+// public void testGetConfig() throws Exception {
+// }
+//
+// @Test
+// public void testCreateSchema() throws Exception {
+// }
+//
+// @Test
+// public void testShowCreateSchema() throws Exception {
+// }
+//
+// @Test
+// public void testUpdateSchema() throws Exception {
+// }
+//
+// @Test
+// public void testGetHibernate() throws Exception {
+// }
+//
+// @Test
+// public void testGetHibernateFactory() throws Exception {
+// }
+//
+// @Test
+// public void testGetHibernateConfiguration() throws Exception {
+// }
+//
+// @Test
+// public void testGetDAO() throws Exception {
+// }
+//
+// @Test
+// public void testBeginTransaction() throws Exception {
+// }
+//
+// @Test
+// public void testCommitTransaction() throws Exception {
+// }
+//
+// @Test
+// public void testRollbackTransaction() throws Exception {
+// }
+//
+// @Test
+// public void testCloseContext() throws Exception {
+// }
+//
+// @Test
+// public void testIsClosed() throws Exception {
+// }
+//
+// @Test
+// public void testFindByTopiaId() throws Exception {
+// }
+//
+// @Test
+// public void testFind() throws Exception {
+// }
+//
+// @Test
+// public void testFind2() throws Exception {
+// }
+//
+// @Test
+// public void testExecute() throws Exception {
+// }
+//
+// @Test
+// public void testAdd() throws Exception {
+// }
+//
+// @Test
+// public void testImportXML() throws Exception {
+// }
+//
+// @Test
+// public void testExportXML() throws Exception {
+// }
+//
+// @Test
+// public void testReplicate() throws Exception {
+// }
+//
+// @Test
+// public void testReplicateEntity() throws Exception {
+// }
+//
+// @Test
+// public void testReplicateEntities() throws Exception {
+// }
+//
+// @Test
+// public void testGetFiresSupport() throws Exception {
+// }
+//
+// @Test
+// public void testBackup() throws Exception {
+// }
+//
+// @Test
+// public void testRestore() throws Exception {
+// }
+//
+// @Test
+// public void testClear() throws Exception {
+// }
+//
+// @Test
+// public void testGetPersistenceClasses() throws Exception {
+// }
+//
+// @Test
+// public void testIsSchemaExist() throws Exception {
+// }
+}
Property changes on: trunk/topia-persistence/src/test/java/org/nuiton/topia/framework/TopiaContextImplTest.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
1
0
r1949 - in trunk/topia-persistence/src: main/java/org/nuiton/topia/generator main/java/org/nuiton/topia/persistence test/java/org/nuiton/topia/persistence
by fdesbois@users.nuiton.org 10 May '10
by fdesbois@users.nuiton.org 10 May '10
10 May '10
Author: fdesbois
Date: 2010-05-10 15:21:44 +0200 (Mon, 10 May 2010)
New Revision: 1949
Url: http://nuiton.org/repositories/revision/topia/1949
Log:
- Evo #592 : add exist methods in DAO. CAREFUL !! Rename existNaturalId generated by existByNaturalId.
- Reorganize methods order in TopiaDAO and TopiaDAOImpl
Modified:
trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/DAOAbstractTransformer.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAO.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAOImpl.java
trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/NaturalIdTest.java
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/DAOAbstractTransformer.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/DAOAbstractTransformer.java 2010-05-10 13:13:04 UTC (rev 1948)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/DAOAbstractTransformer.java 2010-05-10 13:21:44 UTC (rev 1949)
@@ -833,9 +833,9 @@
"findByNaturalId", "E", ObjectModelModifier.PUBLIC);
addException(findByNaturalId, TopiaException.class);
- ObjectModelOperation existNaturalId = addOperation(result,
- "existNaturalId", "boolean", ObjectModelModifier.PUBLIC);
- addException(existNaturalId, TopiaException.class);
+ ObjectModelOperation existByNaturalId = addOperation(result,
+ "existByNaturalId", "boolean", ObjectModelModifier.PUBLIC);
+ addException(existByNaturalId, TopiaException.class);
ObjectModelOperation create = addOperation(result,
"create", "E", ObjectModelModifier.PUBLIC);
@@ -843,23 +843,23 @@
// used for calling findByProperties in findByNaturalId
String searchProperties = "";
- // used for calling findByNaturalId in existNaturalId
+ // used for calling findByNaturalId in existByNaturalId
String params = "";
String clazzName = clazz.getName();
for (ObjectModelAttribute attr : props) {
String propName = attr.getName();
// add property as param in both methods
addParameter(findByNaturalId, attr.getType(), propName);
- addParameter(existNaturalId, attr.getType(), propName);
+ addParameter(existByNaturalId, attr.getType(), propName);
addParameter(create, attr.getType(), propName);
searchProperties +=
", " + clazzName + '.' + getConstantName(propName) +
", " + propName;
- params += ", " + propName;
+ //params += ", " + propName;
}
searchProperties = searchProperties.substring(2);
- params = params.substring(2);
+ //params = params.substring(2);
setOperationBody(findByNaturalId, ""
/*{
@@ -867,9 +867,9 @@
}*/
);
- setOperationBody(existNaturalId, ""
+ setOperationBody(existByNaturalId, ""
/*{
- return findByNaturalId(<%=params%>) != null;
+ return existByProperties(<%=searchProperties%>);
}*/
);
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAO.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAO.java 2010-05-10 13:13:04 UTC (rev 1948)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAO.java 2010-05-10 13:21:44 UTC (rev 1949)
@@ -129,6 +129,59 @@
void rollbackTransaction() throws TopiaException;
/**
+ * Find usages of the given {@code entity} in the entities of the given
+ * {@code type}.
+ *
+ * @param type the type of entity to search
+ * @param entity the entity
+ * @param <U> tthe type of entity to search
+ * @return the list of entities of the given type which uses the given
+ * entity
+ * @throws TopiaException if any problem while getting data
+ * @since 2.3.0
+ */
+ <U extends TopiaEntity> List<U> findUsages(Class<U> type, E entity)
+ throws TopiaException;
+
+ /**
+ * Find all usages of the given {@code entity}.
+ *
+ * @param entity the entity
+ * @return the dictionnary of usages of the given entities (keys are entity
+ * usage container, values are the list of this type of entity to
+ * use the given entity).
+ * @throws TopiaException if any pb while getting data
+ * @since 2.3.0
+ */
+
+ Map<Class<? extends TopiaEntity>, List<? extends TopiaEntity>> findAllUsages(E entity)
+ throws TopiaException;
+
+ /**
+ * Retourne les permissions a verifier pour l'acces a l'entite pour le
+ * service Taas.
+ *
+ * @param topiaId topiaId d'une entite
+ * @param actions encoded actions
+ * @return la liste des permissions
+ * @throws TopiaException if any pb while getting datas
+ */
+ List<Permission> getRequestPermission(String topiaId, int actions)
+ throws TopiaException;
+
+ /* Adders */
+
+ void addTopiaEntityListener(TopiaEntityListener listener);
+
+ void addTopiaEntityVetoable(TopiaEntityVetoable vetoable);
+
+ /* Removers */
+
+ void removeTopiaEntityListener(TopiaEntityListener listener);
+
+ void removeTopiaEntityVetoable(TopiaEntityVetoable vetoable);
+
+ /**
* Construit une nouvelle instance de l'objet géré par ce DAO
*
* @param properties la liste des propriétés que doit avoir l'objet créé les
@@ -183,35 +236,13 @@
*/
void delete(E e) throws TopiaException;
- E findByTopiaId(String k) throws TopiaException;
-
- List<E> findAll() throws TopiaException;
-
/**
- * Recuperation de tous les ids en base pour le type d'entite du dao.
- *
- * @return la liste de tous les ids
- * @throws TopiaException si pb en base
- */
- List<String> findAllIds() throws TopiaException;
-
- List<E> findAllWithOrder(String... propertyNames)
- throws TopiaException;
-
- /**
- * Compte le nombre d'entites en base
- *
- * @return le nombre total d'entites existantes
- * @throws TopiaException if any pb while getting datas
- */
- long size() throws TopiaException;
-
- /**
* Crée une requete basé sur l'entité lié au DAO. Résultat attendu : "FROM
* E"
*
* @return une nouvelle TopiaQuery vide. (uniquement avec le From sur le
* type d'entité)
+ * @since 2.3
*/
TopiaQuery createQuery();
@@ -224,10 +255,32 @@
* @param entityAlias alias permettant de manipuler l'entité dans la
* requête
* @return une nouvelle TopiaQuery
+ * @since 2.3
*/
TopiaQuery createQuery(String entityAlias);
+ @Deprecated
+ E findByTopiaId(String k) throws TopiaException;
+
+ E findById(String k) throws TopiaException;
+
+ E findByProperty(String propertyName, Object value)
+ throws TopiaException;
+
/**
+ * @param propertyName le nom de la propriété
+ * @param value la valeur à tester
+ * @param others les autres proprietes doivent aller par 2
+ * propertyName, value
+ * @return l'entité trouvé
+ * @throws TopiaException if any pb while getting datas
+ */
+ E findByProperties(String propertyName, Object value,
+ Object... others) throws TopiaException;
+
+ E findByProperties(Map<String, Object> properties) throws TopiaException;
+
+ /**
* Execute une requête basé sur l'entité du DAO. Permet de récupérer une
* entité correspondant à la requête.
*
@@ -236,10 +289,38 @@
* n'a été trouvée
* @throws TopiaException if any pb while getting datas
* @see TopiaQuery#executeToEntity(TopiaContext, Class)
+ * @since 2.3
*/
E findByQuery(TopiaQuery query) throws TopiaException;
+ List<E> findAll() throws TopiaException;
+
/**
+ * Recuperation de tous les ids en base pour le type d'entite du dao.
+ *
+ * @return la liste de tous les ids
+ * @throws TopiaException si pb en base
+ */
+ List<String> findAllIds() throws TopiaException;
+
+ List<E> findAllByProperty(String propertyName, Object value)
+ throws TopiaException;
+
+ /**
+ * @param propertyName le nom de la propriété
+ * @param value la valeur à tester
+ * @param others les autres proprietes doivent aller par 2
+ * propertyName, value
+ * @return l'entité trouvé
+ * @throws TopiaException if any pb while getting datas
+ */
+ List<E> findAllByProperties(String propertyName, Object value,
+ Object... others) throws TopiaException;
+
+ List<E> findAllByProperties(Map<String, Object> properties)
+ throws TopiaException;
+
+ /**
* Execute une requête basé sur l'entité du DAO. Permet de récupérer une
* liste d'entités correspondant à la requête.
*
@@ -247,6 +328,7 @@
* @return la liste d'entités correspondant à la recherche
* @throws TopiaException if any pb while getting datas
* @see TopiaQuery#executeToEntityList(TopiaContext, Class)
+ * @since 2.3
*/
List<E> findAllByQuery(TopiaQuery query) throws TopiaException;
@@ -259,6 +341,7 @@
* @return la map d'entités correspondant à la recherche
* @throws TopiaException if any pb while getting datas
* @see TopiaQuery#executeToEntityMap(TopiaContext, Class)
+ * @since 2.3
*/
Map<String, E> findAllMappedByQuery(TopiaQuery query) throws TopiaException;
@@ -274,11 +357,59 @@
* @return la map d'entités correspondant à la recherche
* @throws TopiaException if any pb while getting datas
* @see TopiaQuery#executeToEntityMap(TopiaContext, Class)
+ * @since 2.3
*/
<K> Map<K, E> findAllMappedByQuery(TopiaQuery query,
String keyName, Class<K> keyClass) throws TopiaException;
+ List<E> findAllWithOrder(String... propertyNames)
+ throws TopiaException;
+
/**
+ * Check the existence of an entity with technical {@code id}.
+ *
+ * @param id unique id of the entity to test existence.
+ * @return true if entity exists, false otherwise
+ * @throws TopiaException for Topia errors
+ * @since 2.4
+ */
+ boolean existById(String id) throws TopiaException;
+
+ /**
+ * Check the existence of an entity with {@code propertyName} with
+ * {@code propertyValue}. {@code others} properties can be added to test
+ * existence.
+ *
+ * @param propertyName first property name to test existence
+ * @param propertyValue first property value to test existence
+ * @param others altern propertyName and propertyValue
+ * @return true if entity exists, false otherwise
+ * @throws TopiaException for Topia errors
+ * @since 2.4
+ */
+ boolean existByProperties(String propertyName, Object propertyValue,
+ Object... others) throws TopiaException;
+
+
+ /**
+ * Check the existence of an entity using a {@code query}.
+ *
+ * @param query query used to test existence
+ * @return true if entity exists, false otherwise
+ * @throws TopiaException
+ * @since 2.4
+ */
+ boolean existByQuery(TopiaQuery query) throws TopiaException;
+
+ /**
+ * Compte le nombre d'entites en base
+ *
+ * @return le nombre total d'entites existantes
+ * @throws TopiaException if any pb while getting datas
+ */
+ long size() throws TopiaException;
+
+ /**
* Recherche la classe en utilisant la cle naturelle, chaque champs de la
* cle naturelle est une entre de la map passe en argument.
*
@@ -299,39 +430,6 @@
*/
E findByPrimaryKey(Object... k) throws TopiaException;
- E findByProperty(String propertyName, Object value)
- throws TopiaException;
-
- /**
- * @param propertyName le nom de la propriété
- * @param value la valeur à tester
- * @param others les autres proprietes doivent aller par 2
- * propertyName, value
- * @return l'entité trouvé
- * @throws TopiaException if any pb while getting datas
- */
- E findByProperties(String propertyName, Object value,
- Object... others) throws TopiaException;
-
- E findByProperties(Map<String, Object> properties) throws TopiaException;
-
- List<E> findAllByProperty(String propertyName, Object value)
- throws TopiaException;
-
- /**
- * @param propertyName le nom de la propriété
- * @param value la valeur à tester
- * @param others les autres proprietes doivent aller par 2
- * propertyName, value
- * @return l'entité trouvé
- * @throws TopiaException if any pb while getting datas
- */
- List<E> findAllByProperties(String propertyName, Object value,
- Object... others) throws TopiaException;
-
- List<E> findAllByProperties(Map<String, Object> properties)
- throws TopiaException;
-
/*
* Find Contains
*/
@@ -396,58 +494,5 @@
List<E> findAllContainsProperties(String propertyName,
Collection<?> values, Object... others)
throws TopiaException;
-
- /**
- * Find usages of the given {@code entity} in the entities of the given
- * {@code type}.
- *
- * @param type the type of entity to search
- * @param entity the entity
- * @param <U> tthe type of entity to search
- * @return the list of entities of the given type which uses the given
- * entity
- * @throws TopiaException if any problem while getting data
- * @since 2.3.0
- */
- <U extends TopiaEntity> List<U> findUsages(Class<U> type, E entity)
- throws TopiaException;
-
- /**
- * Find all usages of the given {@code entity}.
- *
- * @param entity the entity
- * @return the dictionnary of usages of the given entities (keys are entity
- * usage container, values are the list of this type of entity to
- * use the given entity).
- * @throws TopiaException if any pb while getting data
- * @since 2.3.0
- */
-
- Map<Class<? extends TopiaEntity>, List<? extends TopiaEntity>> findAllUsages(E entity)
- throws TopiaException;
-
- /**
- * Retourne les permissions a verifier pour l'acces a l'entite pour le
- * service Taas.
- *
- * @param topiaId topiaId d'une entite
- * @param actions encoded actions
- * @return la liste des permissions
- * @throws TopiaException if any pb while getting datas
- */
- List<Permission> getRequestPermission(String topiaId, int actions)
- throws TopiaException;
-
- /* Adders */
-
- void addTopiaEntityListener(TopiaEntityListener listener);
-
- void addTopiaEntityVetoable(TopiaEntityVetoable vetoable);
-
- /* Removers */
-
- void removeTopiaEntityListener(TopiaEntityListener listener);
-
- void removeTopiaEntityVetoable(TopiaEntityVetoable vetoable);
} //TopiaDAO
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAOImpl.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAOImpl.java 2010-05-10 13:13:04 UTC (rev 1948)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAOImpl.java 2010-05-10 13:21:44 UTC (rev 1949)
@@ -274,7 +274,94 @@
public void rollbackTransaction() throws TopiaException {
}
+ /**
+ * private method because this is hibernate specific method and we don't
+ * want expose it
+ *
+ * @return the meta-data of the entity
+ * @throws TopiaException if any pb
+ */
+ private ClassMetadata getClassMetadata() throws TopiaException {
+ ClassMetadata meta = getContext().getHibernateFactory()
+ .getClassMetadata(entityClass);
+ if (meta == null) {
+ meta = getContext().getHibernateFactory().getClassMetadata(
+ entityClass.getName() + "Impl");
+ }
+ return meta;
+ }
+
@Override
+ public <U extends TopiaEntity> List<U> findUsages(Class<U> type, E e)
+ throws TopiaException {
+ // must be implemented by specialized dao
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public Map<Class<? extends TopiaEntity>, List<? extends TopiaEntity>> findAllUsages(E e)
+ throws TopiaException {
+ // must be implemented by specialized dao
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public List<Permission> getRequestPermission(String topiaId, int actions)
+ throws TopiaException {
+ return null;
+ }
+
+ @Override
+ public void addTopiaEntityListener(TopiaEntityListener listener) {
+ getContext().addTopiaEntityListener(entityClass, listener);
+ }
+
+ @Override
+ public void addTopiaEntityVetoable(TopiaEntityVetoable vetoable) {
+ getContext().addTopiaEntityVetoable(entityClass, vetoable);
+ }
+
+ @Override
+ public void removeTopiaEntityListener(TopiaEntityListener listener) {
+ getContext().removeTopiaEntityListener(entityClass, listener);
+ }
+
+ @Override
+ public void removeTopiaEntityVetoable(TopiaEntityVetoable vetoable) {
+ getContext().removeTopiaEntityVetoable(entityClass, vetoable);
+ }
+
+ /**
+ * Renvoie la Session contenue dans le contexte
+ *
+ * @return hibernate session
+ * @throws TopiaException if any pb
+ */
+ private Session getSession() throws TopiaException {
+ return getContext().getHibernate();
+ }
+
+ @Override
+ public E create(E entity) throws TopiaException {
+
+ // TODO EC-20100322 this code may be merged with other create() methods
+ try {
+ // first set topiaId
+ String topiaId = TopiaId.create(entityClass);
+ TopiaEntityAbstract entityAbstract = (TopiaEntityAbstract) entity;
+ entityAbstract.setTopiaId(topiaId);
+ entityAbstract.setTopiaContext(getContext());
+
+ // save entity
+ getSession().save(entity);
+ getContext().getFiresSupport().warnOnUpdateEntity(entity);
+ return entity;
+ } catch (HibernateException eee) {
+ throw new TopiaException(eee);
+ }
+ }
+
+ @Override
public E create(Object... properties) throws TopiaException {
Map<String, Object> map = new HashMap<String, Object>();
Object propertyName = null;
@@ -300,107 +387,279 @@
return result;
}
+ /**
+ * Cette methode appelle fireVetoableCreate et fireOnCreated Si vous la
+ * surchargé, faites attention a appeler le super ou a appeler vous aussi
+ * ces deux methodes.
+ */
@Override
- public E findByPrimaryKey(Map<String, Object> keys)
- throws TopiaException {
+ public E create(Map<String, Object> properties) throws TopiaException {
+ E result = newInstance();
+
+ // TODO reflechir s'il ne faudrait pas creer l'id avant l'event precedent
+ // reflechir toujours dans un context on les E pourrait ne pas
+ // etre des TopiaEntity
+ if (result instanceof TopiaEntity) {
+ String topiaId = TopiaId.create(entityClass);
+ TopiaEntityAbstract entity = (TopiaEntityAbstract) result;
+ entity.setTopiaId(topiaId);
+ entity.setTopiaContext(getContext());
+ }
try {
- // we used hibernate meta information for all persistence type
- // it's more easy than create different for all persistence
- ClassMetadata meta = getClassMetadata();
- if (meta.hasNaturalIdentifier()) {
- E result = findByProperties(keys);
- return result;
+ for (Map.Entry<String, Object> e : properties.entrySet()) {
+ String propertyName = e.getKey();
+ Object value = e.getValue();
+ PropertyUtils.setProperty(result, propertyName, value);
}
- } catch (HibernateException eee) {
- throw new TopiaException(eee);
+ } catch (IllegalAccessException eee) {
+ throw new IllegalArgumentException(
+ "Can't put properties on new Object", eee);
+ } catch (InvocationTargetException eee) {
+ throw new IllegalArgumentException(
+ "Can't put properties on new Object", eee);
+ } catch (NoSuchMethodException eee) {
+ throw new IllegalArgumentException(
+ "Can't put properties on new Object", eee);
}
- throw new TopiaException("La classe " + entityClass.getName()
- + " n'a pas de cle primaire naturelle");
+ // TODO-fdesbois-20100507 : need to be removed for 2.5 version
+ result.postCreate();
+ // on fait un save maintenant, car puisqu'on a creer l'entity au
+ // travers du DAO, on s'attend a l'avoir a disposition tout de
+ // suite pour les requetes sans avoir a faire un update dessus
+ getSession().save(result);
+ getContext().getFiresSupport().warnOnCreateEntity(result);
+ return result;
}
- /**
- * private method because this is hibernate specific method and we don't
- * want expose it
- *
- * @return the meta-data of the entity
- * @throws TopiaException if any pb
- */
- private ClassMetadata getClassMetadata() throws TopiaException {
- ClassMetadata meta = getContext().getHibernateFactory()
- .getClassMetadata(entityClass);
- if (meta == null) {
- meta = getContext().getHibernateFactory().getClassMetadata(
- entityClass.getName() + "Impl");
+ @Override
+ public E update(E e) throws TopiaException {
+ try {
+ getSession().saveOrUpdate(e);
+ getContext().getFiresSupport().warnOnUpdateEntity(e);
+ return e;
+ } catch (HibernateException eee) {
+ throw new TopiaException(eee);
}
- return meta;
}
@Override
- public E findByPrimaryKey(Object... k) throws TopiaException {
- // TODO pour une meilleur gestion des problemes a la compilation
- // mettre un premier couple (propName, value) en argument ca evitera
- // de pouvoir appeler cette methode sans argument
+ public void delete(E e) throws TopiaException {
try {
- ClassMetadata meta = getClassMetadata();
- if (meta.hasNaturalIdentifier()) {
- int[] ikeys = meta.getNaturalIdentifierProperties();
- String[] pnames = meta.getPropertyNames();
-
- Map<String, Object> keys = new HashMap<String, Object>();
- for (int ikey : ikeys) {
- keys.put(pnames[ikey], k[ikey]);
- }
-
- E result = findByProperties(keys);
- return result;
- }
+ getSession().delete(e);
+ getContext().getFiresSupport().warnOnDeleteEntity(e);
} catch (HibernateException eee) {
throw new TopiaException(eee);
}
- throw new TopiaException("La classe " + entityClass.getName()
- + " n'a pas de cle primaire naturelle");
+ }
+ @Override
+ public TopiaQuery createQuery() {
+ return new TopiaQuery(this);
}
@Override
- public E findByProperties(String propertyName, Object value,
- Object... others) throws TopiaException {
+ public TopiaQuery createQuery(String entityAlias) {
+ return new TopiaQuery(this, entityAlias);
+ }
+
+ @Override
+ public E findByTopiaId(String id) throws TopiaException {
+ return findById(id);
+ }
+
+ @Override
+ public E findById(String id) throws TopiaException {
+ return findByQuery(createQuery().add(TopiaEntity.ID, id));
+ }
+
+ @Override
+ public E findByProperty(String propertyName, Object value)
+ throws TopiaException {
Map<String, Object> properties = new HashMap<String, Object>();
properties.put(propertyName, value);
- Object name = null;
- for (int i = 0; i < others.length;) {
- try {
- name = others[i++];
- value = others[i++];
- properties.put((String) name, value);
- } catch (ClassCastException eee) {
- throw new IllegalArgumentException(
- "Les noms des propriétés doivent être des chaines et " +
- "non pas " + propertyName.getClass().getName(),
- eee);
- } catch (ArrayIndexOutOfBoundsException eee) {
- throw new IllegalArgumentException(
- "Le nombre d'argument n'est pas un nombre pair: "
- + (others.length + 2)
- + " La dernière propriété était: " + name, eee);
- }
- }
E result = findByProperties(properties);
return result;
}
@Override
+ public E findByProperties(String propertyName, Object value,
+ Object... others) throws TopiaException {
+// Map<String, Object> properties = new HashMap<String, Object>();
+// properties.put(propertyName, value);
+// Object name = null;
+// for (int i = 0; i < others.length;) {
+// try {
+// name = others[i++];
+// value = others[i++];
+// properties.put((String) name, value);
+// } catch (ClassCastException eee) {
+// throw new IllegalArgumentException(
+// "Les noms des propriétés doivent être des chaines et " +
+// "non pas " + propertyName.getClass().getName(),
+// eee);
+// } catch (ArrayIndexOutOfBoundsException eee) {
+// throw new IllegalArgumentException(
+// "Le nombre d'argument n'est pas un nombre pair: "
+// + (others.length + 2)
+// + " La dernière propriété était: " + name, eee);
+// }
+// }
+ Map<String, Object> properties =
+ convertPropertiesArrayToMap(propertyName, value, others);
+ E result = findByProperties(properties);
+ return result;
+ }
+
+ @Override
+ public E findByProperties(Map<String, Object> properties)
+ throws TopiaException {
+ return findByQuery(createQuery().add(properties));
+ }
+
+ @Override
+ public E findByQuery(TopiaQuery query) throws TopiaException {
+ return query.executeToEntity(context, getEntityClass());
+ }
+
+ @Override
+ public List<E> findAll() throws TopiaException {
+ return findAllByQuery(createQuery());
+ }
+
+ @Override
+ public List<String> findAllIds() throws TopiaException {
+ return createQuery().setSelect(TopiaEntity.ID).execute();
+ }
+
+ @Override
+ public List<E> findAllByProperty(String propertyName, Object value)
+ throws TopiaException {
+ Map<String, Object> properties =
+ convertPropertiesArrayToMap(propertyName, value);
+ List<E> result = findAllByProperties(properties);
+ return result;
+ }
+
+ @Override
public List<E> findAllByProperties(String propertyName, Object value,
Object... others) throws TopiaException {
+// Map<String, Object> properties = new HashMap<String, Object>();
+// properties.put(propertyName, value);
+// Object name = null;
+// for (int i = 0; i < others.length;) {
+// try {
+// name = others[i++];
+// value = others[i++];
+// properties.put((String) name, value);
+// } catch (ClassCastException eee) {
+// throw new IllegalArgumentException(
+// "Les noms des propriétés doivent être des chaines et " +
+// "non pas " + propertyName.getClass().getName(),
+// eee);
+// } catch (ArrayIndexOutOfBoundsException eee) {
+// throw new IllegalArgumentException(
+// "Le nombre d'argument n'est pas un nombre pair: "
+// + (others.length + 2)
+// + " La dernière propriété était: " + name, eee);
+// }
+// }
+ Map<String, Object> properties =
+ convertPropertiesArrayToMap(propertyName, value, others);
+ List<E> result = findAllByProperties(properties);
+ return result;
+ }
+
+ @Override
+ public List<E> findAllByProperties(Map<String, Object> properties)
+ throws TopiaException {
+ return findAllByQuery(createQuery().add(properties));
+ }
+
+ @Override
+ public List<E> findAllByQuery(TopiaQuery query) throws TopiaException {
+ return query.executeToEntityList(context, getEntityClass());
+ }
+
+ @Override
+ public Map<String, E> findAllMappedByQuery(TopiaQuery query)
+ throws TopiaException {
+ return query.executeToEntityMap(context, getEntityClass());
+ }
+
+ @Override
+ public <K> Map<K, E> findAllMappedByQuery(TopiaQuery query, String keyName,
+ Class<K> keyClass)
+ throws TopiaException {
+ return query.executeToEntityMap(context, getEntityClass(), keyName,
+ keyClass);
+ }
+
+ @Override
+ public List<E> findAllWithOrder(String... propertyNames)
+ throws TopiaException {
+ TopiaQuery query = createQuery().addOrder(propertyNames);
+ return findAllByQuery(query);
+ }
+
+ @Override
+ public boolean existById(String id) throws TopiaException {
+ boolean result = existByProperties(TopiaEntity.ID, id);
+ return result;
+ }
+
+ @Override
+ public boolean existByProperties(String propertyName, Object propertyValue,
+ Object... others) throws TopiaException {
+ Map<String, Object> properties =
+ convertPropertiesArrayToMap(propertyName, propertyValue, others);
+ TopiaQuery query = createQuery().add(properties);
+ boolean result = existByQuery(query);
+ return result;
+ }
+
+ @Override
+ public boolean existByQuery(TopiaQuery query) throws TopiaException {
+ int count = query.executeCount();
+ boolean result = count > 0;
+ return result;
+ }
+
+ /**
+ * Count number of existing entities using {@link
+ * TopiaQuery#executeCount(TopiaContext)}
+ *
+ * @return a long for the number of entities in database
+ */
+ @Override
+ public long size() throws TopiaException {
+ return createQuery().executeCount(context);
+ }
+
+ /**
+ * Convert a properties array to a proper map used to find entities in
+ * methods {@link #findByProperties(String, Object, Object...)} and {@link
+ * #findAllByProperties(String, Object, Object...)}.
+ *
+ * @param propertyName first property name to test existence
+ * @param propertyValue first property value to test existence
+ * @param others altern propertyName and propertyValue
+ * @return a Map with properties, propertyName as key.
+ * @throws IllegalArgumentException for ClassCast or ArrayIndexOutOfBounds
+ * errors
+ */
+ private Map<String, Object> convertPropertiesArrayToMap(String propertyName,
+ Object propertyValue,
+ Object... others)
+ throws IllegalArgumentException {
Map<String, Object> properties = new HashMap<String, Object>();
- properties.put(propertyName, value);
+ properties.put(propertyName, propertyValue);
Object name = null;
for (int i = 0; i < others.length;) {
try {
name = others[i++];
- value = others[i++];
- properties.put((String) name, value);
+ propertyValue = others[i++];
+ properties.put((String) name, propertyValue);
} catch (ClassCastException eee) {
throw new IllegalArgumentException(
"Les noms des propriétés doivent être des chaines et " +
@@ -413,11 +672,56 @@
+ " La dernière propriété était: " + name, eee);
}
}
- List<E> result = findAllByProperties(properties);
- return result;
+ return properties;
}
@Override
+ public E findByPrimaryKey(Map<String, Object> keys)
+ throws TopiaException {
+ try {
+ // we used hibernate meta information for all persistence type
+ // it's more easy than create different for all persistence
+ ClassMetadata meta = getClassMetadata();
+ if (meta.hasNaturalIdentifier()) {
+ E result = findByProperties(keys);
+ return result;
+ }
+ } catch (HibernateException eee) {
+ throw new TopiaException(eee);
+ }
+ throw new TopiaException("La classe " + entityClass.getName()
+ + " n'a pas de cle primaire naturelle");
+
+ }
+
+ @Override
+ public E findByPrimaryKey(Object... k) throws TopiaException {
+ // TODO pour une meilleur gestion des problemes a la compilation
+ // mettre un premier couple (propName, value) en argument ca evitera
+ // de pouvoir appeler cette methode sans argument
+ try {
+ ClassMetadata meta = getClassMetadata();
+ if (meta.hasNaturalIdentifier()) {
+ int[] ikeys = meta.getNaturalIdentifierProperties();
+ String[] pnames = meta.getPropertyNames();
+
+ Map<String, Object> keys = new HashMap<String, Object>();
+ for (int ikey : ikeys) {
+ keys.put(pnames[ikey], k[ikey]);
+ }
+
+ E result = findByProperties(keys);
+ return result;
+ }
+ } catch (HibernateException eee) {
+ throw new TopiaException(eee);
+ }
+ throw new TopiaException("La classe " + entityClass.getName()
+ + " n'a pas de cle primaire naturelle");
+
+ }
+
+ @Override
public E findContainsProperties(Map<String, Collection<?>> properties)
throws TopiaException {
List<E> results = findAllContainsProperties(properties);
@@ -550,359 +854,22 @@
return result;
}
- @Override
- public List<E> findAllByProperty(String propertyName, Object value)
- throws TopiaException {
- Map<String, Object> properties = new HashMap<String, Object>();
- properties.put(propertyName, value);
- List<E> result = findAllByProperties(properties);
- return result;
- }
-
- @Override
- public E findByProperty(String propertyName, Object value)
- throws TopiaException {
- Map<String, Object> properties = new HashMap<String, Object>();
- properties.put(propertyName, value);
- E result = findByProperties(properties);
- return result;
- }
-
- @Override
- public <U extends TopiaEntity> List<U> findUsages(Class<U> type, E e)
- throws TopiaException {
- // must be implemented by specialized dao
- throw new UnsupportedOperationException();
- }
-
- @Override
- public Map<Class<? extends TopiaEntity>, List<? extends TopiaEntity>> findAllUsages(E e)
- throws TopiaException {
- // must be implemented by specialized dao
- throw new UnsupportedOperationException();
- }
-
- @Override
- public void addTopiaEntityListener(TopiaEntityListener listener) {
- getContext().addTopiaEntityListener(entityClass, listener);
- }
-
- @Override
- public void addTopiaEntityVetoable(TopiaEntityVetoable vetoable) {
- getContext().addTopiaEntityVetoable(entityClass, vetoable);
- }
-
- @Override
- public void removeTopiaEntityListener(TopiaEntityListener listener) {
- getContext().removeTopiaEntityListener(entityClass, listener);
- }
-
- @Override
- public void removeTopiaEntityVetoable(TopiaEntityVetoable vetoable) {
- getContext().removeTopiaEntityVetoable(entityClass, vetoable);
- }
-
- @Override
- public E create(E entity) throws TopiaException {
-
- // TODO EC-20100322 this code may be merged with other create() methods
- try {
- // first set topiaId
- String topiaId = TopiaId.create(entityClass);
- TopiaEntityAbstract entityAbstract = (TopiaEntityAbstract) entity;
- entityAbstract.setTopiaId(topiaId);
- entityAbstract.setTopiaContext(getContext());
-
- // save entity
- getSession().save(entity);
- getContext().getFiresSupport().warnOnUpdateEntity(entity);
- return entity;
- } catch (HibernateException eee) {
- throw new TopiaException(eee);
- }
- }
-
/**
- * Cette methode appelle fireVetoableCreate et fireOnCreated Si vous la
- * surchargé, faites attention a appeler le super ou a appeler vous aussi
- * ces deux methodes.
- */
- @Override
- public E create(Map<String, Object> properties) throws TopiaException {
- E result = newInstance();
-
- // TODO reflechir s'il ne faudrait pas creer l'id avant l'event precedent
- // reflechir toujours dans un context on les E pourrait ne pas
- // etre des TopiaEntity
- if (result instanceof TopiaEntity) {
- String topiaId = TopiaId.create(entityClass);
- TopiaEntityAbstract entity = (TopiaEntityAbstract) result;
- entity.setTopiaId(topiaId);
- entity.setTopiaContext(getContext());
- }
- try {
- for (Map.Entry<String, Object> e : properties.entrySet()) {
- String propertyName = e.getKey();
- Object value = e.getValue();
- PropertyUtils.setProperty(result, propertyName, value);
- }
- } catch (IllegalAccessException eee) {
- throw new IllegalArgumentException(
- "Can't put properties on new Object", eee);
- } catch (InvocationTargetException eee) {
- throw new IllegalArgumentException(
- "Can't put properties on new Object", eee);
- } catch (NoSuchMethodException eee) {
- throw new IllegalArgumentException(
- "Can't put properties on new Object", eee);
- }
- // TODO-fdesbois-20100507 : need to be removed for 2.5 version
- result.postCreate();
-
- // on fait un save maintenant, car puisqu'on a creer l'entity au
- // travers du DAO, on s'attend a l'avoir a disposition tout de
- // suite pour les requetes sans avoir a faire un update dessus
- getSession().save(result);
- getContext().getFiresSupport().warnOnCreateEntity(result);
- return result;
- }
-
- @Override
- public E update(E e) throws TopiaException {
- try {
- getSession().saveOrUpdate(e);
- getContext().getFiresSupport().warnOnUpdateEntity(e);
- return e;
- } catch (HibernateException eee) {
- throw new TopiaException(eee);
- }
- }
-
- @Override
- public void delete(E e) throws TopiaException {
- try {
- getSession().delete(e);
- getContext().getFiresSupport().warnOnDeleteEntity(e);
- } catch (HibernateException eee) {
- throw new TopiaException(eee);
- }
- }
-
- @Override
- public E findByTopiaId(String k) throws TopiaException {
- return findByQuery(createQuery().add(TopiaEntity.ID, k));
- //return query(Restrictions.idEq(k));
- }
-
- @Override
- public List<E> findAll() throws TopiaException {
- return findAllByQuery(createQuery());
- }
-
- @Override
- public List<String> findAllIds() throws TopiaException {
- return createQuery().setSelect(TopiaEntity.ID).execute();
- }
-
- @Override
- public TopiaQuery createQuery() {
- return new TopiaQuery(this); //TopiaQuery.createQuery(this);
- }
-
- @Override
- public TopiaQuery createQuery(String entityAlias) {
- return new TopiaQuery(this, entityAlias); //TopiaQuery.createQuery(this, entityAlias);
- }
-
- @Override
- public E findByQuery(TopiaQuery query) throws TopiaException {
- return query.executeToEntity(context, getEntityClass());
- }
-
- @Override
- public List<E> findAllByQuery(TopiaQuery query) throws TopiaException {
- return query.executeToEntityList(context, getEntityClass());
- }
-
- @Override
- public Map<String, E> findAllMappedByQuery(TopiaQuery query)
- throws TopiaException {
- return query.executeToEntityMap(context, getEntityClass());
- }
-
- @Override
- public <K> Map<K, E> findAllMappedByQuery(TopiaQuery query, String keyName,
- Class<K> keyClass)
- throws TopiaException {
- return query.executeToEntityMap(context, getEntityClass(), keyName,
- keyClass);
- }
-
- @Override
- public List<E> findAllWithOrder(String... propertyNames)
- throws TopiaException {
-// try {
-// Criteria criteria = createCriteria(FlushMode.AUTO);
-// for (String propertyName : propertyNames) {
-// criteria.addOrder(Order.asc(propertyName));
-// }
-// List<E> result = (List<E>) criteria.list();
-// result = getContext().getFiresSupport().fireEntitiesLoad(context,
-// result);
-// return result;
-// } catch (HibernateException eee) {
-// throw new TopiaException(eee);
-// }
-
- TopiaQuery query = createQuery();
- for (String propertyName : propertyNames) {
- query.addOrder(propertyName);
- }
- return findAllByQuery(query);
- }
-
- /**
- * Count number of existing entities using {@link TopiaQuery#executeCount(TopiaContext)
- * } FIXME-FD20091224 change type to int like in 2.2.2 version
- *
- * @return a long for the number of entities in database
- */
- @Override
- public long size() throws TopiaException {
- //int result = findAll().size();
-// List result = this.getContext().find("SELECT count(*) FROM " + getEntityClass().getName() + "Impl");
-// return (Long)result.get(0);
- return createQuery().executeCount(context);
- }
-
- @Override
- public E findByProperties(Map<String, Object> properties)
- throws TopiaException {
- //return query(Restrictions.allEq(properties));
- return findByQuery(createQuery().add(properties));
- }
-
- @Override
- public List<E> findAllByProperties(Map<String, Object> properties)
- throws TopiaException {
- return findAllByQuery(createQuery().add(properties));
- //return queryAll(Restrictions.allEq(properties));
- }
-
-// private List<E> queryAll(Criterion criterion) throws TopiaException {
-// try {
-// Criteria criteria = createCriteria(FlushMode.AUTO);
-// criteria.add(criterion);
-// List<E> result = (List<E>) criteria.list();
-// result = getContext().getFiresSupport().fireEntitiesLoad(context,
-// result);
-// return result;
-// } catch (HibernateException eee) {
-// throw new TopiaException(eee);
-// }
-// }
-//
-// private E query(Criterion criterion) throws TopiaException {
-// try {
-// Criteria criteria = createCriteria(FlushMode.AUTO);
-// criteria.add(criterion);
-// criteria.setMaxResults(1);
-// List<E> result = (List<E>) criteria.list();
-// int sizeBefore = (result != null ? result.size() : 0);
-// result = getContext().getFiresSupport().fireEntitiesLoad(context,
-// result);
-// int sizeAfter = (result != null ? result.size() : 0);
-// if (sizeAfter < sizeBefore) {
-// if (log.isDebugEnabled()) {
-// log.debug((sizeBefore - sizeAfter)
-// + " element(s) removed. Filter entity: "
-// + entityClass.getName() + " - criterion: "
-// + criterion);
-// }
-// }
-// if (result != null && result.size() > 0) {
-// E elem = result.get(0);
-// return elem;
-// }
-// return null;
-// } catch (HibernateException eee) {
-// throw new TopiaException(eee);
-// }
-// }
-
- //FIXME : Commenté car impossible de trouver le bon Criterion
- // ATTENTION ancienne methode du TopiaDAOAbstract deja presente dans le fichier
-
- // /* (non-Javadoc)
- // * @see org.nuiton.topia.persistence.TopiaDAO#findContainsProperties(java.util.Map)
- // */
- // public E findContainsProperties(Map<String, Collection> properties) throws TopiaException {
- // try {
- // Criteria criteria = createCriteria(FlushMode.AUTO);
- // for (Entry<String, Collection> entry : properties.entrySet()) {
- // for (Object value : entry.getValue()) {
- // criteria.add(Restrictions.eq(entry.getKey(), value));
- // }
- // }
- // criteria.setMaxResults(1);
- // List<E> results = (List<E>)criteria.list();
- // if (results.size() > 0) {
- // return (E)results.get(0);
- // } else {
- // return null;
- // }
- // } catch (HibernateException eee) {
- // throw new TopiaException(eee);
- // }
- // }
- //
- // /* (non-Javadoc)
- // * @see org.nuiton.topia.persistence.TopiaDAO#findAllContainsProperties(java.util.Map)
- // */
- // public List<E> findAllContainsProperties(Map<String, Collection> properties) throws TopiaException {
- // try {
- // Criteria criteria = createCriteria(FlushMode.AUTO);
- // for (Entry<String, Collection> entry : properties.entrySet()) {
- // for (Object value : entry.getValue()) {
- // criteria.add(Restrictions.eq(entry.getKey(), value));
- // }
- // }
- // List<E> result = (List<E>)criteria.list();
- // return result;
- // } catch (HibernateException eee) {
- // throw new TopiaException(eee);
- // }
- // }
-
- /**
* TODO-TC20100225 Should this method deprecated (it is never used ?)
* Renvoie un Criteria créé avec l'entityClass
*
* @param mode le FlushMode du Criteria
* @return le Criteria nouvellement créé
* @throws TopiaException if any pb
+ * @deprecated since 2.4 Criteria is no longer used, prefer using {@link
+ * TopiaQuery}
*/
+ @Deprecated
private Criteria createCriteria(FlushMode mode) throws TopiaException {
Criteria criteria = getSession().createCriteria(entityClass);
criteria.setFlushMode(mode);
return criteria;
}
- /**
- * Renvoie la Session contenue dans le contexte
- *
- * @return hibernate session
- * @throws TopiaException if any pb
- */
- private Session getSession() throws TopiaException {
- return getContext().getHibernate();
- }
- @Override
- public List<Permission> getRequestPermission(String topiaId, int actions)
- throws TopiaException {
- return null;
- }
-
-
} //TopiaDAOImpl
Modified: trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/NaturalIdTest.java
===================================================================
--- trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/NaturalIdTest.java 2010-05-10 13:13:04 UTC (rev 1948)
+++ trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/NaturalIdTest.java 2010-05-10 13:21:44 UTC (rev 1949)
@@ -181,12 +181,12 @@
NaturalizedEntity.NATURAL_ID_NULL, "str");
transaction.commitTransaction();
- boolean result = dao.existNaturalId(5, "str");
+ boolean result = dao.existByNaturalId(5, "str");
Assert.assertTrue(result);
// not find with only one correct property
- result = dao.existNaturalId(8, "str");
+ result = dao.existByNaturalId(8, "str");
Assert.assertFalse(result);
1
0
r1948 - trunk/topia-persistence/src/main/java/org/nuiton/topia/generator
by tchemit@users.nuiton.org 10 May '10
by tchemit@users.nuiton.org 10 May '10
10 May '10
Author: tchemit
Date: 2010-05-10 15:13:04 +0200 (Mon, 10 May 2010)
New Revision: 1948
Url: http://nuiton.org/repositories/revision/topia/1948
Log:
use getId instead of getTopiaId
Modified:
trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/BeanTransformer.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/DAOAbstractTransformer.java
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/BeanTransformer.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/BeanTransformer.java 2010-05-10 09:56:17 UTC (rev 1947)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/BeanTransformer.java 2010-05-10 13:13:04 UTC (rev 1948)
@@ -313,7 +313,7 @@
/*{
if (childs != null) {
for (T o : childs) {
- if (topiaId.equals(o.getTopiaId())) {
+ if (topiaId.equals(o.getId())) {
return o;
}
}
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/DAOAbstractTransformer.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/DAOAbstractTransformer.java 2010-05-10 09:56:17 UTC (rev 1947)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/DAOAbstractTransformer.java 2010-05-10 13:13:04 UTC (rev 1948)
@@ -341,7 +341,7 @@
"SELECT main.topiaid " +
"from <%=attrClassifierDBName%> main, <%=attrJoinTableName%> secondary " +
"where main.topiaid=secondary.<%=attrDBName%>" +
- " and secondary.<%=attrReverseDBName%>='" + entity.getTopiaId() + "'")
+ " and secondary.<%=attrReverseDBName%>='" + entity.getId() + "'")
.addEntity("main", <%=providerFQN%>(<%=attrType%>.class)).list();
for (<%=attrType%> item : list) {
1
0
r1947 - in trunk/topia-persistence/src/main/java/org/nuiton/topia: framework generator persistence
by tchemit@users.nuiton.org 10 May '10
by tchemit@users.nuiton.org 10 May '10
10 May '10
Author: tchemit
Date: 2010-05-10 11:56:17 +0200 (Mon, 10 May 2010)
New Revision: 1947
Url: http://nuiton.org/repositories/revision/topia/1947
Log:
fix javadoc
Modified:
trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/package-info.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/TopiaRelationValidator.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaEntity.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaEntityAbstract.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/package-info.java
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/package-info.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/package-info.java 2010-05-10 09:40:32 UTC (rev 1946)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/package-info.java 2010-05-10 09:56:17 UTC (rev 1947)
@@ -23,23 +23,20 @@
* #L%
*/
/**
- * Contains two interfaces, one {@link TopiaContextImplementor}for internal
- * manipulations of {@link TopiaContext} and one {@link TopiaService}for topia
- * services. This package contains also the main implementation {@link TopiaContextImpl}
- * for both {@link TopiaContext} for final applications and
- * {@link TopiaContextImplementor} for internal.
+ * Contains two interfaces, one {@link org.nuiton.topia.framework.TopiaContextImplementor} for internal
+ * manipulations of {@link org.nuiton.topia.TopiaContext} and one {@link org.nuiton.topia.framework.TopiaService} for topia
+ * services. This package contains also the main implementation {@link org.nuiton.topia.framework.TopiaContextImpl}
+ * for both {@link org.nuiton.topia.TopiaContext} for final applications and
+ * {@link org.nuiton.topia.framework.TopiaContextImplementor} for internal.
* <p />
- * You can also use {@link TopiaQuery} class for query manipulation with
- * {@link TopiaDAO}.
+ * You can also use {@link org.nuiton.topia.framework.TopiaQuery} class for query manipulation with
+ * {@link org.nuiton.topia.persistence.TopiaDAO}.
* <p />
- * {@link TopiaUtil} is a helper class used for TopiaContext manipulations.
+ * {@link org.nuiton.topia.framework.TopiaUtil} is a helper class used for TopiaContext manipulations.
*
* @author fdesbois <fdesbois(a)codelutin.com>
* @version $Id$
- * @see TopiaContext
- * @see TopiaDAO
+ * @see org.nuiton.topia.TopiaContext
+ * @see org.nuiton.topia.persistence.TopiaDAO
*/
package org.nuiton.topia.framework;
-
-import org.nuiton.topia.persistence.TopiaDAO;
-import org.nuiton.topia.TopiaContext;
\ No newline at end of file
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/TopiaRelationValidator.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/TopiaRelationValidator.java 2010-05-10 09:40:32 UTC (rev 1946)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/TopiaRelationValidator.java 2010-05-10 09:56:17 UTC (rev 1947)
@@ -52,7 +52,6 @@
* <li>Toutes les relations ont des reverseAttribute</li>
* </ul>
*
- * @author
* @version $Id$
*/
public class TopiaRelationValidator extends ObjectModelValidator {
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaEntity.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaEntity.java 2010-05-10 09:40:32 UTC (rev 1946)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaEntity.java 2010-05-10 09:56:17 UTC (rev 1947)
@@ -79,7 +79,7 @@
@Deprecated
String TOPIA_CREATE_DATE = "topiaCreateDate";
- /** @deprecated since 2.4 use {@link #VERSION} instead */
+ /** @deprecated since 2.4 use {@link #ENTITY_VERSION} instead */
@Deprecated
String TOPIA_VERSION = "topiaVersion";
@@ -92,27 +92,45 @@
/** Property name of the technical {@code version} of the entity */
String ENTITY_VERSION = "topiaVersion";
- /** @deprecated since 2.4 use {@link #getId()} instead */
+ /**
+ * @return the id
+ * @deprecated since 2.4 use {@link #getId()} instead
+ */
@Deprecated
String getTopiaId();
- /** @deprecated since 2.4 use {@link #setId(String)} instead */
+ /**
+ * @param v the new id
+ * @deprecated since 2.4 use {@link #setId(String)} instead
+ */
@Deprecated
void setTopiaId(String v);
- /** @deprecated since 2.4 use {@link #getVersion()} instead */
+ /**
+ * @return the entity version
+ * @deprecated since 2.4 use {@link #getEntityVersion()} instead
+ */
@Deprecated
long getTopiaVersion();
- /** @deprecated since 2.4 use {@link #setVersion(long)} instead */
+ /**
+ * @param v the new entity version
+ * @deprecated since 2.4 use {@link #setEntityVersion(long)} instead
+ */
@Deprecated
void setTopiaVersion(long v);
- /** @deprecated since 2.4 use {@link #getCreateDate()} */
+ /**
+ * @return the creation date of the entity
+ * @deprecated since 2.4 use {@link #getCreateDate()}
+ */
@Deprecated
Date getTopiaCreateDate();
- /** @deprecated since 2.4 use {@link #setCreateDate(Date)} */
+ /**
+ * @param topiaCreatedate the creation date of the entity
+ * @deprecated since 2.4 use {@link #setCreateDate(Date)}
+ */
@Deprecated
void setTopiaCreateDate(Date topiaCreatedate);
@@ -176,7 +194,7 @@
* Called just after object creation and initialisation each entity impl can
* overide it to do something after creation
*
- * @throws TopiaException
+ * @throws TopiaException if any pb
* @deprecated since 2.4 : don't really know is concrete usage, the needed
* treatment can be directly done after creating the entity with
* {@link TopiaDAO#create(Object...)}
@@ -188,6 +206,7 @@
* @deprecated since 2.4 : context will no longer be keeped by the entity,
* so it will be impossible to do such operation. Use {@link
* TopiaDAO#update(TopiaEntity)} instead.
+ * @throws TopiaException if any pb
*/
@Deprecated
void update() throws TopiaException;
@@ -196,28 +215,29 @@
* @deprecated since 2.4 : context will no longer be keeped by the entity,
* so it will be impossible to do such operation. Use {@link
* TopiaDAO#delete(TopiaEntity)} instead.
+ * @throws TopiaException if any pb
*/
@Deprecated
void delete() throws TopiaException;
/**
* @return all object that must be deleted if this object is deleted
- * @throws TopiaException
+ * @throws TopiaException if any pb
*/
List<TopiaEntity> getComposite() throws TopiaException;
/**
* @return all object that are aggregate with this instance, aggreate object
* are not removed automaticaly
- * @throws TopiaException
+ * @throws TopiaException if any pb
*/
List<TopiaEntity> getAggregate() throws TopiaException;
/**
* Add listener for property writing.
*
- * @param propertyName
- * @param listener
+ * @param propertyName name of property to listen
+ * @param listener the listener to register
*/
void addPropertyChangeListener(String propertyName,
PropertyChangeListener listener);
@@ -225,7 +245,7 @@
/**
* Add listener for property writing.
*
- * @param listener
+ * @param listener the listener to register
*/
void addPropertyChangeListener(PropertyChangeListener listener);
@@ -247,8 +267,8 @@
/**
* Add listener for property reading.
*
- * @param propertyName
- * @param listener
+ * @param propertyName the property name to listen
+ * @param listener the listener to register
*/
void addPropertyListener(String propertyName,
PropertyChangeListener listener);
@@ -256,7 +276,7 @@
/**
* Add listener for property reading.
*
- * @param listener
+ * @param listener the listener to register
*/
void addPropertyListener(PropertyChangeListener listener);
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaEntityAbstract.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaEntityAbstract.java 2010-05-10 09:40:32 UTC (rev 1946)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaEntityAbstract.java 2010-05-10 09:56:17 UTC (rev 1947)
@@ -58,7 +58,7 @@
* d'entité si cela ne pose pas d'autre probleme (heritage entre ces entités).
*
* @author poussin <poussin(a)codelutin.com>
- * @ version $Id$
+ * @version $Id$
*/
public abstract class TopiaEntityAbstract implements TopiaEntity, Serializable {
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/package-info.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/package-info.java 2010-05-10 09:40:32 UTC (rev 1946)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/package-info.java 2010-05-10 09:56:17 UTC (rev 1947)
@@ -25,13 +25,14 @@
/**
* This package contains interfaces and abstract classes for entities and daos.
* <p />
- * For daos : {@link TopiaDAO} as interface and {@link TopiaDAImpl} as
- * implementation.
+ * For daos : {@link org.nuiton.topia.persistence.TopiaDAO} as interface and
+ * {@link org.nuiton.topia.persistence.TopiaDAOImpl} as implementation.
* <p />
- * For entities : {@link TopiaEntity} as interface and {@link
- * TopiaEntityAbstract} as abstract class inherited by generated entities for
+ * For entities : {@link org.nuiton.topia.persistence.TopiaEntity} as interface
+ * and {@link org.nuiton.topia.persistence.TopiaEntityAbstract}
+ * as abstract class inherited by generated entities for
* final applications. Generation is done using transformers from {@code
* org.nuiton.topia.generator} package.
*
*/
-package org.nuiton.topia.persistence;
\ No newline at end of file
+package org.nuiton.topia.persistence;
1
0
r1946 - trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util
by tchemit@users.nuiton.org 10 May '10
by tchemit@users.nuiton.org 10 May '10
10 May '10
Author: tchemit
Date: 2010-05-10 11:40:32 +0200 (Mon, 10 May 2010)
New Revision: 1946
Url: http://nuiton.org/repositories/revision/topia/1946
Log:
add getSourcetype on Loador
Modified:
trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/Loador.java
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/Loador.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/Loador.java 2010-05-09 20:30:29 UTC (rev 1945)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/Loador.java 2010-05-10 09:40:32 UTC (rev 1946)
@@ -37,6 +37,13 @@
public interface Loador<E> extends Serializable {
/**
+ * Obtains the type of the entity.
+ *
+ * @return the type of entity
+ */
+ Class<E> getSourceType();
+
+ /**
* Obtain from an entity all data to bind to another one according the
* definition of the loador.
* <p/>
@@ -57,10 +64,10 @@
/**
* Bind an entity to another.
*
- * @param from the source entity
- * @param dst the destination entity
- * @param tech a flag to bind or not the technical values of the entity
- * (says TopiaId, TopiaVersion and TopiaCreateDate).
+ * @param from the source entity
+ * @param dst the destination entity
+ * @param tech a flag to bind or not the technical values of the entity
+ * (says TopiaId, TopiaVersion and TopiaCreateDate).
* @param propertyNames subset of properties to load
*/
void load(E from, E dst, boolean tech, String... propertyNames);
1
0