Topia-commits
Threads by month
- ----- 2026 -----
- June
- May
- April
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2006 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2005 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2004 -----
- December
- November
- October
- September
- August
- July
- June
- May
October 2013
- 7 participants
- 62 discussions
r2854 - trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence
by bleny@users.nuiton.org 31 Oct '13
by bleny@users.nuiton.org 31 Oct '13
31 Oct '13
Author: bleny
Date: 2013-10-31 18:01:00 +0100 (Thu, 31 Oct 2013)
New Revision: 2854
Url: http://nuiton.org/projects/topia/repository/revisions/2854
Log:
refs #2086 add an alias in generated query HqlAndParametersBuilder
Modified:
trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/HqlAndParametersBuilder.java
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/HqlAndParametersBuilder.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/HqlAndParametersBuilder.java 2013-10-31 14:59:51 UTC (rev 2853)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/HqlAndParametersBuilder.java 2013-10-31 17:01:00 UTC (rev 2854)
@@ -54,6 +54,13 @@
protected Set<String> orderByArguments;
+ protected String alias = "topiaEntity_";
+
+ public void setAlias(String alias) {
+ Preconditions.checkArgument(StringUtils.isNotEmpty(alias));
+ this.alias = alias;
+ }
+
public HqlAndParametersBuilder(Class<E> entityClass) {
this.entityClass = entityClass;
}
@@ -67,7 +74,7 @@
}
public void addNull(String property) {
- whereClauses.add(property + " is null");
+ whereClauses.add(alias + "." + property + " is null");
}
public void setParameters(Map<String, Object> parameters) {
@@ -92,7 +99,7 @@
addNull(property);
} else {
String hqlParameterName = putHqlParameterWithAvailableName(property, value);
- whereClauses.add(property + " = :" + hqlParameterName);
+ whereClauses.add(alias + "." + property + " = :" + hqlParameterName);
}
}
@@ -115,26 +122,26 @@
hqlParameterNames.add(hqlParameterName);
}
}
- String inClause = property + " in (:" + StringUtils.join(hqlParameterNames, ", :")+ ")";
+ String inClause = alias + "." + property + " in (:" + StringUtils.join(hqlParameterNames, ", :")+ ")";
String whereClause = inClause;
if (propertyMayBeNull) {
- whereClause = property + " is null or " + inClause;
+ whereClause = alias + "." + property + " is null or " + inClause;
}
whereClauses.add(whereClause);
}
}
public void addTopiaIdEquals(String property, String topiaId) {
- addEquals(property + "." + TopiaEntity.PROPERTY_TOPIA_ID, topiaId);
+ addEquals(alias + "." + property + "." + TopiaEntity.PROPERTY_TOPIA_ID, topiaId);
}
public void addTopiaIdIn(String property, Iterable<String> topiaIds) {
- addIn(property + "." + TopiaEntity.PROPERTY_TOPIA_ID, (Iterable) topiaIds);
+ addIn(alias + "." + property + "." + TopiaEntity.PROPERTY_TOPIA_ID, (Iterable) topiaIds);
}
public void addContains(String property, Object value) {
String hqlParameterName = putHqlParameterWithAvailableName(property, value);
- whereClauses.add(":" + hqlParameterName + " in elements(" + property + ")");
+ whereClauses.add(":" + hqlParameterName + " in elements(" + alias + "." + property + ")");
}
public void addWhereClause(String whereClause) {
@@ -149,12 +156,12 @@
public String getHql() {
StringBuilder hqlStringBuilder = new StringBuilder();
- hqlStringBuilder.append("from ").append(entityClass.getCanonicalName());
+ hqlStringBuilder.append("from ").append(entityClass.getCanonicalName()).append(" ").append(alias);
if ( ! whereClauses.isEmpty()) {
hqlStringBuilder.append(" where ").append(StringUtils.join(whereClauses, " and "));
}
if (CollectionUtils.isNotEmpty(orderByArguments)) {
- hqlStringBuilder.append(" order by ").append(StringUtils.join(orderByArguments, ", "));
+ hqlStringBuilder.append(" order by ").append(alias).append(".").append(StringUtils.join(orderByArguments, ", " + alias + "."));
}
String hql = hqlStringBuilder.toString();
return hql;
2
1
r2853 - in trunk/topia-persistence/src/main/java/org/nuiton/topia: generator persistence
by bleny@users.nuiton.org 31 Oct '13
by bleny@users.nuiton.org 31 Oct '13
31 Oct '13
Author: bleny
Date: 2013-10-31 15:59:51 +0100 (Thu, 31 Oct 2013)
New Revision: 2853
Url: http://nuiton.org/projects/topia/repository/revisions/2853
Log:
refs #2086 allow adding criteria to query after using a generated dao method (ie forActive(true)...)
Modified:
trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityDaoTransformer.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/AbstractTopiaDao.java
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityDaoTransformer.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityDaoTransformer.java 2013-10-30 17:42:49 UTC (rev 2852)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityDaoTransformer.java 2013-10-31 14:59:51 UTC (rev 2853)
@@ -47,6 +47,7 @@
import org.nuiton.eugene.models.object.ObjectModelOperation;
import org.nuiton.topia.TopiaException;
import org.nuiton.topia.persistence.TopiaEntity;
+import org.nuiton.topia.persistence.TopiaQueryBuilderAddCriteriaOrRunQueryStep;
import java.util.Collection;
import java.util.HashMap;
@@ -426,6 +427,7 @@
}
addImport(daoAbstractClass, List.class);
addImport(daoAbstractClass, TopiaException.class);
+ addImport(daoAbstractClass, TopiaQueryBuilderAddCriteriaOrRunQueryStep.class);
ObjectModelOperation op;
@@ -887,24 +889,24 @@
ObjectModelOperation op;
op = addOperation(result,
getJavaBeanMethodName("for", attrName, "In"),
- "TopiaQueryBuilderRunQueryStep<E>",
+ "TopiaQueryBuilderAddCriteriaOrRunQueryStep<E>",
ObjectModelJavaModifier.PUBLIC);
addParameter(op, "Iterable<" + attrTypeForGeneric + ">", "v");
setOperationBody(op, ""
/*{
- TopiaQueryBuilderRunQueryStep<E> result = forIn(<%=propertyName%>, (Iterable) v);
+ TopiaQueryBuilderAddCriteriaOrRunQueryStep<E> result = forIn(<%=propertyName%>, (Iterable) v);
return result;
}*/
);
op = addOperation(result,
getJavaBeanMethodName("for", attrName, "Equals"),
- "TopiaQueryBuilderRunQueryStep<E>",
+ "TopiaQueryBuilderAddCriteriaOrRunQueryStep<E>",
ObjectModelJavaModifier.PUBLIC);
addParameter(op, attrType, "v");
setOperationBody(op, ""
/*{
- TopiaQueryBuilderRunQueryStep<E> result = forEquals(<%=propertyName%>, v);
+ TopiaQueryBuilderAddCriteriaOrRunQueryStep<E> result = forEquals(<%=propertyName%>, v);
return result;
}*/
);
@@ -981,7 +983,7 @@
op = addOperation(result,
getJavaBeanMethodName("for", attrName, "Contains"),
- "TopiaQueryBuilderRunQueryStep<E>",
+ "TopiaQueryBuilderAddCriteriaOrRunQueryStep<E>",
ObjectModelJavaModifier.PUBLIC);
addParameter(op, attrType, "v");
setOperationBody(op, ""
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/AbstractTopiaDao.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/AbstractTopiaDao.java 2013-10-30 17:42:49 UTC (rev 2852)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/AbstractTopiaDao.java 2013-10-31 14:59:51 UTC (rev 2853)
@@ -382,20 +382,20 @@
}
@Override
- public TopiaQueryBuilderRunQueryStep<E> forContains(String propertyName, Object propertyValue) {
- TopiaQueryBuilderRunQueryStep<E> result = newQueryBuilder().addContains(propertyName, propertyValue).getNextStep();
+ public TopiaQueryBuilderAddCriteriaOrRunQueryStep<E> forContains(String propertyName, Object propertyValue) {
+ TopiaQueryBuilderAddCriteriaOrRunQueryStep<E> result = newQueryBuilder().addContains(propertyName, propertyValue);
return result;
}
@Override
- public TopiaQueryBuilderRunQueryStep<E> forEquals(String propertyName, Object propertyValue) {
- TopiaQueryBuilderRunQueryStep<E> result = newQueryBuilder().addEquals(propertyName, propertyValue).getNextStep();
+ public TopiaQueryBuilderAddCriteriaOrRunQueryStep<E> forEquals(String propertyName, Object propertyValue) {
+ TopiaQueryBuilderAddCriteriaOrRunQueryStep<E> result = newQueryBuilder().addEquals(propertyName, propertyValue);
return result;
}
@Override
- public TopiaQueryBuilderRunQueryStep<E> forIn(String propertyName, Iterable<Object> propertyValues) {
- TopiaQueryBuilderRunQueryStep<E> result = newQueryBuilder().addIn(propertyName, propertyValues).getNextStep();
+ public TopiaQueryBuilderAddCriteriaOrRunQueryStep<E> forIn(String propertyName, Iterable<Object> propertyValues) {
+ TopiaQueryBuilderAddCriteriaOrRunQueryStep<E> result = newQueryBuilder().addIn(propertyName, propertyValues);
return result;
}
@@ -614,16 +614,16 @@
}
@Override
- public TopiaQueryBuilderRunQueryStep<E> forTopiaIdEquals(String topiaId) {
+ public TopiaQueryBuilderAddCriteriaOrRunQueryStep<E> forTopiaIdEquals(String topiaId) {
Preconditions.checkNotNull(topiaId, "given topiaId is null");
- TopiaQueryBuilderRunQueryStep<E> result = forEquals(TopiaEntity.PROPERTY_TOPIA_ID, topiaId);
+ TopiaQueryBuilderAddCriteriaOrRunQueryStep<E> result = forEquals(TopiaEntity.PROPERTY_TOPIA_ID, topiaId);
return result;
}
@Override
- public TopiaQueryBuilderRunQueryStep<E> forTopiaIdIn(Iterable<String> topiaIds) {
+ public TopiaQueryBuilderAddCriteriaOrRunQueryStep<E> forTopiaIdIn(Iterable<String> topiaIds) {
Preconditions.checkNotNull(topiaIds, "given topiaIds is null");
- TopiaQueryBuilderRunQueryStep<E> result = forIn(TopiaEntity.PROPERTY_TOPIA_ID, (Iterable) topiaIds);
+ TopiaQueryBuilderAddCriteriaOrRunQueryStep<E> result = forIn(TopiaEntity.PROPERTY_TOPIA_ID, (Iterable) topiaIds);
return result;
}
@@ -797,37 +797,37 @@
}
@Override
- public TopiaQueryBuilderAddCriteriaStep<E> addEquals(String property, Object value) {
+ public TopiaQueryBuilderAddCriteriaOrRunQueryStep<E> addEquals(String property, Object value) {
hqlAndParametersBuilder.addEquals(property, value);
return this;
}
@Override
- public TopiaQueryBuilderAddCriteriaStep<E> addIn(String property, Iterable<Object> values) {
+ public TopiaQueryBuilderAddCriteriaOrRunQueryStep<E> addIn(String property, Iterable<Object> values) {
hqlAndParametersBuilder.addIn(property, values);
return this;
}
@Override
- public TopiaQueryBuilderAddCriteriaStep<E> addContains(String property, Object value) {
+ public TopiaQueryBuilderAddCriteriaOrRunQueryStep<E> addContains(String property, Object value) {
hqlAndParametersBuilder.addContains(property, value);
return this;
}
@Override
- public TopiaQueryBuilderAddCriteriaStep<E> addNull(String property) {
+ public TopiaQueryBuilderAddCriteriaOrRunQueryStep<E> addNull(String property) {
hqlAndParametersBuilder.addNull(property);
return this;
}
@Override
- public TopiaQueryBuilderAddCriteriaStep<E> addTopiaIdEquals(String property, String topiaId) {
+ public TopiaQueryBuilderAddCriteriaOrRunQueryStep<E> addTopiaIdEquals(String property, String topiaId) {
hqlAndParametersBuilder.addTopiaIdEquals(property, topiaId);
return this;
}
@Override
- public TopiaQueryBuilderAddCriteriaStep<E> addTopiaIdIn(String property, Iterable<String> topiaIds) {
+ public TopiaQueryBuilderAddCriteriaOrRunQueryStep<E> addTopiaIdIn(String property, Iterable<String> topiaIds) {
hqlAndParametersBuilder.addTopiaIdIn(property, topiaIds);
return this;
}
1
0
r2852 - in trunk/topia-persistence/src: main/java/org/nuiton/topia main/java/org/nuiton/topia/persistence test/java/org/nuiton/topiatest/deletetest
by athimel@users.nuiton.org 30 Oct '13
by athimel@users.nuiton.org 30 Oct '13
30 Oct '13
Author: athimel
Date: 2013-10-30 18:42:49 +0100 (Wed, 30 Oct 2013)
New Revision: 2852
Url: http://nuiton.org/projects/topia/repository/revisions/2852
Log:
Add findByTopiaId methods
Modified:
trunk/topia-persistence/src/main/java/org/nuiton/topia/AbstractTopiaPersistenceContext.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/AbstractTopiaDao.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAOImpl.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDao.java
trunk/topia-persistence/src/test/java/org/nuiton/topiatest/deletetest/DeleteEntityTest.java
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/AbstractTopiaPersistenceContext.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/AbstractTopiaPersistenceContext.java 2013-10-30 11:16:15 UTC (rev 2851)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/AbstractTopiaPersistenceContext.java 2013-10-30 17:42:49 UTC (rev 2852)
@@ -292,7 +292,9 @@
@Override
public <E extends TopiaEntity, D extends TopiaDAO<E>> D getDao(Class<E> entityClass, Class<D> daoClass) {
- return (D) getDao(entityClass);
+ TopiaDAO<E> dao = getDao(entityClass);
+ D result = (D) dao;
+ return result;
}
@Override
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/AbstractTopiaDao.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/AbstractTopiaDao.java 2013-10-30 11:16:15 UTC (rev 2851)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/AbstractTopiaDao.java 2013-10-30 17:42:49 UTC (rev 2852)
@@ -311,7 +311,8 @@
}
protected HqlAndParametersBuilder<E> newHqlAndParametersBuilder() {
- return new HqlAndParametersBuilder<E>(getEntityClass());
+ HqlAndParametersBuilder<E> result = new HqlAndParametersBuilder<E>(getEntityClass());
+ return result;
}
protected HqlAndParametersBuilder<E> getHqlForProperties(String propertyName,
@@ -319,29 +320,33 @@
Object... otherPropertyNamesAndValues) {
Map<String, Object> properties =
TopiaUtil.convertPropertiesArrayToMap(propertyName, propertyValue, otherPropertyNamesAndValues);
- return getHqlForProperties(properties);
+ HqlAndParametersBuilder<E> result = getHqlForProperties(properties);
+ return result;
}
protected HqlAndParametersBuilder<E> getHqlForNoConstraint() {
Map<String, Object> properties = Collections.emptyMap();
- return getHqlForProperties(properties);
+ HqlAndParametersBuilder<E> result = getHqlForProperties(properties);
+ return result;
}
protected HqlAndParametersBuilder<E> getHqlForProperties(Map<String, Object> properties) {
- HqlAndParametersBuilder<E> hqlAndParametersBuilder = newHqlAndParametersBuilder();
+ HqlAndParametersBuilder<E> result = newHqlAndParametersBuilder();
for (Map.Entry<String, Object> property : properties.entrySet()) {
- hqlAndParametersBuilder.addEquals(property.getKey(), property.getValue());
+ result.addEquals(property.getKey(), property.getValue());
}
- return hqlAndParametersBuilder;
+ return result;
}
protected TopiaQueryBuilderRunQueryStep<E> forHql(String hql) {
Map<String, Object> properties = Collections.emptyMap();
- return forHql(hql, properties);
+ TopiaQueryBuilderRunQueryStep<E> result = forHql(hql, properties);
+ return result;
}
protected TopiaQueryBuilderRunQueryStep<E> forHql(String hql, Map<String, Object> hqlParameters) {
- return new TopiaQueryBuilderRunQueryStep(this, hql, hqlParameters);
+ TopiaQueryBuilderRunQueryStep result = new TopiaQueryBuilderRunQueryStep(this, hql, hqlParameters);
+ return result;
}
protected TopiaQueryBuilderRunQueryStep<E> forHql(String hql, String parameterName,
@@ -349,14 +354,15 @@
Object... otherParameterNamesAndValues) {
Map<String, Object> hqlParameters =
TopiaUtil.convertPropertiesArrayToMap(parameterName, parameterValue, otherParameterNamesAndValues);
- return forHql(hql, hqlParameters);
+ TopiaQueryBuilderRunQueryStep<E> result = forHql(hql, hqlParameters);
+ return result;
}
@Override
public TopiaQueryBuilderAddCriteriaStep<E> forProperties(Map<String, Object> properties) {
HqlAndParametersBuilder<E> hqlAndParametersBuilder = getHqlForProperties(properties);
- TopiaQueryBuilderAddCriteriaStep nextStep = new TopiaQueryBuilderAddCriteriaStep(this, hqlAndParametersBuilder);
- return nextStep;
+ TopiaQueryBuilderAddCriteriaStep result = new TopiaQueryBuilderAddCriteriaStep(this, hqlAndParametersBuilder);
+ return result;
}
@Override
@@ -364,101 +370,105 @@
Object propertyValue,
Object... otherPropertyNamesAndValues) {
HqlAndParametersBuilder<E> hqlAndParametersBuilder = getHqlForProperties(propertyName, propertyValue, otherPropertyNamesAndValues);
- TopiaQueryBuilderAddCriteriaStep nextStep = new TopiaQueryBuilderAddCriteriaStep(this, hqlAndParametersBuilder);
- return nextStep;
+ TopiaQueryBuilderAddCriteriaStep result = new TopiaQueryBuilderAddCriteriaStep(this, hqlAndParametersBuilder);
+ return result;
}
@Override
public TopiaQueryBuilderAddCriteriaStep<E> newQueryBuilder() {
HqlAndParametersBuilder<E> hqlAndParametersBuilder = newHqlAndParametersBuilder();
- TopiaQueryBuilderAddCriteriaStep nextStep = new TopiaQueryBuilderAddCriteriaStep(this, hqlAndParametersBuilder);
- return nextStep;
+ TopiaQueryBuilderAddCriteriaStep result = new TopiaQueryBuilderAddCriteriaStep(this, hqlAndParametersBuilder);
+ return result;
}
@Override
public TopiaQueryBuilderRunQueryStep<E> forContains(String propertyName, Object propertyValue) {
- return newQueryBuilder().addContains(propertyName, propertyValue).getNextStep();
+ TopiaQueryBuilderRunQueryStep<E> result = newQueryBuilder().addContains(propertyName, propertyValue).getNextStep();
+ return result;
}
@Override
public TopiaQueryBuilderRunQueryStep<E> forEquals(String propertyName, Object propertyValue) {
- return newQueryBuilder().addEquals(propertyName, propertyValue).getNextStep();
+ TopiaQueryBuilderRunQueryStep<E> result = newQueryBuilder().addEquals(propertyName, propertyValue).getNextStep();
+ return result;
}
@Override
public TopiaQueryBuilderRunQueryStep<E> forIn(String propertyName, Iterable<Object> propertyValues) {
- return newQueryBuilder().addIn(propertyName, propertyValues).getNextStep();
+ TopiaQueryBuilderRunQueryStep<E> result = newQueryBuilder().addIn(propertyName, propertyValues).getNextStep();
+ return result;
}
protected boolean exists(String hql, Map<String, Object> hqlParameters) {
List<E> entities = topiaJpaSupport.find(hql, 0, 0, hqlParameters);
- boolean exists = !entities.isEmpty();
- return exists;
+ boolean result = !entities.isEmpty();
+ return result;
}
protected long count(String hql, Map<String, Object> hqlParameters) {
Preconditions.checkArgument(hql.toLowerCase().trim().startsWith("select count("));
- Long count = findUnique(hql, hqlParameters, Long.class);
- return count;
+ Long result = findUnique(hql, hqlParameters, Long.class);
+ return result;
}
protected E findUnique(String hql, Map<String, Object> hqlParameters) {
- E unique = findUnique(hql, hqlParameters, getEntityClass());
- return unique;
+ E result = findUnique(hql, hqlParameters, getEntityClass());
+ return result;
}
protected E findUniqueOrNull(String hql, Map<String, Object> hqlParameters) {
- E uniqueOrNull = findUniqueOrNull(hql, hqlParameters, getEntityClass());
- return uniqueOrNull;
+ E result = findUniqueOrNull(hql, hqlParameters, getEntityClass());
+ return result;
}
protected Optional<E> tryFindUnique(String hql, Map<String, Object> hqlParameters) {
- Optional<E> uniqueOrNull = tryFindUnique(hql, hqlParameters, getEntityClass());
- return uniqueOrNull;
+ Optional<E> result = tryFindUnique(hql, hqlParameters, getEntityClass());
+ return result;
}
protected E findFirst(String hql, Map<String, Object> hqlParameters) {
- E firstOrNull = findFirst(hql, hqlParameters, getEntityClass());
- return firstOrNull;
+ E result = findFirst(hql, hqlParameters, getEntityClass());
+ return result;
}
protected E findFirstOrNull(String hql, Map<String, Object> hqlParameters) {
- E anyOrNull = findFirstOrNull(hql, hqlParameters, getEntityClass());
- return anyOrNull;
+ E result = findFirstOrNull(hql, hqlParameters, getEntityClass());
+ return result;
}
protected Optional<E> tryFindFirst(String hql, Map<String, Object> hqlParameters) {
- Optional<E> anyOrNull = tryFindFirst(hql, hqlParameters, getEntityClass());
- return anyOrNull;
+ Optional<E> result = tryFindFirst(hql, hqlParameters, getEntityClass());
+ return result;
}
protected E findAny(String hql, Map<String, Object> hqlParameters) {
- E anyOrNull = findAny(hql, hqlParameters, getEntityClass());
- return anyOrNull;
+ E result = findAny(hql, hqlParameters, getEntityClass());
+ return result;
}
protected E findAnyOrNull(String hql, Map<String, Object> hqlParameters) {
- E anyOrNull = findAnyOrNull(hql, hqlParameters, getEntityClass());
- return anyOrNull;
+ E result = findAnyOrNull(hql, hqlParameters, getEntityClass());
+ return result;
}
protected Optional<E> tryFindAny(String hql, Map<String, Object> hqlParameters) {
- Optional<E> anyOrNull = tryFindAny(hql, hqlParameters, getEntityClass());
- return anyOrNull;
+ Optional<E> result = tryFindAny(hql, hqlParameters, getEntityClass());
+ return result;
}
protected <R> R findUnique(String hql, Map<String, Object> hqlParameters, Class<R> type) {
- R uniqueOrNull = findUniqueOrNull(hql, hqlParameters, type);
- if (uniqueOrNull == null) {
+ R result = findUniqueOrNull(hql, hqlParameters, type);
+ if (result == null) {
// TODO brendan 30/09/13 throw another exception if no result
throw new TopiaException("query " + hql + " returns no elements");
}
- return uniqueOrNull;
+ return result;
}
protected <R> Optional<R> tryFindUnique(String hql, Map<String, Object> hqlParameters, Class<R> type) {
R uniqueOrNull = findUniqueOrNull(hql, hqlParameters, type);
- return Optional.fromNullable(uniqueOrNull);
+ Optional<R> result = Optional.fromNullable(uniqueOrNull);
+ return result;
}
protected <R> R findUniqueOrNull(String hql, Map<String, Object> hqlParameters, Class<R> type) {
@@ -471,85 +481,87 @@
throw new TopiaException(message);
}
// otherwise return the first one, or null
- R uniqueOrNull = Iterables.getOnlyElement(results, null);
- return uniqueOrNull;
+ R result = Iterables.getOnlyElement(results, null);
+ return result;
}
protected <R> R findFirst(String hql, Map<String, Object> hqlParameters, Class<R> type) {
- R firstOrNull = findFirstOrNull(hql, hqlParameters, type);
- if (firstOrNull == null) {
+ R result = findFirstOrNull(hql, hqlParameters, type);
+ if (result == null) {
// TODO brendan 30/09/13 throw another exception if no result
throw new TopiaException("query " + hql + " returns no elements");
}
- return firstOrNull;
+ return result;
}
protected <R> Optional<R> tryFindFirst(String hql, Map<String, Object> hqlParameters, Class<R> type) {
R firstOrNull = findFirstOrNull(hql, hqlParameters, type);
- return Optional.fromNullable(firstOrNull);
+ Optional<R> result = Optional.fromNullable(firstOrNull);
+ return result;
}
protected <R> R findFirstOrNull(String hql, Map<String, Object> hqlParameters, Class<R> type) {
Preconditions.checkArgument(hql.toLowerCase().contains("order by"));
- R anyOrNull = findAnyOrNull(hql, hqlParameters, type);
- return anyOrNull;
+ R result = findAnyOrNull(hql, hqlParameters, type);
+ return result;
}
protected <R> R findAny(String hql, Map<String, Object> hqlParameters, Class<R> type) {
- R anyOrNull = findAnyOrNull(hql, hqlParameters, type);
- if (anyOrNull == null) {
+ R result = findAnyOrNull(hql, hqlParameters, type);
+ if (result == null) {
// TODO brendan 30/09/13 throw another exception if no result
- throw new TopiaException("query " + hql + " returns no elements");
+ throw new TopiaException(String.format("Query '%s' returns no elements", hql));
}
- return anyOrNull;
+ return result;
}
protected <R> Optional<R> tryFindAny(String hql, Map<String, Object> hqlParameters, Class<R> type) {
R anyOrNull = findAnyOrNull(hql, hqlParameters, type);
- return Optional.fromNullable(anyOrNull);
+ Optional<R> result = Optional.fromNullable(anyOrNull);
+ return result;
}
protected <R> R findAnyOrNull(String hql, Map<String, Object> hqlParameters, Class<R> type) {
Preconditions.checkNotNull(hql);
Preconditions.checkNotNull(hqlParameters);
List<R> results = findAll(hql, hqlParameters, type, 0, 0);
- R anyOrNull = Iterables.getOnlyElement(results, null);
- return anyOrNull;
+ R result = Iterables.getOnlyElement(results, null);
+ return result;
}
protected List<E> findAll(String hql, Map<String, Object> hqlParameters) {
Preconditions.checkNotNull(hql);
Preconditions.checkNotNull(hqlParameters);
- List<E> all = topiaJpaSupport.findAll(hql, hqlParameters);
- return all;
+ List<E> result = topiaJpaSupport.findAll(hql, hqlParameters);
+ return result;
}
protected List<E> findAll(String hql, Map<String, Object> hqlParameters, int startIndex, int endIndex) {
Preconditions.checkNotNull(hql);
Preconditions.checkNotNull(hqlParameters);
- List<E> all = topiaJpaSupport.find(hql, startIndex, endIndex, hqlParameters);
- return all;
+ List<E> result = topiaJpaSupport.find(hql, startIndex, endIndex, hqlParameters);
+ return result;
}
protected List<E> findAll(String hql, Map<String, Object> hqlParameters, TopiaPagerBean pager) {
- List<E> all = findAll(hql, hqlParameters, getEntityClass(), pager);
- return all;
+ List<E> result = findAll(hql, hqlParameters, getEntityClass(), pager);
+ return result;
}
protected <R> List<R> findAll(String hql, Map<String, Object> hqlParameters, Class<R> type) {
Preconditions.checkNotNull(hql);
Preconditions.checkNotNull(hqlParameters);
Preconditions.checkNotNull(type);
- List<R> all = topiaJpaSupport.findAll(hql, hqlParameters);
- return all;
+ List<R> result = topiaJpaSupport.findAll(hql, hqlParameters);
+ return result;
}
protected <R> List<R> findAll(String hql, Map<String, Object> hqlParameters, Class<R> type, int startIndex, int endIndex) {
Preconditions.checkNotNull(hql);
Preconditions.checkNotNull(hqlParameters);
Preconditions.checkNotNull(type);
- List<R> all = topiaJpaSupport.find(hql, startIndex, endIndex, hqlParameters);
- return all;
+ List<R> result = topiaJpaSupport.find(hql, startIndex, endIndex, hqlParameters);
+ return result;
}
protected <R> List<R> findAll(String hql, Map<String, Object> hqlParameters, Class<R> type, TopiaPagerBean pager) {
@@ -575,8 +587,8 @@
}
protected Iterable<E> findAllLazy(String hql, Map<String, Object> hqlParameters) {
- Iterable<E> allLazy = findAllLazy(hql, hqlParameters, getEntityClass());
- return allLazy;
+ Iterable<E> result = findAllLazy(hql, hqlParameters, getEntityClass());
+ return result;
}
protected <R> Iterable<R> findAllLazy(String hql, Map<String, Object> hqlParameters, Class<R> type) {
@@ -604,45 +616,60 @@
@Override
public TopiaQueryBuilderRunQueryStep<E> forTopiaIdEquals(String topiaId) {
Preconditions.checkNotNull(topiaId, "given topiaId is null");
- return forEquals(TopiaEntity.PROPERTY_TOPIA_ID, topiaId);
+ TopiaQueryBuilderRunQueryStep<E> result = forEquals(TopiaEntity.PROPERTY_TOPIA_ID, topiaId);
+ return result;
}
@Override
public TopiaQueryBuilderRunQueryStep<E> forTopiaIdIn(Iterable<String> topiaIds) {
Preconditions.checkNotNull(topiaIds, "given topiaIds is null");
- return forIn(TopiaEntity.PROPERTY_TOPIA_ID, (Iterable) topiaIds);
+ TopiaQueryBuilderRunQueryStep<E> result = forIn(TopiaEntity.PROPERTY_TOPIA_ID, (Iterable) topiaIds);
+ return result;
}
@Override
+ public E findByTopiaId(String id) {
+ // AThimel 30/10/13 Not using findUnique to avoid querying several elements (cf. findUnique implementation)
+ E result = forTopiaIdEquals(id).findAny();
+ return result;
+ }
+
+ @Override
+ public Optional<E> tryFindByTopiaId(String topiaId) {
+ Optional<E> result = forTopiaIdEquals(topiaId).tryFindAny();
+ return result;
+ }
+
+ @Override
public List<String> findAllIds() {
- List<String> find = newQueryBuilder().findAllIds();
- return find;
+ List<String> result = newQueryBuilder().findAllIds();
+ return result;
}
@Override
public List<E> findAll() {
- List<E> all = newQueryBuilder().findAll();
- return all;
+ List<E> result = newQueryBuilder().findAll();
+ return result;
}
@Override
public Iterable<E> findAllLazy() {
String hql = "from " + getTopiaEntityEnum().getImplementationFQN() + " order by id";
Map<String, Object> hqlParameters = Collections.emptyMap();
- Iterable<E> allLazy = findAllLazy(hql, hqlParameters);
- return allLazy;
+ Iterable<E> result = findAllLazy(hql, hqlParameters);
+ return result;
}
@Override
public Iterator<E> iterator() {
- Iterator<E> iterator = findAllLazy().iterator();
- return iterator;
+ Iterator<E> result = findAllLazy().iterator();
+ return result;
}
@Override
public long count() {
- long count = newQueryBuilder().count();
- return count;
+ long result = newQueryBuilder().count();
+ return result;
}
/**
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAOImpl.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAOImpl.java 2013-10-30 11:16:15 UTC (rev 2851)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAOImpl.java 2013-10-30 17:42:49 UTC (rev 2852)
@@ -37,6 +37,7 @@
package org.nuiton.topia.persistence;
+import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
import com.google.common.collect.Iterators;
@@ -973,6 +974,11 @@
}
@Override
+ public Optional<E> tryFindByTopiaId(String topiaId) {
+ throw new UnsupportedOperationException("Please use new Dao implementations");
+ }
+
+ @Override
public TopiaQueryBuilderRunQueryStep<E> forIn(String propertyName, Iterable<Object> propertyValues) {
throw new UnsupportedOperationException("Please use new Dao implementations");
}
@@ -1043,17 +1049,17 @@
@Override
public <E1> List<E1> findAll(String hql, Object... propertyNamesAndValues) throws TopiaException {
- throw new UnsupportedOperationException("Do not use this DAO implementation");
+ throw new UnsupportedOperationException("Please use new Dao implementations");
}
@Override
public <E1> List<E1> find(String hql, int startIndex, int endIndex, Object... propertyNamesAndValues) throws TopiaException {
- throw new UnsupportedOperationException("Do not use this DAO implementation");
+ throw new UnsupportedOperationException("Please use new Dao implementations");
}
@Override
public <E1> E1 findUnique(String hql, Object... propertyNamesAndValues) throws TopiaException {
- throw new UnsupportedOperationException("Do not use this DAO implementation");
+ throw new UnsupportedOperationException("Please use new Dao implementations");
}
} //TopiaDAOImpl
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDao.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDao.java 2013-10-30 11:16:15 UTC (rev 2851)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDao.java 2013-10-30 17:42:49 UTC (rev 2852)
@@ -1,10 +1,12 @@
package org.nuiton.topia.persistence;
+import java.util.List;
+import java.util.Map;
+
import org.nuiton.topia.event.TopiaEntityListener;
import org.nuiton.topia.event.TopiaEntityVetoable;
-import java.util.List;
-import java.util.Map;
+import com.google.common.base.Optional;
/**
* This contract represents the common operation any DAO should
@@ -24,7 +26,7 @@
/**
* Obtains the batch size used to load data.
- *
+ * <p/>
* Default value if 1000.
*
* @return the batch size.
@@ -148,8 +150,9 @@
* @since 3.0
*/
TopiaQueryBuilderAddCriteriaOrRunQueryStep<E> forProperties(String propertyName,
- Object propertyValue,
- Object... otherPropertyNamesAndValues);
+ Object propertyValue,
+ Object... otherPropertyNamesAndValues);
+
/**
* @since 3.0
*/
@@ -176,8 +179,28 @@
TopiaQueryBuilderRunQueryStep<E> forTopiaIdEquals(String topiaId);
/**
+ * Tries to find the entity with the given topiaId. If not found, an exception will be thrown.
+ * <p/>
+ * IMPORTANT : The behavior of the method changes in ToPIA 3.0 because an exception is thrown if no entity found.
+ *
+ * @param topiaId the identifier of the entity to look for
+ * @return The entity found
+ * @throws SomeException when not result is found // TODO AThimel 30/10/13 Find the right exception
+ */
+ E findByTopiaId(String topiaId);
+
+ /**
+ * Tries to find the entity with the given topiaId. If not found, the result.isPresent() will be <code>false</code>.
+ *
+ * @param topiaId the identifier of the entity to look for
+ * @return The entity found wrapped by an Optional
* @since 3.0
*/
+ Optional<E> tryFindByTopiaId(String topiaId);
+
+ /**
+ * @since 3.0
+ */
TopiaQueryBuilderRunQueryStep<E> forTopiaIdIn(Iterable<String> topiaIds);
void addTopiaEntityListener(TopiaEntityListener listener);
Modified: trunk/topia-persistence/src/test/java/org/nuiton/topiatest/deletetest/DeleteEntityTest.java
===================================================================
--- trunk/topia-persistence/src/test/java/org/nuiton/topiatest/deletetest/DeleteEntityTest.java 2013-10-30 11:16:15 UTC (rev 2851)
+++ trunk/topia-persistence/src/test/java/org/nuiton/topiatest/deletetest/DeleteEntityTest.java 2013-10-30 17:42:49 UTC (rev 2852)
@@ -96,7 +96,7 @@
log.debug("DELETE PERSONNE");
dao.delete(personne);
transaction.commitTransaction();
- Personne res = dao.findByTopiaId(idPersonne);
+ Personne res = dao.forTopiaIdEquals(idPersonne).findAnyOrNull();
assertNull(res);
log.debug("ENTITY PERSONNE DELETED !");
@@ -113,7 +113,7 @@
log.debug("DELETE PERSONNE with PartyDAO");
dao2.delete(personne2);
transaction.commitTransaction();
- Party2 res2 = dao2.findByTopiaId(idPersonne2);
+ Party2 res2 = dao2.forTopiaIdEquals(idPersonne2).findAnyOrNull();
assertNull(res2);
log.debug("ENTITY PERSONNE DELETED !");
@@ -161,7 +161,7 @@
log.debug("DELETE PERSONNE");
dao.delete(personne);
transaction.commitTransaction();
- Personne res = dao.findByTopiaId(idPersonne);
+ Personne res = dao.forTopiaIdEquals(idPersonne).findAnyOrNull();
assertNull(res);
log.debug("ENTITY PERSONNE DELETED !");
@@ -170,7 +170,7 @@
log.debug("DELETE CONTACT");
contactDAO.delete(contact);
transaction.commitTransaction();
- Contact2 res2 = contactDAO.findByTopiaId(idContact);
+ Contact2 res2 = contactDAO.forTopiaIdEquals(idContact).findAnyOrNull();
assertNull(res2);
log.debug("ENTITY PERSONNE DELETED !");
1
0
r2851 - in trunk: src/site/rst topia-persistence/src/main/java/org/nuiton/topia topia-persistence/src/main/java/org/nuiton/topia/framework topia-persistence/src/main/java/org/nuiton/topia/generator topia-persistence/src/main/java/org/nuiton/topia/persistence
by athimel@users.nuiton.org 30 Oct '13
by athimel@users.nuiton.org 30 Oct '13
30 Oct '13
Author: athimel
Date: 2013-10-30 12:16:15 +0100 (Wed, 30 Oct 2013)
New Revision: 2851
Url: http://nuiton.org/projects/topia/repository/revisions/2851
Log:
Fix behavior when using new Dao with foreign TopiaContext
Modified:
trunk/src/site/rst/migrate_to_3.0.rst
trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaContext.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/AbstractTopiaContext.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityDaoTransformer.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/AbstractTopiaDao.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/LegacyTopiaDao.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAO.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAOImpl.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaQueryBuilderRunQueryStep.java
Modified: trunk/src/site/rst/migrate_to_3.0.rst
===================================================================
--- trunk/src/site/rst/migrate_to_3.0.rst 2013-10-30 01:17:00 UTC (rev 2850)
+++ trunk/src/site/rst/migrate_to_3.0.rst 2013-10-30 11:16:15 UTC (rev 2851)
@@ -178,6 +178,39 @@
- Expected class declaration is : public class AbstractZoneTopiaDao<E extends Zone> extends GeneratedZoneTopiaDao<E> {
+Méthodes findAll, find et findUnique sur TopiaContext
+-----------------------------------------------------
+|MANDATORY|
+
+Si vous utilisiez ces méthodes, il est désormais recommandé de les utiliser méthodes sur le Dao associé à votre éntité
+ou par l'intermédiare du **TopiaJpaSupport**.
+
+Depuis un Dao surchargé
+~~~~~~~~~~~~~~~~~~~~~~~
+
+Pour faciliter la migration, ces méthodes ont été portées sur l'interface deprecated **TopiaDAO**. Donc si dans votre
+Dao vous faisiez :
+
+::
+
+ List<Zone> zones = context.find("FROM Zone WHERE name=:name" , startIndex, endIndex, "name", "Principale");
+
+Il vous suffit de retirer le "context." :
+
+::
+
+ List<Zone> zones = find("FROM Zone WHERE name=:name" , startIndex, endIndex, "name", "Principale");
+
+Dans tous les cas
+~~~~~~~~~~~~~~~~~
+
+Dans tous les cas, ces méthodes étant dépréciées, vous devriez consulter leur Javadoc pour savoir par quels appels de
+méthodes les remplacer.
+
+
+
+
+
.. |RECOMMENDED| image:: recommended.png
.. |MANDATORY| image:: mandatory.png
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaContext.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaContext.java 2013-10-30 01:17:00 UTC (rev 2850)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaContext.java 2013-10-30 11:16:15 UTC (rev 2851)
@@ -53,6 +53,7 @@
* @author athimel <thimel(a)codelutin.com>
* @version $Id$
*/
+@Deprecated
public interface TopiaContext extends TopiaTransaction, TopiaListenableSupport, TopiaSqlSupport, TopiaJpaSupport,
TopiaPersistenceContext, TopiaServiceSupport, TopiaReplicationSupport, TopiaReplicationDestination, TopiaHibernateSupport {
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/AbstractTopiaContext.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/AbstractTopiaContext.java 2013-10-30 01:17:00 UTC (rev 2850)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/AbstractTopiaContext.java 2013-10-30 11:16:15 UTC (rev 2851)
@@ -737,7 +737,7 @@
// looking for specialized DAO
// normalement il en existe un car il est généré automatiquement
// si on utilise la génération
- String daoClassname = entityClass.getName() + "DAO";
+ String daoClassname = entityClass.getName() + "TopiaDao";
try {
Class<TopiaDAO<E>> daoClass =
(Class<TopiaDAO<E>>) Class.forName(daoClassname);
@@ -763,7 +763,9 @@
@Override
public <E extends TopiaEntity, D extends TopiaDAO<E>> D getDao(Class<E> entityClass,
Class<D> daoClass) throws TopiaException {
- return (D) getDao(entityClass);
+ TopiaDAO<E> dao = getDao(entityClass);
+ D result = (D) dao;
+ return result;
}
@Override
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityDaoTransformer.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityDaoTransformer.java 2013-10-30 01:17:00 UTC (rev 2850)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityDaoTransformer.java 2013-10-30 11:16:15 UTC (rev 2851)
@@ -599,9 +599,11 @@
body.append(""
/*{
{
- List<<%=attrSimpleType%>> list = topiaDaoSupplier
- .getDao(<%=attrSimpleType%>.class, <%=attrConcreteDaoClassName%>.class)
- .forProperties(<%=attrSimpleType%>.<%=getConstantName(reverseAttrName)%>, entity).findAll();
+ <%=attrConcreteDaoClassName%> dao = topiaDaoSupplier
+ .getDao(<%=attrSimpleType%>.class, <%=attrConcreteDaoClassName%>.class);
+ List<<%=attrSimpleType%>> list = dao
+ .forProperties(<%=attrSimpleType%>.<%=getConstantName(reverseAttrName)%>, entity)
+ .findAll();
for (<%=attrSimpleType%> item : list) {
// sletellier : Set null only if target is concerned by deletion
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/AbstractTopiaDao.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/AbstractTopiaDao.java 2013-10-30 01:17:00 UTC (rev 2850)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/AbstractTopiaDao.java 2013-10-30 11:16:15 UTC (rev 2851)
@@ -81,7 +81,7 @@
* @author bpoussin <poussin(a)codelutin.com>
* @version $Id$
*/
-public abstract class AbstractTopiaDao<E extends TopiaEntity> extends LegacyTopiaDao<E> {
+public abstract class AbstractTopiaDao<E extends TopiaEntity> extends LegacyTopiaDao<E> implements TopiaDao<E> {
/** to use log facility, just put in your code: log.info(\"...\"); */
private static Log log = LogFactory.getLog(AbstractTopiaDao.class);
@@ -863,8 +863,8 @@
}
@Override
- public List<E> findAll(int startIndex, int endIndex) {
- return getNextStep().findAll(startIndex, endIndex);
+ public List<E> find(int startIndex, int endIndex) {
+ return getNextStep().find(startIndex, endIndex);
}
@Override
@@ -878,8 +878,8 @@
}
@Override
- public List<String> findAllIds(int startIndex, int endIndex) {
- return getNextStep().findAllIds(startIndex, endIndex);
+ public List<String> findIds(int startIndex, int endIndex) {
+ return getNextStep().findIds(startIndex, endIndex);
}
@Override
@@ -977,7 +977,7 @@
}
@Override
- public List<E> findAll(int startIndex, int endIndex) {
+ public List<E> find(int startIndex, int endIndex) {
return topiaDAO.findAll(hql, hqlParameters, startIndex, endIndex);
}
@@ -989,7 +989,7 @@
}
@Override
- public List<String> findAllIds(int startIndex, int endIndex) {
+ public List<String> findIds(int startIndex, int endIndex) {
// XXX brendan 30/09/13 does this truely work ?
String hqlWithSelectClause = "select topiaId " + hql;
return topiaDAO.findAll(hqlWithSelectClause, hqlParameters, String.class, startIndex, endIndex);
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/LegacyTopiaDao.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/LegacyTopiaDao.java 2013-10-30 01:17:00 UTC (rev 2850)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/LegacyTopiaDao.java 2013-10-30 11:16:15 UTC (rev 2851)
@@ -3,6 +3,7 @@
import com.google.common.base.Preconditions;
import org.apache.commons.lang3.StringUtils;
import org.nuiton.topia.TopiaContext;
+import org.nuiton.topia.TopiaException;
import org.nuiton.topia.framework.TopiaContextImplementor;
import org.nuiton.topia.framework.TopiaUtil;
import org.nuiton.topia.persistence.pager.TopiaPagerBean;
@@ -15,6 +16,7 @@
/**
* Implements deprecated method from {@link TopiaDAO}, should be deleted.
*/
+@Deprecated
public abstract class LegacyTopiaDao<E extends TopiaEntity> implements TopiaDAO<E> {
@Override
@@ -61,7 +63,7 @@
@Deprecated
public <R> R findByQuery(Class<R> type, String hql, Object... propertyNamesAndValues) {
Map<String, Object> properties = TopiaUtil.convertPropertiesArrayToMap(propertyNamesAndValues);
- return findAny(hql, properties, type);
+ return findAnyOrNull(hql, properties, type);
}
@Override
@@ -145,8 +147,7 @@
Preconditions.checkNotNull(StringUtils.isNotBlank(hql));
Preconditions.checkArgument(hql.toUpperCase().trim().startsWith("SELECT COUNT("));
Map<String, Object> hqlParameters = TopiaUtil.convertPropertiesArrayToMap(propertyNamesAndValues);
- // FIXME AThimel 30/10/13 This cannot work : the final query will be "select count(topiaId) select count(...) ..."
- long count = forHql(hql, hqlParameters).count();
+ long count = findAny(hql, hqlParameters, Long.class);
return count;
}
@@ -297,6 +298,8 @@
protected abstract <R> R findAny(String hql, Map<String, Object> properties, Class<R> type);
+ protected abstract <R> R findAnyOrNull(String hql, Map<String, Object> hqlParameters, Class<R> type);
+
protected abstract TopiaQueryBuilderRunQueryStep<E> forHql(String hql, Map<String, Object> hqlParameters);
protected abstract <R> List<R> findAll(String hql, Map<String, Object> hqlParameters, Class<R> type);
@@ -305,6 +308,27 @@
protected abstract <R> List<R> findAll(String hql, Map<String, Object> hqlParameters, Class<R> type, int startIndex, int endIndex);
+ protected abstract <R> R findUnique(String hql, Map<String, Object> hqlParameters, Class<R> type);
+
protected abstract boolean exists(String hql, Map<String, Object> hqlParameters);
+ @Override
+ @Deprecated
+ public <E1> List<E1> findAll(String hql, Object... propertyNamesAndValues) throws TopiaException {
+ return (List<E1>) findAllByQuery(hql, propertyNamesAndValues);
+ }
+
+ @Override
+ @Deprecated
+ public <E1> List<E1> find(String hql, int startIndex, int endIndex, Object... propertyNamesAndValues) throws TopiaException {
+ return (List<E1>) findAllByQueryWithBound(hql, startIndex, endIndex, propertyNamesAndValues);
+ }
+
+ @Override
+ @Deprecated
+ public <E1> E1 findUnique(String hql, Object... propertyNamesAndValues) throws TopiaException {
+ Map<String, Object> hqlParameters = TopiaUtil.convertPropertiesArrayToMap(propertyNamesAndValues);
+ return (E1) findUnique(hql, hqlParameters, Object.class);
+ }
+
}
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAO.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAO.java 2013-10-30 01:17:00 UTC (rev 2850)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAO.java 2013-10-30 11:16:15 UTC (rev 2851)
@@ -618,5 +618,69 @@
List<Permission> getRequestPermission(String topiaId,
int actions) throws TopiaException;
+ // The next 3 methods are copied from TopiaContext in order to facilitate migration
+
+ /**
+ * Allow to do some HQL query
+ * <p/>
+ * WARNING : Depending on the registered service, this method may not
+ * support something else than queries on TopiaEntity
+ *
+ * @param hql the HQL query
+ * @param propertyNamesAndValues the query parameters. Arguments are key-value paired :
+ * [propertyName;value;propertyName;value;...]
+ * @return The result list
+ * @throws TopiaException for any error during querying
+ * @deprecated use method from {@link org.nuiton.topia.TopiaJpaSupport}
+ */
+ @Deprecated
+ <E> List<E> findAll(String hql,
+ Object... propertyNamesAndValues) throws TopiaException;
+
+ /**
+ * Allow to do some JPA-QL query using the given bounds.
+ * <p/>
+ * No lower bound : <code>startIndex</code> = 0.<br/>
+ * No upper bound : <code>endIndex</code> = -1.
+ * <p/>
+ * WARNING : Depending on the registered service, this method may not
+ * support something else than queries on TopiaEntity
+ *
+ * @param hql the HQL query
+ * @param startIndex first index of entity to return
+ * @param endIndex last index of entity to return
+ * @param propertyNamesAndValues the query parameters. Arguments are key-value paired :
+ * [propertyName;value;propertyName;value;...]
+ * @return The result list
+ * @throws TopiaException for any error during querying
+ * @deprecated use method from {@link org.nuiton.topia.TopiaJpaSupport}
+ */
+ @Deprecated
+ <E> List<E> find(String hql,
+ int startIndex,
+ int endIndex,
+ Object... propertyNamesAndValues) throws TopiaException;
+
+ /**
+ * Allow to do some HQL query and return an unique result. If nothing if
+ * found by the query, will return null. If more than one result is found,
+ * will throw an exception.
+ * <p/>
+ * WARNING : Depending on the registered service, this method may not
+ * support something else than queries on TopiaEntity
+ *
+ * @param hql the HQL query
+ * @param propertyNamesAndValues the query parameters. Arguments are key-value paired :
+ * [propertyName;value;propertyName;value;...]
+ * @return The result instance or null
+ * @throws TopiaException for any error during querying or if the the query
+ * returns more than one result.
+ * @deprecated use method from {@link org.nuiton.topia.TopiaJpaSupport}
+ */
+ @Deprecated
+ <E> E findUnique(String hql,
+ Object... propertyNamesAndValues) throws TopiaException;
+
+
} //TopiaDAO
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAOImpl.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAOImpl.java 2013-10-30 01:17:00 UTC (rev 2850)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAOImpl.java 2013-10-30 11:16:15 UTC (rev 2851)
@@ -1041,4 +1041,19 @@
return entities;
}
+ @Override
+ public <E1> List<E1> findAll(String hql, Object... propertyNamesAndValues) throws TopiaException {
+ throw new UnsupportedOperationException("Do not use this DAO implementation");
+ }
+
+ @Override
+ public <E1> List<E1> find(String hql, int startIndex, int endIndex, Object... propertyNamesAndValues) throws TopiaException {
+ throw new UnsupportedOperationException("Do not use this DAO implementation");
+ }
+
+ @Override
+ public <E1> E1 findUnique(String hql, Object... propertyNamesAndValues) throws TopiaException {
+ throw new UnsupportedOperationException("Do not use this DAO implementation");
+ }
+
} //TopiaDAOImpl
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaQueryBuilderRunQueryStep.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaQueryBuilderRunQueryStep.java 2013-10-30 01:17:00 UTC (rev 2850)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaQueryBuilderRunQueryStep.java 2013-10-30 11:16:15 UTC (rev 2851)
@@ -35,10 +35,10 @@
Iterable<E> findAllLazy();
- List<E> findAll(int startIndex, int endIndex);
+ List<E> find(int startIndex, int endIndex);
List<String> findAllIds();
- List<String> findAllIds(int startIndex, int endIndex);
+ List<String> findIds(int startIndex, int endIndex);
}
1
0
r2850 - in trunk/topia-persistence/src/main/java/org/nuiton/topia: generator persistence
by athimel@users.nuiton.org 30 Oct '13
by athimel@users.nuiton.org 30 Oct '13
30 Oct '13
Author: athimel
Date: 2013-10-30 02:17:00 +0100 (Wed, 30 Oct 2013)
New Revision: 2850
Url: http://nuiton.org/projects/topia/repository/revisions/2850
Log:
Deprecated generated ProjectDAOHelper
Keep old getDAO method in ProjectDAOHelper
Improve display for migration help in console
Add missing import in GeneratedXxxTopiaDao
Modified:
trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/DAOHelperTransformer.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityDaoTransformer.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/LegacyTopiaDao.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 2013-10-25 22:18:09 UTC (rev 2849)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/DAOHelperTransformer.java 2013-10-30 01:17:00 UTC (rev 2850)
@@ -154,6 +154,8 @@
addImport(daoHelper, EntityOperatorStore.class);
}
+ addAnnotation(daoHelper, daoHelper, Deprecated.class);
+
// add non public constructor
ObjectModelOperation constructor =
addConstructor(daoHelper, ObjectModelJavaModifier.PROTECTED);
@@ -196,6 +198,19 @@
}
+ // obsolete generic getDAO method
+ op = addOperation(daoHelper, "getDAO", "<T extends TopiaEntity, D extends TopiaDAO<? super T>> D", ObjectModelJavaModifier.PUBLIC, ObjectModelJavaModifier.STATIC);
+ addParameter(op, TopiaContext.class, "context");
+ addParameter(op, "Class<T>", "klass");
+ addException(op, TopiaException.class);
+ addAnnotation(daoHelper, op, Deprecated.class);
+ setOperationBody(op, ""
+/*{
+ D dao = getDao(context, klass);
+ return dao;
+ }*/
+ );
+
// generic getDao method
op = addOperation(daoHelper, "getDao", "<T extends TopiaEntity, D extends TopiaDAO<? super T>> D", ObjectModelJavaModifier.PUBLIC, ObjectModelJavaModifier.STATIC);
addParameter(op, TopiaContext.class, "context");
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityDaoTransformer.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityDaoTransformer.java 2013-10-25 22:18:09 UTC (rev 2849)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityDaoTransformer.java 2013-10-30 01:17:00 UTC (rev 2850)
@@ -378,10 +378,11 @@
String format = "public class %s%s extends %s {";
String superclassName = superclassQualifiedName.substring(superclassQualifiedName.lastIndexOf('.') + 1);
String daoDeclaration = String.format(format, daoName, Strings.nullToEmpty(daoGenerics), superclassName);
- String warnMessage = "Legacy DAO detected !%n" +
- " - You should consider renaming '%s' to '%s.%s'%n" +
- " - Expected class declaration is : %s";
- log.warn(String.format(warnMessage, legacyDaoFqn, packageName, daoName, daoDeclaration));
+ String warnMessage = "Legacy DAO detected : %s !%n" +
+ " - You should consider renaming '%s' to '%s'%n" +
+ " - Expected class declaration is : %s%n" +
+ "%n"; // AThimel 29/10/13 Add a new line for log clearness
+ log.warn(String.format(warnMessage, legacyDaoFqn, legacyDaoName, daoName, daoDeclaration));
}
}
@@ -588,6 +589,7 @@
// TODO peut-etre qu'hibernate est capable de faire ca tout seul ?
// THIMEL: J'ai remplacé reverse.getName() par reverseAttrName sans certitude
addImport(result, attrType);
+ addImport(result, attr.getType() + "TopiaDao"); // AThimel 30/10/13 Not using attrType because we need FQN // Can use TopiaGeneratorUtil.getConcreteDaoFqn(...) ?
String attrSimpleType = TopiaGeneratorUtil.getClassNameFromQualifiedName(attrType);
// XXX brendan 04/10/13 do not hard code concrete dao name
String attrConcreteDaoClassName = attrSimpleType + "TopiaDao";
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/LegacyTopiaDao.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/LegacyTopiaDao.java 2013-10-25 22:18:09 UTC (rev 2849)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/LegacyTopiaDao.java 2013-10-30 01:17:00 UTC (rev 2850)
@@ -145,6 +145,7 @@
Preconditions.checkNotNull(StringUtils.isNotBlank(hql));
Preconditions.checkArgument(hql.toUpperCase().trim().startsWith("SELECT COUNT("));
Map<String, Object> hqlParameters = TopiaUtil.convertPropertiesArrayToMap(propertyNamesAndValues);
+ // FIXME AThimel 30/10/13 This cannot work : the final query will be "select count(topiaId) select count(...) ..."
long count = forHql(hql, hqlParameters).count();
return count;
}
1
0
r2849 - in trunk: src/site/rst topia-persistence/src/main/java/org/nuiton/topia topia-persistence/src/main/java/org/nuiton/topia/generator
by athimel@users.nuiton.org 25 Oct '13
by athimel@users.nuiton.org 25 Oct '13
25 Oct '13
Author: athimel
Date: 2013-10-26 00:18:09 +0200 (Sat, 26 Oct 2013)
New Revision: 2849
Url: http://nuiton.org/projects/topia/repository/revisions/2849
Log:
Display a WARN message if some Legacy Dao is detected
Modified:
trunk/src/site/rst/migrate_to_3.0.rst
trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaPersistenceContext.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityDaoTransformer.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/TopiaGeneratorUtil.java
Modified: trunk/src/site/rst/migrate_to_3.0.rst
===================================================================
--- trunk/src/site/rst/migrate_to_3.0.rst 2013-10-25 14:48:13 UTC (rev 2848)
+++ trunk/src/site/rst/migrate_to_3.0.rst 2013-10-25 22:18:09 UTC (rev 2849)
@@ -71,14 +71,7 @@
La classe sera supprimée. Pour manipuler les topiaId, il faut utiliser le **TopiaIdFactory**.
-TopiaEntities#getTopiaIdFunction()
-----------------------------------
-|RECOMMENDED|
-
-La méthode est dépréciée, il faut maintenant utiliser ``TopiaEntities#GET_TOPIA_ID``.
-
-
TopiaContextImplementor est déprécié
------------------------------------
@@ -138,5 +131,53 @@
**TopiaSchemaListener**.
+Transformer pour la génération des Dao
+--------------------------------------
+
+|RECOMMENDED|
+
+Si vous utilisiez explicitment le Transformer de DAO dans la configuration de votre plugin Eugene, il faut maintenant
+changer le nouveau Transformer : org.nuiton.topia.generator.EntityDaoTransformer
+
+Exemple de configuration :
+
+::
+
+ <plugin>
+ <groupId>org.nuiton.eugene</groupId>
+ <artifactId>eugene-maven-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>generate-entities</id>
+ <phase>generate-sources</phase>
+ <configuration>
+ <inputs>classpath:model:/:myProject.objectmodel</inputs>
+ <defaultPackage>org.project.entities</defaultPackage>
+ <templates>
+ org.nuiton.topia.generator.EntityDaoTransformer
+ </templates>
+ </configuration>
+ <goals>
+ <goal>generate</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+
+
+
+|RECOMMENDED|
+
+Si vous aviez surchargé certains des Dao générés, vous devrez probablement les renommer et changer leur signature.
+Surveillez les logs de génération des Dao à la recherche des messages tels que :
+
+::
+
+ WARN [main] (EntityDaoTransformer.java:384) warnOnLegacyClassDetected - Legacy DAO detected !
+ - You should consider renaming 'org.project.entities.ZoneDAOImpl' to 'org.project.entities.AbstractZoneTopiaDao'
+ - Expected class declaration is : public class AbstractZoneTopiaDao<E extends Zone> extends GeneratedZoneTopiaDao<E> {
+
+
+
.. |RECOMMENDED| image:: recommended.png
.. |MANDATORY| image:: mandatory.png
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaPersistenceContext.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaPersistenceContext.java 2013-10-25 14:48:13 UTC (rev 2848)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaPersistenceContext.java 2013-10-25 22:18:09 UTC (rev 2849)
@@ -38,7 +38,8 @@
* @author Arnaud Thimel <thimel(a)codelutin.com>
* @since 3.0
*/
-public interface TopiaPersistenceContext extends TopiaReplicationSupport, TopiaReplicationDestination, TopiaDaoSupplier, TopiaTransaction {
+public interface TopiaPersistenceContext extends TopiaReplicationSupport, TopiaReplicationDestination,
+ TopiaDaoSupplier, TopiaTransaction {
/**
* Retrieve {@link org.nuiton.topia.persistence.TopiaEntity} using its unique {@code topiaId}.
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityDaoTransformer.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityDaoTransformer.java 2013-10-25 14:48:13 UTC (rev 2848)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityDaoTransformer.java 2013-10-25 22:18:09 UTC (rev 2849)
@@ -27,6 +27,7 @@
/*{generator option: parentheses = false}*/
/*{generator option: writeString = +}*/
+import com.google.common.base.Strings;
import com.google.common.collect.Sets;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
@@ -310,16 +311,24 @@
}
protected void generateConcreteDao(ObjectModelClass clazz, String clazzName, String clazzFQN) {
- ObjectModelClass daoClass = createClass(TopiaGeneratorUtil.getConcreteDaoName(clazz), clazz.getPackageName());
+ String concreteDaoName = TopiaGeneratorUtil.getConcreteDaoName(clazz);
+ ObjectModelClass daoClass = createClass(concreteDaoName, clazz.getPackageName());
setDocumentation(daoClass, "/**\n" +
" * Cette classe etend le DAOImpl pour parametrer la classe avec le bon type\n" +
" * Cette classe est marque finale car l'heritage entre les DAO se fait\n" +
" * sur les DOAImpl, c-a-d que DAOAbstract peut etendre le DAOImpl\n" +
" */");
// to support legacy dao
- setSuperClass(daoClass, TopiaGeneratorUtil.getLegacyDaoFqn(clazz));
+ String superclassQualifiedName = TopiaGeneratorUtil.getLegacyDaoFqn(clazz);
// TODO brendan 04/10/13 above line should be replaced by
- // setSuperClass(daoClass, TopiaGeneratorUtil.getAbstractDaoFqn(clazz) + "<" + clazzName + ">");
+// String superclassQualifiedName = TopiaGeneratorUtil.getAbstractDaoFqn(clazz) + "<" + clazzName + ">";
+ setSuperClass(daoClass, superclassQualifiedName);
+
+ // TODO AThimel 25/10/13 Remove the next lines in ToPIA 3.1
+ // Look for legacy Dao class, then warn user if found in classpath
+ String legacyConcreteDaoName = TopiaGeneratorUtil.getLegacyDaoName(clazz);
+ warnOnLegacyClassDetected(clazz.getPackageName(), legacyConcreteDaoName, concreteDaoName, null,
+ TopiaGeneratorUtil.getAbstractDaoFqn(clazz) + "<" + clazzName + ">");
}
protected void generateAbstractDao(ObjectModelClass clazz,
@@ -331,19 +340,52 @@
if (CollectionUtils.isEmpty(moreOperations)) {
- // no business dao found, can safely generate the daoImpl class
-
- ObjectModelClass daoImplClass = createClass(TopiaGeneratorUtil.getAbstractDaoName(clazz) + "<E extends " + clazzName + ">", clazz.getPackageName());
- setDocumentation(daoImplClass, "/**\n" +
- " Implantation du DAO pour l'entité " + clazzName + ".\n" +
- " * L'utilisateur peut remplacer cette classe par la sienne en la mettant \n" +
- " * simplement dans ces sources. Cette classe générée sera alors simplement\n" +
- " * écrasée\n" +
- " */");
- setSuperClass(daoImplClass, TopiaGeneratorUtil.getGeneratedDaoFqn(clazz) + "<E>");
+ // no business Dao found, can safely generate the abstract Dao class
+
+ String abstractDaoName = TopiaGeneratorUtil.getAbstractDaoName(clazz);
+ String daoGenerics = "<E extends " + clazzName + ">";
+ ObjectModelClass abstractDaoClass = createClass(abstractDaoName + daoGenerics, clazz.getPackageName());
+ String documentation = String.format("/**%n" +
+ " * Implantation du Dao pour l'entité '%s'.%n" +
+ " * L'utilisateur peut remplacer cette classe par la sienne en la mettant%n" +
+ " * simplement dans ses sources. Cette classe générée sera alors simplement%n" +
+ " * ignorée à la génération suivante.%n" +
+ " */", clazzName);
+ setDocumentation(abstractDaoClass, documentation);
+ String superclassQualifiedName = TopiaGeneratorUtil.getGeneratedDaoFqn(clazz) + "<E>";
+ setSuperClass(abstractDaoClass, superclassQualifiedName);
+
+ // TODO AThimel 25/10/13 Remove the next lines in ToPIA 3.1
+ // Look for legacy Dao class, then warn user if found in classpath
+ String legacyDaoImplName = TopiaGeneratorUtil.getLegacyDaoName(clazz) + "Impl";
+ warnOnLegacyClassDetected(clazz.getPackageName(), legacyDaoImplName, abstractDaoName, daoGenerics,
+ superclassQualifiedName);
+
}
}
+ // TODO AThimel 25/10/13 Remove this method in ToPIA 3.1
+ protected void warnOnLegacyClassDetected(String packageName,
+ String legacyDaoName,
+ String daoName,
+ String daoGenerics,
+ String superclassQualifiedName) {
+
+ String legacyDaoFqn = String.format("%s.%s", packageName, legacyDaoName);
+
+ // AThimel 25/10/13 Not using isInClassPath(fqn) because this method logs that file won't be generated
+ if (log.isWarnEnabled() && getFileInClassPath(legacyDaoFqn) != null) {
+ String format = "public class %s%s extends %s {";
+ String superclassName = superclassQualifiedName.substring(superclassQualifiedName.lastIndexOf('.') + 1);
+ String daoDeclaration = String.format(format, daoName, Strings.nullToEmpty(daoGenerics), superclassName);
+ String warnMessage = "Legacy DAO detected !%n" +
+ " - You should consider renaming '%s' to '%s.%s'%n" +
+ " - Expected class declaration is : %s";
+ log.warn(String.format(warnMessage, legacyDaoFqn, packageName, daoName, daoDeclaration));
+ }
+
+ }
+
protected void generateGeneratedDao(ObjectModelClass clazz,
String clazzName,
String clazzFQN) {
@@ -373,13 +415,12 @@
// imports
- Collection<ObjectModelOperation> DAOoperations =
- getDAOOperations(clazz);
+ Collection<ObjectModelOperation> daoOperations = getDaoOperations(clazz);
- if (TopiaGeneratorUtil.isCollectionNeeded(DAOoperations)) {
+ if (TopiaGeneratorUtil.isCollectionNeeded(daoOperations)) {
addImport(daoAbstractClass, Collection.class);
}
- if (TopiaGeneratorUtil.isSetNeeded(DAOoperations)) {
+ if (TopiaGeneratorUtil.isSetNeeded(daoOperations)) {
addImport(daoAbstractClass, Set.class);
}
addImport(daoAbstractClass, List.class);
@@ -413,7 +454,7 @@
}*/
);
- generateDAOOperations(daoAbstractClass, DAOoperations);
+ generateDAOOperations(daoAbstractClass, daoOperations);
generateDelete(clazz, daoAbstractClass);
@@ -983,8 +1024,10 @@
*
* @param clazz the clazz to test.
* @return collections of extra operations, or empty collection if none found.
+ * @deprecated Dao operation will not be generated anymore in a very close future
*/
- public Collection<ObjectModelOperation> getDAOOperations(
+ @Deprecated
+ public Collection<ObjectModelOperation> getDaoOperations(
ObjectModelClass clazz) {
// // Note : this collection will contains extra operations for DAO.
@@ -999,11 +1042,11 @@
// }
// }
- if (log.isWarnEnabled()) {
- log.warn("dao contract in model will not be supported in topia 3.0");
- }
Collection<ObjectModelOperation> extra =
extraOperations.get(clazz.getQualifiedName());
+ if (extra != null && !extra.isEmpty() && log.isWarnEnabled()) {
+ log.warn("Dao contract in model will not be supported in topia 3.0");
+ }
return extra;
// if (extra != null) {
// for (ObjectModelOperation op : extra) {
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 2013-10-25 14:48:13 UTC (rev 2848)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/TopiaGeneratorUtil.java 2013-10-25 22:18:09 UTC (rev 2849)
@@ -220,6 +220,7 @@
return input.getPackageName() + "." + getConcreteDaoName(input);
}
+ @Deprecated
public static String getLegacyDaoFqn(ObjectModelClass input) {
return input.getPackageName() + "." + getLegacyDaoName(input);
}
1
0
r2848 - in trunk/topia-persistence/src: main/java/org/nuiton/topia/persistence test/java/org/nuiton/topia/framework test/java/org/nuiton/topia/generator test/java/org/nuiton/topia/persistence test/java/org/nuiton/topia/test/ano1882 test/java/org/nuiton/topiatest test/java/org/nuiton/topiatest/deletetest
by athimel@users.nuiton.org 25 Oct '13
by athimel@users.nuiton.org 25 Oct '13
25 Oct '13
Author: athimel
Date: 2013-10-25 16:48:13 +0200 (Fri, 25 Oct 2013)
New Revision: 2848
Url: http://nuiton.org/projects/topia/repository/revisions/2848
Log:
Implement missing operations in TopiaDAOImpl
Modified:
trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAOImpl.java
trunk/topia-persistence/src/test/java/org/nuiton/topia/framework/TopiaConnectionProviderTest.java
trunk/topia-persistence/src/test/java/org/nuiton/topia/framework/TopiaContextReplicateTest.java
trunk/topia-persistence/src/test/java/org/nuiton/topia/generator/TopiaTestCase.java
trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/NaturalIdTest.java
trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/TopiaDAOTest.java
trunk/topia-persistence/src/test/java/org/nuiton/topia/test/ano1882/DAOAbstractTransformerTest.java
trunk/topia-persistence/src/test/java/org/nuiton/topiatest/EnumTest.java
trunk/topia-persistence/src/test/java/org/nuiton/topiatest/deletetest/DeleteEntityTest.java
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAOImpl.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAOImpl.java 2013-10-25 12:03:15 UTC (rev 2847)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAOImpl.java 2013-10-25 14:48:13 UTC (rev 2848)
@@ -59,12 +59,14 @@
import org.nuiton.topia.event.TopiaEntityVetoable;
import org.nuiton.topia.framework.TopiaContextImplementor;
import org.nuiton.topia.framework.TopiaFiresSupport;
+import org.nuiton.topia.framework.TopiaUtil;
import org.nuiton.topia.persistence.pager.TopiaPagerBean;
import org.nuiton.util.PagerBeanUtil;
import java.io.Serializable;
import java.lang.reflect.InvocationTargetException;
import java.security.Permission;
+import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
@@ -83,11 +85,11 @@
* @param <E> le type de l'entite
* @author bpoussin <poussin(a)codelutin.com>
* @version $Id$
+ * @deprecated this class is replaced by {@link AbstractTopiaDao}
*/
-
+@Deprecated
public class TopiaDAOImpl<E extends TopiaEntity> implements TopiaDAO<E> { // TopiaDAOImpl
- /** to use log facility, just put in your code: log.info(\"...\"); */
private static Log log = LogFactory.getLog(TopiaDAOImpl.class);
/**
@@ -959,4 +961,84 @@
"This iterator does not support remove operation.");
}
}
+
+ @Override
+ public TopiaQueryBuilderRunQueryStep<E> forTopiaIdIn(Iterable<String> topiaIds) {
+ throw new UnsupportedOperationException("Please use new Dao implementations");
+ }
+
+ @Override
+ public TopiaQueryBuilderRunQueryStep<E> forTopiaIdEquals(String topiaId) {
+ throw new UnsupportedOperationException("Please use new Dao implementations");
+ }
+
+ @Override
+ public TopiaQueryBuilderRunQueryStep<E> forIn(String propertyName, Iterable<Object> propertyValues) {
+ throw new UnsupportedOperationException("Please use new Dao implementations");
+ }
+
+ @Override
+ public TopiaQueryBuilderRunQueryStep<E> forEquals(String propertyName, Object propertyValue) {
+ throw new UnsupportedOperationException("Please use new Dao implementations");
+ }
+
+ @Override
+ public TopiaQueryBuilderRunQueryStep<E> forContains(String propertyName, Object propertyValue) {
+ throw new UnsupportedOperationException("Please use new Dao implementations");
+ }
+
+ @Override
+ public TopiaQueryBuilderAddCriteriaStep<E> newQueryBuilder() {
+ throw new UnsupportedOperationException("Please use new Dao implementations");
+ }
+
+ @Override
+ public TopiaQueryBuilderAddCriteriaOrRunQueryStep<E> forProperties(String propertyName, Object propertyValue, Object... otherPropertyNamesAndValues) {
+ throw new UnsupportedOperationException("Please use new Dao implementations");
+ }
+
+ @Override
+ public TopiaQueryBuilderAddCriteriaOrRunQueryStep<E> forProperties(Map<String, Object> properties) {
+ throw new UnsupportedOperationException("Please use new Dao implementations");
+ }
+
+ @Override
+ public E create(String propertyName, Object propertyValue, Object... otherPropertyNamesAndValues) {
+ Map<String, Object> properties =
+ TopiaUtil.convertPropertiesArrayToMap(propertyName, propertyValue, otherPropertyNamesAndValues);
+ E result = create(properties);
+ return result;
+ }
+
+ @Override
+ public E create() {
+ E result = newInstance();
+ create(result);
+ return result;
+ }
+
+ @Override
+ public Iterable<E> findAllLazy() {
+ String hql = "from " + getTopiaEntityEnum().getImplementationFQN() + " order by id";
+ Map<String, Object> hqlParameters = Collections.emptyMap();
+ Iterable<E> allLazy = findAllLazyByQuery(hql, hqlParameters);
+ return allLazy;
+ }
+
+ @Override
+ public Iterable<E> createAll(Iterable<E> entities) {
+ for (E entity : entities) {
+ create(entity);
+ }
+ return entities;
+ }
+
+ @Override
+ public Iterable<E> updateAll(Iterable<E> entities) {
+ for (E entity : entities) {
+ update(entity);
+ }
+ return entities;
+ }
+
} //TopiaDAOImpl
Modified: trunk/topia-persistence/src/test/java/org/nuiton/topia/framework/TopiaConnectionProviderTest.java
===================================================================
--- trunk/topia-persistence/src/test/java/org/nuiton/topia/framework/TopiaConnectionProviderTest.java 2013-10-25 12:03:15 UTC (rev 2847)
+++ trunk/topia-persistence/src/test/java/org/nuiton/topia/framework/TopiaConnectionProviderTest.java 2013-10-25 14:48:13 UTC (rev 2848)
@@ -33,7 +33,7 @@
import org.nuiton.topia.TopiaTestDAOHelper;
import org.nuiton.topia.TopiaTestTopiaPersistenceContext;
import org.nuiton.topia.test.entities.Person;
-import org.nuiton.topia.test.entities.PersonDao;
+import org.nuiton.topia.test.entities.PersonDAO;
import org.nuiton.topia.test.entities.PersonTopiaDao;
import org.nuiton.topiatest.Personne;
@@ -126,7 +126,7 @@
TopiaTestTopiaPersistenceContext transaction = db.beginTransaction();
try {
- PersonTopiaDao dao = TopiaTestDAOHelper.getPersonDAO(transaction);
+ PersonDAO dao = TopiaTestDAOHelper.getPersonDAO(transaction);
Person personne = dao.create(Personne.PROPERTY_NAME, "Jack Bauer");
transaction.commitTransaction();
Modified: trunk/topia-persistence/src/test/java/org/nuiton/topia/framework/TopiaContextReplicateTest.java
===================================================================
--- trunk/topia-persistence/src/test/java/org/nuiton/topia/framework/TopiaContextReplicateTest.java 2013-10-25 12:03:15 UTC (rev 2847)
+++ trunk/topia-persistence/src/test/java/org/nuiton/topia/framework/TopiaContextReplicateTest.java 2013-10-25 14:48:13 UTC (rev 2848)
@@ -32,9 +32,9 @@
import org.nuiton.topia.TopiaTestDAOHelper;
import org.nuiton.topia.TopiaTestTopiaPersistenceContext;
import org.nuiton.topia.test.entities.Person;
-import org.nuiton.topia.test.entities.PersonDao;
+import org.nuiton.topia.test.entities.PersonDAO;
import org.nuiton.topia.test.entities.Pet;
-import org.nuiton.topia.test.entities.PetDao;
+import org.nuiton.topia.test.entities.PetDAO;
import java.io.File;
import java.util.Properties;
@@ -92,8 +92,8 @@
TopiaTestTopiaPersistenceContext txSource;
TopiaTestTopiaPersistenceContext txTarget;
- PersonDao daoSource, daoTarget;
- PetDao petDAOSource, petDAOTarget;
+ PersonDAO daoSource, daoTarget;
+ PetDAO petDAOSource, petDAOTarget;
Person personSource, personTarget;
Pet petSource, petTarget;
Modified: trunk/topia-persistence/src/test/java/org/nuiton/topia/generator/TopiaTestCase.java
===================================================================
--- trunk/topia-persistence/src/test/java/org/nuiton/topia/generator/TopiaTestCase.java 2013-10-25 12:03:15 UTC (rev 2847)
+++ trunk/topia-persistence/src/test/java/org/nuiton/topia/generator/TopiaTestCase.java 2013-10-25 14:48:13 UTC (rev 2848)
@@ -35,9 +35,9 @@
import org.nuiton.topia.TopiaTestDAOHelper;
import org.nuiton.topia.TopiaTestTopiaPersistenceContext;
import org.nuiton.topiatest.Company;
-import org.nuiton.topiatest.CompanyDao;
+import org.nuiton.topiatest.CompanyDAO;
import org.nuiton.topiatest.Department;
-import org.nuiton.topiatest.DepartmentDao;
+import org.nuiton.topiatest.DepartmentDAO;
/**
* TopiaTestCase.
@@ -123,8 +123,8 @@
// try {
TopiaTestTopiaPersistenceContext newContext = db.beginTransaction();
- CompanyDao companyDAO = newContext.getCompanyDao();
- DepartmentDao departmentDAO = newContext.getDepartmentDao();
+ CompanyDAO companyDAO = newContext.getCompanyDao();
+ DepartmentDAO departmentDAO = newContext.getDepartmentDao();
Company company = companyDAO.create();
company.setName("Ma société");
Modified: trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/NaturalIdTest.java
===================================================================
--- trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/NaturalIdTest.java 2013-10-25 12:03:15 UTC (rev 2847)
+++ trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/NaturalIdTest.java 2013-10-25 14:48:13 UTC (rev 2848)
@@ -36,7 +36,7 @@
import org.nuiton.topia.TopiaTestDAOHelper;
import org.nuiton.topia.TopiaTestTopiaPersistenceContext;
import org.nuiton.topiatest.NaturalizedEntity;
-import org.nuiton.topiatest.NaturalizedEntityDao;
+import org.nuiton.topiatest.NaturalizedEntityDAO;
/**
* NaturalIdTest
@@ -61,7 +61,7 @@
log.debug("Test naturalId : create succesfull");
TopiaTestTopiaPersistenceContext persistenceContext = db.beginTransaction();
- NaturalizedEntityDao dao =
+ NaturalizedEntityDAO dao =
persistenceContext.getNaturalizedEntityDao();
// No exception will be thrown with the two properties
@@ -82,7 +82,7 @@
log.debug("Test naturalId : create failed");
TopiaTestTopiaPersistenceContext persistenceContext = db.beginTransaction();
- NaturalizedEntityDao dao =
+ NaturalizedEntityDAO dao =
persistenceContext.getNaturalizedEntityDao();
// Exception will be throw
@@ -108,7 +108,7 @@
TopiaTestTopiaPersistenceContext persistenceContext = db.beginTransaction();
- NaturalizedEntityDao dao =
+ NaturalizedEntityDAO dao =
persistenceContext.getNaturalizedEntityDao();
NaturalizedEntity entity =
@@ -131,7 +131,7 @@
TopiaTestTopiaPersistenceContext persistenceContext = db.beginTransaction();
- NaturalizedEntityDao dao =
+ NaturalizedEntityDAO dao =
persistenceContext.getNaturalizedEntityDao();
NaturalizedEntity entity =
@@ -149,7 +149,7 @@
TopiaTestTopiaPersistenceContext persistenceContext = db.beginTransaction();
- NaturalizedEntityDao dao =
+ NaturalizedEntityDAO dao =
persistenceContext.getNaturalizedEntityDao();
dao.createByNaturalId(5, "str");
Modified: trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/TopiaDAOTest.java
===================================================================
--- trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/TopiaDAOTest.java 2013-10-25 12:03:15 UTC (rev 2847)
+++ trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/TopiaDAOTest.java 2013-10-25 14:48:13 UTC (rev 2848)
@@ -25,7 +25,8 @@
package org.nuiton.topia.persistence;
-import com.google.common.collect.Lists;
+import java.util.List;
+
import org.hamcrest.CoreMatchers;
import org.junit.Assert;
import org.junit.Before;
@@ -35,9 +36,9 @@
import org.nuiton.topia.TopiaException;
import org.nuiton.topia.TopiaTestTopiaPersistenceContext;
import org.nuiton.topia.test.entities.Person;
-import org.nuiton.topia.test.entities.PersonDao;
+import org.nuiton.topia.test.entities.PersonDAO;
-import java.util.List;
+import com.google.common.collect.Lists;
/**
* Test on {@link TopiaDAO}.
@@ -55,7 +56,7 @@
protected TopiaTestTopiaPersistenceContext context;
- protected PersonDao dao;
+ protected PersonDAO dao;
@Before
public void setup() throws TopiaException {
Modified: trunk/topia-persistence/src/test/java/org/nuiton/topia/test/ano1882/DAOAbstractTransformerTest.java
===================================================================
--- trunk/topia-persistence/src/test/java/org/nuiton/topia/test/ano1882/DAOAbstractTransformerTest.java 2013-10-25 12:03:15 UTC (rev 2847)
+++ trunk/topia-persistence/src/test/java/org/nuiton/topia/test/ano1882/DAOAbstractTransformerTest.java 2013-10-25 14:48:13 UTC (rev 2848)
@@ -41,7 +41,7 @@
public void testAno1882() throws Exception {
TopiaTestTopiaPersistenceContext transaction = db.beginTransaction();
- FrenchCompanyDao dao = TopiaTestDAOHelper.getFrenchCompanyDAO(transaction);
+ FrenchCompanyDAO dao = TopiaTestDAOHelper.getFrenchCompanyDAO(transaction);
SIRETDAO siretDAO = TopiaTestDAOHelper.getSIRETDAO(transaction);
SIRET siret = siretDAO.create();
FrenchCompany entity =
Modified: trunk/topia-persistence/src/test/java/org/nuiton/topiatest/EnumTest.java
===================================================================
--- trunk/topia-persistence/src/test/java/org/nuiton/topiatest/EnumTest.java 2013-10-25 12:03:15 UTC (rev 2847)
+++ trunk/topia-persistence/src/test/java/org/nuiton/topiatest/EnumTest.java 2013-10-25 14:48:13 UTC (rev 2848)
@@ -53,7 +53,7 @@
public void storeEntityWithEnumValue() throws TopiaException {
TopiaTestTopiaPersistenceContext transaction = db.beginTransaction();
- PersonneDao dao = TopiaTestDAOHelper.getPersonneDAO(transaction);
+ PersonneDAO dao = TopiaTestDAOHelper.getPersonneDAO(transaction);
Personne personne = new PersonneImpl();
personne.setGender(Gender.FEMALE);
personne.setOtherGender(Gender.MALE);
Modified: trunk/topia-persistence/src/test/java/org/nuiton/topiatest/deletetest/DeleteEntityTest.java
===================================================================
--- trunk/topia-persistence/src/test/java/org/nuiton/topiatest/deletetest/DeleteEntityTest.java 2013-10-25 12:03:15 UTC (rev 2847)
+++ trunk/topia-persistence/src/test/java/org/nuiton/topiatest/deletetest/DeleteEntityTest.java 2013-10-25 14:48:13 UTC (rev 2848)
@@ -49,7 +49,7 @@
import org.nuiton.topia.TopiaTestTopiaPersistenceContext;
import org.nuiton.topiatest.Gender;
import org.nuiton.topiatest.Personne;
-import org.nuiton.topiatest.PersonneDao;
+import org.nuiton.topiatest.PersonneDAO;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
@@ -84,7 +84,7 @@
TopiaTestTopiaPersistenceContext transaction = db.beginTransaction();
log.debug("DAO : PersonneDAO");
- PersonneDao dao = TopiaTestDAOHelper.getPersonneDAO(transaction);
+ PersonneDAO dao = TopiaTestDAOHelper.getPersonneDAO(transaction);
log.debug("CREATE PERSONNE : Bob Marley");
Personne personne = dao.create(Personne.PROPERTY_NAME, "Bob Marley");
@@ -134,7 +134,7 @@
TopiaTestTopiaPersistenceContext transaction = db.beginTransaction();
- PersonneDao dao = TopiaTestDAOHelper.getPersonneDAO(transaction);
+ PersonneDAO dao = TopiaTestDAOHelper.getPersonneDAO(transaction);
log.debug("CREATE PERSONNE : Bob Marley");
Personne personne = dao.create(Personne.PROPERTY_NAME, "Bob Marley");
@@ -185,7 +185,7 @@
TopiaTestTopiaPersistenceContext transaction = db.beginTransaction();
- PersonneDao dao = TopiaTestDAOHelper.getPersonneDAO(transaction);
+ PersonneDAO dao = TopiaTestDAOHelper.getPersonneDAO(transaction);
Personne person = dao.newInstance();
Assert.assertNull(person.getTopiaId());
1
0
25 Oct '13
Author: bleny
Date: 2013-10-25 14:03:15 +0200 (Fri, 25 Oct 2013)
New Revision: 2847
Url: http://nuiton.org/projects/topia/repository/revisions/2847
Log:
extract contract TopiaDao, breking the build
Added:
trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/AbstractTopiaDao.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/LegacyTopiaDao.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDao.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaQueryBuilderAddCriteriaOrRunQueryStep.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaQueryBuilderAddCriteriaStep.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaQueryBuilderRunQueryStep.java
Removed:
trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/AbstractTopiaDAO.java
Modified:
trunk/topia-persistence/src/main/java/org/nuiton/topia/AbstractTopiaPersistenceContext.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/AbstractTopiaContext.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaFiresSupport.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaHibernateEventListener.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/TopiaGeneratorUtil.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAO.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAOImpl.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaEntityAbstract.java
trunk/topia-persistence/src/test/java/org/nuiton/topia/GeneratedPersonneTopiaDao.java
trunk/topia-persistence/src/test/java/org/nuiton/topia/TopiaJpaSupportTest.java
trunk/topia-persistence/src/test/java/org/nuiton/topia/framework/TopiaConnectionProviderTest.java
trunk/topia-persistence/src/test/java/org/nuiton/topia/framework/TopiaContextReplicateTest.java
trunk/topia-persistence/src/test/java/org/nuiton/topia/generator/TopiaTestCase.java
trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/EntityVisitorExportXmlTest.java
trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/NaturalIdTest.java
trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/TopiaDAOTest.java
trunk/topia-persistence/src/test/java/org/nuiton/topia/test/ano1882/DAOAbstractTransformerTest.java
trunk/topia-persistence/src/test/java/org/nuiton/topiatest/EnumTest.java
trunk/topia-persistence/src/test/java/org/nuiton/topiatest/deletetest/DeleteEntityTest.java
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/AbstractTopiaPersistenceContext.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/AbstractTopiaPersistenceContext.java 2013-10-17 16:14:18 UTC (rev 2846)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/AbstractTopiaPersistenceContext.java 2013-10-25 12:03:15 UTC (rev 2847)
@@ -35,7 +35,7 @@
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
import org.nuiton.topia.framework.TopiaFiresSupport;
-import org.nuiton.topia.persistence.AbstractTopiaDAO;
+import org.nuiton.topia.persistence.AbstractTopiaDao;
import org.nuiton.topia.persistence.TopiaDAO;
import org.nuiton.topia.persistence.TopiaEntity;
import org.nuiton.topia.persistence.TopiaIdFactory;
@@ -278,9 +278,9 @@
throw new TopiaException("unable to find DAO class " + daoClassName, e);
}
- if (dao instanceof AbstractTopiaDAO) {
- AbstractTopiaDAO abstractTopiaDAO = (AbstractTopiaDAO) dao;
- abstractTopiaDAO.init(hibernateSupport, jpaSupport, sqlSupport, listenableSupport, topiaIdFactory, firesSupport, this);
+ if (dao instanceof AbstractTopiaDao) {
+ AbstractTopiaDao abstractTopiaDao = (AbstractTopiaDao) dao;
+ abstractTopiaDao.init(hibernateSupport, jpaSupport, sqlSupport, listenableSupport, topiaIdFactory, firesSupport, this);
}
daoCache.put(entityClass, dao);
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/AbstractTopiaContext.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/AbstractTopiaContext.java 2013-10-17 16:14:18 UTC (rev 2846)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/AbstractTopiaContext.java 2013-10-25 12:03:15 UTC (rev 2847)
@@ -59,7 +59,7 @@
import org.nuiton.topia.event.TopiaSchemaListener;
import org.nuiton.topia.event.TopiaTransactionListener;
import org.nuiton.topia.event.TopiaTransactionVetoable;
-import org.nuiton.topia.persistence.AbstractTopiaDAO;
+import org.nuiton.topia.persistence.AbstractTopiaDao;
import org.nuiton.topia.persistence.DefaultTopiaIdFactory;
import org.nuiton.topia.persistence.TopiaDAO;
import org.nuiton.topia.persistence.TopiaDAOImpl;
@@ -751,8 +751,8 @@
if (result instanceof TopiaDAOImpl) { // backward compatibility
((TopiaDAOImpl)result).init(this, entityClass, getFiresSupport());
- } else if (result instanceof AbstractTopiaDAO) {
- ((AbstractTopiaDAO)result).init(this, this, this, this, getTopiaIdFactory(), getFiresSupport(), this);
+ } else if (result instanceof AbstractTopiaDao) {
+ ((AbstractTopiaDao)result).init(this, this, this, this, getTopiaIdFactory(), getFiresSupport(), this);
}
daoCache.put(entityClass, result);
}
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaFiresSupport.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaFiresSupport.java 2013-10-17 16:14:18 UTC (rev 2846)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaFiresSupport.java 2013-10-25 12:03:15 UTC (rev 2847)
@@ -54,7 +54,7 @@
import org.nuiton.topia.event.TopiaTransactionEvent;
import org.nuiton.topia.event.TopiaTransactionListener;
import org.nuiton.topia.event.TopiaTransactionVetoable;
-import org.nuiton.topia.persistence.AbstractTopiaDAO;
+import org.nuiton.topia.persistence.AbstractTopiaDao;
import org.nuiton.topia.persistence.TopiaEntity;
import org.nuiton.util.CategorisedListenerSet;
import org.nuiton.util.ListenerSet;
@@ -282,7 +282,7 @@
}
}
- public void fireOnPostLoad(AbstractTopiaDAO context,
+ public void fireOnPostLoad(AbstractTopiaDao context,
TopiaEntity entity, Object[] state) {
if (log.isDebugEnabled()) {
log.debug("fireOnPostLoad");
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaHibernateEventListener.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaHibernateEventListener.java 2013-10-17 16:14:18 UTC (rev 2846)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaHibernateEventListener.java 2013-10-25 12:03:15 UTC (rev 2847)
@@ -49,7 +49,7 @@
import org.hibernate.event.spi.SaveOrUpdateEventListener;
import org.nuiton.topia.TopiaDaoSupplier;
import org.nuiton.topia.TopiaException;
-import org.nuiton.topia.persistence.AbstractTopiaDAO;
+import org.nuiton.topia.persistence.AbstractTopiaDao;
import org.nuiton.topia.persistence.TopiaEntity;
import org.nuiton.topia.persistence.TopiaEntityContextable;
@@ -188,7 +188,7 @@
if (daoSupplier != null && event.getEntity() instanceof TopiaEntity) {
attachContext(event.getEntity(), daoSupplier);
TopiaEntity entity = (TopiaEntity) event.getEntity();
- AbstractTopiaDAO<? extends TopiaEntity> dao = (AbstractTopiaDAO) daoSupplier.getDao(entity.getClass());
+ AbstractTopiaDao<? extends TopiaEntity> dao = (AbstractTopiaDao) daoSupplier.getDao(entity.getClass());
dao.getTopiaFiresSupport().fireOnPostLoad(dao, (TopiaEntity) event.getEntity(), new Object[]{});
}
}
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 2013-10-17 16:14:18 UTC (rev 2846)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/TopiaGeneratorUtil.java 2013-10-25 12:03:15 UTC (rev 2847)
@@ -44,7 +44,7 @@
import org.nuiton.eugene.models.object.ObjectModelInterface;
import org.nuiton.eugene.models.object.ObjectModelOperation;
import org.nuiton.eugene.models.object.ObjectModelParameter;
-import org.nuiton.topia.persistence.AbstractTopiaDAO;
+import org.nuiton.topia.persistence.AbstractTopiaDao;
import org.nuiton.topia.persistence.TopiaDAOImpl;
import java.util.ArrayList;
@@ -1042,7 +1042,7 @@
if (StringUtils.isEmpty(daoImpl)) {
// use the default dao implementation of topia
- result = AbstractTopiaDAO.class;
+ result = AbstractTopiaDao.class;
} else {
try {
result = Class.forName(daoImpl);
Deleted: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/AbstractTopiaDAO.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/AbstractTopiaDAO.java 2013-10-17 16:14:18 UTC (rev 2846)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/AbstractTopiaDAO.java 2013-10-25 12:03:15 UTC (rev 2847)
@@ -1,1307 +0,0 @@
-/*
- * #%L
- * ToPIA :: Persistence
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2004 - 2010 CodeLutin
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>.
- * #L%
- */
-
-/* *
- * TopiaDAOAbstract.java
- *
- * Created: 31 déc. 2005 13:10:34
- *
- * @author poussin <poussin(a)codelutin.com>
- * @version $Revision$
- *
- * Last update: $Date$
- * by : $Author$
- */
-
-package org.nuiton.topia.persistence;
-
-import com.google.common.base.Optional;
-import com.google.common.base.Preconditions;
-import com.google.common.collect.Iterables;
-import com.google.common.collect.Iterators;
-import org.apache.commons.beanutils.PropertyUtils;
-import org.apache.commons.lang3.StringUtils;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.hibernate.HibernateException;
-import org.hibernate.metadata.ClassMetadata;
-import org.nuiton.topia.TopiaContext;
-import org.nuiton.topia.TopiaDaoSupplier;
-import org.nuiton.topia.TopiaException;
-import org.nuiton.topia.TopiaHibernateSupport;
-import org.nuiton.topia.TopiaJpaSupport;
-import org.nuiton.topia.TopiaListenableSupport;
-import org.nuiton.topia.TopiaSqlSupport;
-import org.nuiton.topia.event.TopiaEntityListener;
-import org.nuiton.topia.event.TopiaEntityVetoable;
-import org.nuiton.topia.framework.TopiaContextImplementor;
-import org.nuiton.topia.framework.TopiaFiresSupport;
-import org.nuiton.topia.framework.TopiaUtil;
-import org.nuiton.topia.persistence.pager.TopiaPagerBean;
-import org.nuiton.util.PagerBeanUtil;
-
-import java.lang.reflect.InvocationTargetException;
-import java.security.Permission;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.NoSuchElementException;
-import java.util.Set;
-
-/**
- * Cette classe permet d'avoir un ensemble de méthode implantée de façon
- * standard et plus spécifiquement pour Hibernate.
- * <p/>
- * Certains accès à Hibernate sont tout de même fait ici, car on a pris le choix
- * de se baser entièrement sur hibernate pour la persistence, et il est ainsi
- * possible d'accèder au meta information hibernate sur les classes lorque l'on
- * en a besoin.
- *
- * @param <E> le type de l'entite
- * @author bpoussin <poussin(a)codelutin.com>
- * @version $Id$
- */
-
-public abstract class AbstractTopiaDAO<E extends TopiaEntity> implements TopiaDAO<E> {
-
- /** to use log facility, just put in your code: log.info(\"...\"); */
- private static Log log = LogFactory.getLog(AbstractTopiaDAO.class);
-
- /**
- * Default batch size used to iterate on data.
- *
- * @since 2.6.14
- */
- protected int batchSize = 1000;
-
- protected TopiaHibernateSupport topiaHibernateSupport;
-
- protected TopiaJpaSupport topiaJpaSupport;
-
- protected TopiaSqlSupport topiaSqlSupport;
-
- protected TopiaListenableSupport topiaListenableSupport;
-
- protected TopiaIdFactory topiaIdFactory;
-
- protected TopiaFiresSupport topiaFiresSupport;
-
- protected TopiaDaoSupplier topiaDaoSupplier;
-
- public abstract TopiaEntityEnum getTopiaEntityEnum();
-
- public abstract Class<E> getEntityClass();
-
- public Iterator<E> iterator() {
-
- Iterator<E> iterator = new FindAllIterator<E, E>(
- this,
- getEntityClass(),
- batchSize,
- "FROM " + getTopiaEntityEnum().getImplementationFQN() + " ORDER BY id",
- Collections. <String, Object> emptyMap());
-
- return iterator;
-
- }
-
-// /**
-// * Retourne l'id de l'entity
-// *
-// * @param e l'entity
-// * @return l'id de l'entity ou null si pas trouvé
-// * @throws org.nuiton.topia.TopiaException Si une erreur survient durant la recherche
-// */
-// protected Serializable getId(E e) {
-// ClassMetadata meta = getClassMetadata();
-// String idPropName = meta.getIdentifierPropertyName();
-//
-// try {
-// Serializable result;
-// result = (Serializable) PropertyUtils.getSimpleProperty(e,
-// idPropName);
-// return result;
-// } catch (Exception eee) {
-// throw new TopiaException("Impossible de récuperer l'identifiant "
-// + idPropName + " de l'entite: " + e);
-// }
-// }
-
-// /**
-// * Retourne l'id de l'entity representer comme une map
-// *
-// * @param map l'entity en representation map
-// * @return l'id de l'entity ou null si pas trouvé
-// * @throws org.nuiton.topia.TopiaException Si une erreur survient durant la recherche
-// */
-// protected Serializable getId(Map map) {
-// try {
-// ClassMetadata meta = getClassMetadata();
-// String idPropName = meta.getIdentifierPropertyName();
-//
-// Serializable id = (Serializable) map.get(idPropName);
-// return id;
-// } catch (HibernateException eee) {
-// throw new TopiaException(eee);
-// }
-// }
-
- /**
- * When AbstractTopiaContext create the TopiaDAOHibernate, it must call this
- * method just after.
- */
- public void init(
- TopiaHibernateSupport topiaHibernateSupport,
- TopiaJpaSupport topiaJpaSupport,
- TopiaSqlSupport topiaSqlSupport,
- TopiaListenableSupport topiaListenableSupport,
- TopiaIdFactory topiaIdFactory,
- TopiaFiresSupport topiaFiresSupport,
- TopiaDaoSupplier topiaDaoSupplier) {
- log.debug("init dao for " + getEntityClass());
- this.topiaHibernateSupport = topiaHibernateSupport;
- this.topiaJpaSupport = topiaJpaSupport;
- this.topiaSqlSupport = topiaSqlSupport;
- this.topiaListenableSupport = topiaListenableSupport;
- this.topiaIdFactory = topiaIdFactory;
- this.topiaFiresSupport = topiaFiresSupport;
- this.topiaDaoSupplier = topiaDaoSupplier;
- }
-
- public TopiaFiresSupport getTopiaFiresSupport() {
- return topiaFiresSupport;
- }
-
- @Override
- public int getBatchSize() {
- return batchSize;
- }
-
- @Override
- public void setBatchSize(int batchSize) {
- this.batchSize = batchSize;
- }
-
- protected String createSimpleQuery() {
- return newFromClause(null);
- }
-
- protected String newFromClause(String alias) {
- String hql = "from " + getTopiaEntityEnum().getImplementationFQN();
- if (StringUtils.isNotBlank(alias)) {
- hql += " " + alias;
- }
- return hql;
- }
-
- @Deprecated
- public String createSimpleQuery(String alias) {
- return newFromClause(alias);
- }
-
- public E newInstance() {
- if (log.isTraceEnabled()) {
- log.trace("entityClass = " + getEntityClass());
- }
- Class<E> implementation = (Class<E>)
- getTopiaEntityEnum().getImplementation();
- try {
- E newInstance = implementation.newInstance();
- return newInstance;
- } catch (InstantiationException e) {
- throw new TopiaException(
- "Impossible de trouver ou d'instancier la classe "
- + implementation);
- } catch (IllegalAccessException e) {
- throw new TopiaException(
- "Impossible de trouver ou d'instancier la classe "
- + implementation);
- }
- }
-
- public void addTopiaEntityListener(TopiaEntityListener listener) {
- topiaListenableSupport.addTopiaEntityListener(getEntityClass(), listener);
- }
-
- public void addTopiaEntityVetoable(TopiaEntityVetoable vetoable) {
- topiaListenableSupport.addTopiaEntityVetoable(getEntityClass(), vetoable);
- }
-
- public void removeTopiaEntityListener(TopiaEntityListener listener) {
- topiaListenableSupport.removeTopiaEntityListener(getEntityClass(), listener);
- }
-
- public void removeTopiaEntityVetoable(TopiaEntityVetoable vetoable) {
- topiaListenableSupport.removeTopiaEntityVetoable(getEntityClass(), vetoable);
- }
-
- public E create(E entity) {
- try {
- // first set topiaId
- if (StringUtils.isBlank(entity.getTopiaId())) {
-
- // only set id if not already on
- String topiaId = topiaIdFactory.newTopiaId(getEntityClass(), entity);
- entity.setTopiaId(topiaId);
- }
-
- if (entity instanceof TopiaEntityContextable) {
- TopiaEntityContextable contextable = (TopiaEntityContextable) entity;
- contextable.setTopiaDAOSupplier(this.topiaDaoSupplier);
- }
-
- // save entity
- topiaHibernateSupport.getHibernateSession().save(entity);
- topiaFiresSupport.warnOnCreateEntity(entity);
- return entity;
- } catch (HibernateException eee) {
- throw new TopiaException(eee);
- }
- }
-
- public E create(String propertyName, Object propertyValue, Object... otherPropertyNamesAndValues) {
- Map<String, Object> properties =
- TopiaUtil.convertPropertiesArrayToMap(propertyName, propertyValue, otherPropertyNamesAndValues);
- E result = create(properties);
- return result;
- }
-
- @Override
- public E create(Object... propertyNamesAndValues) {
- Map<String, Object> properties = TopiaUtil.convertPropertiesArrayToMap(propertyNamesAndValues);
- E result = create(properties);
- return result;
- }
-
- public E create(Map<String, Object> properties) {
-
- E result = newInstance();
-
- try {
- for (Map.Entry<String, Object> e : properties.entrySet()) {
- String propertyName = e.getKey();
- Object value = e.getValue();
- PropertyUtils.setProperty(result, propertyName, value);
- }
- } catch (IllegalAccessException eee) {
- throw new IllegalArgumentException(
- "Can't put properties on new Object", eee);
- } catch (InvocationTargetException eee) {
- throw new IllegalArgumentException(
- "Can't put properties on new Object", eee);
- } catch (NoSuchMethodException eee) {
- throw new IllegalArgumentException(
- "Can't put properties on new Object", eee);
- }
-
- create(result);
-
- return result;
- }
-
- public E create() {
- E result = newInstance();
- create(result);
- return result;
- }
-
- public E update(E e) {
- try {
- topiaHibernateSupport.getHibernateSession().saveOrUpdate(e);
- topiaFiresSupport.warnOnUpdateEntity(e);
- return e;
- } catch (HibernateException eee) {
- throw new TopiaException(eee);
- }
- }
-
-
- public void delete(E e) {
- try {
- topiaHibernateSupport.getHibernateSession().delete(e);
- e.notifyDeleted();
- topiaFiresSupport.warnOnDeleteEntity(e);
- } catch (HibernateException eee) {
- throw new TopiaException(eee);
- }
- }
-
-
- public void deleteAll(Iterable<E> entities) {
- for (E entity : entities) {
- delete(entity);
- }
- }
-
- protected HqlAndParametersBuilder<E> newHqlAndParametersBuilder() {
- return new HqlAndParametersBuilder<E>(getEntityClass());
- }
-
- protected HqlAndParametersBuilder<E> getHqlForProperties(String propertyName,
- Object propertyValue,
- Object... otherPropertyNamesAndValues) {
- Map<String, Object> properties =
- TopiaUtil.convertPropertiesArrayToMap(propertyName, propertyValue, otherPropertyNamesAndValues);
- return getHqlForProperties(properties);
- }
-
- protected HqlAndParametersBuilder<E> getHqlForNoConstraint() {
- Map<String, Object> properties = Collections.emptyMap();
- return getHqlForProperties(properties);
- }
-
- protected HqlAndParametersBuilder<E> getHqlForProperties(Map<String, Object> properties) {
- HqlAndParametersBuilder<E> hqlAndParametersBuilder = newHqlAndParametersBuilder();
- for (Map.Entry<String, Object> property : properties.entrySet()) {
- hqlAndParametersBuilder.addEquals(property.getKey(), property.getValue());
- }
- return hqlAndParametersBuilder;
- }
-
- protected TopiaQueryBuilderRunQueryStep<E> forHql(String hql) {
- Map<String, Object> properties = Collections.emptyMap();
- return forHql(hql, properties);
- }
-
- protected TopiaQueryBuilderRunQueryStep<E> forHql(String hql, Map<String, Object> hqlParameters) {
- return new TopiaQueryBuilderRunQueryStep(this, hql, hqlParameters);
- }
-
- protected TopiaQueryBuilderRunQueryStep<E> forHql(String hql, String parameterName,
- Object parameterValue,
- Object... otherParameterNamesAndValues) {
- Map<String, Object> hqlParameters =
- TopiaUtil.convertPropertiesArrayToMap(parameterName, parameterValue, otherParameterNamesAndValues);
- return forHql(hql, hqlParameters);
- }
-
- public TopiaQueryBuilderCreateQueryStep<E> newQueryBuilder() {
- return new TopiaQueryBuilderCreateQueryStep(this);
- }
-
- // shortcuts for first step of builder
-
- public TopiaQueryBuilderAddCriteriaStep<E> forProperties(Map<String, Object> properties) {
- return newQueryBuilder().forProperties(properties);
- }
-
- public TopiaQueryBuilderAddCriteriaStep<E> forProperties(String propertyName,
- Object propertyValue,
- Object... otherPropertyNamesAndValues) {
- return newQueryBuilder().forProperties(propertyName, propertyValue, otherPropertyNamesAndValues);
- }
-
- public TopiaQueryBuilderAddCriteriaStep<E> forAll() {
- return newQueryBuilder().forAll();
- }
-
- public TopiaQueryBuilderRunQueryStep<E> forContains(String propertyName, Object propertyValue) {
- return forAll().addContains(propertyName, propertyValue).getNextStep();
- }
-
- public TopiaQueryBuilderRunQueryStep<E> forEquals(String propertyName, Object propertyValue) {
- return forAll().addEquals(propertyName, propertyValue).getNextStep();
- }
-
- public TopiaQueryBuilderRunQueryStep<E> forIn(String propertyName, Iterable<Object> propertyValues) {
- return forAll().addIn(propertyName, propertyValues).getNextStep();
- }
-
- public static class TopiaQueryBuilderCreateQueryStep<E extends TopiaEntity> {
-
- protected AbstractTopiaDAO<E> topiaDAO;
-
- protected TopiaQueryBuilderCreateQueryStep(AbstractTopiaDAO<E> topiaDAO) {
- this.topiaDAO = topiaDAO;
- }
-
- public TopiaQueryBuilderAddCriteriaStep<E> forProperties(Map<String, Object> properties) {
- HqlAndParametersBuilder<E> hqlAndParametersBuilder = topiaDAO.getHqlForProperties(properties);
- return getNextStep(hqlAndParametersBuilder);
- }
-
- public TopiaQueryBuilderAddCriteriaStep<E> forProperties(String propertyName,
- Object propertyValue,
- Object... otherPropertyNamesAndValues) {
- HqlAndParametersBuilder<E> hqlAndParametersBuilder = topiaDAO.getHqlForProperties(propertyName, propertyValue, otherPropertyNamesAndValues);
- return getNextStep(hqlAndParametersBuilder);
- }
-
- public TopiaQueryBuilderAddCriteriaStep<E> forAll() {
- HqlAndParametersBuilder<E> hqlAndParametersBuilder = topiaDAO.getHqlForNoConstraint();
- return getNextStep(hqlAndParametersBuilder);
- }
-
- protected TopiaQueryBuilderAddCriteriaStep<E> getNextStep(HqlAndParametersBuilder<E> hqlAndParametersBuilder) {
- TopiaQueryBuilderAddCriteriaStep nextStep = new TopiaQueryBuilderAddCriteriaStep(topiaDAO, hqlAndParametersBuilder);
- return nextStep;
- }
-
- // shortcuts to next step
-
- public TopiaQueryBuilderAddCriteriaStep<E> addEquals(String property, Object value) {
- return forAll().addEquals(property, value);
- }
-
- public TopiaQueryBuilderAddCriteriaStep<E> addIn(String property, Iterable<Object> values) {
- return forAll().addIn(property, values);
- }
-
- public TopiaQueryBuilderAddCriteriaStep<E> addContains(String property, Object value) {
- return forAll().addContains(property, value);
- }
-
- public TopiaQueryBuilderAddCriteriaStep<E> addNull(String property) {
- return forAll().addNull(property);
- }
-
- public TopiaQueryBuilderRunQueryStep<E> setOrderByArguments(Set<String> orderByArguments) {
- return forAll().setOrderByArguments(orderByArguments);
- }
-
- public TopiaQueryBuilderRunQueryStep<E> setOrderByArguments(String... orderByArguments) {
- return forAll().setOrderByArguments(orderByArguments);
- }
-
- }
-
- public static class TopiaQueryBuilderAddCriteriaStep<E extends TopiaEntity> {
-
- protected AbstractTopiaDAO<E> topiaDAO;
-
- protected HqlAndParametersBuilder<E> hqlAndParametersBuilder;
-
- protected boolean hasOrderByClause = false;
-
- protected TopiaQueryBuilderAddCriteriaStep(AbstractTopiaDAO<E> topiaDAO, HqlAndParametersBuilder<E> hqlAndParametersBuilder) {
- this.topiaDAO = topiaDAO;
- this.hqlAndParametersBuilder = hqlAndParametersBuilder;
- }
-
- public TopiaQueryBuilderRunQueryStep<E> setOrderByArguments(Set<String> orderByArguments) {
- hasOrderByClause = ! Iterables.isEmpty(orderByArguments);
- hqlAndParametersBuilder.setOrderByArguments(orderByArguments);
- return getNextStep();
- }
-
- public TopiaQueryBuilderRunQueryStep<E> setOrderByArguments(String... orderByArguments) {
- hqlAndParametersBuilder.setOrderByArguments(orderByArguments);
- return getNextStep();
- }
-
- public TopiaQueryBuilderAddCriteriaStep<E> addEquals(String property, Object value) {
- hqlAndParametersBuilder.addEquals(property, value);
- return this;
- }
-
- public TopiaQueryBuilderAddCriteriaStep<E> addIn(String property, Iterable<Object> values) {
- hqlAndParametersBuilder.addIn(property, values);
- return this;
- }
-
- public TopiaQueryBuilderAddCriteriaStep<E> addContains(String property, Object value) {
- hqlAndParametersBuilder.addContains(property, value);
- return this;
- }
-
- public TopiaQueryBuilderAddCriteriaStep<E> addNull(String property) {
- hqlAndParametersBuilder.addNull(property);
- return this;
- }
-
- public void addTopiaIdEquals(String property, String topiaId) {
- hqlAndParametersBuilder.addTopiaIdEquals(property, topiaId);
- }
-
- public void addTopiaIdIn(String property, Iterable<String> topiaIds) {
- hqlAndParametersBuilder.addTopiaIdIn(property, topiaIds);
- }
-
- // shortcuts to next step
-
- public boolean exists() {
- return getNextStep().exists();
- }
-
- public E findAnyOrNull() {
- return getNextStep().findAnyOrNull();
- }
-
- public E findUniqueOrNull() {
- return getNextStep().findUniqueOrNull();
- }
-
- public E findAny() {
- return getNextStep().findAny();
- }
-
- public E findUnique() {
- return getNextStep().findUnique();
- }
-
- public E findFirst() {
- return getNextStep().findFirst();
- }
-
- public E findFirstOrNull() {
- return getNextStep().findFirstOrNull();
- }
-
- public Optional<E> tryFindAny() {
- return getNextStep().tryFindAny();
- }
-
- public Optional<E> tryFindFirst() {
- return getNextStep().tryFindFirst();
- }
-
- public Optional<E> tryFindUnique() {
- return getNextStep().tryFindUnique();
- }
-
- public List<E> findAll() {
- return getNextStep().findAll();
- }
-
- public List<E> findAll(int startIndex, int endIndex) {
- return getNextStep().findAll(startIndex, endIndex);
- }
-
- public Iterable<E> findAllLazy() {
- return getNextStep().findAllLazy();
- }
-
- public long count() {
- return getNextStep().count();
- }
-
- public List<String> findAllIds(int startIndex, int endIndex) {
- return getNextStep().findAllIds(startIndex, endIndex);
- }
-
- public List<String> findAllIds() {
- return getNextStep().findAllIds();
- }
-
- protected TopiaQueryBuilderRunQueryStep<E> getNextStep() {
- String hql = hqlAndParametersBuilder.getHql();
- Map<String, Object> hqlParameters = hqlAndParametersBuilder.getHqlParameters();
- TopiaQueryBuilderRunQueryStep nextStep = new TopiaQueryBuilderRunQueryStep(topiaDAO, hql, hqlParameters);
- return nextStep;
- }
-
- }
-
- public static class TopiaQueryBuilderRunQueryStep<E extends TopiaEntity> {
-
- protected final String hql;
-
- protected final Map<String, Object> hqlParameters;
-
- protected AbstractTopiaDAO<E> topiaDAO;
-
- protected TopiaQueryBuilderRunQueryStep(AbstractTopiaDAO<E> topiaDAO, String hql, Map<String, Object> hqlParameters) {
- this.hql = hql;
- this.hqlParameters = hqlParameters;
- this.topiaDAO = topiaDAO;
- }
-
- public boolean exists() {
- return topiaDAO.exists(hql, hqlParameters);
- }
-
- public long count() {
- String hqlWithSelectClause = "select count(topiaId) " + hql;
- return topiaDAO.count(hqlWithSelectClause, hqlParameters);
- }
-
- public E findUnique() {
- return topiaDAO.findUnique(hql, hqlParameters);
- }
-
- public E findUniqueOrNull() {
- return topiaDAO.findUniqueOrNull(hql, hqlParameters);
- }
-
- public Optional<E> tryFindUnique() {
- return topiaDAO.tryFindUnique(hql, hqlParameters);
- }
-
- public E findFirst() {
- return topiaDAO.findFirst(hql, hqlParameters);
- }
-
- public E findFirstOrNull() {
- return topiaDAO.findFirstOrNull(hql, hqlParameters);
- }
-
- public Optional<E> tryFindFirst() {
- return topiaDAO.tryFindFirst(hql, hqlParameters);
- }
-
- public E findAny() {
- return topiaDAO.findAny(hql, hqlParameters);
- }
-
- public E findAnyOrNull() {
- return topiaDAO.findAnyOrNull(hql, hqlParameters);
- }
-
- public Optional<E> tryFindAny() {
- return topiaDAO.tryFindAny(hql, hqlParameters);
- }
-
- public List<E> findAll() {
- return topiaDAO.findAll(hql, hqlParameters);
- }
-
- public Iterable<E> findAllLazy() {
- return topiaDAO.findAllLazy(hql, hqlParameters);
- }
-
- public List<E> findAll(int startIndex, int endIndex) {
- return topiaDAO.findAll(hql, hqlParameters, startIndex, endIndex);
- }
-
- public List<String> findAllIds() {
- // XXX brendan 30/09/13 does this truely work ?
- String hqlWithSelectClause = "select topiaId " + hql;
- return topiaDAO.findAll(hqlWithSelectClause, hqlParameters, String.class);
- }
-
- public List<String> findAllIds(int startIndex, int endIndex) {
- // XXX brendan 30/09/13 does this truely work ?
- String hqlWithSelectClause = "select topiaId " + hql;
- return topiaDAO.findAll(hqlWithSelectClause, hqlParameters, String.class, startIndex, endIndex);
- }
-
- }
-
- protected boolean exists(String hql, Map<String, Object> hqlParameters) {
- List<E> entities = topiaJpaSupport.find(hql, 0, 0, hqlParameters);
- boolean exists = !entities.isEmpty();
- return exists;
- }
-
- protected long count(String hql, Map<String, Object> hqlParameters) {
- Preconditions.checkArgument(hql.toLowerCase().trim().startsWith("select count("));
- Long count = findUnique(hql, hqlParameters, Long.class);
- return count;
- }
-
- protected E findUnique(String hql, Map<String, Object> hqlParameters) {
- E unique = findUnique(hql, hqlParameters, getEntityClass());
- return unique;
- }
-
- protected E findUniqueOrNull(String hql, Map<String, Object> hqlParameters) {
- E uniqueOrNull = findUniqueOrNull(hql, hqlParameters, getEntityClass());
- return uniqueOrNull;
- }
-
- protected Optional<E> tryFindUnique(String hql, Map<String, Object> hqlParameters) {
- Optional<E> uniqueOrNull = tryFindUnique(hql, hqlParameters, getEntityClass());
- return uniqueOrNull;
- }
-
- protected E findFirst(String hql, Map<String, Object> hqlParameters) {
- E firstOrNull = findFirst(hql, hqlParameters, getEntityClass());
- return firstOrNull;
- }
-
- protected E findFirstOrNull(String hql, Map<String, Object> hqlParameters) {
- E anyOrNull = findFirstOrNull(hql, hqlParameters, getEntityClass());
- return anyOrNull;
- }
-
- protected Optional<E> tryFindFirst(String hql, Map<String, Object> hqlParameters) {
- Optional<E> anyOrNull = tryFindFirst(hql, hqlParameters, getEntityClass());
- return anyOrNull;
- }
-
- protected E findAny(String hql, Map<String, Object> hqlParameters) {
- E anyOrNull = findAny(hql, hqlParameters, getEntityClass());
- return anyOrNull;
- }
-
- protected E findAnyOrNull(String hql, Map<String, Object> hqlParameters) {
- E anyOrNull = findAnyOrNull(hql, hqlParameters, getEntityClass());
- return anyOrNull;
- }
-
- protected Optional<E> tryFindAny(String hql, Map<String, Object> hqlParameters) {
- Optional<E> anyOrNull = tryFindAny(hql, hqlParameters, getEntityClass());
- return anyOrNull;
- }
-
- protected <R> R findUnique(String hql, Map<String, Object> hqlParameters, Class<R> type) {
- R uniqueOrNull = findUniqueOrNull(hql, hqlParameters, type);
- if (uniqueOrNull == null) {
- // TODO brendan 30/09/13 throw another exception if no result
- throw new TopiaException("query " + hql + " returns no elements");
- }
- return uniqueOrNull;
- }
-
- protected <R> Optional<R> tryFindUnique(String hql, Map<String, Object> hqlParameters, Class<R> type) {
- R uniqueOrNull = findUniqueOrNull(hql, hqlParameters, type);
- return Optional.fromNullable(uniqueOrNull);
- }
-
- protected <R> R findUniqueOrNull(String hql, Map<String, Object> hqlParameters, Class<R> type) {
- List<R> results = findAll(hql, hqlParameters, type, 0, 1);
- // If there is more than 1 result, throw an exception
- if (results.size() > 1) {
- String message = String.format(
- "The query '%s' returns more than 1 unique result", hql);
- // TODO AThimel 02/08/13 Throw another exception if more than 1 result is found
- throw new TopiaException(message);
- }
- // otherwise return the first one, or null
- R uniqueOrNull = Iterables.getOnlyElement(results, null);
- return uniqueOrNull;
- }
-
- protected <R> R findFirst(String hql, Map<String, Object> hqlParameters, Class<R> type) {
- R firstOrNull = findFirstOrNull(hql, hqlParameters, type);
- if (firstOrNull == null) {
- // TODO brendan 30/09/13 throw another exception if no result
- throw new TopiaException("query " + hql + " returns no elements");
- }
- return firstOrNull;
- }
-
- protected <R> Optional<R> tryFindFirst(String hql, Map<String, Object> hqlParameters, Class<R> type) {
- R firstOrNull = findFirstOrNull(hql, hqlParameters, type);
- return Optional.fromNullable(firstOrNull);
- }
-
- protected <R> R findFirstOrNull(String hql, Map<String, Object> hqlParameters, Class<R> type) {
- Preconditions.checkArgument(hql.toLowerCase().contains("order by"));
- R anyOrNull = findAnyOrNull(hql, hqlParameters, type);
- return anyOrNull;
- }
-
- protected <R> R findAny(String hql, Map<String, Object> hqlParameters, Class<R> type) {
- R anyOrNull = findAnyOrNull(hql, hqlParameters, type);
- if (anyOrNull == null) {
- // TODO brendan 30/09/13 throw another exception if no result
- throw new TopiaException("query " + hql + " returns no elements");
- }
- return anyOrNull;
- }
-
- protected <R> Optional<R> tryFindAny(String hql, Map<String, Object> hqlParameters, Class<R> type) {
- R anyOrNull = findAnyOrNull(hql, hqlParameters, type);
- return Optional.fromNullable(anyOrNull);
- }
-
- protected <R> R findAnyOrNull(String hql, Map<String, Object> hqlParameters, Class<R> type) {
- Preconditions.checkNotNull(hql);
- Preconditions.checkNotNull(hqlParameters);
- List<R> results = findAll(hql, hqlParameters, type, 0, 0);
- R anyOrNull = Iterables.getOnlyElement(results, null);
- return anyOrNull;
- }
-
- protected List<E> findAll(String hql, Map<String, Object> hqlParameters) {
- Preconditions.checkNotNull(hql);
- Preconditions.checkNotNull(hqlParameters);
- List<E> all = topiaJpaSupport.findAll(hql, hqlParameters);
- return all;
- }
-
- protected <R> List<R> findAll(String hql, Map<String, Object> hqlParameters, Class<R> type) {
- Preconditions.checkNotNull(hql);
- Preconditions.checkNotNull(hqlParameters);
- Preconditions.checkNotNull(type);
- List<R> all = topiaJpaSupport.findAll(hql, hqlParameters);
- return all;
- }
-
- protected List<E> findAll(String hql, Map<String, Object> hqlParameters, int startIndex, int endIndex) {
- Preconditions.checkNotNull(hql);
- Preconditions.checkNotNull(hqlParameters);
- List<E> all = topiaJpaSupport.find(hql, startIndex, endIndex, hqlParameters);
- return all;
- }
-
- protected <R> List<R> findAll(String hql, Map<String, Object> hqlParameters, Class<R> type, int startIndex, int endIndex) {
- Preconditions.checkNotNull(hql);
- Preconditions.checkNotNull(hqlParameters);
- Preconditions.checkNotNull(type);
- List<R> all = topiaJpaSupport.find(hql, startIndex, endIndex, hqlParameters);
- return all;
- }
-
- protected <R> List<R> findAll(String hql, Map<String, Object> hqlParameters, Class<R> type, TopiaPagerBean pager) {
- Preconditions.checkNotNull(hql);
- Preconditions.checkNotNull(hqlParameters);
- Preconditions.checkNotNull(type);
- Preconditions.checkNotNull(pager);
-
- if (StringUtils.isNotBlank(pager.getSortColumn())) {
- hql += " order by " + pager.getSortColumn();
- if (!pager.isSortAscendant()) {
- hql += " desc";
- }
- }
-
- List<R> result = topiaJpaSupport.find(
- hql,
- (int) pager.getRecordStartIndex(),
- (int) pager.getRecordEndIndex() - 1,
- hqlParameters);
-
- return result;
-
- }
-
- protected Iterable<E> findAllLazy(String hql, Map<String, Object> hqlParameters) {
-
- Preconditions.checkNotNull(hql);
- Preconditions.checkNotNull(hqlParameters);
-
- final Iterator<E> iterator = new FindAllIterator<E, E>(this,
- getEntityClass(),
- batchSize,
- hql,
- hqlParameters);
- Iterable<E> result = new Iterable<E>() {
- @Override
- public Iterator<E> iterator() {
- return iterator;
- }
- };
- return result;
- }
-
- protected <R> Iterable<R> findAllLazy(String hql, Map<String, Object> hqlParameters, Class<R> type) {
-
- Preconditions.checkNotNull(hql);
- Preconditions.checkNotNull(hqlParameters);
- Preconditions.checkNotNull(type);
-
- final Iterator<R> iterator = new FindAllIterator<E, R>(this,
- type,
- batchSize,
- hql,
- hqlParameters);
- Iterable<R> result = new Iterable<R>() {
- @Override
- public Iterator<R> iterator() {
- return iterator;
- }
- };
- return result;
- }
-
- public TopiaQueryBuilderRunQueryStep<E> forTopiaId(String topiaId) {
- Preconditions.checkNotNull(topiaId, "given topiaId is null");
- return forEquals(TopiaEntity.PROPERTY_TOPIA_ID, topiaId);
- }
-
- public TopiaQueryBuilderRunQueryStep<E> forTopiaIds(Iterable<String> topiaIds) {
- Preconditions.checkNotNull(topiaIds, "given topiaIds is null");
- return forIn(TopiaEntity.PROPERTY_TOPIA_ID, (Iterable) topiaIds);
- }
-
- @Deprecated
- public E findByTopiaId(String id) {
- return forTopiaId(id).findUniqueOrNull();
- }
-
- @Deprecated
- public E findByProperty(String propertyName, Object value) {
- return newQueryBuilder().forProperties(propertyName, value).findAnyOrNull();
- }
-
- @Override
- public <R> R findByQuery(Class<R> type, String hql, Object... propertyNamesAndValues) {
- Map<String, Object> properties = TopiaUtil.convertPropertiesArrayToMap(propertyNamesAndValues);
- return findAny(hql, properties, type);
- }
-
- @Override
- public E findByPrimaryKey(Map<String, Object> keys) {
- return newQueryBuilder().forProperties(keys).findUniqueOrNull();
- }
-
- @Override
- @Deprecated
- public E findByPrimaryKey(Object... propertyNamesAndValues) {
- Map<String, Object> properties = TopiaUtil.convertPropertiesArrayToMap(propertyNamesAndValues);
- E byPrimaryKey = findByPrimaryKey(properties);
- return byPrimaryKey;
- }
-
- @Override
- public List<E> findAllWithOrder(String... propertyNames) {
- return newQueryBuilder().forAll().setOrderByArguments(propertyNames).findAll();
- }
-
- @Override
- public <R> List<R> findAllByQuery(Class<R> type, String hql, Object... propertyNamesAndValues) {
- Map<String, Object> hqlParameters = TopiaUtil.convertPropertiesArrayToMap(propertyNamesAndValues);
- List<R> all = findAll(hql, hqlParameters, type);
- return all;
- }
-
- @Deprecated
- public E findByProperties(String propertyName, Object value,
- Object... propertyNamesAndValues) {
- return newQueryBuilder().forProperties(propertyName, value, propertyNamesAndValues).findUniqueOrNull();
- }
-
- @Deprecated
- public E findByProperties(Map<String, Object> properties) {
- return newQueryBuilder().forProperties(properties).findUniqueOrNull();
- }
-
- public List<E> findAll() {
- return newQueryBuilder().forAll().findAll();
- }
-
- public List<String> findAllIds() {
- List<String> find = newQueryBuilder().forAll().findAllIds();
- return find;
- }
-
- @Deprecated
- public List<E> findAllByProperty(String propertyName, Object value) {
- List<E> all = newQueryBuilder().forProperties(propertyName, value).findAll();
- return all;
- }
-
- @Deprecated
- public List<E> findAllByProperties(String propertyName, Object value, Object... propertyNamesAndValues) {
- List<E> all = newQueryBuilder().forProperties(propertyName, value, propertyNamesAndValues).findAll();
- return all;
- }
-
- @Deprecated
- public List<E> findAllByProperties(Map<String, Object> properties) {
- List<E> all = newQueryBuilder().forProperties(properties).findAll();
- return all;
- }
-
-
- public E findContains(String propertyName, Object value) {
- E find = newQueryBuilder().forAll().addContains(propertyName, value).findAny();
- return find;
- }
-
-
- public List<E> findAllContains(String propertyName,
- Object value) {
- List<E> find = newQueryBuilder().forAll().addContains(propertyName, value).findAll();
- return find;
- }
-
- @Deprecated
- public boolean existByTopiaId(String topiaId) {
- boolean exists = forTopiaId(topiaId).exists();
- return exists;
- }
-
- @Deprecated
- public boolean existByProperties(String propertyName, Object propertyValue,
- Object... propertyNamesAndValues) {
- boolean exists = newQueryBuilder().forProperties(propertyName, propertyValue, propertyNamesAndValues).exists();
- return exists;
- }
-
- public long count() {
- long count = newQueryBuilder().forAll().count();
- return count;
- }
-
-
- @Deprecated
- public boolean existsByQuery(String hql, Object... propertyNamesAndValues) {
- Map<String, Object> hqlParameters = TopiaUtil.convertPropertiesArrayToMap(propertyNamesAndValues);
- boolean exists = exists(hql, hqlParameters);
- return exists;
- }
-
-
- @Deprecated
- public long countByQuery(String hql,
- Object... propertyNamesAndValues) {
-
- Preconditions.checkNotNull(StringUtils.isNotBlank(hql));
- Preconditions.checkArgument(hql.toUpperCase().trim().startsWith("SELECT COUNT("));
- Map<String, Object> hqlParameters = TopiaUtil.convertPropertiesArrayToMap(propertyNamesAndValues);
- long count = forHql(hql, hqlParameters).count();
- return count;
- }
-
-
- @Deprecated
- public E findByQuery(String hql,
- Object... propertyNamesAndValues) {
- Map<String, Object> hqlParameters = TopiaUtil.convertPropertiesArrayToMap(propertyNamesAndValues);
- E uniqueOrNull = forHql(hql, hqlParameters).findUniqueOrNull();
- return uniqueOrNull;
- }
-
-
- @Deprecated
- public List<E> findAllByQuery(String hql,
- Object... propertyNamesAndValues) {
- Map<String, Object> hqlParameters = TopiaUtil.convertPropertiesArrayToMap(propertyNamesAndValues);
- List<E> all = forHql(hql, hqlParameters).findAll();
- return all;
- }
-
-
- @Deprecated
- public Iterable<E> findAllLazyByQuery(String hql,
- Object... propertyNamesAndValues) {
- Map<String, Object> hqlParameters = TopiaUtil.convertPropertiesArrayToMap(propertyNamesAndValues);
- Iterable<E> result = findAllLazy(hql, hqlParameters);
- return result;
- }
-
-
- @Deprecated
- public <R> Iterable<R> findAllLazyByQuery(Class<R> type,
- String hql,
- Object... propertyNamesAndValues) {
- Map<String, Object> hqlParameters = TopiaUtil.convertPropertiesArrayToMap(propertyNamesAndValues);
- Iterable<R> result = findAllLazy(hql, hqlParameters, type);
- return result;
- }
-
-
- @Deprecated
- public Iterable<E> findAllLazyByQuery(int batchSize,
- String hql,
- Object... propertyNamesAndValues) {
- return findAllLazyByQuery(getEntityClass(), batchSize, hql, propertyNamesAndValues);
- }
-
-
- /**
- * @deprecated use {@link #findAllLazy(String, java.util.Map, Class)}
- */
- @Deprecated
- public <R> Iterable<R> findAllLazyByQuery(Class<R> type,
- int batchSize,
- String hql,
- Object... propertyNamesAndValues) {
- setBatchSize(batchSize);
- Map<String, Object> hqlParameters = TopiaUtil.convertPropertiesArrayToMap(propertyNamesAndValues);
- Iterable<R> allLazy = findAllLazy(hql, hqlParameters, type);
- return allLazy;
- }
-
-
- @Deprecated
- public <R> List<R> findAllByQueryWithBound(Class<R> type,
- String hql,
- int startIndex,
- int endIndex,
- Object... propertyNamesAndValues) {
- Map<String, Object> hqlParameters = TopiaUtil.convertPropertiesArrayToMap(propertyNamesAndValues);
- List<R> all = findAll(hql, hqlParameters, type, startIndex, endIndex);
- return all;
- }
-
-
- @Deprecated
- public List<E> findAllByQueryWithBound(String hql,
- int startIndex,
- int endIndex,
- Object... propertyNamesAndValues) {
- List<E> result = findAllByQueryWithBound(getEntityClass(),
- hql,
- startIndex,
- endIndex,
- propertyNamesAndValues);
- return result;
- }
-
-
- @Deprecated
- public <R> List<R> findAllByQueryAndPager(Class<R> type,
- String hql,
- TopiaPagerBean pager,
- Object... propertyNamesAndValues) {
- Preconditions.checkNotNull(pager);
- Preconditions.checkNotNull(hql);
-
- if (StringUtils.isNotBlank(pager.getSortColumn())) {
- hql += " ORDER BY " + pager.getSortColumn();
- if (!pager.isSortAscendant()) {
- hql += " DESC";
- }
- }
- List<R> result = findAllByQueryWithBound(type, hql,
- (int) pager.getRecordStartIndex(),
- (int) pager.getRecordEndIndex() - 1,
- propertyNamesAndValues);
- return result;
- }
-
-
- @Deprecated
- public List<E> findAllByQueryAndPager(String hql,
- TopiaPagerBean pager,
- Object... propertyNamesAndValues) {
-
- List<E> result = findAllByQueryAndPager(getEntityClass(),
- hql,
- pager,
- propertyNamesAndValues);
- return result;
- }
-
-
- public void computeAndAddRecordsToPager(String hql,
- TopiaPagerBean pager,
- Object... propertyNamesAndValues) {
-
- long records = countByQuery(hql, propertyNamesAndValues);
-
- pager.setRecords(records);
- PagerBeanUtil.computeRecordIndexesAndPagesNumber(pager);
- }
-
- /**
- * package locale method because this is hibernate specific method and
- * we don't want expose it.
- *
- * @return the meta-data of the entity
- * @throws org.nuiton.topia.TopiaException if any pb
- */
- protected ClassMetadata getClassMetadata() {
- ClassMetadata meta = topiaHibernateSupport.getHibernateFactory()
- .getClassMetadata(getEntityClass());
- if (meta == null) {
- meta = topiaHibernateSupport.getHibernateFactory().getClassMetadata(
- getTopiaEntityEnum().getImplementationFQN());
- }
- return meta;
- }
-
- public static class FindAllIterator<E extends TopiaEntity, R> implements Iterator<R> {
-
- protected Iterator<R> data;
-
- protected final AbstractTopiaDAO<E> dao;
-
- protected final Class<R> type;
-
- protected final String hql;
-
- protected final Map<String, Object> params;
-
- protected TopiaPagerBean pager;
-
- public FindAllIterator(AbstractTopiaDAO<E> dao,
- Class<R> type,
- int batchSize,
- String hql,
- Map<String, Object> params) {
- this.dao = dao;
- this.type = type;
- this.hql = hql;
- this.params = params;
-
- String hql2 = hql.toLowerCase();
- int i = hql2.indexOf("order by");
- if (i == -1) {
- throw new IllegalStateException(
- "must have a *order by* in hql, " +
- "but did not find it in " + hql);
- }
-
- // get the count (removing the order-by)
- long count2 = dao.count("SELECT COUNT(*) " +
- hql.substring(0, i), params);
- pager = new TopiaPagerBean();
- pager.setRecords(count2);
- pager.setPageSize(batchSize);
- PagerBeanUtil.computeRecordIndexesAndPagesNumber(pager);
-
- // empty iterator (will be changed at first next call)
- data = Iterators.emptyIterator();
- }
-
-
- public boolean hasNext() {
- boolean result = data.hasNext() || // no more data
- pager.getPageIndex() < pager.getPagesNumber();
- return result;
- }
-
-
- public R next() {
- if (!hasNext()) {
- throw new NoSuchElementException();
- }
-
- if (!data.hasNext()) {
-
- // must load iterator
-
- // increments page index
- pager.setPageIndex(pager.getPageIndex() + 1);
- PagerBeanUtil.computeRecordIndexesAndPagesNumber(pager);
-
- // load new window of data
- data = dao.findAll(hql, params, type, pager).iterator();
-
- }
-
- R next = data.next();
- return next;
- }
-
-
- public void remove() {
- throw new UnsupportedOperationException(
- "This iterator does not support remove operation.");
- }
- }
-
- @Override
- public List<Permission> getRequestPermission(String topiaId, int actions) {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public TopiaContextImplementor getContext() {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public TopiaContext getTopiaContext() {
- throw new UnsupportedOperationException();
- }
-
-} //TopiaDAOImpl
Copied: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/AbstractTopiaDao.java (from rev 2846, trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/AbstractTopiaDAO.java)
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/AbstractTopiaDao.java (rev 0)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/AbstractTopiaDao.java 2013-10-25 12:03:15 UTC (rev 2847)
@@ -0,0 +1,1000 @@
+/*
+ * #%L
+ * ToPIA :: Persistence
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2004 - 2010 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
+
+/* *
+ * TopiaDAOAbstract.java
+ *
+ * Created: 31 déc. 2005 13:10:34
+ *
+ * @author poussin <poussin(a)codelutin.com>
+ * @version $Revision$
+ *
+ * Last update: $Date$
+ * by : $Author$
+ */
+
+package org.nuiton.topia.persistence;
+
+import com.google.common.base.Optional;
+import com.google.common.base.Preconditions;
+import com.google.common.collect.Iterables;
+import com.google.common.collect.Iterators;
+import org.apache.commons.beanutils.PropertyUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.hibernate.HibernateException;
+import org.hibernate.metadata.ClassMetadata;
+import org.nuiton.topia.TopiaDaoSupplier;
+import org.nuiton.topia.TopiaException;
+import org.nuiton.topia.TopiaHibernateSupport;
+import org.nuiton.topia.TopiaJpaSupport;
+import org.nuiton.topia.TopiaListenableSupport;
+import org.nuiton.topia.TopiaSqlSupport;
+import org.nuiton.topia.event.TopiaEntityListener;
+import org.nuiton.topia.event.TopiaEntityVetoable;
+import org.nuiton.topia.framework.TopiaFiresSupport;
+import org.nuiton.topia.framework.TopiaUtil;
+import org.nuiton.topia.persistence.pager.TopiaPagerBean;
+import org.nuiton.util.PagerBeanUtil;
+
+import java.lang.reflect.InvocationTargetException;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.NoSuchElementException;
+import java.util.Set;
+
+/**
+ * Cette classe permet d'avoir un ensemble de méthode implantée de façon
+ * standard et plus spécifiquement pour Hibernate.
+ * <p/>
+ * Certains accès à Hibernate sont tout de même fait ici, car on a pris le choix
+ * de se baser entièrement sur hibernate pour la persistence, et il est ainsi
+ * possible d'accèder au meta information hibernate sur les classes lorque l'on
+ * en a besoin.
+ *
+ * @param <E> le type de l'entite
+ * @author bpoussin <poussin(a)codelutin.com>
+ * @version $Id$
+ */
+public abstract class AbstractTopiaDao<E extends TopiaEntity> extends LegacyTopiaDao<E> {
+
+ /** to use log facility, just put in your code: log.info(\"...\"); */
+ private static Log log = LogFactory.getLog(AbstractTopiaDao.class);
+
+ /**
+ * Default batch size used to iterate on data.
+ *
+ * @since 2.6.14
+ */
+ protected int batchSize = 1000;
+
+ protected TopiaHibernateSupport topiaHibernateSupport;
+
+ protected TopiaJpaSupport topiaJpaSupport;
+
+ protected TopiaSqlSupport topiaSqlSupport;
+
+ protected TopiaListenableSupport topiaListenableSupport;
+
+ protected TopiaIdFactory topiaIdFactory;
+
+ protected TopiaFiresSupport topiaFiresSupport;
+
+ protected TopiaDaoSupplier topiaDaoSupplier;
+
+ public abstract TopiaEntityEnum getTopiaEntityEnum();
+
+ public abstract Class<E> getEntityClass();
+
+ /**
+ * When AbstractTopiaContext create the TopiaDAOHibernate, it must call this
+ * method just after.
+ */
+ public void init(
+ TopiaHibernateSupport topiaHibernateSupport,
+ TopiaJpaSupport topiaJpaSupport,
+ TopiaSqlSupport topiaSqlSupport,
+ TopiaListenableSupport topiaListenableSupport,
+ TopiaIdFactory topiaIdFactory,
+ TopiaFiresSupport topiaFiresSupport,
+ TopiaDaoSupplier topiaDaoSupplier) {
+ if (log.isDebugEnabled()) {
+ log.debug("init dao for " + getEntityClass());
+ }
+ this.topiaHibernateSupport = topiaHibernateSupport;
+ this.topiaJpaSupport = topiaJpaSupport;
+ this.topiaSqlSupport = topiaSqlSupport;
+ this.topiaListenableSupport = topiaListenableSupport;
+ this.topiaIdFactory = topiaIdFactory;
+ this.topiaFiresSupport = topiaFiresSupport;
+ this.topiaDaoSupplier = topiaDaoSupplier;
+ }
+
+ public TopiaFiresSupport getTopiaFiresSupport() {
+ return topiaFiresSupport;
+ }
+
+ @Override
+ public int getBatchSize() {
+ return batchSize;
+ }
+
+ @Override
+ public void setBatchSize(int batchSize) {
+ this.batchSize = batchSize;
+ }
+
+ protected String newFromClause(String alias) {
+ String hql = "from " + getTopiaEntityEnum().getImplementationFQN();
+ if (StringUtils.isNotBlank(alias)) {
+ hql += " " + alias;
+ }
+ return hql;
+ }
+
+ @Override
+ public E newInstance() {
+ if (log.isTraceEnabled()) {
+ log.trace("entityClass = " + getEntityClass());
+ }
+ Class<E> implementation = (Class<E>)
+ getTopiaEntityEnum().getImplementation();
+ try {
+ E newInstance = implementation.newInstance();
+ return newInstance;
+ } catch (InstantiationException e) {
+ throw new TopiaException(
+ "Impossible de trouver ou d'instancier la classe "
+ + implementation);
+ } catch (IllegalAccessException e) {
+ throw new TopiaException(
+ "Impossible de trouver ou d'instancier la classe "
+ + implementation);
+ }
+ }
+
+ @Override
+ public void addTopiaEntityListener(TopiaEntityListener listener) {
+ topiaListenableSupport.addTopiaEntityListener(getEntityClass(), listener);
+ }
+
+ @Override
+ public void addTopiaEntityVetoable(TopiaEntityVetoable vetoable) {
+ topiaListenableSupport.addTopiaEntityVetoable(getEntityClass(), vetoable);
+ }
+
+ @Override
+ public void removeTopiaEntityListener(TopiaEntityListener listener) {
+ topiaListenableSupport.removeTopiaEntityListener(getEntityClass(), listener);
+ }
+
+ @Override
+ public void removeTopiaEntityVetoable(TopiaEntityVetoable vetoable) {
+ topiaListenableSupport.removeTopiaEntityVetoable(getEntityClass(), vetoable);
+ }
+
+ @Override
+ public E create(E entity) {
+ try {
+ // first set topiaId
+ if (StringUtils.isBlank(entity.getTopiaId())) {
+
+ // only set id if not already on
+ String topiaId = topiaIdFactory.newTopiaId(getEntityClass(), entity);
+ entity.setTopiaId(topiaId);
+ }
+
+ if (entity instanceof TopiaEntityContextable) {
+ TopiaEntityContextable contextable = (TopiaEntityContextable) entity;
+ contextable.setTopiaDAOSupplier(this.topiaDaoSupplier);
+ }
+
+ // save entity
+ topiaHibernateSupport.getHibernateSession().save(entity);
+ topiaFiresSupport.warnOnCreateEntity(entity);
+ return entity;
+ } catch (HibernateException eee) {
+ throw new TopiaException(eee);
+ }
+ }
+
+ @Override
+ public E create(String propertyName, Object propertyValue, Object... otherPropertyNamesAndValues) {
+ Map<String, Object> properties =
+ TopiaUtil.convertPropertiesArrayToMap(propertyName, propertyValue, otherPropertyNamesAndValues);
+ E result = create(properties);
+ return result;
+ }
+
+ @Override
+ public E create(Map<String, Object> properties) {
+
+ E result = newInstance();
+
+ try {
+ for (Map.Entry<String, Object> e : properties.entrySet()) {
+ String propertyName = e.getKey();
+ Object value = e.getValue();
+ PropertyUtils.setProperty(result, propertyName, value);
+ }
+ } catch (IllegalAccessException eee) {
+ throw new IllegalArgumentException(
+ "Can't put properties on new Object", eee);
+ } catch (InvocationTargetException eee) {
+ throw new IllegalArgumentException(
+ "Can't put properties on new Object", eee);
+ } catch (NoSuchMethodException eee) {
+ throw new IllegalArgumentException(
+ "Can't put properties on new Object", eee);
+ }
+
+ create(result);
+
+ return result;
+ }
+
+ @Override
+ public E create() {
+ E result = newInstance();
+ create(result);
+ return result;
+ }
+
+ @Override
+ public Iterable<E> createAll(Iterable<E> entities) {
+ for (E entity : entities) {
+ create(entity);
+ }
+ return entities;
+ }
+
+ @Override
+ public E update(E entity) {
+ try {
+ topiaHibernateSupport.getHibernateSession().saveOrUpdate(entity);
+ topiaFiresSupport.warnOnUpdateEntity(entity);
+ return entity;
+ } catch (HibernateException eee) {
+ throw new TopiaException(eee);
+ }
+ }
+
+ @Override
+ public Iterable<E> updateAll(Iterable<E> entities) {
+ for (E entity : entities) {
+ update(entity);
+ }
+ return entities;
+ }
+
+ @Override
+ public void delete(E entity) {
+ try {
+ topiaHibernateSupport.getHibernateSession().delete(entity);
+ entity.notifyDeleted();
+ topiaFiresSupport.warnOnDeleteEntity(entity);
+ } catch (HibernateException eee) {
+ throw new TopiaException(eee);
+ }
+ }
+
+ @Override
+ public void deleteAll(Iterable<E> entities) {
+ for (E entity : entities) {
+ delete(entity);
+ }
+ }
+
+ protected HqlAndParametersBuilder<E> newHqlAndParametersBuilder() {
+ return new HqlAndParametersBuilder<E>(getEntityClass());
+ }
+
+ protected HqlAndParametersBuilder<E> getHqlForProperties(String propertyName,
+ Object propertyValue,
+ Object... otherPropertyNamesAndValues) {
+ Map<String, Object> properties =
+ TopiaUtil.convertPropertiesArrayToMap(propertyName, propertyValue, otherPropertyNamesAndValues);
+ return getHqlForProperties(properties);
+ }
+
+ protected HqlAndParametersBuilder<E> getHqlForNoConstraint() {
+ Map<String, Object> properties = Collections.emptyMap();
+ return getHqlForProperties(properties);
+ }
+
+ protected HqlAndParametersBuilder<E> getHqlForProperties(Map<String, Object> properties) {
+ HqlAndParametersBuilder<E> hqlAndParametersBuilder = newHqlAndParametersBuilder();
+ for (Map.Entry<String, Object> property : properties.entrySet()) {
+ hqlAndParametersBuilder.addEquals(property.getKey(), property.getValue());
+ }
+ return hqlAndParametersBuilder;
+ }
+
+ protected TopiaQueryBuilderRunQueryStep<E> forHql(String hql) {
+ Map<String, Object> properties = Collections.emptyMap();
+ return forHql(hql, properties);
+ }
+
+ protected TopiaQueryBuilderRunQueryStep<E> forHql(String hql, Map<String, Object> hqlParameters) {
+ return new TopiaQueryBuilderRunQueryStep(this, hql, hqlParameters);
+ }
+
+ protected TopiaQueryBuilderRunQueryStep<E> forHql(String hql, String parameterName,
+ Object parameterValue,
+ Object... otherParameterNamesAndValues) {
+ Map<String, Object> hqlParameters =
+ TopiaUtil.convertPropertiesArrayToMap(parameterName, parameterValue, otherParameterNamesAndValues);
+ return forHql(hql, hqlParameters);
+ }
+
+ @Override
+ public TopiaQueryBuilderAddCriteriaStep<E> forProperties(Map<String, Object> properties) {
+ HqlAndParametersBuilder<E> hqlAndParametersBuilder = getHqlForProperties(properties);
+ TopiaQueryBuilderAddCriteriaStep nextStep = new TopiaQueryBuilderAddCriteriaStep(this, hqlAndParametersBuilder);
+ return nextStep;
+ }
+
+ @Override
+ public TopiaQueryBuilderAddCriteriaStep<E> forProperties(String propertyName,
+ Object propertyValue,
+ Object... otherPropertyNamesAndValues) {
+ HqlAndParametersBuilder<E> hqlAndParametersBuilder = getHqlForProperties(propertyName, propertyValue, otherPropertyNamesAndValues);
+ TopiaQueryBuilderAddCriteriaStep nextStep = new TopiaQueryBuilderAddCriteriaStep(this, hqlAndParametersBuilder);
+ return nextStep;
+ }
+
+ @Override
+ public TopiaQueryBuilderAddCriteriaStep<E> newQueryBuilder() {
+ HqlAndParametersBuilder<E> hqlAndParametersBuilder = newHqlAndParametersBuilder();
+ TopiaQueryBuilderAddCriteriaStep nextStep = new TopiaQueryBuilderAddCriteriaStep(this, hqlAndParametersBuilder);
+ return nextStep;
+ }
+
+ @Override
+ public TopiaQueryBuilderRunQueryStep<E> forContains(String propertyName, Object propertyValue) {
+ return newQueryBuilder().addContains(propertyName, propertyValue).getNextStep();
+ }
+
+ @Override
+ public TopiaQueryBuilderRunQueryStep<E> forEquals(String propertyName, Object propertyValue) {
+ return newQueryBuilder().addEquals(propertyName, propertyValue).getNextStep();
+ }
+
+ @Override
+ public TopiaQueryBuilderRunQueryStep<E> forIn(String propertyName, Iterable<Object> propertyValues) {
+ return newQueryBuilder().addIn(propertyName, propertyValues).getNextStep();
+ }
+
+ protected boolean exists(String hql, Map<String, Object> hqlParameters) {
+ List<E> entities = topiaJpaSupport.find(hql, 0, 0, hqlParameters);
+ boolean exists = !entities.isEmpty();
+ return exists;
+ }
+
+ protected long count(String hql, Map<String, Object> hqlParameters) {
+ Preconditions.checkArgument(hql.toLowerCase().trim().startsWith("select count("));
+ Long count = findUnique(hql, hqlParameters, Long.class);
+ return count;
+ }
+
+ protected E findUnique(String hql, Map<String, Object> hqlParameters) {
+ E unique = findUnique(hql, hqlParameters, getEntityClass());
+ return unique;
+ }
+
+ protected E findUniqueOrNull(String hql, Map<String, Object> hqlParameters) {
+ E uniqueOrNull = findUniqueOrNull(hql, hqlParameters, getEntityClass());
+ return uniqueOrNull;
+ }
+
+ protected Optional<E> tryFindUnique(String hql, Map<String, Object> hqlParameters) {
+ Optional<E> uniqueOrNull = tryFindUnique(hql, hqlParameters, getEntityClass());
+ return uniqueOrNull;
+ }
+
+ protected E findFirst(String hql, Map<String, Object> hqlParameters) {
+ E firstOrNull = findFirst(hql, hqlParameters, getEntityClass());
+ return firstOrNull;
+ }
+
+ protected E findFirstOrNull(String hql, Map<String, Object> hqlParameters) {
+ E anyOrNull = findFirstOrNull(hql, hqlParameters, getEntityClass());
+ return anyOrNull;
+ }
+
+ protected Optional<E> tryFindFirst(String hql, Map<String, Object> hqlParameters) {
+ Optional<E> anyOrNull = tryFindFirst(hql, hqlParameters, getEntityClass());
+ return anyOrNull;
+ }
+
+ protected E findAny(String hql, Map<String, Object> hqlParameters) {
+ E anyOrNull = findAny(hql, hqlParameters, getEntityClass());
+ return anyOrNull;
+ }
+
+ protected E findAnyOrNull(String hql, Map<String, Object> hqlParameters) {
+ E anyOrNull = findAnyOrNull(hql, hqlParameters, getEntityClass());
+ return anyOrNull;
+ }
+
+ protected Optional<E> tryFindAny(String hql, Map<String, Object> hqlParameters) {
+ Optional<E> anyOrNull = tryFindAny(hql, hqlParameters, getEntityClass());
+ return anyOrNull;
+ }
+
+ protected <R> R findUnique(String hql, Map<String, Object> hqlParameters, Class<R> type) {
+ R uniqueOrNull = findUniqueOrNull(hql, hqlParameters, type);
+ if (uniqueOrNull == null) {
+ // TODO brendan 30/09/13 throw another exception if no result
+ throw new TopiaException("query " + hql + " returns no elements");
+ }
+ return uniqueOrNull;
+ }
+
+ protected <R> Optional<R> tryFindUnique(String hql, Map<String, Object> hqlParameters, Class<R> type) {
+ R uniqueOrNull = findUniqueOrNull(hql, hqlParameters, type);
+ return Optional.fromNullable(uniqueOrNull);
+ }
+
+ protected <R> R findUniqueOrNull(String hql, Map<String, Object> hqlParameters, Class<R> type) {
+ List<R> results = findAll(hql, hqlParameters, type, 0, 1);
+ // If there is more than 1 result, throw an exception
+ if (results.size() > 1) {
+ String message = String.format(
+ "The query '%s' returns more than 1 unique result", hql);
+ // TODO AThimel 02/08/13 Throw another exception if more than 1 result is found
+ throw new TopiaException(message);
+ }
+ // otherwise return the first one, or null
+ R uniqueOrNull = Iterables.getOnlyElement(results, null);
+ return uniqueOrNull;
+ }
+
+ protected <R> R findFirst(String hql, Map<String, Object> hqlParameters, Class<R> type) {
+ R firstOrNull = findFirstOrNull(hql, hqlParameters, type);
+ if (firstOrNull == null) {
+ // TODO brendan 30/09/13 throw another exception if no result
+ throw new TopiaException("query " + hql + " returns no elements");
+ }
+ return firstOrNull;
+ }
+
+ protected <R> Optional<R> tryFindFirst(String hql, Map<String, Object> hqlParameters, Class<R> type) {
+ R firstOrNull = findFirstOrNull(hql, hqlParameters, type);
+ return Optional.fromNullable(firstOrNull);
+ }
+
+ protected <R> R findFirstOrNull(String hql, Map<String, Object> hqlParameters, Class<R> type) {
+ Preconditions.checkArgument(hql.toLowerCase().contains("order by"));
+ R anyOrNull = findAnyOrNull(hql, hqlParameters, type);
+ return anyOrNull;
+ }
+
+ protected <R> R findAny(String hql, Map<String, Object> hqlParameters, Class<R> type) {
+ R anyOrNull = findAnyOrNull(hql, hqlParameters, type);
+ if (anyOrNull == null) {
+ // TODO brendan 30/09/13 throw another exception if no result
+ throw new TopiaException("query " + hql + " returns no elements");
+ }
+ return anyOrNull;
+ }
+
+ protected <R> Optional<R> tryFindAny(String hql, Map<String, Object> hqlParameters, Class<R> type) {
+ R anyOrNull = findAnyOrNull(hql, hqlParameters, type);
+ return Optional.fromNullable(anyOrNull);
+ }
+
+ protected <R> R findAnyOrNull(String hql, Map<String, Object> hqlParameters, Class<R> type) {
+ Preconditions.checkNotNull(hql);
+ Preconditions.checkNotNull(hqlParameters);
+ List<R> results = findAll(hql, hqlParameters, type, 0, 0);
+ R anyOrNull = Iterables.getOnlyElement(results, null);
+ return anyOrNull;
+ }
+
+ protected List<E> findAll(String hql, Map<String, Object> hqlParameters) {
+ Preconditions.checkNotNull(hql);
+ Preconditions.checkNotNull(hqlParameters);
+ List<E> all = topiaJpaSupport.findAll(hql, hqlParameters);
+ return all;
+ }
+
+ protected List<E> findAll(String hql, Map<String, Object> hqlParameters, int startIndex, int endIndex) {
+ Preconditions.checkNotNull(hql);
+ Preconditions.checkNotNull(hqlParameters);
+ List<E> all = topiaJpaSupport.find(hql, startIndex, endIndex, hqlParameters);
+ return all;
+ }
+
+ protected List<E> findAll(String hql, Map<String, Object> hqlParameters, TopiaPagerBean pager) {
+ List<E> all = findAll(hql, hqlParameters, getEntityClass(), pager);
+ return all;
+ }
+
+ protected <R> List<R> findAll(String hql, Map<String, Object> hqlParameters, Class<R> type) {
+ Preconditions.checkNotNull(hql);
+ Preconditions.checkNotNull(hqlParameters);
+ Preconditions.checkNotNull(type);
+ List<R> all = topiaJpaSupport.findAll(hql, hqlParameters);
+ return all;
+ }
+
+ protected <R> List<R> findAll(String hql, Map<String, Object> hqlParameters, Class<R> type, int startIndex, int endIndex) {
+ Preconditions.checkNotNull(hql);
+ Preconditions.checkNotNull(hqlParameters);
+ Preconditions.checkNotNull(type);
+ List<R> all = topiaJpaSupport.find(hql, startIndex, endIndex, hqlParameters);
+ return all;
+ }
+
+ protected <R> List<R> findAll(String hql, Map<String, Object> hqlParameters, Class<R> type, TopiaPagerBean pager) {
+ Preconditions.checkNotNull(hql);
+ Preconditions.checkNotNull(hqlParameters);
+ Preconditions.checkNotNull(type);
+ Preconditions.checkNotNull(pager);
+
+ if (StringUtils.isNotBlank(pager.getSortColumn())) {
+ hql += " order by " + pager.getSortColumn();
+ if (!pager.isSortAscendant()) {
+ hql += " desc";
+ }
+ }
+
+ List<R> result = topiaJpaSupport.find(
+ hql,
+ (int) pager.getRecordStartIndex(),
+ (int) pager.getRecordEndIndex() - 1,
+ hqlParameters);
+
+ return result;
+ }
+
+ protected Iterable<E> findAllLazy(String hql, Map<String, Object> hqlParameters) {
+ Iterable<E> allLazy = findAllLazy(hql, hqlParameters, getEntityClass());
+ return allLazy;
+ }
+
+ protected <R> Iterable<R> findAllLazy(String hql, Map<String, Object> hqlParameters, Class<R> type) {
+
+ Preconditions.checkNotNull(hql);
+ Preconditions.checkNotNull(hqlParameters);
+ Preconditions.checkNotNull(type);
+
+ final Iterator<R> iterator = new FindAllIterator<E, R>(this,
+ type,
+ batchSize,
+ hql,
+ hqlParameters);
+
+ Iterable<R> result = new Iterable<R>() {
+ @Override
+ public Iterator<R> iterator() {
+ return iterator;
+ }
+ };
+
+ return result;
+ }
+
+ @Override
+ public TopiaQueryBuilderRunQueryStep<E> forTopiaIdEquals(String topiaId) {
+ Preconditions.checkNotNull(topiaId, "given topiaId is null");
+ return forEquals(TopiaEntity.PROPERTY_TOPIA_ID, topiaId);
+ }
+
+ @Override
+ public TopiaQueryBuilderRunQueryStep<E> forTopiaIdIn(Iterable<String> topiaIds) {
+ Preconditions.checkNotNull(topiaIds, "given topiaIds is null");
+ return forIn(TopiaEntity.PROPERTY_TOPIA_ID, (Iterable) topiaIds);
+ }
+
+ @Override
+ public List<String> findAllIds() {
+ List<String> find = newQueryBuilder().findAllIds();
+ return find;
+ }
+
+ @Override
+ public List<E> findAll() {
+ List<E> all = newQueryBuilder().findAll();
+ return all;
+ }
+
+ @Override
+ public Iterable<E> findAllLazy() {
+ String hql = "from " + getTopiaEntityEnum().getImplementationFQN() + " order by id";
+ Map<String, Object> hqlParameters = Collections.emptyMap();
+ Iterable<E> allLazy = findAllLazy(hql, hqlParameters);
+ return allLazy;
+ }
+
+ @Override
+ public Iterator<E> iterator() {
+ Iterator<E> iterator = findAllLazy().iterator();
+ return iterator;
+ }
+
+ @Override
+ public long count() {
+ long count = newQueryBuilder().count();
+ return count;
+ }
+
+ /**
+ * package locale method because this is hibernate specific method and
+ * we don't want expose it.
+ *
+ * @return the meta-data of the entity
+ * @throws org.nuiton.topia.TopiaException if any pb
+ */
+ protected ClassMetadata getClassMetadata() {
+ ClassMetadata meta = topiaHibernateSupport.getHibernateFactory()
+ .getClassMetadata(getEntityClass());
+ if (meta == null) {
+ meta = topiaHibernateSupport.getHibernateFactory().getClassMetadata(
+ getTopiaEntityEnum().getImplementationFQN());
+ }
+ return meta;
+ }
+
+ public static class FindAllIterator<E extends TopiaEntity, R> implements Iterator<R> {
+
+ protected Iterator<R> data;
+
+ protected final AbstractTopiaDao<E> dao;
+
+ protected final Class<R> type;
+
+ protected final String hql;
+
+ protected final Map<String, Object> params;
+
+ protected TopiaPagerBean pager;
+
+ public FindAllIterator(AbstractTopiaDao<E> dao,
+ Class<R> type,
+ int batchSize,
+ String hql,
+ Map<String, Object> params) {
+ this.dao = dao;
+ this.type = type;
+ this.hql = hql;
+ this.params = params;
+
+ String hql2 = hql.toLowerCase();
+ int i = hql2.indexOf("order by");
+ if (i == -1) {
+ throw new IllegalStateException(
+ "must have a *order by* in hql, " +
+ "but did not find it in " + hql);
+ }
+
+ // get the count (removing the order-by)
+ long count2 = dao.count("SELECT COUNT(*) " +
+ hql.substring(0, i), params);
+ pager = new TopiaPagerBean();
+ pager.setRecords(count2);
+ pager.setPageSize(batchSize);
+ PagerBeanUtil.computeRecordIndexesAndPagesNumber(pager);
+
+ // empty iterator (will be changed at first next call)
+ data = Iterators.emptyIterator();
+ }
+
+
+ public boolean hasNext() {
+ boolean result = data.hasNext() || // no more data
+ pager.getPageIndex() < pager.getPagesNumber();
+ return result;
+ }
+
+
+ public R next() {
+ if (!hasNext()) {
+ throw new NoSuchElementException();
+ }
+
+ if (!data.hasNext()) {
+
+ // must load iterator
+
+ // increments page index
+ pager.setPageIndex(pager.getPageIndex() + 1);
+ PagerBeanUtil.computeRecordIndexesAndPagesNumber(pager);
+
+ // load new window of data
+ data = dao.findAll(hql, params, type, pager).iterator();
+
+ }
+
+ R next = data.next();
+ return next;
+ }
+
+
+ public void remove() {
+ throw new UnsupportedOperationException(
+ "This iterator does not support remove operation.");
+ }
+ }
+
+ public static class TopiaQueryBuilderAddCriteriaStep<E extends TopiaEntity> implements TopiaQueryBuilderAddCriteriaOrRunQueryStep<E> {
+
+ protected AbstractTopiaDao<E> topiaDAO;
+
+ protected HqlAndParametersBuilder<E> hqlAndParametersBuilder;
+
+ protected boolean hasOrderByClause = false;
+
+ protected TopiaQueryBuilderAddCriteriaStep(AbstractTopiaDao<E> topiaDAO, HqlAndParametersBuilder<E> hqlAndParametersBuilder) {
+ this.topiaDAO = topiaDAO;
+ this.hqlAndParametersBuilder = hqlAndParametersBuilder;
+ }
+
+ @Override
+ public TopiaQueryBuilderRunQueryStep<E> setOrderByArguments(Set<String> orderByArguments) {
+ hasOrderByClause = ! Iterables.isEmpty(orderByArguments);
+ hqlAndParametersBuilder.setOrderByArguments(orderByArguments);
+ return getNextStep();
+ }
+
+ @Override
+ public TopiaQueryBuilderRunQueryStep<E> setOrderByArguments(String... orderByArguments) {
+ hqlAndParametersBuilder.setOrderByArguments(orderByArguments);
+ return getNextStep();
+ }
+
+ @Override
+ public TopiaQueryBuilderAddCriteriaStep<E> addEquals(String property, Object value) {
+ hqlAndParametersBuilder.addEquals(property, value);
+ return this;
+ }
+
+ @Override
+ public TopiaQueryBuilderAddCriteriaStep<E> addIn(String property, Iterable<Object> values) {
+ hqlAndParametersBuilder.addIn(property, values);
+ return this;
+ }
+
+ @Override
+ public TopiaQueryBuilderAddCriteriaStep<E> addContains(String property, Object value) {
+ hqlAndParametersBuilder.addContains(property, value);
+ return this;
+ }
+
+ @Override
+ public TopiaQueryBuilderAddCriteriaStep<E> addNull(String property) {
+ hqlAndParametersBuilder.addNull(property);
+ return this;
+ }
+
+ @Override
+ public TopiaQueryBuilderAddCriteriaStep<E> addTopiaIdEquals(String property, String topiaId) {
+ hqlAndParametersBuilder.addTopiaIdEquals(property, topiaId);
+ return this;
+ }
+
+ @Override
+ public TopiaQueryBuilderAddCriteriaStep<E> addTopiaIdIn(String property, Iterable<String> topiaIds) {
+ hqlAndParametersBuilder.addTopiaIdIn(property, topiaIds);
+ return this;
+ }
+
+ // shortcuts to next step
+
+ @Override
+ public boolean exists() {
+ return getNextStep().exists();
+ }
+
+ @Override
+ public E findAnyOrNull() {
+ return getNextStep().findAnyOrNull();
+ }
+
+ @Override
+ public E findUniqueOrNull() {
+ return getNextStep().findUniqueOrNull();
+ }
+
+ @Override
+ public E findAny() {
+ return getNextStep().findAny();
+ }
+
+ @Override
+ public E findUnique() {
+ return getNextStep().findUnique();
+ }
+
+ @Override
+ public E findFirst() {
+ return getNextStep().findFirst();
+ }
+
+ @Override
+ public E findFirstOrNull() {
+ return getNextStep().findFirstOrNull();
+ }
+
+ @Override
+ public Optional<E> tryFindAny() {
+ return getNextStep().tryFindAny();
+ }
+
+ @Override
+ public Optional<E> tryFindFirst() {
+ return getNextStep().tryFindFirst();
+ }
+
+ @Override
+ public Optional<E> tryFindUnique() {
+ return getNextStep().tryFindUnique();
+ }
+
+ @Override
+ public List<E> findAll() {
+ return getNextStep().findAll();
+ }
+
+ @Override
+ public List<E> findAll(int startIndex, int endIndex) {
+ return getNextStep().findAll(startIndex, endIndex);
+ }
+
+ @Override
+ public Iterable<E> findAllLazy() {
+ return getNextStep().findAllLazy();
+ }
+
+ @Override
+ public long count() {
+ return getNextStep().count();
+ }
+
+ @Override
+ public List<String> findAllIds(int startIndex, int endIndex) {
+ return getNextStep().findAllIds(startIndex, endIndex);
+ }
+
+ @Override
+ public List<String> findAllIds() {
+ return getNextStep().findAllIds();
+ }
+
+ protected TopiaQueryBuilderRunQueryStep<E> getNextStep() {
+ String hql = hqlAndParametersBuilder.getHql();
+ Map<String, Object> hqlParameters = hqlAndParametersBuilder.getHqlParameters();
+ TopiaQueryBuilderRunQueryStep nextStep = new TopiaQueryBuilderRunQueryStep(topiaDAO, hql, hqlParameters);
+ return nextStep;
+ }
+
+ }
+
+ public static class TopiaQueryBuilderRunQueryStep<E extends TopiaEntity> implements org.nuiton.topia.persistence.TopiaQueryBuilderRunQueryStep<E> {
+
+ protected final String hql;
+
+ protected final Map<String, Object> hqlParameters;
+
+ protected AbstractTopiaDao<E> topiaDAO;
+
+ protected TopiaQueryBuilderRunQueryStep(AbstractTopiaDao<E> topiaDAO, String hql, Map<String, Object> hqlParameters) {
+ this.hql = hql;
+ this.hqlParameters = hqlParameters;
+ this.topiaDAO = topiaDAO;
+ }
+
+ @Override
+ public boolean exists() {
+ return topiaDAO.exists(hql, hqlParameters);
+ }
+
+ @Override
+ public long count() {
+ String hqlWithSelectClause = "select count(topiaId) " + hql;
+ return topiaDAO.count(hqlWithSelectClause, hqlParameters);
+ }
+
+ @Override
+ public E findUnique() {
+ return topiaDAO.findUnique(hql, hqlParameters);
+ }
+
+ @Override
+ public E findUniqueOrNull() {
+ return topiaDAO.findUniqueOrNull(hql, hqlParameters);
+ }
+
+ @Override
+ public Optional<E> tryFindUnique() {
+ return topiaDAO.tryFindUnique(hql, hqlParameters);
+ }
+
+ @Override
+ public E findFirst() {
+ return topiaDAO.findFirst(hql, hqlParameters);
+ }
+
+ @Override
+ public E findFirstOrNull() {
+ return topiaDAO.findFirstOrNull(hql, hqlParameters);
+ }
+
+ @Override
+ public Optional<E> tryFindFirst() {
+ return topiaDAO.tryFindFirst(hql, hqlParameters);
+ }
+
+ @Override
+ public E findAny() {
+ return topiaDAO.findAny(hql, hqlParameters);
+ }
+
+ @Override
+ public E findAnyOrNull() {
+ return topiaDAO.findAnyOrNull(hql, hqlParameters);
+ }
+
+ @Override
+ public Optional<E> tryFindAny() {
+ return topiaDAO.tryFindAny(hql, hqlParameters);
+ }
+
+ @Override
+ public List<E> findAll() {
+ return topiaDAO.findAll(hql, hqlParameters);
+ }
+
+ @Override
+ public Iterable<E> findAllLazy() {
+ return topiaDAO.findAllLazy(hql, hqlParameters);
+ }
+
+ @Override
+ public List<E> findAll(int startIndex, int endIndex) {
+ return topiaDAO.findAll(hql, hqlParameters, startIndex, endIndex);
+ }
+
+ @Override
+ public List<String> findAllIds() {
+ // XXX brendan 30/09/13 does this truely work ?
+ String hqlWithSelectClause = "select topiaId " + hql;
+ return topiaDAO.findAll(hqlWithSelectClause, hqlParameters, String.class);
+ }
+
+ @Override
+ public List<String> findAllIds(int startIndex, int endIndex) {
+ // XXX brendan 30/09/13 does this truely work ?
+ String hqlWithSelectClause = "select topiaId " + hql;
+ return topiaDAO.findAll(hqlWithSelectClause, hqlParameters, String.class, startIndex, endIndex);
+ }
+
+ }
+
+}
Added: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/LegacyTopiaDao.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/LegacyTopiaDao.java (rev 0)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/LegacyTopiaDao.java 2013-10-25 12:03:15 UTC (rev 2847)
@@ -0,0 +1,309 @@
+package org.nuiton.topia.persistence;
+
+import com.google.common.base.Preconditions;
+import org.apache.commons.lang3.StringUtils;
+import org.nuiton.topia.TopiaContext;
+import org.nuiton.topia.framework.TopiaContextImplementor;
+import org.nuiton.topia.framework.TopiaUtil;
+import org.nuiton.topia.persistence.pager.TopiaPagerBean;
+import org.nuiton.util.PagerBeanUtil;
+
+import java.security.Permission;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Implements deprecated method from {@link TopiaDAO}, should be deleted.
+ */
+public abstract class LegacyTopiaDao<E extends TopiaEntity> implements TopiaDAO<E> {
+
+ @Override
+ public E create(Object... propertyNamesAndValues) {
+ Map<String, Object> properties = TopiaUtil.convertPropertiesArrayToMap(propertyNamesAndValues);
+ E result = create(properties);
+ return result;
+ }
+
+ @Deprecated
+ public boolean existByTopiaId(String topiaId) {
+ return forTopiaIdEquals(topiaId).exists();
+ }
+
+ @Deprecated
+ public boolean existByProperties(String propertyName, Object propertyValue,
+ Object... propertyNamesAndValues) {
+ return forProperties(propertyName, propertyValue, propertyNamesAndValues).exists();
+ }
+
+ @Deprecated
+ protected String createSimpleQuery() {
+ return newFromClause(null);
+ }
+
+ @Deprecated
+ public String createSimpleQuery(String alias) {
+ return newFromClause(alias);
+ }
+
+ protected abstract String newFromClause(String alias);
+
+ @Deprecated
+ public E findByTopiaId(String id) {
+ return forTopiaIdEquals(id).findUniqueOrNull();
+ }
+
+ @Deprecated
+ public E findByProperty(String propertyName, Object value) {
+ return forProperties(propertyName, value).findAnyOrNull();
+ }
+
+ @Override
+ @Deprecated
+ public <R> R findByQuery(Class<R> type, String hql, Object... propertyNamesAndValues) {
+ Map<String, Object> properties = TopiaUtil.convertPropertiesArrayToMap(propertyNamesAndValues);
+ return findAny(hql, properties, type);
+ }
+
+ @Override
+ @Deprecated
+ public E findByPrimaryKey(Map<String, Object> keys) {
+ return forProperties(keys).findUniqueOrNull();
+ }
+
+ @Override
+ @Deprecated
+ public E findByPrimaryKey(Object... propertyNamesAndValues) {
+ Map<String, Object> properties = TopiaUtil.convertPropertiesArrayToMap(propertyNamesAndValues);
+ E byPrimaryKey = findByPrimaryKey(properties);
+ return byPrimaryKey;
+ }
+
+ @Override
+ @Deprecated
+ public List<E> findAllWithOrder(String... propertyNames) {
+ return newQueryBuilder().setOrderByArguments(propertyNames).findAll();
+ }
+
+ @Override
+ @Deprecated
+ public <R> List<R> findAllByQuery(Class<R> type, String hql, Object... propertyNamesAndValues) {
+ Map<String, Object> hqlParameters = TopiaUtil.convertPropertiesArrayToMap(propertyNamesAndValues);
+ List<R> all = findAll(hql, hqlParameters, type);
+ return all;
+ }
+
+ @Deprecated
+ public E findByProperties(String propertyName, Object value,
+ Object... propertyNamesAndValues) {
+ return forProperties(propertyName, value, propertyNamesAndValues).findUniqueOrNull();
+ }
+
+ @Deprecated
+ public E findByProperties(Map<String, Object> properties) {
+ return forProperties(properties).findUniqueOrNull();
+ }
+
+ @Deprecated
+ public List<E> findAllByProperty(String propertyName, Object value) {
+ List<E> all = forProperties(propertyName, value).findAll();
+ return all;
+ }
+
+ @Deprecated
+ public List<E> findAllByProperties(String propertyName, Object value, Object... propertyNamesAndValues) {
+ List<E> all = forProperties(propertyName, value, propertyNamesAndValues).findAll();
+ return all;
+ }
+
+ @Deprecated
+ public List<E> findAllByProperties(Map<String, Object> properties) {
+ return forProperties(properties).findAll();
+ }
+
+ @Deprecated
+ public E findContains(String propertyName, Object value) {
+ return newQueryBuilder().addContains(propertyName, value).findAny();
+ }
+
+ @Deprecated
+ public List<E> findAllContains(String propertyName,
+ Object value) {
+ return newQueryBuilder().addContains(propertyName, value).findAll();
+ }
+
+ @Deprecated
+ public boolean existsByQuery(String hql, Object... propertyNamesAndValues) {
+ Map<String, Object> hqlParameters = TopiaUtil.convertPropertiesArrayToMap(propertyNamesAndValues);
+ boolean exists = exists(hql, hqlParameters);
+ return exists;
+ }
+
+ @Deprecated
+ public long countByQuery(String hql,
+ Object... propertyNamesAndValues) {
+
+ Preconditions.checkNotNull(StringUtils.isNotBlank(hql));
+ Preconditions.checkArgument(hql.toUpperCase().trim().startsWith("SELECT COUNT("));
+ Map<String, Object> hqlParameters = TopiaUtil.convertPropertiesArrayToMap(propertyNamesAndValues);
+ long count = forHql(hql, hqlParameters).count();
+ return count;
+ }
+
+ @Deprecated
+ public E findByQuery(String hql,
+ Object... propertyNamesAndValues) {
+ Map<String, Object> hqlParameters = TopiaUtil.convertPropertiesArrayToMap(propertyNamesAndValues);
+ E uniqueOrNull = forHql(hql, hqlParameters).findUniqueOrNull();
+ return uniqueOrNull;
+ }
+
+ @Deprecated
+ public List<E> findAllByQuery(String hql,
+ Object... propertyNamesAndValues) {
+ Map<String, Object> hqlParameters = TopiaUtil.convertPropertiesArrayToMap(propertyNamesAndValues);
+ List<E> all = forHql(hql, hqlParameters).findAll();
+ return all;
+ }
+
+ @Deprecated
+ public Iterable<E> findAllLazyByQuery(String hql,
+ Object... propertyNamesAndValues) {
+ Map<String, Object> hqlParameters = TopiaUtil.convertPropertiesArrayToMap(propertyNamesAndValues);
+ Iterable<E> result = findAllLazy(hql, hqlParameters);
+ return result;
+ }
+
+ @Deprecated
+ public <R> Iterable<R> findAllLazyByQuery(Class<R> type,
+ String hql,
+ Object... propertyNamesAndValues) {
+ Map<String, Object> hqlParameters = TopiaUtil.convertPropertiesArrayToMap(propertyNamesAndValues);
+ Iterable<R> result = findAllLazy(hql, hqlParameters, type);
+ return result;
+ }
+
+ @Deprecated
+ public Iterable<E> findAllLazyByQuery(int batchSize,
+ String hql,
+ Object... propertyNamesAndValues) {
+ return findAllLazyByQuery(getEntityClass(), batchSize, hql, propertyNamesAndValues);
+ }
+
+
+ /**
+ * @deprecated use {@link #findAllLazy(String, java.util.Map, Class)}
+ */
+ @Deprecated
+ public <R> Iterable<R> findAllLazyByQuery(Class<R> type,
+ int batchSize,
+ String hql,
+ Object... propertyNamesAndValues) {
+ setBatchSize(batchSize);
+ Map<String, Object> hqlParameters = TopiaUtil.convertPropertiesArrayToMap(propertyNamesAndValues);
+ Iterable<R> allLazy = findAllLazy(hql, hqlParameters, type);
+ return allLazy;
+ }
+
+ @Deprecated
+ public <R> List<R> findAllByQueryWithBound(Class<R> type,
+ String hql,
+ int startIndex,
+ int endIndex,
+ Object... propertyNamesAndValues) {
+ Map<String, Object> hqlParameters = TopiaUtil.convertPropertiesArrayToMap(propertyNamesAndValues);
+ List<R> all = findAll(hql, hqlParameters, type, startIndex, endIndex);
+ return all;
+ }
+
+ @Deprecated
+ public List<E> findAllByQueryWithBound(String hql,
+ int startIndex,
+ int endIndex,
+ Object... propertyNamesAndValues) {
+ List<E> result = findAllByQueryWithBound(getEntityClass(),
+ hql,
+ startIndex,
+ endIndex,
+ propertyNamesAndValues);
+ return result;
+ }
+
+
+ @Deprecated
+ public <R> List<R> findAllByQueryAndPager(Class<R> type,
+ String hql,
+ TopiaPagerBean pager,
+ Object... propertyNamesAndValues) {
+ Preconditions.checkNotNull(pager);
+ Preconditions.checkNotNull(hql);
+
+ if (StringUtils.isNotBlank(pager.getSortColumn())) {
+ hql += " ORDER BY " + pager.getSortColumn();
+ if (!pager.isSortAscendant()) {
+ hql += " DESC";
+ }
+ }
+ List<R> result = findAllByQueryWithBound(type, hql,
+ (int) pager.getRecordStartIndex(),
+ (int) pager.getRecordEndIndex() - 1,
+ propertyNamesAndValues);
+ return result;
+ }
+
+ @Deprecated
+ public List<E> findAllByQueryAndPager(String hql,
+ TopiaPagerBean pager,
+ Object... propertyNamesAndValues) {
+
+ List<E> result = findAllByQueryAndPager(getEntityClass(),
+ hql,
+ pager,
+ propertyNamesAndValues);
+ return result;
+ }
+
+ @Deprecated
+ public void computeAndAddRecordsToPager(String hql,
+ TopiaPagerBean pager,
+ Object... propertyNamesAndValues) {
+
+ long records = countByQuery(hql, propertyNamesAndValues);
+
+ pager.setRecords(records);
+ PagerBeanUtil.computeRecordIndexesAndPagesNumber(pager);
+ }
+
+ @Override
+ public List<Permission> getRequestPermission(String topiaId, int actions) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public TopiaContextImplementor getContext() {
+ throw new UnsupportedOperationException();
+ }
+
+
+ @Override
+ public TopiaContext getTopiaContext() {
+ throw new UnsupportedOperationException();
+ }
+
+
+ // let's use method written in AbstractTopiaDao
+
+ protected abstract Iterable<E> findAllLazy(String hql, Map<String, Object> hqlParameters);
+
+ protected abstract <R> R findAny(String hql, Map<String, Object> properties, Class<R> type);
+
+ protected abstract TopiaQueryBuilderRunQueryStep<E> forHql(String hql, Map<String, Object> hqlParameters);
+
+ protected abstract <R> List<R> findAll(String hql, Map<String, Object> hqlParameters, Class<R> type);
+
+ protected abstract <R> Iterable<R> findAllLazy(String hql, Map<String, Object> hqlParameters, Class<R> type);
+
+ protected abstract <R> List<R> findAll(String hql, Map<String, Object> hqlParameters, Class<R> type, int startIndex, int endIndex);
+
+ protected abstract boolean exists(String hql, Map<String, Object> hqlParameters);
+
+}
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAO.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAO.java 2013-10-17 16:14:18 UTC (rev 2846)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAO.java 2013-10-25 12:03:15 UTC (rev 2847)
@@ -38,8 +38,6 @@
import org.nuiton.topia.TopiaContext;
import org.nuiton.topia.TopiaException;
-import org.nuiton.topia.event.TopiaEntityListener;
-import org.nuiton.topia.event.TopiaEntityVetoable;
import org.nuiton.topia.framework.TopiaContextImplementor;
import org.nuiton.topia.persistence.pager.TopiaPagerBean;
@@ -60,23 +58,16 @@
* @author fdesbois <fdesbois(a)codelutin.com>
* @author tchemit <chemit(a)codelutin.com>
* @version $Id$
+ * @deprecated prefer {@link TopiaDao}
*/
-public interface TopiaDAO<E extends TopiaEntity> extends Iterable<E> {
+@Deprecated
+public interface TopiaDAO<E extends TopiaEntity> extends TopiaDao<E> {
//------------------------------------------------------------------------//
//-- Create - update - delete methods ------------------------------------//
//------------------------------------------------------------------------//
/**
- * Create a new instance of managed entity <strong>not persisted</strong>.
- *
- * @return new entity instance
- * @throws TopiaException if any pb while creating the entity
- * @since 2.3.1
- */
- E newInstance() throws TopiaException;
-
- /**
* Creates a new instance of the entity managed by the DAO
*
* @param propertyNamesAndValues the list of properties that the created entity will have. Arguments are key-value
@@ -87,57 +78,10 @@
* if some property type is not the
* expected one
* @see #create(Map)
+ * @deprecated use {@link TopiaDao#create(String, Object, Object...)}
*/
E create(Object... propertyNamesAndValues) throws TopiaException;
- /**
- * Creates a new instance of the entity managed by the DAO
- *
- * @param properties the key-value list of properties that the created entity will have.
- * @return the newly created entity
- * @throws TopiaException if any problem during instantiation
- * @throws IllegalArgumentException if some property type is not the
- * expected one
- */
- E create(Map<String, Object> properties) throws TopiaException;
-
- /**
- * Creates an entity not created without the DAO. Generally used when DAO
- * is layered after a service layer where the {@link #create(Object...)}
- * would be to onerous.
- *
- * @param e the instance to persist
- * @return the persisted entity (with its topiaId valued)
- * @throws TopiaException if any problem while creating data
- * @since 2.3.1
- */
- E create(E e) throws TopiaException;
-
- /**
- * Update an entity. May be used for an entity coming from another context.
- *
- * @param e the entity to create or update
- * @return the given entity
- * @throws TopiaException if any problem while updating datas
- */
- E update(E e) throws TopiaException;
-
- /**
- * Removes the given entity from the storage
- *
- * @param e the entity to remove
- * @throws TopiaException if any problem while deleting datas
- */
- void delete(E e) throws TopiaException;
-
- /**
- * Permet de supprimer des entités.
- *
- * @param entities les entités à supprimer
- * @throws TopiaException if any pb while deleting datas
- */
- void deleteAll(Iterable<E> entities) throws TopiaException;
-
//------------------------------------------------------------------------//
//-- findByXXX methods ---------------------------------------------------//
//------------------------------------------------------------------------//
@@ -149,6 +93,7 @@
* @param id topiaId of the entity to found
* @return the entity found or null if not
* @throws TopiaException for Topia errors on query
+ * @deprecated ambiguous signature use new API and inline {@link TopiaDao#forTopiaIdEquals(String)}
*/
E findByTopiaId(String id) throws TopiaException;
@@ -159,6 +104,7 @@
* @param value value of the property to match
* @return the first entity matching the request
* @throws TopiaException if any pb while getting datas
+ * @deprecated @deprecated use new API and inline {@link LegacyTopiaDao#findByProperties(String, Object, Object...)}
*/
E findByProperty(String propertyName,
Object value) throws TopiaException;
@@ -172,6 +118,7 @@
* [propertyName;value;propertyName;value;...]
* @return the first entity matching the request
* @throws TopiaException if any pb while getting datas
+ * @deprecated @deprecated use new API and inline {@link LegacyTopiaDao#findByProperties(String, Object, Object...)}
*/
E findByProperties(String propertyName,
Object value,
@@ -183,6 +130,7 @@
* @param properties the properties key + value to match
* @return the first entity matching the request
* @throws TopiaException if any pb while getting datas
+ * @deprecated @deprecated use new API and inline {@link LegacyTopiaDao#findByProperties(java.util.Map)}
*/
E findByProperties(Map<String, Object> properties) throws TopiaException;
@@ -195,6 +143,7 @@
* @return the entity E found or null
* @throws TopiaException if any pb while getting datas
* @since 2.6.12
+ * @deprecated move your code inside the DAO and use a suitable protected method
*/
E findByQuery(String hql,
Object... propertyNamesAndValues) throws TopiaException;
@@ -212,6 +161,7 @@
* @throws TopiaException if any pb while getting datas
* @throws ClassCastException if the found type is not the expected one
* @since 2.6.12
+ * @deprecated move your code inside the DAO and use a suitable protected method
*/
<R> R findByQuery(Class<R> type,
String hql,
@@ -225,6 +175,7 @@
* @param keys Map with the natural id property name as Map.key, and value as Map.value
* @return the entity E found or null
* @throws TopiaException if any pb while getting datas
+ * @deprecated use new API and inline {@link LegacyTopiaDao#findByPrimaryKey(java.util.Map)}
*/
E findByPrimaryKey(Map<String, Object> keys) throws TopiaException;
@@ -236,6 +187,7 @@
* [propertyName;value;propertyName;value;...]
* @return the entity E found or null
* @throws TopiaException if any pb while getting datas
+ * @deprecated use new API and inline {@link LegacyTopiaDao#findByPrimaryKey(Object...)}
*/
E findByPrimaryKey(Object... propertyNamesAndValues) throws TopiaException;
@@ -248,6 +200,7 @@
* @return the entity E found or null
* @throws TopiaException if any pb while getting datas
* @since 2.5.4
+ * @deprecated use new API and inline {@link LegacyTopiaDao#findContains(String, Object)}
*/
E findContains(String propertyName,
Object value) throws TopiaException;
@@ -257,14 +210,6 @@
//------------------------------------------------------------------------//
/**
- * Finds all the entities managed by this DAO.
- *
- * @return the full list of entities
- * @throws TopiaException if any pb while getting datas
- */
- List<E> findAll() throws TopiaException;
-
- /**
* Finds all entites E managed by this DAO. The returned list will be ordered according to the given
* {@code propertyNames}.
* <p/>
@@ -274,19 +219,11 @@
* @param propertyNames property names of order to apply
* @return all entities E of the dao entity type with given order
* @throws TopiaException if any pb while getting datas
+ * @deprecated use new API and inline {@link LegacyTopiaDao#findAllWithOrder(String...)}
*/
List<E> findAllWithOrder(String... propertyNames) throws TopiaException;
/**
- * Find all the ids for the E entity type
- *
- * @return the full list of ids
- * @throws TopiaException if any pb while getting datas
- */
- // TODO AThimel 20/07/13 This method should return a Set ?
- List<String> findAllIds() throws TopiaException;
-
- /**
* Finds all entities E which value for the given {@code propertyName} is
* {@code value}
*
@@ -294,6 +231,7 @@
* @param value value to expect
* @return the list of entities E having the given value
* @throws TopiaException if any pb while getting datas
+ * @deprecated use new API and inline {@link LegacyTopiaDao#findAllByProperties(String, Object, Object...)}
*/
List<E> findAllByProperty(String propertyName,
Object value) throws TopiaException;
@@ -308,6 +246,7 @@
* [propertyName;value;propertyName;value;...]
* @return the list of entities E having the given value
* @throws TopiaException if any pb while getting datas
+ * @deprecated use new API and inline {@link LegacyTopiaDao#findAllByProperties(String, Object, Object...)}
*/
List<E> findAllByProperties(String propertyName,
Object value,
@@ -319,6 +258,7 @@
* @param properties properties to match
* @return the list of entities E having the given values
* @throws TopiaException if any pb while getting datas
+ * @deprecated use new API and inline {@link LegacyTopiaDao#findAllByProperties(java.util.Map)}
*/
List<E> findAllByProperties(Map<String, Object> properties) throws TopiaException;
@@ -331,6 +271,7 @@
* @return the list of entities E found by the query and parameters
* @throws TopiaException if any pb while getting datas
* @since 2.6.12
+ * @deprecated move your code inside the DAO and use {@link AbstractTopiaDao#findAll(String, java.util.Map)}
*/
List<E> findAllByQuery(String hql,
Object... propertyNamesAndValues) throws TopiaException;
@@ -348,6 +289,7 @@
* @return entites of the query result
* @throws TopiaException if any pb while getting datas
* @since 2.6.12
+ * @deprecated move your code inside the DAO and use {@link AbstractTopiaDao#findAll(String, java.util.Map, Class)}
*/
<R> List<R> findAllByQuery(Class<R> type,
String hql,
@@ -367,6 +309,7 @@
* @return entites E of the query result
* @throws TopiaException if any pb while getting datas
* @since 2.6.14
+ * @deprecated move your code inside the DAO and use {@link AbstractTopiaDao#findAllLazy(String, java.util.Map, Class)}
*/
Iterable<E> findAllLazyByQuery(String hql,
Object... propertyNamesAndValues) throws TopiaException;
@@ -384,6 +327,7 @@
* @return entites R of the query result
* @throws TopiaException if any pb while getting datas
* @since 2.6.14
+ * @deprecated move your code inside the DAO and use {@link AbstractTopiaDao#findAllLazy(String, java.util.Map, Class)}
*/
<R> Iterable<R> findAllLazyByQuery(Class<R> type,
String hql,
@@ -402,6 +346,7 @@
* @return entites E of the query result
* @throws TopiaException if any pb while getting datas
* @since 2.6.14
+ * @deprecated move your code inside the DAO and use {@link AbstractTopiaDao#findAllLazy(String, java.util.Map)}
*/
Iterable<E> findAllLazyByQuery(int batchSize,
String hql,
@@ -421,6 +366,7 @@
* @return entites R of the query result
* @throws TopiaException if any pb while getting datas
* @since 2.6.14
+ * @deprecated move your code inside the DAO and use {@link AbstractTopiaDao#findAllLazy(String, java.util.Map, Class)}
*/
<R> Iterable<R> findAllLazyByQuery(Class<R> type,
int batchSize,
@@ -441,6 +387,7 @@
* @return entites E of the paginated query result
* @throws TopiaException if any pb while getting datas
* @since 2.6.12
+ * @deprecated move your code inside the DAO and use {@link AbstractTopiaDao#findAll(String, java.util.Map, int, int)}
*/
List<E> findAllByQueryWithBound(String hql,
int startIndex,
@@ -462,6 +409,7 @@
* @return entites R of the paginated query result
* @throws TopiaException if any pb while getting datas
* @since 2.6.12
+ * @deprecated move your code inside the DAO and use {@link AbstractTopiaDao#findAll(String, java.util.Map, Class, int, int)}
*/
<R> List<R> findAllByQueryWithBound(Class<R> type,
String hql,
@@ -481,6 +429,7 @@
* @throws TopiaException if any pb while getting datas
* @see TopiaPagerBean
* @since 2.6.12
+ * @deprecated move your code inside the DAO and use {@link AbstractTopiaDao#findAll(String, java.util.Map, org.nuiton.topia.persistence.pager.TopiaPagerBean)}
*/
List<E> findAllByQueryAndPager(String hql,
TopiaPagerBean pager,
@@ -499,6 +448,7 @@
* @throws TopiaException if any pb while getting datas
* @see TopiaPagerBean
* @since 2.6.12
+ * @deprecated move your code inside the DAO and use {@link AbstractTopiaDao#findAll(String, java.util.Map, Class, org.nuiton.topia.persistence.pager.TopiaPagerBean)}
*/
<R> List<R> findAllByQueryAndPager(Class<R> type,
String hql,
@@ -514,6 +464,7 @@
* @return all the entities E found
* @throws TopiaException if any pb while getting datas
* @since 2.5.4
+ * @deprecated use new API and inline {@link LegacyTopiaDao#findAllContains(String, Object)}
*/
List<E> findAllContains(String propertyName,
Object value) throws TopiaException;
@@ -529,6 +480,7 @@
* @return true if entity exists, false otherwise
* @throws TopiaException for any error
* @since 2.3.4
+ * @deprecated use new API and inline {@link LegacyTopiaDao#existByTopiaId(String)}
*/
boolean existByTopiaId(String id) throws TopiaException;
@@ -544,6 +496,7 @@
* @return true if entity exists, false otherwise
* @throws TopiaException for Topia errors
* @since 2.3.4
+ * @deprecated move your code inside the DAO and use {@link AbstractTopiaDao#exists(String, java.util.Map)}
*/
boolean existByProperties(String propertyName,
Object propertyValue,
@@ -558,6 +511,7 @@
* @return true if entity exists, false otherwise
* @throws TopiaException
* @since 2.6.12
+ * @deprecated move your code inside the DAO and use {@link AbstractTopiaDao#exists(String, java.util.Map)}
*/
boolean existsByQuery(String hql,
Object... propertyNamesAndValues) throws TopiaException;
@@ -567,15 +521,6 @@
//------------------------------------------------------------------------//
/**
- * Count the number of existing entities.
- *
- * @return number of total entities
- * @throws TopiaException if any pb while getting datas
- * @since 2.3.4
- */
- long count() throws TopiaException;
-
- /**
* Count the number of entities based on a the given HQL query.
*
* @param hql the HQL query to use
@@ -584,6 +529,7 @@
* @return number of entities filtered by the query
* @throws TopiaException if any pb while getting datas
* @since 2.6.12
+ * @deprecated move your call to inside the DAO and use {@link AbstractTopiaDao#count(String, java.util.Map)}
*/
long countByQuery(String hql,
Object... propertyNamesAndValues) throws TopiaException;
@@ -593,33 +539,6 @@
//------------------------------------------------------------------------//
/**
- * Find usages of the given {@code entity} in the entities of the given
- * {@code type}.
- *
- * @param type the type of entity to search
- * @param entity the entity on which search is done
- * @param <R> type of entity to search
- * @return the list of entities R which uses the given entity
- * @throws TopiaException if any problem while getting data
- * @since 2.3.0
- */
- <R extends TopiaEntity> List<R> findUsages(Class<R> type,
- E entity) throws TopiaException;
-
- /**
- * Find all usages of the given {@code entity}.
- *
- * @param entity the entity
- * @return the dictionnary of usages of the given entities (keys are entity
- * usage container, values are the list of this type of entity to
- * use the given entity).
- * @throws TopiaException if any pb while getting data
- * @since 2.3.0
- */
-
- Map<Class<? extends TopiaEntity>, List<? extends TopiaEntity>> findAllUsages(E entity) throws TopiaException;
-
- /**
* Execute the count {@code hql} query and then synch the pager to this
* result (says fill the
* {@link TopiaPagerBean#records} field and then adapt
@@ -632,6 +551,8 @@
* @throws TopiaException if any pb while getting datas
* @see TopiaPagerBean
* @since 2.6.12
+ * // TODO brendan 17/10/13 really ??
+ * @deprecated
*/
void computeAndAddRecordsToPager(String hql,
TopiaPagerBean pager,
@@ -642,13 +563,6 @@
//------------------------------------------------------------------------//
/**
- * Return the class of the entity managed by this DAO.
- *
- * @return this DAO's managed entity's class
- */
- Class<E> getEntityClass();
-
- /**
* Returns the context used by this DAO.
*
* @return Returns the context.
@@ -669,28 +583,12 @@
* Get the entityEnum of the type of entity managed by this DAO.
*
* @return entity type enum managed by this DAO
+ * @deprecated you should get it from persistence context or application context
*/
+ @Deprecated
TopiaEntityEnum getTopiaEntityEnum();
/**
- * Obtains the batch size used to load data.
- * <p/>
- * Default value if 1000.
- *
- * @return the batch size.
- * @since 2.6.14
- */
- int getBatchSize();
-
- /**
- * Set a new default batch size.
- *
- * @param batchSize new batch size to use when iterating.
- * @since 2.6.14
- */
- void setBatchSize(int batchSize);
-
- /**
* Create the simple HQL query for the entity managed by the dao.
* <p/>
* A optional alias can be passed:
@@ -705,22 +603,6 @@
@Deprecated
String createSimpleQuery(String alias);
- //------------------------------------------------------------------------//
- //-- Listener methods ----------------------------------------------------//
- //------------------------------------------------------------------------//
-
- // TODO AThimel 20/07/13 Javadoc
- void addTopiaEntityListener(TopiaEntityListener listener);
-
- // TODO AThimel 20/07/13 Javadoc
- void addTopiaEntityVetoable(TopiaEntityVetoable vetoable);
-
- // TODO AThimel 20/07/13 Javadoc
- void removeTopiaEntityListener(TopiaEntityListener listener);
-
- // TODO AThimel 20/07/13 Javadoc
- void removeTopiaEntityVetoable(TopiaEntityVetoable vetoable);
-
/**
* Retourne les permissions a verifier pour l'acces a l'entite pour le
* service Taas.
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAOImpl.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAOImpl.java 2013-10-17 16:14:18 UTC (rev 2846)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAOImpl.java 2013-10-25 12:03:15 UTC (rev 2847)
@@ -85,8 +85,7 @@
* @version $Id$
*/
-public class TopiaDAOImpl<E extends TopiaEntity> implements
- TopiaDAO<E> { // TopiaDAOImpl
+public class TopiaDAOImpl<E extends TopiaEntity> implements TopiaDAO<E> { // TopiaDAOImpl
/** to use log facility, just put in your code: log.info(\"...\"); */
private static Log log = LogFactory.getLog(TopiaDAOImpl.class);
Added: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDao.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDao.java (rev 0)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDao.java 2013-10-25 12:03:15 UTC (rev 2847)
@@ -0,0 +1,214 @@
+package org.nuiton.topia.persistence;
+
+import org.nuiton.topia.event.TopiaEntityListener;
+import org.nuiton.topia.event.TopiaEntityVetoable;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * This contract represents the common operation any DAO should
+ * be able to provide as API.
+ *
+ * @author bleny
+ * @since 3.0
+ */
+public interface TopiaDao<E extends TopiaEntity> extends Iterable<E> {
+
+ /**
+ * Return the class of the entity managed by this DAO.
+ *
+ * @return this DAO's managed entity's class
+ */
+ Class<E> getEntityClass();
+
+ /**
+ * Obtains the batch size used to load data.
+ *
+ * Default value if 1000.
+ *
+ * @return the batch size.
+ * @since 2.6.14
+ */
+ int getBatchSize();
+
+ /**
+ * Set a new default batch size.
+ *
+ * @param batchSize new batch size to use when iterating.
+ * @since 2.6.14
+ */
+ void setBatchSize(int batchSize);
+
+ /**
+ * Create a new instance of managed entity <strong>not persisted</strong>.
+ *
+ * @since 2.3.1
+ */
+ E newInstance();
+
+ /**
+ * Creates an entity not created without the DAO using any of the others
+ * create methods. The instance may have been created elsewhere.
+ *
+ * @param entity the instance to persist
+ * @return the persisted entity (with its topiaId valued)
+ * @since 2.3.1
+ */
+ E create(E entity);
+
+ /**
+ * @since 3.0
+ */
+ E create(String propertyName, Object propertyValue, Object... otherPropertyNamesAndValues);
+
+ /**
+ * Creates a new instance of the entity managed by the DAO
+ *
+ * @param properties the key-value list of properties that the created entity will have.
+ * @return the newly created entity
+ * @throws IllegalArgumentException if some property type is not the
+ * expected one
+ */
+ E create(Map<String, Object> properties);
+
+ /**
+ * @since 3.0
+ */
+ E create();
+
+ /**
+ * Update an entity. May be used for an entity coming from another context.
+ *
+ * @param entity the entity to create or update
+ * @return the given entity
+ */
+ E update(E entity);
+
+ /**
+ * Deletes the given entity from the storage
+ *
+ * @param entity the entity to remove
+ */
+ void delete(E entity);
+
+ /**
+ * Deletes all given entities from the storage
+ *
+ * @param entities entities to delete
+ * @since 3.0
+ */
+ void deleteAll(Iterable<E> entities);
+
+ /**
+ * Finds all the entities managed by this DAO.
+ *
+ * @return the full list of entities in no particular
+ * (non-determinisic) order
+ */
+ List<E> findAll();
+
+ /**
+ * @since 3.0
+ */
+ Iterable<E> findAllLazy();
+
+ /**
+ * @since 3.0
+ */
+ Iterable<E> createAll(Iterable<E> entities);
+
+ /**
+ * @since 3.0
+ */
+ Iterable<E> updateAll(Iterable<E> entities);
+
+ /**
+ * Find all the ids for the entities managed by this DAO.
+ *
+ * @return the ids of all the entities
+ */
+ // TODO AThimel 20/07/13 This method should return a Set ?
+ List<String> findAllIds();
+
+ /**
+ * Count the number of existing entities.
+ *
+ * @return number of total entities
+ * @since 2.3.4
+ */
+ long count();
+
+ /**
+ * @since 3.0
+ */
+ TopiaQueryBuilderAddCriteriaOrRunQueryStep<E> forProperties(Map<String, Object> properties);
+
+ /**
+ * @since 3.0
+ */
+ TopiaQueryBuilderAddCriteriaOrRunQueryStep<E> forProperties(String propertyName,
+ Object propertyValue,
+ Object... otherPropertyNamesAndValues);
+ /**
+ * @since 3.0
+ */
+ TopiaQueryBuilderAddCriteriaStep<E> newQueryBuilder();
+
+ /**
+ * @since 3.0
+ */
+ TopiaQueryBuilderRunQueryStep<E> forContains(String propertyName, Object propertyValue);
+
+ /**
+ * @since 3.0
+ */
+ TopiaQueryBuilderRunQueryStep<E> forEquals(String propertyName, Object propertyValue);
+
+ /**
+ * @since 3.0
+ */
+ TopiaQueryBuilderRunQueryStep<E> forIn(String propertyName, Iterable<Object> propertyValues);
+
+ /**
+ * @since 3.0
+ */
+ TopiaQueryBuilderRunQueryStep<E> forTopiaIdEquals(String topiaId);
+
+ /**
+ * @since 3.0
+ */
+ TopiaQueryBuilderRunQueryStep<E> forTopiaIdIn(Iterable<String> topiaIds);
+
+ void addTopiaEntityListener(TopiaEntityListener listener);
+
+ void addTopiaEntityVetoable(TopiaEntityVetoable vetoable);
+
+ void removeTopiaEntityListener(TopiaEntityListener listener);
+
+ void removeTopiaEntityVetoable(TopiaEntityVetoable vetoable);
+
+ /**
+ * Find usages of the given {@code entity} in the entities of the given
+ * {@code type}.
+ *
+ * @param type the type of entity to search
+ * @param entity the entity on which search is done
+ * @param <R> type of entity to search
+ * @return the list of entities R which uses the given entity
+ * @since 2.3.0
+ */
+ <R extends TopiaEntity> List<R> findUsages(Class<R> type, E entity);
+
+ /**
+ * Find all usages of the given {@code entity}.
+ *
+ * @param entity the entity
+ * @return the dictionnary of usages of the given entities (keys are entity
+ * usage container, values are the list of this type of entity to
+ * use the given entity).
+ * @since 2.3.0
+ */
+ Map<Class<? extends TopiaEntity>, List<? extends TopiaEntity>> findAllUsages(E entity);
+
+}
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaEntityAbstract.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaEntityAbstract.java 2013-10-17 16:14:18 UTC (rev 2846)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaEntityAbstract.java 2013-10-25 12:03:15 UTC (rev 2847)
@@ -208,7 +208,7 @@
if (fireSupport == null) {
if (this instanceof TopiaEntityContextable) {
TopiaEntityContextable contextable = (TopiaEntityContextable) this;
- AbstractTopiaDAO topiaDAO = (AbstractTopiaDAO)contextable.getTopiaDAOSupplier().getDao(getClass());
+ AbstractTopiaDao topiaDAO = (AbstractTopiaDao)contextable.getTopiaDAOSupplier().getDao(getClass());
fireSupport = topiaDAO.getTopiaFiresSupport();
}
}
Added: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaQueryBuilderAddCriteriaOrRunQueryStep.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaQueryBuilderAddCriteriaOrRunQueryStep.java (rev 0)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaQueryBuilderAddCriteriaOrRunQueryStep.java 2013-10-25 12:03:15 UTC (rev 2847)
@@ -0,0 +1,5 @@
+package org.nuiton.topia.persistence;
+
+public interface TopiaQueryBuilderAddCriteriaOrRunQueryStep<E extends TopiaEntity> extends TopiaQueryBuilderAddCriteriaStep<E>, TopiaQueryBuilderRunQueryStep<E> {
+
+}
Added: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaQueryBuilderAddCriteriaStep.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaQueryBuilderAddCriteriaStep.java (rev 0)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaQueryBuilderAddCriteriaStep.java 2013-10-25 12:03:15 UTC (rev 2847)
@@ -0,0 +1,59 @@
+package org.nuiton.topia.persistence;
+
+import java.util.Set;
+
+/**
+ * Represents a step when building a query to add a constraint.
+ *
+ * The builder implements the fluent interface DP, so you can add multiple
+ * constraints by chaining calls.
+ *
+ * @author bleny
+ * @since 3.0
+ */
+public interface TopiaQueryBuilderAddCriteriaStep<E extends TopiaEntity> {
+
+ /**
+ * @param property the name of a field of the queried entity, must be
+ * a one-to-one or a many-to-one property.
+ * @param value the value the field of the entity must be equals to argument
+ */
+ TopiaQueryBuilderAddCriteriaOrRunQueryStep<E> addEquals(String property, Object value);
+
+ /**
+ * @param property the name of a field of the queried entity, must be
+ * a one-to-one or a many-to-one property
+ * @param values the value the field of the entity must be equals to argument
+ */
+ TopiaQueryBuilderAddCriteriaOrRunQueryStep<E> addIn(String property, Iterable<Object> values);
+
+ /**
+ * @param property the name of a field of the queried entity, must be
+ * a one-to-many or a many-to-many property
+ * @param value the value the field of the entity must be equals to argument
+ */
+ TopiaQueryBuilderAddCriteriaOrRunQueryStep<E> addContains(String property, Object value);
+
+ /**
+ * @param property the name of a field of the queried entity, must be
+ * a one-to-one or a many-to-one property
+ */
+ TopiaQueryBuilderAddCriteriaOrRunQueryStep<E> addNull(String property);
+
+ /**
+ * This method has the same behavior as {@link #addEquals(String, Object)} but
+ * you don't need to have the entity but only the topiaId.
+ *
+ * @param property the name of a field of the queried entity, must be
+ * a one-to-one or a many-to-one property
+ * @param topiaId the
+ */
+ TopiaQueryBuilderAddCriteriaOrRunQueryStep<E> addTopiaIdEquals(String property, String topiaId);
+
+ TopiaQueryBuilderAddCriteriaOrRunQueryStep<E> addTopiaIdIn(String property, Iterable<String> topiaIds);
+
+ TopiaQueryBuilderRunQueryStep<E> setOrderByArguments(Set<String> orderByArguments);
+
+ TopiaQueryBuilderRunQueryStep<E> setOrderByArguments(String... orderByArguments);
+
+}
Added: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaQueryBuilderRunQueryStep.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaQueryBuilderRunQueryStep.java (rev 0)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaQueryBuilderRunQueryStep.java 2013-10-25 12:03:15 UTC (rev 2847)
@@ -0,0 +1,44 @@
+package org.nuiton.topia.persistence;
+
+import com.google.common.base.Optional;
+
+import java.util.List;
+
+/**
+ * @author bleny
+ */
+public interface TopiaQueryBuilderRunQueryStep<E extends TopiaEntity> {
+
+ boolean exists();
+
+ long count();
+
+ E findUnique();
+
+ E findUniqueOrNull();
+
+ Optional<E> tryFindUnique();
+
+ E findFirst();
+
+ E findFirstOrNull();
+
+ Optional<E> tryFindFirst();
+
+ E findAny();
+
+ E findAnyOrNull();
+
+ Optional<E> tryFindAny();
+
+ List<E> findAll();
+
+ Iterable<E> findAllLazy();
+
+ List<E> findAll(int startIndex, int endIndex);
+
+ List<String> findAllIds();
+
+ List<String> findAllIds(int startIndex, int endIndex);
+
+}
Modified: trunk/topia-persistence/src/test/java/org/nuiton/topia/GeneratedPersonneTopiaDao.java
===================================================================
--- trunk/topia-persistence/src/test/java/org/nuiton/topia/GeneratedPersonneTopiaDao.java 2013-10-17 16:14:18 UTC (rev 2846)
+++ trunk/topia-persistence/src/test/java/org/nuiton/topia/GeneratedPersonneTopiaDao.java 2013-10-25 12:03:15 UTC (rev 2847)
@@ -27,7 +27,7 @@
import java.util.List;
import java.util.Map;
-import org.nuiton.topia.persistence.AbstractTopiaDAO;
+import org.nuiton.topia.persistence.AbstractTopiaDao;
import org.nuiton.topia.persistence.TopiaEntity;
import org.nuiton.topia.persistence.TopiaEntityEnum;
import org.nuiton.topiatest.Personne;
@@ -35,7 +35,7 @@
/**
* @author Arnaud Thimel <thimel(a)codelutin.com>
*/
-public abstract class GeneratedPersonneTopiaDao<E extends Personne> extends AbstractTopiaDAO<E> implements PersonneDao {
+public abstract class GeneratedPersonneTopiaDao<E extends Personne> extends AbstractTopiaDao<E> implements PersonneDao {
@Override
public TopiaEntityEnum getTopiaEntityEnum() {
Modified: trunk/topia-persistence/src/test/java/org/nuiton/topia/TopiaJpaSupportTest.java
===================================================================
--- trunk/topia-persistence/src/test/java/org/nuiton/topia/TopiaJpaSupportTest.java 2013-10-17 16:14:18 UTC (rev 2846)
+++ trunk/topia-persistence/src/test/java/org/nuiton/topia/TopiaJpaSupportTest.java 2013-10-25 12:03:15 UTC (rev 2847)
@@ -28,10 +28,10 @@
import org.junit.Rule;
import org.junit.Test;
import org.nuiton.topiatest.Address;
-import org.nuiton.topiatest.AddressDAO;
+import org.nuiton.topiatest.AddressTopiaDao;
import org.nuiton.topiatest.Gender;
import org.nuiton.topiatest.Personne;
-import org.nuiton.topiatest.PersonneDAO;
+import org.nuiton.topiatest.PersonneTopiaDao;
import java.util.List;
@@ -47,8 +47,8 @@
protected TopiaTestTopiaPersistenceContext persistenceContext;
protected TopiaJpaSupport jpaSupport;
- protected AddressDAO addressDAO;
- protected PersonneDAO personneDAO;
+ protected AddressTopiaDao addressDAO;
+ protected PersonneTopiaDao personneDAO;
protected Address address;
@Before
Modified: trunk/topia-persistence/src/test/java/org/nuiton/topia/framework/TopiaConnectionProviderTest.java
===================================================================
--- trunk/topia-persistence/src/test/java/org/nuiton/topia/framework/TopiaConnectionProviderTest.java 2013-10-17 16:14:18 UTC (rev 2846)
+++ trunk/topia-persistence/src/test/java/org/nuiton/topia/framework/TopiaConnectionProviderTest.java 2013-10-25 12:03:15 UTC (rev 2847)
@@ -33,7 +33,8 @@
import org.nuiton.topia.TopiaTestDAOHelper;
import org.nuiton.topia.TopiaTestTopiaPersistenceContext;
import org.nuiton.topia.test.entities.Person;
-import org.nuiton.topia.test.entities.PersonDAO;
+import org.nuiton.topia.test.entities.PersonDao;
+import org.nuiton.topia.test.entities.PersonTopiaDao;
import org.nuiton.topiatest.Personne;
import java.io.File;
@@ -125,7 +126,7 @@
TopiaTestTopiaPersistenceContext transaction = db.beginTransaction();
try {
- PersonDAO dao = TopiaTestDAOHelper.getPersonDAO(transaction);
+ PersonTopiaDao dao = TopiaTestDAOHelper.getPersonDAO(transaction);
Person personne = dao.create(Personne.PROPERTY_NAME, "Jack Bauer");
transaction.commitTransaction();
Modified: trunk/topia-persistence/src/test/java/org/nuiton/topia/framework/TopiaContextReplicateTest.java
===================================================================
--- trunk/topia-persistence/src/test/java/org/nuiton/topia/framework/TopiaContextReplicateTest.java 2013-10-17 16:14:18 UTC (rev 2846)
+++ trunk/topia-persistence/src/test/java/org/nuiton/topia/framework/TopiaContextReplicateTest.java 2013-10-25 12:03:15 UTC (rev 2847)
@@ -27,15 +27,14 @@
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.TopiaTestTopiaPersistenceContext;
import org.nuiton.topia.test.entities.Person;
-import org.nuiton.topia.test.entities.PersonDAO;
+import org.nuiton.topia.test.entities.PersonDao;
import org.nuiton.topia.test.entities.Pet;
-import org.nuiton.topia.test.entities.PetDAO;
+import org.nuiton.topia.test.entities.PetDao;
import java.io.File;
import java.util.Properties;
@@ -93,8 +92,8 @@
TopiaTestTopiaPersistenceContext txSource;
TopiaTestTopiaPersistenceContext txTarget;
- PersonDAO daoSource, daoTarget;
- PetDAO petDAOSource, petDAOTarget;
+ PersonDao daoSource, daoTarget;
+ PetDao petDAOSource, petDAOTarget;
Person personSource, personTarget;
Pet petSource, petTarget;
Modified: trunk/topia-persistence/src/test/java/org/nuiton/topia/generator/TopiaTestCase.java
===================================================================
--- trunk/topia-persistence/src/test/java/org/nuiton/topia/generator/TopiaTestCase.java 2013-10-17 16:14:18 UTC (rev 2846)
+++ trunk/topia-persistence/src/test/java/org/nuiton/topia/generator/TopiaTestCase.java 2013-10-25 12:03:15 UTC (rev 2847)
@@ -35,9 +35,9 @@
import org.nuiton.topia.TopiaTestDAOHelper;
import org.nuiton.topia.TopiaTestTopiaPersistenceContext;
import org.nuiton.topiatest.Company;
-import org.nuiton.topiatest.CompanyDAO;
+import org.nuiton.topiatest.CompanyDao;
import org.nuiton.topiatest.Department;
-import org.nuiton.topiatest.DepartmentDAO;
+import org.nuiton.topiatest.DepartmentDao;
/**
* TopiaTestCase.
@@ -123,8 +123,8 @@
// try {
TopiaTestTopiaPersistenceContext newContext = db.beginTransaction();
- CompanyDAO companyDAO = newContext.getCompanyDao();
- DepartmentDAO departmentDAO = newContext.getDepartmentDao();
+ CompanyDao companyDAO = newContext.getCompanyDao();
+ DepartmentDao departmentDAO = newContext.getDepartmentDao();
Company company = companyDAO.create();
company.setName("Ma société");
Modified: trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/EntityVisitorExportXmlTest.java
===================================================================
--- trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/EntityVisitorExportXmlTest.java 2013-10-17 16:14:18 UTC (rev 2846)
+++ trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/EntityVisitorExportXmlTest.java 2013-10-25 12:03:15 UTC (rev 2847)
@@ -34,13 +34,13 @@
import org.nuiton.topia.TopiaException;
import org.nuiton.topia.TopiaTestTopiaPersistenceContext;
import org.nuiton.topiatest.Address;
-import org.nuiton.topiatest.AddressDAO;
+import org.nuiton.topiatest.AddressTopiaDao;
import org.nuiton.topiatest.Company;
-import org.nuiton.topiatest.CompanyDAO;
+import org.nuiton.topiatest.CompanyTopiaDao;
import org.nuiton.topiatest.Department;
-import org.nuiton.topiatest.DepartmentDAO;
+import org.nuiton.topiatest.DepartmentTopiaDao;
import org.nuiton.topiatest.Employe;
-import org.nuiton.topiatest.EmployeDAO;
+import org.nuiton.topiatest.EmployeTopiaDao;
/**
* Test de visitor.
@@ -72,14 +72,14 @@
TopiaTestTopiaPersistenceContext newContext = db.beginTransaction();
try {
// company
- CompanyDAO companyDAO = newContext.getCompanyDao();
+ CompanyTopiaDao companyDAO = newContext.getCompanyDao();
Company clCompany = companyDAO.create(Company.PROPERTY_NAME, "CodeLutin");
// employe
- EmployeDAO employeDAO = newContext.getEmployeDao();
+ EmployeTopiaDao employeDAO = newContext.getEmployeDao();
Employe empl1 = employeDAO.create(Employe.PROPERTY_NAME, "boss", Employe.PROPERTY_SALARY, 30000);
- AddressDAO adressDAO = newContext.getAddressDao();
+ AddressTopiaDao adressDAO = newContext.getAddressDao();
Address addr1 = adressDAO.create(Address.PROPERTY_CITY, "Nantes", Address.PROPERTY_ADRESS, "12 Avenue Jules Vernes");
empl1.setAddress(addr1);
@@ -88,7 +88,7 @@
empl2.setAddress(addr2);
// departement
- DepartmentDAO departmentDAO = newContext.getDepartmentDao();
+ DepartmentTopiaDao departmentDAO = newContext.getDepartmentDao();
Department depComm = departmentDAO.create(Department.PROPERTY_NAME, "Commercial");
depComm.setLeader(empl1);
@@ -117,7 +117,7 @@
TopiaTestTopiaPersistenceContext context = db.beginTransaction();
- CompanyDAO companyDAO = context.getCompanyDao();
+ CompanyTopiaDao companyDAO = context.getCompanyDao();
Company clCompany = companyDAO.findByName("CodeLutin");
EntityVisitor delegateVisitor = new ExportXMLVisitor();
Modified: trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/NaturalIdTest.java
===================================================================
--- trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/NaturalIdTest.java 2013-10-17 16:14:18 UTC (rev 2846)
+++ trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/NaturalIdTest.java 2013-10-25 12:03:15 UTC (rev 2847)
@@ -36,7 +36,7 @@
import org.nuiton.topia.TopiaTestDAOHelper;
import org.nuiton.topia.TopiaTestTopiaPersistenceContext;
import org.nuiton.topiatest.NaturalizedEntity;
-import org.nuiton.topiatest.NaturalizedEntityDAO;
+import org.nuiton.topiatest.NaturalizedEntityDao;
/**
* NaturalIdTest
@@ -61,7 +61,7 @@
log.debug("Test naturalId : create succesfull");
TopiaTestTopiaPersistenceContext persistenceContext = db.beginTransaction();
- NaturalizedEntityDAO dao =
+ NaturalizedEntityDao dao =
persistenceContext.getNaturalizedEntityDao();
// No exception will be thrown with the two properties
@@ -82,7 +82,7 @@
log.debug("Test naturalId : create failed");
TopiaTestTopiaPersistenceContext persistenceContext = db.beginTransaction();
- NaturalizedEntityDAO dao =
+ NaturalizedEntityDao dao =
persistenceContext.getNaturalizedEntityDao();
// Exception will be throw
@@ -108,7 +108,7 @@
TopiaTestTopiaPersistenceContext persistenceContext = db.beginTransaction();
- NaturalizedEntityDAO dao =
+ NaturalizedEntityDao dao =
persistenceContext.getNaturalizedEntityDao();
NaturalizedEntity entity =
@@ -131,7 +131,7 @@
TopiaTestTopiaPersistenceContext persistenceContext = db.beginTransaction();
- NaturalizedEntityDAO dao =
+ NaturalizedEntityDao dao =
persistenceContext.getNaturalizedEntityDao();
NaturalizedEntity entity =
@@ -149,7 +149,7 @@
TopiaTestTopiaPersistenceContext persistenceContext = db.beginTransaction();
- NaturalizedEntityDAO dao =
+ NaturalizedEntityDao dao =
persistenceContext.getNaturalizedEntityDao();
dao.createByNaturalId(5, "str");
Modified: trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/TopiaDAOTest.java
===================================================================
--- trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/TopiaDAOTest.java 2013-10-17 16:14:18 UTC (rev 2846)
+++ trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/TopiaDAOTest.java 2013-10-25 12:03:15 UTC (rev 2847)
@@ -35,7 +35,7 @@
import org.nuiton.topia.TopiaException;
import org.nuiton.topia.TopiaTestTopiaPersistenceContext;
import org.nuiton.topia.test.entities.Person;
-import org.nuiton.topia.test.entities.PersonDAO;
+import org.nuiton.topia.test.entities.PersonDao;
import java.util.List;
@@ -55,7 +55,7 @@
protected TopiaTestTopiaPersistenceContext context;
- protected PersonDAO dao;
+ protected PersonDao dao;
@Before
public void setup() throws TopiaException {
Modified: trunk/topia-persistence/src/test/java/org/nuiton/topia/test/ano1882/DAOAbstractTransformerTest.java
===================================================================
--- trunk/topia-persistence/src/test/java/org/nuiton/topia/test/ano1882/DAOAbstractTransformerTest.java 2013-10-17 16:14:18 UTC (rev 2846)
+++ trunk/topia-persistence/src/test/java/org/nuiton/topia/test/ano1882/DAOAbstractTransformerTest.java 2013-10-25 12:03:15 UTC (rev 2847)
@@ -26,7 +26,6 @@
import org.junit.Rule;
import org.junit.Test;
-import org.nuiton.topia.TopiaContext;
import org.nuiton.topia.TopiaDatabase;
import org.nuiton.topia.TopiaTestDAOHelper;
import org.nuiton.topia.TopiaTestTopiaPersistenceContext;
@@ -42,7 +41,7 @@
public void testAno1882() throws Exception {
TopiaTestTopiaPersistenceContext transaction = db.beginTransaction();
- FrenchCompanyDAO dao = TopiaTestDAOHelper.getFrenchCompanyDAO(transaction);
+ FrenchCompanyDao dao = TopiaTestDAOHelper.getFrenchCompanyDAO(transaction);
SIRETDAO siretDAO = TopiaTestDAOHelper.getSIRETDAO(transaction);
SIRET siret = siretDAO.create();
FrenchCompany entity =
Modified: trunk/topia-persistence/src/test/java/org/nuiton/topiatest/EnumTest.java
===================================================================
--- trunk/topia-persistence/src/test/java/org/nuiton/topiatest/EnumTest.java 2013-10-17 16:14:18 UTC (rev 2846)
+++ trunk/topia-persistence/src/test/java/org/nuiton/topiatest/EnumTest.java 2013-10-25 12:03:15 UTC (rev 2847)
@@ -27,7 +27,6 @@
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;
@@ -54,7 +53,7 @@
public void storeEntityWithEnumValue() throws TopiaException {
TopiaTestTopiaPersistenceContext transaction = db.beginTransaction();
- PersonneDAO dao = TopiaTestDAOHelper.getPersonneDAO(transaction);
+ PersonneDao dao = TopiaTestDAOHelper.getPersonneDAO(transaction);
Personne personne = new PersonneImpl();
personne.setGender(Gender.FEMALE);
personne.setOtherGender(Gender.MALE);
Modified: trunk/topia-persistence/src/test/java/org/nuiton/topiatest/deletetest/DeleteEntityTest.java
===================================================================
--- trunk/topia-persistence/src/test/java/org/nuiton/topiatest/deletetest/DeleteEntityTest.java 2013-10-17 16:14:18 UTC (rev 2846)
+++ trunk/topia-persistence/src/test/java/org/nuiton/topiatest/deletetest/DeleteEntityTest.java 2013-10-25 12:03:15 UTC (rev 2847)
@@ -43,14 +43,13 @@
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.TopiaTestTopiaPersistenceContext;
import org.nuiton.topiatest.Gender;
import org.nuiton.topiatest.Personne;
-import org.nuiton.topiatest.PersonneDAO;
+import org.nuiton.topiatest.PersonneDao;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
@@ -85,7 +84,7 @@
TopiaTestTopiaPersistenceContext transaction = db.beginTransaction();
log.debug("DAO : PersonneDAO");
- PersonneDAO dao = TopiaTestDAOHelper.getPersonneDAO(transaction);
+ PersonneDao dao = TopiaTestDAOHelper.getPersonneDAO(transaction);
log.debug("CREATE PERSONNE : Bob Marley");
Personne personne = dao.create(Personne.PROPERTY_NAME, "Bob Marley");
@@ -135,7 +134,7 @@
TopiaTestTopiaPersistenceContext transaction = db.beginTransaction();
- PersonneDAO dao = TopiaTestDAOHelper.getPersonneDAO(transaction);
+ PersonneDao dao = TopiaTestDAOHelper.getPersonneDAO(transaction);
log.debug("CREATE PERSONNE : Bob Marley");
Personne personne = dao.create(Personne.PROPERTY_NAME, "Bob Marley");
@@ -186,7 +185,7 @@
TopiaTestTopiaPersistenceContext transaction = db.beginTransaction();
- PersonneDAO dao = TopiaTestDAOHelper.getPersonneDAO(transaction);
+ PersonneDao dao = TopiaTestDAOHelper.getPersonneDAO(transaction);
Personne person = dao.newInstance();
Assert.assertNull(person.getTopiaId());
1
0
Author: bleny
Date: 2013-10-17 18:14:18 +0200 (Thu, 17 Oct 2013)
New Revision: 2846
Url: http://nuiton.org/projects/topia/repository/revisions/2846
Log:
refs #2086 rename DAO to Dao to prevent confusing names
Added:
trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaDaoSupplier.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityDaoTransformer.java
Removed:
trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaDAOSupplier.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityDAOTransformer.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/LegacyEntityDAOTransformer.java
Modified:
trunk/topia-persistence/src/main/java/org/nuiton/topia/AbstractTopiaPersistenceContext.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaPersistenceContext.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/AbstractTopiaContext.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaContextImplementor.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaHibernateEventListener.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/DAOHelperTransformer.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityTransformer.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/PersistenceContextTransformer.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/TopiaMetaTransformer.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/AbstractTopiaDAO.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAO.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaEntityAbstract.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaEntityContextable.java
trunk/topia-service-replication/src/main/java/org/nuiton/topia/replication/TopiaReplicationContext.java
trunk/topia-service-replication/src/main/java/org/nuiton/topia/replication/operation/Duplicate.java
trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/AbstractTopiaReplicationServiceTest.java
trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/TopiaReplicationOperationTest.java
trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/TopiaReplicationServiceImplAllTest.java
trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/TopiaReplicationServiceImplTest.java
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/AbstractTopiaPersistenceContext.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/AbstractTopiaPersistenceContext.java 2013-10-15 15:08:16 UTC (rev 2845)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/AbstractTopiaPersistenceContext.java 2013-10-17 16:14:18 UTC (rev 2846)
@@ -212,7 +212,7 @@
checkClosed();
Class<E> entityClass = getTopiaIdFactory().getClassName(topiaId);
- TopiaDAO<E> dao = getDAO(entityClass);
+ TopiaDAO<E> dao = getDao(entityClass);
E result = dao.findByTopiaId(topiaId);
return result;
}
@@ -223,7 +223,7 @@
String topiaId = entity.getTopiaId();
Class<TopiaEntity> entityClass = getTopiaIdFactory().getClassName(topiaId);
- TopiaDAO<TopiaEntity> dao = getDAO(entityClass);
+ TopiaDAO<TopiaEntity> dao = getDao(entityClass);
dao.update(entity);
}
@@ -234,8 +234,8 @@
}
@Override
- public <E extends TopiaEntity> TopiaDAO<E> getDAO(Class<E> entityClass) {
- Preconditions.checkArgument(entityClass != null, "The method 'getDAO' requires a non null 'entityClass' parameter");
+ public <E extends TopiaEntity> TopiaDAO<E> getDao(Class<E> entityClass) {
+ Preconditions.checkArgument(entityClass != null, "The method 'getDao' requires a non null 'entityClass' parameter");
SessionFactory hibernateFactory = hibernateSupport.getHibernateFactory();
if (hibernateFactory.getClassMetadata(entityClass) == null &&
@@ -291,8 +291,8 @@
}
@Override
- public <E extends TopiaEntity, D extends TopiaDAO<E>> D getDAO(Class<E> entityClass, Class<D> daoClass) {
- return (D) getDAO(entityClass);
+ public <E extends TopiaEntity, D extends TopiaDAO<E>> D getDao(Class<E> entityClass, Class<D> daoClass) {
+ return (D) getDao(entityClass);
}
@Override
Deleted: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaDAOSupplier.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaDAOSupplier.java 2013-10-15 15:08:16 UTC (rev 2845)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaDAOSupplier.java 2013-10-17 16:14:18 UTC (rev 2846)
@@ -1,54 +0,0 @@
-package org.nuiton.topia;
-
-/*
- * #%L
- * ToPIA :: Persistence
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2004 - 2013 CodeLutin
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>.
- * #L%
- */
-
-import org.nuiton.topia.persistence.TopiaDAO;
-import org.nuiton.topia.persistence.TopiaEntity;
-
-/**
- * @author bleny
- */
-public interface TopiaDAOSupplier {
-
- /**
- * Get DAO for specified class. If Specialized DAO exists then it returned
- * otherwize TopiaDAO<entityClass> is returned
- *
- * @param entityClass type of entity
- * @return the expected dao
- */
- <E extends TopiaEntity> TopiaDAO<E> getDAO(Class<E> entityClass);
-
- /**
- * Get DAO for specified class. If Specialized DAO exists then it returned
- * otherwize TopiaDAO<entityClass> is returned
- *
- * @param entityClass type of entity
- * @param daoClass the concrete dao class to use
- * @return the expected dao
- */
- <E extends TopiaEntity, D extends TopiaDAO<E>> D getDAO(Class<E> entityClass, Class<D> daoClass);
-
-}
Copied: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaDaoSupplier.java (from rev 2845, trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaDAOSupplier.java)
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaDaoSupplier.java (rev 0)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaDaoSupplier.java 2013-10-17 16:14:18 UTC (rev 2846)
@@ -0,0 +1,54 @@
+package org.nuiton.topia;
+
+/*
+ * #%L
+ * ToPIA :: Persistence
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2004 - 2013 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
+
+import org.nuiton.topia.persistence.TopiaDAO;
+import org.nuiton.topia.persistence.TopiaEntity;
+
+/**
+ * @author bleny
+ */
+public interface TopiaDaoSupplier {
+
+ /**
+ * Get DAO for specified class. If Specialized DAO exists then it returned
+ * otherwize TopiaDAO<entityClass> is returned
+ *
+ * @param entityClass type of entity
+ * @return the expected dao
+ */
+ <E extends TopiaEntity> TopiaDAO<E> getDao(Class<E> entityClass);
+
+ /**
+ * Get DAO for specified class. If Specialized DAO exists then it returned
+ * otherwize TopiaDAO<entityClass> is returned
+ *
+ * @param entityClass type of entity
+ * @param daoClass the concrete dao class to use
+ * @return the expected dao
+ */
+ <E extends TopiaEntity, D extends TopiaDAO<E>> D getDao(Class<E> entityClass, Class<D> daoClass);
+
+}
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaPersistenceContext.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaPersistenceContext.java 2013-10-15 15:08:16 UTC (rev 2845)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaPersistenceContext.java 2013-10-17 16:14:18 UTC (rev 2846)
@@ -38,7 +38,7 @@
* @author Arnaud Thimel <thimel(a)codelutin.com>
* @since 3.0
*/
-public interface TopiaPersistenceContext extends TopiaReplicationSupport, TopiaReplicationDestination, TopiaDAOSupplier, TopiaTransaction {
+public interface TopiaPersistenceContext extends TopiaReplicationSupport, TopiaReplicationDestination, TopiaDaoSupplier, TopiaTransaction {
/**
* Retrieve {@link org.nuiton.topia.persistence.TopiaEntity} using its unique {@code topiaId}.
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/AbstractTopiaContext.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/AbstractTopiaContext.java 2013-10-15 15:08:16 UTC (rev 2845)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/AbstractTopiaContext.java 2013-10-17 16:14:18 UTC (rev 2846)
@@ -707,12 +707,12 @@
/* -------------------- CHILD CONTEXT AND DAOS --------------------------*/
@Override
- public <E extends TopiaEntity> TopiaDAO<E> getDAO(Class<E> entityClass)
+ public <E extends TopiaEntity> TopiaDAO<E> getDao(Class<E> entityClass)
throws TopiaException {
if (entityClass == null) {
throw new IllegalArgumentException(
String.format("The method '%1$s' requires a non null parameter '%2$s'.",
- "entityClass", "getDAO"));
+ "entityClass", "getDao"));
}
if (equals(getRootContext())) {
throw new TopiaException(
@@ -761,9 +761,9 @@
@SuppressWarnings({"unchecked"})
@Override
- public <E extends TopiaEntity, D extends TopiaDAO<E>> D getDAO(Class<E> entityClass,
+ public <E extends TopiaEntity, D extends TopiaDAO<E>> D getDao(Class<E> entityClass,
Class<D> daoClass) throws TopiaException {
- return (D) getDAO(entityClass);
+ return (D) getDao(entityClass);
}
@Override
@@ -983,7 +983,7 @@
"findByTopiaId"));
Class<E> entityClass = getTopiaIdFactory().getClassName(id);
- TopiaDAO<E> dao = getDAO(entityClass);
+ TopiaDAO<E> dao = getDao(entityClass);
E result = dao.findByTopiaId(id);
return result;
}
@@ -1612,7 +1612,7 @@
String id = entity.getTopiaId();
Class<TopiaEntity> entityClass = getTopiaIdFactory().getClassName(id);
- TopiaDAO<TopiaEntity> dao = getDAO(entityClass);
+ TopiaDAO<TopiaEntity> dao = getDao(entityClass);
dao.update(entity);
}
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaContextImplementor.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaContextImplementor.java 2013-10-15 15:08:16 UTC (rev 2845)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaContextImplementor.java 2013-10-17 16:14:18 UTC (rev 2846)
@@ -146,7 +146,7 @@
* @deprecated use method from {@link org.nuiton.topia.TopiaPersistenceContext}
*/
@Deprecated
- <E extends TopiaEntity> TopiaDAO<E> getDAO(Class<E> entityClass)
+ <E extends TopiaEntity> TopiaDAO<E> getDao(Class<E> entityClass)
throws TopiaException;
/**
@@ -161,7 +161,7 @@
* @deprecated use method from {@link org.nuiton.topia.TopiaPersistenceContext}
*/
@Deprecated
- <E extends TopiaEntity, D extends TopiaDAO<E>> D getDAO(Class<E> entityClass, Class<D> daoClass)
+ <E extends TopiaEntity, D extends TopiaDAO<E>> D getDao(Class<E> entityClass, Class<D> daoClass)
throws TopiaException;
/**
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaHibernateEventListener.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaHibernateEventListener.java 2013-10-15 15:08:16 UTC (rev 2845)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaHibernateEventListener.java 2013-10-17 16:14:18 UTC (rev 2846)
@@ -47,7 +47,7 @@
import org.hibernate.event.spi.PreUpdateEventListener;
import org.hibernate.event.spi.SaveOrUpdateEvent;
import org.hibernate.event.spi.SaveOrUpdateEventListener;
-import org.nuiton.topia.TopiaDAOSupplier;
+import org.nuiton.topia.TopiaDaoSupplier;
import org.nuiton.topia.TopiaException;
import org.nuiton.topia.persistence.AbstractTopiaDAO;
import org.nuiton.topia.persistence.TopiaEntity;
@@ -116,7 +116,7 @@
}
private void attachContext(Object entity,
- TopiaDAOSupplier daoSupplier) {
+ TopiaDaoSupplier daoSupplier) {
if (entity instanceof TopiaEntityContextable) {
TopiaEntityContextable topiaEntityContextable = (TopiaEntityContextable) entity;
if (topiaEntityContextable.getTopiaDAOSupplier() == null) {
@@ -184,11 +184,11 @@
public void onPostLoad(PostLoadEvent event) {
// TopiaContextImplementor context = getContext(rootContext, event
// .getSession());
- TopiaDAOSupplier daoSupplier = null; // TODO brendan 30/09/13 Implment
+ TopiaDaoSupplier daoSupplier = null; // TODO brendan 30/09/13 Implment
if (daoSupplier != null && event.getEntity() instanceof TopiaEntity) {
attachContext(event.getEntity(), daoSupplier);
TopiaEntity entity = (TopiaEntity) event.getEntity();
- AbstractTopiaDAO<? extends TopiaEntity> dao = (AbstractTopiaDAO) daoSupplier.getDAO(entity.getClass());
+ AbstractTopiaDAO<? extends TopiaEntity> dao = (AbstractTopiaDAO) daoSupplier.getDao(entity.getClass());
dao.getTopiaFiresSupport().fireOnPostLoad(dao, (TopiaEntity) event.getEntity(), new Object[]{});
}
}
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/DAOHelperTransformer.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/DAOHelperTransformer.java 2013-10-15 15:08:16 UTC (rev 2845)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/DAOHelperTransformer.java 2013-10-17 16:14:18 UTC (rev 2846)
@@ -39,7 +39,7 @@
import org.nuiton.eugene.models.object.xml.ObjectModelAttributeImpl;
import org.nuiton.eugene.models.object.xml.ObjectModelEnumerationImpl;
import org.nuiton.topia.TopiaContext;
-import org.nuiton.topia.TopiaDAOSupplier;
+import org.nuiton.topia.TopiaDaoSupplier;
import org.nuiton.topia.TopiaException;
import org.nuiton.topia.persistence.TopiaDAO;
import org.nuiton.topia.persistence.TopiaEntity;
@@ -184,12 +184,12 @@
// specialized getXXXDao method
op = addOperation(daoHelper, "get" + daoClazzName, clazz.getPackageName() + '.' + daoClazzName, ObjectModelJavaModifier.PUBLIC, ObjectModelJavaModifier.STATIC);
- addParameter(op, TopiaDAOSupplier.class, "supplier");
+ addParameter(op, TopiaDaoSupplier.class, "supplier");
addImport(daoHelper, clazz);
addException(op, TopiaException.class);
setOperationBody(op, ""
/*{
- <%=daoClazzName%> result = supplier.getDAO(<%=clazzName%>.class, <%=daoClazzName%>.class);
+ <%=daoClazzName%> result = supplier.getDao(<%=clazzName%>.class, <%=daoClazzName%>.class);
return result;
}*/
);
@@ -197,26 +197,26 @@
}
// generic getDao method
- op = addOperation(daoHelper, "getDAO", "<T extends TopiaEntity, D extends TopiaDAO<? super T>> D", ObjectModelJavaModifier.PUBLIC, ObjectModelJavaModifier.STATIC);
+ op = addOperation(daoHelper, "getDao", "<T extends TopiaEntity, D extends TopiaDAO<? super T>> D", ObjectModelJavaModifier.PUBLIC, ObjectModelJavaModifier.STATIC);
addParameter(op, TopiaContext.class, "context");
addParameter(op, "Class<T>", "klass");
addException(op, TopiaException.class);
setOperationBody(op, ""
/*{
<%=entityEnumName%> constant = <%=entityEnumName%>.valueOf(klass);
- D dao = (D) context.getDAO(constant.getContract());
+ D dao = (D) context.getDao(constant.getContract());
return dao;
}*/
);
- op = addOperation(daoHelper, "getDAO", "<T extends TopiaEntity, D extends TopiaDAO<? super T>> D", ObjectModelJavaModifier.PUBLIC, ObjectModelJavaModifier.STATIC);
+ op = addOperation(daoHelper, "getDao", "<T extends TopiaEntity, D extends TopiaDAO<? super T>> D", ObjectModelJavaModifier.PUBLIC, ObjectModelJavaModifier.STATIC);
addParameter(op, TopiaContext.class, "context");
addParameter(op, "T", "entity");
addException(op, TopiaException.class);
setOperationBody(op, ""
/*{
<%=entityEnumName%> constant = <%=entityEnumName%>.valueOf(entity);
- D dao = (D) context.getDAO(constant.getContract());
+ D dao = (D) context.getDao(constant.getContract());
return dao;
}*/
);
Deleted: trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityDAOTransformer.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityDAOTransformer.java 2013-10-15 15:08:16 UTC (rev 2845)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityDAOTransformer.java 2013-10-17 16:14:18 UTC (rev 2846)
@@ -1,1113 +0,0 @@
-/*
- * #%L
- * ToPIA :: Persistence
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2004 - 2011 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.generator;
-
-/*{generator option: parentheses = false}*/
-/*{generator option: writeString = +}*/
-
-import com.google.common.collect.Sets;
-import org.apache.commons.collections.CollectionUtils;
-import org.apache.commons.lang3.StringUtils;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.nuiton.eugene.GeneratorUtil;
-import org.nuiton.eugene.java.JavaGeneratorUtil;
-import org.nuiton.eugene.java.ObjectModelTransformerToJava;
-import org.nuiton.eugene.models.object.ObjectModel;
-import org.nuiton.eugene.models.object.ObjectModelAssociationClass;
-import org.nuiton.eugene.models.object.ObjectModelAttribute;
-import org.nuiton.eugene.models.object.ObjectModelClass;
-import org.nuiton.eugene.models.object.ObjectModelClassifier;
-import org.nuiton.eugene.models.object.ObjectModelDependency;
-import org.nuiton.eugene.models.object.ObjectModelInterface;
-import org.nuiton.eugene.models.object.ObjectModelJavaModifier;
-import org.nuiton.eugene.models.object.ObjectModelOperation;
-import org.nuiton.topia.TopiaException;
-import org.nuiton.topia.persistence.TopiaEntity;
-
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.TreeMap;
-
-/**
- * To generate all <code>DAO</code> related classes for a given entity.
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @since 2.5.4
- * @plexus.component role="org.nuiton.eugene.Template" role-hint="org.nuiton.topia.generator.EntityDAOTransformer"
- */
-public class EntityDAOTransformer extends ObjectModelTransformerToJava {
-
- /** Logger. */
- private static final Log log =
- LogFactory.getLog(EntityDAOTransformer.class);
-
- /**
- * map of direct usages (values) for each entity (key).
- * <p/>
- * This map is used to generate the findUsages methods for DAOAbstract.
- */
- protected Map<ObjectModelClass, Set<ObjectModelClass>> usages;
-
- /**
- * All entities fqn of the model (used to detect if an attribute is not
- * an entity).
- */
- protected Set<String> allEntitiesFqn;
-
- /**
- * The class of abstract dao to use.
- * @since 2.5
- */
- protected Class<?> daoImplementation;
-
- protected String entityEnumName;
-
- protected String entityEnumPackage;
-
- /**
- * Map of extra operations for DAO. The key of the map is the qualified
- * name of the entity relative to the DAO.
- */
- protected Map<String, Collection<ObjectModelOperation>> extraOperations =
- new HashMap<String, Collection<ObjectModelOperation>>();
-
- @Override
- public void transformFromModel(ObjectModel model) {
-
- boolean generateStandaloneEnum =
- TopiaGeneratorUtil.shouldGenerateStandaloneEnumForDAOHelper(model);
- String modelName = model.getName();
-
- entityEnumName = modelName + "EntityEnum";
-
- String packageName =
- getOutputProperties().getProperty(PROP_DEFAULT_PACKAGE);
-
- if (generateStandaloneEnum) {
- entityEnumPackage = packageName + "." + entityEnumName;
- } else {
- String daoHelperClazzName = modelName + "DAOHelper";
- entityEnumPackage = packageName + "." + daoHelperClazzName + "." + entityEnumName;
- }
-
- usages = TopiaGeneratorUtil.searchDirectUsages(model);
-
- daoImplementation = TopiaGeneratorUtil.getDAOImplementation(model);
-
-
- // keep all classifiers on the model which are entities
- List<ObjectModelClass> allEntities =
- TopiaGeneratorUtil.getEntityClasses(model, true);
- allEntitiesFqn = new HashSet<String>(allEntities.size());
- for (ObjectModelClass entity : allEntities) {
- String fqn = entity.getQualifiedName();
- allEntitiesFqn.add(fqn);
- Collection<ObjectModelOperation> daoOperations =
- new HashSet<ObjectModelOperation>();
- for (ObjectModelOperation op : entity.getOperations()) {
- if (TopiaGeneratorUtil.hasDaoStereotype(op)) {
- daoOperations.add(op);
- }
- }
-
- if (daoOperations.isEmpty()) {
-
- // found some dao operations
- extraOperations.put(fqn, daoOperations);
- }
- }
- }
-
- @Override
- public void transformFromInterface(ObjectModelInterface interfacez) {
- if (!TopiaGeneratorUtil.hasDaoStereotype(interfacez)) {
- return;
- }
-
- /**
- * EVO #636 : Manage extra operations for DAO from "dao" dependency
- * between an interface with stereotype <<dao>> (dependency client) and
- * a class with stereotype <<entity>> (dependency supplier).
- */
-
- ObjectModelDependency dependency =
- interfacez.getDependency(TopiaGeneratorUtil.DEPENDENCIES_DAO);
-
- if (dependency == null) {
- if (log.isWarnEnabled()) {
- log.warn("Could not find dependency " +
- TopiaGeneratorUtil.DEPENDENCIES_DAO +
- " but DAO stereotype was placed on the interface " +
- interfacez.getName());
- }
- return;
- }
-
- ObjectModelClassifier classifier = dependency.getSupplier();
-
- if (!TopiaGeneratorUtil.isEntity(classifier)) {
-
- // dependency supplier is not an entity...
- if (log.isWarnEnabled()) {
- log.warn("Dependency supplier " +
- classifier.getQualifiedName() +
- " is not an entity.");
- }
- return;
- }
-
- // keep only direct operations
- Collection<ObjectModelOperation> operations =
- interfacez.getOperations();
-
- if (CollectionUtils.isEmpty(operations)) {
-
- // no operations on interface, this is not normal
- if (log.isWarnEnabled()) {
- log.warn("No operation found on interface with DAO " +
- "stereotype "+classifier.getQualifiedName());
- }
- return;
- }
- if (log.isDebugEnabled()) {
- log.debug("add "+operations.size()+" extra operation(s) for DAO");
- }
-
- extraOperations.put(classifier.getQualifiedName(), operations);
- }
-
- @Override
- public void transformFromClass(ObjectModelClass clazz) {
- if (!TopiaGeneratorUtil.isEntity(clazz)) {
- // not an entity
- return;
- }
- String clazzName = clazz.getName();
- String clazzFQN = clazz.getQualifiedName();
-
- if (isGenerateGeneratedDao(clazz)) {
- generateGeneratedDao(clazz, clazzName, clazzFQN);
- }
-
- if (isGenerateAbstractDao(clazz)) {
- generateAbstractDao(clazz, clazzName, clazzFQN);
- }
-
- if (isGenerateLegacyDao(clazz)) {
- generateLegacyDao(clazz, clazzName, clazzFQN);
- }
-
- if (isGenerateConcreteDao(clazz)) {
- generateConcreteDao(clazz, clazzName, clazzFQN);
- }
-
- }
-
- protected boolean isGenerateLegacyDao(ObjectModelClass input) {
-
- String daoLegacyFqn = TopiaGeneratorUtil.getLegacyDaoFqn(input);
-
- if (isInClassPath(daoLegacyFqn)) {
-
- // already in class-path
- return false;
- }
-
- // can safely generate the dao impl
- return true;
- }
-
- protected boolean isGenerateConcreteDao(ObjectModelClass input) {
-
- String daoConcreteFqn = TopiaGeneratorUtil.getConcreteDaoFqn(input);
-
- if (isInClassPath(daoConcreteFqn)) {
-
- // already in class-path
- return false;
- }
-
- // can safely generate the dao impl
- return true;
- }
-
- protected boolean isGenerateGeneratedDao(ObjectModelClass input) {
-
- String daoGeneratedFqn = TopiaGeneratorUtil.getGeneratedDaoFqn(input);
-
- if (isInClassPath(daoGeneratedFqn)) {
-
- // already in class-path
- return false;
- }
-
- // can safely generate the dao impl
- return true;
-
- }
-
- protected boolean isGenerateAbstractDao(ObjectModelClass input) {
-
- String fqn = TopiaGeneratorUtil.getAbstractDaoFqn(input);
-
- if (isInClassPath(fqn)) {
-
- // already in class-path
- return false;
- }
-
- Collection<ObjectModelOperation> moreOperations =
- extraOperations.get(input.getQualifiedName());
-
- if (CollectionUtils.isNotEmpty(moreOperations)) {
-
- // no user operations, can not generate it
- return false;
- }
-
- // can safely generate the dao impl
- return true;
-
- }
-
- protected void generateLegacyDao(ObjectModelClass clazz, String clazzName, String clazzFQN) {
- ObjectModelClass daoClass = createClass(TopiaGeneratorUtil.getLegacyDaoName(clazz), clazz.getPackageName());
- addAnnotation(daoClass, daoClass, Deprecated.class);
- setDocumentation(daoClass, "/**\n" +
- " * Cette classe etend le DAOImpl pour parametrer la classe avec le bon type\n" +
- " * Cette classe est marque finale car l'heritage entre les DAO se fait\n" +
- " * sur les DOAImpl, c-a-d que DAOAbstract peut etendre le DAOImpl\n" +
- " */");
- setSuperClass(daoClass, TopiaGeneratorUtil.getAbstractDaoFqn(clazz) + "<" + clazzName + ">");
- }
-
- protected void generateConcreteDao(ObjectModelClass clazz, String clazzName, String clazzFQN) {
- ObjectModelClass daoClass = createClass(TopiaGeneratorUtil.getConcreteDaoName(clazz), clazz.getPackageName());
- setDocumentation(daoClass, "/**\n" +
- " * Cette classe etend le DAOImpl pour parametrer la classe avec le bon type\n" +
- " * Cette classe est marque finale car l'heritage entre les DAO se fait\n" +
- " * sur les DOAImpl, c-a-d que DAOAbstract peut etendre le DAOImpl\n" +
- " */");
- // to support legacy dao
- setSuperClass(daoClass, TopiaGeneratorUtil.getLegacyDaoFqn(clazz));
- // TODO brendan 04/10/13 above line should be replaced by
- // setSuperClass(daoClass, TopiaGeneratorUtil.getAbstractDaoFqn(clazz) + "<" + clazzName + ">");
- }
-
- protected void generateAbstractDao(ObjectModelClass clazz,
- String clazzName,
- String clazzFQN) {
-
- Collection<ObjectModelOperation> moreOperations =
- extraOperations.get(clazz.getQualifiedName());
-
- if (CollectionUtils.isEmpty(moreOperations)) {
-
- // no business dao found, can safely generate the daoImpl class
-
- ObjectModelClass daoImplClass = createClass(TopiaGeneratorUtil.getAbstractDaoName(clazz) + "<E extends " + clazzName + ">", clazz.getPackageName());
- setDocumentation(daoImplClass, "/**\n" +
- " Implantation du DAO pour l'entité " + clazzName + ".\n" +
- " * L'utilisateur peut remplacer cette classe par la sienne en la mettant \n" +
- " * simplement dans ces sources. Cette classe générée sera alors simplement\n" +
- " * écrasée\n" +
- " */");
- setSuperClass(daoImplClass, TopiaGeneratorUtil.getGeneratedDaoFqn(clazz) + "<E>");
- }
- }
-
- protected void generateGeneratedDao(ObjectModelClass clazz,
- String clazzName,
- String clazzFQN) {
- ObjectModelClass daoAbstractClass = createAbstractClass(TopiaGeneratorUtil.getGeneratedDaoName(clazz) + "<E extends " + clazzName + '>',
- clazz.getPackageName());
-
- // super class
-
- String superClassName = null;
- for (ObjectModelClass parent : clazz.getSuperclasses()) {
- if (TopiaGeneratorUtil.isEntity(parent)) {
- superClassName = TopiaGeneratorUtil.getAbstractDaoFqn(parent) + "<E>";
- // in java no multi-inheritance
- break;
- }
- }
- if (superClassName == null) {
- superClassName = daoImplementation.getName() + "<E>";
- }
- if (log.isDebugEnabled()) {
- log.debug("super class = " + superClassName);
- }
- setSuperClass(daoAbstractClass, superClassName);
-
- String prefix = getConstantPrefix(clazz, "");
- setConstantPrefix(prefix);
-
- // imports
-
- Collection<ObjectModelOperation> DAOoperations =
- getDAOOperations(clazz);
-
- if (TopiaGeneratorUtil.isCollectionNeeded(DAOoperations)) {
- addImport(daoAbstractClass, Collection.class);
- }
- if (TopiaGeneratorUtil.isSetNeeded(DAOoperations)) {
- addImport(daoAbstractClass, Set.class);
- }
- addImport(daoAbstractClass, List.class);
- addImport(daoAbstractClass, TopiaException.class);
-
- ObjectModelOperation op;
-
- // getEntityClass
-
- op = addOperation(daoAbstractClass,
- "getEntityClass",
- "Class<E>",
- ObjectModelJavaModifier.PUBLIC);
- addAnnotation(daoAbstractClass, op,Override.class);
- setOperationBody(op, ""
-/*{
- return (Class<E>) <%=clazzName%>.class;
- }*/
- );
-
- // getTopiaEntityEnum
- addImport(daoAbstractClass, entityEnumPackage);
- op = addOperation(daoAbstractClass,
- "getTopiaEntityEnum",
- entityEnumName,
- ObjectModelJavaModifier.PUBLIC);
- addAnnotation(daoAbstractClass, op,Override.class);
- setOperationBody(op, ""
-/*{
- return <%=entityEnumName%>.<%=clazzName%>;
- }*/
- );
-
- generateDAOOperations(daoAbstractClass, DAOoperations);
-
- generateDelete(clazz, daoAbstractClass);
-
- generateNaturalId(daoAbstractClass, clazz);
-
- generateNotNull(daoAbstractClass, clazz);
-
- for (ObjectModelAttribute attr : clazz.getAttributes()) {
- if (!attr.isNavigable()) {
- continue;
- }
-
- if (!GeneratorUtil.isNMultiplicity(attr)) {
- generateNoNMultiplicity(clazzName, daoAbstractClass, attr, false);
- } else {
- generateNMultiplicity(clazzName, daoAbstractClass, attr);
- }
- }
-
- if (clazz instanceof ObjectModelAssociationClass) {
- ObjectModelAssociationClass assocClass =
- (ObjectModelAssociationClass) clazz;
- for (ObjectModelAttribute attr : assocClass.getParticipantsAttributes()) {
- if (attr != null) {
- if (!GeneratorUtil.isNMultiplicity(attr)) {
- generateNoNMultiplicity(clazzName, daoAbstractClass, attr, true);
- } else {
- generateNMultiplicity(clazzName, daoAbstractClass, attr);
- }
- }
- }
- }
-
- Set<ObjectModelClass> usagesForclass = usages.get(clazz);
- generateFindUsages(clazz, daoAbstractClass, usagesForclass);
- }
-
- protected void generateDelete(ObjectModelClass clazz,
- ObjectModelClass result) {
-
- StringBuilder body = new StringBuilder();
- String modelName = StringUtils.capitalize(model.getName());
- String providerFQN = getOutputProperties().getProperty(
- PROP_DEFAULT_PACKAGE) + '.' + modelName +
- "DAOHelper.getImplementationClass";
-
- for (ObjectModelAttribute attr : clazz.getAttributes()) {
-
- String attrType = GeneratorUtil.getSimpleName(attr.getType());
-
- String reverseAttrName = attr.getReverseAttributeName();
- ObjectModelAttribute reverse = attr.getReverseAttribute();
- if (attr.hasAssociationClass() ||
- reverse == null || !reverse.isNavigable()) {
-
- // never treate a non reverse and navigable attribute
- // never treate an association class attribute
- continue;
- }
-
- // at this point we are sure to have a attribute which is
- // - reverse
- // - navigable
- // - not from an association class
- if (!allEntitiesFqn.contains(attr.getType())) {
-
- // this attribute is not from an entity, don't treate it
- if (log.isDebugEnabled()) {
- log.debug("[" + result.getName() + "] Skip attribute [" +
- attr.getName() + "] with type " + attr.getType());
- }
- continue;
- }
-
- // At this point, the attribute type is a entity
- if (GeneratorUtil.isNMultiplicity(attr) &&
- GeneratorUtil.isNMultiplicity(reverse)) {
- // On doit absolument supprimer pour les relations many-to-many
- // le this de la collection de l'autre cote
-
- String attrDBName = TopiaGeneratorUtil.getDbName(attr);
- String attrClassifierDBName = TopiaGeneratorUtil.getDbName(attr.getClassifier());
- String attrJoinTableName = TopiaGeneratorUtil.getManyToManyTableName(attr);
- String attrReverseDBName = TopiaGeneratorUtil.getReverseDbName(attr);
-
- //FIXME_-FC-20100413 Use a TopiaQuery (use HQLin elements)
-// // Add DAOHelper
-// String daoHelper = modelName + "DAOHelper";
-// String daoHelperFQN = getOutputProperties().
-// getProperty(PROP_DEFAULT_PACKAGE) + '.' + daoHelper;
-// addImport(result, daoHelperFQN);
-//
-// // Add import for TopiaQuery
-// addImport(result, TopiaQuery.class);
-//
-// // Entity DAO and reversePropertyName
-// String entityDAO = attrType + "DAO";
-// String reverseAttrNameProperty =
-// attrType + "." + getConstantName(reverseAttrName);
-//
-//
-// <%=entityDAO%> dao = <%=daoHelper%>.get<%=entityDAO%>(getTopiaContext());
-// TopiaQuery query = dao.createQuery("B").
-// addFrom(entity.getClass(), "A").
-// add("A", entity).
-// addInElements("A", "B." + <%=reverseAttrNameProperty%>);
-//
-// System.out.println("Query : " + query);
-// List<<%=attrType%>> list = dao.findAllByQuery(query);
-
- String removeName = getJavaBeanMethodName("remove", reverseAttrName);
- body.append(""
-/*{
- {
- List<<%=attrType%>> list = topiaHibernateSupport.getHibernateSession().createSQLQuery(
- "SELECT main.topiaid " +
- "from <%=attrClassifierDBName%> main, <%=attrJoinTableName%> secondary " +
- "where main.topiaid=secondary.<%=attrDBName%>" +
- " and secondary.<%=attrReverseDBName%>='" + entity.getTopiaId() + "'")
- .addEntity("main", <%=providerFQN%>(<%=attrType%>.class)).list();
-
- for (<%=attrType%> item : list) {
- item.<%=removeName%>(entity);
- }
- }
-}*/
- );
- } else if (!GeneratorUtil.isNMultiplicity(reverse)) {
- // On doit mettre a null les attributs qui ont cet objet sur les
- // autres entites en one-to-*
- // TODO peut-etre qu'hibernate est capable de faire ca tout seul ?
- // THIMEL: J'ai remplacé reverse.getName() par reverseAttrName sans certitude
- addImport(result, attrType);
- String attrSimpleType = TopiaGeneratorUtil.getClassNameFromQualifiedName(attrType);
- // XXX brendan 04/10/13 do not hard code concrete dao name
- String attrConcreteDaoClassName = attrSimpleType + "TopiaDao";
- String getName = getJavaBeanMethodName("get", reverseAttrName);
- String setName = getJavaBeanMethodName("set", reverseAttrName);
-
- body.append(""
- /*{
- {
- List<<%=attrSimpleType%>> list = topiaDAOSupplier
- .getDAO(<%=attrSimpleType%>.class, <%=attrConcreteDaoClassName%>.class)
- .forProperties(<%=attrSimpleType%>.<%=getConstantName(reverseAttrName)%>, entity).findAll();
- for (<%=attrSimpleType%> item : list) {
-
- // sletellier : Set null only if target is concerned by deletion
- if (entity.equals(item.<%=getName%>())) {
- item.<%=setName%>(null);
- }
- }*/
- );
- if (attr.isAggregate()) {
- body.append(""
-/*{
- topiaDAOSupplier.getDAO(<%=attrSimpleType%>.class).delete(item);
-}*/
- );
- }
- body.append(""
-/*{
- }
- }
-}*/
- );
-
- }
- }
-
- if (body.length()>0) {
- // something specific was done, need to generate the method
- ObjectModelOperation op;
- op = addOperation(result, "delete", "void", ObjectModelJavaModifier.PUBLIC);
- addAnnotation(result, op,Override.class);
- addParameter(op, "E", "entity");
- body.append(""
-/*{
- super.delete(entity);
- }*/
- );
- setOperationBody(op, body.toString());
- }
-
-
-
- }
-
- protected void generateFindUsages(ObjectModelClass clazz,
- ObjectModelClass result,
- Set<ObjectModelClass> usagesForclass) {
-
- builder.addImport(result, LinkedList.class.getName());
- builder.addImport(result, Map.class.getName());
- builder.addImport(result, HashMap.class.getName());
- builder.addImport(result, TopiaEntity.class.getName());
-
- if (clazz instanceof ObjectModelAssociationClass ||
- usagesForclass.isEmpty()) {
- // not for an association class
- // just let a null method
- ObjectModelOperation operation;
- operation = addOperation(result,
- "findUsages",
- "<U extends TopiaEntity> List<U>",
- ObjectModelJavaModifier.PUBLIC);
-
- addParameter(operation, "Class<U>", "type");
- addParameter(operation, "E", "entity");
- addAnnotation(result, operation, Override.class);
- setOperationBody(operation, ""
-/*{
- return new LinkedList<U>();
- }*/
- );
-
- operation = addOperation(result,
- "findAllUsages",
- "Map<Class<? extends TopiaEntity>, List<? extends TopiaEntity>>",
- ObjectModelJavaModifier.PUBLIC);
-
- addParameter(operation, "E", "entity");
- addAnnotation(result, operation, Override.class);
- setOperationBody(operation, ""
-/*{
- return new HashMap<Class<? extends TopiaEntity>, List<? extends TopiaEntity>>();
- }*/
- );
-
- return;
- }
- List<ObjectModelClass> allEntities;
- Map<String, ObjectModelClass> allEntitiesByFQN;
-
- allEntities = TopiaGeneratorUtil.getEntityClasses(model, true);
- allEntitiesByFQN = new TreeMap<String, ObjectModelClass>();
-
- // prepare usages map and fill allEntitiesByFQN map
- for (ObjectModelClass klass : allEntities) {
- allEntitiesByFQN.put(klass.getQualifiedName(), klass);
- }
-
- ObjectModelOperation operation;
- operation = addOperation(result,
- "findUsages",
- "<U extends TopiaEntity> List<U>",
- ObjectModelJavaModifier.PUBLIC);
-
- addParameter(operation, "Class<U>", "type");
- addParameter(operation, "E", "entity");
- addAnnotation(result, operation, Override.class);
- StringBuilder buffer = new StringBuilder(300);
- buffer.append(""
-/*{
- List<?> result = new LinkedList();
- List tmp;
-}*/
- );
-
- for (ObjectModelClass usageClass : usagesForclass) {
- String usageType = usageClass.getQualifiedName();
- builder.addImport(result, usageType);
- String usageSimpleType =
- TopiaGeneratorUtil.getClassNameFromQualifiedName(usageType);
- String usageSimplePropertyMethod = "findAllBy" + usageSimpleType;
- String usageCollectionPropertyMethod = "findAllContaining" + usageSimpleType;
- for (ObjectModelAttribute attr : usageClass.getAttributes()) {
- if (!attr.isNavigable()) {
- // skip this case
- continue;
- }
- String type;
- String attrName = attr.getName();
- if (attr.hasAssociationClass()) {
- //FIXME-TC20100224 dont known how to do this ?
- continue;
-// type = attr.getAssociationClass().getQualifiedName();
-// //FIXME-TC20100224 : this is crazy ??? must find the good name
-// // Perhaps need to make different cases?
-// attrName = attrName + "_" + TopiaGeneratorUtil.toLowerCaseFirstLetter(attr.getAssociationClass().getName());
- } else {
- type = attr.getType();
- }
- if (!allEntitiesByFQN.containsKey(type)) {
- // not a entity, can skip for this attribute
- continue;
- }
- ObjectModelClass targetEntity = allEntitiesByFQN.get(type);
-// if (!type.equals(clazz.getQualifiedName())) {
- if (!targetEntity.equals(clazz)) {
- // not a good attribute reference
- continue;
- }
- // found something to seek
-
- String methodName;
- if (TopiaGeneratorUtil.isNMultiplicity(attr)) {
- methodName = getJavaBeanMethodName("findAllContains", attrName);
- } else {
- methodName = getJavaBeanMethodName("findAllBy", attrName);
- }
- String daoName = StringUtils.capitalize(usageSimpleType) + "DAO";
-
- builder.addImport(result, usageClass.getPackageName() + '.' + daoName);
-
- buffer.append(""
-/*{
- if (type == <%=usageSimpleType%>.class) {
- <%=daoName%> dao = (<%=daoName%>)
- topiaDAOSupplier.getDAO(<%=usageSimpleType%>.class);
- tmp = dao.<%=methodName%>(entity);
- result.addAll(tmp);
- }
-}*/
- );
- }
- }
-
- buffer.append(""
-/*{
- return (List<U>) result;
- }*/
- );
- setOperationBody(operation, buffer.toString());
-
- operation = addOperation(result,
- "findAllUsages",
- "Map<Class<? extends TopiaEntity>, List<? extends TopiaEntity>>",
- ObjectModelJavaModifier.PUBLIC);
-
- addParameter(operation, "E", "entity");
- addAnnotation(result, operation, Override.class);
-
- buffer = new StringBuilder(300);
- buffer.append(""
-/*{
- Map<Class<? extends TopiaEntity>,List<? extends TopiaEntity>> result;
- result = new HashMap<Class<? extends TopiaEntity>, List<? extends TopiaEntity>>(<%=usagesForclass.size()%>);
-
- List<? extends TopiaEntity> list;
-}*/
- );
- for (ObjectModelClass usageClass : usagesForclass) {
-
- String fqn = usageClass.getName();
- buffer.append(""
-/*{
- list = findUsages(<%=fqn%>.class, entity);
- if (!list.isEmpty()) {
- result.put(<%=fqn%>.class, list);
- }
-}*/
- );
-
- }
- buffer.append(""
-/*{
- return result;
- }*/
- );
-
- setOperationBody(operation, buffer.toString());
- }
-
- /**
- * Generation of DAO operations signatures from class. These operations are
- * abstract and identified by <<dao>> stereotype in the model. The
- * developper must defined these methods in the DAOImpl associated to this
- * DAOAbstract.
- *
- * @param result clazz where to add operations
- * @param operations operations to generate
- * @deprecated will be removed ASAP in topia 3.0
- */
- @Deprecated
- protected void generateDAOOperations(ObjectModelClass result,
- Collection<ObjectModelOperation>
- operations) {
- if (CollectionUtils.isEmpty(operations)) {
-
- // no extra operations to generate
- return;
- }
-
- for (ObjectModelOperation op : operations) {
-
- Set<String> exceptions = op.getExceptions();
- cloneOperation(op,
- result,
- true,
- ObjectModelJavaModifier.ABSTRACT,
- ObjectModelJavaModifier.fromVisibility(op.getVisibility())
- );
- }
- }
-
-
- protected void generateNoNMultiplicity(String clazzName,
- ObjectModelClass result,
- ObjectModelAttribute attr,
- boolean isAssoc) {
- String attrName = attr.getName();
- String attrType = attr.getType();
- String propertyName = clazzName + "." + getConstantName(attrName);
-
- String attrTypeForGeneric;
- if (JavaGeneratorUtil.isPrimitiveType(attrType)) {
- attrTypeForGeneric = TopiaGeneratorUtil.getClassForPrimitiveType(attr);
- } else {
- attrTypeForGeneric = attrType;
- }
-
- if (!isAssoc && attr.hasAssociationClass()) {
- String assocClassName = attr.getAssociationClass().getName();
- String assocAttrName = TopiaGeneratorUtil.getAssocAttrName(attr);
- // It is about transitivity : use the property to access the
- // associationClass + '.' + the property to access the expected
- // attribute
- // <class>.<attrAssoc> + '.' + <assocClass>.<attr>
- propertyName =
- clazzName + '.' + getConstantName(assocAttrName) +
- " + '.' + " +
- assocClassName + '.' + getConstantName(attrName);
- }
-
- ObjectModelOperation op;
- op = addOperation(result,
- getJavaBeanMethodName("for", attrName, "In"),
- "TopiaQueryBuilderRunQueryStep<E>",
- ObjectModelJavaModifier.PUBLIC);
- addParameter(op, "Iterable<" + attrTypeForGeneric + ">", "v");
- setOperationBody(op, ""
-/*{
- TopiaQueryBuilderRunQueryStep<E> result = forIn(<%=propertyName%>, (Iterable) v);
- return result;
- }*/
- );
-
- op = addOperation(result,
- getJavaBeanMethodName("for", attrName, "Equals"),
- "TopiaQueryBuilderRunQueryStep<E>",
- ObjectModelJavaModifier.PUBLIC);
- addParameter(op, attrType, "v");
- setOperationBody(op, ""
-/*{
- TopiaQueryBuilderRunQueryStep<E> result = forEquals(<%=propertyName%>, v);
- return result;
- }*/
- );
-
- String methodToDelegateName = op.getName();
-
- op = addOperation(result,
- getJavaBeanMethodName("findBy", attrName),
- "E",
- ObjectModelJavaModifier.PUBLIC);
- addParameter(op, attrType, "v");
- setOperationBody(op, ""
-/*{
- return <%=methodToDelegateName%>(v).findAnyOrNull();
- }*/
- );
-
- addAnnotation(result, op, Deprecated.class);
-
- op = addOperation(result,
- getJavaBeanMethodName("findAllBy", attrName),
- "List<E>",
- ObjectModelJavaModifier.PUBLIC);
- addParameter(op, attrType, "v");
- setOperationBody(op, ""
-/*{
- return <%=methodToDelegateName%>(v).findAll();
- }*/
- );
-
- addAnnotation(result, op, Deprecated.class);
-
- if (!isAssoc && attr.hasAssociationClass()) {
- String assocClassName = attr.getAssociationClass().getName();
- String assocClassFQN = attr.getAssociationClass().getQualifiedName();
- String assocAttrName = TopiaGeneratorUtil.getAssocAttrName(attr);
- String assocPropertyConstantName = getConstantName(assocAttrName);
- op = addOperation(result,
- getJavaBeanMethodName("findBy", assocClassName),
- "E",
- ObjectModelJavaModifier.PUBLIC);
- addParameter(op, assocClassFQN, "value");
- setOperationBody(op, ""
-/*{
- E result = findByProperty(<%=clazzName + "." + assocPropertyConstantName%>, value);
- return result;
- }*/
- );
-
- op = addOperation(result,
- getJavaBeanMethodName("findAllBy", assocClassName),
- "List<E>",
- ObjectModelJavaModifier.PUBLIC);
- addParameter(op, assocClassFQN, "value");
- setOperationBody(op, ""
-/*{
- List<E> result = findAllByProperty(<%=clazzName + "." + assocPropertyConstantName%>, value);
- return result;
- }*/
- );
- }
- }
-
- protected void generateNMultiplicity(String clazzName,
- ObjectModelClass result,
- ObjectModelAttribute attr) {
- String attrName = attr.getName();
- String attrType = attr.getType();
- if (attr.hasAssociationClass()) {
- // do nothing for association class, too complex...
- return;
- }
- ObjectModelOperation op;
-
- op = addOperation(result,
- getJavaBeanMethodName("for", attrName, "Contains"),
- "TopiaQueryBuilderRunQueryStep<E>",
- ObjectModelJavaModifier.PUBLIC);
- addParameter(op, attrType, "v");
- setOperationBody(op, ""
-/*{
- return forContains(<%=clazzName + "." + getConstantName(attrName)%>, v);
- }*/
- );
-
- String methodToDelegateName = op.getName();
-
- op = addOperation(result,
- getJavaBeanMethodName("findContains", attrName),
- "E",
- ObjectModelJavaModifier.PUBLIC);
- addParameter(op, attrType, "v");
- setOperationBody(op, ""
-/*{
- return <%=methodToDelegateName%>(v).findAnyOrNull();
- }*/
- );
-
- addAnnotation(result, op, Deprecated.class);
-
- op = addOperation(result,
- getJavaBeanMethodName("findAllContains", attrName),
- "List<E>",
- ObjectModelJavaModifier.PUBLIC);
- addParameter(op, attrType, "v");
- setOperationBody(op, ""
-/*{
- return <%=methodToDelegateName%>(v).findAll();
- }*/
- );
-
- addAnnotation(result, op, Deprecated.class);
-
- }
-
-
- /**
- * Obtain business operations of the DAO.
- *
- * This operations can not be generated, but must be written by developper.
- *
- * @param clazz the clazz to test.
- * @return collections of extra operations, or empty collection if none found.
- */
- public Collection<ObjectModelOperation> getDAOOperations(
- ObjectModelClass clazz) {
-
-// // Note : this collection will contains extra operations for DAO.
-// // Overriding existing generated methods is not managed yet
-// Collection<ObjectModelOperation> results =
-// new ArrayList<ObjectModelOperation>();
-
-// // This code will be deprecated
-// for (ObjectModelOperation op : clazz.getOperations()) {
-// if (TopiaGeneratorUtil.hasDaoStereotype(op)) {
-// results.add(op);
-// }
-// }
-
- if (log.isWarnEnabled()) {
- log.warn("dao contract in model will not be supported in topia 3.0");
- }
- Collection<ObjectModelOperation> extra =
- extraOperations.get(clazz.getQualifiedName());
- return extra;
-// if (extra != null) {
-// for (ObjectModelOperation op : extra) {
-// results.add(op);
-// }
-// }
-
-// return results;
- }
-
- private void generateNaturalId(ObjectModelClass result,
- ObjectModelClass clazz) {
- Set<ObjectModelAttribute> props =
- TopiaGeneratorUtil.getNaturalIdAttributes(clazz);
-
- if (!props.isEmpty()) {
-
- if (log.isDebugEnabled()) {
- log.debug("generateNaturalId for " + props);
- }
- ObjectModelOperation findByNaturalId = addOperation(result,
- "findByNaturalId", "E", ObjectModelJavaModifier.PUBLIC);
-
- ObjectModelOperation existByNaturalId = addOperation(result,
- "existByNaturalId", "boolean", ObjectModelJavaModifier.PUBLIC);
-
- ObjectModelOperation createByNaturalId = addOperation(result,
- "createByNaturalId", "E", ObjectModelJavaModifier.PUBLIC);
-
- Set<String> properties = Sets.newLinkedHashSet();
- String clazzName = clazz.getName();
-
- for (ObjectModelAttribute attr : props) {
-
- String propName = attr.getName();
- String type = attr.getType();
-
- addParameter(findByNaturalId, type, propName);
- addParameter(existByNaturalId, type, propName);
- addParameter(createByNaturalId, type, propName);
-
- String property = clazzName + '.' + getConstantName(propName) + ", " + propName;
- properties.add(property);
-
- }
-
- String arguments = StringUtils.join(properties, ", ");
-
- setOperationBody(findByNaturalId, ""
-/*{
- return forProperties(<%=arguments%>).findUnique();
- }*/
- );
-
- setOperationBody(existByNaturalId, ""
-/*{
- return forProperties(<%=arguments%>).exists();
- }*/
- );
-
- setOperationBody(createByNaturalId, ""
-/*{
- return create(<%=arguments%>);
- }*/
- );
- }
- }
-
- protected void generateNotNull(ObjectModelClass result,
- ObjectModelClass clazz) {
-
- Set<ObjectModelAttribute> props =
- TopiaGeneratorUtil.getNotNullAttributes(clazz);
-
- if (!props.isEmpty()) {
-
- if (log.isDebugEnabled()) {
- log.debug("generateNotNull for " + props);
- }
-
- ObjectModelOperation createByNotNull = addOperation(result,
- "createByNotNull", "E", ObjectModelJavaModifier.PUBLIC);
-
- String createProperties = "";
-// String params = "";
- String clazzName = clazz.getName();
- for (ObjectModelAttribute attr : props) {
- String propName = attr.getName();
- // add property as param in both methods
- addParameter(createByNotNull, attr.getType(), propName);
-
- createProperties +=
- ", " + clazzName + '.' + getConstantName(propName) +
- ", " + propName;
- //params += ", " + propName;
- }
- createProperties = createProperties.substring(2);
- //params = params.substring(2);
-
- setOperationBody(createByNotNull, ""
-/*{
- return create(<%=createProperties%>);
- }*/
- );
- }
- }
-}
Copied: trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityDaoTransformer.java (from rev 2845, trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityDAOTransformer.java)
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityDaoTransformer.java (rev 0)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityDaoTransformer.java 2013-10-17 16:14:18 UTC (rev 2846)
@@ -0,0 +1,1113 @@
+/*
+ * #%L
+ * ToPIA :: Persistence
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2004 - 2011 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.generator;
+
+/*{generator option: parentheses = false}*/
+/*{generator option: writeString = +}*/
+
+import com.google.common.collect.Sets;
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.nuiton.eugene.GeneratorUtil;
+import org.nuiton.eugene.java.JavaGeneratorUtil;
+import org.nuiton.eugene.java.ObjectModelTransformerToJava;
+import org.nuiton.eugene.models.object.ObjectModel;
+import org.nuiton.eugene.models.object.ObjectModelAssociationClass;
+import org.nuiton.eugene.models.object.ObjectModelAttribute;
+import org.nuiton.eugene.models.object.ObjectModelClass;
+import org.nuiton.eugene.models.object.ObjectModelClassifier;
+import org.nuiton.eugene.models.object.ObjectModelDependency;
+import org.nuiton.eugene.models.object.ObjectModelInterface;
+import org.nuiton.eugene.models.object.ObjectModelJavaModifier;
+import org.nuiton.eugene.models.object.ObjectModelOperation;
+import org.nuiton.topia.TopiaException;
+import org.nuiton.topia.persistence.TopiaEntity;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeMap;
+
+/**
+ * To generate all <code>DAO</code> related classes for a given entity.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.5.4
+ * @plexus.component role="org.nuiton.eugene.Template" role-hint="org.nuiton.topia.generator.EntityDaoTransformer"
+ */
+public class EntityDaoTransformer extends ObjectModelTransformerToJava {
+
+ /** Logger. */
+ private static final Log log =
+ LogFactory.getLog(EntityDaoTransformer.class);
+
+ /**
+ * map of direct usages (values) for each entity (key).
+ * <p/>
+ * This map is used to generate the findUsages methods for DAOAbstract.
+ */
+ protected Map<ObjectModelClass, Set<ObjectModelClass>> usages;
+
+ /**
+ * All entities fqn of the model (used to detect if an attribute is not
+ * an entity).
+ */
+ protected Set<String> allEntitiesFqn;
+
+ /**
+ * The class of abstract dao to use.
+ * @since 2.5
+ */
+ protected Class<?> daoImplementation;
+
+ protected String entityEnumName;
+
+ protected String entityEnumPackage;
+
+ /**
+ * Map of extra operations for DAO. The key of the map is the qualified
+ * name of the entity relative to the DAO.
+ */
+ protected Map<String, Collection<ObjectModelOperation>> extraOperations =
+ new HashMap<String, Collection<ObjectModelOperation>>();
+
+ @Override
+ public void transformFromModel(ObjectModel model) {
+
+ boolean generateStandaloneEnum =
+ TopiaGeneratorUtil.shouldGenerateStandaloneEnumForDAOHelper(model);
+ String modelName = model.getName();
+
+ entityEnumName = modelName + "EntityEnum";
+
+ String packageName =
+ getOutputProperties().getProperty(PROP_DEFAULT_PACKAGE);
+
+ if (generateStandaloneEnum) {
+ entityEnumPackage = packageName + "." + entityEnumName;
+ } else {
+ String daoHelperClazzName = modelName + "DAOHelper";
+ entityEnumPackage = packageName + "." + daoHelperClazzName + "." + entityEnumName;
+ }
+
+ usages = TopiaGeneratorUtil.searchDirectUsages(model);
+
+ daoImplementation = TopiaGeneratorUtil.getDAOImplementation(model);
+
+
+ // keep all classifiers on the model which are entities
+ List<ObjectModelClass> allEntities =
+ TopiaGeneratorUtil.getEntityClasses(model, true);
+ allEntitiesFqn = new HashSet<String>(allEntities.size());
+ for (ObjectModelClass entity : allEntities) {
+ String fqn = entity.getQualifiedName();
+ allEntitiesFqn.add(fqn);
+ Collection<ObjectModelOperation> daoOperations =
+ new HashSet<ObjectModelOperation>();
+ for (ObjectModelOperation op : entity.getOperations()) {
+ if (TopiaGeneratorUtil.hasDaoStereotype(op)) {
+ daoOperations.add(op);
+ }
+ }
+
+ if (daoOperations.isEmpty()) {
+
+ // found some dao operations
+ extraOperations.put(fqn, daoOperations);
+ }
+ }
+ }
+
+ @Override
+ public void transformFromInterface(ObjectModelInterface interfacez) {
+ if (!TopiaGeneratorUtil.hasDaoStereotype(interfacez)) {
+ return;
+ }
+
+ /**
+ * EVO #636 : Manage extra operations for DAO from "dao" dependency
+ * between an interface with stereotype <<dao>> (dependency client) and
+ * a class with stereotype <<entity>> (dependency supplier).
+ */
+
+ ObjectModelDependency dependency =
+ interfacez.getDependency(TopiaGeneratorUtil.DEPENDENCIES_DAO);
+
+ if (dependency == null) {
+ if (log.isWarnEnabled()) {
+ log.warn("Could not find dependency " +
+ TopiaGeneratorUtil.DEPENDENCIES_DAO +
+ " but DAO stereotype was placed on the interface " +
+ interfacez.getName());
+ }
+ return;
+ }
+
+ ObjectModelClassifier classifier = dependency.getSupplier();
+
+ if (!TopiaGeneratorUtil.isEntity(classifier)) {
+
+ // dependency supplier is not an entity...
+ if (log.isWarnEnabled()) {
+ log.warn("Dependency supplier " +
+ classifier.getQualifiedName() +
+ " is not an entity.");
+ }
+ return;
+ }
+
+ // keep only direct operations
+ Collection<ObjectModelOperation> operations =
+ interfacez.getOperations();
+
+ if (CollectionUtils.isEmpty(operations)) {
+
+ // no operations on interface, this is not normal
+ if (log.isWarnEnabled()) {
+ log.warn("No operation found on interface with DAO " +
+ "stereotype "+classifier.getQualifiedName());
+ }
+ return;
+ }
+ if (log.isDebugEnabled()) {
+ log.debug("add "+operations.size()+" extra operation(s) for DAO");
+ }
+
+ extraOperations.put(classifier.getQualifiedName(), operations);
+ }
+
+ @Override
+ public void transformFromClass(ObjectModelClass clazz) {
+ if (!TopiaGeneratorUtil.isEntity(clazz)) {
+ // not an entity
+ return;
+ }
+ String clazzName = clazz.getName();
+ String clazzFQN = clazz.getQualifiedName();
+
+ if (isGenerateGeneratedDao(clazz)) {
+ generateGeneratedDao(clazz, clazzName, clazzFQN);
+ }
+
+ if (isGenerateAbstractDao(clazz)) {
+ generateAbstractDao(clazz, clazzName, clazzFQN);
+ }
+
+ if (isGenerateLegacyDao(clazz)) {
+ generateLegacyDao(clazz, clazzName, clazzFQN);
+ }
+
+ if (isGenerateConcreteDao(clazz)) {
+ generateConcreteDao(clazz, clazzName, clazzFQN);
+ }
+
+ }
+
+ protected boolean isGenerateLegacyDao(ObjectModelClass input) {
+
+ String daoLegacyFqn = TopiaGeneratorUtil.getLegacyDaoFqn(input);
+
+ if (isInClassPath(daoLegacyFqn)) {
+
+ // already in class-path
+ return false;
+ }
+
+ // can safely generate the dao impl
+ return true;
+ }
+
+ protected boolean isGenerateConcreteDao(ObjectModelClass input) {
+
+ String daoConcreteFqn = TopiaGeneratorUtil.getConcreteDaoFqn(input);
+
+ if (isInClassPath(daoConcreteFqn)) {
+
+ // already in class-path
+ return false;
+ }
+
+ // can safely generate the dao impl
+ return true;
+ }
+
+ protected boolean isGenerateGeneratedDao(ObjectModelClass input) {
+
+ String daoGeneratedFqn = TopiaGeneratorUtil.getGeneratedDaoFqn(input);
+
+ if (isInClassPath(daoGeneratedFqn)) {
+
+ // already in class-path
+ return false;
+ }
+
+ // can safely generate the dao impl
+ return true;
+
+ }
+
+ protected boolean isGenerateAbstractDao(ObjectModelClass input) {
+
+ String fqn = TopiaGeneratorUtil.getAbstractDaoFqn(input);
+
+ if (isInClassPath(fqn)) {
+
+ // already in class-path
+ return false;
+ }
+
+ Collection<ObjectModelOperation> moreOperations =
+ extraOperations.get(input.getQualifiedName());
+
+ if (CollectionUtils.isNotEmpty(moreOperations)) {
+
+ // no user operations, can not generate it
+ return false;
+ }
+
+ // can safely generate the dao impl
+ return true;
+
+ }
+
+ protected void generateLegacyDao(ObjectModelClass clazz, String clazzName, String clazzFQN) {
+ ObjectModelClass daoClass = createClass(TopiaGeneratorUtil.getLegacyDaoName(clazz), clazz.getPackageName());
+ addAnnotation(daoClass, daoClass, Deprecated.class);
+ setDocumentation(daoClass, "/**\n" +
+ " * Cette classe etend le DAOImpl pour parametrer la classe avec le bon type\n" +
+ " * Cette classe est marque finale car l'heritage entre les DAO se fait\n" +
+ " * sur les DOAImpl, c-a-d que DAOAbstract peut etendre le DAOImpl\n" +
+ " */");
+ setSuperClass(daoClass, TopiaGeneratorUtil.getAbstractDaoFqn(clazz) + "<" + clazzName + ">");
+ }
+
+ protected void generateConcreteDao(ObjectModelClass clazz, String clazzName, String clazzFQN) {
+ ObjectModelClass daoClass = createClass(TopiaGeneratorUtil.getConcreteDaoName(clazz), clazz.getPackageName());
+ setDocumentation(daoClass, "/**\n" +
+ " * Cette classe etend le DAOImpl pour parametrer la classe avec le bon type\n" +
+ " * Cette classe est marque finale car l'heritage entre les DAO se fait\n" +
+ " * sur les DOAImpl, c-a-d que DAOAbstract peut etendre le DAOImpl\n" +
+ " */");
+ // to support legacy dao
+ setSuperClass(daoClass, TopiaGeneratorUtil.getLegacyDaoFqn(clazz));
+ // TODO brendan 04/10/13 above line should be replaced by
+ // setSuperClass(daoClass, TopiaGeneratorUtil.getAbstractDaoFqn(clazz) + "<" + clazzName + ">");
+ }
+
+ protected void generateAbstractDao(ObjectModelClass clazz,
+ String clazzName,
+ String clazzFQN) {
+
+ Collection<ObjectModelOperation> moreOperations =
+ extraOperations.get(clazz.getQualifiedName());
+
+ if (CollectionUtils.isEmpty(moreOperations)) {
+
+ // no business dao found, can safely generate the daoImpl class
+
+ ObjectModelClass daoImplClass = createClass(TopiaGeneratorUtil.getAbstractDaoName(clazz) + "<E extends " + clazzName + ">", clazz.getPackageName());
+ setDocumentation(daoImplClass, "/**\n" +
+ " Implantation du DAO pour l'entité " + clazzName + ".\n" +
+ " * L'utilisateur peut remplacer cette classe par la sienne en la mettant \n" +
+ " * simplement dans ces sources. Cette classe générée sera alors simplement\n" +
+ " * écrasée\n" +
+ " */");
+ setSuperClass(daoImplClass, TopiaGeneratorUtil.getGeneratedDaoFqn(clazz) + "<E>");
+ }
+ }
+
+ protected void generateGeneratedDao(ObjectModelClass clazz,
+ String clazzName,
+ String clazzFQN) {
+ ObjectModelClass daoAbstractClass = createAbstractClass(TopiaGeneratorUtil.getGeneratedDaoName(clazz) + "<E extends " + clazzName + '>',
+ clazz.getPackageName());
+
+ // super class
+
+ String superClassName = null;
+ for (ObjectModelClass parent : clazz.getSuperclasses()) {
+ if (TopiaGeneratorUtil.isEntity(parent)) {
+ superClassName = TopiaGeneratorUtil.getAbstractDaoFqn(parent) + "<E>";
+ // in java no multi-inheritance
+ break;
+ }
+ }
+ if (superClassName == null) {
+ superClassName = daoImplementation.getName() + "<E>";
+ }
+ if (log.isDebugEnabled()) {
+ log.debug("super class = " + superClassName);
+ }
+ setSuperClass(daoAbstractClass, superClassName);
+
+ String prefix = getConstantPrefix(clazz, "");
+ setConstantPrefix(prefix);
+
+ // imports
+
+ Collection<ObjectModelOperation> DAOoperations =
+ getDAOOperations(clazz);
+
+ if (TopiaGeneratorUtil.isCollectionNeeded(DAOoperations)) {
+ addImport(daoAbstractClass, Collection.class);
+ }
+ if (TopiaGeneratorUtil.isSetNeeded(DAOoperations)) {
+ addImport(daoAbstractClass, Set.class);
+ }
+ addImport(daoAbstractClass, List.class);
+ addImport(daoAbstractClass, TopiaException.class);
+
+ ObjectModelOperation op;
+
+ // getEntityClass
+
+ op = addOperation(daoAbstractClass,
+ "getEntityClass",
+ "Class<E>",
+ ObjectModelJavaModifier.PUBLIC);
+ addAnnotation(daoAbstractClass, op,Override.class);
+ setOperationBody(op, ""
+/*{
+ return (Class<E>) <%=clazzName%>.class;
+ }*/
+ );
+
+ // getTopiaEntityEnum
+ addImport(daoAbstractClass, entityEnumPackage);
+ op = addOperation(daoAbstractClass,
+ "getTopiaEntityEnum",
+ entityEnumName,
+ ObjectModelJavaModifier.PUBLIC);
+ addAnnotation(daoAbstractClass, op,Override.class);
+ setOperationBody(op, ""
+/*{
+ return <%=entityEnumName%>.<%=clazzName%>;
+ }*/
+ );
+
+ generateDAOOperations(daoAbstractClass, DAOoperations);
+
+ generateDelete(clazz, daoAbstractClass);
+
+ generateNaturalId(daoAbstractClass, clazz);
+
+ generateNotNull(daoAbstractClass, clazz);
+
+ for (ObjectModelAttribute attr : clazz.getAttributes()) {
+ if (!attr.isNavigable()) {
+ continue;
+ }
+
+ if (!GeneratorUtil.isNMultiplicity(attr)) {
+ generateNoNMultiplicity(clazzName, daoAbstractClass, attr, false);
+ } else {
+ generateNMultiplicity(clazzName, daoAbstractClass, attr);
+ }
+ }
+
+ if (clazz instanceof ObjectModelAssociationClass) {
+ ObjectModelAssociationClass assocClass =
+ (ObjectModelAssociationClass) clazz;
+ for (ObjectModelAttribute attr : assocClass.getParticipantsAttributes()) {
+ if (attr != null) {
+ if (!GeneratorUtil.isNMultiplicity(attr)) {
+ generateNoNMultiplicity(clazzName, daoAbstractClass, attr, true);
+ } else {
+ generateNMultiplicity(clazzName, daoAbstractClass, attr);
+ }
+ }
+ }
+ }
+
+ Set<ObjectModelClass> usagesForclass = usages.get(clazz);
+ generateFindUsages(clazz, daoAbstractClass, usagesForclass);
+ }
+
+ protected void generateDelete(ObjectModelClass clazz,
+ ObjectModelClass result) {
+
+ StringBuilder body = new StringBuilder();
+ String modelName = StringUtils.capitalize(model.getName());
+ String providerFQN = getOutputProperties().getProperty(
+ PROP_DEFAULT_PACKAGE) + '.' + modelName +
+ "DAOHelper.getImplementationClass";
+
+ for (ObjectModelAttribute attr : clazz.getAttributes()) {
+
+ String attrType = GeneratorUtil.getSimpleName(attr.getType());
+
+ String reverseAttrName = attr.getReverseAttributeName();
+ ObjectModelAttribute reverse = attr.getReverseAttribute();
+ if (attr.hasAssociationClass() ||
+ reverse == null || !reverse.isNavigable()) {
+
+ // never treate a non reverse and navigable attribute
+ // never treate an association class attribute
+ continue;
+ }
+
+ // at this point we are sure to have a attribute which is
+ // - reverse
+ // - navigable
+ // - not from an association class
+ if (!allEntitiesFqn.contains(attr.getType())) {
+
+ // this attribute is not from an entity, don't treate it
+ if (log.isDebugEnabled()) {
+ log.debug("[" + result.getName() + "] Skip attribute [" +
+ attr.getName() + "] with type " + attr.getType());
+ }
+ continue;
+ }
+
+ // At this point, the attribute type is a entity
+ if (GeneratorUtil.isNMultiplicity(attr) &&
+ GeneratorUtil.isNMultiplicity(reverse)) {
+ // On doit absolument supprimer pour les relations many-to-many
+ // le this de la collection de l'autre cote
+
+ String attrDBName = TopiaGeneratorUtil.getDbName(attr);
+ String attrClassifierDBName = TopiaGeneratorUtil.getDbName(attr.getClassifier());
+ String attrJoinTableName = TopiaGeneratorUtil.getManyToManyTableName(attr);
+ String attrReverseDBName = TopiaGeneratorUtil.getReverseDbName(attr);
+
+ //FIXME_-FC-20100413 Use a TopiaQuery (use HQLin elements)
+// // Add DAOHelper
+// String daoHelper = modelName + "DAOHelper";
+// String daoHelperFQN = getOutputProperties().
+// getProperty(PROP_DEFAULT_PACKAGE) + '.' + daoHelper;
+// addImport(result, daoHelperFQN);
+//
+// // Add import for TopiaQuery
+// addImport(result, TopiaQuery.class);
+//
+// // Entity DAO and reversePropertyName
+// String entityDAO = attrType + "DAO";
+// String reverseAttrNameProperty =
+// attrType + "." + getConstantName(reverseAttrName);
+//
+//
+// <%=entityDAO%> dao = <%=daoHelper%>.get<%=entityDAO%>(getTopiaContext());
+// TopiaQuery query = dao.createQuery("B").
+// addFrom(entity.getClass(), "A").
+// add("A", entity).
+// addInElements("A", "B." + <%=reverseAttrNameProperty%>);
+//
+// System.out.println("Query : " + query);
+// List<<%=attrType%>> list = dao.findAllByQuery(query);
+
+ String removeName = getJavaBeanMethodName("remove", reverseAttrName);
+ body.append(""
+/*{
+ {
+ List<<%=attrType%>> list = topiaHibernateSupport.getHibernateSession().createSQLQuery(
+ "SELECT main.topiaid " +
+ "from <%=attrClassifierDBName%> main, <%=attrJoinTableName%> secondary " +
+ "where main.topiaid=secondary.<%=attrDBName%>" +
+ " and secondary.<%=attrReverseDBName%>='" + entity.getTopiaId() + "'")
+ .addEntity("main", <%=providerFQN%>(<%=attrType%>.class)).list();
+
+ for (<%=attrType%> item : list) {
+ item.<%=removeName%>(entity);
+ }
+ }
+}*/
+ );
+ } else if (!GeneratorUtil.isNMultiplicity(reverse)) {
+ // On doit mettre a null les attributs qui ont cet objet sur les
+ // autres entites en one-to-*
+ // TODO peut-etre qu'hibernate est capable de faire ca tout seul ?
+ // THIMEL: J'ai remplacé reverse.getName() par reverseAttrName sans certitude
+ addImport(result, attrType);
+ String attrSimpleType = TopiaGeneratorUtil.getClassNameFromQualifiedName(attrType);
+ // XXX brendan 04/10/13 do not hard code concrete dao name
+ String attrConcreteDaoClassName = attrSimpleType + "TopiaDao";
+ String getName = getJavaBeanMethodName("get", reverseAttrName);
+ String setName = getJavaBeanMethodName("set", reverseAttrName);
+
+ body.append(""
+ /*{
+ {
+ List<<%=attrSimpleType%>> list = topiaDaoSupplier
+ .getDao(<%=attrSimpleType%>.class, <%=attrConcreteDaoClassName%>.class)
+ .forProperties(<%=attrSimpleType%>.<%=getConstantName(reverseAttrName)%>, entity).findAll();
+ for (<%=attrSimpleType%> item : list) {
+
+ // sletellier : Set null only if target is concerned by deletion
+ if (entity.equals(item.<%=getName%>())) {
+ item.<%=setName%>(null);
+ }
+ }*/
+ );
+ if (attr.isAggregate()) {
+ body.append(""
+/*{
+ topiaDaoSupplier.getDao(<%=attrSimpleType%>.class).delete(item);
+}*/
+ );
+ }
+ body.append(""
+/*{
+ }
+ }
+}*/
+ );
+
+ }
+ }
+
+ if (body.length()>0) {
+ // something specific was done, need to generate the method
+ ObjectModelOperation op;
+ op = addOperation(result, "delete", "void", ObjectModelJavaModifier.PUBLIC);
+ addAnnotation(result, op,Override.class);
+ addParameter(op, "E", "entity");
+ body.append(""
+/*{
+ super.delete(entity);
+ }*/
+ );
+ setOperationBody(op, body.toString());
+ }
+
+
+
+ }
+
+ protected void generateFindUsages(ObjectModelClass clazz,
+ ObjectModelClass result,
+ Set<ObjectModelClass> usagesForclass) {
+
+ builder.addImport(result, LinkedList.class.getName());
+ builder.addImport(result, Map.class.getName());
+ builder.addImport(result, HashMap.class.getName());
+ builder.addImport(result, TopiaEntity.class.getName());
+
+ if (clazz instanceof ObjectModelAssociationClass ||
+ usagesForclass.isEmpty()) {
+ // not for an association class
+ // just let a null method
+ ObjectModelOperation operation;
+ operation = addOperation(result,
+ "findUsages",
+ "<U extends TopiaEntity> List<U>",
+ ObjectModelJavaModifier.PUBLIC);
+
+ addParameter(operation, "Class<U>", "type");
+ addParameter(operation, "E", "entity");
+ addAnnotation(result, operation, Override.class);
+ setOperationBody(operation, ""
+/*{
+ return new LinkedList<U>();
+ }*/
+ );
+
+ operation = addOperation(result,
+ "findAllUsages",
+ "Map<Class<? extends TopiaEntity>, List<? extends TopiaEntity>>",
+ ObjectModelJavaModifier.PUBLIC);
+
+ addParameter(operation, "E", "entity");
+ addAnnotation(result, operation, Override.class);
+ setOperationBody(operation, ""
+/*{
+ return new HashMap<Class<? extends TopiaEntity>, List<? extends TopiaEntity>>();
+ }*/
+ );
+
+ return;
+ }
+ List<ObjectModelClass> allEntities;
+ Map<String, ObjectModelClass> allEntitiesByFQN;
+
+ allEntities = TopiaGeneratorUtil.getEntityClasses(model, true);
+ allEntitiesByFQN = new TreeMap<String, ObjectModelClass>();
+
+ // prepare usages map and fill allEntitiesByFQN map
+ for (ObjectModelClass klass : allEntities) {
+ allEntitiesByFQN.put(klass.getQualifiedName(), klass);
+ }
+
+ ObjectModelOperation operation;
+ operation = addOperation(result,
+ "findUsages",
+ "<U extends TopiaEntity> List<U>",
+ ObjectModelJavaModifier.PUBLIC);
+
+ addParameter(operation, "Class<U>", "type");
+ addParameter(operation, "E", "entity");
+ addAnnotation(result, operation, Override.class);
+ StringBuilder buffer = new StringBuilder(300);
+ buffer.append(""
+/*{
+ List<?> result = new LinkedList();
+ List tmp;
+}*/
+ );
+
+ for (ObjectModelClass usageClass : usagesForclass) {
+ String usageType = usageClass.getQualifiedName();
+ builder.addImport(result, usageType);
+ String usageSimpleType =
+ TopiaGeneratorUtil.getClassNameFromQualifiedName(usageType);
+ String usageSimplePropertyMethod = "findAllBy" + usageSimpleType;
+ String usageCollectionPropertyMethod = "findAllContaining" + usageSimpleType;
+ for (ObjectModelAttribute attr : usageClass.getAttributes()) {
+ if (!attr.isNavigable()) {
+ // skip this case
+ continue;
+ }
+ String type;
+ String attrName = attr.getName();
+ if (attr.hasAssociationClass()) {
+ //FIXME-TC20100224 dont known how to do this ?
+ continue;
+// type = attr.getAssociationClass().getQualifiedName();
+// //FIXME-TC20100224 : this is crazy ??? must find the good name
+// // Perhaps need to make different cases?
+// attrName = attrName + "_" + TopiaGeneratorUtil.toLowerCaseFirstLetter(attr.getAssociationClass().getName());
+ } else {
+ type = attr.getType();
+ }
+ if (!allEntitiesByFQN.containsKey(type)) {
+ // not a entity, can skip for this attribute
+ continue;
+ }
+ ObjectModelClass targetEntity = allEntitiesByFQN.get(type);
+// if (!type.equals(clazz.getQualifiedName())) {
+ if (!targetEntity.equals(clazz)) {
+ // not a good attribute reference
+ continue;
+ }
+ // found something to seek
+
+ String methodName;
+ if (TopiaGeneratorUtil.isNMultiplicity(attr)) {
+ methodName = getJavaBeanMethodName("findAllContains", attrName);
+ } else {
+ methodName = getJavaBeanMethodName("findAllBy", attrName);
+ }
+ String daoName = StringUtils.capitalize(usageSimpleType) + "DAO";
+
+ builder.addImport(result, usageClass.getPackageName() + '.' + daoName);
+
+ buffer.append(""
+/*{
+ if (type == <%=usageSimpleType%>.class) {
+ <%=daoName%> dao = (<%=daoName%>)
+ topiaDaoSupplier.getDao(<%=usageSimpleType%>.class);
+ tmp = dao.<%=methodName%>(entity);
+ result.addAll(tmp);
+ }
+}*/
+ );
+ }
+ }
+
+ buffer.append(""
+/*{
+ return (List<U>) result;
+ }*/
+ );
+ setOperationBody(operation, buffer.toString());
+
+ operation = addOperation(result,
+ "findAllUsages",
+ "Map<Class<? extends TopiaEntity>, List<? extends TopiaEntity>>",
+ ObjectModelJavaModifier.PUBLIC);
+
+ addParameter(operation, "E", "entity");
+ addAnnotation(result, operation, Override.class);
+
+ buffer = new StringBuilder(300);
+ buffer.append(""
+/*{
+ Map<Class<? extends TopiaEntity>,List<? extends TopiaEntity>> result;
+ result = new HashMap<Class<? extends TopiaEntity>, List<? extends TopiaEntity>>(<%=usagesForclass.size()%>);
+
+ List<? extends TopiaEntity> list;
+}*/
+ );
+ for (ObjectModelClass usageClass : usagesForclass) {
+
+ String fqn = usageClass.getName();
+ buffer.append(""
+/*{
+ list = findUsages(<%=fqn%>.class, entity);
+ if (!list.isEmpty()) {
+ result.put(<%=fqn%>.class, list);
+ }
+}*/
+ );
+
+ }
+ buffer.append(""
+/*{
+ return result;
+ }*/
+ );
+
+ setOperationBody(operation, buffer.toString());
+ }
+
+ /**
+ * Generation of DAO operations signatures from class. These operations are
+ * abstract and identified by <<dao>> stereotype in the model. The
+ * developper must defined these methods in the DAOImpl associated to this
+ * DAOAbstract.
+ *
+ * @param result clazz where to add operations
+ * @param operations operations to generate
+ * @deprecated will be removed ASAP in topia 3.0
+ */
+ @Deprecated
+ protected void generateDAOOperations(ObjectModelClass result,
+ Collection<ObjectModelOperation>
+ operations) {
+ if (CollectionUtils.isEmpty(operations)) {
+
+ // no extra operations to generate
+ return;
+ }
+
+ for (ObjectModelOperation op : operations) {
+
+ Set<String> exceptions = op.getExceptions();
+ cloneOperation(op,
+ result,
+ true,
+ ObjectModelJavaModifier.ABSTRACT,
+ ObjectModelJavaModifier.fromVisibility(op.getVisibility())
+ );
+ }
+ }
+
+
+ protected void generateNoNMultiplicity(String clazzName,
+ ObjectModelClass result,
+ ObjectModelAttribute attr,
+ boolean isAssoc) {
+ String attrName = attr.getName();
+ String attrType = attr.getType();
+ String propertyName = clazzName + "." + getConstantName(attrName);
+
+ String attrTypeForGeneric;
+ if (JavaGeneratorUtil.isPrimitiveType(attrType)) {
+ attrTypeForGeneric = TopiaGeneratorUtil.getClassForPrimitiveType(attr);
+ } else {
+ attrTypeForGeneric = attrType;
+ }
+
+ if (!isAssoc && attr.hasAssociationClass()) {
+ String assocClassName = attr.getAssociationClass().getName();
+ String assocAttrName = TopiaGeneratorUtil.getAssocAttrName(attr);
+ // It is about transitivity : use the property to access the
+ // associationClass + '.' + the property to access the expected
+ // attribute
+ // <class>.<attrAssoc> + '.' + <assocClass>.<attr>
+ propertyName =
+ clazzName + '.' + getConstantName(assocAttrName) +
+ " + '.' + " +
+ assocClassName + '.' + getConstantName(attrName);
+ }
+
+ ObjectModelOperation op;
+ op = addOperation(result,
+ getJavaBeanMethodName("for", attrName, "In"),
+ "TopiaQueryBuilderRunQueryStep<E>",
+ ObjectModelJavaModifier.PUBLIC);
+ addParameter(op, "Iterable<" + attrTypeForGeneric + ">", "v");
+ setOperationBody(op, ""
+/*{
+ TopiaQueryBuilderRunQueryStep<E> result = forIn(<%=propertyName%>, (Iterable) v);
+ return result;
+ }*/
+ );
+
+ op = addOperation(result,
+ getJavaBeanMethodName("for", attrName, "Equals"),
+ "TopiaQueryBuilderRunQueryStep<E>",
+ ObjectModelJavaModifier.PUBLIC);
+ addParameter(op, attrType, "v");
+ setOperationBody(op, ""
+/*{
+ TopiaQueryBuilderRunQueryStep<E> result = forEquals(<%=propertyName%>, v);
+ return result;
+ }*/
+ );
+
+ String methodToDelegateName = op.getName();
+
+ op = addOperation(result,
+ getJavaBeanMethodName("findBy", attrName),
+ "E",
+ ObjectModelJavaModifier.PUBLIC);
+ addParameter(op, attrType, "v");
+ setOperationBody(op, ""
+/*{
+ return <%=methodToDelegateName%>(v).findAnyOrNull();
+ }*/
+ );
+
+ addAnnotation(result, op, Deprecated.class);
+
+ op = addOperation(result,
+ getJavaBeanMethodName("findAllBy", attrName),
+ "List<E>",
+ ObjectModelJavaModifier.PUBLIC);
+ addParameter(op, attrType, "v");
+ setOperationBody(op, ""
+/*{
+ return <%=methodToDelegateName%>(v).findAll();
+ }*/
+ );
+
+ addAnnotation(result, op, Deprecated.class);
+
+ if (!isAssoc && attr.hasAssociationClass()) {
+ String assocClassName = attr.getAssociationClass().getName();
+ String assocClassFQN = attr.getAssociationClass().getQualifiedName();
+ String assocAttrName = TopiaGeneratorUtil.getAssocAttrName(attr);
+ String assocPropertyConstantName = getConstantName(assocAttrName);
+ op = addOperation(result,
+ getJavaBeanMethodName("findBy", assocClassName),
+ "E",
+ ObjectModelJavaModifier.PUBLIC);
+ addParameter(op, assocClassFQN, "value");
+ setOperationBody(op, ""
+/*{
+ E result = findByProperty(<%=clazzName + "." + assocPropertyConstantName%>, value);
+ return result;
+ }*/
+ );
+
+ op = addOperation(result,
+ getJavaBeanMethodName("findAllBy", assocClassName),
+ "List<E>",
+ ObjectModelJavaModifier.PUBLIC);
+ addParameter(op, assocClassFQN, "value");
+ setOperationBody(op, ""
+/*{
+ List<E> result = findAllByProperty(<%=clazzName + "." + assocPropertyConstantName%>, value);
+ return result;
+ }*/
+ );
+ }
+ }
+
+ protected void generateNMultiplicity(String clazzName,
+ ObjectModelClass result,
+ ObjectModelAttribute attr) {
+ String attrName = attr.getName();
+ String attrType = attr.getType();
+ if (attr.hasAssociationClass()) {
+ // do nothing for association class, too complex...
+ return;
+ }
+ ObjectModelOperation op;
+
+ op = addOperation(result,
+ getJavaBeanMethodName("for", attrName, "Contains"),
+ "TopiaQueryBuilderRunQueryStep<E>",
+ ObjectModelJavaModifier.PUBLIC);
+ addParameter(op, attrType, "v");
+ setOperationBody(op, ""
+/*{
+ return forContains(<%=clazzName + "." + getConstantName(attrName)%>, v);
+ }*/
+ );
+
+ String methodToDelegateName = op.getName();
+
+ op = addOperation(result,
+ getJavaBeanMethodName("findContains", attrName),
+ "E",
+ ObjectModelJavaModifier.PUBLIC);
+ addParameter(op, attrType, "v");
+ setOperationBody(op, ""
+/*{
+ return <%=methodToDelegateName%>(v).findAnyOrNull();
+ }*/
+ );
+
+ addAnnotation(result, op, Deprecated.class);
+
+ op = addOperation(result,
+ getJavaBeanMethodName("findAllContains", attrName),
+ "List<E>",
+ ObjectModelJavaModifier.PUBLIC);
+ addParameter(op, attrType, "v");
+ setOperationBody(op, ""
+/*{
+ return <%=methodToDelegateName%>(v).findAll();
+ }*/
+ );
+
+ addAnnotation(result, op, Deprecated.class);
+
+ }
+
+
+ /**
+ * Obtain business operations of the DAO.
+ *
+ * This operations can not be generated, but must be written by developper.
+ *
+ * @param clazz the clazz to test.
+ * @return collections of extra operations, or empty collection if none found.
+ */
+ public Collection<ObjectModelOperation> getDAOOperations(
+ ObjectModelClass clazz) {
+
+// // Note : this collection will contains extra operations for DAO.
+// // Overriding existing generated methods is not managed yet
+// Collection<ObjectModelOperation> results =
+// new ArrayList<ObjectModelOperation>();
+
+// // This code will be deprecated
+// for (ObjectModelOperation op : clazz.getOperations()) {
+// if (TopiaGeneratorUtil.hasDaoStereotype(op)) {
+// results.add(op);
+// }
+// }
+
+ if (log.isWarnEnabled()) {
+ log.warn("dao contract in model will not be supported in topia 3.0");
+ }
+ Collection<ObjectModelOperation> extra =
+ extraOperations.get(clazz.getQualifiedName());
+ return extra;
+// if (extra != null) {
+// for (ObjectModelOperation op : extra) {
+// results.add(op);
+// }
+// }
+
+// return results;
+ }
+
+ private void generateNaturalId(ObjectModelClass result,
+ ObjectModelClass clazz) {
+ Set<ObjectModelAttribute> props =
+ TopiaGeneratorUtil.getNaturalIdAttributes(clazz);
+
+ if (!props.isEmpty()) {
+
+ if (log.isDebugEnabled()) {
+ log.debug("generateNaturalId for " + props);
+ }
+ ObjectModelOperation findByNaturalId = addOperation(result,
+ "findByNaturalId", "E", ObjectModelJavaModifier.PUBLIC);
+
+ ObjectModelOperation existByNaturalId = addOperation(result,
+ "existByNaturalId", "boolean", ObjectModelJavaModifier.PUBLIC);
+
+ ObjectModelOperation createByNaturalId = addOperation(result,
+ "createByNaturalId", "E", ObjectModelJavaModifier.PUBLIC);
+
+ Set<String> properties = Sets.newLinkedHashSet();
+ String clazzName = clazz.getName();
+
+ for (ObjectModelAttribute attr : props) {
+
+ String propName = attr.getName();
+ String type = attr.getType();
+
+ addParameter(findByNaturalId, type, propName);
+ addParameter(existByNaturalId, type, propName);
+ addParameter(createByNaturalId, type, propName);
+
+ String property = clazzName + '.' + getConstantName(propName) + ", " + propName;
+ properties.add(property);
+
+ }
+
+ String arguments = StringUtils.join(properties, ", ");
+
+ setOperationBody(findByNaturalId, ""
+/*{
+ return forProperties(<%=arguments%>).findUnique();
+ }*/
+ );
+
+ setOperationBody(existByNaturalId, ""
+/*{
+ return forProperties(<%=arguments%>).exists();
+ }*/
+ );
+
+ setOperationBody(createByNaturalId, ""
+/*{
+ return create(<%=arguments%>);
+ }*/
+ );
+ }
+ }
+
+ protected void generateNotNull(ObjectModelClass result,
+ ObjectModelClass clazz) {
+
+ Set<ObjectModelAttribute> props =
+ TopiaGeneratorUtil.getNotNullAttributes(clazz);
+
+ if (!props.isEmpty()) {
+
+ if (log.isDebugEnabled()) {
+ log.debug("generateNotNull for " + props);
+ }
+
+ ObjectModelOperation createByNotNull = addOperation(result,
+ "createByNotNull", "E", ObjectModelJavaModifier.PUBLIC);
+
+ String createProperties = "";
+// String params = "";
+ String clazzName = clazz.getName();
+ for (ObjectModelAttribute attr : props) {
+ String propName = attr.getName();
+ // add property as param in both methods
+ addParameter(createByNotNull, attr.getType(), propName);
+
+ createProperties +=
+ ", " + clazzName + '.' + getConstantName(propName) +
+ ", " + propName;
+ //params += ", " + propName;
+ }
+ createProperties = createProperties.substring(2);
+ //params = params.substring(2);
+
+ setOperationBody(createByNotNull, ""
+/*{
+ return create(<%=createProperties%>);
+ }*/
+ );
+ }
+ }
+}
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityTransformer.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityTransformer.java 2013-10-15 15:08:16 UTC (rev 2845)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityTransformer.java 2013-10-17 16:14:18 UTC (rev 2846)
@@ -39,7 +39,7 @@
import org.nuiton.eugene.models.object.ObjectModelModifier;
import org.nuiton.eugene.models.object.ObjectModelOperation;
import org.nuiton.eugene.models.object.ObjectModelParameter;
-import org.nuiton.topia.TopiaDAOSupplier;
+import org.nuiton.topia.TopiaDaoSupplier;
import org.nuiton.topia.TopiaException;
import org.nuiton.topia.persistence.EntityVisitor;
import org.nuiton.topia.persistence.TopiaEntity;
@@ -338,24 +338,24 @@
if (TopiaGeneratorUtil.isContextable(input)) {
- addImport(outputAbstract, TopiaDAOSupplier.class);
+ addImport(outputAbstract, TopiaDaoSupplier.class);
// topiaContext attribute
ObjectModelAttribute topiaContextAttribute = addAttribute(
- outputAbstract, "topiaDAOSupplier", TopiaDAOSupplier.class, null,
+ outputAbstract, "topiaDaoSupplier", TopiaDaoSupplier.class, null,
ObjectModelJavaModifier.PROTECTED, ObjectModelJavaModifier.TRANSIENT);
setDocumentation(topiaContextAttribute,
"TopiaDAO instance associated with the current \n" +
"instance. For internal usage only");
ObjectModelOperation op = addOperation(outputAbstract,
- "getTopiaDAOSupplier", TopiaDAOSupplier.class,
+ "getTopiaDAOSupplier", TopiaDaoSupplier.class,
ObjectModelJavaModifier.PUBLIC);
setDocumentation(op,"@since 3.0");
addAnnotation(outputAbstract, op, Override.class);
setOperationBody(op, ""
/*{
- return topiaDAOSupplier;
+ return topiaDaoSupplier;
}*/
);
@@ -363,7 +363,7 @@
"setTopiaDAOSupplier", "void",
ObjectModelJavaModifier.PUBLIC);
addException(op, TopiaException.class);
- addParameter(op, TopiaDAOSupplier.class, "topiaDAOSupplier");
+ addParameter(op, TopiaDaoSupplier.class, "topiaDaoSupplier");
setDocumentation(op,
// "@param context The context to set.\n" +
// "@throws TopiaException if trying to replace a context\n" +
@@ -371,8 +371,8 @@
addAnnotation(outputAbstract, op, Override.class);
setOperationBody(op, ""
/*{
- if (this.topiaDAOSupplier == null) {
- this.topiaDAOSupplier = topiaDAOSupplier;
+ if (this.topiaDaoSupplier == null) {
+ this.topiaDaoSupplier = topiaDaoSupplier;
// } else {
// throw new TopiaException("TopiaContext replacement is forbidden");
}
@@ -386,7 +386,7 @@
addAnnotation(outputAbstract, op, Override.class);
setOperationBody(op, ""
/*{
- getTopiaDAOSupplier().getDAO(<%=input.getName()%>.class).update(this);
+ getTopiaDAOSupplier().getDao(<%=input.getName()%>.class).update(this);
}*/
);
@@ -396,7 +396,7 @@
addAnnotation(outputAbstract, op, Override.class);
setOperationBody(op, ""
/*{
- getTopiaDAOSupplier().getDAO(<%=input.getName()%>.class).delete(this);
+ getTopiaDAOSupplier().getDao(<%=input.getName()%>.class).delete(this);
}*/
);
}
@@ -1407,7 +1407,7 @@
body.append(""
/*{
{
- org.nuiton.topia.persistence.TopiaDAO<<%=assocClassFQN%>> dao = getTopiaContext().getDAO(<%=assocClassFQN%>.class);
+ org.nuiton.topia.persistence.TopiaDAO<<%=assocClassFQN%>> dao = getTopiaContext().getDao(<%=assocClassFQN%>.class);
List<<%=assocClassFQN%>> findAllByProperties = dao.findAllByProperties("<%=reverseAttrName%>", this);
if (findAllByProperties != null) {
tmp.addAll(findAllByProperties);
Deleted: trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/LegacyEntityDAOTransformer.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/LegacyEntityDAOTransformer.java 2013-10-15 15:08:16 UTC (rev 2845)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/LegacyEntityDAOTransformer.java 2013-10-17 16:14:18 UTC (rev 2846)
@@ -1,1204 +0,0 @@
-/*
- * #%L
- * ToPIA :: Persistence
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2004 - 2011 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.generator;
-
-/*{generator option: parentheses = false}*/
-/*{generator option: writeString = +}*/
-
-import org.apache.commons.collections.CollectionUtils;
-import org.apache.commons.lang3.StringUtils;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.nuiton.eugene.GeneratorUtil;
-import org.nuiton.eugene.java.ObjectModelTransformerToJava;
-import org.nuiton.eugene.models.object.ObjectModel;
-import org.nuiton.eugene.models.object.ObjectModelAssociationClass;
-import org.nuiton.eugene.models.object.ObjectModelAttribute;
-import org.nuiton.eugene.models.object.ObjectModelClass;
-import org.nuiton.eugene.models.object.ObjectModelClassifier;
-import org.nuiton.eugene.models.object.ObjectModelDependency;
-import org.nuiton.eugene.models.object.ObjectModelInterface;
-import org.nuiton.eugene.models.object.ObjectModelJavaModifier;
-import org.nuiton.eugene.models.object.ObjectModelOperation;
-import org.nuiton.topia.TopiaException;
-import org.nuiton.topia.persistence.TopiaDAO;
-import org.nuiton.topia.persistence.TopiaEntity;
-import org.nuiton.util.StringUtil;
-
-import java.security.Permission;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.TreeMap;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-/**
- * To generate all <code>DAO</code> related classes for a given entity.
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @since 2.5.4
- * @plexus.component role="org.nuiton.eugene.Template" role-hint="org.nuiton.topia.generator.EntityDAOTransformer"
- */
-public class LegacyEntityDAOTransformer extends ObjectModelTransformerToJava {
-
- /** Logger. */
- private static final Log log =
- LogFactory.getLog(EntityDAOTransformer.class);
-
- /**
- * map of direct usages (values) for each entity (key).
- * <p/>
- * This map is used to generate the findUsages methods for DAOAbstract.
- */
- protected Map<ObjectModelClass, Set<ObjectModelClass>> usages;
-
- /**
- * All entities fqn of the model (used to detect if an attribute is not
- * an entity).
- */
- protected Set<String> allEntitiesFqn;
-
- /**
- * The class of abstract dao to use.
- * @since 2.5
- */
- protected Class<?> daoImplementation;
-
- protected String entityEnumName;
-
- protected String entityEnumPackage;
-
- /**
- * Map of extra operations for DAO. The key of the map is the qualified
- * name of the entity relative to the DAO.
- */
- protected Map<String, Collection<ObjectModelOperation>> extraOperations =
- new HashMap<String, Collection<ObjectModelOperation>>();
-
- @Override
- public void transformFromModel(ObjectModel model) {
-
- boolean generateStandaloneEnum =
- TopiaGeneratorUtil.shouldGenerateStandaloneEnumForDAOHelper(model);
- String modelName = model.getName();
-
- entityEnumName = modelName + "EntityEnum";
-
- String packageName =
- getOutputProperties().getProperty(PROP_DEFAULT_PACKAGE);
-
- if (generateStandaloneEnum) {
- entityEnumPackage = packageName + "." + entityEnumName;
- } else {
- String daoHelperClazzName = modelName + "DAOHelper";
- entityEnumPackage = packageName + "." + daoHelperClazzName + "." + entityEnumName;
- }
-
- usages = TopiaGeneratorUtil.searchDirectUsages(model);
-
- daoImplementation = TopiaGeneratorUtil.getDAOImplementation(model);
-
-
- // keep all classifiers on the model which are entities
- List<ObjectModelClass> allEntities =
- TopiaGeneratorUtil.getEntityClasses(model, true);
- allEntitiesFqn = new HashSet<String>(allEntities.size());
- for (ObjectModelClass entity : allEntities) {
- String fqn = entity.getQualifiedName();
- allEntitiesFqn.add(fqn);
- Collection<ObjectModelOperation> daoOperations =
- new HashSet<ObjectModelOperation>();
- for (ObjectModelOperation op : entity.getOperations()) {
- if (TopiaGeneratorUtil.hasDaoStereotype(op)) {
- daoOperations.add(op);
- }
- }
-
- if (daoOperations.isEmpty()) {
-
- // found some dao operations
- extraOperations.put(fqn, daoOperations);
- }
- }
- }
-
- @Override
- public void transformFromInterface(ObjectModelInterface interfacez) {
- if (!TopiaGeneratorUtil.hasDaoStereotype(interfacez)) {
- return;
- }
-
- /**
- * EVO #636 : Manage extra operations for DAO from "dao" dependency
- * between an interface with stereotype <<dao>> (dependency client) and
- * a class with stereotype <<entity>> (dependency supplier).
- */
-
- ObjectModelDependency dependency =
- interfacez.getDependency(TopiaGeneratorUtil.DEPENDENCIES_DAO);
-
- if (dependency == null) {
- if (log.isWarnEnabled()) {
- log.warn("Could not find dependency " +
- TopiaGeneratorUtil.DEPENDENCIES_DAO +
- " but DAO stereotype was placed on the interface " +
- interfacez.getName());
- }
- return;
- }
-
- ObjectModelClassifier classifier = dependency.getSupplier();
-
- if (!TopiaGeneratorUtil.isEntity(classifier)) {
-
- // dependency supplier is not an entity...
- if (log.isWarnEnabled()) {
- log.warn("Dependency supplier " +
- classifier.getQualifiedName() +
- " is not an entity.");
- }
- return;
- }
-
- // keep only direct operations
- Collection<ObjectModelOperation> operations =
- interfacez.getOperations();
-
- if (CollectionUtils.isEmpty(operations)) {
-
- // no operations on interface, this is not normal
- if (log.isWarnEnabled()) {
- log.warn("No operation found on interface with DAO " +
- "stereotype "+classifier.getQualifiedName());
- }
- return;
- }
- if (log.isDebugEnabled()) {
- log.debug("add "+operations.size()+" extra operation(s) for DAO");
- }
-
- extraOperations.put(classifier.getQualifiedName(), operations);
- }
-
- @Override
- public void transformFromClass(ObjectModelClass clazz) {
- if (!TopiaGeneratorUtil.isEntity(clazz)) {
- // not an entity
- return;
- }
- String clazzName = clazz.getName();
- String clazzFQN = clazz.getQualifiedName();
-
- if (isGenerateDAO(clazz)) {
-
- // generate DAO
- generateDAOClass(clazz, clazzName, clazzFQN);
-
- }
- if (isGenerateImpl(clazz)) {
-
- // generate DAOImpl
- generateDAOImpl(clazz, clazzName, clazzFQN);
- }
-
- if (isGenerateDAOAbstract(clazz)) {
-
- // generate DAOAbstract
- generateDAOAbstract(clazz, clazzName, clazzFQN);
- }
- }
-
- protected boolean isGenerateDAO(ObjectModelClass input) {
-
- String fqn = input.getQualifiedName() + "DAO";
-
- if (isInClassPath(fqn)) {
-
- // already in class-path
- return false;
- }
-
- // can safely generate the dao impl
- return true;
- }
-
- protected boolean isGenerateDAOAbstract(ObjectModelClass input) {
-
- String fqn = input.getQualifiedName() + "DAOAbstract";
-
- if (isInClassPath(fqn)) {
-
- // already in class-path
- return false;
- }
-
- // can safely generate the dao impl
- return true;
- }
-
- protected boolean isGenerateImpl(ObjectModelClass input) {
-
- String fqn = input.getQualifiedName() + "DAOImpl";
-
- if (isInClassPath(fqn)) {
-
- // already in class-path
- return false;
- }
-
- Collection<ObjectModelOperation> moreOperations =
- extraOperations.get(input.getQualifiedName());
-
- if (CollectionUtils.isNotEmpty(moreOperations)) {
-
- // no user operations, can generate it
- return false;
- }
-
- // can safely generate the dao impl
- return true;
- }
-
- protected void generateDAOClass(ObjectModelClass clazz, String clazzName, String clazzFQN) {
- ObjectModelClass daoClass = createClass(clazzName + "DAO", clazz.getPackageName());
- setDocumentation(daoClass, "/**\n" +
- " * Cette classe etend le DAOImpl pour parametrer la classe avec le bon type\n" +
- " * Cette classe est marque finale car l'heritage entre les DAO se fait\n" +
- " * sur les DOAImpl, c-a-d que DAOAbstract peut etendre le DAOImpl\n" +
- " */");
- setSuperClass(daoClass, clazzFQN + "DAOImpl<" + clazzName + ">");
- }
-
- protected void generateDAOImpl(ObjectModelClass clazz,
- String clazzName,
- String clazzFQN) {
-
- Collection<ObjectModelOperation> moreOperations =
- extraOperations.get(clazz.getQualifiedName());
-
- if (CollectionUtils.isEmpty(moreOperations)) {
-
- // no business dao found, can safely generate the daoImpl class
-
- ObjectModelClass daoImplClass = createClass(clazzName + "DAOImpl<E extends " + clazzName + ">", clazz.getPackageName());
- setDocumentation(daoImplClass, "/**\n" +
- " Implantation du DAO pour l'entité " + clazzName + ".\n" +
- " * L'utilisateur peut remplacer cette classe par la sienne en la mettant \n" +
- " * simplement dans ces sources. Cette classe générée sera alors simplement\n" +
- " * écrasée\n" +
- " */");
- setSuperClass(daoImplClass, clazzFQN + "DAOAbstract<E>");
- }
- }
-
- protected void generateDAOAbstract(ObjectModelClass clazz,
- String clazzName,
- String clazzFQN) {
- ObjectModelClass daoAbstractClass = createAbstractClass(
- clazzName + "DAOAbstract<E extends " + clazzName + '>',
- clazz.getPackageName());
-
- // super class
-
- String extendClass = "";
- for (ObjectModelClass parent : clazz.getSuperclasses()) {
- extendClass = parent.getQualifiedName();
- if (TopiaGeneratorUtil.isEntity(parent)) {
- extendClass += "DAOImpl<E>";
- // in java no multi-inheritance
- break;
- }
- }
- if (extendClass.length() == 0) {
- extendClass = daoImplementation.getName() + "<E>";
- }
- if (log.isDebugEnabled()) {
- log.debug("super class = " + extendClass);
- }
- setSuperClass(daoAbstractClass, extendClass);
-
- String prefix = getConstantPrefix(clazz, "");
- setConstantPrefix(prefix);
-
- // imports
-
- Collection<ObjectModelOperation> DAOoperations =
- getDAOOperations(clazz);
-
- if (TopiaGeneratorUtil.isCollectionNeeded(DAOoperations)) {
- addImport(daoAbstractClass, Collection.class);
- }
- if (TopiaGeneratorUtil.isSetNeeded(DAOoperations)) {
- addImport(daoAbstractClass, Set.class);
- }
- addImport(daoAbstractClass, List.class);
- addImport(daoAbstractClass, TopiaException.class);
-
- boolean enableSecurity = TopiaGeneratorUtil.isClassWithSecurity(clazz);
-
- if (enableSecurity) {
- addImport(daoAbstractClass, ArrayList.class);
- addImport(daoAbstractClass, Permission.class);
- addImport(daoAbstractClass, "org.nuiton.topia.taas.entities.TaasAuthorizationImpl");
- addImport(daoAbstractClass, "org.nuiton.topia.taas.jaas.TaasPermission");
- addImport(daoAbstractClass, "org.nuiton.topia.taas.TaasUtil");
- addImport(daoAbstractClass, TopiaDAO.class);
-
- //FIXME : how to do static imports ?
-//import static org.nuiton.topia.taas.TaasUtil.CREATE;
-//import static org.nuiton.topia.taas.TaasUtil.DELETE;
-//import static org.nuiton.topia.taas.TaasUtil.LOAD;
-//import static org.nuiton.topia.taas.TaasUtil.UPDATE;
- }
-
- ObjectModelOperation op;
-
- // getEntityClass
-
- op = addOperation(daoAbstractClass,
- "getEntityClass",
- "Class<E>",
- ObjectModelJavaModifier.PUBLIC);
- addAnnotation(daoAbstractClass, op,Override.class);
- setOperationBody(op, ""
-/*{
- return (Class<E>)<%=clazzName%>.class;
- }*/
- );
-
- // getTopiaEntityEnum
- addImport(daoAbstractClass, entityEnumPackage);
- op = addOperation(daoAbstractClass,
- "getTopiaEntityEnum",
- entityEnumName,
- ObjectModelJavaModifier.PUBLIC);
- addAnnotation(daoAbstractClass, op,Override.class);
- setOperationBody(op, ""
-/*{
- return <%=entityEnumName%>.<%=clazzName%>;
- }*/
- );
-
- generateDAOOperations(daoAbstractClass, DAOoperations);
-
- generateDelete(clazz, daoAbstractClass);
-
- generateNaturalId(daoAbstractClass, clazz);
-
- generateNotNull(daoAbstractClass, clazz);
-
- for (ObjectModelAttribute attr : clazz.getAttributes()) {
- if (!attr.isNavigable()) {
- continue;
- }
-
- if (!GeneratorUtil.isNMultiplicity(attr)) {
- generateNoNMultiplicity(clazzName, daoAbstractClass, attr, false);
- } else {
- generateNMultiplicity(clazzName, daoAbstractClass, attr);
- }
- }
-
- if (clazz instanceof ObjectModelAssociationClass) {
- ObjectModelAssociationClass assocClass =
- (ObjectModelAssociationClass) clazz;
- for (ObjectModelAttribute attr : assocClass.getParticipantsAttributes()) {
- if (attr != null) {
- if (!GeneratorUtil.isNMultiplicity(attr)) {
- generateNoNMultiplicity(clazzName, daoAbstractClass, attr, true);
- } else {
- generateNMultiplicity(clazzName, daoAbstractClass, attr);
- }
- }
- }
- }
-
- if (enableSecurity) {
-
- // getRequestPermission
-
- op = addOperation(daoAbstractClass,
- "getRequestPermission",
- "List<Permission>",
- ObjectModelJavaModifier.PUBLIC);
-// setDocumentation(op, "Retourne les permissions a verifier pour " +
-// "l'acces a l'entite pour le service Taas");
- addException(op, TopiaException.class);
- addParameter(op, String.class, "topiaId");
- addParameter(op, int.class, "actions");
- StringBuilder buffer = new StringBuilder();
- buffer.append(""
-/*{
- List<Permission> resultPermissions = new ArrayList<Permission>();
- if ((actions & TaasUtil.CREATE) == TaasUtil.CREATE) {
-}*/
- );
- buffer.append(generateSecurity(daoAbstractClass, clazz,
- TopiaGeneratorUtil.getSecurityCreateTagValue(clazz)));
- buffer.append(""
-/*{
- }
- if ((actions & TaasUtil.LOAD) == TaasUtil.LOAD) {
-}*/
- );
- buffer.append(generateSecurity(daoAbstractClass, clazz,
- TopiaGeneratorUtil.getSecurityLoadTagValue(clazz)));
- buffer.append(""
-/*{
- }
- if ((actions & TaasUtil.UPDATE) == TaasUtil.UPDATE) {
-}*/
- );
- buffer.append(generateSecurity(daoAbstractClass, clazz,
- TopiaGeneratorUtil.getSecurityUpdateTagValue(clazz)));
- buffer.append(""
-/*{
- }
- if ((actions & TaasUtil.DELETE) == TaasUtil.DELETE) {
-}*/
- );
- buffer.append(generateSecurity(daoAbstractClass, clazz,
- TopiaGeneratorUtil.getSecurityDeleteTagValue(clazz)));
- buffer.append(""
-/*{
- }
- return resultPermissions;
- }*/
- );
-
- setOperationBody(op, buffer.toString());
-
- // THIMEL : Le code suivant doit pouvoir être déplacé dans DAODelegator ?
-
- // getRequestPermission
-
-
- op = addOperation(daoAbstractClass,
- "getRequestPermission",
- "List<Permission>",
- ObjectModelJavaModifier.PROTECTED);
- addParameter(op, String.class, "topiaId");
- addParameter(op, int.class, "actions");
- addParameter(op, String.class, "query");
- addParameter(op, Class.class, "daoClass");
- addException(op, TopiaException.class);
-// setDocumentation(op, "Retourne les permissions a verifier pour " +
-// "l'acces a l'entite pour le service Taas");
- setOperationBody(op, ""
-/*{ TopiaContext context = getTopiaContext();
- List<String> result = context.findAll(query, "id", topiaId);
-
- List<Permission> resultPermissions = new ArrayList<Permission>();
- for (String topiaIdPermission : result) {
- TopiaDAO dao = context.getDAO(daoClass);
- List<Permission> permissions = dao.getRequestPermission(topiaIdPermission, actions);
- if(permissions != null) {
- resultPermissions.addAll(permissions);
- } else {
- TaasPermission permission = new TaasPermission(topiaIdPermission, actions);
- resultPermissions.add(permission);
- }
- }
- return resultPermissions;
- }*/
- );
- }
-
- Set<ObjectModelClass> usagesForclass = usages.get(clazz);
- generateFindUsages(clazz, daoAbstractClass, usagesForclass);
- }
-
- protected void generateDelete(ObjectModelClass clazz,
- ObjectModelClass result) {
-
- StringBuilder body = new StringBuilder();
- String modelName = StringUtils.capitalize(model.getName());
- String providerFQN = getOutputProperties().getProperty(
- PROP_DEFAULT_PACKAGE) + '.' + modelName +
- "DAOHelper.getImplementationClass";
-
- for (ObjectModelAttribute attr : clazz.getAttributes()) {
-
- String attrType = GeneratorUtil.getSimpleName(attr.getType());
-
- String reverseAttrName = attr.getReverseAttributeName();
- ObjectModelAttribute reverse = attr.getReverseAttribute();
- if (attr.hasAssociationClass() ||
- reverse == null || !reverse.isNavigable()) {
-
- // never treate a non reverse and navigable attribute
- // never treate an association class attribute
- continue;
- }
-
- // at this point we are sure to have a attribute which is
- // - reverse
- // - navigable
- // - not from an association class
- if (!allEntitiesFqn.contains(attr.getType())) {
-
- // this attribute is not from an entity, don't treate it
- if (log.isDebugEnabled()) {
- log.debug("[" + result.getName() + "] Skip attribute [" +
- attr.getName() + "] with type " + attr.getType());
- }
- continue;
- }
-
- // At this point, the attribute type is a entity
- if (GeneratorUtil.isNMultiplicity(attr) &&
- GeneratorUtil.isNMultiplicity(reverse)) {
- // On doit absolument supprimer pour les relations many-to-many
- // le this de la collection de l'autre cote
-
- String attrDBName = TopiaGeneratorUtil.getDbName(attr);
- String attrClassifierDBName = TopiaGeneratorUtil.getDbName(attr.getClassifier());
- String attrJoinTableName = TopiaGeneratorUtil.getManyToManyTableName(attr);
- String attrReverseDBName = TopiaGeneratorUtil.getReverseDbName(attr);
-
- //FIXME_-FC-20100413 Use a TopiaQuery (use HQLin elements)
-// // Add DAOHelper
-// String daoHelper = modelName + "DAOHelper";
-// String daoHelperFQN = getOutputProperties().
-// getProperty(PROP_DEFAULT_PACKAGE) + '.' + daoHelper;
-// addImport(result, daoHelperFQN);
-//
-// // Add import for TopiaQuery
-// addImport(result, TopiaQuery.class);
-//
-// // Entity DAO and reversePropertyName
-// String entityDAO = attrType + "DAO";
-// String reverseAttrNameProperty =
-// attrType + "." + getConstantName(reverseAttrName);
-//
-//
-// <%=entityDAO%> dao = <%=daoHelper%>.get<%=entityDAO%>(getTopiaContext());
-// TopiaQuery query = dao.createQuery("B").
-// addFrom(entity.getClass(), "A").
-// add("A", entity).
-// addInElements("A", "B." + <%=reverseAttrNameProperty%>);
-//
-// System.out.println("Query : " + query);
-// List<<%=attrType%>> list = dao.findAllByQuery(query);
-
- String removeName = getJavaBeanMethodName("remove", reverseAttrName);
- body.append(""
-/*{
- {
- List<<%=attrType%>> list = getTopiaContext().getHibernateSession().createSQLQuery(
- "SELECT main.topiaid " +
- "from <%=attrClassifierDBName%> main, <%=attrJoinTableName%> secondary " +
- "where main.topiaid=secondary.<%=attrDBName%>" +
- " and secondary.<%=attrReverseDBName%>='" + entity.getTopiaId() + "'")
- .addEntity("main", <%=providerFQN%>(<%=attrType%>.class)).list();
-
- for (<%=attrType%> item : list) {
- item.<%=removeName%>(entity);
- }
- }
-}*/
- );
- } else if (!GeneratorUtil.isNMultiplicity(reverse)) {
- // On doit mettre a null les attributs qui ont cet objet sur les
- // autres entites en one-to-*
- // TODO peut-etre qu'hibernate est capable de faire ca tout seul ?
- // THIMEL: J'ai remplacé reverse.getName() par reverseAttrName sans certitude
- addImport(result, attrType);
- String attrSimpleType = TopiaGeneratorUtil.getClassNameFromQualifiedName(attrType);
- String getName = getJavaBeanMethodName("get", reverseAttrName);
- String setName = getJavaBeanMethodName("set", reverseAttrName);
-
- body.append(""
- /*{
- {
- List<<%=attrSimpleType%>> list = topiaDAOSupplier
- .getDAO(<%=attrSimpleType%>.class)
- .findAllByProperties(<%=attrSimpleType%>.<%=getConstantName(reverseAttrName)%>, entity);
- for (<%=attrSimpleType%> item : list) {
-
- // sletellier : Set null only if target is concerned by deletion
- if (entity.equals(item.<%=getName%>())) {
- item.<%=setName%>(null);
- }
- }*/
- );
- if (attr.isAggregate()) {
- body.append(""
-/*{
- topiaDAOSupplier.getDAO(<%=attrSimpleType%>.class).delete(item);
-}*/
- );
- }
- body.append(""
-/*{
- }
- }
-}*/
- );
-
- }
- }
-
- if (body.length()>0) {
- // something specific was done, need to generate the method
- ObjectModelOperation op;
- op = addOperation(result, "delete", "void", ObjectModelJavaModifier.PUBLIC);
- addAnnotation(result, op,Override.class);
- addParameter(op, "E", "entity");
- body.append(""
-/*{
- super.delete(entity);
- }*/
- );
- setOperationBody(op, body.toString());
- }
-
-
-
- }
-
- protected void generateFindUsages(ObjectModelClass clazz,
- ObjectModelClass result,
- Set<ObjectModelClass> usagesForclass) {
-
- builder.addImport(result, ArrayList.class.getName());
- builder.addImport(result, Map.class.getName());
- builder.addImport(result, HashMap.class.getName());
- builder.addImport(result, TopiaEntity.class.getName());
-
- if (clazz instanceof ObjectModelAssociationClass ||
- usagesForclass.isEmpty()) {
- // not for an association class
- // just let a null method
- ObjectModelOperation operation;
- operation = addOperation(result,
- "findUsages",
- "<U extends TopiaEntity> List<U>",
- ObjectModelJavaModifier.PUBLIC);
-
- addParameter(operation, "Class<U>", "type");
- addParameter(operation, "E", "entity");
- addAnnotation(result, operation, Override.class);
- setOperationBody(operation, ""
-/*{
- return new ArrayList<U>();
- }*/
- );
-
- operation = addOperation(result,
- "findAllUsages",
- "Map<Class<? extends TopiaEntity>, List<? extends TopiaEntity>>",
- ObjectModelJavaModifier.PUBLIC);
-
- addParameter(operation, "E", "entity");
- addAnnotation(result, operation, Override.class);
- setOperationBody(operation, ""
-/*{
- return new HashMap<Class<? extends TopiaEntity>, List<? extends TopiaEntity>>();
- }*/
- );
-
- return;
- }
- List<ObjectModelClass> allEntities;
- Map<String, ObjectModelClass> allEntitiesByFQN;
-
- allEntities = TopiaGeneratorUtil.getEntityClasses(model, true);
- allEntitiesByFQN = new TreeMap<String, ObjectModelClass>();
-
- // prepare usages map and fill allEntitiesByFQN map
- for (ObjectModelClass klass : allEntities) {
- allEntitiesByFQN.put(klass.getQualifiedName(), klass);
- }
-
- ObjectModelOperation operation;
- operation = addOperation(result,
- "findUsages",
- "<U extends TopiaEntity> List<U>",
- ObjectModelJavaModifier.PUBLIC);
-
- addParameter(operation, "Class<U>", "type");
- addParameter(operation, "E", "entity");
- addAnnotation(result, operation, Override.class);
- StringBuilder buffer = new StringBuilder(300);
- buffer.append(""
-/*{
- List<?> result = new ArrayList();
- List tmp;
-}*/
- );
-
- for (ObjectModelClass usageClass : usagesForclass) {
- String usageType = usageClass.getQualifiedName();
- builder.addImport(result, usageType);
- String usageSimpleType =
- TopiaGeneratorUtil.getClassNameFromQualifiedName(usageType);
- String usageSimplePropertyMethod = "findAllBy" + usageSimpleType;
- String usageCollectionPropertyMethod = "findAllContaining" + usageSimpleType;
- for (ObjectModelAttribute attr : usageClass.getAttributes()) {
- if (!attr.isNavigable()) {
- // skip this case
- continue;
- }
- String type;
- String attrName = attr.getName();
- if (attr.hasAssociationClass()) {
- //FIXME-TC20100224 dont known how to do this ?
- continue;
-// type = attr.getAssociationClass().getQualifiedName();
-// //FIXME-TC20100224 : this is crazy ??? must find the good name
-// // Perhaps need to make different cases?
-// attrName = attrName + "_" + TopiaGeneratorUtil.toLowerCaseFirstLetter(attr.getAssociationClass().getName());
- } else {
- type = attr.getType();
- }
- if (!allEntitiesByFQN.containsKey(type)) {
- // not a entity, can skip for this attribute
- continue;
- }
- ObjectModelClass targetEntity = allEntitiesByFQN.get(type);
-// if (!type.equals(clazz.getQualifiedName())) {
- if (!targetEntity.equals(clazz)) {
- // not a good attribute reference
- continue;
- }
- // found something to seek
-
- String methodName;
- if (TopiaGeneratorUtil.isNMultiplicity(attr)) {
- methodName = getJavaBeanMethodName("findAllContains", attrName);
- } else {
- methodName = getJavaBeanMethodName("findAllBy", attrName);
- }
- String daoName = StringUtils.capitalize(usageSimpleType) + "DAO";
-
- builder.addImport(result, usageClass.getPackageName() + '.' + daoName);
-
- buffer.append(""
-/*{
- if (type == <%=usageSimpleType%>.class) {
- <%=daoName%> dao = (<%=daoName%>)
- topiaDAOSupplier.getDAO(<%=usageSimpleType%>.class);
- tmp = dao.<%=methodName%>(entity);
- result.addAll(tmp);
- }
-}*/
- );
- }
- }
-
- buffer.append(""
-/*{
- return (List<U>) result;
- }*/
- );
- setOperationBody(operation, buffer.toString());
-
- operation = addOperation(result,
- "findAllUsages",
- "Map<Class<? extends TopiaEntity>, List<? extends TopiaEntity>>",
- ObjectModelJavaModifier.PUBLIC);
-
- addParameter(operation, "E", "entity");
- addAnnotation(result, operation, Override.class);
-
- buffer = new StringBuilder(300);
- buffer.append(""
-/*{
- Map<Class<? extends TopiaEntity>,List<? extends TopiaEntity>> result;
- result = new HashMap<Class<? extends TopiaEntity>, List<? extends TopiaEntity>>(<%=usagesForclass.size()%>);
-
- List<? extends TopiaEntity> list;
-}*/
- );
- for (ObjectModelClass usageClass : usagesForclass) {
-
- String fqn = usageClass.getName();
- buffer.append(""
-/*{
- list = findUsages(<%=fqn%>.class, entity);
- if (!list.isEmpty()) {
- result.put(<%=fqn%>.class, list);
- }
-}*/
- );
-
- }
- buffer.append(""
-/*{
- return result;
- }*/
- );
-
- setOperationBody(operation, buffer.toString());
- }
-
- /**
- * Generation of DAO operations signatures from class. These operations are
- * abstract and identified by <<dao>> stereotype in the model. The
- * developper must defined these methods in the DAOImpl associated to this
- * DAOAbstract.
- *
- * @param result clazz where to add operations
- * @param operations operations to generate
- */
- private void generateDAOOperations(ObjectModelClass result,
- Collection<ObjectModelOperation>
- operations) {
- if (CollectionUtils.isEmpty(operations)) {
-
- // no extra operations to generate
- return;
- }
-
- for (ObjectModelOperation op : operations) {
-
- Set<String> exceptions = op.getExceptions();
- cloneOperation(op,
- result,
- true,
- ObjectModelJavaModifier.ABSTRACT,
- ObjectModelJavaModifier.fromVisibility(op.getVisibility())
- );
- }
- }
-
-
-
-
- private String generateSecurity(ObjectModelClass result,
- ObjectModelClass clazz,
- String tagValue) {
- StringBuilder buffer = new StringBuilder();
-
- if (StringUtils.isNotEmpty(tagValue)) {
- String security = tagValue;
- Pattern propertiesPattern = Pattern
- .compile("((?:[_a-zA-Z0-9]+\\.)+(?:_?[A-Z][_a-zA-Z0-9]*\\.)+)attribute\\.(?:([_a-z0-9][_a-zA-Z0-9]*))#(?:(create|load|update|delete))");
- String[] valuesSecurity = security.split(":");
-
- for (String valueSecurity : valuesSecurity) {
- Matcher matcher = propertiesPattern.matcher(valueSecurity);
- matcher.find();
- // className is fully qualified name of class
- String className = matcher.group(1);
- className = StringUtil.substring(className, 0, -1); // remove ended
- // .
- // target is class, attribute or operation
- String attributeName = matcher.group(2);
- String actions = matcher.group(3).toUpperCase();
-
- String query = "";
- String daoClass = "";
- if (className.equals(clazz.getQualifiedName())) {
- query = "select " + attributeName + ".topiaId from " + clazz.getQualifiedName() + " where topiaId = :id";
- daoClass = clazz.getAttribute(attributeName).getClassifier().getQualifiedName();
- } else {
- query = "select at.topiaId from " + className + " at inner join at." + attributeName + " cl where cl.topiaId = :id";
- daoClass = className;
- }
- buffer.append(""
-/*{
- resultPermissions.addAll(getRequestPermission(topiaId,
- <%=actions%>,
- "<%=query%>",
- <%=daoClass%>.class));
-}*/
- );
- }
- } else {
- buffer.append(""
-/*{ return null;
- }*/
- );
- }
- return buffer.toString();
- }
-
- protected void generateNoNMultiplicity(String clazzName,
- ObjectModelClass result,
- ObjectModelAttribute attr,
- boolean isAssoc) {
- String attrName = attr.getName();
- String attrType = attr.getType();
- String propertyName = clazzName + "." + getConstantName(attrName);
- if (!isAssoc && attr.hasAssociationClass()) {
- String assocClassName = attr.getAssociationClass().getName();
- String assocAttrName = TopiaGeneratorUtil.getAssocAttrName(attr);
- // It is about transitivity : use the property to access the
- // associationClass + '.' + the property to access the expected
- // attribute
- // <class>.<attrAssoc> + '.' + <assocClass>.<attr>
- propertyName =
- clazzName + '.' + getConstantName(assocAttrName) +
- " + '.' + " +
- assocClassName + '.' + getConstantName(attrName);
- }
-
- ObjectModelOperation op;
- op = addOperation(result,
- getJavaBeanMethodName("findBy", attrName),
- "E",
- ObjectModelJavaModifier.PUBLIC);
- addParameter(op, attrType, "v");
- setOperationBody(op, ""
-/*{
- E result = findByProperty(<%=propertyName%>, v);
- return result;
- }*/
- );
-
- op = addOperation(result,
- getJavaBeanMethodName("findAllBy", attrName),
- "List<E>",
- ObjectModelJavaModifier.PUBLIC);
- addParameter(op, attrType, "v");
- setOperationBody(op, ""
-/*{
- List<E> result = findAllByProperty(<%=propertyName%>, v);
- return result;
- }*/
- );
-
- if (!isAssoc && attr.hasAssociationClass()) {
- String assocClassName = attr.getAssociationClass().getName();
- String assocClassFQN = attr.getAssociationClass().getQualifiedName();
- String assocAttrName = TopiaGeneratorUtil.getAssocAttrName(attr);
- String assocPropertyConstantName = getConstantName(assocAttrName);
- op = addOperation(result,
- getJavaBeanMethodName("findBy", assocClassName),
- "E",
- ObjectModelJavaModifier.PUBLIC);
- addParameter(op, assocClassFQN, "value");
- setOperationBody(op, ""
-/*{
- E result = findByProperty(<%=clazzName + "." + assocPropertyConstantName%>, value);
- return result;
- }*/
- );
-
- op = addOperation(result,
- getJavaBeanMethodName("findAllBy", assocClassName),
- "List<E>",
- ObjectModelJavaModifier.PUBLIC);
- addParameter(op, assocClassFQN, "value");
- setOperationBody(op, ""
-/*{
- List<E> result = findAllByProperty(<%=clazzName + "." + assocPropertyConstantName%>, value);
- return result;
- }*/
- );
- }
- }
-
- protected void generateNMultiplicity(String clazzName,
- ObjectModelClass result,
- ObjectModelAttribute attr) {
- String attrName = attr.getName();
- String attrType = attr.getType();
- if (attr.hasAssociationClass()) {
- // do nothing for association class, too complex...
- return;
- }
- ObjectModelOperation op;
- // Since 2.4 do nothing, findContains and findAllContains are not generated anymore
- op = addOperation(result,
- getJavaBeanMethodName("findContains", attrName),
- "E",
- ObjectModelJavaModifier.PUBLIC);
- addParameter(op, attrType, "v");
- setOperationBody(op, ""
-/*{
- E result = findContains(<%=clazzName + "." + getConstantName(attrName)%>, v);
- return result;
- }*/
- );
-
- op = addOperation(result,
- getJavaBeanMethodName("findAllContains", attrName),
- "List<E>",
- ObjectModelJavaModifier.PUBLIC);
- addParameter(op, attrType, "v");
- setOperationBody(op, ""
-/*{
- List<E> result = findAllContains(<%=clazzName + "." + getConstantName(attrName)%>, v);
- return result;
- }*/
- );
- }
-
-
- /**
- * Obtain business operations of the DAO.
- *
- * This operations can not be generated, but must be written by developper.
- *
- * @param clazz the clazz to test.
- * @return collections of extra operations, or empty collection if none found.
- */
- public Collection<ObjectModelOperation> getDAOOperations(
- ObjectModelClass clazz) {
-
-// // Note : this collection will contains extra operations for DAO.
-// // Overriding existing generated methods is not managed yet
-// Collection<ObjectModelOperation> results =
-// new ArrayList<ObjectModelOperation>();
-
-// // This code will be deprecated
-// for (ObjectModelOperation op : clazz.getOperations()) {
-// if (TopiaGeneratorUtil.hasDaoStereotype(op)) {
-// results.add(op);
-// }
-// }
- Collection<ObjectModelOperation> extra =
- extraOperations.get(clazz.getQualifiedName());
- return extra;
-// if (extra != null) {
-// for (ObjectModelOperation op : extra) {
-// results.add(op);
-// }
-// }
-
-// return results;
- }
-
- private void generateNaturalId(ObjectModelClass result,
- ObjectModelClass clazz) {
- Set<ObjectModelAttribute> props =
- TopiaGeneratorUtil.getNaturalIdAttributes(clazz);
-
- if (!props.isEmpty()) {
-
- if (log.isDebugEnabled()) {
- log.debug("generateNaturalId for " + props);
- }
- ObjectModelOperation findByNaturalId = addOperation(result,
- "findByNaturalId", "E", ObjectModelJavaModifier.PUBLIC);
-
- ObjectModelOperation existByNaturalId = addOperation(result,
- "existByNaturalId", "boolean", ObjectModelJavaModifier.PUBLIC);
-
- // TODO sletellier 20120406 : remove method on 3.0
- ObjectModelOperation create = addOperation(result,
- "create", "E", ObjectModelJavaModifier.PUBLIC);
-
- // sletellier : mark as Deprecated (http://nuiton.org/issues/2051)
- setDocumentation(create, "@deprecated since 2.6.10, prefer use {@link #createByNaturalId}\n");
- addAnnotation(result, create, "Deprecated");
-
- ObjectModelOperation createByNaturalId = addOperation(result,
- "createByNaturalId", "E", ObjectModelJavaModifier.PUBLIC);
-
- // used for calling findByProperties in findByNaturalId
- String searchProperties = "";
- // used for calling findByNaturalId in existByNaturalId
-// String params = "";
- String clazzName = clazz.getName();
- for (ObjectModelAttribute attr : props) {
- String propName = attr.getName();
- // add property as param in both methods
- addParameter(findByNaturalId, attr.getType(), propName);
- addParameter(existByNaturalId, attr.getType(), propName);
- addParameter(create, attr.getType(), propName);
- addParameter(createByNaturalId, attr.getType(), propName);
-
- searchProperties +=
- ", " + clazzName + '.' + getConstantName(propName) +
- ", " + propName;
- //params += ", " + propName;
- }
- searchProperties = searchProperties.substring(2);
- //params = params.substring(2);
-
- setOperationBody(findByNaturalId, ""
-/*{
- return findByProperties(<%=searchProperties%>);
- }*/
- );
-
- setOperationBody(existByNaturalId, ""
-/*{
- return existByProperties(<%=searchProperties%>);
- }*/
- );
-
- setOperationBody(create, ""
-/*{
- return create(<%=searchProperties%>);
- }*/
- );
-
- setOperationBody(createByNaturalId, ""
-/*{
- return create(<%=searchProperties%>);
- }*/
- );
- }
- }
-
- private void generateNotNull(ObjectModelClass result,
- ObjectModelClass clazz) {
-
- Set<ObjectModelAttribute> props =
- TopiaGeneratorUtil.getNotNullAttributes(clazz);
-
- if (!props.isEmpty()) {
-
- if (log.isDebugEnabled()) {
- log.debug("generateNotNull for " + props);
- }
-
- ObjectModelOperation createByNotNull = addOperation(result,
- "createByNotNull", "E", ObjectModelJavaModifier.PUBLIC);
-
- String createProperties = "";
-// String params = "";
- String clazzName = clazz.getName();
- for (ObjectModelAttribute attr : props) {
- String propName = attr.getName();
- // add property as param in both methods
- addParameter(createByNotNull, attr.getType(), propName);
-
- createProperties +=
- ", " + clazzName + '.' + getConstantName(propName) +
- ", " + propName;
- //params += ", " + propName;
- }
- createProperties = createProperties.substring(2);
- //params = params.substring(2);
-
- setOperationBody(createByNotNull, ""
-/*{
- return create(<%=createProperties%>);
- }*/
- );
- }
- }
-}
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/PersistenceContextTransformer.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/PersistenceContextTransformer.java 2013-10-15 15:08:16 UTC (rev 2845)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/PersistenceContextTransformer.java 2013-10-17 16:14:18 UTC (rev 2846)
@@ -186,7 +186,7 @@
addImport(output, clazz);
setOperationBody(op, ""
/*{
- <%=daoClazzName%> result = getDAO(<%=clazzName%>.class, <%=daoClazzName%>.class);
+ <%=daoClazzName%> result = getDao(<%=clazzName%>.class, <%=daoClazzName%>.class);
return result;
}*/
);
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/TopiaMetaTransformer.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/TopiaMetaTransformer.java 2013-10-15 15:08:16 UTC (rev 2845)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/TopiaMetaTransformer.java 2013-10-17 16:14:18 UTC (rev 2846)
@@ -64,7 +64,7 @@
ApplicationContextTransformer.class,
PersistenceContextTransformer.class,
EntityTransformer.class,
- EntityDAOTransformer.class,
+ EntityDaoTransformer.class,
// DAOTransformer.class,
// DAOImplTransformer.class,
// DAOAbstractTransformer.class,
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/AbstractTopiaDAO.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/AbstractTopiaDAO.java 2013-10-15 15:08:16 UTC (rev 2845)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/AbstractTopiaDAO.java 2013-10-17 16:14:18 UTC (rev 2846)
@@ -48,7 +48,7 @@
import org.hibernate.HibernateException;
import org.hibernate.metadata.ClassMetadata;
import org.nuiton.topia.TopiaContext;
-import org.nuiton.topia.TopiaDAOSupplier;
+import org.nuiton.topia.TopiaDaoSupplier;
import org.nuiton.topia.TopiaException;
import org.nuiton.topia.TopiaHibernateSupport;
import org.nuiton.topia.TopiaJpaSupport;
@@ -109,7 +109,7 @@
protected TopiaFiresSupport topiaFiresSupport;
- protected TopiaDAOSupplier topiaDAOSupplier;
+ protected TopiaDaoSupplier topiaDaoSupplier;
public abstract TopiaEntityEnum getTopiaEntityEnum();
@@ -180,7 +180,7 @@
TopiaListenableSupport topiaListenableSupport,
TopiaIdFactory topiaIdFactory,
TopiaFiresSupport topiaFiresSupport,
- TopiaDAOSupplier topiaDAOSupplier) {
+ TopiaDaoSupplier topiaDaoSupplier) {
log.debug("init dao for " + getEntityClass());
this.topiaHibernateSupport = topiaHibernateSupport;
this.topiaJpaSupport = topiaJpaSupport;
@@ -188,7 +188,7 @@
this.topiaListenableSupport = topiaListenableSupport;
this.topiaIdFactory = topiaIdFactory;
this.topiaFiresSupport = topiaFiresSupport;
- this.topiaDAOSupplier = topiaDAOSupplier;
+ this.topiaDaoSupplier = topiaDaoSupplier;
}
public TopiaFiresSupport getTopiaFiresSupport() {
@@ -270,7 +270,7 @@
if (entity instanceof TopiaEntityContextable) {
TopiaEntityContextable contextable = (TopiaEntityContextable) entity;
- contextable.setTopiaDAOSupplier(this.topiaDAOSupplier);
+ contextable.setTopiaDAOSupplier(this.topiaDaoSupplier);
}
// save entity
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAO.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAO.java 2013-10-15 15:08:16 UTC (rev 2845)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAO.java 2013-10-17 16:14:18 UTC (rev 2846)
@@ -41,7 +41,6 @@
import org.nuiton.topia.event.TopiaEntityListener;
import org.nuiton.topia.event.TopiaEntityVetoable;
import org.nuiton.topia.framework.TopiaContextImplementor;
-import org.nuiton.topia.generator.EntityDAOTransformer;
import org.nuiton.topia.persistence.pager.TopiaPagerBean;
import java.security.Permission;
@@ -53,7 +52,7 @@
* create, delete, update or find entities.
* <p/>
* This interface is implemented by {@link TopiaDAOImpl} overridden by generation
- * from {@link EntityDAOTransformer}.
+ * from {@link org.nuiton.topia.generator.EntityDaoTransformer}.
* <p/>
*
* @param <E> the entity type managed by the dao
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaEntityAbstract.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaEntityAbstract.java 2013-10-15 15:08:16 UTC (rev 2845)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaEntityAbstract.java 2013-10-17 16:14:18 UTC (rev 2846)
@@ -208,7 +208,7 @@
if (fireSupport == null) {
if (this instanceof TopiaEntityContextable) {
TopiaEntityContextable contextable = (TopiaEntityContextable) this;
- AbstractTopiaDAO topiaDAO = (AbstractTopiaDAO)contextable.getTopiaDAOSupplier().getDAO(getClass());
+ AbstractTopiaDAO topiaDAO = (AbstractTopiaDAO)contextable.getTopiaDAOSupplier().getDao(getClass());
fireSupport = topiaDAO.getTopiaFiresSupport();
}
}
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaEntityContextable.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaEntityContextable.java 2013-10-15 15:08:16 UTC (rev 2845)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaEntityContextable.java 2013-10-17 16:14:18 UTC (rev 2846)
@@ -26,7 +26,7 @@
package org.nuiton.topia.persistence;
import org.nuiton.topia.TopiaContext;
-import org.nuiton.topia.TopiaDAOSupplier;
+import org.nuiton.topia.TopiaDaoSupplier;
/**
* {@link TopiaEntity} with {@link TopiaContext} support (injected by
@@ -50,8 +50,8 @@
*/
void delete();
- void setTopiaDAOSupplier(TopiaDAOSupplier topiaDAO);
+ void setTopiaDAOSupplier(TopiaDaoSupplier topiaDAO);
- TopiaDAOSupplier getTopiaDAOSupplier();
+ TopiaDaoSupplier getTopiaDAOSupplier();
}
Modified: trunk/topia-service-replication/src/main/java/org/nuiton/topia/replication/TopiaReplicationContext.java
===================================================================
--- trunk/topia-service-replication/src/main/java/org/nuiton/topia/replication/TopiaReplicationContext.java 2013-10-15 15:08:16 UTC (rev 2845)
+++ trunk/topia-service-replication/src/main/java/org/nuiton/topia/replication/TopiaReplicationContext.java 2013-10-17 16:14:18 UTC (rev 2846)
@@ -229,7 +229,7 @@
// on recupere pour chaque type tous les ids des entites a repliquer
data = new TopiaEntityIdsMap();
for (TopiaEntityEnum e : replicationModel.getContracts()) {
- List<String> ids = srcCtxt.getDAO(e.getContract()).findAllIds();
+ List<String> ids = srcCtxt.getDao(e.getContract()).findAllIds();
data.put(e.getContract(), ids);
}
} else {
Modified: trunk/topia-service-replication/src/main/java/org/nuiton/topia/replication/operation/Duplicate.java
===================================================================
--- trunk/topia-service-replication/src/main/java/org/nuiton/topia/replication/operation/Duplicate.java 2013-10-15 15:08:16 UTC (rev 2845)
+++ trunk/topia-service-replication/src/main/java/org/nuiton/topia/replication/operation/Duplicate.java 2013-10-17 16:14:18 UTC (rev 2846)
@@ -106,7 +106,7 @@
Class<? extends TopiaEntity> entityClass = operationDef.getEntityType();
TopiaDAO<TopiaEntity> dao =
- (TopiaDAO<TopiaEntity>) dstCtxt.getDAO(entityClass);
+ (TopiaDAO<TopiaEntity>) dstCtxt.getDao(entityClass);
List<String> allIds = dao.findAllIds();
try {
Modified: trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/AbstractTopiaReplicationServiceTest.java
===================================================================
--- trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/AbstractTopiaReplicationServiceTest.java 2013-10-15 15:08:16 UTC (rev 2845)
+++ trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/AbstractTopiaReplicationServiceTest.java 2013-10-17 16:14:18 UTC (rev 2846)
@@ -484,8 +484,8 @@
if (getLog().isDebugEnabled()) {
getLog().debug("verify for contract " + c);
}
- TopiaDAO<? extends TopiaEntity> daoSrc = ctxt.getDAO(c.getContract());
- TopiaDAO<? extends TopiaEntity> daoDst = ctxt2.getDAO(c.getContract());
+ TopiaDAO<? extends TopiaEntity> daoSrc = ctxt.getDao(c.getContract());
+ TopiaDAO<? extends TopiaEntity> daoDst = ctxt2.getDao(c.getContract());
long nbSrc = daoSrc.count();
long nbDst = daoDst.count();
assertEquals("le nombres d'entites de type " + c + " devrait etre " + nbSrc + " mais est " + nbDst, nbSrc, nbDst);
Modified: trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/TopiaReplicationOperationTest.java
===================================================================
--- trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/TopiaReplicationOperationTest.java 2013-10-15 15:08:16 UTC (rev 2845)
+++ trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/TopiaReplicationOperationTest.java 2013-10-17 16:14:18 UTC (rev 2846)
@@ -277,13 +277,13 @@
TopiaContextImplementor tx =
(TopiaContextImplementor) context.beginTransaction();
- person = tx.getDAO(Person.class).create(Person.PROPERTY_NAME, "pudding master");
- race = tx.getDAO(Race.class).create(Race.PROPERTY_NAME, "race I");
- pet = tx.getDAO(Pet.class).create(Pet.PROPERTY_NAME, "pudding", Pet.PROPERTY_PERSON, person, Pet.PROPERTY_RACE, race);
+ person = tx.getDao(Person.class).create(Person.PROPERTY_NAME, "pudding master");
+ race = tx.getDao(Race.class).create(Race.PROPERTY_NAME, "race I");
+ pet = tx.getDao(Pet.class).create(Pet.PROPERTY_NAME, "pudding", Pet.PROPERTY_PERSON, person, Pet.PROPERTY_RACE, race);
- person2 = tx.getDAO(Person.class).create(Person.PROPERTY_NAME, "pudding II master");
- pet2 = tx.getDAO(Pet.class).create(Pet.PROPERTY_NAME, "pudding II");
- race2 = tx.getDAO(Race.class).create(Race.PROPERTY_NAME, "race II");
+ person2 = tx.getDao(Person.class).create(Person.PROPERTY_NAME, "pudding II master");
+ pet2 = tx.getDao(Pet.class).create(Pet.PROPERTY_NAME, "pudding II");
+ race2 = tx.getDao(Race.class).create(Race.PROPERTY_NAME, "race II");
tx.commitTransaction();
tx.closeContext();
Modified: trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/TopiaReplicationServiceImplAllTest.java
===================================================================
--- trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/TopiaReplicationServiceImplAllTest.java 2013-10-15 15:08:16 UTC (rev 2845)
+++ trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/TopiaReplicationServiceImplAllTest.java 2013-10-17 16:14:18 UTC (rev 2846)
@@ -236,16 +236,16 @@
TopiaContextImplementor tx = (TopiaContextImplementor) context.beginTransaction();
- person = tx.getDAO(Person.class).create(Person.PROPERTY_NAME, "pudding master");
- race = tx.getDAO(Race.class).create(Race.PROPERTY_NAME, "race I");
- pet = tx.getDAO(Pet.class).create(Pet.PROPERTY_NAME, "pudding", Pet.PROPERTY_PERSON, person, Pet.PROPERTY_RACE, race);
+ person = tx.getDao(Person.class).create(Person.PROPERTY_NAME, "pudding master");
+ race = tx.getDao(Race.class).create(Race.PROPERTY_NAME, "race I");
+ pet = tx.getDao(Pet.class).create(Pet.PROPERTY_NAME, "pudding", Pet.PROPERTY_PERSON, person, Pet.PROPERTY_RACE, race);
- person2 = tx.getDAO(Person.class).create(Person.PROPERTY_NAME, "pudding II master");
- pet2 = tx.getDAO(Pet.class).create(Pet.PROPERTY_NAME, "pudding II");
- race2 = tx.getDAO(Race.class).create(Race.PROPERTY_NAME, "race II");
+ person2 = tx.getDao(Person.class).create(Person.PROPERTY_NAME, "pudding II master");
+ pet2 = tx.getDao(Pet.class).create(Pet.PROPERTY_NAME, "pudding II");
+ race2 = tx.getDao(Race.class).create(Race.PROPERTY_NAME, "race II");
- race3 = tx.getDAO(Race.class).create(Race.PROPERTY_NAME, "race III");
- pet3 = tx.getDAO(Pet.class).create(Pet.PROPERTY_NAME, "pudding III", Pet.PROPERTY_RACE, race3);
+ race3 = tx.getDao(Race.class).create(Race.PROPERTY_NAME, "race III");
+ pet3 = tx.getDao(Pet.class).create(Pet.PROPERTY_NAME, "pudding III", Pet.PROPERTY_RACE, race3);
tx.commitTransaction();
tx.closeContext();
Modified: trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/TopiaReplicationServiceImplTest.java
===================================================================
--- trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/TopiaReplicationServiceImplTest.java 2013-10-15 15:08:16 UTC (rev 2845)
+++ trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/TopiaReplicationServiceImplTest.java 2013-10-17 16:14:18 UTC (rev 2846)
@@ -395,16 +395,16 @@
TopiaContextImplementor tx = (TopiaContextImplementor) context.beginTransaction();
- person = tx.getDAO(Person.class).create(Person.PROPERTY_NAME, "pudding master");
- race = tx.getDAO(Race.class).create(Race.PROPERTY_NAME, "race I");
- pet = tx.getDAO(Pet.class).create(Pet.PROPERTY_NAME, "pudding", Pet.PROPERTY_PERSON, person, Pet.PROPERTY_RACE, race);
+ person = tx.getDao(Person.class).create(Person.PROPERTY_NAME, "pudding master");
+ race = tx.getDao(Race.class).create(Race.PROPERTY_NAME, "race I");
+ pet = tx.getDao(Pet.class).create(Pet.PROPERTY_NAME, "pudding", Pet.PROPERTY_PERSON, person, Pet.PROPERTY_RACE, race);
- person2 = tx.getDAO(Person.class).create(Person.PROPERTY_NAME, "pudding II master");
- pet2 = tx.getDAO(Pet.class).create(Pet.PROPERTY_NAME, "pudding II");
- race2 = tx.getDAO(Race.class).create(Race.PROPERTY_NAME, "race II");
+ person2 = tx.getDao(Person.class).create(Person.PROPERTY_NAME, "pudding II master");
+ pet2 = tx.getDao(Pet.class).create(Pet.PROPERTY_NAME, "pudding II");
+ race2 = tx.getDao(Race.class).create(Race.PROPERTY_NAME, "race II");
- race3 = tx.getDAO(Race.class).create(Race.PROPERTY_NAME, "race III");
- pet3 = tx.getDAO(Pet.class).create(Pet.PROPERTY_NAME, "pudding III", Pet.PROPERTY_RACE, race3);
+ race3 = tx.getDao(Race.class).create(Race.PROPERTY_NAME, "race III");
+ pet3 = tx.getDao(Pet.class).create(Pet.PROPERTY_NAME, "pudding III", Pet.PROPERTY_RACE, race3);
tx.commitTransaction();
tx.closeContext();
1
0
r2845 - in trunk/topia-persistence/src: main/java/org/nuiton/topia main/java/org/nuiton/topia/generator main/java/org/nuiton/topia/persistence test/java/org/nuiton/topia test/java/org/nuiton/topia/generator test/java/org/nuiton/topia/persistence
by bleny@users.nuiton.org 15 Oct '13
by bleny@users.nuiton.org 15 Oct '13
15 Oct '13
Author: bleny
Date: 2013-10-15 17:08:16 +0200 (Tue, 15 Oct 2013)
New Revision: 2845
Url: http://nuiton.org/projects/topia/repository/revisions/2845
Log:
update tests and change contract for generated dao factories
Modified:
trunk/topia-persistence/src/main/java/org/nuiton/topia/AbstractTopiaPersistenceContext.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityDAOTransformer.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/PersistenceContextTransformer.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/AbstractTopiaDAO.java
trunk/topia-persistence/src/test/java/org/nuiton/topia/TopiaJpaSupportTest.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
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/AbstractTopiaPersistenceContext.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/AbstractTopiaPersistenceContext.java 2013-10-11 22:50:35 UTC (rev 2844)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/AbstractTopiaPersistenceContext.java 2013-10-15 15:08:16 UTC (rev 2845)
@@ -257,7 +257,7 @@
// Looking for specialized DAO
// This DAO is supposed to exist, as created by generation
- String daoClassName = entityClass.getName() + "DAO";
+ String daoClassName = entityClass.getName() + "TopiaDao";
try {
Class<TopiaDAO<E>> daoClass = (Class<TopiaDAO<E>>) Class.forName(daoClassName);
dao = daoClass.getConstructor().newInstance();
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityDAOTransformer.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityDAOTransformer.java 2013-10-11 22:50:35 UTC (rev 2844)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityDAOTransformer.java 2013-10-15 15:08:16 UTC (rev 2845)
@@ -873,8 +873,7 @@
addParameter(op, attrType, "v");
setOperationBody(op, ""
/*{
- E result = <%=methodToDelegateName%>(v).findAnyOrNull();
- return result;
+ return <%=methodToDelegateName%>(v).findAnyOrNull();
}*/
);
@@ -887,8 +886,7 @@
addParameter(op, attrType, "v");
setOperationBody(op, ""
/*{
- List<E> result = <%=methodToDelegateName%>(v).findAll();
- return result;
+ return <%=methodToDelegateName%>(v).findAll();
}*/
);
@@ -956,8 +954,7 @@
addParameter(op, attrType, "v");
setOperationBody(op, ""
/*{
- E result = <%=methodToDelegateName%>(v).findAnyOrNull();
- return result;
+ return <%=methodToDelegateName%>(v).findAnyOrNull();
}*/
);
@@ -970,8 +967,7 @@
addParameter(op, attrType, "v");
setOperationBody(op, ""
/*{
- List<E> result = <%=methodToDelegateName%>(v).findAll();
- return result;
+ return <%=methodToDelegateName%>(v).findAll();
}*/
);
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/PersistenceContextTransformer.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/PersistenceContextTransformer.java 2013-10-11 22:50:35 UTC (rev 2844)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/PersistenceContextTransformer.java 2013-10-15 15:08:16 UTC (rev 2845)
@@ -176,10 +176,13 @@
for (ObjectModelClass clazz : entityClasses) {
String clazzName = clazz.getName();
- String daoClazzName = clazzName + "DAO";
+ // TODO brendan 14/10/13 use method
+ String daoContractName = clazzName + "Dao";
+ String daoClazzName = TopiaGeneratorUtil.getConcreteDaoName(clazz);
+
// specialized getXXXDao method
- op = addOperation(output, "get" + daoClazzName, clazz.getPackageName() + '.' + daoClazzName);
+ op = addOperation(output, "get" + daoContractName, clazz.getPackageName() + '.' + daoClazzName);
addImport(output, clazz);
setOperationBody(op, ""
/*{
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/AbstractTopiaDAO.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/AbstractTopiaDAO.java 2013-10-11 22:50:35 UTC (rev 2844)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/AbstractTopiaDAO.java 2013-10-15 15:08:16 UTC (rev 2845)
@@ -37,6 +37,7 @@
package org.nuiton.topia.persistence;
+import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
import com.google.common.collect.Iterables;
import com.google.common.collect.Iterators;
@@ -295,12 +296,6 @@
return result;
}
- /**
- * Cette methode appelle fireVetoableCreate et fireOnCreated Si vous la
- * surchargé, faites attention a appeler le super ou a appeler vous aussi
- * ces deux methodes.
- */
-
public E create(Map<String, Object> properties) {
E result = newInstance();
@@ -327,6 +322,11 @@
return result;
}
+ public E create() {
+ E result = newInstance();
+ create(result);
+ return result;
+ }
public E update(E e) {
try {
@@ -570,6 +570,18 @@
return getNextStep().findFirstOrNull();
}
+ public Optional<E> tryFindAny() {
+ return getNextStep().tryFindAny();
+ }
+
+ public Optional<E> tryFindFirst() {
+ return getNextStep().tryFindFirst();
+ }
+
+ public Optional<E> tryFindUnique() {
+ return getNextStep().tryFindUnique();
+ }
+
public List<E> findAll() {
return getNextStep().findAll();
}
@@ -634,6 +646,10 @@
return topiaDAO.findUniqueOrNull(hql, hqlParameters);
}
+ public Optional<E> tryFindUnique() {
+ return topiaDAO.tryFindUnique(hql, hqlParameters);
+ }
+
public E findFirst() {
return topiaDAO.findFirst(hql, hqlParameters);
}
@@ -642,6 +658,10 @@
return topiaDAO.findFirstOrNull(hql, hqlParameters);
}
+ public Optional<E> tryFindFirst() {
+ return topiaDAO.tryFindFirst(hql, hqlParameters);
+ }
+
public E findAny() {
return topiaDAO.findAny(hql, hqlParameters);
}
@@ -650,6 +670,10 @@
return topiaDAO.findAnyOrNull(hql, hqlParameters);
}
+ public Optional<E> tryFindAny() {
+ return topiaDAO.tryFindAny(hql, hqlParameters);
+ }
+
public List<E> findAll() {
return topiaDAO.findAll(hql, hqlParameters);
}
@@ -698,6 +722,11 @@
return uniqueOrNull;
}
+ protected Optional<E> tryFindUnique(String hql, Map<String, Object> hqlParameters) {
+ Optional<E> uniqueOrNull = tryFindUnique(hql, hqlParameters, getEntityClass());
+ return uniqueOrNull;
+ }
+
protected E findFirst(String hql, Map<String, Object> hqlParameters) {
E firstOrNull = findFirst(hql, hqlParameters, getEntityClass());
return firstOrNull;
@@ -708,6 +737,11 @@
return anyOrNull;
}
+ protected Optional<E> tryFindFirst(String hql, Map<String, Object> hqlParameters) {
+ Optional<E> anyOrNull = tryFindFirst(hql, hqlParameters, getEntityClass());
+ return anyOrNull;
+ }
+
protected E findAny(String hql, Map<String, Object> hqlParameters) {
E anyOrNull = findAny(hql, hqlParameters, getEntityClass());
return anyOrNull;
@@ -718,6 +752,11 @@
return anyOrNull;
}
+ protected Optional<E> tryFindAny(String hql, Map<String, Object> hqlParameters) {
+ Optional<E> anyOrNull = tryFindAny(hql, hqlParameters, getEntityClass());
+ return anyOrNull;
+ }
+
protected <R> R findUnique(String hql, Map<String, Object> hqlParameters, Class<R> type) {
R uniqueOrNull = findUniqueOrNull(hql, hqlParameters, type);
if (uniqueOrNull == null) {
@@ -727,6 +766,11 @@
return uniqueOrNull;
}
+ protected <R> Optional<R> tryFindUnique(String hql, Map<String, Object> hqlParameters, Class<R> type) {
+ R uniqueOrNull = findUniqueOrNull(hql, hqlParameters, type);
+ return Optional.fromNullable(uniqueOrNull);
+ }
+
protected <R> R findUniqueOrNull(String hql, Map<String, Object> hqlParameters, Class<R> type) {
List<R> results = findAll(hql, hqlParameters, type, 0, 1);
// If there is more than 1 result, throw an exception
@@ -750,6 +794,11 @@
return firstOrNull;
}
+ protected <R> Optional<R> tryFindFirst(String hql, Map<String, Object> hqlParameters, Class<R> type) {
+ R firstOrNull = findFirstOrNull(hql, hqlParameters, type);
+ return Optional.fromNullable(firstOrNull);
+ }
+
protected <R> R findFirstOrNull(String hql, Map<String, Object> hqlParameters, Class<R> type) {
Preconditions.checkArgument(hql.toLowerCase().contains("order by"));
R anyOrNull = findAnyOrNull(hql, hqlParameters, type);
@@ -765,6 +814,11 @@
return anyOrNull;
}
+ protected <R> Optional<R> tryFindAny(String hql, Map<String, Object> hqlParameters, Class<R> type) {
+ R anyOrNull = findAnyOrNull(hql, hqlParameters, type);
+ return Optional.fromNullable(anyOrNull);
+ }
+
protected <R> R findAnyOrNull(String hql, Map<String, Object> hqlParameters, Class<R> type) {
Preconditions.checkNotNull(hql);
Preconditions.checkNotNull(hqlParameters);
Modified: trunk/topia-persistence/src/test/java/org/nuiton/topia/TopiaJpaSupportTest.java
===================================================================
--- trunk/topia-persistence/src/test/java/org/nuiton/topia/TopiaJpaSupportTest.java 2013-10-11 22:50:35 UTC (rev 2844)
+++ trunk/topia-persistence/src/test/java/org/nuiton/topia/TopiaJpaSupportTest.java 2013-10-15 15:08:16 UTC (rev 2845)
@@ -23,8 +23,6 @@
*/
package org.nuiton.topia;
-import java.util.List;
-
import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
@@ -35,6 +33,8 @@
import org.nuiton.topiatest.Personne;
import org.nuiton.topiatest.PersonneDAO;
+import java.util.List;
+
/**
* Tests the TopiaContext#find|findAll|findUnique methods
*
@@ -56,8 +56,8 @@
persistenceContext = db.beginTransaction();
jpaSupport = persistenceContext.jpaSupport;
- personneDAO = persistenceContext.getPersonneDAO();
- addressDAO = persistenceContext.getAddressDAO();
+ personneDAO = persistenceContext.getPersonneDao();
+ addressDAO = persistenceContext.getAddressDao();
address = addressDAO.create(
Address.PROPERTY_ADRESS, "17 rue de la Pote Gellée, 44200 NANTES");
Modified: trunk/topia-persistence/src/test/java/org/nuiton/topia/generator/TopiaTestCase.java
===================================================================
--- trunk/topia-persistence/src/test/java/org/nuiton/topia/generator/TopiaTestCase.java 2013-10-11 22:50:35 UTC (rev 2844)
+++ trunk/topia-persistence/src/test/java/org/nuiton/topia/generator/TopiaTestCase.java 2013-10-15 15:08:16 UTC (rev 2845)
@@ -30,7 +30,6 @@
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;
@@ -124,8 +123,8 @@
// try {
TopiaTestTopiaPersistenceContext newContext = db.beginTransaction();
- CompanyDAO companyDAO = newContext.getCompanyDAO();
- DepartmentDAO departmentDAO = newContext.getDepartmentDAO();
+ CompanyDAO companyDAO = newContext.getCompanyDao();
+ DepartmentDAO departmentDAO = newContext.getDepartmentDao();
Company company = companyDAO.create();
company.setName("Ma société");
Modified: trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/EntityVisitorExportXmlTest.java
===================================================================
--- trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/EntityVisitorExportXmlTest.java 2013-10-11 22:50:35 UTC (rev 2844)
+++ trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/EntityVisitorExportXmlTest.java 2013-10-15 15:08:16 UTC (rev 2845)
@@ -72,14 +72,14 @@
TopiaTestTopiaPersistenceContext newContext = db.beginTransaction();
try {
// company
- CompanyDAO companyDAO = newContext.getCompanyDAO();
+ CompanyDAO companyDAO = newContext.getCompanyDao();
Company clCompany = companyDAO.create(Company.PROPERTY_NAME, "CodeLutin");
// employe
- EmployeDAO employeDAO = newContext.getEmployeDAO();
+ EmployeDAO employeDAO = newContext.getEmployeDao();
Employe empl1 = employeDAO.create(Employe.PROPERTY_NAME, "boss", Employe.PROPERTY_SALARY, 30000);
- AddressDAO adressDAO = newContext.getAddressDAO();
+ AddressDAO adressDAO = newContext.getAddressDao();
Address addr1 = adressDAO.create(Address.PROPERTY_CITY, "Nantes", Address.PROPERTY_ADRESS, "12 Avenue Jules Vernes");
empl1.setAddress(addr1);
@@ -88,7 +88,7 @@
empl2.setAddress(addr2);
// departement
- DepartmentDAO departmentDAO = newContext.getDepartmentDAO();
+ DepartmentDAO departmentDAO = newContext.getDepartmentDao();
Department depComm = departmentDAO.create(Department.PROPERTY_NAME, "Commercial");
depComm.setLeader(empl1);
@@ -117,7 +117,7 @@
TopiaTestTopiaPersistenceContext context = db.beginTransaction();
- CompanyDAO companyDAO = context.getCompanyDAO();
+ CompanyDAO companyDAO = context.getCompanyDao();
Company clCompany = companyDAO.findByName("CodeLutin");
EntityVisitor delegateVisitor = new ExportXMLVisitor();
Modified: trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/NaturalIdTest.java
===================================================================
--- trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/NaturalIdTest.java 2013-10-11 22:50:35 UTC (rev 2844)
+++ trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/NaturalIdTest.java 2013-10-15 15:08:16 UTC (rev 2845)
@@ -31,13 +31,10 @@
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.TopiaPersistenceContext;
import org.nuiton.topia.TopiaTestDAOHelper;
import org.nuiton.topia.TopiaTestTopiaPersistenceContext;
-import org.nuiton.topia.TopiaTransaction;
import org.nuiton.topiatest.NaturalizedEntity;
import org.nuiton.topiatest.NaturalizedEntityDAO;
@@ -65,7 +62,7 @@
TopiaTestTopiaPersistenceContext persistenceContext = db.beginTransaction();
NaturalizedEntityDAO dao =
- persistenceContext.getNaturalizedEntityDAO();
+ persistenceContext.getNaturalizedEntityDao();
// No exception will be thrown with the two properties
dao.createByNaturalId(5, "str");
@@ -86,7 +83,7 @@
TopiaTestTopiaPersistenceContext persistenceContext = db.beginTransaction();
NaturalizedEntityDAO dao =
- persistenceContext.getNaturalizedEntityDAO();
+ persistenceContext.getNaturalizedEntityDao();
// Exception will be throw
try {
@@ -112,7 +109,7 @@
TopiaTestTopiaPersistenceContext persistenceContext = db.beginTransaction();
NaturalizedEntityDAO dao =
- persistenceContext.getNaturalizedEntityDAO();
+ persistenceContext.getNaturalizedEntityDao();
NaturalizedEntity entity =
dao.createByNaturalId(5, "str");
@@ -135,7 +132,7 @@
NaturalizedEntityDAO dao =
- persistenceContext.getNaturalizedEntityDAO();
+ persistenceContext.getNaturalizedEntityDao();
NaturalizedEntity entity =
dao.createByNaturalId(5, "str");
@@ -153,7 +150,7 @@
NaturalizedEntityDAO dao =
- persistenceContext.getNaturalizedEntityDAO();
+ persistenceContext.getNaturalizedEntityDao();
dao.createByNaturalId(5, "str");
persistenceContext.commitTransaction();
Modified: trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/TopiaDAOTest.java
===================================================================
--- trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/TopiaDAOTest.java 2013-10-11 22:50:35 UTC (rev 2844)
+++ trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/TopiaDAOTest.java 2013-10-15 15:08:16 UTC (rev 2845)
@@ -61,7 +61,7 @@
public void setup() throws TopiaException {
context = db.beginTransaction();
- dao = context.getPersonDAO();
+ dao = context.getPersonDao();
}
/**
1
0