r2161 - in trunk/topia-persistence/src: main/java/org/nuiton/topia/generator test/xmi
Author: tchemit Date: 2010-11-30 17:25:09 +0100 (Tue, 30 Nov 2010) New Revision: 2161 Url: http://nuiton.org/repositories/revision/topia/2161 Log: Evolution #1121: Deprecates the useDAOLegacy tag value, replace it by daoImplementation Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/DAOAbstractTransformer.java trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/TopiaGeneratorUtil.java trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/TopiaTagValues.java trunk/topia-persistence/src/test/xmi/topiatest.properties 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-11-29 13:16:49 UTC (rev 2160) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/DAOAbstractTransformer.java 2010-11-30 16:25:09 UTC (rev 2161) @@ -89,7 +89,11 @@ */ Set<String> allEntitiesFqn; - protected boolean extendLegacyDAO; + /** + * The class of abstract dao to use. + * @since 2.5 + */ + protected Class<?> daoImplementation; /** * Map of extra operations for DAO. The key of the map is the qualified @@ -102,7 +106,14 @@ public void transformFromModel(ObjectModel model) { usages = TopiaGeneratorUtil.searchDirectUsages(model); - extendLegacyDAO = Boolean.valueOf(model.getTagValue(TopiaTagValues.TAG_USE_LEGACY_DAO)); + boolean extendLegacyDAO = Boolean.valueOf(model.getTagValue(TopiaTagValues.TAG_USE_LEGACY_DAO)); + if (extendLegacyDAO) { + log.warn("Using a deprecated tag value "+ + TopiaTagValues.TAG_USE_LEGACY_DAO+", prefer use the tag value "+TopiaTagValues.TAG_DAO_IMPLEMENTATION); + daoImplementation = TopiaDAOLegacy.class; + } else { + daoImplementation = TopiaGeneratorUtil.getDAOImplementation(model); + } List<ObjectModelClass> allEntities = TopiaGeneratorUtil.getEntityClasses(model, true); allEntitiesFqn = new HashSet<String>(allEntities.size()); @@ -173,11 +184,12 @@ } } if (extendClass.length() == 0) { - if (extendLegacyDAO) { - extendClass = TopiaDAOLegacy.class.getName() + "<E>"; - } else { - extendClass = TopiaDAOImpl.class.getName() + "<E>"; - } + extendClass = daoImplementation.getName() + "<E>"; +// if (extendLegacyDAO) { +// extendClass = TopiaDAOLegacy.class.getName() + "<E>"; +// } else { +// extendClass = TopiaDAOImpl.class.getName() + "<E>"; +// } } if (log.isDebugEnabled()) { log.debug("super class = " + extendClass); 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-11-29 13:16:49 UTC (rev 2160) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/TopiaGeneratorUtil.java 2010-11-30 16:25:09 UTC (rev 2161) @@ -42,6 +42,7 @@ import org.nuiton.eugene.models.object.ObjectModelInterface; import org.nuiton.eugene.models.object.ObjectModelOperation; import org.nuiton.eugene.models.object.ObjectModelParameter; +import org.nuiton.topia.persistence.TopiaDAOImpl; import java.util.ArrayList; import java.util.Arrays; @@ -179,8 +180,8 @@ } /** - * @param attr - * @return + * @param attr the attribute to inspece + * @return the name of the name in db of the reverse attribute * @deprecated since 2.5, prefer use the methode {@link #getReverseDbName(ObjectModelAttribute)} */ @Deprecated @@ -971,6 +972,35 @@ return result; } + /** + * Obtain the class to use as abstract dao. + * + * It will look after a tag value {@link TopiaTagValues#TAG_DAO_IMPLEMENTATION} in model + * and if not found will use the default value which is {@link TopiaDAOImpl}. + * + * @param model the model which could contains + * @return the type of the abstract dao to use + * @since 2.5 + */ + public static Class<?> getDAOImplementation(ObjectModel model) { + String daoImpl = getDaoImplementationTagValue(model); + Class<?> result; + if (StringUtils.isEmpty(daoImpl)) { + + // use the default dao implementation of topia + result = TopiaDAOImpl.class; + } else { + try { + result = Class.forName(daoImpl); + } catch (ClassNotFoundException e) { + String message = "Could not find dao implementation named " + daoImpl; + log.error(message); + throw new IllegalStateException(message, e); + } + } + return result; + } + public static Map<ObjectModelClass, Set<ObjectModelClass>> searchDirectUsages(ObjectModel model) { List<ObjectModelClass> allEntities; @@ -1636,5 +1666,20 @@ return value; } + /** + * Obtain the value of the {@link TopiaTagValues#TAG_DAO_IMPLEMENTATION} + * tag value on the given model. + * <p/> + * + * @param model model to seek + * @return the none empty value of the found tag value or {@code null} if not found nor empty. + * @see TopiaTagValues#TAG_DAO_IMPLEMENTATION + * @since 2.5 + */ + public static String getDaoImplementationTagValue(ObjectModel model) { + String value = findTagValue(TopiaTagValues.TAG_DAO_IMPLEMENTATION, null, model); + return value; + } + } // TopiaGeneratorUtil Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/TopiaTagValues.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/TopiaTagValues.java 2010-11-29 13:16:49 UTC (rev 2160) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/TopiaTagValues.java 2010-11-30 16:25:09 UTC (rev 2161) @@ -295,11 +295,27 @@ * * @see TopiaGeneratorUtil#getTypeTagValue(ObjectModelAttribute) * @since 2.5 + * @deprecated since 2.5, prefer use the tag value */ + @Deprecated @TagValueDefinition(target = {ObjectModel.class}) String TAG_USE_LEGACY_DAO = "useLegacyDAO"; + /** + * To specify the abstract dao to use. + * + * If none given, will use the {@code org.nuiton.topia.persistence.TopiaDAOImpl}. + * + * Other value possible is {@code org.nuiton.topia.persistence.TopiaDAOLegacy} + * + * @see TopiaGeneratorUtil#getDaoImplementationTagValue(ObjectModel) + * @since 2.5 + */ + @TagValueDefinition(target = {ObjectModel.class}) + String TAG_DAO_IMPLEMENTATION = "daoImplementation"; + + /** * Tag pour specifier l'exception principale de l'application. * Utiliser dans le ServiceTransformer ou QueryHelperTransformer pour etre Modified: trunk/topia-persistence/src/test/xmi/topiatest.properties =================================================================== --- trunk/topia-persistence/src/test/xmi/topiatest.properties 2010-11-29 13:16:49 UTC (rev 2160) +++ trunk/topia-persistence/src/test/xmi/topiatest.properties 2010-11-30 16:25:09 UTC (rev 2161) @@ -24,9 +24,13 @@ ### model.tagvalue.i18n=topia.test.common. model.tagvalue.generateOperatorForDAOHelper=true -model.tagvalue.useLegacyDAO=true model.tagvalue.constantPrefix=PROPERTY_ +# Do not use this tag value (deprecated since 2.5) +#model.tagvalue.useLegacyDAO=true +# Replaced by this one, which will allow us to switch to any dao implementation... +model.tagvalue.daoImplementation=org.nuiton.topia.persistence.TopiaDAOLegacy + #org.nuiton.topiatest.Company.class.tagvalue.naturalIdMutable=false #org.nuiton.topiatest.Company.attribute.siret.tagvalue.naturalId=true #org.nuiton.topiatest.Company.attribute.name.tagvalue.naturalId=true
participants (1)
-
tchemit@users.nuiton.org