Top Banner
ht 2009 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. ColdFusion 9 : ORM Rupesh Kumar Sr. Computer Scientist
21
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: ColdFusion 9 ORM

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

ColdFusion 9 : ORM

Rupesh Kumar

Sr. Computer Scientist

Page 2: ColdFusion 9 ORM

®

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

Page 3: ColdFusion 9 ORM

®

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

Page 4: ColdFusion 9 ORM

®

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.

Page 5: ColdFusion 9 ORM

®

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">

Page 6: ColdFusion 9 ORM

®

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

Page 7: ColdFusion 9 ORM

®

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”

Page 8: ColdFusion 9 ORM

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

Basic Demo

Page 9: ColdFusion 9 ORM

®

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

ORM CRUD Functions

EntityNew()

EntityLoad()

EntitySave()

EntityDelete()

EntityLoadByExample()

EntityLoadByPK()

Page 10: ColdFusion 9 ORM

®

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

Relationship Mapping

One-To-One

One-To-Many

Many-To-One

Many-To-Many

Page 11: ColdFusion 9 ORM

®

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>

Page 12: ColdFusion 9 ORM

®

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

Embedded Mapping

Simulate sub objects without creating multiple tables

Page 13: ColdFusion 9 ORM

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

ColdFusion 9’s ORM Not so Basics

Page 14: ColdFusion 9 ORM

®

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

Page 15: ColdFusion 9 ORM

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

Important Concepts

Page 16: ColdFusion 9 ORM

®

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

CFQuery is alive and well

Multiple datasource per application

Reporting

Preference

Page 17: ColdFusion 9 ORM

®

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

Why so many options?

Objects and tables don’t line up

Page 18: ColdFusion 9 ORM

®

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

Page 19: ColdFusion 9 ORM

®

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

Page 20: ColdFusion 9 ORM

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

Any Questions?

Terry [email protected]

http://terrenceryan.com

Page 21: ColdFusion 9 ORM

®

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