Gateway.getByFilter - new function... OMG!

7 views
Skip to first unread message

Mark Drew

unread,
Jul 10, 2009, 11:06:44 AM7/10/09
to reacto...@googlegroups.com, reacto...@googlegroups.com
Dear Users

Hallo there, I bet you are surprised there is an email from me right? Anyway, I have been busy adding a little feature that should make using  gatewauys and object oriented quieries a tad easier :) 

Easier you say? I am sure you want some of that action right? So, what I have added to a gateway is the ability to do the following, lets start with a big example of code and work our way through it. So imagine you have a table of blog posts, and you want to get all the published ones, in order of date, and you want to paginate it.... how would you do this with reactor currently:

1) Create a custom function in your gateway
2) Go nuts with the Object Oriented Queries.

I say NO, dont do that! Do this:


Posts = reactor.getByFilter(
include={siteid=1, approved=1},
exclude={deleted=1},
contains={title="elvis"}
orderby={publicationDate="DESC"},
page=1,
rows=10
);


So what am I doing here? Well its actually rather easy...  the get by filter takes in a number of structs and variables, the include, excliude and contains structs are key value pairs of things to include (Where X=Y), the things to exclude is another struct of things to exclude and the contains is to search for , in this example where title has the word "elvis" in it

The order by close you can add various fields with either DESC and ASC on it to order it

you can also paginate results! yes! you have to just ask which page you want to get and how many rows per page you want.

Careful tho, the pagination only works natively with mySQL, I have added code that makes it work across databases but it fakes it for other db's by doing a cfloop

what else is there?

Oh yeah, well it normally returns a query by default, but I am sure you might want to do format="iterator" If you want to return an iterating business object, this is kinda flakey as I want to just return an iterator object but didnt have time to really look into ti

I have checked it all in so hopefully it should make your working life easier. 

Regards

Mark Drew


denstar

unread,
Jul 11, 2009, 1:27:34 AM7/11/09
to reacto...@googlegroups.com
On Fri, Jul 10, 2009 at 9:06 AM, Mark Drew<mark...@gmail.com> wrote:
> Dear Users
> Hallo there, I bet you are surprised there is an email from me right?
> Anyway, I have been busy adding a little feature that should make using
>  gatewauys and object oriented quieries a tad easier :)
...

Sweet!

...

Guess everyone else has already gone home for the weekend. :-)

Nice to see that revision number go up. Real nice.

--
I've got a great ambition to die of exhaustion rather than boredom.
Thomas Carlyle

Jared Rypka-Hauer

unread,
Jul 14, 2009, 3:17:44 PM7/14/09
to reacto...@googlegroups.com
Hot damn dude... that rawks!

J

On Jul 10, 2009, at 10:06 AM 7/10/09, Mark Drew wrote:

... Posts = reactor.getByFilter(

Gareth Cole

unread,
Jul 15, 2009, 3:24:43 PM7/15/09
to reacto...@googlegroups.com

Erm.. I think this may have introduced a bug

 

When I try to load a record, I get this error:

Invalid CFML construct found on line 198 at column 38.

 

ColdFusion was looking at the following text:

contains

The CFML compiler was processing:

  • The tag attribute collection, on line 198, column 25.
  • A cfloop tag beginning on line 198, column 18.
  • A cfloop tag beginning on line 198, column 18.

 

 

The error occurred in C:\sites\ xxxxxxxxxx\reactor\base\abstractGateway.cfc: line 198
Called from C:\sites\xxxxxxxxxxxxxx\reactor\core\objectFactory.cfc: line 164
Called from C:\sites\ xxxxxxxxxxxxxx \reactor\reactorFactory.cfc: line 53
Called from C:\sites\ xxxxxxxxxxxxxx \reactor\project\ xxxxxxxx\Dao\CellDao.cfc: line 229
Called from C:\sites\ xxxxxxxxxxxxxx \reactor\base\abstractRecord.cfc: line 106
Called from C:\sites\ xxxxxxxxxxxxxx \wwwroot\test.cfm: line 8

196 :          
197 :          <!--- Do the contains --->     
198 :          <cfloop collection="#contains#" item="cont">
199 :                          <cfset Where.isLike(TableName,cont, contains[cont])>
200 :          </cfloop>

 

This is on Coldfusion 8. My guess is that 'contains' is a reserved word in adobe CF, but not in Railo. Commenting out the loop fixes things, but obviously I lose the new feature.

Mark Drew

unread,
Jul 16, 2009, 4:38:51 AM7/16/09
to reacto...@googlegroups.com
Well spotted! 

I have changed it to :

<cfloop collection="#arguments.contains#" item="cont">
<cfset Where.isLike(TableName,cont, arguments.contains[cont])>
</cfloop>

That should do the trick?

I shall commit this shortly

MD

Doug Hughes

unread,
Jul 16, 2009, 8:13:26 AM7/16/09
to reacto...@googlegroups.com
I ran into this too, BTW.

Doug Hughes, President
Alagad Inc.
dhu...@alagad.com
888 Alagad4 (x300)
Office: 919-550-0755
Fax: 888-248-7836

Mark Drew

unread,
Jul 16, 2009, 8:15:56 AM7/16/09
to reacto...@googlegroups.com
Check out the latest, there are other functionality I am adding, which hopefully your hair will be blown away! Mine already has! :D

Gareth Cole

unread,
Jul 22, 2009, 12:09:52 PM7/22/09
to reacto...@googlegroups.com

I think I've found another CF bug, and a small enhancement.

 

Line 176 of abstractGateway.cfc was:

var TableName = this.getObjectMetadata().getName();

 

I had to change this to:

var TableName = getObjectMetadata().getAlias();

 

First, the 'this' keyword caused problems in cf. I think it referred to the sub-class (userGateway in my case) scope, as I got a message that it couldn't find getObjectmetadata() in UserGateway.cfc.

 

Secondly, I changed getName() to getAlias() so it works for aliased table names too.

 

-----Original Message-----
From: reacto...@googlegroups.com [mailto:reacto...@googlegroups.com] On Behalf Of Mark Drew
Sent: 10 July 2009 16:07
To: reacto...@googlegroups.com
Cc: reacto...@googlegroups.com
Subject: [reactor-users] Gateway.getByFilter - new function... OMG!

 

Dear Users

Tom Chiverton

unread,
Jul 23, 2009, 6:46:23 AM7/23/09
to reacto...@googlegroups.com
On Wednesday 22 Jul 2009, Gareth Cole wrote:
> I think I've found another CF bug, and a small enhancement.

Logged, cheers Gareth.

--

Tom Chiverton
Developer

Tom.Ch...@halliwells.com
3 Hardman Square, Manchester, M3 3EB

****************************************************

This email is sent for and on behalf of Halliwells LLP.

Halliwells LLP is a limited liability partnership registered in England and Wales under registered number OC307980 whose registered office address is at Halliwells LLP, 3 Hardman Square, Spinningfields, Manchester, M3 3EB. A list of members is available for inspection at the registered office together with a list of those non members who are referred to as partners. We use the word ?partner? to refer to a member of the LLP, or an employee or consultant with equivalent standing and qualifications. Regulated by the Solicitors Regulation Authority.

CONFIDENTIALITY

This email is intended only for the use of the addressee named above and may be confidential or legally privileged. If you are not the addressee you must not read it and must not use any information contained in nor copy it nor inform any person other than Halliwells LLP or the addressee of its existence or contents. If you have received this email in error please delete it and notify Halliwells LLP IT Department on 0870 365 2500.

For more information about Halliwells LLP visit
www.Halliwells.com.

Rand

unread,
Jul 27, 2009, 7:02:24 PM7/27/09
to Reactor
Mark, I'm implementing this on a system that still uses CF7, is there
a simpler way to do the following, or is this the only way pre-CF8?

included.siteid = 1;
included.approved = 1;
excluded.deleted = 1;
containing.title = "elvis";
orderedby.publicationdate = "DESC";

Posts = reactor.getByFilter(
include=included,
exclude=excluded,
contains=containing,
orderby=orderedby,
page=1,
rows=10
);


-Rand

Tom Chiverton

unread,
Jul 28, 2009, 4:27:17 AM7/28/09
to reacto...@googlegroups.com
On Tuesday 28 Jul 2009, Rand wrote:
> Mark, I'm implementing this on a system that still uses CF7, is there
> a simpler way to do the following, or is this the only way pre-CF8?

Did CF7 have argumentCollection ?


--

Tom Chiverton
Developer

Tom.Ch...@halliwells.com
3 Hardman Square, Manchester, M3 3EB

****************************************************

This email is sent for and on behalf of Halliwells LLP.

Halliwells LLP is a limited liability partnership registered in England and Wales under registered number OC307980 whose registered office address is at Halliwells LLP, 3 Hardman Square, Spinningfields, Manchester, M3 3EB. A list of members is available for inspection at the registered office together with a list of those non members who are referred to as partners. We use the word “partner” to refer to a member of the LLP, or an employee or consultant with equivalent standing and qualifications. Regulated by the Solicitors Regulation Authority.



CONFIDENTIALITY

This email is intended only for the use of the addressee named above and may be confidential or legally privileged. If you are not the addressee you must not read it and must not use any information contained in nor copy it nor inform any person other than Halliwells LLP or the addressee of its existence or contents. If you have received this email in error please delete it and notify Halliwells LLP IT Department on 0870 365 2500.

For more information about Halliwells LLP visit

Rand Thacker

unread,
Jul 28, 2009, 11:42:15 AM7/28/09
to reacto...@googlegroups.com
Yes, it does, and that works wonderfully.

Thanks,

Rand
--
"I am the most humble person in the world!"

Rand

unread,
Jul 30, 2009, 7:02:30 PM7/30/09
to Reactor
OK, I'm loving this function. I was wondering if, using the current
function, one might be able to do:
startDate >= '01/01/2009' AND startDate <= '12/31/2009'

Or if there might be some future enhancements that might take care of
that kind of date-specific fun?

On Jul 10, 10:06 am, Mark Drew <mark.d...@gmail.com> wrote:

Tom Chiverton

unread,
Aug 4, 2009, 4:58:00 AM8/4/09
to reacto...@googlegroups.com
On Friday 31 Jul 2009, Rand wrote:
> OK, I'm loving this function. I was wondering if, using the current
> function, one might be able to do:
> startDate >= '01/01/2009' AND startDate <= '12/31/2009'

Like :
Posts = gateway.getByFilter( include={siteid=1, approved=1},

exclude={deleted=1},
contains={title="elvis"}
between={publishedDate={aDate,bDate}}
)
?

I think only Railo and CF9 support that nested syntax. I also think that:
Posts = gateway.getByFilter( include={siteid=1, approved=1},

exclude={deleted=1},
contains={title="elvis"}
from={publishedDate=aDate},
to={publishedDate=bDate}
)
is a lot clearer too.

What do people think ?

Tom Chiverton

unread,
Aug 4, 2009, 5:22:49 AM8/4/09
to reacto...@googlegroups.com
On Tuesday 04 Aug 2009, Tom Chiverton wrote:
> from={publishedDate=aDate},
> to={publishedDate=bDate}
> )

To clarify, you can give either, both or none of from and to.


--

Tom Chiverton
Developer

Tom.Ch...@halliwells.com
3 Hardman Square, Manchester, M3 3EB

****************************************************

This email is sent for and on behalf of Halliwells LLP.

Halliwells LLP is a limited liability partnership registered in England and Wales under registered number OC307980 whose registered office address is at Halliwells LLP, 3 Hardman Square, Spinningfields, Manchester, M3 3EB. A list of members is available for inspection at the registered office together with a list of those non members who are referred to as partners. We use the word ?partner? to refer to a member of the LLP, or an employee or consultant with equivalent standing and qualifications. Regulated by the Solicitors Regulation Authority.



CONFIDENTIALITY

This email is intended only for the use of the addressee named above and may be confidential or legally privileged. If you are not the addressee you must not read it and must not use any information contained in nor copy it nor inform any person other than Halliwells LLP or the addressee of its existence or contents. If you have received this email in error please delete it and notify Halliwells LLP IT Department on 0870 365 2500.

For more information about Halliwells LLP visit

Rand Thacker

unread,
Aug 4, 2009, 10:38:59 AM8/4/09
to reacto...@googlegroups.com
So the FROM would basically be a >= and the TO would be a <=...

I like that idea.  It allows for even more scenarios that I have run across recently.

ol...@ansit.no

unread,
Oct 20, 2009, 7:33:07 AM10/20/09
to reacto...@googlegroups.com

I'm having a problem with the getByFilter method and the orderby structure
whitch accoring to Mike's initial post should be able to handle various
fields and any combination of ASC/DESC sorting.

. . . The order by close you can add various fields with either DESC and
ASC on it to order it . . .


<set name="orderedby.FIR_NAVN" value="ASC" />
<set name="orderedby.PST_STED" value="ASC" />
<invoke object="Application.VfiGateway"
methodcall="getByFilter(orderby=orderedby)" returnvariable="qry" />

generates the following SQL under ....\reactor\project\....

SELECT "V_FIRMA"."FIR_ID" AS "FIR_ID", "V_FIRMA"."FIR_ORGNR" AS
"FIR_ORGNR", "V_FIRMA"."FIR_NAVN" AS "FIR_NAVN", "V_FIRMA"."FIR_FADRESSE"
AS "FIR_FADRESSE", "V_FIRMA"."FIR_FADRESSE_POSTNR" AS
"FIR_FADRESSE_POSTNR", "V_FIRMA"."PST_STED" AS "PST_STED",
"V_FIRMA"."FIR_TELEFON" AS "FIR_TELEFON",
"V_FIRMA"."FIR_KONTAKTPERSON_NAVN" AS "FIR_KONTAKTPERSON_NAVN" FROM
"DROPBOX"."V_FIRMA" "V_FIRMA"
ORDER BY "V_FIRMA"."PST_STED" ASC , "V_FIRMA"."FIR_NAVN" ASC

How can I controll the sequence of the elements in the generated ORDER BY
statement?

Olav A. Antonsen
Developer, Oslo, Norway


On Tue, 4 Aug 2009 09:38:59 -0500, Rand Thacker <rand.t...@gmail.com>
wrote:

Tom Chiverton

unread,
Oct 28, 2009, 12:26:18 PM10/28/09
to reacto...@googlegroups.com
On Tuesday 20 Oct 2009, ol...@ansit.no wrote:
> How can I controll the sequence of the elements in the generated ORDER BY
> statement?

Hmm, this is a good point.
I expect Reactor doesn't promise anything about the order when you do this.

I wonder if Reactor should support orderby being an array of struts (key/value
pairs) ?
Do people feel this should be as well as or instead of the current system ?

--

Tom Chiverton
Developer

Tom.Ch...@halliwells.com
3 Hardman Square, Manchester, M3 3EB

****************************************************

This email is sent for and on behalf of Halliwells LLP.

Halliwells LLP is a limited liability partnership registered in England and Wales under registered number OC307980 whose registered office address is at Halliwells LLP, 3 Hardman Square, Spinningfields, Manchester, M3 3EB. A list of members is available for inspection at the registered office together with a list of those non members who are referred to as partners. We use the word “partner” to refer to a member of the LLP, or an employee or consultant with equivalent standing and qualifications. Regulated by the Solicitors Regulation Authority.



CONFIDENTIALITY

This email is intended only for the use of the addressee named above and may be confidential or legally privileged. If you are not the addressee you must not read it and must not use any information contained in nor copy it nor inform any person other than Halliwells LLP or the addressee of its existence or contents. If you have received this email in error please delete it and notify Halliwells LLP IT Department on 0870 365 2500.

For more information about Halliwells LLP visit

Tom Chiverton

unread,
Nov 9, 2009, 5:42:10 AM11/9/09
to reacto...@googlegroups.com
On Wednesday 28 Oct 2009, Tom Chiverton wrote:
> On Tuesday 20 Oct 2009, ol...@ansit.no wrote:
> > How can I controll the sequence of the elements in the generated ORDER BY
> > statement?
>
> Hmm, this is a good point.
> I expect Reactor doesn't promise anything about the order when you do this.
>
> I wonder if Reactor should support orderby being an array of struts
> (key/value pairs) ?
> Do people feel this should be as well as or instead of the current system ?

Would it be even easier for people if they could provide an
optional 'orderByOrder' list parameter ?


<set name="orderedby.FIR_NAVN" value="ASC" />
<set name="orderedby.PST_STED" value="ASC" />
<invoke object="Application.VfiGateway"
methodcall="getByFilter(orderby=orderedby,orderByOrder='PST_STED,FIR_NAVN')"
returnvariable="qry" />


?
--

Tom Chiverton
Developer

Tom.Ch...@halliwells.com
3 Hardman Square, Manchester, M3 3EB

****************************************************

This email is sent for and on behalf of Halliwells LLP.

Halliwells LLP is a limited liability partnership registered in England and Wales under registered number OC307980 whose registered office address is at Halliwells LLP, 3 Hardman Square, Spinningfields, Manchester, M3 3EB. A list of members is available for inspection at the registered office together with a list of those non members who are referred to as partners. We use the word ?partner? to refer to a member of the LLP, or an employee or consultant with equivalent standing and qualifications. Regulated by the Solicitors Regulation Authority.



CONFIDENTIALITY

This email is intended only for the use of the addressee named above and may be confidential or legally privileged. If you are not the addressee you must not read it and must not use any information contained in nor copy it nor inform any person other than Halliwells LLP or the addressee of its existence or contents. If you have received this email in error please delete it and notify Halliwells LLP IT Department on 0870 365 2500.

For more information about Halliwells LLP visit

Mark Drew

unread,
Nov 9, 2009, 4:47:37 AM11/9/09
to reacto...@googlegroups.com
I think I have some code to check in regarding this, in fact I have a lot of code to check-in including being able to inject services into your generated reactor objects. 

Will do when I get to Melbourne and back online since I need to synch a lot of stuff.

I am also playing with hibernate and changing how we find out what columns/tables there are in the DB by using cfdbinfo since under some cases, mysql reports erroneous data with the current queries

MD

Tom Chiverton

unread,
Nov 9, 2009, 10:57:04 AM11/9/09
to reacto...@googlegroups.com
On Monday 09 Nov 2009, Mark Drew wrote:
> Will do when I get to Melbourne and back online since I need to synch
> a lot of stuff.

I did that sand boxing fix over the weekend by the way.


> I am also playing with hibernate and changing how we find out what
> columns/tables there are in the DB by using cfdbinfo since under some
> cases, mysql reports erroneous data with the current queries

You mean rewriting the MySQL adaptor so it uses cfdbinfo where available ?

Mark Drew

unread,
Nov 19, 2009, 2:31:59 AM11/19/09
to reacto...@googlegroups.com
I thought I would mention I put a number of fixes into SVN tonight, including a fix that allows injecting services into your created beans. It isn't as complete as I would like it and will spend some time fixing it up so that it works properly, but essentially, if you configure ractor via coldspring like so:


<bean id="reactorConfiguration" class="reactor.config.config">
<constructor-arg name="pathToConfigXml"><value>/config/reactor.xml.cfm</value></constructor-arg>
<property name="project"><value>MyProject</value></property>
<property name="dsn"><value>myDSN</value></property>
<property name="type"><value>mysql</value></property>
<property name="mapping"><value>/model/reactor</value></property>
<property name="mode"><value>production</value></property>
</bean>


<bean id="reactor" class="reactor.reactorFactory">
<constructor-arg name="configuration"><ref bean="reactorConfiguration"/></constructor-arg>
</bean>


You can then add the following configs to inject services into your records,gateways and in fact any generated object:



<bean id="MyRecordInjector" class="reactor.core.Injector">
<property name="target"><value>SomeRecordMySQL</value></property>
<property name="beans"><value>SomeService</value></property>
</bean>


Where 

<bean id="SomeService" class="services.SomeService" />


The fix that I need to do is so that you don't have to define the DB type when you are defining the record or gateway

Within the record you can now refer to that service as:


<cfset something = variables.SomeService.DoSomething()>


Regards

Mark Drew

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Reactor" group.
To post to this group, send email to reacto...@googlegroups.com
To unsubscribe from this group, send email to reactor-user...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/reactor-users?hl=en
-~----------~----~----~----~------~----~------~--~---


Tom Chiverton

unread,
Nov 23, 2009, 10:17:55 AM11/23/09
to reacto...@googlegroups.com
On Thursday 19 Nov 2009, Mark Drew wrote:
> <bean id="MyRecordInjector" class="reactor.core.Injector">
> <property name="target"><value>SomeRecordMySQL</value></property>
> <property name="beans"><value>SomeService</value></property>
> </bean>

That's cool !
Do you want to blog it and I'll wiki it, or the other way around ?

Mark Drew

unread,
Nov 23, 2009, 1:03:57 PM11/23/09
to reacto...@googlegroups.com
I shall do! 

Good plan

I can also esplain the getByFilter ( I have added a whole bunch of new functionality I need to pass through to the main build)

MD


--

You received this message because you are subscribed to the Google Groups "Reactor" group.
To post to this group, send email to reacto...@googlegroups.com.
To unsubscribe from this group, send email to reactor-user...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/reactor-users?hl=.

Reply all
Reply to author
Forward
0 new messages