Wanted - NHibernate templates

Anything that doesn't fall into the defect or enhancement categories

Wanted - NHibernate templates

Postby mike.griffin on Fri Aug 20, 2004 4:15 pm

If you are a NHibernate user looking for templates to generate mapping files and are willing to write them and publish them on our template library please make a post here. MyGeneration is full scripting and we have all the meta data ready for you. You can even use the XML Dom classes in our templates, you could write them in either VBScript, JScript or in DotScript (C# and VB.NET). Both communities could grow from this union. I'm sure NHibernate folks could think of other things in their project besides mapping files they could benefit from, ie, user interface generation and other items and we get MyGeneration on more desktops.

Thanx

Our online template library can be found here:
http://www.punktech.com/mygeneration/
User avatar
mike.griffin
Site Admin
 
Posts: 3290
Joined: Sat Apr 03, 2004 6:10 am
Location: Indianapolis, IN

Postby Jean-Luc on Mon Aug 23, 2004 12:25 am

Here is the NHibernateEntity.vsl velocity template of my andromda cartridge for nhibernate (a shamefull & dirty hack based on the existing hibernate cartridge) :

-----------------------------------------------------------------------------------
Code: Select all
/**
* Attention: Generated source! Do not modify by hand!
*/
using System;
using System.Collections;
#set ($packagename = $transform.findPackageName(${class.package}))
namespace $packagename {
##
#macro ( generateDocumentation $item $indent)
#foreach ( $tgv in $item.taggedValues )
#if ($tgv.tag == \"documentation\")
#set ($paras = $transform.formatHTMLStringAsParagraphs($tgv.value))
#foreach ( $par in $paras )
${indent}*
${indent}* <p>
#foreach ( $line in $par.lines )
${indent}* $line
#end
${indent}* </p>
#end
#end
#end
#end
##
#set ($primKey = $transform.getPrimaryKeyAttribute($class))
#set ($primKeyTypeName = $transform.findFullyQualifiedName($primKey.type))
##
#foreach ( $dep in $class.dependencies )
    #set ($class2 = $transform.findClassById($dep.targetType))
    #if ($transform.getStereotype($dep.id) == \"Exception\")
        #set ($defaultException = $class2)
    #end
#end

/**
#generateDocumentation ($class \" \")
#set ($tablename = $str.toDatabaseAttributeName(${class.name}, \"_\"))
*
* @hibernate.class
*     table=\"HIB_$tablename\"
*
* @hibernate.discriminator
*     column=\"class\"
*
*
#foreach ( $tgv in $class.taggedValues )
#if ($tgv.tag != \"documentation\")
#if ($tgv.tag == \"---\")
    #set ($tag = \"\")
#else
    #set ($tag = $tgv.tag)
#end
* $tag    $tgv.value
#end
#end
*
*/
public class ${class.name} {

    // --------------- attributes ---------------------
#foreach ( $att in $class.attributes )
#set ($atttypename = $transform.findFullyQualifiedName($att.type))

    private $atttypename ${att.name};
   
   /**
#generateDocumentation ($att \"    \")
    *
#set ($attcolumnname = $str.toDatabaseAttributeName(${att.name}, \"_\"))
#set ($attjdbctype   = $transform.findAttributeJDBCType($att))
#set ($attsqltype    = $transform.findAttributeSQLType($att))
#if ($transform.getStereotype($att.id) == \"PrimaryKey\")
    * @hibernate.id
    *     generator-class=\"native\"
#else
    * @hibernate.property
#end
    *     column=\"$attcolumnname\"
    *
    * @hibernate.column
    *     name=\"$attcolumnname\"
    *     sql-type=\"$attsqltype\"
    *
    */
    public $atttypename ${str.upperCaseFirstLetter(${att.name})}
    {
   get { return ${att.name}; }
   set { ${att.name} = value; }
    }   


#end

    // ------------- relations ------------------

#set ($sep = \"_\")
#set ($suffix = \"_FK\")
#foreach ( $assoc in $class.associationLinks )
    #set ($adata = $transform.getAssociationData($assoc))
    #set ($sourcetype = $adata.source.type)
    #set ($targettype = $adata.target.type)
    #set ($targettypename = $transform.findFullyQualifiedName($targettype))
#if ($adata.target.navigable == \"true\")
   /**
#generateDocumentation ($adata.target.end \"    \")
##    * multiplicity:     $adata.multiplicities
##    * source navigable: $adata.source.navigable
##    * target navigable: $adata.target.navigable
    *
#if ($adata.isOne2Many())
#set($foreignKeyColumn = \"${str.toDatabaseAttributeName(${adata.source.roleName}, $sep)}$suffix\")
#set ($foreignKeyAtt = $transform.getPrimaryKeyAttribute($sourcetype))
    * @hibernate.set
    *     role=\"$adata.target.roleName\"
    *     lazy=\"true\"
    * @hibernate.collection-key
    *     column=\"$foreignKeyColumn\"
    * @hibernate.collection-one-to-many
    *     class=\"$targettypename\"
    */
    public IDictionary ${str.upperCaseFirstLetter($adata.target.roleName)}
    {
       get { return ${adata.target.roleName}; }
   set { ${adata.target.roleName} = value; }
    }

    private IDictionary ${adata.target.roleName};
   
#end
#if ($adata.isMany2Many())
##
#set ($sourceKeyAtt  = $str.upperCaseFirstLetter(${transform.getPrimaryKeyAttribute($sourcetype).name}))
#set ($sourceColumn  = \"${adata.source.roleName}$sourceKeyAtt\")
#set ($sourceColumn  = ${str.toDatabaseAttributeName($sourceColumn, $sep)})
##
#set ($targetKeyAtt  = $str.upperCaseFirstLetter(${transform.getPrimaryKeyAttribute($targettype).name}))
#set ($targetColumn  = \"${adata.target.roleName}$targetKeyAtt\")
#set ($targetColumn  = ${str.toDatabaseAttributeName($targetColumn, $sep)})
##
#set ($joinTableName = ${str.toRelationName($sourceColumn, $targetColumn, $sep)})
##
    * @hibernate.set
    *     lazy=\"true\"
    *     table=\"HIB_${joinTableName}\"
    * @hibernate.collection-key
    *     column=\"$sourceColumn\"
    * @hibernate.collection-many-to-many
    *     column=\"$targetColumn\"
    *     class=\"$targettypename\"
    */
    public IDictionary ${str.upperCaseFirstLetter($adata.target.roleName)}
    {
       get { return ${adata.target.roleName}; }
       set { ${adata.target.roleName} = value; }
    }

    private IDictionary ${adata.target.roleName};
   
#end
#if ($adata.isOne2One() || $adata.isMany2One())
#if ($adata.isMany2One())
    *   @hibernate.many-to-one
#end
#if ($adata.isOne2One())
    *   @hibernate.one-to-one
#end
#set($foreignKeyColumn = \"${str.toDatabaseAttributeName(${adata.target.roleName}, $sep)}$suffix\")
    *       column=\"${foreignKeyColumn}\"
    */
    public ${targettypename} ${str.upperCaseFirstLetter($adata.target.roleName)}
    {
       get { return ${adata.target.roleName}; }
       set { ${adata.target.roleName} = value; }
    }
    private ${targettypename} ${adata.target.roleName};

#end


#end
#end

    // ---------------- business methods  ----------------------

#foreach ( $op in $class.operations)
#if ($transform.getStereotype($op.id) != \"FinderMethod\")
   /**
#generateDocumentation ($op \"    \")
    *
    */
#set ($msig = $transform.getOperationSignature($op))
#set ($returntype = $transform.findFullyQualifiedName($op.getType()))
#if ($defaultException)
    $op.visibility abstract $returntype ${msig}
        throws $defaultException.name;
#else
    $op.visibility abstract $returntype ${msig};
#end
#end
#end
}
}
Jean-Luc
Lurker
 
Posts: 1
Joined: Sun Aug 22, 2004 11:13 pm

Postby mike.griffin on Mon Aug 23, 2004 1:24 pm

Thanx, I will take a look at this, we're just coming up for air after a pretty big build, welcome aboard too.
User avatar
mike.griffin
Site Admin
 
Posts: 3290
Joined: Sat Apr 03, 2004 6:10 am
Location: Indianapolis, IN

Postby mike.griffin on Tue Aug 31, 2004 1:15 am

User avatar
mike.griffin
Site Admin
 
Posts: 3290
Joined: Sat Apr 03, 2004 6:10 am
Location: Indianapolis, IN

Postby mike.griffin on Fri Oct 08, 2004 7:32 pm

NET is user friendly.
Posted By: Vagif Hagverdi on October 06, 2004 @ 11:49 AM in response to Message #141541 3 replies in this thread

Here's just one simple example.
I'm a user of hibernate. And naturaly i was intrested in code generation tools that support hibernate, such as Middlegen and andromda. I tried to download and use Middlegen 3 times !!! COuld not pass the stage of messing with ant scripts, config files, copying jar files to correct locations. Finally on a 4-th try I spent couple of hours and did it !! Boy i was happy just to see finally GUI with my tables loaded in it. And mid you Middlegen is old and established product.

Now let's go to NET side. I'm also working with dotnet now, and because i'm a happy user of hibernate i naturally picked up NHibernate. AFter some research I found out that there are free codegeneration tools in dotnet. Namely CodeSmith and MyGeneration. I chosed MyGeneration because it already had some hnibernate templates. Download, installation and running GUI took less than 2 minutes ! And no messing with configs, jar files, scripts, environment variables etc. In a nice GUI I just clicked the button, selected database, provided username and password and voila ! Nice tree view with all my dtabase objects, tables, columns, foregn key, properties, custom properties, scripts source code, script output screen, everything ! Is this product commercial ? No ! Is this product 10 years old ? No !

Do you still wonder why MS wins debelopers ? I do not. Cause i'm sold already !


From http://www.theserverside.com/news/thread.tss?thread_id=29258
User avatar
mike.griffin
Site Admin
 
Posts: 3290
Joined: Sat Apr 03, 2004 6:10 am
Location: Indianapolis, IN

Postby sbc on Fri Oct 08, 2004 9:26 pm

Pity no one has taken on your template and created their own. Unless someone is working on one now and is about to release it...

We need more templates - after all that is the real power of MyGeneration, not dOOdads (and some day EntitySpaces). Gentle.NET is the second most popular template (and the only third-party developed framework template), after SQL Stored Procedures (which is actually very useful - designed with dOOdads in mind, but can be used with anything).

Perhaps there will be a flood of them one day.
User avatar
sbc
Expert
 
Posts: 446
Joined: Sat Apr 03, 2004 6:10 am
Location: North East Lincolnshire, England

Postby mike.griffin on Fri Oct 08, 2004 11:38 pm

I know, it's been downloaded 169 times or so, I'm disappointed that nobody has contributed a better template, I'm sure somebody has improved it. Take, Take, Take, and nothing to offer ......... :cry:
User avatar
mike.griffin
Site Admin
 
Posts: 3290
Joined: Sat Apr 03, 2004 6:10 am
Location: Indianapolis, IN

I have just uploaded a NHibernate vb.net template ...

Postby mhnyborg on Wed Oct 20, 2004 6:37 am

I have just uploaded a NHibernate vb.net template that also generates the mapping file.
Must of the code in the template is stolen from the C# version of the template. I did a translation of to reasons, to better understand the template code and to have the template in VB, that’s the language we are using in the company where I am working.

I am planning to extend the template to support one-to-many and many-to-many code generation. But for the moment I am waiting for NHibernate to work in version 2 of the .NET framework.

Best Regards Martin
mhnyborg
Lurker
 
Posts: 1
Joined: Wed Oct 20, 2004 6:26 am

Postby mike.griffin on Wed Oct 20, 2004 1:48 pm

Fantastic Martin, you're the person we've been hoping for. Let me know if you have any questions. I'll download it and give it a try ...
User avatar
mike.griffin
Site Admin
 
Posts: 3290
Joined: Sat Apr 03, 2004 6:10 am
Location: Indianapolis, IN

Postby mike.griffin on Wed Oct 20, 2004 1:52 pm

Also, you should create an Archive and then add your template to the archive, that will it will appear at the top of the page and more folks will see it. It only takes a few minutes, just create an archive, then add your template to it.

Again thanx and welcome aboard (see previous post above).
User avatar
mike.griffin
Site Admin
 
Posts: 3290
Joined: Sat Apr 03, 2004 6:10 am
Location: Indianapolis, IN


Return to General Questions or Comments

Who is online

Users browsing this forum: No registered users and 3 guests

cron