DataFaucet PersistenceService Update - Tested Many-to-Many

I just committed some updates to the SVN repository that includes testing for many-to-many relationships with the PersistenceService. And yes there were a handful of issues that needed to be addressed to get these working. ;)

The object code for a reciprocal many-to-many relationshiup looks like this:

<cfcomponent displayname="department">
<cfproperty name="departmentID" type="uuid" required="true" key="1" />
<cfproperty name="departmentName" type="string" required="true" />
<cfproperty name="facultyArray" type="array" required="false" />

...
</cfcomponent>

<cfcomponent displayname="faculty">
<cfproperty name="facultyID" type="uuid" required="true" key="1" />
<cfproperty name="firstname" type="string" required="false" />
<cfproperty name="lastname" type="string" required="false" />
<cfproperty name="departmentArray" type="array" required="false" xref="tblDepartmentFaculty" />

...
</cfcomponent>

Once you've got these CFCs ready, then you would set up your PersistenceService with the appropriate IoC factory (or multiple factories if you prefer) and call the install method to install the tables to hold the data for these components. (The below code would normally be configured in your IoC factory - it's shown here for reference.) :)

<cfscript>
cacheFactory = CreateObject("component","datafaucet.system.classcachefactory").init();
cacheManager = CreateObject("component","datafaucet.system.classcachemanager").init(cacheFactory);
daoFactory = CreateObject("component","datafaucet.system.daofactory").init(accessorPattern="get*",mutatorPattern="set*");
factory = CreateObject("component","datafaucet.system.classfactory").init("datafaucet.demo");
service = CreateObject("component","datafaucet.system.persistenceservice").init(factory,daoFactory,cacheManager);

service.install("department");
service.install("faculty");
</cfscript>

And viola! You've got tables. Then all you need to do is get and save a few departments and faculty. As you create and save them it will both cache the objects and relationships and it will update the cross-reference table indicated in the xref attribute. Restart your ColdFusion server and fetch any department or faculty record via service.get("department",departmentid) and it will automatically load the associated objects.

As previously mentioned, this is a deceptively simple feature and it can be very easy to swamp your server with hundreds or even thousands of objects that aren't being used, simply because you declared a couple properties of type "array". So BE CAREFUL if you choose to use this. Make sure these are objects that really are frequently used and really should be cached in memory.

Related Blog Entries

Comments
BlogCFC was created by Raymond Camden. This blog is running version 5.5.006.