Vinny,
If you are calling getAllEmployees() remotely, you are going to get a
new instance of employeemanager.cfc. CF does not automatically run the
init() function, so it doesn't have those variables set up.
I think what you are trying to do is persist a CFC but call it
remotely... seems like you are on the right track. In application.cfm,
you need to scope the employeeManager instance into application (I think
you were trying to do that anyways).
You will need another cfc (facade) to talk to the
application.employeeManager instance. You can't call remote methods on
the object directly, but your facade cfc can access the persistant
application.employeeManager for you, not caring that he gets re-created
each time a method is called.
hope this helps,
dave
>>> [EMAIL PROTECTED] 2/3/2004 8:30:11 AM >>>
Thanks a lot Sean. It is just what I was looking for. However, I keep
on
getting the following errormessage:
Error : Service threw an exception during method invocation: Element
EMPLOYEEGATEWAY is undefined in a Java object of type class
[Ljava.lang.String; referenced as
Just for a quick test I have put your code snippet in the
Application.cfm.
Application.cfm
<cfapplication name="atlantis" clientmanagement="yes"
sessionmanagement="yes" setclientcookies="no" setdomaincookies="yes">
<cfscript>
APPLICATION.dataSource = "AtlantisDatabase";
APPLICATION.ApplicationName = "Atlantis";
</cfscript>
<cfif not structKeyExists(application,"employeeManager")>
<cflock name="#APPLICATION.ApplicationName#_employeeManager"
type="exclusive" timeout="10">
<cfif not structKeyExists(application,"employeeManager")>
<cfset employeeManager =
createObject("component","atlantis.model.employeemanager").init() />
</cfif>
</cflock>
</cfif>
And changed the employeemanager.cfc into
<cfcomponent displayname="Employee Manager" hint="I am the facade for
the
Atlantis application">
<cffunction name="init" access="public" returntype="void"
output="false"
displayname="Constructor">
<cfset var dsn = "#APPLICATION.DataSource#" />
<cfset VARIABLES.employeeGateway =
createObject("component","atlantis.model.employeegateway").init(dsn)
/>
<cfset VARIABLES.employeeDAO =
createObject("component","atlantis.model.employeedao").init(dsn) />
</cffunction>
<cffunction name="getAllEmployees" access="remote"
returntype="query"
output="false" displayname="Get All Employees">
<cfreturn VARIABLES.employeeGateway.getEmployees() />
</cffunction>
</cfcomponent>
Why is the employeeGateway object not created?
Vinny
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On
Behalf
Of Sean A Corfield
Sent: maandag 2 februari 2004 22:59
To: [EMAIL PROTECTED]
Subject: Re: [CFCDev] implementing Sean Corfields data access pattern
without mach-ii
On Feb 2, 2004, at 5:24 AM, Kairoh! wrote:
> What is the best way to do this configuration without using the
> mach-ii framework?
In Mach II, the configure() method is essentially what you would
normally
call the init() method (the framework reserves init() for its internal
use).
So, just remove extends="MachII.framework.Listener" and rename
configure()
to init() - now you've got a 'regular'
(non-framework) object. Oh, and change the <cfargument> tags to reflect
the
actual arguments you'll be passing in instead of the event object.
> Calling the configure method from the Flash application through Flash
> Remoting?
When you make a Flash Remoting call, the CFC is created for each call.
If you want to maintain state between calls, you need to use a session
facade or something similar. Read:
http://www.macromedia.com/devnet/mx/flashremoting/articles/facades.html
> I really like the idea behind Sean's pattern but I am not sure how to
> efficiently adapt it to a non-mach-ii scenario.
Well, it's not *my* pattern - go read the references in the front of
the
Mach II Development Guide for the origins of the pattern. The pattern
itself
has nothing to with Mach II and can be implemented easily in any
context.
The only part of the code you are looking at that is Mach II specific
in the
'manager' CFC.
Since that object is designed to work in application scope, you could
use
write a CFC that is an "application facade" that you call from Flash
Remoting:
managerfacade.cfc:
<cfcomponent>
<cffunction name="getManager" access="private" ...>
<cfif not
structKeyExists(application,"articleManager")>
<!--- perform initialization --->
<cfset articleManager =
createObject("component","articlemanager").init(...) />
</cfif>
<cfreturn articleManager />
</cffunction>
<cffunction name="..." access="remote" ...>
<cfset var artMgr = getManager() />
...
</cffunction>
</cfcomponent>
The "perform initialization" code could read an XML config or whatever
you
wanted to do. Oh, and you'd need locking in the getManager() method to
protect against race conditions:
<cfif not
structKeyExists(application,"articleManager")>
<cflock
name="application_articleManager"
type="exclusive" ...>
<cfif not
structKeyExists(application,"articleManager")>
...
</cfif>
</cflock>
</cfif>
This if-lock-if structure ensures that no locking is used for the
normal
flow of code but also protects against race conditions at startup.
Regards,
Sean
----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email to
[EMAIL PROTECTED] with the words 'unsubscribe cfcdev'
in the message of the email.
CFCDev is run by CFCZone (www.cfczone.org) and supported by Mindtool,
Corporation (www.mindtool.com).
An archive of the CFCDev list is available at
www.mail-archive.com/[EMAIL PROTECTED]
----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email
to [EMAIL PROTECTED] with the words 'unsubscribe cfcdev'
in the message of the email.
CFCDev is run by CFCZone (www.cfczone.org) and supported
by Mindtool, Corporation (www.mindtool.com).
An archive of the CFCDev list is available at
www.mail-archive.com/[EMAIL PROTECTED]
----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email
to [EMAIL PROTECTED] with the words 'unsubscribe cfcdev'
in the message of the email.
CFCDev is run by CFCZone (www.cfczone.org) and supported
by Mindtool, Corporation (www.mindtool.com).
An archive of the CFCDev list is available at www.mail-archive.com/[EMAIL PROTECTED]