<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Manju&#039;s blog &#187; ORM</title>
	<atom:link href="http://www.manjukiran.net/category/orm/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.manjukiran.net</link>
	<description></description>
	<lastBuildDate>Thu, 20 May 2010 06:35:24 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>ColdFusion-ORM: Auto-generation of tables, Naming Strategy and automatically populating data</title>
		<link>http://www.manjukiran.net/2009/10/09/coldfusion-orm-auto-generation-of-tables-naming-strategy-and-automatically-populating-data/</link>
		<comments>http://www.manjukiran.net/2009/10/09/coldfusion-orm-auto-generation-of-tables-naming-strategy-and-automatically-populating-data/#comments</comments>
		<pubDate>Fri, 09 Oct 2009 12:39:00 +0000</pubDate>
		<dc:creator>Manjukiran</dc:creator>
				<category><![CDATA[Adobe]]></category>
		<category><![CDATA[ColdFusion]]></category>
		<category><![CDATA[ORM]]></category>

		<guid isPermaLink="false">http://www.manjukiran.net/2009/10/09/coldfusion-orm-auto-generation-of-tables-naming-strategy-and-automatically-populating-data/</guid>
		<description><![CDATA[


Task:     Example to demonstrate Auto-generation of tables, Naming strategy and automatically populating data in ColdFusion-ORM
Previous Related Posts:     Getting Started with ORM     ColdFusion-ORM: Using CRUD Functions     ColdFusion-ORM: Define One-to-Many and Many-to-one relationships     ColdFusion-ORM: Collections   [...]]]></description>
			<content:encoded><![CDATA[<!--INFOLINKS_ON--><p><strong>Task:</strong>     <br />Example to demonstrate Auto-generation of tables, Naming strategy and automatically populating data in ColdFusion-ORM</p>
<p><strong>Previous Related Posts:</strong>     <br /><strong><a href="http://www.manjukiran.net/2009/07/14/101/">Getting Started with ORM</a></strong>     <br /><strong><a href="http://www.manjukiran.net/2009/07/14/coldfusion-orm-using-crud-functions/">ColdFusion-ORM: Using CRUD Functions</a></strong>     <br /><strong><a href="http://www.manjukiran.net/2009/07/15/coldfusion-orm-define-one-to-many-and-many-to-one-relationships/">ColdFusion-ORM: Define One-to-Many and Many-to-one relationships</a></strong>     <br /><strong><a href="http://www.manjukiran.net/2009/07/16/coldfusion-orm-collections/">ColdFusion-ORM: Collections</a></strong>     <br /><strong><strong><a href="http://www.manjukiran.net/2009/07/18/coldfusion-orm-define-computed-properties-formula-attribute/">ColdFusion-ORM: Define Computed Properties</a></strong></strong> </p>
<p><strong>Stuff that you would learn: </strong>    <br />- To auto-generate tables in ORM     <br />- To fill data into the auto-generated tables     <br />- To use the DDL-only attributes     <br />- To define custom Naming Strategy</p>
<p><strong>Steps to Run the example:</strong>     <br />-&#160; Create a datasource by name ‘test_datasource’ pointing to a empty database. Note that the example will take care of creating the tables and populating data into it.     <br />-&#160; Create a directory say &quot;orm_autogen&quot; under webroot.     <br />-&#160; Create the following files – Application.cfc, Art.cfc, Artists.cfc, mysqlscript.sql, lcasestrategy.cfc and index.cfm.     <br />-&#160; Run the URL “http://&lt;ip&gt;:&lt;port&gt;/orm_autogen/index.cfm”</p>
<p><b>Application.cfc </b>
<pre style="border-bottom: #999999 1px dashed; border-left: #999999 1px dashed; padding-bottom: 5px; line-height: 14px; background-color: #eee; padding-left: 5px; width: 100.36%; padding-right: 5px; font-family: andale mono, lucida console, monaco, fixed, monospace; height: 793px; color: #000000; font-size: 12px; overflow: auto; border-top: #999999 1px dashed; border-right: #999999 1px dashed; padding-top: 5px"><code>&lt;cfcomponent&gt;
    &lt;cfset this.name = &quot;ORM_Autogen&quot;&gt;
    &lt;cfset this.ormenabled = &quot;true&quot;&gt;
    &lt;!---
    * 'test_datasource' is a datasource which should be created
    * as a pre-requisite for this example. Artists table contains
    ---&gt;
    &lt;cfset this.datasource = &quot;test_datasource&quot;&gt;

    &lt;!---
    * To auto-generate tables, dbcreate should be specified.
    * dbcreate is 'none' by default.
    * It can be 'dropcreate' or 'update'.
    * Setting it to 'update' creates the table if it does not
    * exist or update the table if it exists.
    * Setting it to 'dropcreate' drops the table if it
    * exists and then creates it.
    ---&gt;
    &lt;cfset this.ormsettings.dbcreate = &quot;dropcreate&quot;&gt;

    &lt;!---
    * Path to the SQL script file that should be executed after
    * ORM is initialized.
    * Note that this applies only if dbcreate is set to dropcreate.
    * This must be the absolute file path or the path relative
    * to the application.
    * The SQL script file lets you populate the tables before
    * the application is accessed.
    ---&gt;
    &lt;cfset this.ormsettings.sqlscript=&quot;mysqlscript.sql&quot;&gt;

    &lt;!---
    * (Logical column name is the name of the property OR the value
    * of the column attribute if specified)
    * By default, when auto-generating the tables, the logical column
    * name is used as the column name.
    * If you want to change it, you should use the namingstrategy setting.

    * By default, namingstrategy=&quot;default&quot;. 

    * namingstrategy=&quot;smart&quot;: This strategy changes the logical table or
    * column name to uppercase. Also, if the logical table or column name
    * is in camel case, this strategy breaks the camelcased name and separates
    * the broken words using '_'.
    * For eg: firstName -&gt; FIRST_NAME, dateOfBirth -&gt; DATE_OF_BIRTH.

    * If you want to use a custom strategy, then, you should create a CFC,
    * implement the cfide.orm.INamingStrategy interface and specify the CFC
    * name for this setting.  In this example, I have demonstrated the
    * custom strategy.
    ---&gt;
    &lt;cfset this.ormsettings.namingstrategy=&quot;lcasestrategy&quot;&gt;
&lt;/cfcomponent&gt;

</code></pre>
<p><b>Art.cfc</b> </p>
<pre style="border-bottom: #999999 1px dashed; border-left: #999999 1px dashed; padding-bottom: 5px; line-height: 14px; background-color: #eee; padding-left: 5px; width: 100.35%; padding-right: 5px; font-family: andale mono, lucida console, monaco, fixed, monospace; height: 231px; color: #000000; font-size: 12px; overflow: auto; border-top: #999999 1px dashed; border-right: #999999 1px dashed; padding-top: 5px"><code>&lt;cfcomponent persistent=&quot;true&quot; table=&quot;Art&quot;&gt;
      &lt;cfproperty name=&quot;artId&quot; generator=&quot;identity&quot; fieldtype=&quot;id&quot;&gt;
    &lt;!---
    * Note that the attributes 'ormtype' and 'length' are used
    * only when the tables are auto-generated.  There are other
    * similar attributes like dbdefault, index, notnull, precision,
    * scale, sqltype, unique and uniquekey.
    ---&gt;
      &lt;cfproperty name=&quot;artName&quot; ormtype=&quot;string&quot; length=&quot;50&quot;&gt;
      &lt;cfproperty name=&quot;price&quot; ormtype=&quot;double&quot;&gt;
      &lt;cfproperty name=&quot;largeImage&quot; ormtype=&quot;string&quot; length=&quot;30&quot;&gt;
      &lt;cfproperty name=&quot;mediaId&quot; ormtype=&quot;integer&quot; length=&quot;10&quot;&gt;
      &lt;cfproperty name=&quot;isSold&quot; ormtype=&quot;boolean&quot; dbdefault=1&gt;
      &lt;cfproperty name=&quot;artist&quot; fkcolumn=&quot;artistid&quot; fieldtype=&quot;many-to-one&quot; cfc=&quot;Artists&quot;&gt;
&lt;/cfcomponent&gt;
</code></pre>
<p><b>Artists.cfc</b> </p>
<pre style="border-bottom: #999999 1px dashed; border-left: #999999 1px dashed; padding-bottom: 5px; line-height: 14px; background-color: #eee; padding-left: 5px; width: 100.36%; padding-right: 5px; font-family: andale mono, lucida console, monaco, fixed, monospace; height: 200px; color: #000000; font-size: 12px; overflow: auto; border-top: #999999 1px dashed; border-right: #999999 1px dashed; padding-top: 5px"><code>&lt;cfcomponent persistent=&quot;true&quot; table=&quot;Artists&quot;&gt;
      &lt;cfproperty name=&quot;artistId&quot; fieldtype=&quot;id&quot; ormtype=&quot;integer&quot; length=10&gt;
      &lt;cfproperty name=&quot;firstName&quot; ormtype=&quot;string&quot; length=&quot;20&quot; notnull=&quot;true&quot;&gt;
      &lt;cfproperty name=&quot;lastName&quot; ormtype=&quot;string&quot; length=&quot;20&quot; notnull=&quot;true&quot;&gt;
      &lt;cfproperty name=&quot;address&quot;  ormtype=&quot;string&quot; length=&quot;50&quot;&gt;
      &lt;cfproperty name=&quot;city&quot; ormtype=&quot;string&quot; length=&quot;20&quot;&gt;
      &lt;cfproperty name=&quot;state&quot; ormtype=&quot;string&quot; length=&quot;2&quot;&gt;
      &lt;cfproperty name=&quot;postalCode&quot; ormtype=&quot;string&quot; length=&quot;10&quot;&gt;
      &lt;cfproperty name=&quot;email&quot; ormtype=&quot;string&quot; length=&quot;50&quot; unique=&quot;true&quot;&gt;
      &lt;cfproperty name=&quot;phone&quot; ormtype=&quot;string&quot; length=&quot;20&quot;&gt;
      &lt;cfproperty name=&quot;fax&quot; ormtype=&quot;string&quot; length=&quot;12&quot;&gt;
      &lt;cfproperty name=&quot;thePassword&quot; ormtype=&quot;string&quot; length=&quot;20&quot;&gt;
&lt;/cfcomponent&gt;
</code></pre>
<p><b>lcasestrategy.cfc</b> </p>
<pre style="border-bottom: #999999 1px dashed; border-left: #999999 1px dashed; padding-bottom: 5px; line-height: 14px; background-color: #eee; padding-left: 5px; width: 100.35%; padding-right: 5px; font-family: andale mono, lucida console, monaco, fixed, monospace; height: 342px; color: #000000; font-size: 12px; overflow: auto; border-top: #999999 1px dashed; border-right: #999999 1px dashed; padding-top: 5px"><code>&lt;cfcomponent implements=&quot;cfide.orm.INamingStrategy&quot;&gt;
    &lt;!---
    * ColdFusion calls this method for each table name to generate
    * the new table name. The logical table name is the input.
    ---&gt;
    &lt;cffunction name=&quot;getTableName&quot; returntype=&quot;String&quot; access=&quot;public&quot;&gt;
        &lt;cfargument name=&quot;tableName&quot; type=&quot;String&quot;&gt; 

        &lt;cfreturn lCase(tableName)&gt; 

    &lt;/cffunction&gt;

    &lt;!---
    * ColdFusion calls this method for each column name to generated the
    * new column name. The logical column name is the input.
    ---&gt;
    &lt;cffunction name=&quot;getColumnName&quot; returntype=&quot;String&quot; access=&quot;public&quot;&gt;
        &lt;cfargument name=&quot;columnName&quot; type=&quot;String&quot;&gt;

        &lt;cfreturn lCase(columnName)&gt; 

    &lt;/cffunction&gt;
&lt;/cfcomponent&gt;
</code></pre>
<p><b>mySQLScript.sql</b> </p>
<pre style="border-bottom: #999999 1px dashed; border-left: #999999 1px dashed; padding-bottom: 5px; line-height: 14px; background-color: #eee; padding-left: 5px; width: 100.36%; padding-right: 5px; font-family: andale mono, lucida console, monaco, fixed, monospace; height: 162px; color: #000000; font-size: 12px; overflow: auto; border-top: #999999 1px dashed; border-right: #999999 1px dashed; padding-top: 5px"><code>--This SQl script will be automatically executed after the tables are auto-generated.
--Note that each SQL should be separated by a ';'.
insert into Artists(artistid, firstname, lastname, address, city, state, postalcode, email, phone, fax, thepassword)
values(1, 'Aiden', 'Donolan', '352 Corporate Ave.', 'Denver', 'CO', '80206-4526', 'aiden.donolan@donolan.com', '555-751-8464', '555-751-8463', 'peapod');
insert into Artists(artistid, firstname, lastname, address, city, state, postalcode, email, phone, fax, thepassword)
values(2, 'Austin', 'Weber', '25463 Main Street, Suite C', 'Berkeley', 'CA', '94707-4513', 'austin@life.com', '555-513-4318', '510-513-4888', 'nopolyes');
insert into Art(artname, price, largeimage, mediaid, issold, artistid)
values('Michael', 13900, 'aiden02.jpg', 1, 0, 1);
insert into Art(artname, price, largeimage, mediaid, issold, artistid)
values('Space', 9800, 'elecia01.jpg', 2, 1, 2);
</code></pre>
<p><b>index.cfm</b> </p>
<pre style="border-bottom: #999999 1px dashed; border-left: #999999 1px dashed; padding-bottom: 5px; line-height: 14px; background-color: #eee; padding-left: 5px; width: 100.73%; padding-right: 5px; font-family: andale mono, lucida console, monaco, fixed, monospace; height: 273px; color: #000000; font-size: 12px; overflow: auto; border-top: #999999 1px dashed; border-right: #999999 1px dashed; padding-top: 5px"><code>&lt;!---
* This example demonstrates Auto-generation of tables.
* This example will teach you
* - how to auto-generate tables in ORM
* - to fill data into the auto-generated tables
* - DDL-only attributes
* - how to use custom Naming Strategy

* 'test_datasource' is a datasource which should be created
* as a pre-requisite for this example. Artists table contains
* a list of artists records.  Art table contains a list of art
* records.  Artists table has a one-to-many relationship with
* Art table. These table would be created used in this example.
---&gt;

&lt;!---Load the artists and dump it---&gt;
&lt;cfdump var=&quot;#EntityLoad(&quot;Artists&quot;)#&quot;&gt;

</code></pre>
<!--INFOLINKS_OFF-->]]></content:encoded>
			<wfw:commentRss>http://www.manjukiran.net/2009/10/09/coldfusion-orm-auto-generation-of-tables-naming-strategy-and-automatically-populating-data/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Speaking on &#8216;ColdFusion 9: Advance ORM&#8217; at CFUnited 2009</title>
		<link>http://www.manjukiran.net/2009/07/23/speaking-on-coldfusion-9-advance-orm-at-cfunited-2009/</link>
		<comments>http://www.manjukiran.net/2009/07/23/speaking-on-coldfusion-9-advance-orm-at-cfunited-2009/#comments</comments>
		<pubDate>Thu, 23 Jul 2009 17:33:34 +0000</pubDate>
		<dc:creator>Manjukiran</dc:creator>
				<category><![CDATA[Adobe]]></category>
		<category><![CDATA[CFUnited]]></category>
		<category><![CDATA[ColdFusion]]></category>
		<category><![CDATA[ORM]]></category>

		<guid isPermaLink="false">http://www.manjukiran.net/2009/07/23/speaking-on-coldfusion-9-advance-orm-at-cfunited-2009/</guid>
		<description><![CDATA[I am excited to say that I will be speaking on ColdFusion 9: Advanced ORM at CFUnited &#8211; on August 13th at 3:15PM.&#160; Terry Ryan will cover the basics of ORM in an other session just before mine.&#160; I am planning to cover the following as part of the talk:

Relationship – one-to-many, many-to-one, one-to-one and [...]]]></description>
			<content:encoded><![CDATA[<!--INFOLINKS_ON--><p>I am excited to say that I will be <a href="http://cfunited.com/2009/speakers#speaker-616">speaking</a> on <a href="http://cfunited.com/2009/topics/366">ColdFusion 9: Advanced ORM</a> at CFUnited &#8211; on August 13th at 3:15PM.&#160; <a href="http://www.terrenceryan.com">Terry Ryan</a> will cover the basics of ORM in an other session just before mine.&#160; I am planning to cover the following as part of the talk:</p>
<ul>
<li>Relationship – one-to-many, many-to-one, one-to-one and many-to-many </li>
<li>Event Handling </li>
<li>Lazy Loading </li>
<li>Caching </li>
<li>Transactions </li>
<li>ORM Session Management </li>
<li>HBM files </li>
<li>Development time support – ormreload(), logSQL, savemapping, etc </li>
<li>Generating DDL </li>
</ul>
<p>If you want me to cover any other topics, do comment about it(Note that the above list is tentative.&#160; ORM is a vast subject and I need to consider the time factor as well.)&#160; This is my second session in CFUnited.&#160; Last year I had talked about Taking advantage of 64-bit support in ColdFusion.</p>
<p> Details about the other sessions from Adobe speakers is <a href="http://www.terrenceryan.com/blog/index.cfm/2009/7/20/CFUnited-2009">here</a>.&#160; Meet you all at CFUnited!</p>
<!--INFOLINKS_OFF-->]]></content:encoded>
			<wfw:commentRss>http://www.manjukiran.net/2009/07/23/speaking-on-coldfusion-9-advance-orm-at-cfunited-2009/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>ColdFusion-ORM: Define Computed properties (formula attribute)</title>
		<link>http://www.manjukiran.net/2009/07/18/coldfusion-orm-define-computed-properties-formula-attribute/</link>
		<comments>http://www.manjukiran.net/2009/07/18/coldfusion-orm-define-computed-properties-formula-attribute/#comments</comments>
		<pubDate>Fri, 17 Jul 2009 19:43:00 +0000</pubDate>
		<dc:creator>Manjukiran</dc:creator>
				<category><![CDATA[Adobe]]></category>
		<category><![CDATA[ColdFusion]]></category>
		<category><![CDATA[ORM]]></category>

		<guid isPermaLink="false">http://www.manjukiran.net/2009/07/18/coldfusion-orm-define-computed-properties-formula-attribute/</guid>
		<description><![CDATA[What are computed properties?      Consider the tables – Art and Artists.&#160; Art and Artists form a one-to-many relationship where one Artist has created many Art.&#160; Say, in each Artist object, you need a property that would contain the number of arts made by the Artist &#8211; use computed properties.&#160; The [...]]]></description>
			<content:encoded><![CDATA[<!--INFOLINKS_ON--><p><strong>What are computed properties?      <br /></strong>Consider the tables – Art and Artists.&#160; Art and Artists form a one-to-many relationship where one Artist has created many Art.&#160; Say, in each Artist object, you need a property that would contain the number of arts made by the Artist &#8211; use computed properties.&#160; The formula to compute the value of the property should be specified using the formula attribute of the cfproperty tag.&#160; The formula should be specified as a SQL that returns a single value.&#160; Note that computed properties do not map to any column in the table and are not persistent.</p>
<p><strong>Task:</strong>     <br />Example to demonstrate using computed properties in ColdFusion-ORM</p>
<p><strong>Previous Related Posts:</strong>     <br /><strong><a href="http://www.manjukiran.net/2009/07/14/101/">Getting Started with ORM</a></strong>     <br /><strong><a href="http://www.manjukiran.net/2009/07/14/coldfusion-orm-using-crud-functions/">ColdFusion-ORM: Using CRUD Functions</a></strong>     <br /><strong><a href="http://www.manjukiran.net/2009/07/15/coldfusion-orm-define-one-to-many-and-many-to-one-relationships/">ColdFusion-ORM: Define One-to-Many and Many-to-one relationships</a></strong>     <br /><strong><a href="http://www.manjukiran.net/2009/07/16/coldfusion-orm-collections/">ColdFusion-ORM: Collections</a></strong></p>
<p><strong>Stuff that you would learn: </strong>    <br />- how to define computed properties     <br />- how to define the formula for computed properties</p>
<p><strong>Steps to Run the example:</strong>     <br />-&#160; This example needs the cfartgallery datasource. This is shipped with ColdFusion by default.     <br />-&#160; Create a directory say &quot;ormformula&quot; under webroot.     <br />-&#160; Create the following files – Application.cfc, Artists.cfc and index.cfm.     <br />-&#160; Run the URL “http://&lt;ip&gt;:&lt;port&gt;/ormformula/index.cfm”</p>
<p><strong>Application.cfc</strong>     </p>
<pre style="border-bottom: #999999 1px dashed; border-left: #999999 1px dashed; padding-bottom: 5px; line-height: 14px; background-color: #eee; padding-left: 5px; width: 100%; padding-right: 5px; font-family: andale mono, lucida console, monaco, fixed, monospace; color: #000000; font-size: 12px; overflow: auto; border-top: #999999 1px dashed; border-right: #999999 1px dashed; padding-top: 5px"><code>component
{
    //Name of the application
    this.name = &quot;ORM_Formula&quot;;

    //ormenabled should be set to true so that ORM is enabled for this application
    this.ormenabled = &quot;true&quot;;

    //Set the datasource that needs to be used by the ORM Functions.  You can also set this in the ormsettings struct
    this.datasource = &quot;cfartgallery&quot;;
}
</code></pre>
<p><strong>Artists.cfc</strong></p>
<pre style="border-bottom: #999999 1px dashed; border-left: #999999 1px dashed; padding-bottom: 5px; line-height: 14px; background-color: #eee; padding-left: 5px; width: 100%; padding-right: 5px; font-family: andale mono, lucida console, monaco, fixed, monospace; color: #000000; font-size: 12px; overflow: auto; border-top: #999999 1px dashed; border-right: #999999 1px dashed; padding-top: 5px"><code>component persistent=&quot;true&quot; entityname=&quot;Artists&quot; table=&quot;Artists&quot;
{
    property name=&quot;id&quot; column=&quot;ARTISTID&quot; generator=&quot;increment&quot;;
    property name=&quot;firstname&quot;;
    property name=&quot;lastname&quot;;
    property name=&quot;address&quot;;
    property name=&quot;city&quot;;
    property name=&quot;state&quot;;
    property name=&quot;postalcode&quot;;
    property name=&quot;email&quot;;
    property name=&quot;phone&quot;;
    property name=&quot;fax&quot;;
    property name=&quot;thepassword&quot;;
    /*
        A property automatically becomes a computed property if formula attribute is specified.
        A SQL that returns a single value should be input to the formula attribute.  Note
        that computed properties do not map to any column in the table and are not persistent.

        In this example, the &quot;numberOfArts&quot; property will store the number of arts made by the
        Artist.  

        Have a close look at the SQL that is used. In this SQL, if you specify any column name, by default,
        hibernate assumes that the column is from the table to which this CFC maps to - here
        Artists table.  If you want to specify a column that belongs to another table, you should alias
        them. Hence, here, in the where condition art.ArtistId=ArtistId, the latter 'ArtistId' would be
        from the Artists table.  For each Artists entity, Hibernate would then substitue 'ArtistId' with
        the column-value for that entity.  For example, for the entity with ArtistId=5, the SQL would be:

            select Count(*) from Art art where art.ArtistId=5
    */
    property name=&quot;numberOfArts&quot; formula=&quot;select Count(*) from Art art where art.ArtistId=ArtistId&quot;;
}</code></pre>
<p><strong>index.cfm</strong></p>
<pre style="border-bottom: #999999 1px dashed; border-left: #999999 1px dashed; padding-bottom: 5px; line-height: 14px; background-color: #eee; padding-left: 5px; width: 100%; padding-right: 5px; font-family: andale mono, lucida console, monaco, fixed, monospace; color: #000000; font-size: 12px; overflow: auto; border-top: #999999 1px dashed; border-right: #999999 1px dashed; padding-top: 5px"><code>&lt;!---
This example will teach you
- how to define computed properties
- how to define the formula for computed properties
---&gt;

&lt;cfset ormreload()&gt;

&lt;cfset artists = EntityLoad(&quot;Artists&quot;)&gt;

&lt;cfloop array=&quot;#artists#&quot; index=&quot;artist&quot;&gt;
    &lt;cfoutput&gt;
        #artist.getFirstName()# #artist.getLastName()# has &lt;b&gt;#artist.getNumberOfArts()#&lt;/b&gt; arts&lt;br&gt;
    &lt;/cfoutput&gt;
&lt;/cfloop&gt;</code></pre>
<!--INFOLINKS_OFF-->]]></content:encoded>
			<wfw:commentRss>http://www.manjukiran.net/2009/07/18/coldfusion-orm-define-computed-properties-formula-attribute/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>ColdFusion ORM: ORM-CFC Generator Extension for Adobe ColdFusion Builder</title>
		<link>http://www.manjukiran.net/2009/07/17/coldfusion-orm-orm-cfc-generator-extension-for-adobe-coldfusion-builder/</link>
		<comments>http://www.manjukiran.net/2009/07/17/coldfusion-orm-orm-cfc-generator-extension-for-adobe-coldfusion-builder/#comments</comments>
		<pubDate>Fri, 17 Jul 2009 11:09:00 +0000</pubDate>
		<dc:creator>Manjukiran</dc:creator>
				<category><![CDATA[Adobe]]></category>
		<category><![CDATA[Adobe ColdFusion Builder]]></category>
		<category><![CDATA[CF Builder Extensions]]></category>
		<category><![CDATA[ColdFusion]]></category>
		<category><![CDATA[ORM]]></category>

		<guid isPermaLink="false">http://www.manjukiran.net/2009/07/17/coldfusion-orm-orm-cfc-generator-extension-for-adobe-coldfusion-builder/</guid>
		<description><![CDATA[When we started working on ColdFusion-ORM feature (me and Rupesh), the only way to provide ORM mapping was by using the hibernate XML file (hbm.xml).&#160; Later, we provided a way to specify the mapping in CFCs – ColdFusion-ORM would then take care of creating the hibernate mapping.&#160; This made life easier for the ColdFusion developers.&#160; [...]]]></description>
			<content:encoded><![CDATA[<!--INFOLINKS_ON--><p>When we started working on ColdFusion-ORM feature (me and Rupesh), the only way to provide ORM mapping was by using the hibernate XML file (hbm.xml).&#160; Later, we provided a way to specify the mapping in CFCs – ColdFusion-ORM would then take care of creating the hibernate mapping.&#160; This made life easier for the ColdFusion developers.&#160; Now we have the ORM-CFC Generator Extension in Adobe ColdFusion Builder which will generate ORM-CFCs automatically!</p>
<p>The Adobe CFC Generator can be downloaded from <a href="http://blogs.adobe.com/cfbuilder/attachments/Adobe%20CFC%20Generator.zip" target="_blank">this location</a> and the instructions to use it are <a href="http://blogs.adobe.com/cfbuilder/attachments/Using Adobe CFC Generator.pdf" target="_blank">here</a>.&#160; The Adobe CFC Generator </p>
<ul>
<li>allows you to create ORM-CFCs from a set of tables. </li>
<li>allows you to configure the ORM-CFCs – change the CFC-Name, change EntityName, change property-name, select/de-select columns, add relationships and join-conditions, etc. </li>
<li>generates ORM-CFCs (of-course!) </li>
<li>generates Service CFCs for each ORM-CFC that contain certain utility methods to work with the ORM-entities </li>
</ul>
<p>Note that the Adobe CFC Generator is provided as a sample extension.&#160; When the extension is installed, the source-code for the extension can be found in the installed location.&#160; Using the source code, you can modify/customize the UI/ORM-cfcs/Service-cfcs to add additional functionality.</p>
<p>Check out this blog post &#8211; <a href="http://blogs.adobe.com/cfbuilder/2009/07/ho_do_i_generate_orm_cfcs.html">How Do I generate ORM CFC&#8217;s???</a> – A nice captivate demo which shows you how to install and use ORM-CFC Generator Extension.&#160; The CFBuilder team will be posting heavily on extensions in the coming days – do have an eye on that space.</p>
<!--INFOLINKS_OFF-->]]></content:encoded>
			<wfw:commentRss>http://www.manjukiran.net/2009/07/17/coldfusion-orm-orm-cfc-generator-extension-for-adobe-coldfusion-builder/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>ColdFusion-ORM: Collections</title>
		<link>http://www.manjukiran.net/2009/07/16/coldfusion-orm-collections/</link>
		<comments>http://www.manjukiran.net/2009/07/16/coldfusion-orm-collections/#comments</comments>
		<pubDate>Thu, 16 Jul 2009 18:27:00 +0000</pubDate>
		<dc:creator>Manjukiran</dc:creator>
				<category><![CDATA[Adobe]]></category>
		<category><![CDATA[ColdFusion]]></category>
		<category><![CDATA[ORM]]></category>

		<guid isPermaLink="false">http://www.manjukiran.net/2009/07/16/coldfusion-orm-collections/</guid>
		<description><![CDATA[In this post, I will digress a bit and introduce you to a lighter feature of ColdFusion-ORM – COLLECTIONS.
What are collections?      Consider the same tables we have been using – Art and Artists.&#160; Say, in the Artist object, you just need an array/struct of Art names instead of an array/struct [...]]]></description>
			<content:encoded><![CDATA[<!--INFOLINKS_ON--><p>In this post, I will digress a bit and introduce you to a lighter feature of ColdFusion-ORM – COLLECTIONS.</p>
<p><strong>What are collections?      <br /></strong>Consider the same tables we have been using – Art and Artists.&#160; Say, in the Artist object, you just need an array/struct of Art names instead of an array/struct of the Art objects, then use collections.</p>
<p><strong>Task:</strong>     <br />Example to demonstrate collections in ColdFusion-ORM</p>
<p><strong>Previous Related Posts:</strong>     <br /><strong><a href="http://www.manjukiran.net/2009/07/14/101/">Getting Started with ORM</a></strong>     <br /><strong><a href="http://www.manjukiran.net/2009/07/14/coldfusion-orm-using-crud-functions/">ColdFusion-ORM: Using CRUD Functions</a></strong>     <br /><strong><a href="http://www.manjukiran.net/2009/07/15/coldfusion-orm-define-one-to-many-and-many-to-one-relationships/">ColdFusion-ORM: Define One-to-Many and Many-to-one relationships</a></strong> </p>
<p><strong>Stuff that you would learn: </strong>    <br />- how to create a collection as an array     <br />- how to create a collection as a struct     <br />- how to create a sorted collection</p>
<p><strong>Steps to Run the example:</strong>     <br />-&#160; This example needs the cfartgallery datasource. This is shipped with ColdFusion by default.     <br />-&#160; Create a directory say &quot;ormcollections&quot; under webroot.     <br />-&#160; Create the following files – Application.cfc, Artists.cfc and index.cfm.     <br />-&#160; Run the URL <a href="http://localhost:8500/ormcollections/index.cfm">http://localhost:8500/ormcollections/index.cfm</a></p>
<p>In this example, I have put comments only in Artsists.cfc.&#160; Please read the previous posts if need information about the other files.</p>
<p> <strong>Application.cfc</strong>
<pre style="border-bottom: #999999 1px dashed; border-left: #999999 1px dashed; padding-bottom: 5px; line-height: 14px; background-color: #eee; padding-left: 5px; width: 100%; padding-right: 5px; font-family: andale mono, lucida console, monaco, fixed, monospace; color: #000000; font-size: 12px; overflow: auto; border-top: #999999 1px dashed; border-right: #999999 1px dashed; padding-top: 5px"><code>component
{
    //Name for the application
    this.name = &quot;ORM_Collections&quot;;

    //ormenabled should be set to true so that ORM is enabled for this application
    this.ormenabled = &quot;true&quot;;

    /*
    Set the datasource that needs to be used by the ORM Functions.
    You can also set this in the ormsettings struct
    */
    this.datasource = &quot;cfartgallery&quot;;
}</code></pre>
<p><strong>Artists.cfc</strong> </p>
<pre style="border-bottom: #999999 1px dashed; border-left: #999999 1px dashed; padding-bottom: 5px; line-height: 14px; background-color: #eee; padding-left: 5px; width: 100%; padding-right: 5px; font-family: andale mono, lucida console, monaco, fixed, monospace; color: #000000; font-size: 12px; overflow: auto; border-top: #999999 1px dashed; border-right: #999999 1px dashed; padding-top: 5px">

<code>component persistent=&quot;true&quot;
{

    property name=&quot;artistid&quot; generator=&quot;increment&quot;;
    property name=&quot;firstname&quot;;
    property name=&quot;lastname&quot;;
    property name=&quot;address&quot;;
    property name=&quot;city&quot;;
    property name=&quot;state&quot;;
    property name=&quot;postalcode&quot;;
    property name=&quot;email&quot;;
    property name=&quot;phone&quot;;
    property name=&quot;fax&quot;;
    property name=&quot;thepassword&quot;;

/*
Artists have many arts.  Using Collections, the name of the arts created by
each artist can be retrieved as a string array.  Note that the art names
is picked from the table and you don’t require the ART component.  This also means
that you get an array of strings and not an array of persistent objects.

For doing this, first of all, set fieldtype=&quot;collection&quot;.

type: can be &quot;array&quot; or &quot;struct&quot;. Defaults to array.  If type=array, the art
names are retrieved as an array of names.  If type=struct, the art names are
retrieved as key-value pairs.

table: The name of the table in which the collection needs to be retrieved from.

fkcolumn: The name of the foriegn key. If not specified, will be figured
out by inspecting the database.

elementcolumn: The name of the table column which should be the retrieved as
the values of the array/struct. In this case, the names of the arts (Art-&gt;artname).

elementtype: The datatype of the table column used in elementcolumn.

orderby: Specify the sort order.  The string should be specified in the format
&quot;&lt;column_name_1&gt; &lt;sort_order&gt;, &lt;column_name_2&gt; &lt;sort_order&gt;, ...&quot;. &lt;column_name&gt;
should be the name of the column name of the table. &lt;sort_order&gt; is &quot;desc&quot; or &quot;asc&quot;.
*/

    property name=&quot;ArtNamesAsArray&quot; fieldtype=&quot;collection&quot; table=&quot;Art&quot;
    fkcolumn=&quot;artistid&quot; type=&quot;array&quot; elementtype=&quot;string&quot; elementcolumn=&quot;artname&quot;
    orderby=&quot;artname desc&quot;;

/*
Here is one more property which retrieves artnames but it retrieves it as a struct.

Two additional attributes are requried to defined for this collection type - structkeycolumn and
structkeytype in addition to the attributes used for fieldtype=&quot;collection&quot; for type=&quot;array&quot;.

Structkeycolumn: Specify the column name of the table which should be used for the keys of the struct.
This column should be unique for the records that are retrieved. Here, the column artid is used.  

Structkeytype: The type of the column that is used in structkeycolumn.
*/

    property name=&quot;ArtNamesAsStruct&quot; fieldtype=&quot;collection&quot; table=&quot;Art&quot; fkcolumn=&quot;artistid&quot;
    type=&quot;struct&quot; elementtype=&quot;string&quot; elementcolumn=&quot;artname&quot; structkeytype=&quot;int&quot;
    structkeycolumn=&quot;artid&quot; orderby=&quot;artid&quot;;
}

</code>
</pre>
<p><strong>index.cfm</strong> </p>
<pre style="border-bottom: #999999 1px dashed; border-left: #999999 1px dashed; padding-bottom: 5px; line-height: 14px; background-color: #eee; padding-left: 5px; width: 100%; padding-right: 5px; font-family: andale mono, lucida console, monaco, fixed, monospace; color: #000000; font-size: 12px; overflow: auto; border-top: #999999 1px dashed; border-right: #999999 1px dashed; padding-top: 5px"><code>&lt;!---
This example will teach you Collections.
- how to create a collection as an array
- how to create a collection as a struct
- how to create a sorted collection

cfartgallery datasource is used for this application.
Artists table is one of the table in cfartgallery which contains a list of
artists records. Arts is one other table which contains a list of arts created
by artists.  Artists has a one-to-many relationship with Arts records.  

Artists and Arts tables are used in this example.
---&gt;

&lt;cfscript&gt;
    /*
      Load the artists
    */
    artists = EntityLoad(&quot;Artists&quot;);

    WriteOutput(&quot;&lt;b&gt;Display the Artist name and the name of their arts which we got as an array&lt;br /&gt;&lt;/b&gt;&quot;);

    for (i=1;i&lt;=ArrayLen(artists);i++)
    {
        artist = artists[i];

        /*Retrieve the Names of the Arts created by the artist
          The Art-Names are retrieved as an array
        */
        artNameArray = artist.getArtNamesAsArray();

        /*
          Display the Artist Name and their arts
        */
        WriteOutput(&quot;&lt;b&gt;&quot; &amp; artist.getFirstName() &amp; &quot; &quot; &amp; artist.getLastName() &amp; &quot;&lt;/b&gt; has created &quot;);
        if (ArrayLen(artNameArray))
        {
            for (j=1;j&lt;=ArrayLen(artNameArray);j++)
            {
                WriteOutput('&lt;i&gt;' &amp; artNameArray[j] &amp; '&lt;/i&gt;, ');
            }
        }
        else
        {
            WriteOutput(&quot;&lt;i&gt;none&lt;/i&gt;&quot;);
        }
        WriteOutput(&quot;&lt;br&gt;&quot;);
    }
    WriteOutput(&quot;&lt;br&gt;&quot;);
    /*
      In the above section, retrieving art names as a array is shown.  The following section retrieves the
      art names as a struct
    */
    WriteOutput(&quot;&lt;b&gt;Display the Artist name and his arts which we got as struct&lt;br /&gt;&lt;/b&gt;&quot;);

    for (i=1;i&lt;=ArrayLen(artists);i++)
    {
        artist = artists[i];

        /*
          Retrieve the names of arts.  The Art Names are retrieved as a struct
          The keys of the struct are the IDs of the respective arts.
        */
        artNameStruct = artist.getArtNamesAsStruct();

        /*
        Display the Artist Name and their arts.
        */
        WriteOutput(&quot;&lt;b&gt;&quot; &amp; artist.getFirstName() &amp; &quot; &quot; &amp; artist.getLastName() &amp; &quot;&lt;/b&gt; has created &quot;);
        artNameKeyArray = StructKeyArray(artNameStruct);
        if (ArrayLen(artNameKeyArray))
        {
            for (j=1;j&lt;=ArrayLen(artNameKeyArray);j++)
            {
                /*
                  Art ID is a integer.  Hence using the java method to retrieve the value of the struct member
                */
                WriteOutput('&lt;i&gt;' &amp; artNameStruct.get(javacast(&quot;int&quot;, artNameKeyArray[j])) &amp; '&lt;/i&gt;, ');
            }
        }
        else
        {
            WriteOutput(&quot;&lt;i&gt;none&lt;/i&gt;&quot;);
        }
        WriteOutput(&quot;&lt;br&gt;&quot;);
    }
&lt;/cfscript&gt;</code></pre>
<!--INFOLINKS_OFF-->]]></content:encoded>
			<wfw:commentRss>http://www.manjukiran.net/2009/07/16/coldfusion-orm-collections/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>ColdFusion-ORM: Define One-to-Many and Many-to-one relationships</title>
		<link>http://www.manjukiran.net/2009/07/15/coldfusion-orm-define-one-to-many-and-many-to-one-relationships/</link>
		<comments>http://www.manjukiran.net/2009/07/15/coldfusion-orm-define-one-to-many-and-many-to-one-relationships/#comments</comments>
		<pubDate>Wed, 15 Jul 2009 12:43:00 +0000</pubDate>
		<dc:creator>Manjukiran</dc:creator>
				<category><![CDATA[ColdFusion]]></category>
		<category><![CDATA[ORM]]></category>
		<category><![CDATA[Adobe]]></category>

		<guid isPermaLink="false">http://www.manjukiran.net/2009/07/15/coldfusion-orm-define-one-to-many-and-many-to-one-relationships/</guid>
		<description><![CDATA[Task:     Example to demonstrate how to establish one-to-many and many-to-one Relationships in ColdFusion-ORM
 Previous Related Posts:   Getting Started with ORM   ColdFusion-ORM: Using CRUD Functions
Stuff that you would learn:      -&#160; how to establish a One-to-Many relationship between 2 CFCs.     [...]]]></description>
			<content:encoded><![CDATA[<!--INFOLINKS_ON--><p><strong>Task:</strong>     <br />Example to demonstrate how to establish one-to-many and many-to-one Relationships in ColdFusion-ORM</p>
<p> <strong>Previous Related Posts:</strong>   <br /><strong><a href="http://www.manjukiran.net/2009/07/14/101/" target="_blank">Getting Started with ORM</a></strong>   <br /><strong><a href="http://www.manjukiran.net/2009/07/14/coldfusion-orm-using-crud-functions/" target="_blank">ColdFusion-ORM: Using CRUD Functions</a></strong>
<p><strong>Stuff that you would learn:      <br /></strong>-&#160; how to establish a One-to-Many relationship between 2 CFCs.     <br />-&#160; how to establish a Many-to-One relationship between 2 CFCs.     <br />-&#160; how to do CRUD operations with CFCs which have a relationship.     <br />-&#160; how to use the implicit relationship methods added by ColdFusion.     <br />-&#160; cascade insert and delete</p>
<p><strong>Steps to Run the example:</strong>     <br />-&#160; This example needs the cfartgallery datasource. This is shipped with ColdFusion by default.     <br />-&#160; Create a directory say &quot;1tonorm&quot; under webroot.     <br />-&#160; Create the following files &#8211; Application.cfc, Art.cfc, Artists.cfc and index.cfm.     <br />-&#160; Run the URL <a href="http://localhost:8500/1tonorm/index.cfm">http://localhost:8500/1tonorm/index.cfm</a></p>
<p>I have interspersed the example with a lot of comments. You can understand the concept by just following the comments starting with Application.cfc and then Artists.cfc and then Arts.cfc and then index.cfm. </p>
<p> <strong>Application.cfc</strong>
<pre style="border-bottom: #999999 1px dashed; border-left: #999999 1px dashed; padding-bottom: 5px; line-height: 14px; background-color: #eee; padding-left: 5px; width: 100%; padding-right: 5px; font-family: andale mono, lucida console, monaco, fixed, monospace; color: #000000; font-size: 12px; overflow: auto; border-top: #999999 1px dashed; border-right: #999999 1px dashed; padding-top: 5px"><code>component
{
    //Name of the application
    this.name = &quot;ORM_One2Many&quot;;

    //ormenabled should be set to true so that ORM is enabled for this application
    this.ormenabled = &quot;true&quot;;

    //Set the datasource that needs to be used by the ORM Functions.
    this.datasource = &quot;cfartgallery&quot;;
}
</code></pre>
<p><strong>Artists.cfc</strong> </p>
<pre style="border-bottom: #999999 1px dashed; border-left: #999999 1px dashed; padding-bottom: 5px; line-height: 14px; background-color: #eee; padding-left: 5px; width: 100%; padding-right: 5px; font-family: andale mono, lucida console, monaco, fixed, monospace; color: #000000; font-size: 12px; overflow: auto; border-top: #999999 1px dashed; border-right: #999999 1px dashed; padding-top: 5px"><code>component persistent=&quot;true&quot;
{
    property name=&quot;artistid&quot; generator=&quot;increment&quot;;
    property firstname;
    property lastname;
    property address;
    property city;
    property state;
    property postalcode;
    property email;
    property phone;
    property fax;
    property thepassword;

    /*
    Artists have many arts and henace they form a one-to-many relation. The idea is to have all
    the arts as an array of art objects in each Artists' object.

    Set fieldytpe=&quot;one-to-many&quot;.

    Specify CFC=&quot;Art&quot; to convey that the relationship is with Art.cfc.

    fkcolumn=&quot;artistid&quot; to specify the foreign key.  But this is not required if foreignkey constraint
    is defined in the database - ColdFusion-ORM will figure it out by inspecting the database.

    cascade=&quot;all-delete-orphan&quot;: &quot;all&quot; signifies that all the CRUD operations will be cascaded to the
    related objects. &quot;delete-orphan&quot; means that it will delete the orphan objects in the art array
    i.e. if i remove an art from the arts array, it is now an orphan as it has no artist associated
    with it and hence will be automatically deleted.

    Implit Methods:    When a one-to-many relationship is established, the following implicit methods are introduced
    into the artist object:
    void addart(&lt;artobj&gt;) - used to add a art object to the relationship.
    boolean removeart(&lt;artobj&gt;) - used to remove the art object from the relationship.
    boolean hasart() - to check if there are any art objects in the artist object.
    boolean hasart(&lt;artobj&gt;) - to check if the input art object is present in the artist object.

    singularname: Use this attribute to specify custom name to the above implicit methods.

    type=array: To retrieve the arts objects as an array.  If type=&quot;struct&quot;, then the arts objects are retrieved as
    key-value pairs.  structkeycolumn and structkeytype should be specified in addition to all the above attributes
    to retrieve arts as key-value pairs.

    inverse=true: In a bi-directional relationship like this, you should specify one of the side as the controlling side
    which will set the relationship.  Usually, in a one-to-many bi-directional relationship, the many-to-one side should
    be the controlling side.  To do that, set inverse=true on this side (one-to-many side).
    */
    property name=&quot;arts&quot; type=&quot;array&quot; fieldtype=&quot;one-to-many&quot; cfc=&quot;Art&quot; singularname=&quot;art&quot; fkcolumn=&quot;artistid&quot;
    inverse=&quot;true&quot; cascade=&quot;all-delete-orphan&quot;;
}

</code></pre>
<p><strong>Art.cfc</strong> </p>
<pre style="border-bottom: #999999 1px dashed; border-left: #999999 1px dashed; padding-bottom: 5px; line-height: 14px; background-color: #eee; padding-left: 5px; width: 100%; padding-right: 5px; font-family: andale mono, lucida console, monaco, fixed, monospace; color: #000000; font-size: 12px; overflow: auto; border-top: #999999 1px dashed; border-right: #999999 1px dashed; padding-top: 5px"><code>component persistent=&quot;true&quot;
{
    property name=&quot;artid&quot; generator=&quot;increment&quot;;
    property name=&quot;artname&quot;;
    property name=&quot;price&quot;;
    property name=&quot;largeimage&quot;;
    property name=&quot;mediaid&quot;;
    property name=&quot;issold&quot;;  

/*
  Many arts have an artist and hence form a &quot;many-to-one&quot; relation.

  To establish a &quot;many-to-one&quot; relation, set fieldytpe=&quot;many-to-one&quot;

  Specify CFC=&quot;Artists&quot; to convey that the relationship is with Artists.cfc.

  fkcolumn=&quot;artistid&quot;: Used to specify the foreign key.

  missingRowIgnored: If the value is true, and the row that is referenced by the foreign
  key is missing, it is treated as a null association.
*/
    property name=&quot;artist&quot; fieldtype=&quot;many-to-one&quot; fkcolumn=&quot;artistid&quot;
    cfc=&quot;Artists&quot; missingRowIgnored=&quot;true&quot;;
}

</code></pre>
<p><strong>index.cfm</strong> </p>
<pre style="border-bottom: #999999 1px dashed; border-left: #999999 1px dashed; padding-bottom: 5px; line-height: 14px; background-color: #eee; padding-left: 5px; width: 100%; padding-right: 5px; font-family: andale mono, lucida console, monaco, fixed, monospace; color: #000000; font-size: 12px; overflow: auto; border-top: #999999 1px dashed; border-right: #999999 1px dashed; padding-top: 5px"><code>&lt;!---
This example will teach you
- how to establish a One-to-Many relationship between 2 CFCs.
- how to establish a Many-to-One relationship between 2 CFCs.
- how to do CRUD operations with CFCs which have a relationship.
- how to use the implicit relationship methods added by ColdFusion.
- Using cascade in one-to-many to many-to-one relationships.

cfartgallery datasource is used for this application.
---&gt;
&lt;cfscript&gt;
    ormreload();

    /*
        Display the existing records in Artists Table.
        This will display the artist and their arts.
    */
    WriteOutput(&quot;&lt;b&gt;Initial state of the Artists and Art tables&lt;br&gt;&lt;/b&gt;&quot;);
    DisplayArtists();

    /*
        Create an artist object and 2 art objects
    */
    newArtist = new Artists();
    newArtist.setfirstname(&quot;Daniel&quot;);
    newArtist.setlastname(&quot;Richard&quot;);

    newArt1 = new Art();
    newArt1.setArtName(&quot;Champions&quot;);

    newArt2 = new Art();
    newArt2.setArtName(&quot;Isolate&quot;);

    /*
        Associate the Arts to the Artist.  Notice that the
        implicit-relationship method - addArt is called.
    */
    newArtist.addArt(newArt1);
    newartist.addArt(newArt2);

    /*
        The one-to-many relationship should be established from both
        the ends.  Hence set the Artist to the new Arts.
    */
    newArt1.setArtist(newArtist);
    newArt2.setArtist(newArtist);

    /*
        Save the new artist. Note that EntitySave will save the artist as
        well as the associated arts as well (cascade-insert)
    */
    EntitySave(newArtist);
    ormflush();

    /*
        Display the existing records to check whether insert succeeded.
    */
    WriteOutput(&quot;&lt;b&gt;State of the Artists and Art tables after insert.  Notice that the new
                artist - Daniel Richard is added with his arts 'Champions' and 'Isolate'&lt;br&gt;&lt;/b&gt;&quot;);
    DisplayArtists();

    /*
        Remove newArt2 and add newArt3.  In a way, you are just modifying the 'arts' array.  Notice that
        we are using the implicit=relationship method - removeArt is called.
    */
    newArt3 = new Art();
    newArt3.setArtName(&quot;Holiday&quot;);
    newArt3.setArtist(newArtist);
    newArtist.addArt(newArt3);
    newArtist.removeArt(newArt2);
    ormflush();    

    /*
        Check if delete and update of art succeeded.
    */
    WriteOutput(&quot;&lt;b&gt;State of the Artists and Art tables after Deleting/Updating his Arts.  Notice that
                    the art 'Isolate' is removed and the art 'Holiday' is added.&lt;br&gt;&lt;/b&gt;&quot;);
    DisplayArtists();

    /*
        Delete the Artist.  Note that EntityDelete will delete
        the Artist as well as the associated arts. (cascade-delete).
    */
    EntityDelete(newArtist);
    ormflush();

    /*
        Check if delete succeeded.
    */
    WriteOutput(&quot;&lt;b&gt;State of the Artists and Art tables after deleting the Artist.
                Notice that the artist 'Daniel Richard' is deleted.  All his arts are also deleted!&lt;br&gt;&lt;/b&gt;&quot;);
    DisplayArtists();

    /*
        A Utility function to display artists and his arts
    */
    function DisplayArtists()
    {
        query1 = new Query();
        query1.setSQL(&quot;select ArtistID, firstname, lastname from Artists where ArtistID&gt;10&quot;);
        WriteDump(query1.execute().getresult());

        query1.setSQL(&quot;select ArtID, ArtName, ArtistID from Art where ArtID&gt;50&quot;);
        WriteDump(query1.execute().getresult());
    }
&lt;/cfscript&gt;

</code></pre>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:7ee894f4-56b4-4788-bbc5-f5958aa9a097" class="wlWriterEditableSmartContent">del.icio.us Tags: <a href="http://del.icio.us/popular/ColdFusion" rel="tag">ColdFusion</a>,<a href="http://del.icio.us/popular/ORM" rel="tag">ORM</a>,<a href="http://del.icio.us/popular/Adobe" rel="tag">Adobe</a></div>
<!--INFOLINKS_OFF-->]]></content:encoded>
			<wfw:commentRss>http://www.manjukiran.net/2009/07/15/coldfusion-orm-define-one-to-many-and-many-to-one-relationships/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>ColdFusion-ORM: Using CRUD Functions</title>
		<link>http://www.manjukiran.net/2009/07/14/coldfusion-orm-using-crud-functions/</link>
		<comments>http://www.manjukiran.net/2009/07/14/coldfusion-orm-using-crud-functions/#comments</comments>
		<pubDate>Tue, 14 Jul 2009 06:57:14 +0000</pubDate>
		<dc:creator>Manjukiran</dc:creator>
				<category><![CDATA[ColdFusion]]></category>
		<category><![CDATA[ORM]]></category>

		<guid isPermaLink="false">http://www.manjukiran.net/2009/07/14/coldfusion-orm-using-crud-functions/</guid>
		<description><![CDATA[Previous Related Posts:
Getting Started with ORM
First of all, pardon me for posting this example &#8211; I could have easily clubbed these concepts with my first post: Getting Started with ORM.  I promise that in my further posts, I will club more concepts into a single example (but still try to keep it simple).
Task:
Example that [...]]]></description>
			<content:encoded><![CDATA[<!--INFOLINKS_ON--><p><b>Previous Related Posts:</b><br />
<a href="http://www.manjukiran.net/2009/07/14/101/">Getting Started with ORM</a></p>
<p>First of all, pardon me for posting this example &#8211; I could have easily clubbed these concepts with my first post: <a href="http://www.manjukiran.net/2009/07/14/101/">Getting Started with ORM</a>.  I promise that in my further posts, I will club more concepts into a single example (but still try to keep it simple).</p>
<p><b>Task:</b><br />
Example that demonstrates the CRUD Functions in ColdFusion-ORM</p>
<p><b>Stuff that you would learn:</b><br />
- To work with the CRUD Functions &#8211; EntityNew, EntityLoad, EntitySave, EntityDelete<br />
- ormflush() function to force-commit ORM calls<br />
- OrmExecuteQuery function to execute HQL<br />
- Saving the mapping file</p>
<p><b>Steps to Run the example:</b><br />
- This example needs the cfartgallery datasource. This is shipped with ColdFusion by default.<br />
- Create a directory say &#8220;crudorm&#8221; under webroot.<br />
- Create the following files &#8211; Application.cfc, CArtists.cfc and index.cfm.<br />
- Run the URL http://localhost:8500/crudorm/index.cfm</p>
<p>I have interspersed the example with a lot of comments. You can understand the concept by just following the comments starting with Application.cfc and then CArtists.cfc and then index.cfm.</p>
<p><b>Application.cfc</b>
<pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"><code>component
{
    //Name of the application
    this.name = &quot;ORM_CRUDExample&quot;;

    //ormenabled should be set to true so that ORM is enabled for this application
    this.ormenabled = &quot;true&quot;;

    //Set the datasource that needs to be used by the ORM Functions.  You can also set this in the ormsettings struct
    this.datasource = &quot;cfartgallery&quot;;

    /*
    ColdFusion-ORM uses hibernate as its under-lying engine.  ColdFusion-ORM generates
    the hbm.xml file which contains the hibernate mapping.  To save the hibernate mapping
    that is generated, you need to set savemapping flag to true.  In this case, CArtists.hbm.xml
    file will be generated in the same folder as that of the application.
    */
    this.ormsettings.savemapping="true";
}
</code></pre>
<p><b>CArtists.cfc</b><br />
(I have not added any comments to this file.  If you need to learn about the different attributes used here, refer the example <a href="http://www.manjukiran.net/2009/07/14/101/">Getting Started with ORM</a>)</p>
<pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"><code>component persistent=&quot;true&quot; entityname=&quot;Artists&quot; table=&quot;Artists&quot;
{
    property name=&quot;id&quot; column=&quot;ARTISTID&quot; generator=&quot;increment&quot;;
    property name=&quot;firstname&quot;;
    property name=&quot;lastname&quot;;
    property name=&quot;address&quot;;
    property name=&quot;city&quot;;
    property name=&quot;state&quot;;
    property name=&quot;postalcode&quot;;
    property name=&quot;email&quot;;
    property name=&quot;phone&quot;;
    property name=&quot;fax&quot;;
    property name=&quot;thepassword&quot;;
}

</code></pre>
<p><b>index.cfm</b>
<pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"><code>&lt;!---
This example will teach you
- how to do CRUD operations on this table using the Entity* functions.
- ormflush function.
- how to use ORMExecuteQuery function.
- Saving the mapping file

cfartgallery datasource is used for this application.
Artists table is one of the table in cfartgallery which contains a list of
artists records.  This table is used in this example.
---&gt;

&lt;cfscript&gt;
    ormreload();
    /*
    Load the Artist records to display them.  There are a number of
    variations to the EntityLoad method which will help you to retrieve
    the records the way you want. Refer the documentation for EntityLoad for details.
    */
    WriteOutput(&quot;&lt;b&gt;Initial state of the table&lt;br /&gt;&lt;/b&gt;&quot;);
    DisplayArtists(EntityLoad(&quot;Artists&quot;));

    /*
    Create a new Artist object and set the properties. This will
    be inserted to the table in the next step.
    EntityNew function takes entityname as input and creates a
    fresh object of the entity.
    */
    newArtistObj = EntityNew(&quot;Artists&quot;);
    newArtistObj.setfirstname(&quot;John&quot;);
    newArtistObj.setlastname(&quot;Smith&quot;);
    newArtistObj.setaddress(&quot;5 Newport lane&quot;);
    newArtistObj.setcity(&quot;San Francisco&quot;);
    newArtistObj.setstate(&quot;CA&quot;);
    newArtistObj.setPostalCode(&quot;90012&quot;);
    newArtistObj.setphone(&quot;612-832-2343&quot;);
    newArtistObj.setfax(&quot;612-832-2344&quot;);
    newArtistObj.setemail(&quot;jsmith@company.com&quot;);
    newArtistObj.setThePassword(&quot;jsmith&quot;);

    /*
    Insert the new artist object that you just created.
    EntitySave will insert the newArtistObj into the database.
    EntitySave is used for both update and insert.  ColdFusion
    will smartly figure out whether it is an update or insert.  As we are
    sure that this is an insert operation, we set the secondparameter to &quot;true&quot;.
    ColdFusion now will always do the insert operation.
    */
    EntitySave(newArtistObj, true);

    /*
    Call ormflush so that the Insert SQL runs immediately. If ormflush
    is not called, all the CRUD operations in this page will be flushed at
    the end of the request.
    */
    ormflush();

    /*
     Display the artist records now to check if the new record got added.
     This time I have used a different function to retrieve the Artist records.
     This is just to introduce you to the ORMExecuteQuery set of functions.
     ORMExecuteQuery takes HQL as input and returns one-entity/array-of-entities/
     string/array-of-strings depending on the HQL.  HQL is the query language used
     in hibernate to retrieve objects based on complex joins.  This function has
     a number of overloads.  Please refer the documentation for more details.
    */
     WriteOutput(&quot;&lt;b&gt;After adding the new record (Notice the Record with FirstName John being added)&lt;br /&gt;&lt;/b&gt;&quot;);
     DisplayArtists(ORMExecuteQuery(&quot;from Artists&quot;));

    /*
    Update the new Artist record.  Change the Phone number.
    You dont need to call EntitySave method here as the newArtistObj is
    an entity maintained by ORM.  Hence the updates to this entity will be automatically committed.
    */
    newArtistObj.setphone(&quot;612-832-1111&quot;);
    ormflush();

    /*
    Display the Artist records now to check if the new record got updated.
    */
    WriteOutput(&quot;&lt;b&gt;After updating the new record (Notice the phone number with FirstName John updated)&lt;br /&gt;&lt;/b&gt;&quot;);
    DisplayArtists(ORMExecuteQuery(&quot;from Artists&quot;));

    /*
    Delete the record.  Also call ormflush so that the Delete SQL gets run immediately
    */
    EntityDelete(newArtistObj);
    ormflush();

    /*
    Display the Artist records now to check if the new record that was added, got deleted
    */
    WriteOutput(&quot;&lt;b&gt;After deleting the new record (Notice the Record with FirstName John deleted)&lt;br /&gt;&lt;/b&gt;&quot;);
    DisplayArtists(ORMExecuteQuery(&quot;from Artists&quot;));
&lt;/cfscript&gt;

&lt;!---A simple function to display the artist records in a table---&gt;
&lt;cffunction name=&quot;DisplayArtists&quot;&gt;
&lt;cfargument name=&quot;artistArr&quot;&gt;
    &lt;cfoutput&gt;
        &lt;table border=&quot;1&quot;&gt;
        &lt;tr&gt;
            &lt;td&gt;ID&lt;/td&gt;
            &lt;td&gt;NAME&lt;/td&gt;
            &lt;td&gt;ADDRESS&lt;/td&gt;
            &lt;td&gt;PHONE&lt;/td&gt;
            &lt;td&gt;FAX&lt;/td&gt;
            &lt;td&gt;EMAIL&lt;/td&gt;
        &lt;/tr&gt;
        &lt;cfloop array=&quot;#artistArr#&quot; index=&quot;artistsObj&quot;&gt;
        &lt;tr&gt;
            &lt;td&gt;#artistsObj.getid()#&lt;/td&gt;
            &lt;td&gt;#artistsObj.getfirstname()# #artistsObj.getlastname()#&lt;/td&gt;
            &lt;td&gt;#artistsObj.getaddress()# #artistsObj.getCity()# #artistsObj.getState()# #artistsObj.getPostalCode()#&lt;/td&gt;
            &lt;td&gt;#artistsObj.getphone()#&lt;/td&gt;
            &lt;td&gt;#artistsObj.getFax()#&lt;/td&gt;
            &lt;td&gt;#artistsObj.getemail()#&lt;/td&gt;
        &lt;/tr&gt;
        &lt;/cfloop&gt;
        &lt;/table&gt;
    &lt;/cfoutput&gt;
&lt;/cffunction&gt;

</code></pre>
<!--INFOLINKS_OFF-->]]></content:encoded>
			<wfw:commentRss>http://www.manjukiran.net/2009/07/14/coldfusion-orm-using-crud-functions/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Getting Started with ColdFusion-ORM</title>
		<link>http://www.manjukiran.net/2009/07/14/101/</link>
		<comments>http://www.manjukiran.net/2009/07/14/101/#comments</comments>
		<pubDate>Mon, 13 Jul 2009 19:46:58 +0000</pubDate>
		<dc:creator>Manjukiran</dc:creator>
				<category><![CDATA[ColdFusion]]></category>
		<category><![CDATA[ORM]]></category>

		<guid isPermaLink="false">http://www.manjukiran.net/2009/07/14/101/</guid>
		<description><![CDATA[ColdFusion-ORM is the one of the top features in ColdFusion 9.  This feature is close to my heart as I have worked on it the whole release right from its inception &#8211; specification, design, development and testing &#8211; most of the time involved in testing it.  Believe it or not, I have written [...]]]></description>
			<content:encoded><![CDATA[<!--INFOLINKS_ON--><p>ColdFusion-ORM is the one of the top features in ColdFusion 9.  This feature is close to my heart as I have worked on it the whole release right from its inception &#8211; specification, design, development and testing &#8211; most of the time involved in testing it.  Believe it or not, I have written more than 500 test cases for ORM which include 2000+ CFM/CFC files.  I am making an effort to help the community to get started on this feature by posting a series of examples that would introduce you to ColdFusion-ORM.  The documentation does cover the ColdFusion-ORM stuff in good detail.  But I believe in the &#8220;Learn as you code&#8221; approach.  I will post a series of examples &#8211; each example would introduce a new concept in ColdFusion-ORM.  I hope you would like this approach. and as you read the posts, do provide me with timely feedback so that I can mend my further examples as appropriate.</p>
<p><b>Task:</b><br />
Basic ColdFusion-ORM Example</p>
<p><b>Stuff that you would learn:</b><br />
To Configure ORM for a ColdFusion application.<br />
Configuring a datasource to be used by ORM.<br />
Mapping a table to a CFC.<br />
Using the EntityLoad method and iterating over the resultset.<br />
To Log the SQLs generated by ORM to the ColdFusion console.</p>
<p><b>Steps to Run the example:</b><br />
- This example needs the cfartgallery.  This is shipped with ColdFusion by default.<br />
- Create a directory say &#8220;basicorm&#8221; under webroot.<br />
- Create the following files &#8211; Application.cfc, Artists.cfc and index.cfm.<br />
- Run the URL http://localhost:8500/basicorm/index.cfm</p>
<p>I have interspersed the example with a lot of comments.  You can understand the concept by just following the comments starting with Application.cfc and then Artists.cfc and then index.cfm.</p>
<p><b>Application.cfc</b>
<pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"><code>/*
You always need a Application.cfc to work with ORM.  You
need to set ormenabled to true for the application to use ORM.
Note that ORM Configuration and mapping is generated and loaded
when the aplication starts.
*/
component
{
    //Name of the application
    this.name = &quot;ORM_BasicExample&quot;;

    //ormenabled should be set to true so that ORM is enabled for this application
    this.ormenabled = &quot;true&quot;;

    //Set the datasource that needs to be used by the ORM Functions.  You can also set this in the ormsettings struct
    this.datasource = &quot;cfartgallery&quot;;

    //Set logSQL to true.  This will log SQLs to the console.
    this.ormsettings.logSQL = &quot;true&quot;;
}
</code></pre>
<p><b>Artists.cfc</b>
<pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"><code>/*
FileName: Artists.cfc
Usually one CFC maps to one table. In this case, the CFC Artists.cfc maps to the table Artists. 

Persistent attribute should be set to true for cfcomponent so that ColdFusion knows
that mapping needs to generated for this CFC. 

If the name of the component is not the same as that of the table, specify the table
name. 

EntityName should be specified for the CFC which will be used by the Entity* functions
to do CRUD operations on this CFC. If EntityName is not specified, then, the name of
the component is taken as the entityname.
*/ 

component persistent=&quot;true&quot; entityname=&quot;Artists&quot; table=&quot;Artists&quot;
{ 

/*Usually one property corresponds to one column in the table. In this case, the property
&quot;firstname&quot; corresponds to the column FIRSTNAME in the Employees table.
*/
property name=&quot;firstname&quot;; 

/*
fieldtype=&quot;id&quot; denotes that the property &quot;id&quot; is the primary key of the table Art.
ColdFusion will figure it out by inspecting the database if not specified. 

column attribute is used to define the name of the field in the table to which this
property maps to. If the column attribute is not specified, then, the name of the
property is taken as the name of the field. 

Generator attribute is used to auto-generate the primarykey when a new record is added.
Here we use increment generator. To know more about generators, refer ColdFusion ORM documentation.
*/
property name=&quot;id&quot; column=&quot;ARTISTID&quot; generator=&quot;increment&quot;; 

/*
Few other properties which map to the appropriate columns in the Employees table
*/
property name=&quot;lastname&quot;;
property name=&quot;address&quot;;
property name=&quot;city&quot;;
property name=&quot;state&quot;;
property name=&quot;postalcode&quot;;
property name=&quot;email&quot;;
property name=&quot;phone&quot;;
property name=&quot;fax&quot;;
property name=&quot;thepassword&quot;; 

} 

</code></pre>
<p><b>index.cfm</b>
<pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"><code>&lt;!---
FileName: index.cfm
This is the most basic example in this kit. This example will teach you
- how to map a table to a CFC
- how to Retrieve records using the EntityLoad function.

cfartgallery datasource is used for this application.
Artists table is one of the table in cfartgallery which contains a list of
artists records.  This table is used in this example.
---&gt;

&lt;cfscript&gt;
   /*
      Call ormreload() function so that ORM configuration/mapping is always created afresh
      when index.cfm is called.  This is convenirent to have in development time.  You shouldn't
      do this in production
   */
   ormreload();

    /*
     Load the Artist records to display them.  There are a number of
     variations to the EntityLoad method which will help you to retrieve
     the records the way you want. Refer the documentation for EntityLoad for details.
   */
   artists = EntityLoad(&quot;Artists&quot;);

    /*
     Display the Artist records that you just loaded
    */
    for (i=1;i&lt;ArrayLen(artists);i++)
    {
        artistObj = artists[i];
        WriteOutput(&quot;&lt;b&gt;&quot; &amp; artistObj.getFirstName() &amp; &quot; &quot; &amp; artistObj.getLastName() &amp; &quot;&lt;br&gt;&lt;/b&gt;&quot;);
        WriteOutput(&quot;Address: &quot; &amp; artistObj.getAddress() &amp; &quot; &quot; &amp; artistObj.getCity() &amp; &quot; &quot; &amp;
                    artistObj.getState() &amp; &quot; &quot; &amp; artistObj.getPostalCode() &amp; &quot;&lt;br&gt;&quot;);
        WriteOutput(&quot;Ph: &quot; &amp; artistObj.getPhone() &amp; &quot;&lt;br&gt;&quot;);
        WriteOutput(&quot;Fax: &quot; &amp; artistObj.getFax() &amp; &quot;&lt;br&gt;&quot;);
        WriteOutput(&quot;EMail: &quot; &amp; artistObj.getEmail() &amp; &quot;&lt;br&gt;&quot;);
        WriteOutput(&quot;&lt;br&gt;&quot;);
    }
&lt;/cfscript&gt;

</code></pre>
<!--INFOLINKS_OFF-->]]></content:encoded>
			<wfw:commentRss>http://www.manjukiran.net/2009/07/14/101/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
	</channel>
</rss>
