DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
  1. DZone
  2. Data Engineering
  3. Databases
  4. Some Things About MappedSuperClass in ColdFusion 9.0.1

Some Things About MappedSuperClass in ColdFusion 9.0.1

Terrence Ryan user avatar by
Terrence Ryan
·
Apr. 10, 11 · News
Like (1)
Save
Tweet
Share
6.58K Views

Join the DZone community and get the full member experience.

Join For Free

I was fooling around with inheritance in super classes in ColdFusion 9.0.1. I was trying to add that whole dynamic/static inheritance thing to Apptacular so you can add on to an Apptacular application without having to worry about changes being overridden by the regeneration process. Typically when you do that, the dynamic, rewritten class is usually the parent of the child static class. The child, static, class is what you refer to in the rest of code and in which you write custom code. The scaffolder never touches this file again, allowing you to alter things in the database, rescaffold and not overwrite code customizations. I hearby call this "non-destructive scaffold regeneration," regardless of what other people call it.

ORM entities can't really work that way. If you try to setup that sort of thing, ORM craps out in ColdFusion with an error. CF9 ORM doesn't really like ORM objects being the parent of other items, unless you are using inheritance mapping.

However, if you use the "mappedSuperClass" cfc attribute that is now available in ColdFusion 9.0.1 you can achieve sort of the same thing, but you have to flip this on its head. The superclass is the one that is static, and you can edit, while the dynamic one is the child.

This is mostly good. Except for one thing: one of the main reasons to write code this way is so you can override methods, and if the child is the one that is dynamic, and overwritten, then you cannot override the methods from the static parent. You can add methods and properties, but you cannot override them.

At first glance this seems like a deal breaker, but it doesn't have to be. Most generated ORM entities are light on code, because of implicit getters and setters. But those implicit getters and setters are exactly what you want to override in an ORM entity. However it turns out that explicit functions will always override implicit ones, even when the explicit function is in the super class and not the child class.

I put together a simple little demo to show this off:

component mappedSuperClass="true"{
	public string function getFirstName(){
		return "Yo";
	}
	
	public string function getRealFirstName(){
		return variables.firstName;
	}
}
component{
	This.name = "cfartgallery";
	This.ormenabled = true;
	This.datasource = "cfartgallery";
}
component extends="_artistsSuperEntity" persistent="true"{

	property name="ARTISTID" fieldtype="id" ;
	property name="FIRSTNAME" type="string";
	property name="LASTNAME" type="string";
	property name="ADDRESS" type="string";
	property name="CITY" type="string";
	property name="STATE" type="string";
	property name="POSTALCODE" type="string";
	property name="EMAIL" type="string";
	property name="PHONE" type="string";
	property name="FAX" type="string";
	property name="THEPASSWORD" type="string";	
}
<cfset artist = entityLoad("artists", 1, true) />
<cfoutput>
	<p>GetFirstName = #artist.getFirstName()#</p>
	<p>GetRealFirstName = #artist.getRealFirstName()#</p>
</cfoutput>

Result from test.cfm:

GetFirstName = Yo

GetRealFirstName = Aiden

So it's a little upside down, but if you want to do some non-destructive scaffold regeneration with ColdFusion 9 ORM, it's a workable solution. E

Database Inheritance (object-oriented programming) IT Sort (Unix) Scaffold (programming) application Light (web browser)

Published at DZone with permission of Terrence Ryan, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • PHP vs React
  • Memory Debugging: A Deep Level of Insight
  • Best Practices for Writing Clean and Maintainable Code
  • What Should You Know About Graph Database’s Scalability?

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: