Configuring two instances of Transfer and how to call

2 views
Skip to first unread message

James Buckingham

unread,
Sep 20, 2010, 3:30:39 PM9/20/10
to ColdBox Platform
Hi again,

I'm needing to setup 2 Transfer ORM Factories - 2 Datasources are
being put in place so I'm guessing I'm needing two instances of the
loader put in my Configuration?

I've seen a few ppl talking about this on the group but not
specifically CB3.0 config. To be honest after a few hours of trying to
do this I'm struggling a bit. Mainly with syntax and working examples
of how the configuration would be setup for doing this. Does anyone
have any pointers / examples of how the interceptor would be setup to
do this? Any help appreciated.

---

Off the back of that I've got another question.... I'm all ears though
if anyone has a better approach :-)

We have a baseService that all our other services extend. At the
moment ColdBox is being injected into this by Lightwire.

In there is a getTransfer() method which right now is calling Transfer
through this code : -

<cfreturn variables.instance.coldbox.getColdboxOCM().get('Transfer') /
>

With the new datasource going in getTransfer() now needs to be
dynamically populated depending on the service being called.

Lightwire documentation seems to be a bit thin on the ground so I was
wondering again if anyone had any pointers on how to set this up or if
there is maybe a better way?

Thanks a lot
James

James Buckingham

unread,
Sep 20, 2010, 4:05:06 PM9/20/10
to ColdBox Platform
Ok I think I've got Lightwire now populating the services for me
through this ...

<?xml version="1.0" encoding="UTF-8"?>
<beans>
<!-- Coldbox -->
<bean id="ColdboxFactory" class="coldbox.system.ioc.ColdboxFactory" /
>
<bean id="Coldbox" factory-bean="ColdBoxFactory" factory-
method="getColdbox" />
<bean id="ColdboxOCM" factory-bean="ColdBoxFactory" factory-
method="getColdBoxOCM" />

<!-- Transfer -->
<bean id="Transfer" factory-bean="ColdBoxOCM" factory-method="get">
<constructor-arg name="objectKey"><value>Transfer</value></
constructor-arg>
</bean>

<!-- Login -->
<bean id="LoginService" class="model.login.LoginService"
singleton="true">
<constructor-arg name="Coldbox">
<ref bean="Coldbox" />
</constructor-arg>
<constructor-arg name="Transfer">
<ref bean="Transfer" />
</constructor-arg>
</bean>
<!-- /END - Login -->
</beans>


That's only a single instance of Transfer but does that look about
right?

Is there a way that I can call ColdBoxORM through the ColdBox bean
instead of having to declare it separately?

And finally am I right in assuming that I would use ColdBoxORM to call
my different instances of Transfer once I get them up and running? How
would I do that?

So many questions :-)

Cheers,
James

enigment

unread,
Sep 20, 2010, 4:42:57 PM9/20/10
to col...@googlegroups.com
Some of what you're doing here I'm not familiar with, but if each
service needs one or the other Transfer instance, maybe the cleanest
approach would be two next-base classes that extend your existing
base, with each one having the appropriate Transfer instance injected
into it. Essentially you have to "classes" of server, one with each
Transfer config.

If it's more dynamic than that, then your getTransfer method needs to
be more active than just retrieving a single injected item.

Make sense?

Dave

> --
> You received this message because you are subscribed to the Google Groups "ColdBox Platform" group.
> To post to this group, send email to col...@googlegroups.com
> To unsubscribe from this group, send email to coldbox-u...@googlegroups.com
> For more options, visit this group at http://groups-beta.google.com/group/coldbox
> For News, visit http://blog.coldbox.org
> For Documentation, visit http://wiki.coldbox.org
>

James Buckingham

unread,
Sep 20, 2010, 5:04:59 PM9/20/10
to ColdBox Platform
Thanks for the input Dave, appreciate it :-)

It kind of makes sense but the two base extensions would be exactly
the same apart from calling the CB config for the different Transfer
details

They'd basically contain a getColdBox() and getTransfer() method....
with the getTransfer() pulling in the custom details through
getColdBox(). Gut instinct is telling me that's not very reusable.

The Lightwire approach I'm trying to do is by telling it which
Transfer instance needs to be injected into which service when they're
called. The likelihood is we're not going to have a service needing
both Transfer instances so this should work ( He says :-) ).

I just can't get my head around the syntax.

Thanks again,
James

Luis Majano

unread,
Sep 20, 2010, 5:09:00 PM9/20/10
to col...@googlegroups.com
Dave, look at the transfer loader interceptor, you can declare more than 1 with all the information you need for each factory, very easy to do.

Luis F. Majano
President
Ortus Solutions, Corp

ColdBox Platform: http://www.coldbox.org
Linked In: http://www.linkedin.com/pub/3/731/483
Blog: http://www.luismajano.com
IECFUG Manager: http://www.iecfug.com

James Buckingham

unread,
Sep 20, 2010, 5:16:14 PM9/20/10
to ColdBox Platform
Hi Luis,

I have this at the moment, but how would I define another Transfer
Interceptor next to this one and how would I then call each one if /
when I need it?

interceptors = [
//Autowire
{class="coldbox.system.interceptors.Autowire",
properties={}
},
{class="coldbox.system.orm.transfer.TransferLoader",
properties={
configPath = "/config/transfer.enrolment.xml.cfm",
definitionPath = "/config/definitions/",
datasourceAlias = "enrolNow",
loadBeanInjector = true,
beanInjectorProperties = {
useSetterInjection = false
}
}
}];

I guess I need some kind of id or name attribute for each?

Cheers,
James

Luis Majano

unread,
Sep 20, 2010, 5:23:04 PM9/20/10
to col...@googlegroups.com
Yes, each interceptor can take  in a "name" attribute, so you will have to name them differently.  Also, the most important part is that you setup the cache keys for each interceptor property.  Read the docs, it tells you the keys for the 3 saved entries in cache, transfer, transferFactory and transferTransaction.  Each interceptor must name each key differently so they don't collide.



Luis F. Majano
President
Ortus Solutions, Corp

ColdBox Platform: http://www.coldbox.org
Linked In: http://www.linkedin.com/pub/3/731/483
Blog: http://www.luismajano.com
IECFUG Manager: http://www.iecfug.com


James Buckingham

unread,
Sep 28, 2010, 3:49:36 PM9/28/10
to ColdBox Platform
Just to close off this one, in case anyone else searches for it,
here's what I've now got in place and working :-

ColdBox.cfc
=========

//Register interceptors as an array, we need order
interceptors = [
//Autowire
{class="coldbox.system.interceptors.Autowire",
properties={}
},
// Transfer - Enrolnow
{class="coldbox.system.orm.transfer.TransferLoader",
properties={
configPath = "/config/xxxxx",
definitionPath = "/config/definitions/",
datasourceAlias = "xxxxxxx",
loadBeanInjector = true,
transferFactoryCacheKey = "TransferFactory_EnrolNow",
transferCacheKey = "Transfer_EnrolNow",
transferTransaction = "TransferTransaction_EnrolNow",
beanInjectorProperties = {
useSetterInjection = false
}
}
},
// Transfer - SITS
{class="coldbox.system.orm.transfer.TransferLoader",
properties={
configPath = "/config/xxxxxx",
definitionPath = "/config/definitions/",
datasourceAlias = "xxxxxxxxxxxx",
loadBeanInjector = true,
transferFactoryCacheKey = "TransferFactory_SITS",
transferCacheKey = "Transfer_SITS",
transferTransaction = "TransferTransaction_SITS",
beanInjectorProperties = {
useSetterInjection = false
}
}
}
];

In the lightwire configuration file I've now got this....

<!-- Coldbox -->
<bean id="ColdboxFactory" class="coldbox.system.ioc.ColdboxFactory" /
>
<bean id="Coldbox" factory-bean="ColdBoxFactory" factory-
method="getColdbox" />
<bean id="ColdboxOCM" factory-bean="ColdBoxFactory" factory-
method="getColdBoxOCM" />

<!-- Transfer -->
<!-- Enrol -->
<bean id="Transfer_EnrolNow" factory-bean="ColdBoxOCM" factory-
method="get">
<constructor-arg name="objectKey"><value>Transfer_EnrolNow</value></
constructor-arg>
</bean>

<!-- SITS -->
<bean id="Transfer_SITS" factory-bean="ColdBoxOCM" factory-
method="get">
<constructor-arg name="objectKey"><value>Transfer_SITS</value></
constructor-arg>
</bean>

So if I need any of these in my services I just pass them in like
so....

<!-- Login -->
<bean id="LoginFacade" class="model.login.LoginFacade"
singleton="true">
<constructor-arg name="Coldbox">
<ref bean="Coldbox" />
</constructor-arg>
<constructor-arg name="Transfer">
<ref bean="Transfer_EnrolNow" />
</constructor-arg>
</bean>


A very special thanks to Tom de Manincor for his help on getting this
up and running ;-).

Cheers,
James
Reply all
Reply to author
Forward
0 new messages