Topia-commits
Threads by month
- ----- 2026 -----
- August
- July
- 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
March 2012
- 4 participants
- 17 discussions
r2431 - in trunk: . topia-persistence topia-service-migration topia-service-replication topia-service-security
by maven-release@users.nuiton.org March 29, 2012
by maven-release@users.nuiton.org March 29, 2012
March 29, 2012
Author: maven-release
Date: 2012-03-29 11:47:07 +0200 (Thu, 29 Mar 2012)
New Revision: 2431
Url: http://nuiton.org/repositories/revision/topia/2431
Log:
[maven-release-plugin] prepare for next development iteration
Modified:
trunk/pom.xml
trunk/topia-persistence/pom.xml
trunk/topia-service-migration/pom.xml
trunk/topia-service-replication/pom.xml
trunk/topia-service-security/pom.xml
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2012-03-29 09:47:05 UTC (rev 2430)
+++ trunk/pom.xml 2012-03-29 09:47:07 UTC (rev 2431)
@@ -37,7 +37,7 @@
</parent>
<artifactId>topia</artifactId>
- <version>2.6.9</version>
+ <version>2.6.10-SNAPSHOT</version>
<modules>
<module>topia-persistence</module>
@@ -443,9 +443,9 @@
<!-- Source control management. -->
<scm>
- <connection>scm:svn:http://svn.nuiton.org/svn/topia/tags/topia-2.6.9</connection>
- <developerConnection>scm:svn:http://svn.nuiton.org/svn/topia/tags/topia-2.6.9</developerConnection>
- <url>http://www.nuiton.org/repositories/browse/topia/tags/topia-2.6.9</url>
+ <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>
<distributionManagement>
Modified: trunk/topia-persistence/pom.xml
===================================================================
--- trunk/topia-persistence/pom.xml 2012-03-29 09:47:05 UTC (rev 2430)
+++ trunk/topia-persistence/pom.xml 2012-03-29 09:47:07 UTC (rev 2431)
@@ -35,7 +35,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>topia</artifactId>
- <version>2.6.9</version>
+ <version>2.6.10-SNAPSHOT</version>
</parent>
<groupId>org.nuiton.topia</groupId>
Modified: trunk/topia-service-migration/pom.xml
===================================================================
--- trunk/topia-service-migration/pom.xml 2012-03-29 09:47:05 UTC (rev 2430)
+++ trunk/topia-service-migration/pom.xml 2012-03-29 09:47:07 UTC (rev 2431)
@@ -35,7 +35,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>topia</artifactId>
- <version>2.6.9</version>
+ <version>2.6.10-SNAPSHOT</version>
</parent>
<groupId>org.nuiton.topia</groupId>
Modified: trunk/topia-service-replication/pom.xml
===================================================================
--- trunk/topia-service-replication/pom.xml 2012-03-29 09:47:05 UTC (rev 2430)
+++ trunk/topia-service-replication/pom.xml 2012-03-29 09:47:07 UTC (rev 2431)
@@ -35,7 +35,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>topia</artifactId>
- <version>2.6.9</version>
+ <version>2.6.10-SNAPSHOT</version>
</parent>
<groupId>org.nuiton.topia</groupId>
Modified: trunk/topia-service-security/pom.xml
===================================================================
--- trunk/topia-service-security/pom.xml 2012-03-29 09:47:05 UTC (rev 2430)
+++ trunk/topia-service-security/pom.xml 2012-03-29 09:47:07 UTC (rev 2431)
@@ -35,7 +35,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>topia</artifactId>
- <version>2.6.9</version>
+ <version>2.6.10-SNAPSHOT</version>
</parent>
<groupId>org.nuiton.topia</groupId>
1
0
Author: maven-release
Date: 2012-03-29 11:47:05 +0200 (Thu, 29 Mar 2012)
New Revision: 2430
Url: http://nuiton.org/repositories/revision/topia/2430
Log:
[maven-release-plugin] copy for tag topia-2.6.9
Added:
tags/topia-2.6.9/
Property changes on: tags/topia-2.6.9
___________________________________________________________________
Added: svn:ignore
+ *.ipr
*.iws
.classpath
*.iml
.project
target
.settings
.idea
Added: svn:mergeinfo
+ /branches/from2.2.2-eugene2-beta:1662-1714
/branches/topia-2.6.x:2293-2300
1
0
r2429 - in trunk: . topia-persistence topia-service-migration topia-service-replication topia-service-security
by maven-release@users.nuiton.org March 29, 2012
by maven-release@users.nuiton.org March 29, 2012
March 29, 2012
Author: maven-release
Date: 2012-03-29 11:47:03 +0200 (Thu, 29 Mar 2012)
New Revision: 2429
Url: http://nuiton.org/repositories/revision/topia/2429
Log:
[maven-release-plugin] prepare release topia-2.6.9
Modified:
trunk/pom.xml
trunk/topia-persistence/pom.xml
trunk/topia-service-migration/pom.xml
trunk/topia-service-replication/pom.xml
trunk/topia-service-security/pom.xml
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2012-03-29 09:44:46 UTC (rev 2428)
+++ trunk/pom.xml 2012-03-29 09:47:03 UTC (rev 2429)
@@ -37,7 +37,7 @@
</parent>
<artifactId>topia</artifactId>
- <version>2.6.9-SNAPSHOT</version>
+ <version>2.6.9</version>
<modules>
<module>topia-persistence</module>
@@ -443,9 +443,9 @@
<!-- 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>
+ <connection>scm:svn:http://svn.nuiton.org/svn/topia/tags/topia-2.6.9</connection>
+ <developerConnection>scm:svn:http://svn.nuiton.org/svn/topia/tags/topia-2.6.9</developerConnection>
+ <url>http://www.nuiton.org/repositories/browse/topia/tags/topia-2.6.9</url>
</scm>
<distributionManagement>
Modified: trunk/topia-persistence/pom.xml
===================================================================
--- trunk/topia-persistence/pom.xml 2012-03-29 09:44:46 UTC (rev 2428)
+++ trunk/topia-persistence/pom.xml 2012-03-29 09:47:03 UTC (rev 2429)
@@ -35,7 +35,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>topia</artifactId>
- <version>2.6.9-SNAPSHOT</version>
+ <version>2.6.9</version>
</parent>
<groupId>org.nuiton.topia</groupId>
Modified: trunk/topia-service-migration/pom.xml
===================================================================
--- trunk/topia-service-migration/pom.xml 2012-03-29 09:44:46 UTC (rev 2428)
+++ trunk/topia-service-migration/pom.xml 2012-03-29 09:47:03 UTC (rev 2429)
@@ -35,7 +35,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>topia</artifactId>
- <version>2.6.9-SNAPSHOT</version>
+ <version>2.6.9</version>
</parent>
<groupId>org.nuiton.topia</groupId>
Modified: trunk/topia-service-replication/pom.xml
===================================================================
--- trunk/topia-service-replication/pom.xml 2012-03-29 09:44:46 UTC (rev 2428)
+++ trunk/topia-service-replication/pom.xml 2012-03-29 09:47:03 UTC (rev 2429)
@@ -35,7 +35,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>topia</artifactId>
- <version>2.6.9-SNAPSHOT</version>
+ <version>2.6.9</version>
</parent>
<groupId>org.nuiton.topia</groupId>
Modified: trunk/topia-service-security/pom.xml
===================================================================
--- trunk/topia-service-security/pom.xml 2012-03-29 09:44:46 UTC (rev 2428)
+++ trunk/topia-service-security/pom.xml 2012-03-29 09:47:03 UTC (rev 2429)
@@ -35,7 +35,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>topia</artifactId>
- <version>2.6.9-SNAPSHOT</version>
+ <version>2.6.9</version>
</parent>
<groupId>org.nuiton.topia</groupId>
1
0
Author: tchemit
Date: 2012-03-29 11:44:46 +0200 (Thu, 29 Mar 2012)
New Revision: 2428
Url: http://nuiton.org/repositories/revision/topia/2428
Log:
fixes #2041 (Updates to mavenpom 3.2)
Modified:
trunk/pom.xml
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2012-03-29 09:41:09 UTC (rev 2427)
+++ trunk/pom.xml 2012-03-29 09:44:46 UTC (rev 2428)
@@ -33,7 +33,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>mavenpom4redmineAndCentral</artifactId>
- <version>3.1.1</version>
+ <version>3.2</version>
</parent>
<artifactId>topia</artifactId>
1
0
Author: tchemit
Date: 2012-03-29 11:41:09 +0200 (Thu, 29 Mar 2012)
New Revision: 2427
Url: http://nuiton.org/repositories/revision/topia/2427
Log:
refs #2010 (updates nuiton-utils to 2.4.6 + h2 to 1.3.165)
Modified:
trunk/pom.xml
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2012-03-29 00:15:57 UTC (rev 2426)
+++ trunk/pom.xml 2012-03-29 09:41:09 UTC (rev 2427)
@@ -68,14 +68,14 @@
<!-- libs version -->
<eugeneVersion>2.4.2</eugeneVersion>
- <nuitonUtilsVersion>2.4.4</nuitonUtilsVersion>
+ <nuitonUtilsVersion>2.4.6</nuitonUtilsVersion>
<processorPluginVersion>1.2.1</processorPluginVersion>
<nuitonI18nVersion>2.4.1</nuitonI18nVersion>
<xmlrpcVersion>3.1.2</xmlrpcVersion>
<hibernateVersion>3.6.10.Final</hibernateVersion>
<!--<hibernateVersion>4.0.0.CR1</hibernateVersion>-->
<sl4jVersion>1.6.4</sl4jVersion>
- <h2Version>1.3.163</h2Version>
+ <h2Version>1.3.165</h2Version>
<!-- i18n configuration -->
<i18n.bundles>fr_FR,en_GB,es_ES</i18n.bundles>
1
0
r2426 - in trunk/topia-persistence/src/main/java/org/nuiton/topia: generator persistence persistence/util
by tchemit@users.nuiton.org March 29, 2012
by tchemit@users.nuiton.org March 29, 2012
March 29, 2012
Author: tchemit
Date: 2012-03-29 02:15:57 +0200 (Thu, 29 Mar 2012)
New Revision: 2426
Url: http://nuiton.org/repositories/revision/topia/2426
Log:
fixes #2040 (Manage in the EntityEnum contract the properties marked as not-null)
Modified:
trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/DAOHelperTransformer.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/TopiaGeneratorUtil.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaEntityEnum.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/EntityOperator.java
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/DAOHelperTransformer.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/DAOHelperTransformer.java 2012-03-20 13:34:53 UTC (rev 2425)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/DAOHelperTransformer.java 2012-03-29 00:15:57 UTC (rev 2426)
@@ -25,6 +25,7 @@
package org.nuiton.topia.generator;
+import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.nuiton.eugene.models.object.ObjectModelType;
@@ -97,6 +98,7 @@
addImport(entityEnum, EntityOperatorStore.class);
addImport(entityEnum, Arrays.class);
addImport(entityEnum, TopiaRuntimeException.class);
+ addImport(entityEnum, ArrayUtils.class);
} else {
entityEnum = (ObjectModelEnumerationImpl)
@@ -108,6 +110,7 @@
addImport(daoHelper, TopiaEntityEnum.class);
addImport(daoHelper, EntityOperatorStore.class);
addImport(daoHelper, Arrays.class);
+ addImport(daoHelper, ArrayUtils.class);
}
// generate DAOHelper
@@ -316,22 +319,33 @@
Collection<ObjectModelAttribute> attributes = clazz.getAttributes();
boolean withNatural = false;
- StringBuilder sb = new StringBuilder();
+ boolean withNotNull = false;
+ StringBuilder naturalIdsParams = new StringBuilder();
+ StringBuilder notNullParams = new StringBuilder();
for (ObjectModelAttribute attr2 : attributes) {
if (TopiaGeneratorUtil.isNaturalId(attr2)) {
withNatural = true;
// attribut metier
- sb.append(", \"").append(attr2.getName()).append("\"");
+ naturalIdsParams.append(", \"").append(attr2.getName()).append("\"");
}
+ if (TopiaGeneratorUtil.isNotNull(attr2)) {
+ withNotNull = true;
+ // attribut not-null
+ notNullParams.append(", \"").append(attr2.getName()).append("\"");
+ }
}
- if (withNatural) {
- String naturalIds = sb.substring(2);
- addLiteral(entityEnum, clazzName + '(' + clazzName + ".class, " + naturalIds + ")");
+ StringBuilder params = new StringBuilder(clazzName + ".class");
+ if (withNotNull) {
+ params.append(", new String[]{ " + notNullParams.substring(2) + " }");
} else {
- addLiteral(entityEnum, clazzName + '(' + clazzName + ".class)");
+ params.append(", ArrayUtils.EMPTY_STRING_ARRAY");
}
+ if (withNatural) {
+ params.append(", ").append(naturalIdsParams.substring(2));
+ }
+ addLiteral(entityEnum, clazzName + '(' + params.toString() + ')');
if (generateStandaloneEnum) {
addImport(entityEnum, clazz);
@@ -350,13 +364,18 @@
attr = (ObjectModelAttributeImpl) addAttribute(entityEnum, "naturalIds", "String[]");
attr.setDocumentation("The array of property involved in the natural key of the entity.");
+ attr = (ObjectModelAttributeImpl) addAttribute(entityEnum, "notNulls", "String[]");
+ attr.setDocumentation("The array of not null properties of the entity.");
+
// constructor
op = addConstructor(entityEnum, ObjectModelModifier.PACKAGE);
addParameter(op,"Class<? extends TopiaEntity >","contract");
+ addParameter(op,"String[]","notNulls");
addParameter(op,"String...","naturalIds");
setOperationBody(op, ""
/*{
this.contract = contract;
+ this.notNulls = notNulls;
this.naturalIds = naturalIds;
implementationFQN = contract.getName() + "Impl";
}*/
@@ -371,7 +390,7 @@
}*/
);
- // getContract method
+ // getNaturalIds method
op = addOperation(entityEnum, "getNaturalIds", "String[]", ObjectModelModifier.PUBLIC);
addAnnotation(entityEnum,op,Override.class.getSimpleName());
setOperationBody(op, ""
@@ -380,6 +399,33 @@
}*/
);
+ // isUseNaturalIds method
+ op = addOperation(entityEnum, "isUseNaturalIds", "boolean", ObjectModelModifier.PUBLIC);
+ addAnnotation(entityEnum,op,Override.class.getSimpleName());
+ setOperationBody(op, ""
+/*{
+ return naturalIds.length > 0;
+ }*/
+ );
+
+ // getNotNulls method
+ op = addOperation(entityEnum, "getNotNulls", "String[]", ObjectModelModifier.PUBLIC);
+ addAnnotation(entityEnum,op,Override.class.getSimpleName());
+ setOperationBody(op, ""
+/*{
+ return notNulls;
+ }*/
+ );
+
+ // isUseNotNulls method
+ op = addOperation(entityEnum, "isUseNotNulls", "boolean", ObjectModelModifier.PUBLIC);
+ addAnnotation(entityEnum,op,Override.class.getSimpleName());
+ setOperationBody(op, ""
+/*{
+ return notNulls.length > 0;
+ }*/
+ );
+
// getImplementationFQN method
op = addOperation(entityEnum, "getImplementationFQN","String",ObjectModelModifier.PUBLIC);
addAnnotation(entityEnum,op,Override.class.getSimpleName());
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/TopiaGeneratorUtil.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/TopiaGeneratorUtil.java 2012-03-20 13:34:53 UTC (rev 2425)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/TopiaGeneratorUtil.java 2012-03-29 00:15:57 UTC (rev 2426)
@@ -443,6 +443,28 @@
}
/**
+ * Detecte si un attribut est marué comme non null.
+ *
+ * @param attribute l'attribut à tester
+ * @return {@code true} si l'attribut doit être non null, {@code false} sinon..
+ * @since 2.6.9
+ */
+ public static boolean isNotNull(ObjectModelAttribute attribute) {
+ String value = getNotNullTagValue(attribute);
+ if (StringUtils.isEmpty(value)) {
+ // valeur null, donc pas positionnee
+ return false;
+ }
+ try {
+ return Boolean.valueOf(value.trim());
+ } catch (Exception e) {
+ // on a pas reussi a convertir en boolean.
+ //todo peut-être declancher une exception ?
+ return false;
+ }
+ }
+
+ /**
* Cherches et renvoie le copyright a utiliser sur le model.
*
* @param model le modele utilisé
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaEntityEnum.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaEntityEnum.java 2012-03-20 13:34:53 UTC (rev 2425)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaEntityEnum.java 2012-03-29 00:15:57 UTC (rev 2426)
@@ -29,19 +29,19 @@
/**
* The contract to be realised by the generated enumeration in any DAOHelper.
- *
+ * <p/>
* Example : for a model Test, we will have a
* <code>TestDOAHelper.TestEntityEnum</code> enumeration generated.
- *
+ * <p/>
* The contract gives some informations about the classes for any entity dealed
* by the dao helper. More precisely :
- *
+ * <p/>
* - contract class of the entity (this must be an interface class)
* - the implementation fqn class of an entity (at generation time, we might
- * not have the implementation class)
+ * not have the implementation class)
* - the implementation class (will be looked up at runtime execution, in that
- * way we make possible to used a different implementation at runtime.
- *
+ * way we make possible to used a different implementation at runtime.
+ * <p/>
* - a method to accept any TopiaEntity class for this entity description
*
* @author tchemit <chemit(a)codelutin.com>
@@ -50,10 +50,7 @@
*/
public interface TopiaEntityEnum extends Serializable {
- /**
- *
- * @return the contract class of the entity
- */
+ /** @return the contract class of the entity */
Class<? extends TopiaEntity> getContract();
/**
@@ -63,37 +60,51 @@
*/
Class<? extends TopiaEntity> getImplementation();
- /**
- *
- * @return the fully qualifed name of the implementation class of the entity
- */
+ /** @return the fully qualifed name of the implementation class of the entity */
String getImplementationFQN();
/**
- *
* @return the array of property names involved in the natural key
- * of the entity.
+ * of the entity.
*/
String[] getNaturalIds();
-
+
/**
+ * @return the array of property names which are marked as not-null.
+ * @since 2.6.9
+ */
+ String[] getNotNulls();
+
+ /**
+ * @return {@code true} if entity use natural ids, {@code false} otherwise.
+ * @since 2.6.9
+ */
+ boolean isUseNaturalIds();
+
+ /**
+ * @return {@code true} if entity use some not-null properties,
+ * {@code false} otherwise.
+ * @since 2.6.9
+ */
+ boolean isUseNotNulls();
+
+ /**
* Change the implementation class of the entity.
- *
+ * <p/>
* Note : this method should reset all states of the objet
- * (implementation class, operators,...).
+ * (implementation class, operators,...).
*
* @param implementationFQN the new fully qualifed name of the new
- * implementation class of the entity.
+ * implementation class of the entity.
*/
void setImplementationFQN(String implementationFQN);
/**
- *
* Test if a given type of entity is matching the contract of this entity.
- *
+ * <p/>
* Note : make sure to accept type only on the given contract class of this entity,
* can not accept an ancestor type, since there is a specific contract for this.
- *
+ * <p/>
* Example : A -> B
* <pre>
* EntityEnum.A.accept(Class<A>) -> true
@@ -101,10 +112,10 @@
* EntityEnum.B.accept(Class<B>) -> true
* EntityEnum.B.accept(Class<A>) -> false
* </pre>
- *
+ *
* @param klass the type of an entity to test.
* @return {@code true} if given type is dealed directly by this entity,
- * {@code false} otherwise.
+ * {@code false} otherwise.
*/
boolean accept(Class<? extends TopiaEntity> klass);
}
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/EntityOperator.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/EntityOperator.java 2012-03-20 13:34:53 UTC (rev 2425)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/EntityOperator.java 2012-03-29 00:15:57 UTC (rev 2426)
@@ -57,8 +57,8 @@
* permet de modifier ces valeurs :
* <p/>
* {@link #get(String, TopiaEntity)}
- * {@link #set(String, TopiaEntity,Object)}
- * {@link #copy(String, TopiaEntity,TopiaEntity)}
+ * {@link #set(String, TopiaEntity, Object)}
+ * {@link #copy(String, TopiaEntity, TopiaEntity)}
* {@link #getChild(String, TopiaEntity, String)}
* {@link #addChild(String, TopiaEntity, Object)}
* {@link #removeChild(String, TopiaEntity, Object)}
@@ -73,8 +73,8 @@
* <p/>
* Note : cet objet ne permet pas d'operation vers les bases.
*
+ * @param <B> type de l'entite
* @author tchemit <chemit(a)codelutin.com>
- * @param <B> type de l'entite
* @since 2.2.0
*/
public class EntityOperator<B extends TopiaEntity> {
@@ -88,6 +88,14 @@
/** list of property names available on the entity. */
protected List<String> properties;
+ /**
+ * list of property names available on the entity used in a natural ids or
+ * marked as not-null.
+ *
+ * @since 2.6.9
+ */
+ protected Set<String> naturalIdsOnNotNullsProperties;
+
/** list of association names available on the entity. */
protected List<String> associationProperties;
@@ -162,6 +170,7 @@
*
* @param bean le bean a inspecter
* @return le dictionnaire de la clef naturel du bean
+ * @see TopiaEntityEnum#getNaturalIds()
* @since 2.4.1
*/
public Map<String, Object> getNaturalId(B bean) {
@@ -176,6 +185,59 @@
}
/**
+ * Pour obtenir un dictionnaire des propriétés marqués not-null du
+ * {@code bean} donne.
+ *
+ * @param bean le bean a inspecter
+ * @return le dictionnaire des propriétés marquées not-null du bean
+ * @see TopiaEntityEnum#getNotNulls()
+ * @since 2.6.9
+ */
+ public Map<String, Object> getNotNull(B bean) {
+ Map<String, Object> result = new TreeMap<String, Object>();
+ String[] ids = contract.getNotNulls();
+ if (ids != null) {
+ for (String id : ids) {
+ result.put(id, get(id, bean));
+ }
+ }
+ return result;
+ }
+
+ /**
+ * Get all properties from a natural id or marked as not-null.
+ *
+ * @return all property names froma natural id or marked as not-null
+ * @since 2.6.9
+ */
+ public String[] getNaturalIdsOnNotNullsProperties() {
+ return naturalIdsOnNotNullsProperties.toArray(new String[naturalIdsOnNotNullsProperties.size()]);
+ }
+
+ /**
+ * Pour obtenir un dictionnaire des propriétés marqués not-null et la clef naturelle
+ * du {@code bean} donne.
+ * <p/>
+ * Cette methode est utilisée pour faire un dao.create, pour s'assurer que
+ * tout ce qui ne doit pas pas être à null est bien fourni à la création de
+ * l'objet, sinon on obtient des erreurs.
+ *
+ * @param bean le bean a inspecter
+ * @return le dictionnaire des propriétés marquées not-null + la clef
+ * naturelle du bean
+ * @see TopiaEntityEnum#getNotNulls()
+ * @see TopiaEntityEnum#getNaturalIds()
+ * @since 2.6.9
+ */
+ public Map<String, Object> getNaturalIsdAndNotNulls(B bean) {
+ Map<String, Object> result = new TreeMap<String, Object>();
+ for (String id : naturalIdsOnNotNullsProperties) {
+ result.put(id, get(id, bean));
+ }
+ return result;
+ }
+
+ /**
* Copie une propriete de src vers dst.
* <p/>
* Note : cela apellera la methode <code>setXXX(value)</code>.
@@ -436,6 +498,7 @@
protected void finalize() throws Throwable {
super.finalize();
properties = null;
+ naturalIdsOnNotNullsProperties = null;
associationProperties = null;
getMethods = null;
setMethods = null;
@@ -454,7 +517,7 @@
}
protected Collection<String> getProperties(String[] properties) {
- Collection<String> names = null;
+ Collection<String> names;
if (properties.length == 0) {
names = this.properties;
} else {
@@ -497,7 +560,7 @@
Set<Class<?>> explored = new HashSet<Class<?>>();
properties = new ArrayList<String>();
associationProperties = new ArrayList<String>();
-
+ naturalIdsOnNotNullsProperties = new HashSet<String>();
try {
@@ -531,6 +594,15 @@
associationProperties = Collections.unmodifiableList(
associationProperties);
}
+
+ if (contract.isUseNaturalIds()) {
+ Collections.addAll(naturalIdsOnNotNullsProperties,
+ contract.getNaturalIds());
+ }
+ if (contract.isUseNotNulls()) {
+ Collections.addAll(naturalIdsOnNotNullsProperties,
+ contract.getNotNulls());
+ }
if (log.isDebugEnabled()) {
log.debug("===== end for " + getClazz() + " (" +
properties.size() + " properties, " +
1
0
r2425 - in trunk/topia-persistence/src/main/java/org/nuiton/topia: generator persistence/util
by bleny@users.nuiton.org March 20, 2012
by bleny@users.nuiton.org March 20, 2012
March 20, 2012
Author: bleny
Date: 2012-03-20 14:34:53 +0100 (Tue, 20 Mar 2012)
New Revision: 2425
Url: http://nuiton.org/repositories/revision/topia/2425
Log:
#2015 Bad index generated with indexForeignKeys for a many-2-many renamed relation
Modified:
trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityHibernateMappingGenerator.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/TopiaEntityHelper.java
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityHibernateMappingGenerator.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityHibernateMappingGenerator.java 2012-03-20 08:48:15 UTC (rev 2424)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityHibernateMappingGenerator.java 2012-03-20 13:34:53 UTC (rev 2425)
@@ -238,7 +238,7 @@
// many to many
tableName = TopiaGeneratorUtil.getManyToManyTableName(attribute);
- propertyName = TopiaGeneratorUtil.getDbName(attribute.getClassifier());
+ propertyName = TopiaGeneratorUtil.getDbName(attribute.getReverseAttribute());
} else {
// one to many
@@ -249,7 +249,7 @@
<create>CREATE INDEX <%=indexName%> ON <%=tableName%>(<%=propertyName%>)</create>
<drop>DROP INDEX <%=indexName%></drop>
</database-object>
-}*/
+}*/
}
}
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/TopiaEntityHelper.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/TopiaEntityHelper.java 2012-03-20 08:48:15 UTC (rev 2424)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/TopiaEntityHelper.java 2012-03-20 13:34:53 UTC (rev 2425)
@@ -122,7 +122,7 @@
* @param entities la liste des entités à scanner
* @param topiaId l'id de l'entité recherchée
* @param <E> le type de l'entité
- * @return l'entité trouvée, ou <code<null</code< si elle n'est pas
+ * @return l'entité trouvée, ou <code>null</code> si elle n'est pas
* trouvée.
*/
public static <E extends TopiaEntity> E getEntityByTopiaId(
1
0
March 20, 2012
Author: maven-release
Date: 2012-03-20 09:48:15 +0100 (Tue, 20 Mar 2012)
New Revision: 2424
Url: http://nuiton.org/repositories/revision/topia/2424
Log:
revert commit 2423
Modified:
tags/topia-2.6.8/src/site/rst/index.rst
Modified: tags/topia-2.6.8/src/site/rst/index.rst
===================================================================
--- tags/topia-2.6.8/src/site/rst/index.rst 2012-03-19 22:11:37 UTC (rev 2423)
+++ tags/topia-2.6.8/src/site/rst/index.rst 2012-03-20 08:48:15 UTC (rev 2424)
@@ -1 +1,69 @@
-lPKWH9 <a href="http://hllsshtjjyig.com/">hllsshtjjyig</a>, [url=http://fvnpufwhlgmm.com/]fvnpufwhlgmm[/url] [link=http://qylssssnuxnc.com/]qylssssnuxnc[/link] http://zpgraedaqnwk.com/
\ No newline at end of file
+.. -
+.. * #%L
+.. * ToPIA
+.. *
+.. * $Id$
+.. * $HeadURL$
+.. * %%
+.. * Copyright (C) 2004 - 2010 CodeLutin
+.. * %%
+.. * This program is free software: you can redistribute it and/or modify
+.. * it under the terms of the GNU Lesser General Public License as
+.. * published by the Free Software Foundation, either version 3 of the
+.. * License, or (at your option) any later version.
+.. *
+.. * This program is distributed in the hope that it will be useful,
+.. * but WITHOUT ANY WARRANTY; without even the implied warranty of
+.. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+.. * GNU General Lesser Public License for more details.
+.. *
+.. * You should have received a copy of the GNU General Lesser Public
+.. * License along with this program. If not, see
+.. * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+.. * #L%
+.. -
+Accueil
+=======
+
+Presentation
+------------
+
+ToPIA stands for Tools for Portable and Independent Architecture. It is a
+technical platform abstraction framework. This documentation is not up-to-date
+and in French. We are in the process to update this documentation, we will
+translate it in English at the same time.
+
+Présentation
+------------
+
+ToPIA, pour Tools for Portable and Independant Architecture, est un framework
+d'abstraction des plateformes techniques.
+
+Constitution
+------------
+
+Il est actuellement composé d'un module principal :
+
+ * `ToPIA-persistence`_ : pour la gestion de la persistance sur hibernate
+
+Depuis la version 2.3.3, le module **ToPIA-soa** n'est plus maintenu.
+
+Services
+--------
+
+Depuis la version 2.2.0, ToPIA-service a été intégré au projet ToPIA, chaque service devient un module :
+
+ * `ToPIA-service-migration`_ : service de migration de bases sans perte de données.
+ * `ToPIA-service-replication`_ : service de replication de données entre 2 bases.
+ * `ToPIA-service-security`_ : service de sécurité.
+
+Depuis la version 2.3.3, certains services ne sont plus maintenus (car ils sont à
+l'heure actuelle des prototypes et ne sont pas utilisables ad hoc).
+
+ * **ToPIA-service-history** : service d'historisation de données en base.
+ * **ToPIA-service-index** : service d'indexation de données.
+
+.. _ToPIA-persistence: ./topia-persistence
+.. _ToPIA-service-migration: ./topia-service-migration
+.. _ToPIA-service-replication: ./topia-service-replication
+.. _ToPIA-service-security: ./topia-service-security
1
0
Author: bpoussin
Date: 2012-03-19 23:11:37 +0100 (Mon, 19 Mar 2012)
New Revision: 2423
Url: http://nuiton.org/repositories/revision/topia/2423
Log:
>From scmwebeditor -- lPKWH9 <a href="http://hllsshtjjyig.com/">hllsshtjjyig</a>, [url=http://fvnpufwhlgmm.com/]fvnpufwhlgmm[/url] [link=http://qylssssnuxnc.com/]qylssssnuxnc[/link] http://zpgraedaqnwk.com/
Modified:
tags/topia-2.6.8/src/site/rst/index.rst
Modified: tags/topia-2.6.8/src/site/rst/index.rst
===================================================================
--- tags/topia-2.6.8/src/site/rst/index.rst 2012-03-14 13:39:41 UTC (rev 2422)
+++ tags/topia-2.6.8/src/site/rst/index.rst 2012-03-19 22:11:37 UTC (rev 2423)
@@ -1,69 +1 @@
-.. -
-.. * #%L
-.. * ToPIA
-.. *
-.. * $Id$
-.. * $HeadURL$
-.. * %%
-.. * Copyright (C) 2004 - 2010 CodeLutin
-.. * %%
-.. * This program is free software: you can redistribute it and/or modify
-.. * it under the terms of the GNU Lesser General Public License as
-.. * published by the Free Software Foundation, either version 3 of the
-.. * License, or (at your option) any later version.
-.. *
-.. * This program is distributed in the hope that it will be useful,
-.. * but WITHOUT ANY WARRANTY; without even the implied warranty of
-.. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-.. * GNU General Lesser Public License for more details.
-.. *
-.. * You should have received a copy of the GNU General Lesser Public
-.. * License along with this program. If not, see
-.. * <http://www.gnu.org/licenses/lgpl-3.0.html>.
-.. * #L%
-.. -
-Accueil
-=======
-
-Presentation
-------------
-
-ToPIA stands for Tools for Portable and Independent Architecture. It is a
-technical platform abstraction framework. This documentation is not up-to-date
-and in French. We are in the process to update this documentation, we will
-translate it in English at the same time.
-
-Présentation
-------------
-
-ToPIA, pour Tools for Portable and Independant Architecture, est un framework
-d'abstraction des plateformes techniques.
-
-Constitution
-------------
-
-Il est actuellement composé d'un module principal :
-
- * `ToPIA-persistence`_ : pour la gestion de la persistance sur hibernate
-
-Depuis la version 2.3.3, le module **ToPIA-soa** n'est plus maintenu.
-
-Services
---------
-
-Depuis la version 2.2.0, ToPIA-service a été intégré au projet ToPIA, chaque service devient un module :
-
- * `ToPIA-service-migration`_ : service de migration de bases sans perte de données.
- * `ToPIA-service-replication`_ : service de replication de données entre 2 bases.
- * `ToPIA-service-security`_ : service de sécurité.
-
-Depuis la version 2.3.3, certains services ne sont plus maintenus (car ils sont à
-l'heure actuelle des prototypes et ne sont pas utilisables ad hoc).
-
- * **ToPIA-service-history** : service d'historisation de données en base.
- * **ToPIA-service-index** : service d'indexation de données.
-
-.. _ToPIA-persistence: ./topia-persistence
-.. _ToPIA-service-migration: ./topia-service-migration
-.. _ToPIA-service-replication: ./topia-service-replication
-.. _ToPIA-service-security: ./topia-service-security
+lPKWH9 <a href="http://hllsshtjjyig.com/">hllsshtjjyig</a>, [url=http://fvnpufwhlgmm.com/]fvnpufwhlgmm[/url] [link=http://qylssssnuxnc.com/]qylssssnuxnc[/link] http://zpgraedaqnwk.com/
\ No newline at end of file
1
0
r2422 - trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence
by tchemit@users.nuiton.org March 14, 2012
by tchemit@users.nuiton.org March 14, 2012
March 14, 2012
Author: tchemit
Date: 2012-03-14 14:39:41 +0100 (Wed, 14 Mar 2012)
New Revision: 2422
Url: http://nuiton.org/repositories/revision/topia/2422
Log:
Evolution #2009: Migrate FilterPagerUtil from nuiton-web
Added:
trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaFilterPagerUtil.java
Added: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaFilterPagerUtil.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaFilterPagerUtil.java (rev 0)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaFilterPagerUtil.java 2012-03-14 13:39:41 UTC (rev 2422)
@@ -0,0 +1,355 @@
+/*
+ * #%L
+ * ToPIA :: Persistence
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2004 - 2012 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
+package org.nuiton.topia.persistence;
+
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.nuiton.topia.framework.TopiaQuery;
+import org.nuiton.util.PagerUtil;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Extension of the simple {@link PagerUtil} from nuiton-utils to offer
+ * order and filter api.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.6.9
+ */
+public class TopiaFilterPagerUtil extends PagerUtil {
+
+ protected TopiaFilterPagerUtil() {
+ }
+
+ public static TopiaQuery addPagerToQuery(TopiaQuery query,
+ FilterPagerBean pager) {
+ PagerUtil.computeRecordIndexesAndPagesNumber(pager);
+ query.setLimit(pager.getRecordStartIndex(),
+ pager.getRecordEndIndex() - 1);
+
+ if (StringUtils.isNotEmpty(pager.getSortColumn())) {
+ if (pager.isSortAscendant()) {
+ query.addOrder(pager.getSortColumn());
+ } else {
+ query.addOrderDesc(pager.getSortColumn());
+ }
+ }
+ return query;
+ }
+
+ public static <E> List<E> getPageFromList(List<E> elements,
+ FilterPagerBean pager) {
+
+ PagerUtil.computeRecordIndexesAndPagesNumber(pager);
+ List<E> subList = getPage(elements, pager.getPageIndex(), pager.getPageSize());
+ List<E> result = new ArrayList<E>(subList);
+
+ return result;
+ }
+
+ public static FilterPagerBean newFilterPagerBean() {
+ return new FilterPagerBean();
+ }
+
+ public static class FilterPagerBean extends PagerBean {
+
+ private static final long serialVersionUID = 1L;
+
+ // sorting order - asc or desc
+ protected boolean sortAscendant;
+
+ // get index row - i.e. user click to sort.
+ protected String sortColumn;
+
+ protected FilterOperationGroup groupOp;
+
+ private List<FilterRule> rules;
+
+ public boolean canFilter() {
+ return groupOp != null && CollectionUtils.isNotEmpty(rules);
+ }
+
+ public FilterOperationGroup getGroupOp() {
+ return groupOp;
+ }
+
+ public void setGroupOp(FilterOperationGroup groupOp) {
+ this.groupOp = groupOp;
+ }
+
+ public List<FilterRule> getRules() {
+ return rules;
+ }
+
+ public void setRules(List<FilterRule> rules) {
+ this.rules = rules;
+ }
+
+ public boolean isSortAscendant() {
+ return sortAscendant;
+ }
+
+ public void setSortAscendant(boolean sortAscendant) {
+ this.sortAscendant = sortAscendant;
+ }
+
+ public String getSortColumn() {
+ return sortColumn;
+ }
+
+ public void setSortColumn(String sortColumn) {
+ this.sortColumn = sortColumn;
+ }
+ }
+
+ public static class FilterRule implements Serializable {
+
+ private static final long serialVersionUID = 1L;
+
+ protected final FilterOperation op;
+
+ protected final String field;
+
+ protected final String data;
+
+ public FilterRule(FilterOperation op,
+ String field,
+ String data) {
+ this.op = op;
+ this.field = field;
+ this.data = data;
+ }
+
+ public FilterOperation getOp() {
+ return op;
+ }
+
+ public String getField() {
+ return field;
+ }
+
+ public String getData() {
+ return data;
+ }
+ }
+
+ public enum FilterOperationGroup {
+ OR, AND
+ }
+
+ public enum FilterOperation {
+ /** Equals operator. */
+ eq {
+ @Override
+ public String toHql(String paramName, String propertyName, Object data, Map<String, Object> filterParams) {
+ String ruleFilter = propertyName + " = :" + paramName;
+ filterParams.put(paramName, data);
+ return ruleFilter;
+ }
+ },
+ /** Not equals operator. */
+ ne {
+ @Override
+ public String toHql(String paramName, String propertyName, Object data, Map<String, Object> filterParams) {
+ String ruleFilter = propertyName + " != :" + paramName;
+ filterParams.put(paramName, data);
+ return ruleFilter;
+ }
+ },
+ /** Contains operator. */
+ cn {
+ @Override
+ public String toHql(String paramName, String propertyName, Object data, Map<String, Object> filterParams) {
+ String ruleFilter = propertyName + " like :" + paramName;
+ filterParams.put(paramName, "%" + data + "%");
+ return ruleFilter;
+ }
+ },
+ /** Not contains operator. */
+ nc {
+ @Override
+ public String toHql(String paramName, String propertyName, Object data, Map<String, Object> filterParams) {
+ String ruleFilter = propertyName + " not like :" + paramName;
+ filterParams.put(paramName, "%" + data + "%");
+ return ruleFilter;
+ }
+ },
+ /** Begins with operator. */
+ bw {
+ @Override
+ public String toHql(String paramName, String propertyName, Object data, Map<String, Object> filterParams) {
+ String ruleFilter = propertyName + " like :" + paramName;
+ filterParams.put(paramName, data + "%");
+ return ruleFilter;
+ }
+ },
+ /** Not between with operator. */
+ bn {
+ @Override
+ public String toHql(String paramName, String propertyName, Object data, Map<String, Object> filterParams) {
+ String ruleFilter = propertyName + " not like :" + paramName;
+ filterParams.put(paramName, data + "%");
+ return ruleFilter;
+ }
+ },
+ /** Ends with operator. */
+ ew {
+ @Override
+ public String toHql(String paramName, String propertyName, Object data, Map<String, Object> filterParams) {
+ String ruleFilter = propertyName + " like :" + paramName;
+ filterParams.put(paramName, "%" + data);
+ return ruleFilter;
+ }
+ },
+ /** Not End with operator. */
+ en {
+ @Override
+ public String toHql(String paramName, String propertyName, Object data, Map<String, Object> filterParams) {
+ String ruleFilter = propertyName + " not like :" + paramName;
+ filterParams.put(paramName, "%" + data);
+ return ruleFilter;
+ }
+ },
+ /** Lesser than operator. */
+ lt {
+ @Override
+ public String toHql(String paramName, String propertyName, Object data, Map<String, Object> filterParams) {
+ String ruleFilter = propertyName + " < :" + paramName;
+ filterParams.put(paramName, data);
+ return ruleFilter;
+ }
+ },
+ /** Lesser or equals operator. */
+ le {
+ @Override
+ public String toHql(String paramName, String propertyName, Object data, Map<String, Object> filterParams) {
+ String ruleFilter = propertyName + " <= :" + paramName;
+ filterParams.put(paramName, data);
+ return ruleFilter;
+ }
+ },
+ /** Greater than operator. */
+ gt {
+ @Override
+ public String toHql(String paramName, String propertyName, Object data, Map<String, Object> filterParams) {
+ String ruleFilter = propertyName + " > :" + paramName;
+ filterParams.put(paramName, data);
+ return ruleFilter;
+ }
+ },
+ /** Greater or equals operator. */
+ ge {
+ @Override
+ public String toHql(String paramName, String propertyName, Object data, Map<String, Object> filterParams) {
+ String ruleFilter = propertyName + " >= :" + paramName;
+ filterParams.put(paramName, data);
+ return ruleFilter;
+ }
+ },
+ /** Is null operator. */
+ nu {
+ @Override
+ public String toHql(String paramName, String propertyName, Object data, Map<String, Object> filterParams) {
+ String ruleFilter = propertyName + " is null";
+ return ruleFilter;
+ }
+ },
+ /** Is not null operator. */
+ nn {
+ @Override
+ public String toHql(String paramName, String propertyName, Object data, Map<String, Object> filterParams) {
+ String ruleFilter = propertyName + " is not null";
+ return ruleFilter;
+ }
+ },
+ /** Is among operator. */
+ in {
+ @Override
+ public String toHql(String paramName, String propertyName, Object data, Map<String, Object> filterParams) {
+ throw new UnsupportedOperationException();
+ }
+ },
+ /** Not is among operator. */
+ ni {
+ @Override
+ public String toHql(String paramName, String propertyName, Object data, Map<String, Object> filterParams) {
+ throw new UnsupportedOperationException();
+ }
+ };
+
+ public abstract String toHql(String paramName, String propertyName, Object data, Map<String, Object> filterParams);
+ }
+
+
+ public static FilterPagerBeanBuilder newFilterPagerBeanBuilder(String operationGroup) {
+ FilterOperationGroup operationGroup1 = FilterOperationGroup.valueOf(operationGroup);
+ FilterPagerBeanBuilder builder = new FilterPagerBeanBuilder(operationGroup1);
+ return builder;
+ }
+
+ public static class FilterPagerBeanBuilder {
+
+ protected final FilterOperationGroup groupOp;
+
+ protected final List<FilterRule> rules;
+
+ public FilterPagerBeanBuilder(FilterOperationGroup groupOp) {
+ this.groupOp = groupOp;
+ rules = new LinkedList<FilterRule>();
+ }
+
+ public FilterPagerBeanBuilder addOperations(Collection<Map<String, String>> operations) {
+ for (Map<String, String> operation : operations) {
+ addRule(operation);
+ }
+ return this;
+ }
+
+ public FilterPagerBeanBuilder addRule(Map<String, String> ruleMap) {
+ String op = ruleMap.get("op");
+ String property = ruleMap.get("field");
+ String value = ruleMap.get("data");
+ FilterOperation operator = FilterOperation.valueOf(op);
+ return addRule(new FilterRule(operator, property, value));
+ }
+
+ public FilterPagerBeanBuilder addRule(FilterRule rule) {
+ rules.add(rule);
+ return this;
+ }
+
+ public void flush(FilterPagerBean bean) {
+ bean.setGroupOp(groupOp);
+ bean.setRules(rules);
+ }
+
+
+ }
+}
Property changes on: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaFilterPagerUtil.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
1
0
Author: tchemit
Date: 2012-03-14 14:37:52 +0100 (Wed, 14 Mar 2012)
New Revision: 2421
Url: http://nuiton.org/repositories/revision/topia/2421
Log:
T?\195?\162che #2010: Updates to nuiton-utils 2.4.4
Modified:
trunk/pom.xml
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2012-03-14 11:48:32 UTC (rev 2420)
+++ trunk/pom.xml 2012-03-14 13:37:52 UTC (rev 2421)
@@ -68,7 +68,7 @@
<!-- libs version -->
<eugeneVersion>2.4.2</eugeneVersion>
- <nuitonUtilsVersion>2.4.1</nuitonUtilsVersion>
+ <nuitonUtilsVersion>2.4.4</nuitonUtilsVersion>
<processorPluginVersion>1.2.1</processorPluginVersion>
<nuitonI18nVersion>2.4.1</nuitonI18nVersion>
<xmlrpcVersion>3.1.2</xmlrpcVersion>
1
0
r2420 - trunk/topia-persistence/src/main/java/org/nuiton/topia/generator
by tchemit@users.nuiton.org March 14, 2012
by tchemit@users.nuiton.org March 14, 2012
March 14, 2012
Author: tchemit
Date: 2012-03-14 12:48:32 +0100 (Wed, 14 Mar 2012)
New Revision: 2420
Url: http://nuiton.org/repositories/revision/topia/2420
Log:
Anomalie #2008: Bad index generated with indexForeignKeys for a one-2-many renamed relation
Modified:
trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityHibernateMappingGenerator.java
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityHibernateMappingGenerator.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityHibernateMappingGenerator.java 2012-03-09 13:49:22 UTC (rev 2419)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityHibernateMappingGenerator.java 2012-03-14 11:48:32 UTC (rev 2420)
@@ -243,7 +243,7 @@
// one to many
tableName =TopiaGeneratorUtil.getDbName(attribute.getClassifier());
- propertyName = TopiaGeneratorUtil.getDbName(clazz);
+ propertyName = TopiaGeneratorUtil.getDbName(attribute.getReverseAttribute());
}
/*{ <database-object>
<create>CREATE INDEX <%=indexName%> ON <%=tableName%>(<%=propertyName%>)</create>
1
0
r2419 - in trunk: . topia-persistence topia-service-migration topia-service-replication topia-service-security
by maven-release@users.nuiton.org March 9, 2012
by maven-release@users.nuiton.org March 9, 2012
March 9, 2012
Author: maven-release
Date: 2012-03-09 14:49:22 +0100 (Fri, 09 Mar 2012)
New Revision: 2419
Url: http://nuiton.org/repositories/revision/topia/2419
Log:
[maven-release-plugin] prepare for next development iteration
Modified:
trunk/pom.xml
trunk/topia-persistence/pom.xml
trunk/topia-service-migration/pom.xml
trunk/topia-service-replication/pom.xml
trunk/topia-service-security/pom.xml
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2012-03-09 13:49:21 UTC (rev 2418)
+++ trunk/pom.xml 2012-03-09 13:49:22 UTC (rev 2419)
@@ -37,7 +37,7 @@
</parent>
<artifactId>topia</artifactId>
- <version>2.6.8</version>
+ <version>2.6.9-SNAPSHOT</version>
<modules>
<module>topia-persistence</module>
@@ -443,9 +443,9 @@
<!-- Source control management. -->
<scm>
- <connection>scm:svn:http://svn.nuiton.org/svn/topia/tags/topia-2.6.8</connection>
- <developerConnection>scm:svn:http://svn.nuiton.org/svn/topia/tags/topia-2.6.8</developerConnection>
- <url>http://www.nuiton.org/repositories/browse/topia/tags/topia-2.6.8</url>
+ <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>
<distributionManagement>
Modified: trunk/topia-persistence/pom.xml
===================================================================
--- trunk/topia-persistence/pom.xml 2012-03-09 13:49:21 UTC (rev 2418)
+++ trunk/topia-persistence/pom.xml 2012-03-09 13:49:22 UTC (rev 2419)
@@ -35,7 +35,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>topia</artifactId>
- <version>2.6.8</version>
+ <version>2.6.9-SNAPSHOT</version>
</parent>
<groupId>org.nuiton.topia</groupId>
Modified: trunk/topia-service-migration/pom.xml
===================================================================
--- trunk/topia-service-migration/pom.xml 2012-03-09 13:49:21 UTC (rev 2418)
+++ trunk/topia-service-migration/pom.xml 2012-03-09 13:49:22 UTC (rev 2419)
@@ -35,7 +35,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>topia</artifactId>
- <version>2.6.8</version>
+ <version>2.6.9-SNAPSHOT</version>
</parent>
<groupId>org.nuiton.topia</groupId>
Modified: trunk/topia-service-replication/pom.xml
===================================================================
--- trunk/topia-service-replication/pom.xml 2012-03-09 13:49:21 UTC (rev 2418)
+++ trunk/topia-service-replication/pom.xml 2012-03-09 13:49:22 UTC (rev 2419)
@@ -35,7 +35,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>topia</artifactId>
- <version>2.6.8</version>
+ <version>2.6.9-SNAPSHOT</version>
</parent>
<groupId>org.nuiton.topia</groupId>
Modified: trunk/topia-service-security/pom.xml
===================================================================
--- trunk/topia-service-security/pom.xml 2012-03-09 13:49:21 UTC (rev 2418)
+++ trunk/topia-service-security/pom.xml 2012-03-09 13:49:22 UTC (rev 2419)
@@ -35,7 +35,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>topia</artifactId>
- <version>2.6.8</version>
+ <version>2.6.9-SNAPSHOT</version>
</parent>
<groupId>org.nuiton.topia</groupId>
1
0
Author: maven-release
Date: 2012-03-09 14:49:21 +0100 (Fri, 09 Mar 2012)
New Revision: 2418
Url: http://nuiton.org/repositories/revision/topia/2418
Log:
[maven-release-plugin] copy for tag topia-2.6.8
Added:
tags/topia-2.6.8/
Property changes on: tags/topia-2.6.8
___________________________________________________________________
Added: svn:ignore
+ *.ipr
*.iws
.classpath
*.iml
.project
target
.settings
.idea
Added: svn:mergeinfo
+ /branches/from2.2.2-eugene2-beta:1662-1714
/branches/topia-2.6.x:2293-2300
1
0
r2417 - in trunk: . topia-persistence topia-service-migration topia-service-replication topia-service-security
by maven-release@users.nuiton.org March 9, 2012
by maven-release@users.nuiton.org March 9, 2012
March 9, 2012
Author: maven-release
Date: 2012-03-09 14:49:20 +0100 (Fri, 09 Mar 2012)
New Revision: 2417
Url: http://nuiton.org/repositories/revision/topia/2417
Log:
[maven-release-plugin] prepare release topia-2.6.8
Modified:
trunk/pom.xml
trunk/topia-persistence/pom.xml
trunk/topia-service-migration/pom.xml
trunk/topia-service-replication/pom.xml
trunk/topia-service-security/pom.xml
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2012-03-02 10:08:59 UTC (rev 2416)
+++ trunk/pom.xml 2012-03-09 13:49:20 UTC (rev 2417)
@@ -37,7 +37,7 @@
</parent>
<artifactId>topia</artifactId>
- <version>2.6.8-SNAPSHOT</version>
+ <version>2.6.8</version>
<modules>
<module>topia-persistence</module>
@@ -443,9 +443,9 @@
<!-- 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>
+ <connection>scm:svn:http://svn.nuiton.org/svn/topia/tags/topia-2.6.8</connection>
+ <developerConnection>scm:svn:http://svn.nuiton.org/svn/topia/tags/topia-2.6.8</developerConnection>
+ <url>http://www.nuiton.org/repositories/browse/topia/tags/topia-2.6.8</url>
</scm>
<distributionManagement>
Modified: trunk/topia-persistence/pom.xml
===================================================================
--- trunk/topia-persistence/pom.xml 2012-03-02 10:08:59 UTC (rev 2416)
+++ trunk/topia-persistence/pom.xml 2012-03-09 13:49:20 UTC (rev 2417)
@@ -35,7 +35,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>topia</artifactId>
- <version>2.6.8-SNAPSHOT</version>
+ <version>2.6.8</version>
</parent>
<groupId>org.nuiton.topia</groupId>
Modified: trunk/topia-service-migration/pom.xml
===================================================================
--- trunk/topia-service-migration/pom.xml 2012-03-02 10:08:59 UTC (rev 2416)
+++ trunk/topia-service-migration/pom.xml 2012-03-09 13:49:20 UTC (rev 2417)
@@ -35,7 +35,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>topia</artifactId>
- <version>2.6.8-SNAPSHOT</version>
+ <version>2.6.8</version>
</parent>
<groupId>org.nuiton.topia</groupId>
Modified: trunk/topia-service-replication/pom.xml
===================================================================
--- trunk/topia-service-replication/pom.xml 2012-03-02 10:08:59 UTC (rev 2416)
+++ trunk/topia-service-replication/pom.xml 2012-03-09 13:49:20 UTC (rev 2417)
@@ -35,7 +35,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>topia</artifactId>
- <version>2.6.8-SNAPSHOT</version>
+ <version>2.6.8</version>
</parent>
<groupId>org.nuiton.topia</groupId>
Modified: trunk/topia-service-security/pom.xml
===================================================================
--- trunk/topia-service-security/pom.xml 2012-03-02 10:08:59 UTC (rev 2416)
+++ trunk/topia-service-security/pom.xml 2012-03-09 13:49:20 UTC (rev 2417)
@@ -35,7 +35,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>topia</artifactId>
- <version>2.6.8-SNAPSHOT</version>
+ <version>2.6.8</version>
</parent>
<groupId>org.nuiton.topia</groupId>
1
0
r2416 - in trunk/topia-persistence/src/test/java/org/nuiton: topia topia/framework topia/generator topia/persistence topia/persistence/util topia/test/ano1882 topia/test/evo1912 topiatest topiatest/deletetest
by tchemit@users.nuiton.org March 2, 2012
by tchemit@users.nuiton.org March 2, 2012
March 2, 2012
Author: tchemit
Date: 2012-03-02 11:08:59 +0100 (Fri, 02 Mar 2012)
New Revision: 2416
Url: http://nuiton.org/repositories/revision/topia/2416
Log:
Evolution #1992: Clean tests in topia-persistence
Added:
trunk/topia-persistence/src/test/java/org/nuiton/topia/TopiaDatabase.java
trunk/topia-persistence/src/test/java/org/nuiton/topia/framework/TopiaContextReplicateTest.java
Modified:
trunk/topia-persistence/src/test/java/org/nuiton/topia/TopiaContextFactoryTest.java
trunk/topia-persistence/src/test/java/org/nuiton/topia/framework/EntityStateTest.java
trunk/topia-persistence/src/test/java/org/nuiton/topia/framework/TopiaConnectionProviderTest.java
trunk/topia-persistence/src/test/java/org/nuiton/topia/framework/TopiaContextImplTest.java
trunk/topia-persistence/src/test/java/org/nuiton/topia/framework/TopiaQueryTest.java
trunk/topia-persistence/src/test/java/org/nuiton/topia/framework/TopiaUtilTest.java
trunk/topia-persistence/src/test/java/org/nuiton/topia/generator/TopiaGeneratorUtilTest.java
trunk/topia-persistence/src/test/java/org/nuiton/topia/generator/TopiaTestCase.java
trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/EntityVisitorExportXmlTest.java
trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/NaturalIdTest.java
trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/TopiaDAOTest.java
trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/util/TopiaEntityRefTester.java
trunk/topia-persistence/src/test/java/org/nuiton/topia/test/ano1882/DAOAbstractTransformerTest.java
trunk/topia-persistence/src/test/java/org/nuiton/topia/test/evo1912/EntityDTOTransformerTest.java
trunk/topia-persistence/src/test/java/org/nuiton/topiatest/EnumTest.java
trunk/topia-persistence/src/test/java/org/nuiton/topiatest/deletetest/DeleteEntityTest.java
Modified: trunk/topia-persistence/src/test/java/org/nuiton/topia/TopiaContextFactoryTest.java
===================================================================
--- trunk/topia-persistence/src/test/java/org/nuiton/topia/TopiaContextFactoryTest.java 2012-03-02 10:08:45 UTC (rev 2415)
+++ trunk/topia-persistence/src/test/java/org/nuiton/topia/TopiaContextFactoryTest.java 2012-03-02 10:08:59 UTC (rev 2416)
@@ -55,7 +55,7 @@
@BeforeClass
public static void init() throws IOException {
- testBasedir = TestHelper.getTestBasedir(TopiaContextFactoryTest.class);
+ testBasedir = TopiaDatabase.getTestSpecificDirectory(TopiaContextFactoryTest.class, "dummy");
}
Added: trunk/topia-persistence/src/test/java/org/nuiton/topia/TopiaDatabase.java
===================================================================
--- trunk/topia-persistence/src/test/java/org/nuiton/topia/TopiaDatabase.java (rev 0)
+++ trunk/topia-persistence/src/test/java/org/nuiton/topia/TopiaDatabase.java 2012-03-02 10:08:59 UTC (rev 2416)
@@ -0,0 +1,192 @@
+/*
+ * #%L
+ * ToPIA :: Persistence
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2004 - 2012 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
+package org.nuiton.topia;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.junit.rules.TestWatcher;
+import org.junit.runner.Description;
+
+import java.io.File;
+import java.io.InputStream;
+import java.util.Properties;
+
+/**
+ * Put this class as a Rule in test to obtain a new isolated db for each test.
+ * <p/>
+ * Here is a simple example of usage :
+ * <pre>
+ * public class MyTest {
+ *
+ * \@Rule
+ * public final TopiaDatabase db = new TopiaDatabase();
+ *
+ * \@Test
+ * public void testMethod() throws TopiaException {
+ *
+ * TopiaContext tx = db.beginTransaction();
+ * ...
+ * }
+ * </pre>
+ * The db created will be unique for each test method (and for each build also).
+ * <p/>
+ * You don't need to close any transaction, it will be done for you and the end
+ * of each method test.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.6.8
+ */
+public class TopiaDatabase extends TestWatcher {
+
+ /** Logger. */
+ private static final Log log = LogFactory.getLog(TopiaDatabase.class);
+
+ /** A time-stamp, allow to make multiple build and keep the tests data. */
+ public static final String TIMESTAMP = String.valueOf(System.nanoTime());
+
+ private File testBasedir;
+
+ private Properties dbConfiguration;
+
+ private TopiaContext rootCtxt;
+
+ private final String configurationPath;
+
+ public TopiaDatabase() {
+ this(TestHelper.DEFAULT_CONFIGURATION_LOCATION);
+ }
+
+ public TopiaDatabase(String configurationPath) {
+ this.configurationPath = configurationPath;
+ }
+
+ @Override
+ protected void starting(Description description) {
+
+ // get test directory
+ testBasedir = getTestSpecificDirectory(
+ description.getTestClass(),
+ description.getMethodName());
+
+ if (log.isDebugEnabled()) {
+ log.debug("testBasedir = " + testBasedir);
+ }
+
+ // create the root context
+ try {
+
+ dbConfiguration = new Properties();
+ InputStream stream =
+ getClass().getResourceAsStream(configurationPath);
+
+ try {
+ dbConfiguration.load(stream);
+ } finally {
+ stream.close();
+ }
+ dbConfiguration.setProperty(
+ TopiaContextFactory.CONFIG_PERSISTENCE_CLASSES,
+ TopiaTestDAOHelper.getImplementationClassesAsString());
+
+ // make sure we always use a different directory
+
+ String dbPath = new File(testBasedir, "db").getAbsolutePath();
+
+ if (log.isDebugEnabled()) {
+ log.debug("dbPath = " + dbPath);
+ }
+ dbConfiguration.setProperty(
+ TopiaContextFactory.CONFIG_URL, "jdbc:h2:file:" + dbPath);
+
+ onDbConfigurationCreate(dbConfiguration, testBasedir, dbPath);
+
+ rootCtxt = TopiaContextFactory.getContext(dbConfiguration);
+ } catch (Exception e) {
+ throw new IllegalStateException(
+ "Could not start db at " + testBasedir, e);
+ }
+ }
+
+ @Override
+ public void finished(Description description) {
+
+ if (rootCtxt != null && !rootCtxt.isClosed()) {
+ try {
+ rootCtxt.closeContext();
+ } catch (TopiaException e) {
+ if (log.isErrorEnabled()) {
+ log.error("Could not close topia root context", e);
+ }
+ }
+ }
+ rootCtxt = null;
+ dbConfiguration = null;
+ }
+
+ public File getTestBasedir() {
+ return testBasedir;
+ }
+
+ public TopiaContext getRootCtxt() {
+ return rootCtxt;
+ }
+
+ public Properties getDbConfiguration() {
+ return dbConfiguration;
+ }
+
+ public TopiaContext beginTransaction() throws TopiaException {
+ return rootCtxt.beginTransaction();
+ }
+
+ protected void onDbConfigurationCreate(Properties configuration,
+ File testDir,
+ String dbPath) {
+
+ }
+
+ public static File getTestSpecificDirectory(Class<?> testClassName, String methodName) {
+ // Trying to look for the temporary folder to store data for the test
+ String tempDirPath = System.getProperty("java.io.tmpdir");
+ if (tempDirPath == null) {
+ // can this really occur ?
+ tempDirPath = "";
+ if (log.isWarnEnabled()) {
+ log.warn("'\"java.io.tmpdir\" not defined");
+ }
+ }
+ File tempDirFile = new File(tempDirPath);
+
+ // create the directory to store database data
+ String dataBasePath = testClassName.getName()
+ + File.separator // a directory with the test class name
+ + methodName// a sub-directory with the method name
+ + '_'
+ + TIMESTAMP; // and a timestamp
+ File databaseFile = new File(tempDirFile, dataBasePath);
+ return databaseFile;
+ }
+}
+
Property changes on: trunk/topia-persistence/src/test/java/org/nuiton/topia/TopiaDatabase.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Modified: trunk/topia-persistence/src/test/java/org/nuiton/topia/framework/EntityStateTest.java
===================================================================
--- trunk/topia-persistence/src/test/java/org/nuiton/topia/framework/EntityStateTest.java 2012-03-02 10:08:45 UTC (rev 2415)
+++ trunk/topia-persistence/src/test/java/org/nuiton/topia/framework/EntityStateTest.java 2012-03-02 10:08:59 UTC (rev 2416)
@@ -30,20 +30,20 @@
/**
* EntityStateTest.java
- *
+ * <p/>
* Created: 22 nov. 06 12:15:11
*
* @author poussin <poussin(a)codelutin.com>
* @version $Revision$
- *
- * Last update: $Date$
- * by : $Author$
+ * <p/>
+ * Last update: $Date$
+ * by : $Author$
*/
public class EntityStateTest {
/**
* Test les changements d'etat de {@link EntityState}.
- *
+ *
* @throws Exception
*/
@Test
Modified: trunk/topia-persistence/src/test/java/org/nuiton/topia/framework/TopiaConnectionProviderTest.java
===================================================================
--- trunk/topia-persistence/src/test/java/org/nuiton/topia/framework/TopiaConnectionProviderTest.java 2012-03-02 10:08:45 UTC (rev 2415)
+++ trunk/topia-persistence/src/test/java/org/nuiton/topia/framework/TopiaConnectionProviderTest.java 2012-03-02 10:08:59 UTC (rev 2416)
@@ -24,16 +24,12 @@
*/
package org.nuiton.topia.framework;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.hibernate.cfg.Environment;
-import org.junit.After;
import org.junit.Assert;
-import org.junit.BeforeClass;
+import org.junit.Rule;
import org.junit.Test;
-import org.nuiton.topia.TestHelper;
import org.nuiton.topia.TopiaContext;
import org.nuiton.topia.TopiaContextFactory;
+import org.nuiton.topia.TopiaDatabase;
import org.nuiton.topia.TopiaException;
import org.nuiton.topia.TopiaTestDAOHelper;
import org.nuiton.topia.test.entities.Person;
@@ -55,54 +51,67 @@
*/
public class TopiaConnectionProviderTest {
+// private static final Log log =
+// LogFactory.getLog(TopiaConnectionProviderTest.class);
- private static final Log log =
- LogFactory.getLog(TopiaConnectionProviderTest.class);
+ public static final String TEST_URL = "testURL";
- protected static File testBasedir;
+ @Rule
+ public final TopiaDatabase db =
+ new TopiaDatabase("/TopiaConnectionProviderHardcoded.properties") {
- public static final String TEST_URL = "testURL";
+ @Override
+ protected void onDbConfigurationCreate(Properties configuration,
+ File testdir,
+ String dbPath) {
- protected TopiaContext root;
+ Assert.assertFalse(testdir.exists());
- @BeforeClass
- public static void setUpClass() throws Exception {
+ String dbPathFake = new File(testdir, "fake" + File.separator + "db").getAbsolutePath();
- testBasedir = TestHelper.getTestBasedir(TopiaConnectionProviderTest.class);
- }
+ Assert.assertFalse(new File(dbPathFake).getParentFile().exists());
- @After
- public void tearDown() throws TopiaException {
- if (root != null && !root.isClosed()) {
- root.closeContext();
- }
- }
+ configuration.setProperty("dbPath", dbPath);
+ configuration.setProperty("dbPathFake", dbPathFake);
+ // give the path where connection provider will create db
+ configuration.setProperty(TEST_URL,
+ "jdbc:h2:file:" + dbPath);
+
+ // give a fake db path (we will make sure it is never create after hibernate usage).
+ configuration.setProperty(TopiaContextFactory.CONFIG_URL,
+ "jdbc:h2:file:" + dbPathFake);
+ }
+ };
+
@Test
public void testWithHardcoded() throws Exception {
- Properties dbProperties = TestHelper.loadHibernateConfiguration(
- "/TopiaConnectionProviderHardcoded.properties");
+// Properties dbProperties = TestHelper.loadHibernateConfiguration(
+// "/TopiaConnectionProviderHardcoded.properties");
+//
+// File directory = new File(TestHelper.getDbName(testBasedir, "testWithHardcoded"));
- File directory = new File(TestHelper.getDbName(testBasedir, "testWithHardcoded"));
+ String dbPath = (String) db.getDbConfiguration().get("dbPath");
+ String dbPathFake = (String) db.getDbConfiguration().get("dbPathFake");
- String dbPath = new File(directory, "real" + File.separator + "db").getAbsolutePath();
- Assert.assertFalse(new File(dbPath).getParentFile().exists());
+// new File(directory, "real" + File.separator + "db").getAbsolutePath();
+// Assert.assertFalse(new File(dbPath).getParentFile().exists());
- String dbPathFake = new File(directory, "fake" + File.separator + "db").getAbsolutePath();
+// String dbPathFake = new File(directory, "fake" + File.separator + "db").getAbsolutePath();
- Assert.assertFalse(new File(dbPathFake).getParentFile().exists());
+// Assert.assertFalse(new File(dbPathFake).getParentFile().exists());
- // give the path where connection provider will create db
- dbProperties.setProperty(TEST_URL, "jdbc:h2:file:" + dbPath);
+// // give the path where connection provider will create db
+// dbProperties.setProperty(TEST_URL, "jdbc:h2:file:" + dbPath);
+//
+// // give a fake db path (we will make sure it is never create after hibernate usage).
+// dbProperties.setProperty(Environment.URL, "jdbc:h2:file:" + dbPathFake);
+//
+// root = TopiaContextFactory.getContext(dbProperties);
- // give a fake db path (we will make sure it is never create after hibernate usage).
- dbProperties.setProperty(Environment.URL, "jdbc:h2:file:" + dbPathFake);
+ Locale.setDefault(Locale.FRANCE);
- root = TopiaContextFactory.getContext(dbProperties);
-
- Locale.setDefault(Locale.FRANCE);
-
doStuffOnDb();
// the db file must have been created
@@ -113,7 +122,7 @@
}
private void doStuffOnDb() throws TopiaException {
- TopiaContext transaction = root.beginTransaction();
+ TopiaContext transaction = db.beginTransaction();
try {
PersonDAO dao = TopiaTestDAOHelper.getPersonDAO(transaction);
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 2012-03-02 10:08:45 UTC (rev 2415)
+++ trunk/topia-persistence/src/test/java/org/nuiton/topia/framework/TopiaContextImplTest.java 2012-03-02 10:08:59 UTC (rev 2416)
@@ -35,16 +35,9 @@
import org.junit.BeforeClass;
import org.junit.Test;
import org.nuiton.i18n.I18n;
-import org.nuiton.topia.TestHelper;
-import org.nuiton.topia.TopiaContext;
import org.nuiton.topia.TopiaContextFactory;
-import org.nuiton.topia.TopiaException;
+import org.nuiton.topia.TopiaDatabase;
import org.nuiton.topia.TopiaNotFoundException;
-import org.nuiton.topia.TopiaTestDAOHelper;
-import org.nuiton.topia.test.entities.Person;
-import org.nuiton.topia.test.entities.PersonDAO;
-import org.nuiton.topia.test.entities.Pet;
-import org.nuiton.topia.test.entities.PetDAO;
import org.nuiton.topiatest.persistence.Entity1;
import org.nuiton.topiatest.persistence.Entity1Impl;
import org.nuiton.topiatest.service.FakeService;
@@ -74,7 +67,7 @@
@BeforeClass
public static void setUpClass() throws Exception {
- testBasedir = TestHelper.getTestBasedir(TopiaContextImplTest.class);
+ testBasedir = TopiaDatabase.getTestSpecificDirectory(TopiaContextImplTest.class, "dummy");
I18n.init(null, Locale.FRENCH);
}
@@ -371,102 +364,102 @@
// Note : maybe add a test to load classes from services
}
- @Test
- public void replicateEntity() throws Exception {
+// @Test
+// public void replicateEntity() throws Exception {
+//
+// Properties configSource = TestHelper.initTopiaContextConfiguration(
+// testBasedir,
+// "/TopiaContextImpl.properties",
+// "replicateSource");
+//
+// Properties configTarget = TestHelper.initTopiaContextConfiguration(
+// testBasedir,
+// "/TopiaContextImpl.properties",
+// "replicateTarget");
+//
+//
+// TopiaContext contextSource = null;
+// TopiaContext contextTarget = null;
+//
+// try {
+// contextSource = TopiaContextFactory.getContext(configSource);
+// contextTarget = TopiaContextFactory.getContext(configTarget);
+//
+// TopiaContext txSource;
+// TopiaContext txTarget;
+// PersonDAO daoSource, daoTarget;
+// PetDAO petDAOSource, petDAOTarget;
+// Person personSource, personTarget;
+// Pet petSource, petTarget;
+//
+// txSource = contextSource.beginTransaction();
+// daoSource = TopiaTestDAOHelper.getPersonDAO(txSource);
+// petDAOSource = TopiaTestDAOHelper.getPetDAO(txSource);
+//
+// personSource = daoSource.create(Person.PROPERTY_FIRSTNAME, " firstName",
+// Person.PROPERTY_NAME, " name"
+// );
+//
+// petSource = petDAOSource.create(Pet.PROPERTY_NAME, "name",
+// Pet.PROPERTY_TYPE, "type",
+// Pet.PROPERTY_PERSON, personSource
+// );
+//
+// personSource.addPet(petSource);
+//
+// txSource.commitTransaction();
+//
+// daoSource = TopiaTestDAOHelper.getPersonDAO(txSource);
+//
+// personSource = daoSource.findByTopiaId(personSource.getTopiaId());
+// Assert.assertNotNull(personSource);
+//
+// petSource = petDAOSource.findByTopiaId(petSource.getTopiaId());
+// Assert.assertNotNull(petSource);
+// Assert.assertEquals(1, personSource.sizePet());
+// Assert.assertEquals(petSource, personSource.getPet().iterator().next());
+//
+// txTarget = contextTarget.beginTransaction();
+//
+// txSource.replicateEntity(txTarget, petSource);
+// txSource.replicateEntity(txTarget, personSource);
+//
+// txTarget.commitTransaction();
+//
+// daoTarget = TopiaTestDAOHelper.getPersonDAO(txTarget);
+// petDAOTarget = TopiaTestDAOHelper.getPetDAO(txTarget);
+//
+// personTarget = daoTarget.findByTopiaId(personSource.getTopiaId());
+// Assert.assertNotNull(personTarget);
+// Assert.assertEquals(personSource, personTarget);
+// Assert.assertEquals(1, personTarget.sizePet());
+//
+// petTarget = petDAOTarget.findByTopiaId(petSource.getTopiaId());
+// Assert.assertNotNull(petTarget);
+// Assert.assertEquals(petSource, petTarget);
+//
+// Assert.assertEquals(petTarget, personTarget.getPet().iterator().next());
+//
+//
+// } finally {
+// closeDb(contextSource);
+// closeDb(contextTarget);
+// }
+//
+// }
+//
+// protected static void closeDb(TopiaContext contextSource) {
+// if (contextSource != null && !contextSource.isClosed())
+// try {
+// contextSource.clear(false);
+// } catch (TopiaException e) {
+// if (log.isErrorEnabled()) {
+// log.error("Could not close db " + contextSource, e);
+// }
+// }
+// }
- Properties configSource = TestHelper.initTopiaContextConfiguration(
- testBasedir,
- "/TopiaContextImpl.properties",
- "replicateSource");
- Properties configTarget = TestHelper.initTopiaContextConfiguration(
- testBasedir,
- "/TopiaContextImpl.properties",
- "replicateTarget");
-
-
- TopiaContext contextSource = null;
- TopiaContext contextTarget = null;
-
- try {
- contextSource = TopiaContextFactory.getContext(configSource);
- contextTarget = TopiaContextFactory.getContext(configTarget);
-
- TopiaContext txSource;
- TopiaContext txTarget;
- PersonDAO daoSource, daoTarget;
- PetDAO petDAOSource, petDAOTarget;
- Person personSource, personTarget;
- Pet petSource, petTarget;
-
- txSource = contextSource.beginTransaction();
- daoSource = TopiaTestDAOHelper.getPersonDAO(txSource);
- petDAOSource = TopiaTestDAOHelper.getPetDAO(txSource);
-
- personSource = daoSource.create(Person.PROPERTY_FIRSTNAME, " firstName",
- Person.PROPERTY_NAME, " name"
- );
-
- petSource = petDAOSource.create(Pet.PROPERTY_NAME, "name",
- Pet.PROPERTY_TYPE, "type",
- Pet.PROPERTY_PERSON, personSource
- );
-
- personSource.addPet(petSource);
-
- txSource.commitTransaction();
-
- daoSource = TopiaTestDAOHelper.getPersonDAO(txSource);
-
- personSource = daoSource.findByTopiaId(personSource.getTopiaId());
- Assert.assertNotNull(personSource);
-
- petSource = petDAOSource.findByTopiaId(petSource.getTopiaId());
- Assert.assertNotNull(petSource);
- Assert.assertEquals(1, personSource.sizePet());
- Assert.assertEquals(petSource, personSource.getPet().iterator().next());
-
- txTarget = contextTarget.beginTransaction();
-
- txSource.replicateEntity(txTarget, petSource);
- txSource.replicateEntity(txTarget, personSource);
-
- txTarget.commitTransaction();
-
- daoTarget = TopiaTestDAOHelper.getPersonDAO(txTarget);
- petDAOTarget = TopiaTestDAOHelper.getPetDAO(txTarget);
-
- personTarget = daoTarget.findByTopiaId(personSource.getTopiaId());
- Assert.assertNotNull(personTarget);
- Assert.assertEquals(personSource, personTarget);
- Assert.assertEquals(1, personTarget.sizePet());
-
- petTarget = petDAOTarget.findByTopiaId(petSource.getTopiaId());
- Assert.assertNotNull(petTarget);
- Assert.assertEquals(petSource, petTarget);
-
- Assert.assertEquals(petTarget, personTarget.getPet().iterator().next());
-
-
- } finally {
- closeDb(contextSource);
- closeDb(contextTarget);
- }
-
- }
-
- protected static void closeDb(TopiaContext contextSource) {
- if (contextSource != null && !contextSource.isClosed())
- try {
- contextSource.clear(false);
- } catch (TopiaException e) {
- if (log.isErrorEnabled()) {
- log.error("Could not close db " + contextSource, e);
- }
- }
- }
-
-
//
// @Test
// public void testGetHibernateConfiguration() throws Exception {
Added: trunk/topia-persistence/src/test/java/org/nuiton/topia/framework/TopiaContextReplicateTest.java
===================================================================
--- trunk/topia-persistence/src/test/java/org/nuiton/topia/framework/TopiaContextReplicateTest.java (rev 0)
+++ trunk/topia-persistence/src/test/java/org/nuiton/topia/framework/TopiaContextReplicateTest.java 2012-03-02 10:08:59 UTC (rev 2416)
@@ -0,0 +1,157 @@
+/*
+ * #%L
+ * ToPIA :: Persistence
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2004 - 2012 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
+package org.nuiton.topia.framework;
+
+import org.junit.Assert;
+import org.junit.Rule;
+import org.junit.Test;
+import org.nuiton.topia.TopiaContext;
+import org.nuiton.topia.TopiaContextFactory;
+import org.nuiton.topia.TopiaDatabase;
+import org.nuiton.topia.TopiaTestDAOHelper;
+import org.nuiton.topia.test.entities.Person;
+import org.nuiton.topia.test.entities.PersonDAO;
+import org.nuiton.topia.test.entities.Pet;
+import org.nuiton.topia.test.entities.PetDAO;
+
+import java.io.File;
+import java.util.Properties;
+
+/**
+ * To test replication sugin TopiaContext.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.6.8
+ */
+public class TopiaContextReplicateTest {
+
+ @Rule
+ public final TopiaDatabase dbSource =
+ new TopiaDatabase() {
+
+ @Override
+ protected void onDbConfigurationCreate(Properties configuration, File testDir, String dbPath) {
+ configuration.setProperty(
+ TopiaContextFactory.CONFIG_URL, "jdbc:h2:file:" + dbPath + "-source");
+
+ }
+ };
+
+ @Rule
+ public final TopiaDatabase dbTarget =
+ new TopiaDatabase() {
+
+ @Override
+ protected void onDbConfigurationCreate(Properties configuration, File testDir, String dbPath) {
+ configuration.setProperty(
+ TopiaContextFactory.CONFIG_URL, "jdbc:h2:file:" + dbPath + "-target");
+
+ }
+ };
+
+ @Test
+ public void replicateEntity() throws Exception {
+//
+// Properties configSource = TestHelper.initTopiaContextConfiguration(
+// testBasedir,
+// "/TopiaContextImpl.properties",
+// "replicateSource");
+//
+// Properties configTarget = TestHelper.initTopiaContextConfiguration(
+// testBasedir,
+// "/TopiaContextImpl.properties",
+// "replicateTarget");
+//
+
+ TopiaContext contextSource = dbSource.getRootCtxt();
+ TopiaContext contextTarget = dbTarget.getRootCtxt();
+
+// try {
+// contextSource = TopiaContextFactory.getContext(configSource);
+// contextTarget = TopiaContextFactory.getContext(configTarget);
+
+ TopiaContext txSource;
+ TopiaContext txTarget;
+ PersonDAO daoSource, daoTarget;
+ PetDAO petDAOSource, petDAOTarget;
+ Person personSource, personTarget;
+ Pet petSource, petTarget;
+
+ txSource = contextSource.beginTransaction();
+ daoSource = TopiaTestDAOHelper.getPersonDAO(txSource);
+ petDAOSource = TopiaTestDAOHelper.getPetDAO(txSource);
+
+ personSource = daoSource.create(Person.PROPERTY_FIRSTNAME, " firstName",
+ Person.PROPERTY_NAME, " name"
+ );
+
+ petSource = petDAOSource.create(Pet.PROPERTY_NAME, "name",
+ Pet.PROPERTY_TYPE, "type",
+ Pet.PROPERTY_PERSON, personSource
+ );
+
+ personSource.addPet(petSource);
+
+ txSource.commitTransaction();
+
+ daoSource = TopiaTestDAOHelper.getPersonDAO(txSource);
+
+ personSource = daoSource.findByTopiaId(personSource.getTopiaId());
+ Assert.assertNotNull(personSource);
+
+ petSource = petDAOSource.findByTopiaId(petSource.getTopiaId());
+ Assert.assertNotNull(petSource);
+ Assert.assertEquals(1, personSource.sizePet());
+ Assert.assertEquals(petSource, personSource.getPet().iterator().next());
+
+ txTarget = contextTarget.beginTransaction();
+
+ txSource.replicateEntity(txTarget, petSource);
+ txSource.replicateEntity(txTarget, personSource);
+
+ txTarget.commitTransaction();
+
+ daoTarget = TopiaTestDAOHelper.getPersonDAO(txTarget);
+ petDAOTarget = TopiaTestDAOHelper.getPetDAO(txTarget);
+
+ personTarget = daoTarget.findByTopiaId(personSource.getTopiaId());
+ Assert.assertNotNull(personTarget);
+ Assert.assertEquals(personSource, personTarget);
+ Assert.assertEquals(1, personTarget.sizePet());
+
+ petTarget = petDAOTarget.findByTopiaId(petSource.getTopiaId());
+ Assert.assertNotNull(petTarget);
+ Assert.assertEquals(petSource, petTarget);
+
+ Assert.assertEquals(petTarget, personTarget.getPet().iterator().next());
+
+
+// } finally {
+// closeDb(contextSource);
+// closeDb(contextTarget);
+// }
+
+ }
+}
Property changes on: trunk/topia-persistence/src/test/java/org/nuiton/topia/framework/TopiaContextReplicateTest.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Modified: trunk/topia-persistence/src/test/java/org/nuiton/topia/framework/TopiaQueryTest.java
===================================================================
--- trunk/topia-persistence/src/test/java/org/nuiton/topia/framework/TopiaQueryTest.java 2012-03-02 10:08:45 UTC (rev 2415)
+++ trunk/topia-persistence/src/test/java/org/nuiton/topia/framework/TopiaQueryTest.java 2012-03-02 10:08:59 UTC (rev 2416)
@@ -46,7 +46,7 @@
query.addEquals(QueriedEntity.PROPERTY_TEST_ADD, value);
Assert.assertEquals(
"FROM org.nuiton.topiatest.QueriedEntity " +
- "WHERE testAdd = :testAdd",
+ "WHERE testAdd = :testAdd",
query.fullQuery());
// Test with null paramValue
@@ -55,7 +55,7 @@
query.addEquals(QueriedEntity.PROPERTY_TEST_ADD, new Object[]{null});
Assert.assertEquals(
"FROM org.nuiton.topiatest.QueriedEntity " +
- "WHERE testAdd IS NULL",
+ "WHERE testAdd IS NULL",
query.fullQuery());
// Test with two paramValues
@@ -64,7 +64,7 @@
query.addEquals(QueriedEntity.PROPERTY_TEST_ADD, value, value2);
Assert.assertEquals(
"FROM org.nuiton.topiatest.QueriedEntity " +
- "WHERE testAdd IN (:testAdd1, :testAdd2)",
+ "WHERE testAdd IN (:testAdd1, :testAdd2)",
query.fullQuery());
// Test with two paramValues + null
@@ -72,7 +72,7 @@
query.addEquals(QueriedEntity.PROPERTY_TEST_ADD, value, value2, null);
Assert.assertEquals(
"FROM org.nuiton.topiatest.QueriedEntity " +
- "WHERE testAdd IN (:testAdd1, :testAdd2) OR testAdd IS NULL",
+ "WHERE testAdd IN (:testAdd1, :testAdd2) OR testAdd IS NULL",
query.fullQuery());
}
@@ -139,12 +139,10 @@
query.addSubQuery(QueriedEntity.PROPERTY_TEST_ADD + " IN (?)", subquery);
log.debug(query);
- Assert.assertEquals(4, query.getParams().size());
+ Assert.assertEquals(4, query.getParams().size());
}
- /**
- * Test of addFilter method, of class TopiaQuery.
- */
+ /** Test of addFilter method, of class TopiaQuery. */
@Test
public void testAddFilter() {
log.info("testAddFilter");
@@ -159,8 +157,8 @@
log.debug("Query : " + query);
Assert.assertEquals("FROM " + QueriedEntity.class.getName() +
- " ORDER BY " + QueriedEntity.PROPERTY_TEST_ADD,
- query.fullQuery());
+ " ORDER BY " + QueriedEntity.PROPERTY_TEST_ADD,
+ query.fullQuery());
filter.setOrderBy(null);
@@ -169,8 +167,8 @@
log.debug("Query : " + query);
Assert.assertEquals("FROM " + QueriedEntity.class.getName() +
- " ORDER BY " + TopiaEntity.TOPIA_CREATE_DATE + " DESC",
- query.fullQuery());
+ " ORDER BY " + TopiaEntity.TOPIA_CREATE_DATE + " DESC",
+ query.fullQuery());
}
@@ -184,8 +182,8 @@
log.debug("Query : " + query);
Assert.assertEquals("FROM " + QueriedEntity.class.getName() +
- " WHERE lower(name) LIKE :lower_name_",
- query.fullQuery());
+ " WHERE lower(name) LIKE :lower_name_",
+ query.fullQuery());
}
}
Modified: trunk/topia-persistence/src/test/java/org/nuiton/topia/framework/TopiaUtilTest.java
===================================================================
--- trunk/topia-persistence/src/test/java/org/nuiton/topia/framework/TopiaUtilTest.java 2012-03-02 10:08:45 UTC (rev 2415)
+++ trunk/topia-persistence/src/test/java/org/nuiton/topia/framework/TopiaUtilTest.java 2012-03-02 10:08:59 UTC (rev 2416)
@@ -25,15 +25,13 @@
package org.nuiton.topia.framework;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
+import org.junit.Rule;
import org.junit.Test;
-import org.nuiton.topia.TestHelper;
import org.nuiton.topia.TopiaContext;
+import org.nuiton.topia.TopiaDatabase;
import org.nuiton.topia.test.entities.PersonImpl;
import org.nuiton.topiatest.Personne;
-import java.io.File;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -56,24 +54,9 @@
protected static final String PERSON_ID2 = "org.nuiton.topiatest.Personne#1226701039001#0.6502325993664999";
- private static TopiaContext rootContext;
+ @Rule
+ public final TopiaDatabase db = new TopiaDatabase();
- @BeforeClass
- public static void setUpClass() throws Exception {
-
-
- File testBasedir = TestHelper.getTestBasedir(TopiaUtilTest.class);
-
- rootContext = TestHelper.initTopiaContext(testBasedir, "topiautilest");
- }
-
- @AfterClass
- public static void tearDownClass() throws Exception {
- if (rootContext != null) {
- rootContext.closeContext();
- }
- }
-
@Test
public void testGetTopiaIdPattern() throws Exception {
String expected;
@@ -109,27 +92,22 @@
@Test(expected = IllegalArgumentException.class)
public void testIsSchemaExistFailed() throws Exception {
- TopiaUtil.isSchemaExist(rootContext, "fake");
+ TopiaUtil.isSchemaExist(db.getRootCtxt(), "fake");
}
@Test
public void testIsSchemaExist() throws Exception {
+ TopiaContext rootContext = db.getRootCtxt();
boolean actual = TopiaUtil.isSchemaExist(rootContext,
PersonImpl.class.getName());
assertFalse(actual);
TopiaContext tx = rootContext.beginTransaction();
- try {
- tx.createSchema();
- actual = TopiaUtil.isSchemaExist(rootContext, PersonImpl.class.getName());
+ tx.createSchema();
+ actual = TopiaUtil.isSchemaExist(rootContext, PersonImpl.class.getName());
- assertTrue(actual);
- } finally {
- if (tx != null) {
- tx.closeContext();
- }
- }
+ assertTrue(actual);
}
}
Modified: trunk/topia-persistence/src/test/java/org/nuiton/topia/generator/TopiaGeneratorUtilTest.java
===================================================================
--- trunk/topia-persistence/src/test/java/org/nuiton/topia/generator/TopiaGeneratorUtilTest.java 2012-03-02 10:08:45 UTC (rev 2415)
+++ trunk/topia-persistence/src/test/java/org/nuiton/topia/generator/TopiaGeneratorUtilTest.java 2012-03-02 10:08:59 UTC (rev 2416)
@@ -26,12 +26,10 @@
package org.nuiton.topia.generator;
import org.junit.Test;
-import static org.junit.Assert.*;
-/**
- *
- * @author tchemit <chemit(a)codelutin.com>
- */
+import static org.junit.Assert.assertEquals;
+
+/** @author tchemit <chemit(a)codelutin.com> */
public class TopiaGeneratorUtilTest {
@Deprecated
@@ -47,7 +45,7 @@
expResult = "ABC";
result = TopiaGeneratorUtil.convertVariableNameToConstantName(variableName);
assertEquals(expResult, result);
-
+
variableName = "abC";
expResult = "AB_C";
result = TopiaGeneratorUtil.convertVariableNameToConstantName(variableName);
Modified: trunk/topia-persistence/src/test/java/org/nuiton/topia/generator/TopiaTestCase.java
===================================================================
--- trunk/topia-persistence/src/test/java/org/nuiton/topia/generator/TopiaTestCase.java 2012-03-02 10:08:45 UTC (rev 2415)
+++ trunk/topia-persistence/src/test/java/org/nuiton/topia/generator/TopiaTestCase.java 2012-03-02 10:08:59 UTC (rev 2416)
@@ -27,26 +27,18 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.junit.AfterClass;
import org.junit.Assert;
-import org.junit.Before;
-import org.junit.BeforeClass;
+import org.junit.Rule;
import org.junit.Test;
-import org.nuiton.topia.TestHelper;
import org.nuiton.topia.TopiaContext;
-import org.nuiton.topia.TopiaContextFactory;
+import org.nuiton.topia.TopiaDatabase;
import org.nuiton.topia.TopiaException;
-import org.nuiton.topia.TopiaNotFoundException;
import org.nuiton.topia.TopiaTestDAOHelper;
import org.nuiton.topiatest.Company;
import org.nuiton.topiatest.CompanyDAO;
import org.nuiton.topiatest.Department;
import org.nuiton.topiatest.DepartmentDAO;
-import java.io.File;
-import java.io.IOException;
-import java.util.Properties;
-
/**
* TopiaTestCase.
*
@@ -61,115 +53,118 @@
/** Logger */
private final static Log log = LogFactory.getLog(TopiaTestCase.class);
- /** Proprietes */
- protected static Properties config;
+ @Rule
+ public final TopiaDatabase db = new TopiaDatabase();
- /** TopiaContext */
- protected static TopiaContext context;
+// /** Proprietes */
+// protected static Properties config;
+//
+// /** TopiaContext */
+// protected static TopiaContext context;
- /**
- * Init les proprietes de connection a la base
- *
- * @throws IOException for any IO error while getting configuration.
- */
- @BeforeClass
- public static void init() throws IOException {
+// /**
+// * Init les proprietes de connection a la base
+// *
+// * @throws IOException for any IO error while getting configuration.
+// */
+// @BeforeClass
+// public static void init() throws IOException {
+//
+// File testBasedir = TestHelper.getTestBasedir(TopiaTestCase.class);
+//
+// config = TestHelper.initTopiaContextConfiguration(
+// testBasedir,
+// "/TopiaContextImpl.properties",
+// "TopiaTestCaseDb");
+//// config = new Properties();
+//// config.setProperty("topia.persistence.classes", TopiaTestDAOHelper.getImplementationClassesAsString());
+////
+//// config.setProperty(Environment.USER, "sa");
+//// config.setProperty(Environment.PASS, "");
+//// config.setProperty(Environment.CURRENT_SESSION_CONTEXT_CLASS, "thread");
+//// config.setProperty(Environment.DIALECT, "org.hibernate.dialect.H2Dialect");
+//// config.setProperty(Environment.DRIVER, "org.h2.Driver");
+//// config.setProperty(Environment.URL, "jdbc:h2:file:" + testBasedir + "/db/data_" + System.currentTimeMillis());
+// }
+//
+// @AfterClass
+// public static void after() throws TopiaException {
+// // destroy database
+// context.clear(false);
+// }
- File testBasedir = TestHelper.getTestBasedir(TopiaTestCase.class);
-
- config = TestHelper.initTopiaContextConfiguration(
- testBasedir,
- "/TopiaContextImpl.properties",
- "TopiaTestCaseDb");
-// config = new Properties();
-// config.setProperty("topia.persistence.classes", TopiaTestDAOHelper.getImplementationClassesAsString());
+// /** Create base with schema created. */
+// @Before
+// public void setUp() {
//
-// config.setProperty(Environment.USER, "sa");
-// config.setProperty(Environment.PASS, "");
-// config.setProperty(Environment.CURRENT_SESSION_CONTEXT_CLASS, "thread");
-// config.setProperty(Environment.DIALECT, "org.hibernate.dialect.H2Dialect");
-// config.setProperty(Environment.DRIVER, "org.h2.Driver");
-// config.setProperty(Environment.URL, "jdbc:h2:file:" + testBasedir + "/db/data_" + System.currentTimeMillis());
- }
+// if (log.isDebugEnabled()) {
+// log.debug("Junit beforeTest");
+// }
+//
+// try {
+// context = TopiaContextFactory.getContext(config);
+//
+// try {
+// context.createSchema();
+// } catch (TopiaException e) {
+// log.error("Erreur à la creation du schema", e);
+// }
+// } catch (TopiaNotFoundException e) {
+// log.error("Erreur à la creation du topia context", e);
+// }
+// }
- @AfterClass
- public static void after() throws TopiaException {
- // destroy database
- context.clear(false);
- }
-
- /** Create base with schema created. */
- @Before
- public void setUp() {
-
- if (log.isDebugEnabled()) {
- log.debug("Junit beforeTest");
- }
-
- try {
- context = TopiaContextFactory.getContext(config);
-
- try {
- context.createSchema();
- } catch (TopiaException e) {
- log.error("Erreur à la creation du schema", e);
- }
- } catch (TopiaNotFoundException e) {
- log.error("Erreur à la creation du topia context", e);
- }
- }
-
@Test
- public void testCompositeAssociations() {
+ public void testCompositeAssociations() throws TopiaException {
if (log.isDebugEnabled()) {
log.debug("Junit Test testCompositeAssociations");
}
- try {
- TopiaContext newContext = context.beginTransaction();
+// try {
+ TopiaContext newContext = db.beginTransaction();
- CompanyDAO companyDAO = TopiaTestDAOHelper.getCompanyDAO(newContext);
- DepartmentDAO departmentDAO = TopiaTestDAOHelper.getDepartmentDAO(newContext);
+ CompanyDAO companyDAO = TopiaTestDAOHelper.getCompanyDAO(newContext);
+ DepartmentDAO departmentDAO = TopiaTestDAOHelper.getDepartmentDAO(newContext);
- Company company = companyDAO.create();
- company.setName("Ma société");
+ Company company = companyDAO.create();
+ company.setName("Ma société");
- Department dep1 = departmentDAO.create();
- dep1.setName("Departement 1");
- Department dep2 = departmentDAO.create();
- dep2.setName("Departement 2");
- Department dep3 = departmentDAO.create();
- dep3.setName("Departement 3");
- Department dep4 = departmentDAO.create();
- dep4.setName("Departement 7");
+ Department dep1 = departmentDAO.create();
+ dep1.setName("Departement 1");
+ Department dep2 = departmentDAO.create();
+ dep2.setName("Departement 2");
+ Department dep3 = departmentDAO.create();
+ dep3.setName("Departement 3");
+ Department dep4 = departmentDAO.create();
+ dep4.setName("Departement 7");
- departmentDAO.update(dep1);
- departmentDAO.update(dep2);
- departmentDAO.update(dep3);
- departmentDAO.update(dep4);
+ departmentDAO.update(dep1);
+ departmentDAO.update(dep2);
+ departmentDAO.update(dep3);
+ departmentDAO.update(dep4);
- company.addDepartment(dep1);
- company.addDepartment(dep2);
- company.addDepartment(dep3);
- company.addDepartment(dep4);
+ company.addDepartment(dep1);
+ company.addDepartment(dep2);
+ company.addDepartment(dep3);
+ company.addDepartment(dep4);
- companyDAO.update(company);
- newContext.commitTransaction();
+ companyDAO.update(company);
+ newContext.commitTransaction();
- newContext = context.beginTransaction();
+ newContext = db.beginTransaction();
- companyDAO = TopiaTestDAOHelper.getCompanyDAO(newContext);
+ companyDAO = TopiaTestDAOHelper.getCompanyDAO(newContext);
- company = companyDAO.findByTopiaId(company.getTopiaId());
+ company = companyDAO.findByTopiaId(company.getTopiaId());
- Assert.assertEquals(company.getName(), "Ma société");
- Assert.assertEquals(company.getDepartment().size(), 4);
+ Assert.assertEquals(company.getName(), "Ma société");
+ Assert.assertEquals(company.getDepartment().size(), 4);
- newContext.commitTransaction();
- newContext.closeContext();
- } catch (TopiaException e) {
- log.error("Erreur pendant le test testCompositeAssociations", e);
- }
+ newContext.commitTransaction();
+// newContext.closeContext();
+// } catch (TopiaException e) {
+// log.error("Erreur pendant le test testCompositeAssociations", e);
+// }
}
}
Modified: trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/EntityVisitorExportXmlTest.java
===================================================================
--- trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/EntityVisitorExportXmlTest.java 2012-03-02 10:08:45 UTC (rev 2415)
+++ trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/EntityVisitorExportXmlTest.java 2012-03-02 10:08:59 UTC (rev 2416)
@@ -27,15 +27,11 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.hibernate.cfg.Environment;
-import org.junit.After;
-import org.junit.AfterClass;
import org.junit.Before;
-import org.junit.BeforeClass;
+import org.junit.Rule;
import org.junit.Test;
-import org.nuiton.topia.TestHelper;
import org.nuiton.topia.TopiaContext;
-import org.nuiton.topia.TopiaContextFactory;
+import org.nuiton.topia.TopiaDatabase;
import org.nuiton.topia.TopiaException;
import org.nuiton.topia.TopiaTestDAOHelper;
import org.nuiton.topiatest.Address;
@@ -46,12 +42,7 @@
import org.nuiton.topiatest.DepartmentDAO;
import org.nuiton.topiatest.Employe;
import org.nuiton.topiatest.EmployeDAO;
-import org.nuiton.util.FileUtil;
-import java.io.File;
-import java.io.IOException;
-import java.util.Properties;
-
/**
* Test de visitor.
*
@@ -63,122 +54,57 @@
*/
public class EntityVisitorExportXmlTest {
- private static Log log = LogFactory.getLog(EntityVisitorExportXmlTest.class);
+ private static final Log log =
+ LogFactory.getLog(EntityVisitorExportXmlTest.class);
- protected static File tempDir;
+ @Rule
+ public final TopiaDatabase db = new TopiaDatabase();
- protected static Properties config;
-
/**
- * Init les données de tous les tests.
- *
- * @throws IOException
- */
- @BeforeClass
- public static void init() throws IOException {
-
-
- File testBasedir = TestHelper.getTestBasedir(EntityVisitorExportXmlTest.class);
-
- tempDir = FileUtil.createTempDirectory("h2", "-exportxml", testBasedir);
-
- // init dburl
- String dburl = "file:" + tempDir.getAbsolutePath() + File.separator + "data";
-
- // init config
-
- config = new Properties();
- config.setProperty("topia.persistence.classes", TopiaTestDAOHelper.getImplementationClassesAsString());
-
- config.setProperty(Environment.USER, "sa");
- config.setProperty(Environment.PASS, "");
- config.setProperty(Environment.CURRENT_SESSION_CONTEXT_CLASS, "thread");
- config.setProperty(Environment.DIALECT, "org.hibernate.dialect.H2Dialect");
- config.setProperty(Environment.DRIVER, "org.h2.Driver");
- config.setProperty(Environment.URL, "jdbc:h2:" + dburl);
- }
-
- /** Remove temp directory */
- @AfterClass
- public static void clear() {
- // tchemit 2010-11-28 No! never delete tests data, how to see what's happening if something is wrong ???
-// FileUtil.deleteRecursively(tempDir);
- }
-
- /**
* Prepare test.
* <p/>
* Add all tests commons data
*
- * @throws TopiaException
+ * @throws TopiaException if could not create datas
*/
@Before
public void setUp() throws TopiaException {
- TopiaContext context = TopiaContextFactory.getContext(config);
- context.createSchema();
- addData(context);
- }
+ TopiaContext newContext = db.beginTransaction();
+ try {
+ // company
+ CompanyDAO companyDAO = TopiaTestDAOHelper.getCompanyDAO(newContext);
+ Company clCompany = companyDAO.create(Company.PROPERTY_NAME, "CodeLutin");
- /**
- * Add tests data.
- *
- * @param context the context to add
- * @throws TopiaException
- */
- protected void addData(TopiaContext context) throws TopiaException {
+ // employe
+ EmployeDAO employeDAO = TopiaTestDAOHelper.getEmployeDAO(newContext);
+ Employe empl1 = employeDAO.create(Employe.PROPERTY_NAME, "boss", Employe.PROPERTY_SALARY, 30000);
- TopiaContext newContext = context.beginTransaction();
+ AddressDAO adressDAO = TopiaTestDAOHelper.getAddressDAO(newContext);
+ Address addr1 = adressDAO.create(Address.PROPERTY_CITY, "Nantes", Address.PROPERTY_ADRESS, "12 Avenue Jules Vernes");
+ empl1.setAddress(addr1);
- // company
- CompanyDAO companyDAO = TopiaTestDAOHelper.getCompanyDAO(newContext);
- Company clCompany = companyDAO.create();
- clCompany.setName("CodeLutin");
+ Employe empl2 = employeDAO.create(Employe.PROPERTY_NAME, "boss2", Employe.PROPERTY_SALARY, 29000);
+ Address addr2 = adressDAO.create(Address.PROPERTY_CITY, "Nantes", Address.PROPERTY_ADRESS, "12 Avenue Jules Vernes");
+ empl2.setAddress(addr2);
- // employe
- EmployeDAO employeDAO = TopiaTestDAOHelper.getEmployeDAO(newContext);
- Employe empl1 = employeDAO.create();
- empl1.setName("boss");
- empl1.setSalary(30000);
+ // departement
+ DepartmentDAO departmentDAO = TopiaTestDAOHelper.getDepartmentDAO(newContext);
+ Department depComm = departmentDAO.create(Department.PROPERTY_NAME, "Commercial");
+ depComm.setLeader(empl1);
- AddressDAO adressDAO = TopiaTestDAOHelper.getAddressDAO(newContext);
- Address addr1 = adressDAO.create();
- addr1.setCity("nantes");
- addr1.setAdress("bd des pas enchantés");
- empl1.setAddress(addr1);
+ Department depDev = departmentDAO.create(Department.PROPERTY_NAME, "Dev");
+ depDev.setLeader(empl2);
+ clCompany.addDepartment(depComm);
+ clCompany.addDepartment(depDev);
- Employe empl2 = employeDAO.create();
- empl2.setName("boss2");
- empl2.setSalary(29000);
- Address addr2 = adressDAO.create();
- addr2.setCity("nantes");
- addr2.setAdress("bd des pas enchantés");
- empl2.setAddress(addr2);
+ newContext.commitTransaction();
+ } finally {
- // departement
- DepartmentDAO departmentDAO = TopiaTestDAOHelper.getDepartmentDAO(newContext);
- Department depComm = departmentDAO.create();
- depComm.setName("Commercial");
- depComm.setLeader(empl1);
-
- Department depDev = departmentDAO.create();
- depDev.setName("Dev");
- depDev.setLeader(empl2);
- clCompany.addDepartment(depComm);
- clCompany.addDepartment(depDev);
-
- newContext.commitTransaction();
- newContext.closeContext();
+ newContext.closeContext();
+ }
}
- /** Clean tests. */
- @After
- public void tearDown() {
- // tchemit 2010-11-28 No! never delete tests data, how to see what's happening if something is wrong ???
-// if(tempDir.exists()) {
-// tempDir.delete();
-// }
- }
/**
* Test l'export XML via un visiteur.
@@ -189,9 +115,8 @@
*/
@Test
public void testExportXMLDepth() throws TopiaException {
- TopiaContext rootContext = TopiaContextFactory.getContext(config);
- TopiaContext context = rootContext.beginTransaction();
+ TopiaContext context = db.beginTransaction();
CompanyDAO companyDAO = TopiaTestDAOHelper.getCompanyDAO(context);
Company clCompany = companyDAO.findByName("CodeLutin");
@@ -199,7 +124,6 @@
EntityVisitor delegateVisitor = new ExportXMLVisitor();
EntityVisitor visitor = new DepthEntityVisitor(delegateVisitor);
clCompany.accept(visitor);
- context.closeContext();
if (log.isInfoEnabled()) {
log.info("Export XML = \n" + delegateVisitor.toString());
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 2012-03-02 10:08:45 UTC (rev 2415)
+++ trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/NaturalIdTest.java 2012-03-02 10:08:59 UTC (rev 2416)
@@ -29,19 +29,15 @@
import org.apache.commons.logging.LogFactory;
import org.hibernate.PropertyValueException;
import org.junit.Assert;
-import org.junit.BeforeClass;
+import org.junit.Rule;
import org.junit.Test;
-import org.nuiton.topia.TestHelper;
import org.nuiton.topia.TopiaContext;
+import org.nuiton.topia.TopiaDatabase;
import org.nuiton.topia.TopiaException;
-import org.nuiton.topia.TopiaNotFoundException;
import org.nuiton.topia.TopiaTestDAOHelper;
import org.nuiton.topiatest.NaturalizedEntity;
import org.nuiton.topiatest.NaturalizedEntityDAO;
-import java.io.File;
-import java.io.IOException;
-
/**
* NaturalIdTest
* <p/>
@@ -57,26 +53,13 @@
private static final Log log = LogFactory.getLog(NaturalIdTest.class);
- protected static File testBasedir;
+ @Rule
+ public final TopiaDatabase db = new TopiaDatabase();
- @BeforeClass
- public static void setUpClass() throws Exception {
-
- testBasedir = TestHelper.getTestBasedir(NaturalIdTest.class);
- }
-
- protected TopiaContext initTopiaContext(String testName) throws IOException, TopiaNotFoundException {
- TopiaContext root = TestHelper.initTopiaContext(testBasedir,
- "/TopiaContextImpl.properties",
- testName);
- return root;
- }
-
@Test
public void testCreateSucessfull() throws Exception {
log.debug("Test naturalId : create succesfull");
- TopiaContext root = initTopiaContext("createSucessfull");
- TopiaContext transaction = root.beginTransaction();
+ TopiaContext transaction = db.beginTransaction();
NaturalizedEntityDAO dao =
TopiaTestDAOHelper.getNaturalizedEntityDAO(transaction);
@@ -89,16 +72,12 @@
// No exception will only the need property
dao.create(NaturalizedEntity.PROPERTY_NATURAL_ID_NOT_NULL, 3);
transaction.commitTransaction();
-
- transaction.closeContext();
- root.closeContext();
}
@Test
public void testCreateFailed() throws Exception {
log.debug("Test naturalId : create failed");
- TopiaContext root = initTopiaContext("createFailed");
- TopiaContext transaction = root.beginTransaction();
+ TopiaContext transaction = db.beginTransaction();
NaturalizedEntityDAO dao =
TopiaTestDAOHelper.getNaturalizedEntityDAO(transaction);
@@ -113,17 +92,13 @@
} catch (PropertyValueException eee) {
Assert.assertEquals("naturalIdNotNull", eee.getPropertyName());
}
-
- transaction.closeContext();
- root.closeContext();
}
@Test
public void testUpdateFailed() throws Exception {
log.debug("Test naturalId : update failed");
- TopiaContext root = initTopiaContext("updateFailed");
- TopiaContext transaction = root.beginTransaction();
+ TopiaContext transaction = db.beginTransaction();
NaturalizedEntityDAO dao =
TopiaTestDAOHelper.getNaturalizedEntityDAO(transaction);
@@ -140,17 +115,13 @@
} catch (TopiaException eee) {
Assert.assertEquals("org.hibernate.HibernateException",
eee.getCause().getClass().getName());
- } finally {
- transaction.closeContext();
- root.closeContext();
}
}
@Test
public void testFindByNaturalId() throws Exception {
log.debug("Test naturalId : findByNaturalId");
- TopiaContext root = initTopiaContext("findByNaturalId");
- TopiaContext transaction = root.beginTransaction();
+ TopiaContext transaction = db.beginTransaction();
NaturalizedEntityDAO dao =
TopiaTestDAOHelper.getNaturalizedEntityDAO(transaction);
@@ -163,16 +134,12 @@
NaturalizedEntity result = dao.findByNaturalId(5, "str");
Assert.assertEquals(entity, result);
-
- transaction.closeContext();
- root.closeContext();
}
@Test
public void testExistNaturalId() throws Exception {
log.debug("Test naturalId : existNaturalId");
- TopiaContext root = initTopiaContext("existNaturalId");
- TopiaContext transaction = root.beginTransaction();
+ TopiaContext transaction = db.beginTransaction();
NaturalizedEntityDAO dao =
TopiaTestDAOHelper.getNaturalizedEntityDAO(transaction);
@@ -189,8 +156,5 @@
result = dao.existByNaturalId(8, "str");
Assert.assertFalse(result);
-
- transaction.closeContext();
- root.closeContext();
}
}
Modified: trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/TopiaDAOTest.java
===================================================================
--- trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/TopiaDAOTest.java 2012-03-02 10:08:45 UTC (rev 2415)
+++ trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/TopiaDAOTest.java 2012-03-02 10:08:59 UTC (rev 2416)
@@ -25,75 +25,53 @@
package org.nuiton.topia.persistence;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
import org.junit.Assert;
-import org.junit.BeforeClass;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.matchers.JUnitMatchers;
-import org.nuiton.topia.TestHelper;
import org.nuiton.topia.TopiaContext;
-import org.nuiton.topia.TopiaException;
+import org.nuiton.topia.TopiaDatabase;
import org.nuiton.topia.TopiaTestDAOHelper;
-import org.nuiton.topia.framework.TopiaUtilTest;
import org.nuiton.topia.test.entities.Person;
import org.nuiton.topia.test.entities.PersonDAO;
-import java.io.File;
-import java.io.IOException;
import java.util.List;
/**
* Test on {@link TopiaDAO}.
+ * <p/>
+ * Last update : $Date$
+ * By : $Author$
*
* @author chatellier
* @version $Revision$
- * <p/>
- * Last update : $Date$
- * By : $Author$
*/
public class TopiaDAOTest {
- private static final Log log = LogFactory.getLog(TopiaUtilTest.class);
+ @Rule
+ public final TopiaDatabase db = new TopiaDatabase();
- protected static File testBasedir;
-
- @BeforeClass
- public static void setUpClass() throws Exception {
-
- testBasedir = TestHelper.getTestBasedir(TopiaDAOTest.class);
- }
-
/**
* Test de creer une entité et de verifier qu'elle est
* présente dans la persistence au sein de la transaction.
*
- * @throws TopiaException
- * @throws IOException
+ * @throws Exception if any exception while test
*/
@Test
- public void testCreateAndFindInTransaction() throws TopiaException, IOException {
+ public void testCreateAndFindInTransaction() throws Exception {
- TopiaContext rootContext = TestHelper.initTopiaContext(
- testBasedir,
- "/TopiaContextImpl.properties",
- "testCreateAndFindInTransaction"
- );
+ TopiaContext context = db.beginTransaction();
- TopiaContext context = rootContext.beginTransaction();
-
PersonDAO personDAO = TopiaTestDAOHelper.getPersonDAO(context);
// appel 1 find all
- Person person = personDAO.create();
- person.setName("toto");
+ Person person = personDAO.create(Person.PROPERTY_NAME, "toto");
List<Person> allPerson = personDAO.findAll();
Assert.assertEquals(1, allPerson.size());
context.commitTransaction();
// recherce la personne créée dans la même transaction
- Person person2 = personDAO.create();
- person2.setName("titi");
+ Person person2 = personDAO.create(Person.PROPERTY_NAME, "titi");
allPerson = personDAO.findAll();
Assert.assertEquals(2, allPerson.size());
Assert.assertThat(allPerson, JUnitMatchers.hasItem(person2));
@@ -101,13 +79,11 @@
context.rollbackTransaction();
// meme test apres roolback
- Person person3 = personDAO.create();
- person3.setName("tata");
+ Person person3 = personDAO.create(Person.PROPERTY_NAME, "tata");
allPerson = personDAO.findAll();
Assert.assertEquals(2, allPerson.size());
Assert.assertThat(allPerson, JUnitMatchers.hasItem(person3));
context.commitTransaction();
- rootContext.closeContext();
}
}
Modified: trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/util/TopiaEntityRefTester.java
===================================================================
--- trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/util/TopiaEntityRefTester.java 2012-03-02 10:08:45 UTC (rev 2415)
+++ trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/util/TopiaEntityRefTester.java 2012-03-02 10:08:59 UTC (rev 2416)
@@ -273,7 +273,7 @@
TopiaEntity... expected) {
Assert.assertNotNull(refs);
Assert.assertTrue("no index [" + index + "] in refs of size " +
- refs.size(), index < refs.size());
+ refs.size(), index < refs.size());
TopiaEntityRef actual = refs.get(index);
Assert.assertEquals(actual.getInvoker(), invoker);
Assert.assertEquals(actual.getInvokerProperty(), invokerProperty);
Modified: trunk/topia-persistence/src/test/java/org/nuiton/topia/test/ano1882/DAOAbstractTransformerTest.java
===================================================================
--- trunk/topia-persistence/src/test/java/org/nuiton/topia/test/ano1882/DAOAbstractTransformerTest.java 2012-03-02 10:08:45 UTC (rev 2415)
+++ trunk/topia-persistence/src/test/java/org/nuiton/topia/test/ano1882/DAOAbstractTransformerTest.java 2012-03-02 10:08:59 UTC (rev 2416)
@@ -24,58 +24,34 @@
*/
package org.nuiton.topia.test.ano1882;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.junit.BeforeClass;
+import org.junit.Rule;
import org.junit.Test;
-import org.nuiton.topia.TestHelper;
import org.nuiton.topia.TopiaContext;
-import org.nuiton.topia.TopiaNotFoundException;
+import org.nuiton.topia.TopiaDatabase;
import org.nuiton.topia.TopiaTestDAOHelper;
-import org.nuiton.topia.persistence.NaturalIdTest;
-import java.io.File;
-import java.io.IOException;
import java.util.Arrays;
public class DAOAbstractTransformerTest {
- private static final Log log = LogFactory.getLog(NaturalIdTest.class);
+ @Rule
+ public final TopiaDatabase db = new TopiaDatabase();
- protected static File testBasedir;
-
- @BeforeClass
- public static void setUpClass() throws Exception {
-
- testBasedir = TestHelper.getTestBasedir(NaturalIdTest.class);
- }
-
- protected TopiaContext initTopiaContext(String testName) throws IOException, TopiaNotFoundException {
- TopiaContext root = TestHelper.initTopiaContext(testBasedir,
- "/TopiaContextImpl.properties",
- testName);
- return root;
- }
-
@Test
public void testAno1882() throws Exception {
- TopiaContext rootContext = initTopiaContext("testAno1882");
- TopiaContext transaction = rootContext.beginTransaction();
- try {
- FrenchCompanyDAO dao = TopiaTestDAOHelper.getFrenchCompanyDAO(transaction);
- SIRETDAO siretDAO = TopiaTestDAOHelper.getSIRETDAO(transaction);
- SIRET siret = siretDAO.create();
- FrenchCompany entity =
- dao.create(
- FrenchCompany.PROPERTY_S_IREN, null,
- FrenchCompany.PROPERTY_SIREN2, null,
- FrenchCompany.PROPERTY_S_IRET, Arrays.asList(siret),
- FrenchCompany.PROPERTY_SIRET2, null);
- transaction.commitTransaction();
- dao.delete(entity);
- transaction.commitTransaction();
- } finally {
- rootContext.closeContext();
- }
+ TopiaContext transaction = db.beginTransaction();
+
+ FrenchCompanyDAO dao = TopiaTestDAOHelper.getFrenchCompanyDAO(transaction);
+ SIRETDAO siretDAO = TopiaTestDAOHelper.getSIRETDAO(transaction);
+ SIRET siret = siretDAO.create();
+ FrenchCompany entity =
+ dao.create(
+ FrenchCompany.PROPERTY_S_IREN, null,
+ FrenchCompany.PROPERTY_SIREN2, null,
+ FrenchCompany.PROPERTY_S_IRET, Arrays.asList(siret),
+ FrenchCompany.PROPERTY_SIRET2, null);
+ transaction.commitTransaction();
+ dao.delete(entity);
+ transaction.commitTransaction();
}
}
Property changes on: trunk/topia-persistence/src/test/java/org/nuiton/topia/test/ano1882/DAOAbstractTransformerTest.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Modified: trunk/topia-persistence/src/test/java/org/nuiton/topia/test/evo1912/EntityDTOTransformerTest.java
===================================================================
--- trunk/topia-persistence/src/test/java/org/nuiton/topia/test/evo1912/EntityDTOTransformerTest.java 2012-03-02 10:08:45 UTC (rev 2415)
+++ trunk/topia-persistence/src/test/java/org/nuiton/topia/test/evo1912/EntityDTOTransformerTest.java 2012-03-02 10:08:59 UTC (rev 2416)
@@ -28,9 +28,7 @@
import org.junit.Test;
import org.nuiton.topiatest.CompanyDTO;
-/**
- * @author ymartel <martel(a)codelutin.com>
- */
+/** @author ymartel <martel(a)codelutin.com> */
public class EntityDTOTransformerTest {
@Test
Property changes on: trunk/topia-persistence/src/test/java/org/nuiton/topia/test/evo1912/EntityDTOTransformerTest.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Modified: trunk/topia-persistence/src/test/java/org/nuiton/topiatest/EnumTest.java
===================================================================
--- trunk/topia-persistence/src/test/java/org/nuiton/topiatest/EnumTest.java 2012-03-02 10:08:45 UTC (rev 2415)
+++ trunk/topia-persistence/src/test/java/org/nuiton/topiatest/EnumTest.java 2012-03-02 10:08:59 UTC (rev 2416)
@@ -25,52 +25,33 @@
package org.nuiton.topiatest;
import junit.framework.Assert;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.junit.BeforeClass;
+import org.junit.Rule;
import org.junit.Test;
-import org.nuiton.topia.TestHelper;
import org.nuiton.topia.TopiaContext;
-import org.nuiton.topia.TopiaNotFoundException;
+import org.nuiton.topia.TopiaDatabase;
+import org.nuiton.topia.TopiaException;
import org.nuiton.topia.TopiaTestDAOHelper;
-import java.io.File;
-import java.io.IOException;
-
/**
* Test the support of possibility to have an attribute of type enumeration
* in a entity
*/
public class EnumTest {
- private static final Log log = LogFactory.getLog(EnumTest.class);
+ @Rule
+ public final TopiaDatabase db = new TopiaDatabase();
- protected static File testBasedir;
-
- @BeforeClass
- public static void setUpClass() throws Exception {
- testBasedir = TestHelper.getTestBasedir(EnumTest.class);
- }
-
- protected TopiaContext initTopiaContext(String testName) throws IOException, TopiaNotFoundException {
- TopiaContext root = TestHelper.initTopiaContext(testBasedir,
- "/TopiaContextImpl.properties",
- testName);
- return root;
- }
-
/**
* Create an entity having two field of type enumeration. One is stored
* using ordinal, the other using the name.
- *
+ * <p/>
* The test check that values are stored, and that find methods works
*
- * @throws Exception
+ * @throws TopiaException if any exception with db
*/
@Test
- public void storeEntityWithEnumValue() throws Exception {
- TopiaContext root = initTopiaContext("storeEntityWithEnumValue");
- TopiaContext transaction = root.beginTransaction();
+ public void storeEntityWithEnumValue() throws TopiaException {
+ TopiaContext transaction = db.beginTransaction();
PersonneDAO dao = TopiaTestDAOHelper.getPersonneDAO(transaction);
Personne personne = new PersonneImpl();
@@ -81,7 +62,7 @@
transaction.commitTransaction();
transaction.closeContext();
- transaction = root.beginTransaction();
+ transaction = db.beginTransaction();
dao = TopiaTestDAOHelper.getPersonneDAO(transaction);
dao.findByTopiaId(topiaId);
Assert.assertEquals(Gender.FEMALE, personne.getGender());
Modified: trunk/topia-persistence/src/test/java/org/nuiton/topiatest/deletetest/DeleteEntityTest.java
===================================================================
--- trunk/topia-persistence/src/test/java/org/nuiton/topiatest/deletetest/DeleteEntityTest.java 2012-03-02 10:08:45 UTC (rev 2415)
+++ trunk/topia-persistence/src/test/java/org/nuiton/topiatest/deletetest/DeleteEntityTest.java 2012-03-02 10:08:59 UTC (rev 2416)
@@ -40,19 +40,16 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
+import org.junit.Rule;
import org.junit.Test;
-import org.nuiton.topia.TestHelper;
import org.nuiton.topia.TopiaContext;
+import org.nuiton.topia.TopiaDatabase;
import org.nuiton.topia.TopiaException;
import org.nuiton.topia.TopiaTestDAOHelper;
import org.nuiton.topia.generator.DAOAbstractTransformer;
import org.nuiton.topiatest.Personne;
import org.nuiton.topiatest.PersonneDAO;
-import java.io.File;
-
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
@@ -66,97 +63,60 @@
*/
public class DeleteEntityTest {
- private static TopiaContext rootContext;
-
private static final Log log = LogFactory.getLog(DeleteEntityTest.class);
+ @Rule
+ public final TopiaDatabase db = new TopiaDatabase();
- protected static File testBasedir;
-
- @BeforeClass
- public static void setUpClass() throws Exception {
-
- testBasedir = TestHelper.getTestBasedir(DeleteEntityTest.class);
-
- rootContext = TestHelper.initTopiaContext(testBasedir,
- "/TopiaContextImpl.properties",
- "deleteEntityDb");
-//
-// try {
-// Properties conf = new Properties();
-// URL url = Resource.getURL("TopiaContextImpl.properties");
-// if (log.isDebugEnabled()) {
-// log.debug(url);
-// }
-// conf.load(url.openStream());
-// conf.setProperty("topia.persistence.classes", TopiaTestDAOHelper.getImplementationClassesAsString());
-//
-// rootContext = TopiaContextFactory.getContext(conf);
-// if (log.isInfoEnabled()) {
-// log.info("Context Ready !");
-// }
-// } catch (Exception ex) {
-// log.error("Initialize error !!", ex);
-// }
- }
-
-
- @AfterClass
- public static void tearDownClass() throws Exception {
- rootContext.closeContext();
- }
-
/**
* Test for deleting entities with inheritance. Delete from the DAO linked
* with the subclass entity and from the DAO linked with the superclass
* entity. In the test model, the two entities have NMultiplicity
* relationship without association class entity.
+ *
+ * @throws TopiaException if any exception while manipulating db
*/
@Test
- public void testDeleteEntityWithInheritance() {
+ public void testDeleteEntityWithInheritance() throws TopiaException {
log.debug("START TEST : testDeleteEntityWithInheritance");
- try {
- TopiaContext transaction = rootContext.beginTransaction();
- log.debug("DAO : PersonneDAO");
- PersonneDAO dao = TopiaTestDAOHelper.getPersonneDAO(transaction);
+ TopiaContext transaction = db.beginTransaction();
- log.debug("CREATE PERSONNE : Bob Marley");
- Personne personne = dao.create(Personne.PROPERTY_NAME, "Bob Marley");
- transaction.commitTransaction();
- String idPersonne = personne.getTopiaId();
- assertNotNull(idPersonne);
- log.debug("ENTITY PERSONNE SAVED !");
+ log.debug("DAO : PersonneDAO");
+ PersonneDAO dao = TopiaTestDAOHelper.getPersonneDAO(transaction);
- log.debug("DELETE PERSONNE");
- dao.delete(personne);
- transaction.commitTransaction();
- Personne res = dao.findByTopiaId(idPersonne);
- assertNull(res);
- log.debug("ENTITY PERSONNE DELETED !");
+ log.debug("CREATE PERSONNE : Bob Marley");
+ Personne personne = dao.create(Personne.PROPERTY_NAME, "Bob Marley");
+ transaction.commitTransaction();
+ String idPersonne = personne.getTopiaId();
+ assertNotNull(idPersonne);
+ log.debug("ENTITY PERSONNE SAVED !");
- log.debug("CREATE PERSONNE : Ziggy Marley");
- Personne personne2 = dao.create(Personne.PROPERTY_NAME, "Ziggy Marley");
- transaction.commitTransaction();
- String idPersonne2 = personne2.getTopiaId();
- assertNotNull(idPersonne2);
- log.debug("ENTITY PERSONNE SAVED !");
+ log.debug("DELETE PERSONNE");
+ dao.delete(personne);
+ transaction.commitTransaction();
+ Personne res = dao.findByTopiaId(idPersonne);
+ assertNull(res);
+ log.debug("ENTITY PERSONNE DELETED !");
- log.debug("DAO parent (abstract) : PartyDAO");
- Party2DAO dao2 = TopiaTestDAOHelper.getParty2DAO(transaction);
+ log.debug("CREATE PERSONNE : Ziggy Marley");
+ Personne personne2 = dao.create(Personne.PROPERTY_NAME, "Ziggy Marley");
+ transaction.commitTransaction();
+ String idPersonne2 = personne2.getTopiaId();
+ assertNotNull(idPersonne2);
+ log.debug("ENTITY PERSONNE SAVED !");
- log.debug("DELETE PERSONNE with PartyDAO");
- dao2.delete(personne2);
- transaction.commitTransaction();
- Party2 res2 = dao2.findByTopiaId(idPersonne2);
- assertNull(res2);
- log.debug("ENTITY PERSONNE DELETED !");
+ log.debug("DAO parent (abstract) : PartyDAO");
+ Party2DAO dao2 = TopiaTestDAOHelper.getParty2DAO(transaction);
- transaction.closeContext();
- } catch (TopiaException ex) {
- log.error("TopiaException", ex);
- }
- log.debug("END TEST");
+ log.debug("DELETE PERSONNE with PartyDAO");
+ dao2.delete(personne2);
+ transaction.commitTransaction();
+ Party2 res2 = dao2.findByTopiaId(idPersonne2);
+ assertNull(res2);
+ log.debug("ENTITY PERSONNE DELETED !");
+
+
}
/**
@@ -165,60 +125,55 @@
* between two entities with NMultiplicity relation. In the test model, the
* two entities have both inheritance.
*
+ * @throws TopiaException if any exception while manipulating db
* @see DAOAbstractTransformer
*/
@Test
- public void testDeleteEntityWithManyToManyRelation() {
+ public void testDeleteEntityWithManyToManyRelation() throws TopiaException {
log.debug("START TEST : testDeleteEntityWithManyToManyRelation");
- try {
- TopiaContext transaction = rootContext.beginTransaction();
- PersonneDAO dao = TopiaTestDAOHelper.getPersonneDAO(transaction);
+ TopiaContext transaction = db.beginTransaction();
- log.debug("CREATE PERSONNE : Bob Marley");
- Personne personne = dao.create(Personne.PROPERTY_NAME, "Bob Marley");
- transaction.commitTransaction();
- String idPersonne = personne.getTopiaId();
- assertNotNull(idPersonne);
- log.debug("ENTITY PERSONNE SAVED !");
+ PersonneDAO dao = TopiaTestDAOHelper.getPersonneDAO(transaction);
- Contact2DAO contactDAO = TopiaTestDAOHelper.getContact2DAO(transaction);
+ log.debug("CREATE PERSONNE : Bob Marley");
+ Personne personne = dao.create(Personne.PROPERTY_NAME, "Bob Marley");
+ transaction.commitTransaction();
+ String idPersonne = personne.getTopiaId();
+ assertNotNull(idPersonne);
+ log.debug("ENTITY PERSONNE SAVED !");
- log.debug("CREATE CONTACT : jaja(a)codelutin.com");
- Contact2 contact = contactDAO.create(Contact2.PROPERTY_CONTACT_VALUE, "jaja(a)codelutin.com");
- transaction.commitTransaction();
- String idContact = contact.getTopiaId();
- assertNotNull(idContact);
- log.debug("ENTITY CONTACT SAVED !");
+ Contact2DAO contactDAO = TopiaTestDAOHelper.getContact2DAO(transaction);
- log.debug("ADD CONTACT TO PERSONNE");
- personne.addContacts(contact);
- transaction.commitTransaction();
- assertEquals(1, personne.getContacts().size());
- log.debug("CONTACT ADDED !");
+ log.debug("CREATE CONTACT : jaja(a)codelutin.com");
+ Contact2 contact = contactDAO.create(Contact2.PROPERTY_CONTACT_VALUE, "jaja(a)codelutin.com");
+ transaction.commitTransaction();
+ String idContact = contact.getTopiaId();
+ assertNotNull(idContact);
+ log.debug("ENTITY CONTACT SAVED !");
- log.debug("DELETE PERSONNE");
- dao.delete(personne);
- transaction.commitTransaction();
- Personne res = dao.findByTopiaId(idPersonne);
- assertNull(res);
- log.debug("ENTITY PERSONNE DELETED !");
+ log.debug("ADD CONTACT TO PERSONNE");
+ personne.addContacts(contact);
+ transaction.commitTransaction();
+ assertEquals(1, personne.getContacts().size());
+ log.debug("CONTACT ADDED !");
- assertEquals(0, contact.getParty2().size());
+ log.debug("DELETE PERSONNE");
+ dao.delete(personne);
+ transaction.commitTransaction();
+ Personne res = dao.findByTopiaId(idPersonne);
+ assertNull(res);
+ log.debug("ENTITY PERSONNE DELETED !");
- log.debug("DELETE CONTACT");
- contactDAO.delete(contact);
- transaction.commitTransaction();
- Contact2 res2 = contactDAO.findByTopiaId(idContact);
- assertNull(res2);
- log.debug("ENTITY PERSONNE DELETED !");
+ assertEquals(0, contact.getParty2().size());
+ log.debug("DELETE CONTACT");
+ contactDAO.delete(contact);
+ transaction.commitTransaction();
+ Contact2 res2 = contactDAO.findByTopiaId(idContact);
+ assertNull(res2);
+ log.debug("ENTITY PERSONNE DELETED !");
- transaction.closeContext();
- } catch (TopiaException ex) {
- log.error("TopiaException", ex);
- }
- log.debug("END TEST");
}
}
1
0
r2415 - in trunk/topia-persistence/src: main/java/org/nuiton/topia/framework test/java/org/nuiton/topia/test test/java/org/nuiton/topia/test/ano1991
by tchemit@users.nuiton.org March 2, 2012
by tchemit@users.nuiton.org March 2, 2012
March 2, 2012
Author: tchemit
Date: 2012-03-02 11:08:45 +0100 (Fri, 02 Mar 2012)
New Revision: 2415
Url: http://nuiton.org/repositories/revision/topia/2415
Log:
Anomalie #1991: Using IN in TopiaQuery does not work when using object list
Added:
trunk/topia-persistence/src/test/java/org/nuiton/topia/test/ano1991/
trunk/topia-persistence/src/test/java/org/nuiton/topia/test/ano1991/TopiaQueryTest.java
Modified:
trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaQuery.java
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaQuery.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaQuery.java 2012-02-29 11:32:44 UTC (rev 2414)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaQuery.java 2012-03-02 10:08:45 UTC (rev 2415)
@@ -802,7 +802,12 @@
result.append(Op.NULL);
} else {
String valueName = getValueName(paramName);
- result.append(operator).append(" :").append(valueName);
+ if (Op.IN ==operator || Op.NOT_IN == operator) {
+
+ result.append(operator).append(" (:").append(valueName).append(')');
+ } else {
+ result.append(operator).append(" :").append(valueName);
+ }
addParam(valueName, paramValue);
}
// parentheses = false;
Added: trunk/topia-persistence/src/test/java/org/nuiton/topia/test/ano1991/TopiaQueryTest.java
===================================================================
--- trunk/topia-persistence/src/test/java/org/nuiton/topia/test/ano1991/TopiaQueryTest.java (rev 0)
+++ trunk/topia-persistence/src/test/java/org/nuiton/topia/test/ano1991/TopiaQueryTest.java 2012-03-02 10:08:45 UTC (rev 2415)
@@ -0,0 +1,130 @@
+/*
+ * #%L
+ * ToPIA :: Persistence
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2004 - 2012 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
+package org.nuiton.topia.test.ano1991;
+
+import org.junit.Assert;
+import org.junit.Rule;
+import org.junit.Test;
+import org.nuiton.topia.TopiaContext;
+import org.nuiton.topia.TopiaDatabase;
+import org.nuiton.topia.TopiaException;
+import org.nuiton.topia.TopiaTestDAOHelper;
+import org.nuiton.topia.framework.TopiaQuery;
+import org.nuiton.topia.test.entities.Person;
+import org.nuiton.topia.test.entities.PersonDAO;
+import org.nuiton.topia.test.entities.Pet;
+import org.nuiton.topia.test.entities.PetDAO;
+
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ * Prevent regression of http://nuiton.org/issues/1991.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.6.8
+ */
+public class TopiaQueryTest {
+
+ @Rule
+ public final TopiaDatabase db = new TopiaDatabase();
+
+ @Test
+ public void testInOperatorForIds() throws TopiaException {
+
+ TopiaContext context = db.beginTransaction();
+
+ PersonDAO personDAO = TopiaTestDAOHelper.getPersonDAO(context);
+
+ // appel 1 find all
+ Person toto = personDAO.create(Person.PROPERTY_NAME, "toto");
+ Person titi = personDAO.create(Person.PROPERTY_NAME, "titi");
+
+ TopiaQuery query;
+
+ query = personDAO.createQuery().addWhere(
+ Person.PROPERTY_NAME, TopiaQuery.Op.IN, new String[]{"toto"}
+ );
+
+ List<Person> result;
+ result = personDAO.findAllByQuery(query);
+ Assert.assertNotNull(result);
+ Assert.assertEquals(1, result.size());
+ Assert.assertEquals(toto, result.get(0));
+
+ query = personDAO.createQuery().addWhere(
+ Person.PROPERTY_NAME, TopiaQuery.Op.NOT_IN, new String[]{"toto"}
+ );
+
+ result = personDAO.findAllByQuery(query);
+ Assert.assertNotNull(result);
+ Assert.assertEquals(1, result.size());
+ Assert.assertEquals(titi, result.get(0));
+ }
+
+ @Test
+ public void testInOperatorForEntities() throws TopiaException {
+
+ TopiaContext context = db.beginTransaction();
+
+ PetDAO petDAO = TopiaTestDAOHelper.getPetDAO(context);
+ PersonDAO personDAO = TopiaTestDAOHelper.getPersonDAO(context);
+
+ Pet bernard = petDAO.create(Pet.PROPERTY_NAME, "bernard");
+ Pet bianca = petDAO.create(Pet.PROPERTY_NAME, "bianca");
+ Pet minou = petDAO.create(Pet.PROPERTY_NAME, "minou");
+ Person toto = personDAO.create(Person.PROPERTY_NAME, "toto");
+ toto.addPet(bernard);
+
+ Person titi = personDAO.create(Person.PROPERTY_NAME, "titi");
+ titi.addPet(bianca);
+
+ Person tutu = personDAO.create(Person.PROPERTY_NAME, "tutu");
+ tutu.addPet(minou);
+
+ TopiaQuery query;
+
+ query = petDAO.createQuery("p").addWhere(
+ "p." + Pet.PROPERTY_PERSON, TopiaQuery.Op.IN, Arrays.asList(toto, titi)
+ );
+
+ List<Pet> result;
+ result = petDAO.findAllByQuery(query);
+ Assert.assertNotNull(result);
+ Assert.assertEquals(2, result.size());
+ Assert.assertTrue(result.contains(bernard));
+ Assert.assertTrue(result.contains(bianca));
+
+ query = petDAO.createQuery("p").addWhere(
+ "p." + Pet.PROPERTY_PERSON, TopiaQuery.Op.NOT_IN, Arrays.asList(toto, titi)
+ );
+
+ result = petDAO.findAllByQuery(query);
+ Assert.assertNotNull(result);
+ Assert.assertEquals(1, result.size());
+ Assert.assertTrue(result.contains(minou));
+ }
+
+}
Property changes on: trunk/topia-persistence/src/test/java/org/nuiton/topia/test/ano1991/TopiaQueryTest.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
1
0