21
ht 2009 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. ColdFusion 9 : ORM Rupesh Kumar Sr. Computer Scientist

ColdFusion 9 ORM

Embed Size (px)

Citation preview

Copyright 2009 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.

ColdFusion 9 : ORM

Rupesh Kumar

Sr. Computer Scientist

®

Copyright 2009 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.

Agenda

What is ORM?

Why do you want it?

Configuration

Basic CRUD

Relationship

Q & A

®

Copyright 2009 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.

What is ORM?

Object-relational mapping

A persistence framework to map objects to the relational database without writing SQL.

A programming technique for converting data between incompatible type systems in relational databases and object-oriented programming languages.

ColdFusion ORM – based on Hibernate One of the most mature and popular persistence framework

®

Copyright 2009 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.

Why do you want it?

Write less code – easy to maintain Easy to write

Focus on the business logic

Persistence taken care by the framework

Application much cleaner and better encapsulation

No repetitive and error prone SQL queries

Database vendor independence

Flexible to changes in the table/column names

Built in concurrency, caching and other optimizations.

®

Copyright 2009 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.

Configuration

All configuration done in application.cfc

Set up the datasource

Enable ORM in the application.cfc Lots of configuration using ormsettings

Sample Application.cfc

<cfset this.name = "ArtGalleryApp"> <cfset this.ormenabled = "true"><cfset this.datasource = "cfartgallery">

®

Copyright 2009 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.

Configuration…

Write your Object definition Persistent CFC using persistent=“true”

Field using cfproperty

Map your components CFC Tables

Cfproperty Columns

Mapping using CFC metadata

Mapping using hibernate mapping files

®

Copyright 2009 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.

Persistent CFC

lot of attributes on CFC and cfproperty added for orm metadata

Attributes can also be specified using cfscript annotation

Work with the objects and its data will be persisted using ORM methods.

Use persistent=“true”

Copyright 2009 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.

Basic Demo

®

Copyright 2009 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.

ORM CRUD Functions

EntityNew()

EntityLoad()

EntitySave()

EntityDelete()

EntityLoadByExample()

EntityLoadByPK()

®

Copyright 2009 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.

Relationship Mapping

One-To-One

One-To-Many

Many-To-One

Many-To-Many

®

Copyright 2009 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.

Many-to-One

<cfcomponent persistent="true” ><cfproperty name=”name" column="employeeID" fieldtype="id" /><cfproperty name=”name" column=”name" /><cfproperty name="department" fieldtype="many-to-one" cfc="department" />

</cfcomponent>

®

Copyright 2009 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.

Embedded Mapping

Simulate sub objects without creating multiple tables

Copyright 2009 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.

ColdFusion 9’s ORM Not so Basics

®

Copyright 2009 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.

Advanced Topics

Covered in later session

More on Relationships

More on Mappings

HQL

Event Handling

Transactions

Caching

Hibernate Access ORM Session Management

Config files

Copyright 2009 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.

Important Concepts

®

Copyright 2009 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.

CFQuery is alive and well

Multiple datasource per application

Reporting

Preference

®

Copyright 2009 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.

Why so many options?

Objects and tables don’t line up

®

Copyright 2009 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.

RAD Workflow

Bolt to generate ORM code

Modify ORM to meet your needs Display functions

Business Logic

Write your front end ColdFusion created HTML

ColdFusion UI components

Flex front End

®

Copyright 2009 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.

Agenda – ORM II

Advanced Mappings

What happens internally

Transaction & concurrency control

Caching & optimization

Logging & Event Handling

Auto-generation of tables

Q & A

Copyright 2009 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.

Any Questions?

Terry [email protected]

http://terrenceryan.com

®

Copyright 2009 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.