You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@turbine.apache.org by Lars Grammel <la...@gmx.net> on 2001/07/18 18:18:37 UTC
[Patch] convenience methods in peers for unique columns
cvs diff -u -r1.1.1.1 Peer.vm
Index: Peer.vm
===================================================================
RCS file: /home/cvspublic/jakarta-turbine-torque/src/templates/om/Peer.vm,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 Peer.vm
--- Peer.vm 2001/07/18 12:54:18 1.1.1.1
+++ Peer.vm 2001/07/18 16:13:39
@@ -1362,6 +1362,72 @@
#end
#end
+#*
+--------------------------------------------------------------------------------
+convenience method for retrival of objects by the values of unique columns
+--------------------------------------------------------------------------------
+*#
+
+#foreach ( $unique in $table.Unices )
+
+ #foreach ( $colname in $unique.IndexColumns )
+
+ #if ( $table.containsColumn( $colname ) )
+
+ #set ( $col = $table.getColumn( $colname ) )
+ #set ( $tfc = $table.JavaName )
+ #set ( $cfc = $col.JavaName )
+ #set ( $cup = $col.Name.toUpperCase() )
+ #set ( $clo = $col.Name.toLowerCase() )
+
+ /**
+ * retrieves a $tfc by it's $clo
+ *
+ * @param $clo
+ * $cfc of the $tfc
+ *
+ * @return $tfc with the given $clo or null, if such a $tfc
+ * does not exist
+ *
+ * @throws Exception
+ * exception
+ */
+ public static $tfc retrieveBy$cfc( $col.JavaNative $clo )
+ throws Exception
+ {
+
+ /*
+ * generate criteria
+ */
+ Criteria c = new Criteria();
+
+ c.add( $cup , $clo );
+
+ /*
+ * retrieve elements
+ */
+ List l = doSelect( c );
+
+ /*
+ * check list size & return result
+ */
+ if ( l.size() > 0 )
+ {
+ return ($tfc) l.get( 0 );
+ }
+ else
+ {
+ return null;
+ }
+
+ }
+
+ #end
+
+ #end
+
+#end
+
## ------------------------------------------------------------
---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-dev-help@jakarta.apache.org