From: <wal...@us...> - 2010-09-22 23:11:24
|
Revision: 14623 http://andromda.svn.sourceforge.net/andromda/?rev=14623&view=rev Author: walterim Date: 2010-09-22 23:11:17 +0000 (Wed, 22 Sep 2010) Log Message: ----------- Added a search method to search for unique attributes. Modified Paths: -------------- trunk/cartridges/andromda-spring/src/main/resources/templates/spring/SpringDao.vsl trunk/cartridges/andromda-spring/src/main/resources/templates/spring/hibernate/SpringHibernateDaoBase.vsl trunk/cartridges/andromda-spring/src/test/expected/cartridge-output.zip Modified: trunk/cartridges/andromda-spring/src/main/resources/templates/spring/SpringDao.vsl =================================================================== --- trunk/cartridges/andromda-spring/src/main/resources/templates/spring/SpringDao.vsl 2010-09-20 19:13:43 UTC (rev 14622) +++ trunk/cartridges/andromda-spring/src/main/resources/templates/spring/SpringDao.vsl 2010-09-22 23:11:17 UTC (rev 14623) @@ -728,5 +728,26 @@ */ public void transformEntities(final int transform, final java.util.Collection#if($enableTemplating)<?>#end entities); +#set ($attributes = $entity.getAttributes(true, $entity.usingAssignedIdentifier)) +#foreach ($attribute in $attributes) +#if ($attribute.unique) +#set ($searchUniqueMethod = "searchUnique${stringUtils.capitalise($attribute.name)}") + /** + * Searchs for a single instance of ${entity.fullyQualifiedEntityName}. + * @param ${attribute.name} the unique ${attribute.name} to be used in the search.' + * @return a single instance of ${entity.fullyQualifiedEntityName}. + */ + public ${entity.fullyQualifiedEntityName} $searchUniqueMethod(final ${attribute.type.fullyQualifiedName} ${attribute.name}); + + /** + * Searchs for a single instance of ${entity.fullyQualifiedEntityName}. + * @param transform the transformation flag. + * @param ${attribute.name} the unique ${attribute.name} to be used in the search. + * @return a value object according the transformation flag. + */ + public Object $searchUniqueMethod(final int transform, final ${attribute.type.fullyQualifiedName} ${attribute.name}); + +#end +#end // spring-dao merge-point } \ No newline at end of file Modified: trunk/cartridges/andromda-spring/src/main/resources/templates/spring/hibernate/SpringHibernateDaoBase.vsl =================================================================== --- trunk/cartridges/andromda-spring/src/main/resources/templates/spring/hibernate/SpringHibernateDaoBase.vsl 2010-09-20 19:13:43 UTC (rev 14622) +++ trunk/cartridges/andromda-spring/src/main/resources/templates/spring/hibernate/SpringHibernateDaoBase.vsl 2010-09-22 23:11:17 UTC (rev 14623) @@ -1388,5 +1388,45 @@ } } +#foreach ($attribute in $attributes) +#if ($attribute.unique) +#set ($searchUniqueMethod = "searchUnique${stringUtils.capitalise($attribute.name)}") + /** + * {@inheritDoc} + */ + public ${entity.fullyQualifiedEntityName} $searchUniqueMethod(final ${attribute.type.fullyQualifiedName} ${attribute.name}) + { + final $fullyQualifiedSearchClassName search=new $fullyQualifiedSearchClassName( + new ${springTypesPackage}.SearchParameter[]{ + new ${springTypesPackage}.SearchParameter("${attribute.name}",${attribute.name},${springTypesPackage}.SearchParameter.EQUAL_COMPARATOR) + } + ); + + final java.util.Set#if($enableTemplating)<#if($daoInheritance)? extends #end${rootEntityType}>#end searchResult=this.search(search); + switch(searchResult.size()){ + case 0: return null; + case 1: return#if(!$enableTemplating) ($entity.fullyQualifiedName)#end searchResult.iterator().next(); + default: throw new org.hibernate.NonUniqueResultException(searchResult.size()); + } + } + + /** + * {@inheritDoc} + */ + public Object $searchUniqueMethod(final int transform, final ${attribute.type.fullyQualifiedName} ${attribute.name}) + { + final ${entity.fullyQualifiedEntityName} entity=this.$searchUniqueMethod(${attribute.name}); + if(entity == null) + { + return null; + } + else + { + return transformEntity(transform, entity); + } + } + +#end +#end // spring-hibernate-dao-base merge-point } \ No newline at end of file Modified: trunk/cartridges/andromda-spring/src/test/expected/cartridge-output.zip =================================================================== (Binary files differ) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |