adobe photo shop font download

cs5 web premium cheapest adobe photoshop 7 free download adobe photoshop cs3 v10 download for windows buy cheap download adobe acrobat pdf writer free download for adobe distiller pc

adobe reader download mac osx

cheap adobe photoshop adobe after effects download adobe reader tar gz download buy cheap find free adobe download adobe 8 download

adobe download interuption

photoshop elements buy cheap download adobe reader version 5 download adobe acrobat 9 cheap internet explorer crashes upon adobe download free adobe acrobat software download

download adobe photoshop cs3 rapidshare

buy cheap adobe dreamweaver adobe acrobat 8 update download adobe photoshop cs3 iso file download cheap free adobe 8 download adobe fine reader free download

adobe flash video exporter download

adobe fireworks cheap adobe pagemaker download full free adobe acrobat 7 pro download buy cheap adobe illustrator cs 2 download for windows adobe illustrator crack download

download adobe documents

buy cheap creative suite 4 adobe master collection torrent download where to download adobe acrobat buy cheap adobe photoshop album download free download adobe illustrator cs3 mac

free adobe photoshop software download

Adobe Creative Suite 5.5 buy cheap how do i download adobe reader for free adobe version 5 download cheap download madden 2005 strategy guides to adobe reader for safe and secure free adobe flash download

unable to download adobe acrobat reader

Adobe Flash CS5.5/a> download adobe illustrator cs download adobe acrobat megaupload cheapest freeware adobe acrobat download free software download adobe reader

adobe live motion download

buy cheap Adobe After Effects CS5.5 free safe download of adobe acrobat reader download free adobe acrobat cheapest download a older version of flash player adobe free to download adobe illustrator

adobe photoshop cs 3 download

adobe software cheap download adobe acrobat reader free adobe reader slowenian download cheapest adobe acrobat 6 full download adobe acrobat 6 pro download

free trial download adobe photoshop mac

creative suite 5 cheapest download record adobe flash movie adobe patch download cheapest internet explorer crashes upon adobe download adobe flashplayer active x download

get free download of adobe flash cs3

buy online adobe incopy adobe photoshop download discount software download adobe 9 free cheap acrobat reader adobe download download the adobe photoshop cs2 book for digital photographers

adobe reader kostenloser download

adobe creative suite 5 cheap adobe 7 free download adobe premiere download cheapest adobe acrobat download vista where to download adobe acrobat

download trial version of adobe acrobat 8 professional

cheap photoshop lightroom 3 download stand alone adobe flash adobe flash palyer download cheap adobe acrobat viewer download free adobe professional download

adobe download

buy online cs5 master collection free download adobe acrobat reader professional 6 cracked adobe indesign cs2 mac download cheap adobe pdf printer download download adobe premiere pro cs3

free adobe acrobat writer download

buy online adobe premiere pro adobe cs3 patch download free adobe flshplayer 9 download buy online free adobe premiere download adobe acrobat pdf writer download

adobe illustrator and download

adobe web premium buy online download free edition adobe photoshop instructions on how to download documents on to adobe reader buy online adobe illustrator cs download adobe flash player downloader free download hunter grabber

ColdFusion-ORM: Define Computed properties (formula attribute)


What are computed properties?
Consider the tables – Art and Artists.  Art and Artists form a one-to-many relationship where one Artist has created many Art.  Say, in each Artist object, you need a property that would contain the number of arts made by the Artist – use computed properties.  The formula to compute the value of the property should be specified using the formula attribute of the cfproperty tag.  The formula should be specified as a SQL that returns a single value.  Note that computed properties do not map to any column in the table and are not persistent.

Task:
Example to demonstrate using computed properties 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

Stuff that you would learn:
- how to define computed properties
- how to define the formula for computed properties

Steps to Run the example:
-  This example needs the cfartgallery datasource. This is shipped with ColdFusion by default.
-  Create a directory say "ormformula" under webroot.
-  Create the following files – Application.cfc, Artists.cfc and index.cfm.
-  Run the URL “http://<ip>:<port>/ormformula/index.cfm”

Application.cfc

component
{
    //Name of the application
    this.name = "ORM_Formula";

    //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";
}

Artists.cfc

component persistent="true" entityname="Artists" table="Artists"
{
    property name="id" column="ARTISTID" generator="increment";
    property name="firstname";
    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";
    /*
        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 "numberOfArts" 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="numberOfArts" formula="select Count(*) from Art art where art.ArtistId=ArtistId";
}

index.cfm

<!---
This example will teach you
- how to define computed properties
- how to define the formula for computed properties
--->

<cfset ormreload()>

<cfset artists = EntityLoad("Artists")>

<cfloop array="#artists#" index="artist">
    <cfoutput>
        #artist.getFirstName()# #artist.getLastName()# has <b>#artist.getNumberOfArts()#</b> arts<br>
    </cfoutput>
</cfloop>




Comments



1
Author:  John Whish | Date:  July 24, 2009 | Time:  3:40 PM

Interesting. If I’m right, essentially this is shorthand for doing,

/**
* I return the number of items sold for this artist
* @output false
*/
public numeric function getNumberOfArts()
{
return ORMExecuteQuery(
“select Count(*) from Art art where art.ArtistId=:ArtistID”,
{ ArtistID=this.getArtistID() }
, True );
}

Can you do more complex formulas for example:

property name=”numberOfSoldArts”
formula=”select Count(*) from Art art where art.ArtistId=ArtistId and art.IsSold=True”;

2
Author:  Manjukiran | Date:  July 24, 2009 | Time:  3:51 PM

Yes, John – you can have complex formulas like the one above.

3
Author:  Tom Chiverton | Date:  August 18, 2009 | Time:  5:37 PM

Cool. I assume when it runs the sql snippit it is a nice parametrised non-sql injecting query ?

4
Author:  Manjukiran | Date:  August 20, 2009 | Time:  1:38 PM

Tom, the SQL that gets generated is a parameterised query. But, even otherwise, I do not see any scope for injecting SQL as the SQL is just available in the metadata.

5
Author:  Raymond Camden | Date:  November 21, 2009 | Time:  10:19 PM

Query – this seems to work ok, but I notice that when I have no data in the related table, I get back an empty string. Shouldn’t the count always return 0?

6
Author:  Raymond Camden | Date:  November 21, 2009 | Time:  10:36 PM

Ok, something wonky is up. I added data so I should get 1 back, but I’m getting an empty string back. I checked my HQL logging and no db call is being made.

7
Author:  Raymond Camden | Date:  November 21, 2009 | Time:  10:55 PM

Forgive me – stupid mistake on my part. I forgot to refresh ORM for the application.



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>