I agree with Fedor.
It is terrible to change from criteria to Query.
Regards
fanyun
-----原始邮件-----
发件人: Fedor Karpelevitch [mailto:[EMAIL PROTECTED]]
发送时间: 2001年5月11日 11:34
收件人: [EMAIL PROTECTED]
主题: Re: [PROPOSAL] New Query Model
The thing I do not like about you proposal (vs. mine) as well as about
current Criteria is the fact that you are mixing together different things
which deserve a clear separation. What I mean is that you are using Query in
some context as query ( with all it's attributes ) and in some contexts (when
you pass it to add method) you ignore use only condition part of it and
ignore other attributes. This makes me feel bad about it. In my opinion, when
you need a condition, you should use a Condition object, when you need a
query you use a Query etc, etc. Everything should serve it's purpose, not
more or less. And the code you are producing looks not much more like SQL
besides that I do not see why it should. See some more comments below....
On Thursday 10 May 2001 18:01, you wrote:
> On Thursday, May 10, 2001, at 09:48 AM, Eric Dobbs wrote:
> > I am working on some example code to implement the above which I
> > will send soon for comparison and discussion.
>
> Attached is a tarball of some example code. A few notes:
> I've spent more time writing and verifying test cases than I have
> in writing comments. The present example supports fairly complex
> SELECT queries. INSERT, UPDATE, and DELETE are incomplete. And
> it requires a patch to TableColumn.java which I include in the
> body of this message below. I've chosen to put this stuff in
> package org.apache.turbine.util.db.query;
>
> The most interesting test case is as follows:
>
> Query q = new Query(Query.SELECT)
> .addSelectColumn(column1)
> .addSelectColumn(column2)
> .addSelectColumn(column3)
> .addSelectColumn(column4)
> .where(column1,column3,Query.EQUAL)
just to make sure.. Do you realize that column3 here (which, I think, is a
String) is indistinguishible from a String you'd like to compare column1 to?
i.e. how would you go about:
.where(column1, "somevalue", Query.EQUAL) ?
> .and(column2,"'foo%'",Query.LIKE)
this is also looks very questionable to me. Why the first condition is added
with where() and all the other ones - with an add(). I do not like two
functions doing the same thing. It's just plain wrong.
> .and(new Query()
> .where(column4,new Integer(1),Query.EQUAL)
now this does not look like SQL at all - would that be :
... AND (WHERE column4=1 OR ...) ....
not really...
> .or(column4,new Integer(6),Query.EQUAL)
> .or(column4,new Integer(15),Query.EQUAL))
> .orderBy(column2,Query.ASC);
>
> which produces this output (linewrapped here for readability):
> SELECT
> TABLE1.COLUMN1,
> TABLE1.COLUMN2,
> TABLE2.COLUMN1,
> TABLE2.COLUMN2
> FROM
> TABLE1,
> TABLE2
> WHERE
> (TABLE1.COLUMN1=TABLE2.COLUMN1
> AND TABLE1.COLUMN2 LIKE 'foo%'
> AND (TABLE2.COLUMN2=1
> OR TABLE2.COLUMN2=6
> OR TABLE2.COLUMN2=15))
> ORDER BY
> TABLE1.COLUMN2 ASC
>
> On Thursday, May 10, 2001, at 06:03 PM, Daniel Rall wrote:
> > For your suggested model, preferable would be:
> >
> > Query q = new Insert()
> > .setColumn(tableColumn1,value1)
>
> Excellent suggestion. Thank you. I'll try to implement that
> soon and post another tarball.
>
> -Eric
>
> ps. here's the patch I promised. I need the getters in a
> couple places, and I think I need the empty constructor for
> my TableColumnOrder subclass.
>
> Index: TableColumn.java
> ===================================================================
> RCS file: /home/cvspublic/jakarta-
> turbine/src/java/org/apache/turbine/util/db/TableColumn.java,v
> retrieving revision 1.2
> diff -u -r1.2 TableColumn.java
> --- TableColumn.java 2001/03/06 06:14:01 1.2
> +++ TableColumn.java 2001/05/11 00:34:49
> @@ -76,13 +76,30 @@
> * The concatenation of the table name and column name separated
> with a
> * dot.
> */
> - private String tableColumn;
> + protected String tableColumn;
>
> + public TableColumn()
> + {
> + //empty
> + }
> +
> public TableColumn(String tableName, String columnName)
> {
> this.tableName = tableName;
> this.columnName = columnName;
> this.tableColumn = (tableName + '.' + columnName);
> + }
> +
> + /** return the table name as a String */
> + public String getTable()
> + {
> + return this.tableName;
> + }
> +
> + /** return the column name as a String */
> + public String getColumn()
> + {
> + return this.columnName;
> }
>
> /**
>
>
> <Attachment missing>
----------------------------------------
Content-Type: text/plain; charset="us-ascii"; name="Attachment: 1"
Content-Transfer-Encoding: 7bit
Content-Description:
----------------------------------------
----------------------------------------
Content-Type: application/x-gzip; charset="us-ascii"; name="query.tar.gz"
Content-Transfer-Encoding: base64
Content-Description:
----------------------------------------
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]