Is it just me or does anyone else think that Query as in <cfset myRecords = QueryNew("col_a, col_b, etc") /> should be called RecordSet, like <cfset myRecords = RecordSetNew("col_a, col_b, etc") />, I was so damn confused when Dave tried to explain this code to me earlier, and only after reading this post did I get that he wasn't talking about an SQL Query. It's kind of odd. Isn't the result of <cfquery ...> a RecordSet, not a Query? It's always bugged me. Semantics. Baaaagggh...


Chris Scott




On Feb 24, 2006, at 12:23 PM, Dave Ross wrote:

Jared asked for this one a while ago, and since it was on the 1.0
final knockdown list, I took a stab at it this morning. Instead of
adding new syntax to the xml, like <query/> or <recordset/>, I simply
wrote a helper class that uses our new factory-method support to
generate queries.

coldspring.beans.util.QueryCreatingFactoryBean is a factory bean which
creates queries. The factory method createQuery takes two arguments,
both arrays. The first argument, "columnNames", is a flat array of
names for each column in the query you are creating. The second
argument, "data", is a nested array, one array for each row,
containing an array of data for each column. Here's an example of how
this would look in the xml:

    <bean id="QueryFactory"
class="coldspring.beans.util.QueryCreatingFactoryBean"/>

    <bean id="beanWithQuery" class="some.bean">
        <property name="SomeQuery">
            <bean factory-bean="QueryFactory" factory-method="createQuery">
                <constructor-arg name="ColumnNames">
                    <list>
                        <value>col1</value>
                        <value>col2</value>
                        <value>col3</value>
                    </list>
                </constructor-arg>
                <constructor-arg name="Data">
                    <list>
                        <list>
                            <value>data1</value>
                            <value>data2</value>
                            <value>data3</value>
                        </list>
                        <list>
                            <value>data3</value>
                            <value>data4</value>
                            <value>data5</value>
                        </list>
                    </list>
                </constructor-arg>
            </bean>
        </property>
    </bean>

As you can see beanWithQuery is populated with SomeQuery using the
QueryCreatingFactoryBean we set up. In order to support this, I had to
expand our factory-bean/factory-method support into "inner beans"
(<bean/>s defined within other <bean/>s), which is a good thing.

Feel free to check out the latest from CVS if you want to play around.

-Dave


Reply via email to