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
February 2010
- 3 participants
- 23 discussions
r1816 - trunk/topia-persistence/src/main/java/org/nuiton/topia/generator
by tchemit@users.nuiton.org 26 Feb '10
by tchemit@users.nuiton.org 26 Feb '10
26 Feb '10
Author: tchemit
Date: 2010-02-26 19:52:36 +0100 (Fri, 26 Feb 2010)
New Revision: 1816
Modified:
trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/DAOAbstractTransformer.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/DAOHelperTransformer.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityAbstractTransformer.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/TopiaGeneratorUtil.java
Log:
- Evolution #331: Add methods findUsages on TopiaDAO api
- Evolution #332: Add getModelName method on generated DAOHelper
- reformat code (80 caracters max on a line)
- use caracters rather than one string
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/DAOAbstractTransformer.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/DAOAbstractTransformer.java 2010-02-26 18:48:25 UTC (rev 1815)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/DAOAbstractTransformer.java 2010-02-26 18:52:36 UTC (rev 1816)
@@ -31,6 +31,7 @@
import org.nuiton.topia.framework.TopiaContextImplementor;
import org.nuiton.topia.persistence.TopiaDAO;
import org.nuiton.topia.persistence.TopiaDAOImpl;
+import org.nuiton.topia.persistence.TopiaEntity;
import org.nuiton.util.StringUtil;
import java.util.*;
@@ -60,8 +61,16 @@
*/
private static final Log log = LogFactory.getLog(
DAOAbstractTransformer.class);
-
+
+ Map<ObjectModelClass, Set<ObjectModelClass>> usages;
+
@Override
+ public void transformFromModel(ObjectModel model) {
+
+ usages = TopiaGeneratorUtil.searchDirectUsages(model);
+ }
+
+ @Override
public void transformFromClass(ObjectModelClass clazz) {
if (!clazz.hasStereotype(TopiaGeneratorUtil.STEREOTYPE_ENTITY)) {
return;
@@ -70,7 +79,7 @@
String clazzName = clazz.getName();
ObjectModelClass result = createAbstractClass(
- clazzName + "DAOAbstract<E extends " + clazzName + ">",
+ clazzName + "DAOAbstract<E extends " + clazzName + '>',
clazz.getPackageName());
// super class
@@ -148,91 +157,14 @@
generateDAOOperations(result, DAOoperations);
- // delete
-
- op = addOperation(result, "delete", "void", ObjectModelModifier.PUBLIC);
- addException(op, TopiaException.class);
- addParameter(op, "E", "entity");
- StringBuilder body = new StringBuilder();
- String modelName = StringUtils.capitalize(model.getName());
- String providerFQN = getOutputProperties().getProperty(
- Template.PROP_DEFAULT_PACKAGE) + "." + modelName +
- "DAOHelper.getImplementationClass";
- for (ObjectModelAttribute attr : clazz.getAttributes()) {
- String attrType = attr.getType();
- String reverseAttrName = attr.getReverseAttributeName();
- ObjectModelAttribute reverse = attr.getReverseAttribute();
- if (!attr.hasAssociationClass() && reverse != null && reverse.isNavigable()
- && 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
+ generateDelete(clazz,result);
- String attrDBName = TopiaGeneratorUtil.getDBName(attr);
- String attrClassifierDBName = TopiaGeneratorUtil.getDBName(attr.getClassifier());
- String attrJoinTableName = TopiaGeneratorUtil.getManyToManyTableName(attr);
- String attrReverseDBName = TopiaGeneratorUtil.getReverseDBName(attr);
- body.append(""
-/*{
- {
- List<<%=attrType%>> list = getContext().getHibernate().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.remove<%=StringUtils.capitalize(reverseAttrName)%>(entity);
- }
- }
-}*/
- );
- } else if (!attr.hasAssociationClass() && reverse != null
- && reverse.isNavigable()
- && !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
- body.append(""
- /*{
- {
- List<<%=attrType%>> list = getContext()
- .getDAO(<%=attrType%>.class)
- .findAllByProperties("<%=reverseAttrName%>", entity);
- for (<%=attrType%> item : list) {
- item.set<%=StringUtils.capitalize(reverseAttrName)%>(null);
-}*/
- );
- if(attr.isAggregate()){
- body.append(""
-/*{
- item.delete();
-}*/
- );
- }
- body.append(""
-/*{
- }
- }
-}*/
- );
-
- }
- }
- body.append(""
-/*{
- super.delete(entity);
- }*/
- );
- setOperationBody(op,body.toString());
-
generateNaturalId(result, clazz);
for (ObjectModelAttribute attr : clazz.getAttributes()) {
if (!attr.isNavigable()) {
continue;
}
- String attrName = attr.getName();
if (!GeneratorUtil.isNMultiplicity(attr)) {
generateNoNMultiplicity(clazzName, result, attr, false);
@@ -345,8 +277,274 @@
}*/
);
}
+
+ Set<ObjectModelClass> usagesForclass = usages.get(clazz);
+ generateFindUsages(clazz,result,usagesForclass);
}
+ private void generateDelete(ObjectModelClass clazz,
+ ObjectModelClass result) {
+ ObjectModelOperation op;
+ op = addOperation(result, "delete", "void", ObjectModelModifier.PUBLIC);
+ addException(op, TopiaException.class);
+ addParameter(op, "E", "entity");
+ StringBuilder body = new StringBuilder();
+ String modelName = StringUtils.capitalize(model.getName());
+ String providerFQN = getOutputProperties().getProperty(
+ Template.PROP_DEFAULT_PACKAGE) + '.' + modelName +
+ "DAOHelper.getImplementationClass";
+ for (ObjectModelAttribute attr : clazz.getAttributes()) {
+ String attrType = attr.getType();
+ String reverseAttrName = attr.getReverseAttributeName();
+ ObjectModelAttribute reverse = attr.getReverseAttribute();
+ if (!attr.hasAssociationClass() && reverse != null && reverse.isNavigable()
+ && 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);
+ body.append(""
+/*{
+ {
+ List<<%=attrType%>> list = getContext().getHibernate().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.remove<%=StringUtils.capitalize(reverseAttrName)%>(entity);
+ }
+ }
+}*/
+ );
+ } else if (!attr.hasAssociationClass() && reverse != null
+ && reverse.isNavigable()
+ && !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
+ builder.addImport(result, attrType);
+ String attrSimpleType = TopiaGeneratorUtil.getClassNameFromQualifiedName(attrType);
+
+ body.append(""
+ /*{
+ {
+ List<<%=attrSimpleType%>> list = getContext()
+ .getDAO(<%=attrSimpleType%>.class)
+ .findAllByProperties(<%=attrSimpleType%>.<%=getConstantName(reverseAttrName)%>, entity);
+// .findAllByProperties("<%=reverseAttrName%>", entity);
+ for (<%=attrSimpleType%> item : list) {
+ item.set<%=StringUtils.capitalize(reverseAttrName)%>(null);
+}*/
+ );
+ if(attr.isAggregate()){
+ body.append(""
+/*{
+ item.delete();
+}*/
+ );
+ }
+ body.append(""
+/*{
+ }
+ }
+}*/
+ );
+
+ }
+ }
+ body.append(""
+/*{
+ super.delete(entity);
+ }*/
+ );
+
+ setOperationBody(op,body.toString());
+ }
+ private 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>",
+ ObjectModelModifier.PUBLIC);
+
+ addParameter(operation, "Class<U>", "type");
+ addParameter(operation, "E", "entity");
+ addException(operation, TopiaException.class);
+ addAnnotation(result, operation,"Override");
+ setOperationBody(operation,""
+/*{
+ return new ArrayList<U>();
+ }*/
+ );
+
+ operation = addOperation(result,
+ "findAllUsages",
+ "Map<Class<?>, List<? extends TopiaEntity>>",
+ ObjectModelModifier.PUBLIC);
+
+ addParameter(operation, "E", "entity");
+ addException(operation, TopiaException.class);
+ addAnnotation(result, operation,"Override");
+ setOperationBody(operation, ""
+/*{
+ return new HashMap<Class<?>, 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>",
+ ObjectModelModifier.PUBLIC);
+
+ addParameter(operation,"Class<U>","type");
+ addParameter(operation,"E","entity");
+ addException(operation,TopiaException.class);
+ addAnnotation(result, operation,"Override");
+ 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);
+
+ 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 (!GeneratorUtil.isNMultiplicity(attr)) {
+ methodName = "findAllBy"+ StringUtils.capitalize(attrName);
+ } else {
+ methodName = "findAllContains"+ StringUtils.capitalize(attrName);
+ }
+ String daoName = StringUtils.capitalize(usageSimpleType) + "DAO";
+
+ builder.addImport(result, usageClass.getPackageName() + '.' + daoName);
+
+ buffer.append(""
+/*{
+ if (type == <%=usageSimpleType%>.class) {
+ <%=daoName%> dao = (<%=daoName%>)
+ getContext().getDAO(<%=usageSimpleType%>.class);
+ tmp = dao.<%=methodName%>(entity);
+// tmp = dao.findAllByProperties(<%=usageSimpleType%>.<%=getConstantName(attrName)%>, entity);
+ result.addAll(tmp);
+ }
+}*/
+ );
+ }
+ }
+
+ buffer.append(""
+/*{
+ return (List<U>) result;
+ }*/
+ );
+ setOperationBody(operation, buffer.toString());
+
+ operation = addOperation(result,
+ "findAllUsages",
+ "Map<Class<?>, List<? extends TopiaEntity>>",
+ ObjectModelModifier.PUBLIC);
+
+ addParameter(operation, "E", "entity");
+ addException(operation, TopiaException.class);
+ addAnnotation(result, operation,"Override");
+
+ buffer = new StringBuilder(300);
+ buffer.append(""
+/*{
+ Map<Class<?>,List<? extends TopiaEntity>> result;
+ result = new HashMap<Class<?>, 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.
@@ -445,7 +643,7 @@
String propertyName = attrName;
if (!isAssoc && attr.hasAssociationClass()) {
propertyName = TopiaGeneratorUtil.toLowerCaseFirstLetter(
- attr.getAssociationClass().getName()) + "." + propertyName;
+ attr.getAssociationClass().getName()) + '.' + propertyName;
}
ObjectModelOperation op;
op = addOperation(result,
@@ -627,7 +825,7 @@
addParameter(create, attr.getType(), propName);
searchProperties +=
- ", " + clazzName + "." + getConstantName(propName) +
+ ", " + clazzName + '.' + getConstantName(propName) +
", " + propName;
params += ", " + propName;
}
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 2010-02-26 18:48:25 UTC (rev 1815)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/DAOHelperTransformer.java 2010-02-26 18:52:36 UTC (rev 1816)
@@ -101,13 +101,21 @@
}*/
);
+ // getModelName method
+ op = addOperation(resultClass, "getModelName", "String", ObjectModelModifier.PUBLIC, ObjectModelModifier.STATIC);
+ setOperationBody(op, ""
+ /*{
+ return "<%=modelName%>";
+ }*/
+ );
+
for (ObjectModelClass clazz : classes) {
String clazzName = clazz.getName();
String daoClazzName = clazzName + "DAO";
// specialized getXXXDao method
- op = addOperation(resultClass, "get" + daoClazzName, clazz.getPackageName() + "." + daoClazzName, ObjectModelModifier.PUBLIC, ObjectModelModifier.STATIC);
+ op = addOperation(resultClass, "get" + daoClazzName, clazz.getPackageName() + '.' + daoClazzName, ObjectModelModifier.PUBLIC, ObjectModelModifier.STATIC);
addParameter(op, TopiaContext.class, "context");
addImport(resultClass, clazz);
addException(op, TopiaException.class);
@@ -234,7 +242,7 @@
for (ObjectModelClass clazz : classes) {
String clazzName = clazz.getName();
- addLiteral(entityEnum, clazzName + "(" + clazzName + ".class)");
+ addLiteral(entityEnum, clazzName + '(' + clazzName + ".class)");
}
attr = (ObjectModelAttributeImpl) addAttribute(entityEnum, "contract", "Class<? extends TopiaEntity>");
attr.setDocumentation("the contract of the entity");
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityAbstractTransformer.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityAbstractTransformer.java 2010-02-26 18:48:25 UTC (rev 1815)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityAbstractTransformer.java 2010-02-26 18:52:36 UTC (rev 1816)
@@ -40,7 +40,6 @@
import java.util.List;
/*{generator option: parentheses = false}*/
-
/*{generator option: writeString = +}*/
/**
@@ -175,7 +174,7 @@
if (GeneratorUtil.isNMultiplicity(attr)) {
String collectionType =
TopiaGeneratorUtil.getNMultiplicityInterfaceType(attr);
- type = collectionType + "<" + type + ">";
+ type = collectionType + '<' + type + '>';
}
String attrVisibility = attr.getVisibility();
@@ -189,14 +188,14 @@
attr.hasTagValue(TopiaGeneratorUtil.TAG_DB_NAME)) {
if (TopiaGeneratorUtil.hasDocumentation(attr)) {
String attrDocumentation = attr.getDocumentation();
- doc.append(attrDocumentation).append("\n");
+ doc.append(attrDocumentation).append('\n');
}
if (attr.hasTagValue(TopiaGeneratorUtil.TAG_DB_NAME)) {
String dbName =
attr.getTagValue(TopiaGeneratorUtil.TAG_DB_NAME);
doc.append("Nom de l'attribut en BD : ");
doc.append(dbName);
- doc.append("\n");
+ doc.append('\n');
}
}
@@ -430,7 +429,7 @@
"addAll" + StringUtils.capitalize(attrName),
"void",
ObjectModelModifier.PUBLIC);
- addParameter(op, collectionInterface + "<" + attrType + ">", "values");
+ addParameter(op, collectionInterface + '<' + attrType + '>', "values");
setOperationBody(op, ""
/*{
@@ -464,7 +463,7 @@
"set" + StringUtils.capitalize(attrName),
"void",
ObjectModelModifier.PUBLIC);
- addParameter(op, collectionInterface + "<" + attrType + ">", "values");
+ addParameter(op, collectionInterface + '<' + attrType + '>', "values");
setOperationBody(op, ""
/*{
@@ -631,7 +630,7 @@
"addAll" + StringUtils.capitalize(assocAttrName),
"void",
ObjectModelModifier.PUBLIC);
- addParameter(op, collectionInterface + "<" + assocClassFQN + ">", "values");
+ addParameter(op, collectionInterface + '<' + assocClassFQN + '>', "values");
setOperationBody(op, ""
/*{
if (values == null) {
@@ -649,7 +648,7 @@
"set" + StringUtils.capitalize(assocAttrName),
"void",
ObjectModelModifier.PUBLIC);
- addParameter(op, collectionInterface + "<" + assocClassFQN + ">", "values");
+ addParameter(op, collectionInterface + '<' + assocClassFQN + '>', "values");
setOperationBody(op, ""
/*{
// clear<%=StringUtils.capitalize(assocAttrName)%>();
@@ -738,7 +737,7 @@
op = addOperation(result,
"get" + StringUtils.capitalize(attrName),
- collectionInterface + "<" + attrType + ">",
+ collectionInterface + '<' + attrType + '>',
ObjectModelModifier.PUBLIC);
setOperationBody(op, ""
/*{
@@ -783,7 +782,7 @@
op = addOperation(result,
"get" + StringUtils.capitalize(assocAttrName),
- collectionInterface + "<" + assocClassFQN + ">",
+ collectionInterface + '<' + assocClassFQN + '>',
ObjectModelModifier.PUBLIC);
setOperationBody(op, ""
/*{
@@ -845,8 +844,9 @@
}
}
- protected void generateAssociationAccessors(ObjectModelClass result,
- ObjectModelAssociationClass assoc) {
+ protected void generateAssociationAccessors(
+ ObjectModelClass result,
+ ObjectModelAssociationClass assoc) {
for (ObjectModelAttribute attr : assoc.getParticipantsAttributes()) {
if (attr != null) {
String attrType = TopiaGeneratorUtil.getSimpleName(attr.getType());
@@ -915,7 +915,7 @@
ObjectModelOperation op = addOperation(result,
"getComposite",
- List.class.getName() + "<" + TopiaEntity.class.getName() + ">",
+ List.class.getName() + '<' + TopiaEntity.class.getName() + '>',
ObjectModelModifier.PUBLIC);
addException(op, TopiaException.class);
StringBuilder body = new StringBuilder();
@@ -1014,7 +1014,7 @@
ObjectModelOperation op = addOperation(result,
"accept",
- List.class.getName() + "<" + TopiaEntity.class.getName() + ">",
+ List.class.getName() + '<' + TopiaEntity.class.getName() + '>',
ObjectModelModifier.PUBLIC);
addException(op, TopiaException.class);
@@ -1065,7 +1065,8 @@
setOperationBody(op, body.length() == 0 ? " " : body.toString());
}
- protected void generateAcceptMethod(ObjectModelClass result, ObjectModelClass clazz) {
+ protected void generateAcceptMethod(ObjectModelClass result,
+ ObjectModelClass clazz) {
ObjectModelOperation op = addOperation(result,
"accept",
@@ -1160,7 +1161,8 @@
}
- private void generateAssociationAccessors(ObjectModelClass result, String name, String type) {
+ private void generateAssociationAccessors(ObjectModelClass result,
+ String name, String type) {
ObjectModelOperation op;
op = addOperation(result,
"set" + StringUtils.capitalize(name),
@@ -1197,7 +1199,8 @@
* @param result ObjectModelClass result corresponding to the EntityAbstract
* @param clazz ObjectModelClass source from ObjectModel
*/
- private void generateAbstractMethods(ObjectModelClass result, ObjectModelClass clazz) {
+ private void generateAbstractMethods(ObjectModelClass result,
+ ObjectModelClass clazz) {
for (ObjectModelOperation op : clazz.getOperations()) {
if (log.isDebugEnabled()) {
log.debug("clazz : " + clazz.getQualifiedName() +
@@ -1216,12 +1219,16 @@
}
}
- private void generateI18n(ObjectModelClass result, String i18nPrefix, ObjectModelClass clazz) {
+ private void generateI18n(ObjectModelClass result, String i18nPrefix,
+ ObjectModelClass clazz) {
- StringBuilder buffer = new StringBuilder();
+ StringBuilder buffer = new StringBuilder(300);
addI18n(buffer, i18nPrefix, Introspector.decapitalize(clazz.getName()));
for (ObjectModelAttribute attr : clazz.getAttributes()) {
- addI18n(buffer, i18nPrefix, Introspector.decapitalize(attr.getName()));
+ //TC-20100225 only treate navigable relations
+ if (attr.isNavigable()) {
+ addI18n(buffer, i18nPrefix, Introspector.decapitalize(attr.getName()));
+ }
}
//FIXME : use a block extension for java
@@ -1229,7 +1236,8 @@
setOperationBody(op, buffer.toString());
}
- private void addI18n(StringBuilder buffer, String i18nPrefix, String suffix) {
+ private void addI18n(StringBuilder buffer, String i18nPrefix,
+ String suffix) {
buffer.append("\n org.nuiton.i18n.I18n.n_(\"");
buffer.append(i18nPrefix);
buffer.append(suffix);
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 2010-02-26 18:48:25 UTC (rev 1815)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/TopiaGeneratorUtil.java 2010-02-26 18:52:36 UTC (rev 1816)
@@ -29,16 +29,11 @@
*/
package org.nuiton.topia.generator;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Set;
+import java.util.*;
import org.apache.commons.lang.StringUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.nuiton.eugene.AbstractGenerator;
import org.nuiton.eugene.GeneratorUtil;
import org.nuiton.eugene.models.Model;
@@ -57,6 +52,11 @@
public class TopiaGeneratorUtil extends GeneratorUtil {
/**
+ * Logger
+ */
+ private static final Log log = LogFactory.getLog(TopiaGeneratorUtil.class);
+
+ /**
* Stéréotype pour les interfaces devant être générées sous forme de facades
*/
public final static String STEREOTYPE_FACADE = "facade";
@@ -308,7 +308,8 @@
}
/**
- * Cherche et renvoie le schema a utiliser sur cet element, sinon sur le model.
+ * Cherche et renvoie le schema a utiliser sur cet element, sinon sur le
+ * model.
*
* @param element l'élément à tester
* @param model le modele utilisé
@@ -320,7 +321,8 @@
}
/**
- * Cherche et renvoie le prefixe i18n à utiliser sur cet element, sinon sur le model.
+ * Cherche et renvoie le prefixe i18n à utiliser sur cet element, sinon sur
+ * le model.
*
* @param element l'élément à tester
* @param model le modele utilisé
@@ -332,25 +334,32 @@
}
/**
- * Cherche et renvoie le prefixe i18n à utiliser sur cet element, sinon sur le model.
+ * Cherche et renvoie le prefixe i18n à utiliser sur cet element, sinon sur
+ * le model.
*
* @param element l'élément à tester
* @param model le modele utilisé
* @return le prefix i18n ou <code>null</code> si non spécifié
*/
- public static boolean shouldgenerateOperatorForDAOHelper(ObjectModelElement element,
- ObjectModel model) {
- String tagValue = GeneratorUtil.findTagValue(TAG_GENERATE_OPERATOR_FOR_DAO_HELPER, element, model);
- boolean generate = GeneratorUtil.notEmpty(tagValue) && Boolean.valueOf(tagValue);
+ public static boolean shouldgenerateOperatorForDAOHelper(
+ ObjectModelElement element,
+ ObjectModel model) {
+ String tagValue = GeneratorUtil.findTagValue(
+ TAG_GENERATE_OPERATOR_FOR_DAO_HELPER, element, model);
+ boolean generate = GeneratorUtil.notEmpty(tagValue) &&
+ Boolean.valueOf(tagValue);
return generate;
}
/**
- * Cherche et renvoie la liste des attributs constituant la clef metier d'une classe.
+ * Cherche et renvoie la liste des attributs constituant la clef metier
+ * d'une classe.
*
* @param clazz la classe à tester
- * @return la liste des attributs de la clef métier ou null si pas de clef métier.
- * @deprecated use {@link #getNaturalIdAttributes(ObjectModelClass) } instead
+ * @return la liste des attributs de la clef métier ou null si pas de clef
+ * métier.
+ * @deprecated since 2.3.0 use
+ * {@link #getNaturalIdAttributes(ObjectModelClass) } instead
* this usage is not allowed, prefer put tagvalue.naturalId on each
* entity attribute needed
*/
@@ -358,7 +367,7 @@
public static List<String> getNaturalId(ObjectModelClass clazz) {
String value = clazz.getTagValue(TAG_NATURAL_ID);
if (value == null || value.trim().isEmpty()) {
- return java.util.Collections.emptyList();
+ return Collections.emptyList();
}
List<String> result = new ArrayList<String>();
for (String attribute : value.split(",")) {
@@ -368,13 +377,16 @@
}
/**
- * Cherche et renvoie la liste des attributs constituant la clef metier d'une classe.
+ * Cherche et renvoie la liste des attributs constituant la clef metier
+ * d'une classe.
*
* @param clazz la classe à tester
* @return la liste des attributs de la clef métier
*/
- public static List<ObjectModelAttribute> getNaturalIdAttributes(ObjectModelClass clazz) {
- List<ObjectModelAttribute> results = new ArrayList<ObjectModelAttribute>();
+ public static List<ObjectModelAttribute> getNaturalIdAttributes(
+ ObjectModelClass clazz) {
+ List<ObjectModelAttribute> results =
+ new ArrayList<ObjectModelAttribute>();
for (ObjectModelAttribute attr : clazz.getAttributes()) {
if (isNaturalId(attr)) {
results.add(attr);
@@ -384,11 +396,13 @@
}
/**
- * Cherche et renvoie la liste des attributs constituant la clef metier d'une classe.
+ * Cherche et renvoie la liste des attributs constituant la clef metier
+ * d'une classe.
*
* @param clazz la classe à tester
* @param model le modele
- * @return la liste des attributs de la clef métier ou null si pas de clef métier.
+ * @return la liste des attributs de la clef métier ou null si pas de
+ * clef métier.
*/
public static boolean generateToString(ObjectModelClass clazz,
ObjectModel model) {
@@ -402,17 +416,20 @@
}
/**
- * Cherche et renvoie la liste des attributs constituant la clef metier d'une classe.
+ * Cherche et renvoie la liste des attributs constituant la clef metier
+ * d'une classe.
*
* @param clazz la classe à tester
* @param model le modele
- * @return la liste des attributs de la clef métier ou null si pas de clef métier.
+ * @return la liste des attributs de la clef métier ou null si pas de
+ * clef métier.
*/
public static boolean sortAttribute(ObjectModelClass clazz,
ObjectModel model) {
String value;
value = clazz.getTagValue(TAG_SORT_ATTRIBUTE);
- if (value == null || value.trim().isEmpty() || "false".equals(value.trim())) {
+ if (value == null || value.trim().isEmpty() ||
+ "false".equals(value.trim())) {
return false;
}
if ("true".equals(value.trim())) {
@@ -420,7 +437,8 @@
}
value = model.getTagValue(TAG_SORT_ATTRIBUTE);
- if (value == null || value.trim().isEmpty() || "false".equals(value.trim())) {
+ if (value == null || value.trim().isEmpty() ||
+ "false".equals(value.trim())) {
return false;
}
if ("true".equals(value.trim())) {
@@ -433,7 +451,8 @@
* Detecte si un attribut fait partie d'une clef metier.
*
* @param attribute l'attribut à tester
- * @return <code>true</code> si l'attribut fait partie d'une clef metier, <code>false</cdoe> sinon.
+ * @return <code>true</code> si l'attribut fait partie d'une clef metier,
+ * <code>false</cdoe> sinon.
*/
public static boolean isNaturalId(ObjectModelAttribute attribute) {
String value = attribute.getTagValue(TAG_NATURAL_ID);
@@ -506,10 +525,13 @@
public static String getPrimaryKeyAttributesListDeclaration(
ObjectModelClass clazz, boolean includeName) {
String attributes = "";
- for (ObjectModelAttribute attr : getElementsWithStereotype(clazz.getAttributes(), STEREOTYPE_PRIMARYKAY)) {
+ final Collection<ObjectModelAttribute> attributeCollection;
+ attributeCollection = getElementsWithStereotype(clazz.getAttributes(),
+ STEREOTYPE_PRIMARYKAY);
+ for (ObjectModelAttribute attr : attributeCollection) {
attributes += attr.getType();
if (includeName) {
- attributes += " " + attr.getName();
+ attributes += ' ' + attr.getName();
}
attributes += ", ";
}
@@ -524,7 +546,10 @@
// }
public static boolean isAssociationClassDoublon(ObjectModelAttribute attr) {
- return (attr.getReverseAttribute() != null) && (attr.getDeclaringElement().equals(attr.getReverseAttribute().getDeclaringElement())) && (!GeneratorUtil.isFirstAttribute(attr));
+ return (attr.getReverseAttribute() != null) &&
+ (attr.getDeclaringElement().equals(
+ attr.getReverseAttribute().getDeclaringElement())) &&
+ (!GeneratorUtil.isFirstAttribute(attr));
}
/**
@@ -540,7 +565,8 @@
attr.getType().lastIndexOf(".") + 1);
String result = attr.getName();
if (attr.getName().equalsIgnoreCase(typeName)) {
- result += StringUtils.capitalize(attr.getAssociationClass().getName());
+ result += StringUtils.capitalize(
+ attr.getAssociationClass().getName());
}
return result;
}
@@ -656,7 +682,8 @@
* @return true dans ce cas, false sinon
*/
public static boolean shouldBeAbstract(ObjectModelClass clazz) {
- return clazz != null && (clazz.isAbstract() && hasNothingOrAbstractMethods(clazz));
+ return clazz != null && clazz.isAbstract() &&
+ hasNothingOrAbstractMethods(clazz);
}
/**
@@ -679,7 +706,8 @@
ObjectModelAttribute attr, ObjectModel model) {
ObjectModelAttribute reverse = attr.getReverseAttribute();
//relation 1-n
- if (reverse != null && isNMultiplicity(attr) && !isNMultiplicity(reverse)) {
+ if (reverse != null && isNMultiplicity(attr) &&
+ !isNMultiplicity(reverse)) {
//Pas de navigabilité
if (!reverse.isNavigable()) {
//Il s'agit d'une entity
@@ -717,9 +745,9 @@
String revers = attr.getReverseAttributeName();
if (name.compareToIgnoreCase(revers) < 0) {
- result = name + "_" + revers;
+ result = name + '_' + revers;
} else {
- result = revers + "_" + name;
+ result = revers + '_' + name;
}
}
// String result;
@@ -737,7 +765,8 @@
* @param attr l'attribut a traiter
* @return String
*/
- public static String getNMultiplicityInterfaceType(ObjectModelAttribute attr) {
+ public static String getNMultiplicityInterfaceType(
+ ObjectModelAttribute attr) {
if (attr.hasStereotype(STEREOTYPE_UNIQUE)) {
return Set.class.getName();
} else if (attr.isIndexed() || attr.isOrdered()) {
@@ -771,7 +800,8 @@
* @param attr l'attribut a traiter
* @return String
*/
- public static String getNMultiplicityHibernateType(ObjectModelAttribute attr) {
+ public static String getNMultiplicityHibernateType(
+ ObjectModelAttribute attr) {
if (attr.hasStereotype(STEREOTYPE_UNIQUE)) {
return "set";
} else if (attr.isIndexed()) {
@@ -782,7 +812,8 @@
}
/**
- * Obtain the list of entities classes with the possibility to sort the result.
+ * Obtain the list of entities classes with the possibility to sort the
+ * result.
*
* @param model the current model to scan
* @param sort flag to allow sort the result
@@ -794,7 +825,8 @@
}
/**
- * Obtain the list of classes for a given stereotype with the possibility to sort the result.
+ * Obtain the list of classes for a given stereotype with the possibility
+ * to sort the result.
*
* @param stereotype filter stereotype
* @param model the current model to scan
@@ -810,28 +842,34 @@
}
}
if (sort && !classes.isEmpty()) {
- java.util.Collections.sort(classes,
- new java.util.Comparator<ObjectModelClass>() {
- @Override
- public int compare(ObjectModelClass o1,
- ObjectModelClass o2) {
- return o1.getQualifiedName().compareTo(
- o2.getQualifiedName());
- }
- });
+ Collections.sort(classes, OBJECT_MODEL_CLASS_COMPARATOR);
}
return classes;
}
+ static public final Comparator<ObjectModelClass>
+ OBJECT_MODEL_CLASS_COMPARATOR =
+ new Comparator<ObjectModelClass>() {
+
+ @Override
+ public int compare(ObjectModelClass o1,
+ ObjectModelClass o2) {
+ return o1.getQualifiedName().compareTo(
+ o2.getQualifiedName());
+ }
+ };
+
/**
* Detecte si la clef metier d'une classe est mutable ou pas.
* <p/>
- * On respecte la valeur par defaut d'hibernate, à savoir que par default une clef metier est non mutable.
+ * On respecte la valeur par defaut d'hibernate, à savoir que par default
+ * une clef metier est non mutable.
*
* @param clazz la classe a tester
- * @return <code>true</code> si le tag value a ete positionne sur la classe via le tag
- * {@link #TAG_NATURAL_ID_MUTABLE}, , <code>false</code> sinon.
+ * @return <code>true</code> si le tag value a ete positionne sur la classe
+ * via le tag {@link #TAG_NATURAL_ID_MUTABLE}, <code>false</code>
+ * sinon.
*/
public static boolean isNaturalIdMutable(ObjectModelClass clazz) {
String value = clazz.getTagValue(TAG_NATURAL_ID_MUTABLE);
@@ -855,7 +893,8 @@
* @param incomingFqns incoming fqns
* @return the list of fqn of attributes
*/
- public static List<String> getImports(ObjectModelClass aClass, String... incomingFqns) {
+ public static List<String> getImports(ObjectModelClass aClass,
+ String... incomingFqns) {
Set<String> tmp = new HashSet<String>();
tmp.addAll(Arrays.asList(incomingFqns));
getImports(aClass, tmp);
@@ -870,7 +909,8 @@
* @param incomingFqns incoming fqns
* @return the list of fqn of attributes
*/
- public static List<String> getImports(ObjectModelInterface anInterface, String... incomingFqns) {
+ public static List<String> getImports(ObjectModelInterface anInterface,
+ String... incomingFqns) {
Set<String> tmp = new HashSet<String>();
tmp.addAll(Arrays.asList(incomingFqns));
getImports(anInterface, tmp);
@@ -899,7 +939,8 @@
* @param aClass the class to inspect
* @param fqns where to store found fqns
*/
- protected static void getImports(ObjectModelClass aClass, Set<String> fqns) {
+ protected static void getImports(ObjectModelClass aClass,
+ Set<String> fqns) {
// scan attributes
for (ObjectModelAttribute attr : aClass.getAttributes()) {
fqns.add(attr.getType());
@@ -915,8 +956,10 @@
}
// scan associations
if (aClass instanceof ObjectModelAssociationClass) {
- ObjectModelAssociationClass assoc = (ObjectModelAssociationClass) aClass;
- for (ObjectModelAttribute attr : assoc.getParticipantsAttributes()) {
+ ObjectModelAssociationClass assoc =
+ (ObjectModelAssociationClass) aClass;
+ for (ObjectModelAttribute attr :
+ assoc.getParticipantsAttributes()) {
if (attr == null) {
continue;
}
@@ -951,7 +994,8 @@
* @param anInterface the interface to inspect
* @param fqns where to store found fqns
*/
- protected static void getImports(ObjectModelInterface anInterface, Set<String> fqns) {
+ protected static void getImports(ObjectModelInterface anInterface,
+ Set<String> fqns) {
// scan operations
for (ObjectModelOperation operation : anInterface.getOperations()) {
getImports(operation, fqns);
@@ -969,7 +1013,8 @@
* @param operation operation to inspect
* @param fqns where to store found fqns
*/
- protected static void getImports(ObjectModelOperation operation, Set<String> fqns) {
+ protected static void getImports(ObjectModelOperation operation,
+ Set<String> fqns) {
String fqn = operation.getReturnType();
fqns.add(fqn);
for (ObjectModelParameter parameter : operation.getParameters()) {
@@ -984,7 +1029,8 @@
* @param fqns the dirty set of fqns
* @return the sorted cleaned list of fqns.
*/
- protected static List<String> cleanImports(String packageName, Set<String> fqns) {
+ protected static List<String> cleanImports(String packageName,
+ Set<String> fqns) {
fqns.removeAll(primitiveTypes);
fqns.remove(VOID_TYPE);
int packageLength = packageName.length();
@@ -1006,7 +1052,7 @@
fqns.addAll(genericType);
ArrayList<String> result = new ArrayList<String>(fqns);
- java.util.Collections.sort(result);
+ Collections.sort(result);
return result;
}
@@ -1042,5 +1088,65 @@
}
return buffer.toString();
}
+
+ public static Map<ObjectModelClass, Set<ObjectModelClass>>
+ searchDirectUsages(ObjectModel model) {
+ List<ObjectModelClass> allEntities;
+ Map<String, ObjectModelClass> allEntitiesByFQN;
+ Map<ObjectModelClass, Set<ObjectModelClass>> usages;
+
+ allEntities = getEntityClasses(model, true);
+
+ allEntitiesByFQN = new TreeMap<String, ObjectModelClass>();
+ usages = new LinkedHashMap<ObjectModelClass, Set<ObjectModelClass>>();
+
+ // prepare usages map and fill allEntitiesByFQN map
+ for (ObjectModelClass klass : allEntities) {
+ usages.put(klass, new HashSet<ObjectModelClass>());
+ allEntitiesByFQN.put(klass.getQualifiedName(), klass);
+ }
+
+ // first pass to detect direct usages
+ for (ObjectModelClass klass : allEntities) {
+ searchDirectUsages(klass, allEntitiesByFQN, usages);
+ }
+ allEntities.clear();
+ allEntitiesByFQN.clear();
+ return usages;
+
+ }
+
+ public static void searchDirectUsages(
+ ObjectModelClass klass,
+ Map<String, ObjectModelClass> allEntitiesByFQN,
+ Map<ObjectModelClass, Set<ObjectModelClass>> usages) {
+
+ if (log.isDebugEnabled()) {
+ log.debug("for entity " + klass.getQualifiedName());
+ }
+ for (ObjectModelAttribute attr : klass.getAttributes()) {
+ if (!attr.isNavigable()) {
+ // skip this case
+ continue;
+ }
+ String type;
+ if (attr.hasAssociationClass()) {
+ type = attr.getAssociationClass().getQualifiedName();
+ } else {
+ type = attr.getType();
+ }
+ if (!allEntitiesByFQN.containsKey(type)) {
+ // not a entity, can skip for this attribute
+ continue;
+ }
+ if (log.isDebugEnabled()) {
+ log.debug(" uses " + type);
+ }
+ // register the klass as using the targetEntity
+ ObjectModelClass targetEntity = allEntitiesByFQN.get(type);
+ Set<ObjectModelClass> classes = usages.get(targetEntity);
+ classes.add(klass);
+ }
+ }
} // GeneratorUtil
1
0
r1815 - in trunk/topia-persistence/src: main/java/org/nuiton/topia/persistence main/java/org/nuiton/topia/persistence/util test/java/org/nuiton/topia/generator test/java/org/nuiton/topia/persistence/util
by tchemit@users.nuiton.org 26 Feb '10
by tchemit@users.nuiton.org 26 Feb '10
26 Feb '10
Author: tchemit
Date: 2010-02-26 19:48:25 +0100 (Fri, 26 Feb 2010)
New Revision: 1815
Added:
trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/util/TopiaEntityBinderTest.java
Modified:
trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/DepthEntityVisitor.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/EntityVisitor.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/HorizontalEntityVisitor.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/TopiaEntity.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaEntityAbstract.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaId.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/BeanPropertyLoador.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/Deletor.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/EntityLoador.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/Loador.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/TopiaEntityBinder.java
trunk/topia-persistence/src/test/java/org/nuiton/topia/generator/TopiaGeneratorUtilTest.java
trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/util/CollectorTest.java
trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/util/EntityOperatorTest.java
Log:
- remove IDE headers
- reformat code (80 caracters max on a line)
- simplify exception managment in TopiaDAOImpl
- improve loador api (based now on Binder)
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/DepthEntityVisitor.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/DepthEntityVisitor.java 2010-02-25 13:58:22 UTC (rev 1814)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/DepthEntityVisitor.java 2010-02-26 18:48:25 UTC (rev 1815)
@@ -69,7 +69,8 @@
}
@Override
- public void visit(TopiaEntity e, String propertyName, Class<?> type, Object value) {
+ public void visit(TopiaEntity e, String propertyName, Class<?> type,
+ Object value) {
// si c'est une entité
if (value instanceof TopiaEntity) {
TopiaEntity entity = (TopiaEntity) value;
@@ -90,8 +91,8 @@
}
@Override
- public void visit(TopiaEntity e, String propertyName, Class<?> collectionType, Class<?> type,
- Object value) {
+ public void visit(TopiaEntity e, String propertyName,
+ Class<?> collectionType, Class<?> type,Object value) {
Collection<?> cValue = (Collection<?>) value;
if (cValue != null && !cValue.isEmpty()) {
@@ -103,7 +104,9 @@
}
@Override
- public void visit(TopiaEntity e, String propertyName, Class<?> collectionType, Class<?> type, int index, Object value) {
+ public void visit(TopiaEntity e, String propertyName,
+ Class<?> collectionType, Class<?> type, int index,
+ Object value) {
// si c'est une entité
if (value instanceof TopiaEntity) {
TopiaEntity entity = (TopiaEntity) value;
@@ -118,7 +121,8 @@
}
} else {
if (delegateVisitor != null) {
- delegateVisitor.visit(e, propertyName, collectionType, type, index, value);
+ delegateVisitor.visit(e, propertyName, collectionType, type,
+ index, value);
}
}
}
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/EntityVisitor.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/EntityVisitor.java 2010-02-25 13:58:22 UTC (rev 1814)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/EntityVisitor.java 2010-02-26 18:48:25 UTC (rev 1815)
@@ -56,7 +56,8 @@
* @param type the type of the visited property
* @param value the value of the visited property
*/
- void visit(TopiaEntity entity, String propertyName, Class<?> type, Object value);
+ void visit(TopiaEntity entity, String propertyName, Class<?> type,
+ Object value);
/**
* Visit a collection property for the given entity.
@@ -69,7 +70,8 @@
* @param type the type of the visited property
* @param value the value of the visited property
*/
- void visit(TopiaEntity entity, String propertyName, Class<?> collectionType, Class<?> type, Object value);
+ void visit(TopiaEntity entity, String propertyName,
+ Class<?> collectionType, Class<?> type, Object value);
/**
* Visit a indexed value from a collection property for the given entity.
@@ -83,7 +85,8 @@
* @param index the index of the visited property in his container
* @param value the value of the visited property
*/
- void visit(TopiaEntity entity, String propertyName, Class<?> collectionType, Class<?> type, int index, Object value);
+ void visit(TopiaEntity entity, String propertyName,
+ Class<?> collectionType, Class<?> type, int index, Object value);
/**
* Reset all states of the visitor.
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/HorizontalEntityVisitor.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/HorizontalEntityVisitor.java 2010-02-25 13:58:22 UTC (rev 1814)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/HorizontalEntityVisitor.java 2010-02-26 18:48:25 UTC (rev 1815)
@@ -26,8 +26,6 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.nuiton.topia.TopiaException;
-import org.nuiton.topia.persistence.EntityVisitor;
-import org.nuiton.topia.persistence.TopiaEntity;
/**
* Parcourt en largeur du modele et délegation à un autre visiteur.
@@ -63,9 +61,6 @@
this.toVisitEntities = new ArrayList<TopiaEntity>();
}
- /*
- * @see org.nuiton.topia.persistence.EntityVisitor#start(org.nuiton.topia.persistence.TopiaEntity)
- */
@Override
public void start(TopiaEntity entity) {
delegateVisitor.start(entity);
@@ -74,11 +69,9 @@
}
}
- /*
- * @see org.nuiton.topia.persistence.EntityVisitor#visit(org.nuiton.topia.persistence.TopiaEntity, java.lang.String, java.lang.Class, java.lang.Object)
- */
@Override
- public void visit(TopiaEntity entity, String propertyName, Class<?> type, Object value) {
+ public void visit(TopiaEntity entity, String propertyName, Class<?> type,
+ Object value) {
// si c'est une entité
if (value instanceof TopiaEntity) {
TopiaEntity entityValue = (TopiaEntity) value;
@@ -88,45 +81,40 @@
}
}
- /*
- * @see org.nuiton.topia.persistence.EntityVisitor#visit(org.nuiton.topia.persistence.TopiaEntity, java.lang.String, java.lang.Class, java.lang.Class, java.lang.Object)
- */
@Override
- public void visit(TopiaEntity entity, String propertyName, Class<?> collectionType,
- Class<?> type, Object value) {
+ public void visit(TopiaEntity entity, String propertyName,
+ Class<?> collectionType,Class<?> type, Object value) {
Collection<?> values = (Collection<?>) value;
if (values != null && !values.isEmpty()) {
int i = 0;
for (Object currentValue : values) {
- visit(entity, propertyName, type, collectionType, i++, currentValue);
+ visit(entity, propertyName, type, collectionType, i++,
+ currentValue);
}
}
}
- /*
- * @see org.nuiton.topia.persistence.EntityVisitor#visit(org.nuiton.topia.persistence.TopiaEntity, java.lang.String, java.lang.Class, java.lang.Class, int, java.lang.Object)
- */
@Override
- public void visit(TopiaEntity entity, String propertyName, Class<?> collectionType,
- Class<?> type, int index, Object value) {
+ public void visit(TopiaEntity entity, String propertyName,
+ Class<?> collectionType, Class<?> type, int index,
+ Object value) {
// si c'est une entité
if (value instanceof TopiaEntity) {
TopiaEntity entityValue = (TopiaEntity) value;
toVisitEntities.add(entityValue);
} else {
- delegateVisitor.visit(entity, propertyName, collectionType, type, index, value);
+ delegateVisitor.visit(entity, propertyName, collectionType, type,
+ index, value);
}
}
- /*
- * @see org.nuiton.topia.persistence.EntityVisitor#end(org.nuiton.topia.persistence.TopiaEntity)
- */
@Override
public void end(TopiaEntity entity) {
delegateVisitor.end(entity);
// here, must revisit all remembered entities
- List<TopiaEntity> currentEntities = new ArrayList<TopiaEntity>(toVisitEntities);
+ List<TopiaEntity> currentEntities =
+ new ArrayList<TopiaEntity>(toVisitEntities);
// TODO verify if clearing here is enough
toVisitEntities.clear();
for (TopiaEntity currentEntity : currentEntities) {
@@ -143,9 +131,6 @@
}
}
- /*
- * @see org.nuiton.topia.persistence.EntityVisitor#clear()
- */
@Override
public void clear() {
alreadyExplored.clear();
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAO.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAO.java 2010-02-25 13:58:22 UTC (rev 1814)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAO.java 2010-02-26 18:48:25 UTC (rev 1815)
@@ -49,12 +49,12 @@
public interface TopiaDAO<Entity extends TopiaEntity> {
/**
- * When TopiaContextImpl create the TopiaDAOHibernate, it must call this method just
- * after.
+ * When TopiaContextImpl create the TopiaDAOHibernate, it must call this
+ * method just after.
*
* @param context context
* @param entityClass entity class
- * @throws TopiaException
+ * @throws TopiaException if any pb while init
*/
void init(TopiaContextImplementor context, Class<Entity> entityClass)
throws TopiaException;
@@ -77,14 +77,14 @@
* car plusieurs type de persistence peuvent etre melangé, et il
* serait bien que si l'une echoué les autres echoue aussi.
*
- * @throws TopiaException
+ * @throws TopiaException if any pb while commit
*/
void commitTransaction() throws TopiaException;
/**
* Appelé lorsque le context a eu un rollback de fait.
*
- * @throws TopiaException
+ * @throws TopiaException if any pb while rollback
*/
void rollbackTransaction() throws TopiaException;
@@ -115,7 +115,7 @@
* de DAO
* @param e l'entite a ajouter ou mettre a jour
* @return l'entity passé en paramètre.
- * @throws TopiaException
+ * @throws TopiaException if any pb while updating datas
*/
Entity update(Entity e) throws TopiaException;
@@ -140,7 +140,7 @@
* Compte le nombre d'entites en base
*
* @return le nombre total d'entites existantes
- * @throws TopiaException
+ * @throws TopiaException if any pb while getting datas
*/
long size() throws TopiaException;
@@ -148,12 +148,15 @@
* Crée une requete basé sur l'entité lié au DAO.
* Résultat attendu : "FROM Entity"
*
- * @return une nouvelle TopiaQuery vide. (uniquement avec le From sur le type d'entité)
+ * @return une nouvelle TopiaQuery vide. (uniquement avec le From sur le
+ * type d'entité)
*/
TopiaQuery createQuery();
/**
- * Crée une requête basé sur l'entité lié au DAO et lui assigne un alias valable dans la requête.
+ * Crée une requête basé sur l'entité lié au DAO et lui assigne un alias
+ * valable dans la requête..
+ *
* Résultat attendu : "FROM Entity AS entityAlias"
*
* @param entityAlias alias permettant de manipuler l'entité dans la requête
@@ -168,7 +171,7 @@
* @param query la requête
* @return l'entité correspondant à la recherche ou null si aucune entité
* n'a été trouvée
- * @throws TopiaException
+ * @throws TopiaException if any pb while getting datas
* @see org.nuiton.topia.framework.TopiaQuery#executeToEntity(org.nuiton.topia.TopiaContext, java.lang.Class)
*/
Entity findByQuery(TopiaQuery query) throws TopiaException;
@@ -179,7 +182,7 @@
*
* @param query la requête
* @return la liste d'entités correspondant à la recherche
- * @throws TopiaException
+ * @throws TopiaException if any pb while getting datas
* @see org.nuiton.topia.framework.TopiaQuery#executeToEntityList(org.nuiton.topia.TopiaContext, java.lang.Class)
*/
List<Entity> findAllByQuery(TopiaQuery query) throws TopiaException;
@@ -191,7 +194,7 @@
*
* @param query la requête
* @return la map d'entités correspondant à la recherche
- * @throws TopiaException
+ * @throws TopiaException if any pb while getting datas
* @see org.nuiton.topia.framework.TopiaQuery#executeToEntityMap(org.nuiton.topia.TopiaContext, java.lang.Class)
*/
Map<String, Entity> findAllMappedByQuery(TopiaQuery query) throws TopiaException;
@@ -206,7 +209,7 @@
* @param keyName nom de la propriété de l'entité utilisée comme clé
* @param keyClass type de la propriété de l'entité utilisée comme clé
* @return la map d'entités correspondant à la recherche
- * @throws TopiaException
+ * @throws TopiaException if any pb while getting datas
* @see org.nuiton.topia.framework.TopiaQuery#executeToEntityMap(org.nuiton.topia.TopiaContext, java.lang.Class)
*/
<K> Map<K, Entity> findAllMappedByQuery(TopiaQuery query,
@@ -229,11 +232,12 @@
*
* @param k l'objet cle naturelle de la classe
* @return l'entité trouvé
- * @throws TopiaException
+ * @throws TopiaException if any pb while getting datas
*/
Entity findByPrimaryKey(Object... k) throws TopiaException;
- Entity findByProperty(String propertyName, Object value) throws TopiaException;
+ Entity findByProperty(String propertyName, Object value)
+ throws TopiaException;
/**
*
@@ -242,9 +246,10 @@
* @param others les autres proprietes doivent aller par 2 propertyName,
* value
* @return l'entité trouvé
- * @throws TopiaException
+ * @throws TopiaException if any pb while getting datas
*/
- Entity findByProperties(String propertyName, Object value, Object... others) throws TopiaException;
+ Entity findByProperties(String propertyName, Object value,
+ Object... others) throws TopiaException;
Entity findByProperties(Map<String, Object> properties) throws TopiaException;
@@ -258,7 +263,7 @@
* @param others les autres proprietes doivent aller par 2 propertyName,
* value
* @return l'entité trouvé
- * @throws TopiaException
+ * @throws TopiaException if any pb while getting datas
*/
List<Entity> findAllByProperties(String propertyName, Object value,
Object... others) throws TopiaException;
@@ -275,7 +280,7 @@
*
* @param properties
* @return l'entité trouvé
- * @throws TopiaException
+ * @throws TopiaException if any pb while getting datas
*/
Entity findContainsProperties(Map<String, Collection> properties) throws
TopiaException;
@@ -288,7 +293,7 @@
* @param values
* @param others
* @return l'entité trouvé
- * @throws TopiaException
+ * @throws TopiaException if any pb while getting datas
*/
Entity findContainsProperties(String propertyName, Collection values,
Object... others) throws TopiaException;
@@ -299,7 +304,7 @@
*
* @param properties
* @return l'entité trouvé
- * @throws TopiaException
+ * @throws TopiaException if any pb while getting datas
*/
List<Entity> findAllContainsProperties(Map<String, Collection> properties)
throws TopiaException;
@@ -308,22 +313,52 @@
* Cherche et renvoie toutes les entités trouvées dont la propriété
* propertyName contient values, ainsi de suite avec others.
*
- * @param propertyName
+ * @param propertyName the name of the property
* @param values
* @param others
* @return l'entité trouvé
- * @throws TopiaException
+ * @throws TopiaException if any pb while getting datas
*/
List<Entity> findAllContainsProperties(String propertyName,
Collection values, Object... others) throws TopiaException;
/**
- * Retourne les permissions a verifier pour l'acces a l'entite pour le service Taas.
+ * Find usages of the given {@code entity} in the entities of the given
+ * {@code type}.
+ *
+ * @param type the type of entity to search
+ * @param entity the entity
+ * @param <U> tthe type of entity to search
+ * @return the list of entities of the given type which uses the given
+ * entity
+ * @throws TopiaException if any problem while getting data
+ * @since 2.3.0
+ */
+ <U extends TopiaEntity> List<U> findUsages(Class<U> type, Entity 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<?>, List<? extends TopiaEntity>> findAllUsages(Entity entity)
+ throws TopiaException;
+
+ /**
+ * Retourne les permissions a verifier pour l'acces a l'entite pour le
+ * service Taas.
+ *
* @param topiaId topiaId d'une entite
* @param actions
* @return la liste des permissions
- * @throws TopiaException
+ * @throws TopiaException if any pb while getting datas
*/
List<Permission> getRequestPermission(String topiaId, int actions)
throws TopiaException;
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAOImpl.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAOImpl.java 2010-02-25 13:58:22 UTC (rev 1814)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAOImpl.java 2010-02-26 18:48:25 UTC (rev 1815)
@@ -96,21 +96,25 @@
ClassMetadata meta = getClassMetadata();
String idPropName = meta.getIdentifierPropertyName();
- Serializable result;
try {
+ Serializable result;
result = (Serializable) PropertyUtils.getSimpleProperty(e,
idPropName);
- } catch (IllegalAccessException eee) {
+ return result;
+ } catch (Exception eee) {
throw new TopiaException("Impossible de récuperer l'identifiant "
+ idPropName + " de l'entite: " + e);
- } catch (InvocationTargetException eee) {
- throw new TopiaException("Impossible de récuperer l'identifiant "
- + idPropName + " de l'entite: " + e);
- } catch (NoSuchMethodException eee) {
- throw new TopiaException("Impossible de récuperer l'identifiant "
- + idPropName + " de l'entite: " + e);
}
- return result;
+// } catch (IllegalAccessException eee) {
+// throw new TopiaException("Impossible de récuperer l'identifiant "
+// + idPropName + " de l'entite: " + e);
+// } catch (InvocationTargetException eee) {
+// throw new TopiaException("Impossible de récuperer l'identifiant "
+// + idPropName + " de l'entite: " + e);
+// } catch (NoSuchMethodException eee) {
+// throw new TopiaException("Impossible de récuperer l'identifiant "
+// + idPropName + " de l'entite: " + e);
+// }
}
/**
@@ -132,8 +136,8 @@
}
/**
- * When TopiaContextImpl create the TopiaDAOHibernate, it must call this method just
- * after
+ * When TopiaContextImpl create the TopiaDAOHibernate, it must call this
+ * method just after.
*
* @param entityClass
*/
@@ -165,29 +169,37 @@
log.debug("Utilisation de la classe " + classname + "Impl"
+ " pour " + classname);
}
- } catch (InstantiationException eee) {
+ } catch (ClassNotFoundException eee) {
if (log.isWarnEnabled()) {
- log.warn("Impossible d'instancier " + classname + "Impl");
+ log.warn("Impossible de trouver la classe " + classname
+ + "Impl");
}
if (log.isDebugEnabled()) {
log.debug("StackTrace", eee);
}
- } catch (IllegalAccessException eee) {
+ } catch (Exception eee) {
if (log.isWarnEnabled()) {
log.warn("Impossible d'instancier " + classname + "Impl");
}
if (log.isDebugEnabled()) {
log.debug("StackTrace", eee);
}
- } catch (ClassNotFoundException eee) {
- if (log.isWarnEnabled()) {
- log.warn("Impossible de trouver la classe " + classname
- + "Impl");
- }
- if (log.isDebugEnabled()) {
- log.debug("StackTrace", eee);
- }
}
+// } catch (InstantiationException eee) {
+// if (log.isWarnEnabled()) {
+// log.warn("Impossible d'instancier " + classname + "Impl");
+// }
+// if (log.isDebugEnabled()) {
+// log.debug("StackTrace", eee);
+// }
+// } catch (IllegalAccessException eee) {
+// if (log.isWarnEnabled()) {
+// log.warn("Impossible d'instancier " + classname + "Impl");
+// }
+// if (log.isDebugEnabled()) {
+// log.debug("StackTrace", eee);
+// }
+// }
if (result == null) {
// le impl n'est pas trouvé on essai avec la classe elle meme
@@ -197,21 +209,29 @@
log.debug("Utilisation de la classe " + classname
+ " pour " + classname);
}
- } catch (InstantiationException eee) {
+ } catch (Exception eee) {
if (log.isWarnEnabled()) {
log.warn("Impossible d'instancier " + classname);
}
if (log.isDebugEnabled()) {
log.debug("StackTrace", eee);
}
- } catch (IllegalAccessException eee) {
- if (log.isWarnEnabled()) {
- log.warn("Impossible d'instancier " + classname);
- }
- if (log.isDebugEnabled()) {
- log.debug("StackTrace", eee);
- }
}
+// } catch (InstantiationException eee) {
+// if (log.isWarnEnabled()) {
+// log.warn("Impossible d'instancier " + classname);
+// }
+// if (log.isDebugEnabled()) {
+// log.debug("StackTrace", eee);
+// }
+// } catch (IllegalAccessException eee) {
+// if (log.isWarnEnabled()) {
+// log.warn("Impossible d'instancier " + classname);
+// }
+// if (log.isDebugEnabled()) {
+// log.debug("StackTrace", eee);
+// }
+// }
}
if (result == null) {
@@ -259,8 +279,8 @@
+ propertyName);
} catch (ClassCastException eee) {
throw new IllegalArgumentException(
- "Wrong argument type, wait property name as String and have "
- + propertyName.getClass().getName());
+ "Wrong argument type, wait property name as String and " +
+ "have " + propertyName.getClass().getName());
}
E result = create(map);
@@ -343,8 +363,9 @@
properties.put((String) name, value);
} catch (ClassCastException eee) {
throw new IllegalArgumentException(
- "Les noms des propriétés doivent être des chaines et non pas "
- + propertyName.getClass().getName(), eee);
+ "Les noms des propriétés doivent être des chaines et " +
+ "non pas " + propertyName.getClass().getName(),
+ eee);
} catch (ArrayIndexOutOfBoundsException eee) {
throw new IllegalArgumentException(
"Le nombre d'argument n'est pas un nombre pair: "
@@ -369,8 +390,9 @@
properties.put((String) name, value);
} catch (ClassCastException eee) {
throw new IllegalArgumentException(
- "Les noms des propriétés doivent être des chaines et non pas "
- + propertyName.getClass().getName(), eee);
+ "Les noms des propriétés doivent être des chaines et " +
+ "non pas " + propertyName.getClass().getName(),
+ eee);
} catch (ArrayIndexOutOfBoundsException eee) {
throw new IllegalArgumentException(
"Le nombre d'argument n'est pas un nombre pair: "
@@ -387,7 +409,7 @@
throws TopiaException {
List<E> results = findAllContainsProperties(properties);
E result = null;
- if (results.size() > 0) {
+ if (!results.isEmpty()) {
result = results.get(0);
}
return result;
@@ -406,8 +428,9 @@
properties.put((String) name, values);
} catch (ClassCastException eee) {
throw new IllegalArgumentException(
- "Les noms des propriétés doivent être des chaines et non pas "
- + propertyName.getClass().getName(), eee);
+ "Les noms des propriétés doivent être des chaines et " +
+ "non pas " + propertyName.getClass().getName(),
+ eee);
} catch (ArrayIndexOutOfBoundsException eee) {
throw new IllegalArgumentException(
"Le nombre d'argument n'est pas un nombre pair: "
@@ -421,8 +444,8 @@
/**
* Find all entities with a specific rule :
- * When the entity have a Collection type property, you want to find all entites where some values are
- * contained in the collection type property.
+ * When the entity have a Collection type property, you want to find all
+ * entites where some values are contained in the collection type property.
* Example entity parameter : private Collection<Date> historicalDates;
* You want some dates to be contained in historicalDates.
* Collection<Date> myDates...
@@ -435,7 +458,8 @@
* @throws org.nuiton.topia.TopiaException if any pb
*/
@Override
- public List<E> findAllContainsProperties(Map<String, Collection> properties) throws TopiaException {
+ public List<E> findAllContainsProperties(Map<String,
+ Collection> properties) throws TopiaException {
List<E> all = findAll();
List<E> result = new ArrayList<E>();
for (E e : all) {
@@ -450,28 +474,36 @@
break;
}
}
- } catch (IllegalAccessException eee) {
+ } catch (Exception eee) {
ok = false;
if (log.isWarnEnabled()) {
log.warn(
- "Impossible d'acceder a la methode demandé pour l'obbjet "
- + e, eee);
+ "Impossible d'acceder a la methode demandé pour " +
+ "l'obbjet " + e, eee);
}
- } catch (InvocationTargetException eee) {
- ok = false;
- if (log.isWarnEnabled()) {
- log.warn(
- "Impossible d'acceder a la methode demandé pour l'obbjet "
- + e, eee);
- }
- } catch (NoSuchMethodException eee) {
- ok = false;
- if (log.isWarnEnabled()) {
- log.warn(
- "Impossible d'acceder a la methode demandé pour l'obbjet "
- + e, eee);
- }
}
+// } catch (IllegalAccessException eee) {
+// ok = false;
+// if (log.isWarnEnabled()) {
+// log.warn(
+// "Impossible d'acceder a la methode demandé pour l'obbjet "
+// + e, eee);
+// }
+// } catch (InvocationTargetException eee) {
+// ok = false;
+// if (log.isWarnEnabled()) {
+// log.warn(
+// "Impossible d'acceder a la methode demandé pour l'obbjet "
+// + e, eee);
+// }
+// } catch (NoSuchMethodException eee) {
+// ok = false;
+// if (log.isWarnEnabled()) {
+// log.warn(
+// "Impossible d'acceder a la methode demandé pour l'obbjet "
+// + e, eee);
+// }
+// }
if (ok) {
result.add(e);
}
@@ -492,8 +524,9 @@
properties.put((String) name, values);
} catch (ClassCastException eee) {
throw new IllegalArgumentException(
- "Les noms des propriétés doivent être des chaines et non pas "
- + propertyName.getClass().getName(), eee);
+ "Les noms des propriétés doivent être des chaines et " +
+ "non pas " + propertyName.getClass().getName(),
+ eee);
} catch (ArrayIndexOutOfBoundsException eee) {
throw new IllegalArgumentException(
"Le nombre d'argument n'est pas un nombre pair: "
@@ -523,6 +556,22 @@
return result;
}
+ @Override
+ public <U extends TopiaEntity> List<U> findUsages(Class<U> type, E e)
+ throws TopiaException {
+ // must be implemented by specialized dao
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public Map<Class<?>, List<? extends TopiaEntity>> findAllUsages(E e)
+ throws TopiaException {
+ // must be implemented by specialized dao
+ throw new UnsupportedOperationException();
+ }
+
+ //TODO-TC20100225 Says since when it is deprecated (via javadoc annotations
+ //TODO-TC20100225 + tells what to use instead)
@Deprecated
private Criterion computeCriterions(Object... values) {
if (values == null) {
@@ -535,11 +584,13 @@
return criterion;
}
+ //TODO-TC20100225 Says since when it is deprecated (via javadoc annotations
+ //TODO-TC20100225 + tells what to use instead)
@Deprecated
private Criterion computeCriterion(Object value) {
Criterion criterion = null;
SearchFields fields = entityClass.getAnnotation(SearchFields.class);
- String textValue = "%" + value + "%";
+ String textValue = "%" + value + '%';
//textFields
String[] textFields = fields.txtFields();
for (String propName : textFields) {
@@ -560,7 +611,7 @@
String[] numFields = fields.numFields();
for (String propName : numFields) {
criterion = or(criterion, Restrictions.sqlRestriction(propName
- + " like '" + textValue + "'"));
+ + " like '" + textValue + '\''));
}
}
//boolFields
@@ -586,11 +637,13 @@
String[] timeFields = fields.dateFields();
for (String propName : timeFields) {
criterion = or(criterion, Restrictions.sqlRestriction(propName
- + " like '" + textValue + "'"));
+ + " like '" + textValue + '\''));
}
return criterion;
}
+ //TODO-TC20100225 Says since when it is deprecated (via javadoc annotations
+ //TODO-TC20100225 + tells what to use instead)
@Deprecated
private Criterion or(Criterion crit1, Criterion crit2) {
if (crit1 == null) {
@@ -735,14 +788,17 @@
}
@Override
- public Map<String, E> findAllMappedByQuery(TopiaQuery query) throws TopiaException {
+ public Map<String, E> findAllMappedByQuery(TopiaQuery query)
+ throws TopiaException {
return query.executeToEntityMap(context, getEntityClass());
}
@Override
- public <K> Map<K, E> findAllMappedByQuery(TopiaQuery query, String keyName, Class<K> keyClass)
+ public <K> Map<K, E> findAllMappedByQuery(TopiaQuery query, String keyName,
+ Class<K> keyClass)
throws TopiaException {
- return query.executeToEntityMap(context, getEntityClass(), keyName, keyClass);
+ return query.executeToEntityMap(context, getEntityClass(), keyName,
+ keyClass);
}
@Override
@@ -769,7 +825,8 @@
}
/**
- * Count number of existing entities using {@link org.nuiton.topia.framework.TopiaQuery#executeCount(org.nuiton.topia.TopiaContext) }
+ * Count number of existing entities using
+ * {@link TopiaQuery#executeCount(org.nuiton.topia.TopiaContext) }
* FIXME-FD20091224 change type to int like in 2.2.2 version
*
* @return a long for the number of entities in database
@@ -882,6 +939,7 @@
// }
/**
+ * TODO-TC20100225 Should this method deprecated (it is never used ?)
* Renvoie un Criteria créé avec l'entityClass
* @param mode le FlushMode du Criteria
* @return le Criteria nouvellement créé
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaEntity.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaEntity.java 2010-02-25 13:58:22 UTC (rev 1814)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaEntity.java 2010-02-26 18:48:25 UTC (rev 1815)
@@ -54,49 +54,49 @@
String TOPIA_CREATE_DATE = "topiaCreateDate";
String TOPIA_VERSION = "topiaVersion";
- public String getTopiaId();
+ String getTopiaId();
- public void setTopiaId(String v);
+ void setTopiaId(String v);
- public long getTopiaVersion();
+ long getTopiaVersion();
- public void setTopiaVersion(long v);
+ void setTopiaVersion(long v);
/**
* @return Returns the topiaCreateTime.
*/
- public Date getTopiaCreateDate();
+ Date getTopiaCreateDate();
/**
* @param topiaCreatedate the topiaCreateTime to set.
*/
- public void setTopiaCreateDate(Date topiaCreatedate);
+ void setTopiaCreateDate(Date topiaCreatedate);
- public TopiaContext getTopiaContext();
+ TopiaContext getTopiaContext();
/**
* called just after object creation and initialisation
* each entity impl can overide it to do something after creation
* @throws TopiaException
*/
- public void postCreate() throws TopiaException;
+ void postCreate() throws TopiaException;
- public void update() throws TopiaException;
+ void update() throws TopiaException;
- public void delete() throws TopiaException;
+ void delete() throws TopiaException;
/**
* @return all object that must be deleted if this object is deleted
* @throws TopiaException
*/
- public List<TopiaEntity> getComposite() throws TopiaException;
+ List<TopiaEntity> getComposite() throws TopiaException;
/**
* @return all object that are aggregate with this instance, aggreate object
* are not removed automaticaly
* @throws TopiaException
*/
- public List<TopiaEntity> getAggregate() throws TopiaException;
+ List<TopiaEntity> getAggregate() throws TopiaException;
/**
* Add listener for property writing.
@@ -104,7 +104,7 @@
* @param propertyName
* @param listener
*/
- public void addPropertyChangeListener(String propertyName,
+ void addPropertyChangeListener(String propertyName,
PropertyChangeListener listener);
/**
@@ -112,22 +112,22 @@
*
* @param listener
*/
- public void addPropertyChangeListener(PropertyChangeListener listener);
+ void addPropertyChangeListener(PropertyChangeListener listener);
- public void addVetoableChangeListener(String propertyName,
+ void addVetoableChangeListener(String propertyName,
VetoableChangeListener vetoable);
- public void addVetoableChangeListener(VetoableChangeListener vetoable);
+ void addVetoableChangeListener(VetoableChangeListener vetoable);
- public void removePropertyChangeListener(String propertyName,
+ void removePropertyChangeListener(String propertyName,
PropertyChangeListener listener);
- public void removePropertyChangeListener(PropertyChangeListener listener);
+ void removePropertyChangeListener(PropertyChangeListener listener);
- public void removeVetoableChangeListener(String propertyName,
+ void removeVetoableChangeListener(String propertyName,
VetoableChangeListener vetoable);
- public void removeVetoableChangeListener(VetoableChangeListener vetoable);
+ void removeVetoableChangeListener(VetoableChangeListener vetoable);
/**
* Add listener for property reading.
@@ -135,30 +135,30 @@
* @param propertyName
* @param listener
*/
- public void addPropertyListener(String propertyName,
- PropertyChangeListener listener);
+ void addPropertyListener(String propertyName,
+ PropertyChangeListener listener);
/**
* Add listener for property reading.
*
* @param listener
*/
- public void addPropertyListener(PropertyChangeListener listener);
+ void addPropertyListener(PropertyChangeListener listener);
- public void addVetoableListener(String propertyName,
+ void addVetoableListener(String propertyName,
VetoableChangeListener vetoable);
- public void addVetoableListener(VetoableChangeListener vetoable);
+ void addVetoableListener(VetoableChangeListener vetoable);
- public void removePropertyListener(String propertyName,
+ void removePropertyListener(String propertyName,
PropertyChangeListener listener);
- public void removePropertyListener(PropertyChangeListener listener);
+ void removePropertyListener(PropertyChangeListener listener);
- public void removeVetoableListener(String propertyName,
+ void removeVetoableListener(String propertyName,
VetoableChangeListener vetoable);
- public void removeVetoableListener(VetoableChangeListener vetoable);
+ void removeVetoableListener(VetoableChangeListener vetoable);
/**
* Parcourt de l'entité via un visiteur.
@@ -166,6 +166,6 @@
* @param visitor visitor le visiteur utilise
* @throws TopiaException pour toute erreur pendant le parcours
*/
- public void accept(EntityVisitor visitor) throws TopiaException;
+ void accept(EntityVisitor visitor) throws TopiaException;
} //TopiaEntity
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaEntityAbstract.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaEntityAbstract.java 2010-02-25 13:58:22 UTC (rev 1814)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaEntityAbstract.java 2010-02-26 18:48:25 UTC (rev 1815)
@@ -66,80 +66,45 @@
transient protected TopiaContext topiaContext = null;
- transient protected VetoableChangeSupport readVetoables = new VetoableChangeSupport(
- this);
- transient protected PropertyChangeSupport readListeners = new PropertyChangeSupport(
- this);
- transient protected VetoableChangeSupport writeVetoables = new VetoableChangeSupport(
- this);
- transient protected PropertyChangeSupport writeListeners = new PropertyChangeSupport(
- this);
+ transient protected VetoableChangeSupport readVetoables =
+ new VetoableChangeSupport(this);
+ transient protected PropertyChangeSupport readListeners =
+ new PropertyChangeSupport(this);
+ transient protected VetoableChangeSupport writeVetoables =
+ new VetoableChangeSupport(this);
+ transient protected PropertyChangeSupport writeListeners =
+ new PropertyChangeSupport(this);
- /*
- * (non-Javadoc)
- *
- * @see org.nuiton.topia.persistence.TopiaEntity#getTopiaId()
- */
@Override
public String getTopiaId() {
return topiaId;
}
- /*
- * (non-Javadoc)
- *
- * @see org.nuiton.topia.persistence.TopiaEntity#setTopiaId(String)
- */
@Override
public void setTopiaId(String v) {
this.topiaId = v;
}
- /*
- * (non-Javadoc)
- *
- * @see org.nuiton.topia.persistence.TopiaEntity#getTopiaVersion()
- */
@Override
public long getTopiaVersion() {
return topiaVersion;
}
- /*
- * (non-Javadoc)
- *
- * @see org.nuiton.topia.persistence.TopiaEntity#setTopiaVersion(long)
- */
@Override
public void setTopiaVersion(long v) {
this.topiaVersion = v;
}
- /*
- * (non-Javadoc)
- *
- * @see org.nuiton.topia.persistence.TopiaEntity#getTopiaCreateTime()
- */
@Override
public Date getTopiaCreateDate() {
return topiaCreateDate;
}
- /*
- * (non-Javadoc)
- *
- * @see org.nuiton.topia.persistence.TopiaEntity#setTopiaCreateTime(java.util.Date)
- */
@Override
public void setTopiaCreateDate(Date topiaCreateDate) {
this.topiaCreateDate = topiaCreateDate;
}
- /*
- * (non-Javadoc)
- *
- * @see org.nuiton.topia.persistence.TopiaEntity#getTopiaContext()
- */
@Override
public TopiaContext getTopiaContext() {
return topiaContext;
@@ -162,37 +127,21 @@
// do nothing by default
}
- /*
- * (non-Javadoc)
- *
- * @see org.nuiton.topia.persistence.TopiaEntity#update()
- */
@Override
public void update() throws TopiaException {
throw new UnsupportedOperationException();
}
- /*
- * (non-Javadoc)
- *
- * @see org.nuiton.topia.persistence.TopiaEntity#delete()
- */
@Override
public void delete() throws TopiaException {
throw new UnsupportedOperationException();
}
- /* (non-Javadoc)
- * @see org.nuiton.topia.persistence.TopiaEntity#getComposite()
- */
@Override
public List<TopiaEntity> getComposite() throws TopiaException {
throw new UnsupportedOperationException();
}
- /* (non-Javadoc)
- * @see org.nuiton.topia.persistence.TopiaEntity#getAggregate()
- */
@Override
public List<TopiaEntity> getAggregate() throws TopiaException {
throw new UnsupportedOperationException();
@@ -237,7 +186,8 @@
}
protected void fireOnPreRead(String propertyName, Object value) {
- TopiaContextImplementor contextImplementor = (TopiaContextImplementor) getTopiaContext();
+ TopiaContextImplementor contextImplementor =
+ (TopiaContextImplementor) getTopiaContext();
if (contextImplementor != null) {
contextImplementor.getFiresSupport().fireOnPreRead(readVetoables,
this, propertyName, value);
@@ -245,15 +195,18 @@
}
protected void fireOnPostRead(String propertyName, Object value) {
- TopiaContextImplementor contextImplementor = (TopiaContextImplementor) getTopiaContext();
+ TopiaContextImplementor contextImplementor =
+ (TopiaContextImplementor) getTopiaContext();
if (contextImplementor != null) {
contextImplementor.getFiresSupport().fireOnPostRead(readListeners,
this, propertyName, value);
}
}
- protected void fireOnPostRead(String propertyName, int index, Object value) {
- TopiaContextImplementor contextImplementor = (TopiaContextImplementor) getTopiaContext();
+ protected void fireOnPostRead(String propertyName, int index,
+ Object value) {
+ TopiaContextImplementor contextImplementor =
+ (TopiaContextImplementor) getTopiaContext();
if (contextImplementor != null) {
contextImplementor.getFiresSupport().fireOnPostRead(readListeners,
this, propertyName, index, value);
@@ -262,7 +215,8 @@
protected void fireOnPreWrite(String propertyName, Object oldValue,
Object newValue) {
- TopiaContextImplementor contextImplementor = (TopiaContextImplementor) getTopiaContext();
+ TopiaContextImplementor contextImplementor =
+ (TopiaContextImplementor) getTopiaContext();
if (contextImplementor != null) {
contextImplementor.getFiresSupport().fireOnPreWrite(writeVetoables,
this, propertyName, oldValue, newValue);
@@ -271,7 +225,8 @@
protected void fireOnPostWrite(String propertyName, Object oldValue,
Object newValue) {
- TopiaContextImplementor contextImplementor = (TopiaContextImplementor) getTopiaContext();
+ TopiaContextImplementor contextImplementor =
+ (TopiaContextImplementor) getTopiaContext();
if (contextImplementor != null) {
contextImplementor.getFiresSupport().fireOnPostWrite(
writeListeners, this, propertyName, oldValue, newValue);
@@ -280,7 +235,8 @@
protected void fireOnPostWrite(String propertyName, int index,
Object oldValue, Object newValue) {
- TopiaContextImplementor contextImplementor = (TopiaContextImplementor) getTopiaContext();
+ TopiaContextImplementor contextImplementor =
+ (TopiaContextImplementor) getTopiaContext();
if (contextImplementor != null) {
contextImplementor.getFiresSupport().fireOnPostWrite(
writeListeners, this, propertyName, index, oldValue,
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaId.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaId.java 2010-02-25 13:58:22 UTC (rev 1814)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaId.java 2010-02-26 18:48:25 UTC (rev 1815)
@@ -58,6 +58,7 @@
public int hashCode() {
if (topiaId == null) {
+ //TODO-TC20100225 : use commons-loggin api instead of jdk one
Logger.getLogger(getClass().getName() + ".hashCode").log(
Level.WARNING, "Use null topiaId", new Throwable());
return 0;
@@ -88,7 +89,7 @@
while (Double.toString(random).contains("E-")) {
random = Math.random();
}
- return clazz.getName() + "#" + System.currentTimeMillis() + "#"
+ return clazz.getName() + '#' + System.currentTimeMillis() + '#'
+ random;
}
@@ -120,7 +121,7 @@
*/
public static String getClassNameAsString(String topiaId) {
String result = "";
- int i = topiaId.indexOf("#");
+ int i = topiaId.indexOf('#');
if (i > 0) {
result = topiaId.substring(0, i);
}
@@ -143,6 +144,7 @@
}
return false;
} catch (Exception eee) {
+ //TODO-TC20100225 : use commons-loggin api instead of jdk one
Logger.getLogger(TopiaId.class.getName() + ".isValidId").log(
Level.WARNING, "Error during verfication of topiaId", eee);
return false;
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/BeanPropertyLoador.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/BeanPropertyLoador.java 2010-02-25 13:58:22 UTC (rev 1814)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/BeanPropertyLoador.java 2010-02-26 18:48:25 UTC (rev 1815)
@@ -21,6 +21,8 @@
package org.nuiton.topia.persistence.util;
+import org.nuiton.util.ObjectUtil;
+
import java.beans.IntrospectionException;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
@@ -37,8 +39,8 @@
* Some factory methods are defined to simplify the generic cast, prefer used them
* instead of the (protected) constructor.
*
+ * @author tchemit < chemit(a)codelutin.com >
* @param <E> type of bean to bind
- * @author tchemit < chemit(a)codelutin.com >
* @deprecated since 2.3.0, prefer use the {@link TopiaEntityBinder}
*/
@Deprecated
@@ -47,12 +49,13 @@
public static <E> BeanPropertyLoador<E> newLoador(Class<E> klass, String... properties) {
return new BeanPropertyLoador<E>(klass, properties);
}
+
private static final long serialVersionUID = 1L;
- protected static final Integer ZERO = 0;
- protected static final Float ZEROF = 0f;
- protected static final Long ZEROL = 0l;
- protected static final Double ZEROD = 0.;
- protected static final Byte ZEROB = 0;
+// protected static final Integer ZERO = 0;
+// protected static final Float ZEROF = 0f;
+// protected static final Long ZEROL = 0l;
+// protected static final Double ZEROD = 0.;
+// protected static final Byte ZEROB = 0;
protected List<String> properties;
protected transient PropertyDescriptor[] descriptors;
protected Class<E> klass;
@@ -84,10 +87,15 @@
}
@Override
- public Map<String, Object> obtainProperties(E from) {
+ public Map<String, Object> obtainProperties(E from, String... propertyNames) {
if (from == null) {
return java.util.Collections.emptyMap();
}
+ if (propertyNames.length > 0) {
+ throw new IllegalArgumentException("The BeanPropertyLoader does " +
+ "not accept subset of properties, prefer use the " +
+ "org.nuiton.util.beans.Binder api instead now.");
+ }
Map<String, Object> result = new HashMap<String, Object>();
for (PropertyDescriptor descriptor : getDescriptors()) {
Object read;
@@ -107,17 +115,12 @@
}
@Override
- @Deprecated
- public Map<String, Object> obtainProgperties(E from) {
- return obtainProperties(from);
- }
-
- @Override
- public void load(E from, E dst, boolean tech) {
+ public void load(E from, E dst, boolean tech, String... propertyNames) {
if (from == null) {
// reset all fields
for (PropertyDescriptor descriptor : getDescriptors()) {
- Object read = TopiaEntityHelper.getNullValue(descriptor.getPropertyType());
+ Object read =
+ ObjectUtil.getNullValue(descriptor.getPropertyType());
setProperty(dst, descriptor, read);
}
} else {
@@ -150,7 +153,7 @@
*/
@Deprecated
protected static Object getNullValue(Class<?> type) {
- return TopiaEntityHelper.getNullValue(type);
+ return ObjectUtil.getNullValue(type);
}
/**
@@ -160,7 +163,7 @@
*/
@Deprecated
public static boolean isNullValue(Object value) {
- return TopiaEntityHelper.isNullValue(value);
+ return ObjectUtil.isNullValue(value);
}
protected void checkProperties() {
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/Deletor.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/Deletor.java 2010-02-25 13:58:22 UTC (rev 1814)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/Deletor.java 2010-02-26 18:48:25 UTC (rev 1815)
@@ -24,7 +24,8 @@
* A simple contract to hook the deletion of an entity.
*
* @author chemit
- * @param <P> the parent of the entity to delete (if the entity has no parent says is not in a association
+ * @param <P> the parent of the entity to delete (if the entity has no parent
+ * says is not in a association)
* of another entity, just used the {@link Void} type).
* @param <E> the type of the entity to delete.
*/
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/EntityLoador.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/EntityLoador.java 2010-02-25 13:58:22 UTC (rev 1814)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/EntityLoador.java 2010-02-26 18:48:25 UTC (rev 1815)
@@ -49,14 +49,14 @@
}
@Override
- public void load(E from, E dst, boolean tech) {
+ public void load(E from, E dst, boolean tech,String... propertyNames) {
if (from == null) {
from = empty;
}
if (tech) {
TopiaEntityHelper.bindTechnical(from, dst);
}
- super.load(from, dst, tech);
+ super.load(from, dst, tech,propertyNames);
}
protected EntityLoador(Class<E> klass, E empty, String... properties) {
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/Loador.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/Loador.java 2010-02-25 13:58:22 UTC (rev 1814)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/Loador.java 2010-02-26 18:48:25 UTC (rev 1815)
@@ -25,37 +25,37 @@
/**
* A simple contract to load an object from another one.
*
+ * @author chemit
* @param <E> type of bean to load
- * @author chemit
- * @deprecated since 2.3.0, prefer use the {@link org.nuiton.util.beans.Binder}
- * api (and {@link TopiaEntityBinder} extension.
*/
-@Deprecated
public interface Loador<E> extends java.io.Serializable {
/**
- * Obtain from an entity all data to bind to another one according the definition of the loador.
+ * Obtain from an entity all data to bind to another one according the
+ * definition of the loador.
* <p/>
- * This method is usefull when you can not directly used the {@link #load(Object, Object, boolean)} method.
+ * This method is usefull when you can not directly used the
+ * {@link #load(Object, Object, boolean, String...)} method.
* <p/>
- * For example, when an entity has a immutable business key (says with an hibernate naturalId for example),
- * and that you want to create the data in a db, you must give all the properties at the create time so
- * this method allow you to do it).
+ * For example, when an entity has a immutable business key (says with an
+ * hibernate naturalId for example),
+ * and that you want to create the data in a db, you must give all the
+ * properties at the create time so this method allow you to do it).
*
- * @param from the entity to bind
+ * @param from the entity to bind
+ * @param propertyNames subset of properties to load
* @return the map of properties to bind from the given entity.
*/
- Map<String, Object> obtainProperties(E from);
+ Map<String, Object> obtainProperties(E from, String... propertyNames);
- @Deprecated
- Map<String, Object> obtainProgperties(E from);
-
/**
* Bind an entity to another.
*
* @param from the source entity
* @param dst the destination entity
- * @param tech a flag to bind or not the technical values of the entity (says TopiaId, TopiaVersion and TopiaCreateDate).
+ * @param tech a flag to bind or not the technical values of the entity
+ * (says TopiaId, TopiaVersion and TopiaCreateDate).
+ * @param propertyNames subset of properties to load
*/
- void load(E from, E dst, boolean tech);
+ void load(E from, E dst, boolean tech, String... propertyNames);
}
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/TopiaEntityBinder.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/TopiaEntityBinder.java 2010-02-25 13:58:22 UTC (rev 1814)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/TopiaEntityBinder.java 2010-02-26 18:48:25 UTC (rev 1815)
@@ -32,15 +32,15 @@
* <p/>
* There is an internal sate {@link #empty} to deal with default values of
* properties of an entity.
+ * <p/>
+ * <b>Note:</b> Should remove {@link Loador} contract soon.
*
- * <b>Note:</b> Should remove {@link Loador} contract soon (let it form the
- * the moment for application using
* @author tchemit < chemit(a)codelutin.com >
* @param <E> the type of entity
* @since 2.3.0
*/
public class TopiaEntityBinder<E extends TopiaEntity> extends Binder<E, E>
- implements Loador<E>{
+ implements Loador<E> {
private static final long serialVersionUID = 1L;
protected E empty;
@@ -49,24 +49,15 @@
this.empty = empty;
}
- public void copy(E source, E target, boolean tech) {
+ @Override
+ public void load(E source, E target, boolean tech,
+ String... propertyNames) {
if (source == null) {
source = empty;
}
if (tech) {
TopiaEntityHelper.bindTechnical(source, target);
}
- copy(source, target);
+ copy(source, target, propertyNames);
}
-
- @Override
- public Map<String, Object> obtainProgperties(E from) {
- throw new NotImplementedException("the method 'obtainProgperties' is" +
- " no more implemented");
- }
-
- @Override
- public void load(E from, E dst, boolean tech) {
- copy(from,dst,tech);
- }
}
\ No newline at end of file
Modified: trunk/topia-persistence/src/test/java/org/nuiton/topia/generator/TopiaGeneratorUtilTest.java
===================================================================
--- trunk/topia-persistence/src/test/java/org/nuiton/topia/generator/TopiaGeneratorUtilTest.java 2010-02-25 13:58:22 UTC (rev 1814)
+++ trunk/topia-persistence/src/test/java/org/nuiton/topia/generator/TopiaGeneratorUtilTest.java 2010-02-26 18:48:25 UTC (rev 1815)
@@ -18,10 +18,6 @@
* <http://www.gnu.org/licenses/lgpl-3.0.html>.
* ##%*
*/
-/*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
package org.nuiton.topia.generator;
import org.junit.Test;
Modified: trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/util/CollectorTest.java
===================================================================
--- trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/util/CollectorTest.java 2010-02-25 13:58:22 UTC (rev 1814)
+++ trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/util/CollectorTest.java 2010-02-26 18:48:25 UTC (rev 1815)
@@ -18,10 +18,6 @@
* <http://www.gnu.org/licenses/lgpl-3.0.html>.
* ##%*
*/
-/*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
package org.nuiton.topia.persistence.util;
import org.junit.AfterClass;
Modified: trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/util/EntityOperatorTest.java
===================================================================
--- trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/util/EntityOperatorTest.java 2010-02-25 13:58:22 UTC (rev 1814)
+++ trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/util/EntityOperatorTest.java 2010-02-26 18:48:25 UTC (rev 1815)
@@ -1,4 +1,4 @@
-/**
+/*
* *##%
* ToPIA :: Persistence
* Copyright (C) 2004 - 2009 CodeLutin
Added: trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/util/TopiaEntityBinderTest.java
===================================================================
--- trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/util/TopiaEntityBinderTest.java (rev 0)
+++ trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/util/TopiaEntityBinderTest.java 2010-02-26 18:48:25 UTC (rev 1815)
@@ -0,0 +1,92 @@
+/*
+ * *##%
+ * ToPIA :: Persistence
+ * Copyright (C) 2004 - 2009 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>.
+ * ##%*
+ */
+package org.nuiton.topia.persistence.util;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.nuiton.topia.TopiaTestDAOHelper;
+import org.nuiton.topia.persistence.TopiaEntity;
+import org.nuiton.topia.persistence.TopiaEntityEnum;
+import org.nuiton.topiatest.Company;
+import org.nuiton.util.beans.Binder;
+import org.nuiton.util.beans.BinderBuilder;
+import org.nuiton.util.beans.BinderProvider;
+
+public class TopiaEntityBinderTest {
+
+ static TopiaEntityEnum[] contracts;
+
+ @BeforeClass
+ public static void setUpClass() throws Exception {
+ contracts = TopiaTestDAOHelper.getContracts();
+ }
+
+ public static class CompanyDTO {
+ protected String name;
+ protected int siret;
+ protected String id;
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public int getSiret() {
+ return siret;
+ }
+
+ public void setSiret(int siret) {
+ this.siret = siret;
+ }
+
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+ }
+
+ @Before
+ public void setUp() {
+ BinderProvider.clear();
+ }
+
+ @Test
+ public void testBinder() {
+
+ BinderBuilder builder = new BinderBuilder();
+ builder.createBinderModel(Company.class, CompanyDTO.class);
+ builder.addSimpleProperties(Company.NAME, Company.SIRET);
+ builder.addProperties(TopiaEntity.TOPIA_ID, "id");
+ BinderProvider.registerBinder(builder);
+
+ Binder<Company, CompanyDTO> binder =
+ BinderProvider.getBinder(Company.class, CompanyDTO.class);
+ Assert.assertNotNull(binder);
+ }
+}
\ No newline at end of file
Property changes on: trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/util/TopiaEntityBinderTest.java
___________________________________________________________________
Added: svn:keywords
+ "Author Date Id Revision HeadURL
1
0
r1814 - trunk/topia-persistence/src/main/java/org/nuiton/topia/framework
by fdesbois@users.nuiton.org 25 Feb '10
by fdesbois@users.nuiton.org 25 Feb '10
25 Feb '10
Author: fdesbois
Date: 2010-02-25 14:58:22 +0100 (Thu, 25 Feb 2010)
New Revision: 1814
Modified:
trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaQuery.java
Log:
[TopiaQuery] add method : addNullOr to manage an element that is null or depends on some value
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaQuery.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaQuery.java 2010-02-23 18:11:49 UTC (rev 1813)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaQuery.java 2010-02-25 13:58:22 UTC (rev 1814)
@@ -641,7 +641,8 @@
* @param paramName the name of the parameter in the query (attribute of
* the entity)
* @param constraint the operation concerned
- * @param paramValue the value of the parameter (an other entity, a String, ...)
+ * @param paramValue the value of the parameter (an other entity, a String,
+ * ...)
* @return the TopiaQuery
*/
public TopiaQuery add(String paramName, Op constraint, Object paramValue) {
@@ -657,6 +658,28 @@
return add(result.toString());
}
+ /**
+ * Add an element to the query. The nullity is tested or a constraint is
+ * added for that element. Ex : addNullOr("begin", Op.GT, new Date()) means
+ * begin IS NULL OR begin > :begin (where :begin = new Date()).
+ *
+ * @param paramName the name of the parameter in the query (attribute of
+ * the entity)
+ * @param constraint the operation concerned by the or
+ * @param paramValue the value of the parameter (an other entity, a String,
+ * ...)
+ * @return the TopiaQuery
+ */
+ public TopiaQuery addNullOr(String paramName, Op constraint, Object paramValue) {
+ String valueName = getValueName(paramName);
+ StringBuilder result =
+ new StringBuilder(paramName).append(' ').append(Op.NULL).
+ append(" OR ").append(paramName).append(constraint).
+ append(" :").append(valueName);
+ addParam(valueName, paramValue);
+ return add(result.toString());
+ }
+
protected String getValueName(String paramName) {
int dot = paramName.lastIndexOf('.');
String valueName = paramName;
1
0
r1813 - trunk/topia-persistence/src/main/java/org/nuiton/topia/generator
by fdesbois@users.nuiton.org 23 Feb '10
by fdesbois@users.nuiton.org 23 Feb '10
23 Feb '10
Author: fdesbois
Date: 2010-02-23 19:11:49 +0100 (Tue, 23 Feb 2010)
New Revision: 1813
Modified:
trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/DAOAbstractTransformer.java
Log:
Add create method with naturalId
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/DAOAbstractTransformer.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/DAOAbstractTransformer.java 2010-02-22 14:19:38 UTC (rev 1812)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/DAOAbstractTransformer.java 2010-02-23 18:11:49 UTC (rev 1813)
@@ -610,6 +610,10 @@
"existNaturalId", "boolean", ObjectModelModifier.PUBLIC);
addException(existNaturalId, TopiaException.class);
+ ObjectModelOperation create = addOperation(result,
+ "create", "E", ObjectModelModifier.PUBLIC);
+ addException(create, TopiaException.class);
+
// used for calling findByProperties in findByNaturalId
String searchProperties = "";
// used for calling findByNaturalId in existNaturalId
@@ -620,6 +624,7 @@
// add property as param in both methods
addParameter(findByNaturalId, attr.getType(), propName);
addParameter(existNaturalId, attr.getType(), propName);
+ addParameter(create, attr.getType(), propName);
searchProperties +=
", " + clazzName + "." + getConstantName(propName) +
@@ -640,6 +645,12 @@
return findByNaturalId(<%=params%>) != null;
}*/
);
+
+ setOperationBody(create, ""
+/*{
+ return create(<%=searchProperties%>);
+ }*/
+ );
}
1
0
r1812 - trunk/topia-persistence/src/main/java/org/nuiton/topia
by echatellier@users.nuiton.org 22 Feb '10
by echatellier@users.nuiton.org 22 Feb '10
22 Feb '10
Author: echatellier
Date: 2010-02-22 15:19:38 +0100 (Mon, 22 Feb 2010)
New Revision: 1812
Modified:
trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaContext.java
Log:
Add missing javadoc
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaContext.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaContext.java 2010-02-22 09:54:12 UTC (rev 1811)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaContext.java 2010-02-22 14:19:38 UTC (rev 1812)
@@ -140,6 +140,12 @@
*/
void updateSchema() throws TopiaException;
+ /**
+ * Return a new context containing his own transaction.
+ *
+ * @return new context with transaction
+ * @throws TopiaException
+ */
TopiaContext beginTransaction() throws TopiaException;
/**
1
0
r1811 - trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util
by tchemit@users.nuiton.org 22 Feb '10
by tchemit@users.nuiton.org 22 Feb '10
22 Feb '10
Author: tchemit
Date: 2010-02-22 10:54:12 +0100 (Mon, 22 Feb 2010)
New Revision: 1811
Modified:
trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/TopiaEntityBinder.java
Log:
let TopiaEntityBinder still implements Loador contract to make easier migration (and breaks no client code)
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/TopiaEntityBinder.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/TopiaEntityBinder.java 2010-02-21 20:39:35 UTC (rev 1810)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/TopiaEntityBinder.java 2010-02-22 09:54:12 UTC (rev 1811)
@@ -20,9 +20,12 @@
*/
package org.nuiton.topia.persistence.util;
+import org.apache.commons.lang.NotImplementedException;
import org.nuiton.topia.persistence.TopiaEntity;
import org.nuiton.util.beans.Binder;
+import java.util.Map;
+
/**
* A {@link Binder} dedicated to {@link TopiaEntity} dealing with technical
* values.
@@ -30,11 +33,14 @@
* There is an internal sate {@link #empty} to deal with default values of
* properties of an entity.
*
+ * <b>Note:</b> Should remove {@link Loador} contract soon (let it form the
+ * the moment for application using
* @author tchemit < chemit(a)codelutin.com >
* @param <E> the type of entity
* @since 2.3.0
*/
-public class TopiaEntityBinder<E extends TopiaEntity> extends Binder<E, E> {
+public class TopiaEntityBinder<E extends TopiaEntity> extends Binder<E, E>
+ implements Loador<E>{
private static final long serialVersionUID = 1L;
protected E empty;
@@ -52,4 +58,15 @@
}
copy(source, target);
}
+
+ @Override
+ public Map<String, Object> obtainProgperties(E from) {
+ throw new NotImplementedException("the method 'obtainProgperties' is" +
+ " no more implemented");
+ }
+
+ @Override
+ public void load(E from, E dst, boolean tech) {
+ copy(from,dst,tech);
+ }
}
\ No newline at end of file
1
0
r1810 - trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util
by tchemit@users.nuiton.org 21 Feb '10
by tchemit@users.nuiton.org 21 Feb '10
21 Feb '10
Author: tchemit
Date: 2010-02-21 21:39:35 +0100 (Sun, 21 Feb 2010)
New Revision: 1810
Added:
trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/TopiaEntityBinder.java
Modified:
trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/BeanPropertyLoador.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/Collector.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/EntityLoador.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/EntityOperator.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/EntityOperatorStore.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/Loador.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/TopiaEntityHelper.java
Log:
introduce TopiaEntityBinder, deprecate Loador api + reformat code
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/BeanPropertyLoador.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/BeanPropertyLoador.java 2010-02-21 19:38:11 UTC (rev 1809)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/BeanPropertyLoador.java 2010-02-21 20:39:35 UTC (rev 1810)
@@ -1,7 +1,7 @@
-/**
+/*
* *##%
* ToPIA :: Persistence
- * Copyright (C) 2004 - 2009 CodeLutin
+ * 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
@@ -38,8 +38,10 @@
* instead of the (protected) constructor.
*
* @param <E> type of bean to bind
- * @author chemit
+ * @author tchemit < chemit(a)codelutin.com >
+ * @deprecated since 2.3.0, prefer use the {@link TopiaEntityBinder}
*/
+@Deprecated
public class BeanPropertyLoador<E> implements Loador<E> {
public static <E> BeanPropertyLoador<E> newLoador(Class<E> klass, String... properties) {
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/Collector.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/Collector.java 2010-02-21 19:38:11 UTC (rev 1809)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/Collector.java 2010-02-21 20:39:35 UTC (rev 1810)
@@ -29,14 +29,13 @@
import org.nuiton.topia.persistence.DepthEntityVisitor;
import org.nuiton.topia.persistence.TopiaEntityEnum;
import org.nuiton.topia.persistence.TopiaEntity;
-import org.nuiton.topia.persistence.util.Collector.CollectorVisitor;
/**
- * Un objet qui permet de parcourir des entites (via un {@link CollectorVisitor})
- * et de collecter des donnees pendant le parcours.
+ * Un objet qui permet de parcourir des entites (via un
+ * {@link CollectorVisitor})et de collecter des donnees pendant le parcours.
*
* La classe a un type qui est le type de retour de la methode
- * {@link #detect(TopiaEntity[])}.
+ * {@link #detect(TopiaEntity...)}.
*
* On peut donc très facilement en faire un collecteur de donnees.
*
@@ -46,7 +45,7 @@
*
* @since 2.2.0
*/
-public abstract class Collector<R extends Object> {
+public abstract class Collector<R> {
private static final Log log = LogFactory.getLog(Collector.class);
/**
@@ -79,25 +78,36 @@
protected void onStarted(TopiaEntity e, boolean enter) {
}
- protected boolean onVisiting(TopiaEntity e, String name, Class<?> type, Object value) {
+ protected boolean onVisiting(TopiaEntity e, String name, Class<?> type,
+ Object value) {
return true;
}
- protected void onVisited(TopiaEntity e, String name, Class<?> type, Object value, boolean enter) {
+ protected void onVisited(TopiaEntity e, String name, Class<?> type,
+ Object value, boolean enter) {
}
- protected boolean onVisiting(TopiaEntity e, String name, Class<?> collectionType, Class<?> type, Object value) {
+ protected boolean onVisiting(TopiaEntity e, String name,
+ Class<?> collectionType,
+ Class<?> type, Object value) {
return true;
}
- protected void onVisited(TopiaEntity e, String name, Class<?> collectionType, Class<?> type, Object value, boolean enter) {
+ protected void onVisited(TopiaEntity e, String name,
+ Class<?> collectionType,
+ Class<?> type, Object value, boolean enter) {
}
- protected boolean onVisiting(TopiaEntity e, String name, Class<?> collectionType, Class<?> type, int index, Object value) {
+ protected boolean onVisiting(TopiaEntity e, String name,
+ Class<?> collectionType,
+ Class<?> type, int index, Object value) {
return true;
}
- protected void onVisited(TopiaEntity e, String name, Class<?> collectionType, Class<?> type, int index, Object value, boolean enter) {
+ protected void onVisited(TopiaEntity e, String name,
+ Class<?> collectionType,
+ Class<?> type,
+ int index, Object value, boolean enter) {
}
protected boolean onEnding(TopiaEntity e) {
@@ -107,7 +117,8 @@
protected void onEnded(TopiaEntity e, boolean enter) {
}
- protected void beforeAll(CollectorVisitor visitor, TopiaEntity... entities) {
+ protected void beforeAll(CollectorVisitor visitor,
+ TopiaEntity... entities) {
}
protected void before(CollectorVisitor visitor, TopiaEntity entity) {
@@ -116,9 +127,11 @@
protected void after(CollectorVisitor visitor, TopiaEntity entity) {
}
- protected abstract R afterAll(CollectorVisitor visitor, TopiaEntity... entities);
+ protected abstract R afterAll(CollectorVisitor visitor,
+ TopiaEntity... entities);
- public synchronized R detect(TopiaEntity... entities) throws TopiaException {
+ public synchronized R detect(TopiaEntity... entities)
+ throws TopiaException {
try {
beforeAll(visitor, entities);
@@ -180,7 +193,8 @@
}
@Override
- public void visit(TopiaEntity e, String name, Class<?> type, Object value) {
+ public void visit(TopiaEntity e, String name, Class<?> type,
+ Object value) {
boolean canContinue = collector.onVisiting(e, name, type, value);
if (canContinue) {
super.visit(e, name, type, value);
@@ -189,21 +203,28 @@
}
@Override
- public void visit(TopiaEntity e, String name, Class<?> collectionType, Class<?> type, Object value) {
- boolean canContinue = collector.onVisiting(e, name, collectionType, type, value);
+ public void visit(TopiaEntity e, String name, Class<?> collectionType,
+ Class<?> type, Object value) {
+ boolean canContinue =
+ collector.onVisiting(e, name, collectionType, type, value);
if (canContinue) {
super.visit(e, name, collectionType, type, value);
}
- collector.onVisited(e, name, collectionType, type, value, canContinue);
+ collector.onVisited(e, name, collectionType, type, value,
+ canContinue);
}
@Override
- public void visit(TopiaEntity e, String name, Class<?> collectionType, Class<?> type, int index, Object value) {
- boolean canContinue = collector.onVisiting(e, name, collectionType, type, index, value);
+ public void visit(TopiaEntity e, String name, Class<?> collectionType,
+ Class<?> type, int index, Object value) {
+ boolean canContinue =
+ collector.onVisiting(e, name, collectionType, type, index,
+ value);
if (canContinue) {
super.visit(e, name, collectionType, type, index, value);
}
- collector.onVisited(e, name, collectionType, type, index, value, canContinue);
+ collector.onVisited(e, name, collectionType, type, index, value,
+ canContinue);
}
@Override
@@ -235,7 +256,8 @@
if (contracts.length == 0) {
return null;
}
- Class<? extends TopiaEntity> contractClass = TopiaEntityHelper.getContractClass(contracts, e.getClass());
+ Class<? extends TopiaEntity> contractClass =
+ TopiaEntityHelper.getContractClass(contracts, e.getClass());
if (contractClass != null) {
return contractClass;
}
@@ -243,6 +265,7 @@
}
protected TopiaEntity getTopiaValue(Object value) {
- return (TopiaEntity) (value != null && value instanceof TopiaEntity ? value : null);
+ return (TopiaEntity) (value != null &&
+ value instanceof TopiaEntity ? value : null);
}
}
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/EntityLoador.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/EntityLoador.java 2010-02-21 19:38:11 UTC (rev 1809)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/EntityLoador.java 2010-02-21 20:39:35 UTC (rev 1810)
@@ -1,7 +1,7 @@
-/**
+/*
* *##%
* ToPIA :: Persistence
- * Copyright (C) 2004 - 2009 CodeLutin
+ * 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
@@ -29,18 +29,22 @@
* instead of the (protected) constructor).
*
* @param <E> type of entity
- * @author chemit
+ * @author tchemit < chemit(a)codelutin.com >
+ * @deprecated since 2.3.0, prefer use the {@link TopiaEntityBinder}
*/
+@Deprecated
public class EntityLoador<E extends TopiaEntity> extends BeanPropertyLoador<E> {
private static final long serialVersionUID = 1L;
protected E empty;
- public static <E extends TopiaEntity> EntityLoador<E> newEntityLoador(Class<E> klass, E empty, String... properties) {
+ public static <E extends TopiaEntity> EntityLoador<E> newEntityLoador(
+ Class<E> klass, E empty, String... properties) {
return new EntityLoador<E>(klass, empty, properties);
}
- public static <E extends TopiaEntity> EntityLoador<E> newEntityLoador(Class<E> klass, String... properties) {
+ public static <E extends TopiaEntity> EntityLoador<E> newEntityLoador(
+ Class<E> klass, String... properties) {
return newEntityLoador(klass, null, properties);
}
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/EntityOperator.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/EntityOperator.java 2010-02-21 19:38:11 UTC (rev 1809)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/EntityOperator.java 2010-02-21 20:39:35 UTC (rev 1810)
@@ -1,7 +1,7 @@
-/**
+/*
* *##%
* ToPIA :: Persistence
- * Copyright (C) 2004 - 2009 CodeLutin
+ * 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
@@ -59,9 +59,9 @@
* D'autres methodes permettent d'effectuer des operations en lot (sur plusieurs
* proprietes en meme temps) sur les proprietes :
*
- * {@link #copyProperties(TopiaEntity, TopiaEntity, boolean, String[])}
- * {@link #obtainProperties(TopiaEntity, String[])}
- * {@link #clearProperties(TopiaEntity, String[])}
+ * {@link #copyProperties(TopiaEntity, TopiaEntity, boolean, String...)}
+ * {@link #obtainProperties(TopiaEntity, String...)}
+ * {@link #clearProperties(TopiaEntity, String...)}
*
* Note : cet objet ne permet pas d'operation vers les bases.
*
@@ -88,7 +88,8 @@
protected EntityOperator(TopiaEntityEnum contract) {
if (contract == null) {
- throw new NullPointerException("contract parameter can not be null!");
+ throw new NullPointerException("contract parameter can not be " +
+ "null!");
}
this.contract = contract;
init();
@@ -266,7 +267,8 @@
* @param tech un drapeau pour recopier aussi les infos techniques
* @param properties les proprietes a recopier
*/
- public void copyProperties(B from, B dst, boolean tech, String... properties) {
+ public void copyProperties(B from, B dst, boolean tech,
+ String... properties) {
// if (from == null) {
//
// from = newInstance();
@@ -378,7 +380,8 @@
try {
return super.clone();
} catch (CloneNotSupportedException e) {
- throw new RuntimeException("could not clone " + this + " for reason : " + e.getMessage(), e);
+ throw new RuntimeException("could not clone " + this +
+ " for reason : " + e.getMessage(), e);
}
}
@@ -400,7 +403,7 @@
@Override
public String toString() {
- return super.toString() + "<" + getClazz() + ">";
+ return super.toString() + '<' + getClazz() + '>';
}
protected Collection<String> getProperties(String[] properties) {
@@ -455,7 +458,10 @@
log.debug("===== start for " + getClazz());
}
- init(getClazz(), explored, properties, associationProperties, getters, setters, childGetters, childAdders, childAddersAll, childRemovers, childSize, childClearers, childIsEmpty);
+ init(getClazz(), explored, properties, associationProperties,
+ getters, setters, childGetters, childAdders,
+ childAddersAll, childRemovers, childSize,
+ childClearers, childIsEmpty);
if (!properties.isEmpty()) {
int size = properties.size();
@@ -478,7 +484,9 @@
associationProperties = Collections.unmodifiableList(associationProperties);
}
if (log.isDebugEnabled()) {
- log.debug("===== end for " + getClazz() + " (" + properties.size() + " properties, " + associationProperties.size() + " associations)");
+ log.debug("===== end for " + getClazz() + " (" +
+ properties.size() + " properties, " +
+ associationProperties.size() + " associations)");
}
} catch (IntrospectionException e) {
throw new RuntimeException(e);
@@ -496,9 +504,11 @@
}
}
- private Method getMethod(String name, int nbParams, Method[] methodDescriptors) {
+ private Method getMethod(String name, int nbParams,
+ Method[] methodDescriptors) {
for (Method m : methodDescriptors) {
- if (name.equals(m.getName()) && m.getParameterTypes().length == nbParams) {
+ if (name.equals(m.getName()) &&
+ m.getParameterTypes().length == nbParams) {
return m;
}
}
@@ -508,7 +518,8 @@
private int checkPropertyIndex(String name) {
int index = properties.indexOf(name);
if (index == -1) {
- throw new IllegalArgumentException("property " + name + " is unknown for " + this);
+ throw new IllegalArgumentException("property " + name +
+ " is unknown for " + this);
}
return index;
}
@@ -516,7 +527,8 @@
private int checkAssociationPropertyIndex(String name) {
int index = associationProperties.indexOf(name);
if (index == -1) {
- throw new IllegalArgumentException("association property " + name + " is unknown for " + this);
+ throw new IllegalArgumentException("association property " +
+ name + " is unknown for " + this);
}
return index;
}
@@ -535,7 +547,8 @@
}
@SuppressWarnings({"unchecked"})
- protected static <V> V invokeWithResult(Method m, Object bean, Object... args) {
+ protected static <V> V invokeWithResult(Method m, Object bean,
+ Object... args) {
try {
if (log.isTraceEnabled()) {
log.trace(bean.getClass() + "#" + m.getName());
@@ -566,7 +579,8 @@
throw new NullPointerException("entityClass can not be null!");
}
if (!entityClass.isInterface()) {
- throw new IllegalArgumentException("entityClass parameter " + entityClass + " is not interface!");
+ throw new IllegalArgumentException("entityClass parameter " +
+ entityClass + " is not interface!");
}
if (explored.contains(entityClass)) {
return;
@@ -585,7 +599,8 @@
for (PropertyDescriptor propertydescriptor : propertyDescriptors) {
String propertyName = propertydescriptor.getName();
- if (propertydescriptor.getReadMethod() != null && propertydescriptor.getWriteMethod() != null) {
+ if (propertydescriptor.getReadMethod() != null &&
+ propertydescriptor.getWriteMethod() != null) {
// on a detecte une propriete (lecture/ecriture)
if (log.isDebugEnabled()) {
log.debug("detected property : " + propertyName);
@@ -634,7 +649,9 @@
Class<?>[] interfaces = entityClass.getInterfaces();
if (interfaces.length > 0) {
for (Class<?> c : interfaces) {
- if (TopiaEntity.class == c || !(TopiaEntity.class.isAssignableFrom(c)) || explored.contains(c)) {
+ if (TopiaEntity.class == c ||
+ !(TopiaEntity.class.isAssignableFrom(c)) ||
+ explored.contains(c)) {
// on ne traite pas
continue;
}
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/EntityOperatorStore.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/EntityOperatorStore.java 2010-02-21 19:38:11 UTC (rev 1809)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/EntityOperatorStore.java 2010-02-21 20:39:35 UTC (rev 1810)
@@ -50,9 +50,11 @@
* @see EntityOperator
*/
@SuppressWarnings("unchecked")
- public static <E extends TopiaEntity> EntityOperator<E> getOperator(TopiaEntityEnum contract) {
+ public static <E extends TopiaEntity> EntityOperator<E> getOperator(
+ TopiaEntityEnum contract) {
- EntityOperator<E> operator = (EntityOperator<E>) shared.store.get(contract);
+ EntityOperator<E> operator =
+ (EntityOperator<E>) shared.store.get(contract);
if (operator == null) {
synchronized (shared.store) {
operator = new EntityOperator<E>(contract);
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/Loador.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/Loador.java 2010-02-21 19:38:11 UTC (rev 1809)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/Loador.java 2010-02-21 20:39:35 UTC (rev 1810)
@@ -27,7 +27,10 @@
*
* @param <E> type of bean to load
* @author chemit
+ * @deprecated since 2.3.0, prefer use the {@link org.nuiton.util.beans.Binder}
+ * api (and {@link TopiaEntityBinder} extension.
*/
+@Deprecated
public interface Loador<E> extends java.io.Serializable {
/**
Added: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/TopiaEntityBinder.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/TopiaEntityBinder.java (rev 0)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/TopiaEntityBinder.java 2010-02-21 20:39:35 UTC (rev 1810)
@@ -0,0 +1,55 @@
+/*
+ * *##%
+ * ToPIA :: Persistence
+ * 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>.
+ * ##%*
+ */
+package org.nuiton.topia.persistence.util;
+
+import org.nuiton.topia.persistence.TopiaEntity;
+import org.nuiton.util.beans.Binder;
+
+/**
+ * A {@link Binder} dedicated to {@link TopiaEntity} dealing with technical
+ * values.
+ * <p/>
+ * There is an internal sate {@link #empty} to deal with default values of
+ * properties of an entity.
+ *
+ * @author tchemit < chemit(a)codelutin.com >
+ * @param <E> the type of entity
+ * @since 2.3.0
+ */
+public class TopiaEntityBinder<E extends TopiaEntity> extends Binder<E, E> {
+ private static final long serialVersionUID = 1L;
+
+ protected E empty;
+
+ public void setEmpty(E empty) {
+ this.empty = empty;
+ }
+
+ public void copy(E source, E target, boolean tech) {
+ if (source == null) {
+ source = empty;
+ }
+ if (tech) {
+ TopiaEntityHelper.bindTechnical(source, target);
+ }
+ copy(source, target);
+ }
+}
\ No newline at end of file
Property changes on: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/TopiaEntityBinder.java
___________________________________________________________________
Added: svn:keywords
+ "Author Date Id Revision HeadURL
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/TopiaEntityHelper.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/TopiaEntityHelper.java 2010-02-21 19:38:11 UTC (rev 1809)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/TopiaEntityHelper.java 2010-02-21 20:39:35 UTC (rev 1810)
@@ -68,6 +68,14 @@
protected static final Double ZEROD = 0.;
protected static final Byte ZEROB = 0;
+ /**
+ *
+ * @param type the type to test
+ * @return null object (default value for primitive types)
+ * @deprecated since 2.3.0, prefer use the
+ * {@link org.nuiton.util.ObjectUtil#getNullValue(Class)} method
+ */
+ @Deprecated
protected static Object getNullValue(Class<?> type) {
if (type.isPrimitive()) {
type = MethodUtils.getPrimitiveWrapper(type);
@@ -93,6 +101,14 @@
return null;
}
+ /**
+ * @param value the value to test
+ * @return {@code true} if value is null or default value for primitive
+ * types)
+ * @deprecated since 2.3.0, prefer use the
+ * {@link org.nuiton.util.ObjectUtil#isNullValue(Object)} method
+ */
+ @Deprecated
public static boolean isNullValue(Object value) {
if (value == null) {
return true;
1
0
Author: tchemit
Date: 2010-02-21 20:38:11 +0100 (Sun, 21 Feb 2010)
New Revision: 1809
Modified:
trunk/pom.xml
Log:
use nuiton-utils 1.1.5
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2010-02-21 10:27:45 UTC (rev 1808)
+++ trunk/pom.xml 2010-02-21 19:38:11 UTC (rev 1809)
@@ -189,7 +189,7 @@
<!-- libs version -->
<eugene.version>2.0.0-beta-4</eugene.version>
- <lutinutil.version>1.1.3</lutinutil.version>
+ <lutinutil.version>1.1.5-SNAPSHOT</lutinutil.version>
<processor.version>1.0.2</processor.version>
<i18n.version>1.0.1</i18n.version>
<xmlrpc.version>3.1.2</xmlrpc.version>
1
0
Author: tchemit
Date: 2010-02-21 11:27:45 +0100 (Sun, 21 Feb 2010)
New Revision: 1808
Modified:
trunk/pom.xml
Log:
Utilisation de mavenpom4redmine 2.0.5
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2010-02-20 15:14:09 UTC (rev 1807)
+++ trunk/pom.xml 2010-02-21 10:27:45 UTC (rev 1808)
@@ -9,7 +9,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>mavenpom4redmine</artifactId>
- <version>2.0.4</version>
+ <version>2.0.5</version>
</parent>
<artifactId>topia</artifactId>
1
0
r1807 - trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration
by tchemit@users.nuiton.org 20 Feb '10
by tchemit@users.nuiton.org 20 Feb '10
20 Feb '10
Author: tchemit
Date: 2010-02-20 16:14:09 +0100 (Sat, 20 Feb 2010)
New Revision: 1807
Modified:
trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/ManualMigrationCallback.java
Log:
reformat code
Modified: trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/ManualMigrationCallback.java
===================================================================
--- trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/ManualMigrationCallback.java 2010-02-20 13:39:12 UTC (rev 1806)
+++ trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/ManualMigrationCallback.java 2010-02-20 15:14:09 UTC (rev 1807)
@@ -47,7 +47,7 @@
*/
public abstract class ManualMigrationCallback {
- /** to use log facility, just put in your code: log.info("..."); */
+ /** Logger */
static private Log log = LogFactory.getLog(ManualMigrationCallback.class);
/**
@@ -63,16 +63,20 @@
CUSTOM_MIGRATION
}
- public abstract boolean askUser(Version dbVersion, Version applicationVersion, List<Version> versions);
+ public abstract boolean askUser(Version dbVersion,
+ Version applicationVersion,
+ List<Version> versions);
/**
- * Tentative de migration depuis la version de la base version la version souhaitee.
+ * Tentative de migration depuis la version de la base version la version
+ * souhaitee.
*
- * On applique toutes les migrations de version indiquee dans le parametre <code>version</code>.
+ * On applique toutes les migrations de version indiquee dans le parametre
+ * <code>version</code>.
*
* Pour chaque version, on cherche la methode migrateTo_XXX ou XXX est la
- * version transforme en identifiant java via la methode {@link Version#getValidName()}.
- * et on l'execute.
+ * version transforme en identifiant java via la methode
+ * {@link Version#getValidName()} et on l'execute.
*
* Note: pour chaque version a appliquer, on ouvre une nouvelle transaction.
*
@@ -81,7 +85,8 @@
* @param applicationVersion application version
* @param showSql drapeau pour afficher les requete sql
* @param showProgression drapeau pour afficher la progression
- * @param versions all versions knwon by service @return migration aggrement
+ * @param versions all versions knwon by service @return migration a
+ * ggrement
* @return le choix de migration executee
*/
public MigrationChoice doMigration(TopiaContext ctxt, Version dbVersion,
@@ -230,7 +235,8 @@
sta.executeUpdate();
sta.close();
if (log.isDebugEnabled()) {
- String message = _("topia.migration.end.sql", (++index), max, StringUtil.convertTime(System.nanoTime() - t0));
+ String message;
+ message = _("topia.migration.end.sql", (++index), max, StringUtil.convertTime(System.nanoTime() - t0));
log.debug(message);
}
}
1
0