You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by Null kühl <nu...@gmail.com> on 2009/08/25 09:29:25 UTC

Simple Select Query

I would like to do have a list of of a certain column in a certain table, by
sql language that means something like

SELECT name FROM `client` c;

it's my first time to use cayenne and i searched a lot in it's manual for
doing such a query and the only way that was kind of close is writing the
query manual , and i believe that this is not the best way to do it.

so i was asking about a simple and easy way to do that.

also the return of such a query will be a list of clients as List <clients>
c; , or since am querying for a certain field it can be something like List
<String> names;

Please Advice.

Re: Simple Select Query

Posted by Andrey Razumovsky <ra...@gmail.com>.
Yes, the query I mentioned will return List<String> (and if the objAttrubute
you select is mapped as Integer, it will return List<Integer>). Also you can
specify several columns, then result will be List<Object[]>

2009/8/25 Null kühl <nu...@gmail.com>

> would that query return only the column name from the client table ? also
> the return type will be an object of type client ? is there anyway that i
> can retrieve from this sorta query a list of strings if am querying for a
> name or a list of integers if am querying for a numeral value ?
>
> On Tue, Aug 25, 2009 at 10:09 AM, Andrey Razumovsky <
> razumovsky.andrey@gmail.com> wrote:
>
> > Hi,
> >
> > You can use EJBQLQuery for that, something like "select c.name from
> Client
> > c", where Client is a mapped ObjEntity.
> > http://cayenne.apache.org/doc/ejbqlquery.html
> >
> > Regards,
> > Andrey
> >
> > 2009/8/25 Null kühl <nu...@gmail.com>
> >
> > > I would like to do have a list of of a certain column in a certain
> table,
> > > by
> > > sql language that means something like
> > >
> > > SELECT name FROM `client` c;
> > >
> > > it's my first time to use cayenne and i searched a lot in it's manual
> for
> > > doing such a query and the only way that was kind of close is writing
> the
> > > query manual , and i believe that this is not the best way to do it.
> > >
> > > so i was asking about a simple and easy way to do that.
> > >
> > > also the return of such a query will be a list of clients as List
> > <clients>
> > > c; , or since am querying for a certain field it can be something like
> > List
> > > <String> names;
> > >
> > > Please Advice.
> > >
> >
>

Re: Simple Select Query

Posted by Null kühl <nu...@gmail.com>.
would that query return only the column name from the client table ? also
the return type will be an object of type client ? is there anyway that i
can retrieve from this sorta query a list of strings if am querying for a
name or a list of integers if am querying for a numeral value ?

On Tue, Aug 25, 2009 at 10:09 AM, Andrey Razumovsky <
razumovsky.andrey@gmail.com> wrote:

> Hi,
>
> You can use EJBQLQuery for that, something like "select c.name from Client
> c", where Client is a mapped ObjEntity.
> http://cayenne.apache.org/doc/ejbqlquery.html
>
> Regards,
> Andrey
>
> 2009/8/25 Null kühl <nu...@gmail.com>
>
> > I would like to do have a list of of a certain column in a certain table,
> > by
> > sql language that means something like
> >
> > SELECT name FROM `client` c;
> >
> > it's my first time to use cayenne and i searched a lot in it's manual for
> > doing such a query and the only way that was kind of close is writing the
> > query manual , and i believe that this is not the best way to do it.
> >
> > so i was asking about a simple and easy way to do that.
> >
> > also the return of such a query will be a list of clients as List
> <clients>
> > c; , or since am querying for a certain field it can be something like
> List
> > <String> names;
> >
> > Please Advice.
> >
>

Re: Simple Select Query

Posted by Andrey Razumovsky <ra...@gmail.com>.
Hi,

You can use EJBQLQuery for that, something like "select c.name from Client
c", where Client is a mapped ObjEntity.
http://cayenne.apache.org/doc/ejbqlquery.html

Regards,
Andrey

2009/8/25 Null kühl <nu...@gmail.com>

> I would like to do have a list of of a certain column in a certain table,
> by
> sql language that means something like
>
> SELECT name FROM `client` c;
>
> it's my first time to use cayenne and i searched a lot in it's manual for
> doing such a query and the only way that was kind of close is writing the
> query manual , and i believe that this is not the best way to do it.
>
> so i was asking about a simple and easy way to do that.
>
> also the return of such a query will be a list of clients as List <clients>
> c; , or since am querying for a certain field it can be something like List
> <String> names;
>
> Please Advice.
>

Re: Simple Select Query

Posted by Aristedes Maniatis <ar...@maniatis.org>.
On 25/08/09 6:23 PM, Null kühl wrote:
> yes, but imagine if it's a huge table, performance wise, ill be reading the
> whole table from the db, all columns and all rows.then throw away all the
> data except for a certain column, would it have a vast effect on performance
> if i just constrain the reading from the beginning ?

It will depend on what you are doing. But I think you should explore 'paging' in Cayenne before your current approach. Only once you find you actually have performance problems should you go down this path. You will no longer be able to deal with clients as a list of Client objects which means no validation, saving data back to the db, and much more which Cayenne gives you.

It is a common mistake of people new to ORMs to still think in terms of SQL and reading columns. Perhaps in your case this is necessary to get the speed you want, but often it is a premature optimisation which precludes a lot of useful functionality.


Ari Maniatis


-------------------------->
Aristedes Maniatis
GPG fingerprint CBFB 84B4 738D 4E87 5E5C  5EFA EF6A 7D2E 3E49 102A

Re: Simple Select Query

Posted by Null kühl <nu...@gmail.com>.
yes, but imagine if it's a huge table, performance wise, ill be reading the
whole table from the db, all columns and all rows.then throw away all the
data except for a certain column, would it have a vast effect on performance
if i just constrain the reading from the beginning ?

On Tue, Aug 25, 2009 at 10:20 AM, Aristedes Maniatis <ar...@maniatis.org>wrote:

> On 25/08/09 5:29 PM, Null kühl wrote:
>
>> also the return of such a query will be a list of clients as List<clients>
>> c; , or since am querying for a certain field it can be something like
>> List
>> <String>  names;
>>
>
> Although you can do what you want by returning DataRows, I strongly advise
> you avoid that approach while you are learning Cayenne. Instead, just
> perform the query to return full objects. The whole point of Cayenne is so
> that you can stop worrying about columns and start thinking in terms of Java
> objects.
>
> Ari Maniatis
>
> -------------------------->
> Aristedes Maniatis
> GPG fingerprint CBFB 84B4 738D 4E87 5E5C  5EFA EF6A 7D2E 3E49 102A
>

Re: Simple Select Query

Posted by Aristedes Maniatis <ar...@maniatis.org>.
On 25/08/09 5:29 PM, Null kühl wrote:
> also the return of such a query will be a list of clients as List<clients>
> c; , or since am querying for a certain field it can be something like List
> <String>  names;

Although you can do what you want by returning DataRows, I strongly advise you avoid that approach while you are learning Cayenne. Instead, just perform the query to return full objects. The whole point of Cayenne is so that you can stop worrying about columns and start thinking in terms of Java objects.

Ari Maniatis

-------------------------->
Aristedes Maniatis
GPG fingerprint CBFB 84B4 738D 4E87 5E5C  5EFA EF6A 7D2E 3E49 102A