You are viewing a plain text version of this content. The canonical link for it is here.
Posted to torque-user@db.apache.org by de...@freenet.de on 2003/10/31 13:37:27 UTC

Re: Re: Problem OR\\\'ing criterias

Thanks, any hints are highly appreciated 
;-)
--- original Nachricht Ende ----


I had the exact same problem, it seems that or() adds "AND" to the
query string!

no time to check the source code yet... will let you know if something
arises

Tulsi

 --- denis.griesmeyer@freenet.de escribió: 
> Hello torque-users,
> 
> I have a problem with OR'ing criterias. 
> 
> The code is as follows:
> 
> ---SNIP---
> 
> Criteria crit = new Criteria();
> 		
> crit.or (SongsPeer.ARTIST,(Object)searchString,Criteria.LIKE);
> crit.or (SongsPeer.TITLE,(Object)searchString,Criteria.LIKE);
> crit.or (SongsPeer.ALBUM,(Object)searchString,Criteria.LIKE);
> 
> ---SNIP---
> 
> I would expect the query to look sth. like this:
> 
> ---SNIP---
> ...
> FROM SONGS 
> WHERE SONGS.ALBUM LIKE '%4%' OR SONGS.TITLE LIKE '%4%' OR
> SONGS.ARTIST LIKE '%4%'
> ---SNIP---
> 
> But instead it AND's all X LIKE Y's together... :-(
> 
> Maybe I missunderstood some of the basic concepts of torque... 
> 
> Can someone give me a hint please?
> 
> Thanks in advance
> Denis
> 
> 
> -- 
> eBay - Jetzt besser einkaufen!
> Ueber 1. Mio. Angebote. Startpreise ab EUR 1,-
> <a href='http://www.freenet.de/tipp/shopping/ebay' target='_blank'><u>http://www.freenet.de/tipp/shopping/ebay</u></a>
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
> For additional commands, e-mail: torque-user-help@db.apache.org
>  

------------
Internet GRATIS es Yahoo! Conexión
4004-1010 desde Buenos Aires. Usuario: yahoo; contraseña: yahoo
Más ciudades: <a href='http://conexion.yahoo.com.ar' target='_blank'><u>http://conexion.yahoo.com.ar</u></a>

---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org




-- 
Nur 1x anmelden
und automatisch bis zu 1200 Produktproben und Gutscheine erhalten!
http://www.freenet.de/tipp/shopping/probenking/index.html

---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org


Re: Problem OR\\\'ing criterias

Posted by Denis Griesmeyer <de...@freenet.de>.
I made it finally. The following snippet does exactly what I wanted:

searchString = "%" + searchString + "%";

Criteria crit = new Criteria();

Criteria.Criterion CArtist = crit.getNewCriterion(SongsPeer.ARTIST,(Object)searchString,Criteria.LIKE);

Criteria.Criterion CTitle  = crit.getNewCriterion(SongsPeer.TITLE ,(Object)searchString,Criteria.LIKE);

Criteria.Criterion CAlbum  = crit.getNewCriterion(SongsPeer.ALBUM,(Object)searchString,Criteria.LIKE);

crit.add (CArtist.or(CTitle).or(CAlbum));

List foundSongs = SongsPeer.doSelect(crit);


I found an explanation in the Peers howto document right at the end. 
(http://db.apache.org/torque/peers-howto.html)

Thanks to the list for helping.

Cheers,
Denis

Amine Bousta wrote:

>Hello,
>
>I've experienced the same problem with "or" and "Criteria.LIKE". "or" was
>replaced by "and" and "Like" by "=".
>Then I tried to use Criterion but it was too complicated and it didn't work
>as well.
>So I've used a sql query and I ran an "executeQuery" instead of a
>"doSelect".
>
>When I succeeded in running the sql query I wondered what was the real use
>of "Criterions".
>In my opinion, using a normal "select" query is much readable and powerful
>for where clauses.
>With SQL you can easily manage parenthesis and all of the sql functions like
>substring and else.... There is no bug with OR or IN, you can join tables
>easily...
>Why using Criteria that builds itself a sql query with limited options
>instead of directly writting it?
>
>I'm not blindly blaming the Criteria object but it's just a honest question
>about the advantages of this.
>So if anybody could light this point for me....
>
>Thanks
>Amine
>
>
>
>-----Message d'origine-----
>De : denis.griesmeyer@freenet.de [mailto:denis.griesmeyer@freenet.de]
>Envoyé : vendredi 31 octobre 2003 13:37
>À : Apache Torque Users List
>Objet : Re: Re: Problem OR\\\'ing criterias
>
>
>Thanks, any hints are highly appreciated
>;-)
>--- original Nachricht Ende ----
>
>
>I had the exact same problem, it seems that or() adds "AND" to the
>query string!
>
>no time to check the source code yet... will let you know if something
>arises
>
>Tulsi
>
> --- denis.griesmeyer@freenet.de escribió:
>  
>
>>Hello torque-users,
>>
>>I have a problem with OR'ing criterias.
>>
>>The code is as follows:
>>
>>---SNIP---
>>
>>Criteria crit = new Criteria();
>>
>>crit.or (SongsPeer.ARTIST,(Object)searchString,Criteria.LIKE);
>>crit.or (SongsPeer.TITLE,(Object)searchString,Criteria.LIKE);
>>crit.or (SongsPeer.ALBUM,(Object)searchString,Criteria.LIKE);
>>
>>---SNIP---
>>
>>I would expect the query to look sth. like this:
>>
>>---SNIP---
>>...
>>FROM SONGS
>>WHERE SONGS.ALBUM LIKE '%4%' OR SONGS.TITLE LIKE '%4%' OR
>>SONGS.ARTIST LIKE '%4%'
>>---SNIP---
>>
>>But instead it AND's all X LIKE Y's together... :-(
>>
>>Maybe I missunderstood some of the basic concepts of torque...
>>
>>Can someone give me a hint please?
>>
>>Thanks in advance
>>Denis
>>
>>
>>--
>>eBay - Jetzt besser einkaufen!
>>Ueber 1. Mio. Angebote. Startpreise ab EUR 1,-
>><a href='http://www.freenet.de/tipp/shopping/ebay'
>>    
>>
>target='_blank'><u>http://www.freenet.de/tipp/shopping/ebay</u></a>
>  
>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
>>For additional commands, e-mail: torque-user-help@db.apache.org
>>
>>    
>>
>
>------------
>Internet GRATIS es Yahoo! Conexión
>4004-1010 desde Buenos Aires. Usuario: yahoo; contraseña: yahoo
>Más ciudades: <a href='http://conexion.yahoo.com.ar'
>target='_blank'><u>http://conexion.yahoo.com.ar</u></a>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
>For additional commands, e-mail: torque-user-help@db.apache.org
>
>
>
>
>--
>Nur 1x anmelden
>und automatisch bis zu 1200 Produktproben und Gutscheine erhalten!
>http://www.freenet.de/tipp/shopping/probenking/index.html
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
>For additional commands, e-mail: torque-user-help@db.apache.org
>
>
>
>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
>For additional commands, e-mail: torque-user-help@db.apache.org
>
>
>
>  
>


Re: Problem with jdbc 2 XML

Posted by Loïc Minier <lo...@via.ecp.fr>.
Amine Bousta <ab...@lxsolutions.com> - Wed, Nov 05, 2003:

> I'm experiencing a lot of problems by trying to generate an xml schema from
> a sql file.
> I'm using Mysql with InnoDB tables and foreign keys.
> I'm trying to launch ant on build-torque.xml with the "jdbc" option.

 I'm new to Torque, but isn't the jdbc target reserved
 to Oracle databases? (This is how I understand
 the description of torque.database.schema at
 <http://db.apache.org/torque/properties-reference.html>.)


    Regards,

-- 
Loïc Minier <lo...@dooz.org>

---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org


RE: Problem with jdbc 2 XML

Posted by Chiu Yee Weay <yw...@paradigm.com.my>.
Greetings,

I do not know how's mysql's behavior, but looking at the source file,
this might be caused by the following conditions :

 - foreign keys' name is not null
 - same foreign keys' name for different foreign tables

So, instead of using the foreign key name, I would recommend using the
foreign table name instead.

Here's my refined getForeignKeys method in TorqueJDBCTransformTask.java
:

    /**
     * Retrieves a list of foreign key columns for a given table.
     *
     * @param dbMeta JDBC metadata.
     * @param tableName Table from which to retrieve FK information.
     * @return A list of foreign keys in <code>tableName</code>.
     * @throws SQLException
     */
    public Collection getForeignKeys(DatabaseMetaData dbMeta, String
tableName)
        throws SQLException
    {
        Hashtable fks = new Hashtable();
        ResultSet foreignKeys = null;
        try
        {
            foreignKeys = dbMeta.getImportedKeys(null, dbSchema,
tableName);
            while (foreignKeys.next())
            {
                String refTableName = foreignKeys.getString(3);
//referenced table name
                String refColumnName = foreignKeys.getString(4);
//foreign column
                String localColumnName = foreignKeys.getString(8);
//local column

                Object[] fk = (Object[]) fks.get(refTableName);
                List refs;
                if (fk == null)
                {
                    fk = new Object[2];
                    fk[0] = refTableName;
                    refs = new ArrayList();
                }
                else
                {
                    refs = (ArrayList) fk[1];
                }
                String[] ref = new String[2];
                ref[0] = localColumnName;
                ref[1] = refColumnName;
                refs.add(ref);
                fk[1] = refs;
                fks.put(refTableName, fk);
            }
        }
        finally
        {
            if (foreignKeys != null)
            {
                foreignKeys.close();
            }
        }
        return fks.values();
    }


Thanks.


Chiu Yee Weay
Systems Engineer
Paradigm Systems Sdn Bhd

-----Original Message-----
From: Amine Bousta [mailto:abousta@lxsolutions.com] 
Sent: Thursday, November 06, 2003 12:34 AM
To: Apache Torque Users List
Subject: Problem with jdbc 2 XML

Hello,

I'm experiencing a lot of problems by trying to generate an xml schema
from
a sql file.
The last one is :
I'm using Mysql with InnoDB tables and foreign keys.
I'm trying to launch ant on build-torque.xml with the "jdbc" option.
When a table A has a foreign key into a table B and another into table
C, it
generates :
<foreign-key foreignTable="B">
	<reference foreign="id" local="B_id"/>
	<reference foreign="id" local="C_id"/>
</foreign-key>

instead of :
<foreign-key foreignTable="B">
	<reference foreign="id" local="B_id"/>
</foreign-key>
<foreign-key foreignTable="C">
	<reference foreign="id" local="C_id"/>
</foreign-key>

as expected.


If anybody knows a workaround I'd really appreciate :)

Thank you
Amine
PS : Is this the good place here to report Torque bugs or do I have to
post
them in a bug database?




---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org


[ Scanned by JARING E-Mail Virus Scanner ( http://www.jaring.my ) ]



---------------------------------------------------------------------
To unsubscribe, e-mail: torque-dev-unsubscribe@db.apache.org
For additional commands, e-mail: torque-dev-help@db.apache.org


RE: Problem with jdbc 2 XML

Posted by Chiu Yee Weay <yw...@paradigm.com.my>.
Greetings,

I do not know how's mysql's behavior, but looking at the source file,
this might be caused by the following conditions :

 - foreign keys' name is not null
 - same foreign keys' name for different foreign tables

So, instead of using the foreign key name, I would recommend using the
foreign table name instead.

Here's my refined getForeignKeys method in TorqueJDBCTransformTask.java
:

    /**
     * Retrieves a list of foreign key columns for a given table.
     *
     * @param dbMeta JDBC metadata.
     * @param tableName Table from which to retrieve FK information.
     * @return A list of foreign keys in <code>tableName</code>.
     * @throws SQLException
     */
    public Collection getForeignKeys(DatabaseMetaData dbMeta, String
tableName)
        throws SQLException
    {
        Hashtable fks = new Hashtable();
        ResultSet foreignKeys = null;
        try
        {
            foreignKeys = dbMeta.getImportedKeys(null, dbSchema,
tableName);
            while (foreignKeys.next())
            {
                String refTableName = foreignKeys.getString(3);
//referenced table name
                String refColumnName = foreignKeys.getString(4);
//foreign column
                String localColumnName = foreignKeys.getString(8);
//local column

                Object[] fk = (Object[]) fks.get(refTableName);
                List refs;
                if (fk == null)
                {
                    fk = new Object[2];
                    fk[0] = refTableName;
                    refs = new ArrayList();
                }
                else
                {
                    refs = (ArrayList) fk[1];
                }
                String[] ref = new String[2];
                ref[0] = localColumnName;
                ref[1] = refColumnName;
                refs.add(ref);
                fk[1] = refs;
                fks.put(refTableName, fk);
            }
        }
        finally
        {
            if (foreignKeys != null)
            {
                foreignKeys.close();
            }
        }
        return fks.values();
    }


Thanks.


Chiu Yee Weay
Systems Engineer
Paradigm Systems Sdn Bhd

-----Original Message-----
From: Amine Bousta [mailto:abousta@lxsolutions.com] 
Sent: Thursday, November 06, 2003 12:34 AM
To: Apache Torque Users List
Subject: Problem with jdbc 2 XML

Hello,

I'm experiencing a lot of problems by trying to generate an xml schema
from
a sql file.
The last one is :
I'm using Mysql with InnoDB tables and foreign keys.
I'm trying to launch ant on build-torque.xml with the "jdbc" option.
When a table A has a foreign key into a table B and another into table
C, it
generates :
<foreign-key foreignTable="B">
	<reference foreign="id" local="B_id"/>
	<reference foreign="id" local="C_id"/>
</foreign-key>

instead of :
<foreign-key foreignTable="B">
	<reference foreign="id" local="B_id"/>
</foreign-key>
<foreign-key foreignTable="C">
	<reference foreign="id" local="C_id"/>
</foreign-key>

as expected.


If anybody knows a workaround I'd really appreciate :)

Thank you
Amine
PS : Is this the good place here to report Torque bugs or do I have to
post
them in a bug database?




---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org


[ Scanned by JARING E-Mail Virus Scanner ( http://www.jaring.my ) ]



---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org


Problem with jdbc 2 XML

Posted by Amine Bousta <ab...@lxsolutions.com>.
Hello,

I'm experiencing a lot of problems by trying to generate an xml schema from
a sql file.
The last one is :
I'm using Mysql with InnoDB tables and foreign keys.
I'm trying to launch ant on build-torque.xml with the "jdbc" option.
When a table A has a foreign key into a table B and another into table C, it
generates :
<foreign-key foreignTable="B">
	<reference foreign="id" local="B_id"/>
	<reference foreign="id" local="C_id"/>
</foreign-key>

instead of :
<foreign-key foreignTable="B">
	<reference foreign="id" local="B_id"/>
</foreign-key>
<foreign-key foreignTable="C">
	<reference foreign="id" local="C_id"/>
</foreign-key>

as expected.


If anybody knows a workaround I'd really appreciate :)

Thank you
Amine
PS : Is this the good place here to report Torque bugs or do I have to post
them in a bug database?




---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org


RE: Re: Problem OR\\\'ing criterias

Posted by Amine Bousta <ab...@lxsolutions.com>.
Hello,

I've experienced the same problem with "or" and "Criteria.LIKE". "or" was
replaced by "and" and "Like" by "=".
Then I tried to use Criterion but it was too complicated and it didn't work
as well.
So I've used a sql query and I ran an "executeQuery" instead of a
"doSelect".

When I succeeded in running the sql query I wondered what was the real use
of "Criterions".
In my opinion, using a normal "select" query is much readable and powerful
for where clauses.
With SQL you can easily manage parenthesis and all of the sql functions like
substring and else.... There is no bug with OR or IN, you can join tables
easily...
Why using Criteria that builds itself a sql query with limited options
instead of directly writting it?

I'm not blindly blaming the Criteria object but it's just a honest question
about the advantages of this.
So if anybody could light this point for me....

Thanks
Amine



-----Message d'origine-----
De : denis.griesmeyer@freenet.de [mailto:denis.griesmeyer@freenet.de]
Envoyé : vendredi 31 octobre 2003 13:37
À : Apache Torque Users List
Objet : Re: Re: Problem OR\\\'ing criterias


Thanks, any hints are highly appreciated
;-)
--- original Nachricht Ende ----


I had the exact same problem, it seems that or() adds "AND" to the
query string!

no time to check the source code yet... will let you know if something
arises

Tulsi

 --- denis.griesmeyer@freenet.de escribió:
> Hello torque-users,
>
> I have a problem with OR'ing criterias.
>
> The code is as follows:
>
> ---SNIP---
>
> Criteria crit = new Criteria();
>
> crit.or (SongsPeer.ARTIST,(Object)searchString,Criteria.LIKE);
> crit.or (SongsPeer.TITLE,(Object)searchString,Criteria.LIKE);
> crit.or (SongsPeer.ALBUM,(Object)searchString,Criteria.LIKE);
>
> ---SNIP---
>
> I would expect the query to look sth. like this:
>
> ---SNIP---
> ...
> FROM SONGS
> WHERE SONGS.ALBUM LIKE '%4%' OR SONGS.TITLE LIKE '%4%' OR
> SONGS.ARTIST LIKE '%4%'
> ---SNIP---
>
> But instead it AND's all X LIKE Y's together... :-(
>
> Maybe I missunderstood some of the basic concepts of torque...
>
> Can someone give me a hint please?
>
> Thanks in advance
> Denis
>
>
> --
> eBay - Jetzt besser einkaufen!
> Ueber 1. Mio. Angebote. Startpreise ab EUR 1,-
> <a href='http://www.freenet.de/tipp/shopping/ebay'
target='_blank'><u>http://www.freenet.de/tipp/shopping/ebay</u></a>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
> For additional commands, e-mail: torque-user-help@db.apache.org
>

------------
Internet GRATIS es Yahoo! Conexión
4004-1010 desde Buenos Aires. Usuario: yahoo; contraseña: yahoo
Más ciudades: <a href='http://conexion.yahoo.com.ar'
target='_blank'><u>http://conexion.yahoo.com.ar</u></a>

---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org




--
Nur 1x anmelden
und automatisch bis zu 1200 Produktproben und Gutscheine erhalten!
http://www.freenet.de/tipp/shopping/probenking/index.html

---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org






---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org