adobe photoshop elements newsgram february download Adobe Contribute CS4 adobe photoshop download 7.0 adobe creative suite 2 book download Adobe Creative Suite 5 Master Collection for Mac adobe tech support dreamweaver adobe photoshop cs start up download Adobe Dreamweaver CS5 adobe creative suite cs3 adobe photoshop site licence download Adobe Photoshop CS5 buy adobe photoshop cs upgrade adobe photoshop full torrent download Adobe Dreamweaver CS4 for Mac adobe creative suite 3 and buy adobe photoshop 7 0 software download Adobe Dreamweaver CS3 adobe photoshop elements key serial number adobe photoshop cs 8.0 download Adobe Creative Suite 4 Web Premium for Mac color profile photoshop adobe rgb adobe photoshop brush downloads download Adobe Creative Suite 4 Web Standard for Mac crack adobe creative suite cs adobe creative suite registration crack download Adobe Creative Suite 4 Production Premium for Mac adobe photoshop activation authorization code free download adobe photoshop image ready download Adobe Creative Suite 4 Production Premium adobe photoshop cs3 system requirements adobe photoshop 6.0 price download Adobe Creative Suite 4 Design Standard for Mac adobe creative cs2 edition premium suite try adobe contribute 4 download Adobe Creative Suite 4 Design Premium for Mac adobe photoshop template swish frames full adobe creative suite download download Adobe Creative Suite 4 Design Premium adobe photoshop helpline bypass adobe photoshop elemensts 3.0 download Adobe Creative Suite 3 Web Premium adobe photoshop and image ready upgrade adobe photoshop elements download Adobe Creative Suite 3 Design Premium adobe photoshop cs3 serial numbers

Getting Started with ColdFusion-ORM


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 – specification, design, development and testing – 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 “Learn as you code” approach. I will post a series of examples – 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.

Task:
Basic ColdFusion-ORM Example

Stuff that you would learn:
To Configure ORM for a ColdFusion application.
Configuring a datasource to be used by ORM.
Mapping a table to a CFC.
Using the EntityLoad method and iterating over the resultset.
To Log the SQLs generated by ORM to the ColdFusion console.

Steps to Run the example:
- This example needs the cfartgallery. This is shipped with ColdFusion by default.
- Create a directory say “basicorm” under webroot.
- Create the following files – Application.cfc, Artists.cfc and index.cfm.
- Run the URL http://localhost:8500/basicorm/index.cfm

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.

Application.cfc

/*
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 = "ORM_BasicExample";

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

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

    //Set logSQL to true.  This will log SQLs to the console.
    this.ormsettings.logSQL = "true";
}

Artists.cfc

/*
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="true" entityname="Artists" table="Artists"
{ 

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

/*
fieldtype="id" denotes that the property "id" 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="id" column="ARTISTID" generator="increment"; 

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

} 

index.cfm

<!---
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.
--->

<cfscript>
   /*
      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("Artists");

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





Comments



1
Author:  Brian FitzGerald | Date:  July 14, 2009 | Time:  7:46 PM

Very helpful, thank you. I am looking forward to more. One thing in particular I’m wondering about is how easy is it to add additional methods to the object returned from hibernate… in other words, if I simply add another specialized method into Artists.cfc, will it automatically be available in every object of the result set?

Thanks!
Brian

2
Author:  Manjukiran | Date:  July 14, 2009 | Time:  8:28 PM

Hi Brian, the entities (objects) that are returned from Hibernate are indeed CFC-objects. They would contain all the methods that you add to the CFC (here Artists.cfc).

3
Author:  simon | Date:  July 21, 2009 | Time:  2:33 PM

will be nice to have an example with complex object like in adobe site, including the arts… Im looking for a cfc function with remote access to past a complexe object (from Flex) and CREATE it in one call:

ie Artist(name:simon, surname:toto, arts[painting, carving]).save

4
Author:  Leigh | Date:  July 21, 2009 | Time:  9:04 PM

Silly question, but what does “This will log SQLs to the console” mean in ColdFusion terms? Does that just mean sql statements will be written to the server logs, like a System.out.println() statement ?

-Leigh

5
Author:  Manjukiran | Date:  July 21, 2009 | Time:  10:20 PM

@simon, saving a complex object in one shot should be straight-forward. Once the object is in ColdFusion, you can save it by just calling EntitySave. Refer to this post – ColdFusion-ORM: Define One-to-Many and Many-to-one relationships for more information.

6
Author:  Manjukiran | Date:  July 21, 2009 | Time:  10:23 PM

@Leigh, if you start ColdFusion from command-line, the SQLs will be printed on the console. If you use JRun Server, then you start ColdFusion in command line using the command “jrun start coldfusion”.

7
Author:  Raghuram Reddy | Date:  November 24, 2009 | Time:  1:03 PM

Manju!!

I have a question here.
My project will not allow me to make change in application.cfc/cfm as it will impact whole appliction.
Any idea to make ORM implementation specific to the existing module.
You may say use local application.cfc.
But iam looking for ORM config related code(like this.ormenabled = “true”;) in other than application.cfc/cfm file.

Thanks,
Raghuram Reddy Gottimukkula
Adobe Certified Coldfusion Professional
Bangalroe

8
Author:  Manjukiran | Date:  November 24, 2009 | Time:  10:46 PM

Raghu, right now, there is no way you can do this. Only if orm is enabled in Application.cfc that the ORM configuration is built. Do file an enhancement – we will check if there is any work-around or support that we can provide to solve this problem.

9
Author:  Bill Brutzman | Date:  March 26, 2010 | Time:  2:37 AM

Good job Mr. Manju. I tried demo’s from a few other posts that left out some important details… leading to their apps not working.

This one works… and thus is a big help to us newbies.

10
Author:  Manjukiran | Date:  April 1, 2010 | Time:  11:31 AM

Thanks Bill. Nice to hear that it helped you.



Write a Comment

Note: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>