SlideShare a Scribd company logo
1 of 51
Download to read offline
Slaying the ORM Dragons
with CBORM
WHO AM I?
• Luis Majano - Computer Engineer
• Imported from El Salvador----------->
• Architecture + Software Design
• CEO of Ortus Solutions
• Adobe Community Professional
• Creator of all things Box: 

ColdBox, ContentBox,
CommandBox,WireBox….
AGENDA
• ORM FirstThoughts
• Is ORM a Silver Bullet?
• Visit from a Special Guest
• Specialized ORM Services
ORMThoughts?
CF ORM was
easier to use?
OO way to
query
ORM was fast
80% of API
Querying
Extensible
way to finish
the remaining
20%
When is
HappyBox?
Auto build
relationships
CONCLUSIONS
• Can’t or doesn’t exist
• Sounds like bull…..
• What’s this latino up to?
• Is he trying to get my money
PROVE IT!
ORM is NOT a silver bullet
• Just another tool
• Times you need the power of the database: reports, legacy, sp, etc.
• Mix and match
• What if you wanted array of structs, or lists or queries or arrays of data?
• There is a learning curve, but it is worth the investment
Applied Benefits
• Increase in productivity of about 40%
• Rich Object Models
• Deliver DB patching updates
• Increased Flexibility
• Great for abstracting vendor specific
intricacies
• OO Queries
• Avg JDBC <10ms of about 350K
Transactions
How do we start?
coldfusionormbook.com amazon
Guru ORMLui
10 keys to ORM Success!
#1: OO Modeling is Key
• ORM relationship modeling is key
• OO is required
• UML is your best friend
• STOPTHINKING ABOUT DATA
• YOU ARE NOT MODELING A DATABASE
#1: OO Modeling is Key
#1: OO Modeling is Key
Query Object
Data Data + Behavior
#2: Bad Engine Defaults
Do not use engine defaults:
Control Data Flushing +Transaction Borders:


ormsettings.flushAtRequestEnd=false
ormsettings.autoManageSession=false
Control Database Dialects (If Possible)
ormsettings.dialect=“MySQLwithInnoDB”
#2: Bad Engine Defaults
• this.ormsettings.cfclocation
• Use it to a specified directory, else pay the price of discovery
• this.ormsettings.logSQL=true
• Great for debugging, false for production, else pay the price
• Having Issues?
• Hibernate MXML: this.ormsettings.saveMapping=true
• DataBoss - ortussolutions.com/products/databoss
#3: Understand Hibernate Session
• Not the same as session scope
• A transitionary space + Caching Layer
• entityLoad()
• entityNew() ?
• You need to control when to send to DB
• transaction{}, ormflush()
• You can remove entities from it and clear it
• ORMClearSession()
• ORMEvictEntity(), ORMEvictCollection()
• ORMCloseSession()
#3: Understand Hibernate Session
Hibernate Session 

(Conversation - Request)
DB
Eu
Ex EzEy
Cache
ehCache/
Couchbase
Batched SQL
EntityNew()
EntityLoad()
Data (!CFCs)
Hibernate Session
Factory (application)
CRUD
When?
ORMClearSession()
#3: Understand Hibernate Session
DB	Sync
Insertions	in	order
updates
Collection	deletions
collection	deletion,	updates,	inserts
collection	insertions
deletions	in	order
#4:Transaction Demarcation
• Transactions demarcate SQL boundaries
• Important Imperative for ORM + SQL
• No communication to DB should occur without one
• Reactive programming, expect the worst
• cftransaction or Hibernate transactions
#4:Transaction Demarcation
• Transaction Theory:
• Any existing ORM session is flushed and reused
• Data can be committed or rollback
• ORMFlush() is ignored in transactions
• If commit, then flushed to database
• If rollback, session is cleared
#5 Lazyness
• Immediate Fetching (Default)
• select with left outer join

poor, poor, poor, poor performance
• Use lazy For ALL Relationships or pay the price
• Three types of laziness:
• lazy=“true”
• all relationships
• Loads all the relationship data when called upon (Batch sizes if used)
• lazy=“extra”
• one-to-many, many-to-many
• Loads proxies with primary keys (Event better - Batch sizes if used)
• lazy=“proxy”
• one-to-one, many-to-one
• Loads proxy with primary key
• Eager Fetching
• Mostly used in one-to-one and many-to-one, but applies to all
• Default uses 2 SQL queries, reduce to 1 Query
• property name=“role” fieldtype=“many-to-one” fetch=“join”;
• Batch Fetching
• Limits the way relationships are loaded, else Hibernate tries to load all records
• Used on many-to-many and one-to-many collection properties:
• property name=“comments” fieldtype=“one-to-many” batchsize=“10” lazy=“extra”;
• Used at entity level as well:
• component name=“Comment” batchsize=10{}
#5 Lazyness
Oracle Tip
• JDBC Fetch Sizes are defaulted to 10
• Slow for many records or batch operations
• Increase the JDBC Fetch size
• Custom Hibernate setting
• hibernate.jdbc.fetch_size=100
#5 Lazyness
#6:Avoid bi-directional
• They can be more of a headache
• Cascading Deletes
• Choose the master relationship
• inverse=true
• Else double queries
• Does it make sense?
• Supporting methods for bi-directional linkage
• Supporting methods for un-linkages
#6:Avoid bi-directional
#6:Avoid bi-directional
#7: Do not store entities in scopes
• Don’t do it!
• No linkage to Hibernate Session
• Relationships will fail if not lazy
• entityMerge()
• Store ID’s instead
#8: Use DB Indexes
• #1 Performance Problem
• Identify relationships
• Identify HQL, SQL
• property name=“isActive” index=“idxActive”
#9: Cache = BOOST!
• Don’t go cache crazy
• Develop a strategy
• Does not store CFC, stores individual property values
• Use distributed caches: ehcache, couchbase
• You can cache:
• Entity property data : Only caches properties data values
• Entity association data : Only caches primary keys
• Query data : HQL, ORMExecuteQuery()
• Evictions:
• ORMEvictEntity(), ORMEvictCollection()
#10: HQL Maps
select new map( 

max( bodyWeight ) as max, 

min( bodyWeight ) as min, 

count( * ) as n
)
from Cat cat
• Return array of structs
• Why a full ORM Object graph?
• Boost your APIs, stop converting queries/array of
objects to JSON
ORM Module
install cborm
ORM Module
Base ORM Service
Virtual ORM Service
Active Entity
Entity Populators
Validation
Event Handlers

DI/AOP
Base ORM Service
• Service layer for any entity
• OO Querying, caching, transactions
• Dynamic finders, getters, counters
• Object metadata & session management
• Exposes more features from Hibernate
• 90% Foundation
• Extends Base ORM Services
• Roots itself to a single entity = LessTyping
• You can build the 10%
Virtual/Concrete ORM
Services
• Active Record Pattern
• Sweet validation integration
• DI/AOP Available
Active Entity
• Populate Entities: xml, json, queries, structs
• Compose relationships from simple values
• Null support
• Exclude/include fields
• Server side validation
• Dependency Injection Listeners
• Custom Event Driven Programming
Entity Populators
Validation
Event Handlers
ORM Utilities
ORM Services in Action
box install cartracker-demo
Base ORM Service
• count(), countWhere()
• delete(), deleteAll(), deleteByID(), deleteByQuery(), delete Where()
• evict(), evictEntity(), evictQueries()
• executeQuery(), list()
• exists()
• findAll(), findAllWhere(), findByExample(), findIt(), findWhere()
• get(), getAll(),
• getKey(), getPropertyNames(), getSessionStatistics(), getTableName()
• clear(), merge(), new(), refresh()
• populate(), populateFromJSON(), populateFromXML(), populateFromQuery()
• save(), saveAll()
Base ORM Service
Dynamic Finders/Counters
• Expressive Programming
• Three types of dynamic Finders/Counters
• findBy : find ONE entity
• findAllBy : find ALL entities
• countBy: Give you a count
Base ORM Service
Dynamic Finders/Counters
• Conditionals
• LessThanEquals, LessThan
• GreaterThanEquals, GreaterThan
• Like
• Equal, NotEqual
• isNull, isNotNull
• Between, NotBetween
• inList, notInList
• Operators
• And
• Or
• Query Options
• ignoreCase, timeout, max, offset
• cacheable, cachename
Criteria Builder
Awesome OO Queries
Criteria Builder
• Limitations of CF ORM:
• entityLoad() has limited features
• Some operations we always need an entity = slow
• What if I want arrays, or arrays of structs
• Complex relationships are hard to query
• SQL/HQL string build is so 90’s == NOT FUN!
Criteria Builder
• Programmatic DSL Builder
• Rich set of criterias
• Projections and Result transformations
• Subqueries
• Caching
• SQL Inspections & Debugging
• Array of structures is twice as fast as
queries
Criteria Builder
Criteria Builder
• Request new criteria
• newCriteria()
• Add simple restriction(s)
• Find all cars sold between April and July
• Use between()
• Get results
• Use list( max, offset, timeout, sortOrder, ignoreCase, asQuery )
• Get counts
• Use count()
Criteria Builder
Restrictions
• between()
• eq()
• gt()
• ge()
• gtProperty()
• isEmpty()
• isNull()
• ne()
• ilike()
• and()
• or()
• not()
• conjunction()
• disjunction()
• isTrue()
• isFalse()
• sqlRestriction()
• ...much more!
Criteria Builder
Retrievals
• Retrieval
• firstResult()
• get()
• list()
• count()
• Options
• fetchSize()
• readOnly()
• maxResults()
• cache(), cacheRegion()
• timeout()
• order()
Criteria Builder
Aliases -> Joins
• Allows you to do queries within
relationships
• Creates SQL Joins
• Aliases can be nested, so if your entity
knows about it, you can query it!
Criteria Builder
Projections
• Projects change nature of results
• Arrays of data, or arrays of structs (Mighty Fast)
• Once its added its there forever
• avg
• count
• countDistinct
• distinct
• groupProperty
• max
• min
• property
• sum
• rowCount
• id
• sqlProjection
• sqlGroupProjection
• detachedSQLProjection
Criteria Builder
Debugging + Logging
• Criteria Builder SQL Inspector
• startSQLLog( returnExecutableSQL, formatSQL )
• stopSQLLog()
• getSQLLog()
• getSQL( returnExecutableSQL, formatSQL )
Thanks!
Q & A

More Related Content

What's hot

Building Concurrent WebObjects applications with Scala
Building Concurrent WebObjects applications with ScalaBuilding Concurrent WebObjects applications with Scala
Building Concurrent WebObjects applications with Scala
WO Community
 
SeaJUG May 2012 mybatis
SeaJUG May 2012 mybatisSeaJUG May 2012 mybatis
SeaJUG May 2012 mybatis
Will Iverson
 

What's hot (20)

RESTful Services
RESTful ServicesRESTful Services
RESTful Services
 
Scala at Treasure Data
Scala at Treasure DataScala at Treasure Data
Scala at Treasure Data
 
Building Concurrent WebObjects applications with Scala
Building Concurrent WebObjects applications with ScalaBuilding Concurrent WebObjects applications with Scala
Building Concurrent WebObjects applications with Scala
 
Apache Cayenne: a Java ORM Alternative
Apache Cayenne: a Java ORM AlternativeApache Cayenne: a Java ORM Alternative
Apache Cayenne: a Java ORM Alternative
 
Hibernate Tips ‘n’ Tricks - 15 Tips to solve common problems
Hibernate Tips ‘n’ Tricks - 15 Tips to solve common problemsHibernate Tips ‘n’ Tricks - 15 Tips to solve common problems
Hibernate Tips ‘n’ Tricks - 15 Tips to solve common problems
 
Scala profiling
Scala profilingScala profiling
Scala profiling
 
Oozie @ Riot Games
Oozie @ Riot GamesOozie @ Riot Games
Oozie @ Riot Games
 
PHP, the GraphQL ecosystem and GraphQLite
PHP, the GraphQL ecosystem and GraphQLitePHP, the GraphQL ecosystem and GraphQLite
PHP, the GraphQL ecosystem and GraphQLite
 
Hibernate performance tuning
Hibernate performance tuningHibernate performance tuning
Hibernate performance tuning
 
How to JavaOne 2016 - Generate Customized Java 8 Code from Your Database [TUT...
How to JavaOne 2016 - Generate Customized Java 8 Code from Your Database [TUT...How to JavaOne 2016 - Generate Customized Java 8 Code from Your Database [TUT...
How to JavaOne 2016 - Generate Customized Java 8 Code from Your Database [TUT...
 
Speed Up Your APEX Apps with JSON and Handlebars
Speed Up Your APEX Apps with JSON and HandlebarsSpeed Up Your APEX Apps with JSON and Handlebars
Speed Up Your APEX Apps with JSON and Handlebars
 
Demystifying Oak Search
Demystifying Oak SearchDemystifying Oak Search
Demystifying Oak Search
 
Using JPA applications in the era of NoSQL: Introducing Hibernate OGM
Using JPA applications in the era of NoSQL: Introducing Hibernate OGMUsing JPA applications in the era of NoSQL: Introducing Hibernate OGM
Using JPA applications in the era of NoSQL: Introducing Hibernate OGM
 
04 integrate entityframework
04 integrate entityframework04 integrate entityframework
04 integrate entityframework
 
Evolving Streaming Applications
Evolving Streaming ApplicationsEvolving Streaming Applications
Evolving Streaming Applications
 
SeaJUG May 2012 mybatis
SeaJUG May 2012 mybatisSeaJUG May 2012 mybatis
SeaJUG May 2012 mybatis
 
RuleBox : A natural language Rule Engine
RuleBox : A natural language Rule EngineRuleBox : A natural language Rule Engine
RuleBox : A natural language Rule Engine
 
Projects Valhalla, Loom and GraalVM at JUG Mainz
Projects Valhalla, Loom and GraalVM at JUG MainzProjects Valhalla, Loom and GraalVM at JUG Mainz
Projects Valhalla, Loom and GraalVM at JUG Mainz
 
Scala in practice
Scala in practiceScala in practice
Scala in practice
 
PLAT-7 Spring Web Scripts and Spring Surf
PLAT-7 Spring Web Scripts and Spring SurfPLAT-7 Spring Web Scripts and Spring Surf
PLAT-7 Spring Web Scripts and Spring Surf
 

Viewers also liked

Viewers also liked (6)

SQLAlchemy Primer
SQLAlchemy PrimerSQLAlchemy Primer
SQLAlchemy Primer
 
Database programming
Database programmingDatabase programming
Database programming
 
Automating Management of Amazon EC2 Instances with Auto Scaling - March 2017 ...
Automating Management of Amazon EC2 Instances with Auto Scaling - March 2017 ...Automating Management of Amazon EC2 Instances with Auto Scaling - March 2017 ...
Automating Management of Amazon EC2 Instances with Auto Scaling - March 2017 ...
 
An Overview of Designing Microservices Based Applications on AWS - March 2017...
An Overview of Designing Microservices Based Applications on AWS - March 2017...An Overview of Designing Microservices Based Applications on AWS - March 2017...
An Overview of Designing Microservices Based Applications on AWS - March 2017...
 
PlaySQLAlchemyORM2017.key
PlaySQLAlchemyORM2017.keyPlaySQLAlchemyORM2017.key
PlaySQLAlchemyORM2017.key
 
ColdBox Hierarchical MVC - Transform Your Monolith
ColdBox Hierarchical MVC - Transform Your MonolithColdBox Hierarchical MVC - Transform Your Monolith
ColdBox Hierarchical MVC - Transform Your Monolith
 

Similar to ITB2017 - Slaying the ORM dragons with cborm

Yapc10 Cdt World Domination
Yapc10   Cdt World DominationYapc10   Cdt World Domination
Yapc10 Cdt World Domination
cPanel
 
A Case Study of NoSQL Adoption: What Drove Wordnik Non-Relational?
A Case Study of NoSQL Adoption: What Drove Wordnik Non-Relational?A Case Study of NoSQL Adoption: What Drove Wordnik Non-Relational?
A Case Study of NoSQL Adoption: What Drove Wordnik Non-Relational?
DATAVERSITY
 
Fixing Twitter Improving The Performance And Scalability Of The Worlds Most ...
Fixing Twitter  Improving The Performance And Scalability Of The Worlds Most ...Fixing Twitter  Improving The Performance And Scalability Of The Worlds Most ...
Fixing Twitter Improving The Performance And Scalability Of The Worlds Most ...
xlight
 

Similar to ITB2017 - Slaying the ORM dragons with cborm (20)

ORM Pink Unicorns
ORM Pink UnicornsORM Pink Unicorns
ORM Pink Unicorns
 
hibernateormfeatures-140223193044-phpapp02.pdf
hibernateormfeatures-140223193044-phpapp02.pdfhibernateormfeatures-140223193044-phpapp02.pdf
hibernateormfeatures-140223193044-phpapp02.pdf
 
The Return of the Living Datalog
The Return of the Living DatalogThe Return of the Living Datalog
The Return of the Living Datalog
 
Yapc10 Cdt World Domination
Yapc10   Cdt World DominationYapc10   Cdt World Domination
Yapc10 Cdt World Domination
 
Dev nexus 2017
Dev nexus 2017Dev nexus 2017
Dev nexus 2017
 
Why ruby and rails
Why ruby and railsWhy ruby and rails
Why ruby and rails
 
OrigoDB - take the red pill
OrigoDB - take the red pillOrigoDB - take the red pill
OrigoDB - take the red pill
 
A Case Study of NoSQL Adoption: What Drove Wordnik Non-Relational?
A Case Study of NoSQL Adoption: What Drove Wordnik Non-Relational?A Case Study of NoSQL Adoption: What Drove Wordnik Non-Relational?
A Case Study of NoSQL Adoption: What Drove Wordnik Non-Relational?
 
Top ten-list
Top ten-listTop ten-list
Top ten-list
 
Performance and Abstractions
Performance and AbstractionsPerformance and Abstractions
Performance and Abstractions
 
Inside sql server in memory oltp sql sat nyc 2017
Inside sql server in memory oltp sql sat nyc 2017Inside sql server in memory oltp sql sat nyc 2017
Inside sql server in memory oltp sql sat nyc 2017
 
Scaling the Web: Databases & NoSQL
Scaling the Web: Databases & NoSQLScaling the Web: Databases & NoSQL
Scaling the Web: Databases & NoSQL
 
Fixing twitter
Fixing twitterFixing twitter
Fixing twitter
 
Fixing_Twitter
Fixing_TwitterFixing_Twitter
Fixing_Twitter
 
Fixing Twitter Improving The Performance And Scalability Of The Worlds Most ...
Fixing Twitter  Improving The Performance And Scalability Of The Worlds Most ...Fixing Twitter  Improving The Performance And Scalability Of The Worlds Most ...
Fixing Twitter Improving The Performance And Scalability Of The Worlds Most ...
 
Fixing Twitter Improving The Performance And Scalability Of The Worlds Most ...
Fixing Twitter  Improving The Performance And Scalability Of The Worlds Most ...Fixing Twitter  Improving The Performance And Scalability Of The Worlds Most ...
Fixing Twitter Improving The Performance And Scalability Of The Worlds Most ...
 
John adams talk cloudy
John adams   talk cloudyJohn adams   talk cloudy
John adams talk cloudy
 
Design for scale
Design for scaleDesign for scale
Design for scale
 
Harness SharePoint and jQuery to Make Dynamic Displays and Applications
 Harness SharePoint and jQuery to Make Dynamic Displays and Applications Harness SharePoint and jQuery to Make Dynamic Displays and Applications
Harness SharePoint and jQuery to Make Dynamic Displays and Applications
 
12 Step Guide to Lotuscript
12 Step Guide to Lotuscript12 Step Guide to Lotuscript
12 Step Guide to Lotuscript
 

More from Ortus Solutions, Corp

More from Ortus Solutions, Corp (20)

BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 
Ortus Government.pdf
Ortus Government.pdfOrtus Government.pdf
Ortus Government.pdf
 
Luis Majano The Battlefield ORM
Luis Majano The Battlefield ORMLuis Majano The Battlefield ORM
Luis Majano The Battlefield ORM
 
Brad Wood - CommandBox CLI
Brad Wood - CommandBox CLI Brad Wood - CommandBox CLI
Brad Wood - CommandBox CLI
 
Secure your Secrets and Settings in ColdFusion
Secure your Secrets and Settings in ColdFusionSecure your Secrets and Settings in ColdFusion
Secure your Secrets and Settings in ColdFusion
 
Daniel Garcia ContentBox: CFSummit 2023
Daniel Garcia ContentBox: CFSummit 2023Daniel Garcia ContentBox: CFSummit 2023
Daniel Garcia ContentBox: CFSummit 2023
 
ITB_2023_Human-Friendly_Scheduled_Tasks_Giancarlo_Gomez.pdf
ITB_2023_Human-Friendly_Scheduled_Tasks_Giancarlo_Gomez.pdfITB_2023_Human-Friendly_Scheduled_Tasks_Giancarlo_Gomez.pdf
ITB_2023_Human-Friendly_Scheduled_Tasks_Giancarlo_Gomez.pdf
 
ITB_2023_CommandBox_Multi-Server_-_Brad_Wood.pdf
ITB_2023_CommandBox_Multi-Server_-_Brad_Wood.pdfITB_2023_CommandBox_Multi-Server_-_Brad_Wood.pdf
ITB_2023_CommandBox_Multi-Server_-_Brad_Wood.pdf
 
ITB_2023_The_Many_Layers_of_OAuth_Keith_Casey_.pdf
ITB_2023_The_Many_Layers_of_OAuth_Keith_Casey_.pdfITB_2023_The_Many_Layers_of_OAuth_Keith_Casey_.pdf
ITB_2023_The_Many_Layers_of_OAuth_Keith_Casey_.pdf
 
ITB_2023_Relationships_are_Hard_Data_modeling_with_NoSQL_Curt_Gratz.pdf
ITB_2023_Relationships_are_Hard_Data_modeling_with_NoSQL_Curt_Gratz.pdfITB_2023_Relationships_are_Hard_Data_modeling_with_NoSQL_Curt_Gratz.pdf
ITB_2023_Relationships_are_Hard_Data_modeling_with_NoSQL_Curt_Gratz.pdf
 
ITB_2023_Extend_your_contentbox_apps_with_custom_modules_Javier_Quintero.pdf
ITB_2023_Extend_your_contentbox_apps_with_custom_modules_Javier_Quintero.pdfITB_2023_Extend_your_contentbox_apps_with_custom_modules_Javier_Quintero.pdf
ITB_2023_Extend_your_contentbox_apps_with_custom_modules_Javier_Quintero.pdf
 
ITB_2023_25_Most_Dangerous_Software_Weaknesses_Pete_Freitag.pdf
ITB_2023_25_Most_Dangerous_Software_Weaknesses_Pete_Freitag.pdfITB_2023_25_Most_Dangerous_Software_Weaknesses_Pete_Freitag.pdf
ITB_2023_25_Most_Dangerous_Software_Weaknesses_Pete_Freitag.pdf
 
ITB_2023_CBWire_v3_Grant_Copley.pdf
ITB_2023_CBWire_v3_Grant_Copley.pdfITB_2023_CBWire_v3_Grant_Copley.pdf
ITB_2023_CBWire_v3_Grant_Copley.pdf
 
ITB_2023_Practical_AI_with_OpenAI_-_Grant_Copley_.pdf
ITB_2023_Practical_AI_with_OpenAI_-_Grant_Copley_.pdfITB_2023_Practical_AI_with_OpenAI_-_Grant_Copley_.pdf
ITB_2023_Practical_AI_with_OpenAI_-_Grant_Copley_.pdf
 
ITB_2023_When_Your_Applications_Work_As_a_Team_Nathaniel_Francis.pdf
ITB_2023_When_Your_Applications_Work_As_a_Team_Nathaniel_Francis.pdfITB_2023_When_Your_Applications_Work_As_a_Team_Nathaniel_Francis.pdf
ITB_2023_When_Your_Applications_Work_As_a_Team_Nathaniel_Francis.pdf
 
ITB_2023_Faster_Apps_That_Wont_Get_Crushed_Brian_Klaas.pdf
ITB_2023_Faster_Apps_That_Wont_Get_Crushed_Brian_Klaas.pdfITB_2023_Faster_Apps_That_Wont_Get_Crushed_Brian_Klaas.pdf
ITB_2023_Faster_Apps_That_Wont_Get_Crushed_Brian_Klaas.pdf
 
ITB_2023_Chatgpt_Box_Scott_Steinbeck.pdf
ITB_2023_Chatgpt_Box_Scott_Steinbeck.pdfITB_2023_Chatgpt_Box_Scott_Steinbeck.pdf
ITB_2023_Chatgpt_Box_Scott_Steinbeck.pdf
 
ITB_2023_CommandBox_Task_Runners_Brad_Wood.pdf
ITB_2023_CommandBox_Task_Runners_Brad_Wood.pdfITB_2023_CommandBox_Task_Runners_Brad_Wood.pdf
ITB_2023_CommandBox_Task_Runners_Brad_Wood.pdf
 
ITB_2023_Create_as_many_web_sites_or_web_apps_as_you_want_George_Murphy.pdf
ITB_2023_Create_as_many_web_sites_or_web_apps_as_you_want_George_Murphy.pdfITB_2023_Create_as_many_web_sites_or_web_apps_as_you_want_George_Murphy.pdf
ITB_2023_Create_as_many_web_sites_or_web_apps_as_you_want_George_Murphy.pdf
 
ITB2023 Developing for Performance - Denard Springle.pdf
ITB2023 Developing for Performance - Denard Springle.pdfITB2023 Developing for Performance - Denard Springle.pdf
ITB2023 Developing for Performance - Denard Springle.pdf
 

Recently uploaded

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Recently uploaded (20)

Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 

ITB2017 - Slaying the ORM dragons with cborm

  • 1.
  • 2. Slaying the ORM Dragons with CBORM
  • 3. WHO AM I? • Luis Majano - Computer Engineer • Imported from El Salvador-----------> • Architecture + Software Design • CEO of Ortus Solutions • Adobe Community Professional • Creator of all things Box: 
 ColdBox, ContentBox, CommandBox,WireBox….
  • 4. AGENDA • ORM FirstThoughts • Is ORM a Silver Bullet? • Visit from a Special Guest • Specialized ORM Services
  • 5. ORMThoughts? CF ORM was easier to use? OO way to query ORM was fast 80% of API Querying Extensible way to finish the remaining 20% When is HappyBox? Auto build relationships
  • 6. CONCLUSIONS • Can’t or doesn’t exist • Sounds like bull….. • What’s this latino up to? • Is he trying to get my money PROVE IT!
  • 7. ORM is NOT a silver bullet • Just another tool • Times you need the power of the database: reports, legacy, sp, etc. • Mix and match • What if you wanted array of structs, or lists or queries or arrays of data? • There is a learning curve, but it is worth the investment
  • 8. Applied Benefits • Increase in productivity of about 40% • Rich Object Models • Deliver DB patching updates • Increased Flexibility • Great for abstracting vendor specific intricacies • OO Queries • Avg JDBC <10ms of about 350K Transactions
  • 9. How do we start? coldfusionormbook.com amazon
  • 10. Guru ORMLui 10 keys to ORM Success!
  • 11. #1: OO Modeling is Key • ORM relationship modeling is key • OO is required • UML is your best friend • STOPTHINKING ABOUT DATA • YOU ARE NOT MODELING A DATABASE
  • 12. #1: OO Modeling is Key
  • 13. #1: OO Modeling is Key Query Object Data Data + Behavior
  • 14. #2: Bad Engine Defaults Do not use engine defaults: Control Data Flushing +Transaction Borders: 
 ormsettings.flushAtRequestEnd=false ormsettings.autoManageSession=false Control Database Dialects (If Possible) ormsettings.dialect=“MySQLwithInnoDB”
  • 15. #2: Bad Engine Defaults • this.ormsettings.cfclocation • Use it to a specified directory, else pay the price of discovery • this.ormsettings.logSQL=true • Great for debugging, false for production, else pay the price • Having Issues? • Hibernate MXML: this.ormsettings.saveMapping=true • DataBoss - ortussolutions.com/products/databoss
  • 16. #3: Understand Hibernate Session • Not the same as session scope • A transitionary space + Caching Layer • entityLoad() • entityNew() ? • You need to control when to send to DB • transaction{}, ormflush() • You can remove entities from it and clear it • ORMClearSession() • ORMEvictEntity(), ORMEvictCollection() • ORMCloseSession()
  • 17. #3: Understand Hibernate Session Hibernate Session 
 (Conversation - Request) DB Eu Ex EzEy Cache ehCache/ Couchbase Batched SQL EntityNew() EntityLoad() Data (!CFCs) Hibernate Session Factory (application) CRUD When? ORMClearSession()
  • 18. #3: Understand Hibernate Session DB Sync Insertions in order updates Collection deletions collection deletion, updates, inserts collection insertions deletions in order
  • 19. #4:Transaction Demarcation • Transactions demarcate SQL boundaries • Important Imperative for ORM + SQL • No communication to DB should occur without one • Reactive programming, expect the worst • cftransaction or Hibernate transactions
  • 20. #4:Transaction Demarcation • Transaction Theory: • Any existing ORM session is flushed and reused • Data can be committed or rollback • ORMFlush() is ignored in transactions • If commit, then flushed to database • If rollback, session is cleared
  • 21. #5 Lazyness • Immediate Fetching (Default) • select with left outer join
 poor, poor, poor, poor performance • Use lazy For ALL Relationships or pay the price • Three types of laziness: • lazy=“true” • all relationships • Loads all the relationship data when called upon (Batch sizes if used) • lazy=“extra” • one-to-many, many-to-many • Loads proxies with primary keys (Event better - Batch sizes if used) • lazy=“proxy” • one-to-one, many-to-one • Loads proxy with primary key
  • 22. • Eager Fetching • Mostly used in one-to-one and many-to-one, but applies to all • Default uses 2 SQL queries, reduce to 1 Query • property name=“role” fieldtype=“many-to-one” fetch=“join”; • Batch Fetching • Limits the way relationships are loaded, else Hibernate tries to load all records • Used on many-to-many and one-to-many collection properties: • property name=“comments” fieldtype=“one-to-many” batchsize=“10” lazy=“extra”; • Used at entity level as well: • component name=“Comment” batchsize=10{} #5 Lazyness
  • 23. Oracle Tip • JDBC Fetch Sizes are defaulted to 10 • Slow for many records or batch operations • Increase the JDBC Fetch size • Custom Hibernate setting • hibernate.jdbc.fetch_size=100 #5 Lazyness
  • 24. #6:Avoid bi-directional • They can be more of a headache • Cascading Deletes • Choose the master relationship • inverse=true • Else double queries • Does it make sense? • Supporting methods for bi-directional linkage • Supporting methods for un-linkages
  • 27. #7: Do not store entities in scopes • Don’t do it! • No linkage to Hibernate Session • Relationships will fail if not lazy • entityMerge() • Store ID’s instead
  • 28. #8: Use DB Indexes • #1 Performance Problem • Identify relationships • Identify HQL, SQL • property name=“isActive” index=“idxActive”
  • 29. #9: Cache = BOOST! • Don’t go cache crazy • Develop a strategy • Does not store CFC, stores individual property values • Use distributed caches: ehcache, couchbase • You can cache: • Entity property data : Only caches properties data values • Entity association data : Only caches primary keys • Query data : HQL, ORMExecuteQuery() • Evictions: • ORMEvictEntity(), ORMEvictCollection()
  • 30. #10: HQL Maps select new map( 
 max( bodyWeight ) as max, 
 min( bodyWeight ) as min, 
 count( * ) as n ) from Cat cat • Return array of structs • Why a full ORM Object graph? • Boost your APIs, stop converting queries/array of objects to JSON
  • 32. ORM Module Base ORM Service Virtual ORM Service Active Entity Entity Populators Validation Event Handlers
 DI/AOP
  • 33. Base ORM Service • Service layer for any entity • OO Querying, caching, transactions • Dynamic finders, getters, counters • Object metadata & session management • Exposes more features from Hibernate • 90% Foundation
  • 34. • Extends Base ORM Services • Roots itself to a single entity = LessTyping • You can build the 10% Virtual/Concrete ORM Services
  • 35. • Active Record Pattern • Sweet validation integration • DI/AOP Available Active Entity
  • 36. • Populate Entities: xml, json, queries, structs • Compose relationships from simple values • Null support • Exclude/include fields • Server side validation • Dependency Injection Listeners • Custom Event Driven Programming Entity Populators Validation Event Handlers ORM Utilities
  • 37. ORM Services in Action box install cartracker-demo
  • 38. Base ORM Service • count(), countWhere() • delete(), deleteAll(), deleteByID(), deleteByQuery(), delete Where() • evict(), evictEntity(), evictQueries() • executeQuery(), list() • exists() • findAll(), findAllWhere(), findByExample(), findIt(), findWhere() • get(), getAll(), • getKey(), getPropertyNames(), getSessionStatistics(), getTableName() • clear(), merge(), new(), refresh() • populate(), populateFromJSON(), populateFromXML(), populateFromQuery() • save(), saveAll()
  • 39. Base ORM Service Dynamic Finders/Counters • Expressive Programming • Three types of dynamic Finders/Counters • findBy : find ONE entity • findAllBy : find ALL entities • countBy: Give you a count
  • 40. Base ORM Service Dynamic Finders/Counters • Conditionals • LessThanEquals, LessThan • GreaterThanEquals, GreaterThan • Like • Equal, NotEqual • isNull, isNotNull • Between, NotBetween • inList, notInList • Operators • And • Or • Query Options • ignoreCase, timeout, max, offset • cacheable, cachename
  • 42. Criteria Builder • Limitations of CF ORM: • entityLoad() has limited features • Some operations we always need an entity = slow • What if I want arrays, or arrays of structs • Complex relationships are hard to query • SQL/HQL string build is so 90’s == NOT FUN!
  • 43. Criteria Builder • Programmatic DSL Builder • Rich set of criterias • Projections and Result transformations • Subqueries • Caching • SQL Inspections & Debugging • Array of structures is twice as fast as queries
  • 45. Criteria Builder • Request new criteria • newCriteria() • Add simple restriction(s) • Find all cars sold between April and July • Use between() • Get results • Use list( max, offset, timeout, sortOrder, ignoreCase, asQuery ) • Get counts • Use count()
  • 46. Criteria Builder Restrictions • between() • eq() • gt() • ge() • gtProperty() • isEmpty() • isNull() • ne() • ilike() • and() • or() • not() • conjunction() • disjunction() • isTrue() • isFalse() • sqlRestriction() • ...much more!
  • 47. Criteria Builder Retrievals • Retrieval • firstResult() • get() • list() • count() • Options • fetchSize() • readOnly() • maxResults() • cache(), cacheRegion() • timeout() • order()
  • 48. Criteria Builder Aliases -> Joins • Allows you to do queries within relationships • Creates SQL Joins • Aliases can be nested, so if your entity knows about it, you can query it!
  • 49. Criteria Builder Projections • Projects change nature of results • Arrays of data, or arrays of structs (Mighty Fast) • Once its added its there forever • avg • count • countDistinct • distinct • groupProperty • max • min • property • sum • rowCount • id • sqlProjection • sqlGroupProjection • detachedSQLProjection
  • 50. Criteria Builder Debugging + Logging • Criteria Builder SQL Inspector • startSQLLog( returnExecutableSQL, formatSQL ) • stopSQLLog() • getSQLLog() • getSQL( returnExecutableSQL, formatSQL )