cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Nikita Timofeev <ntimof...@objectstyle.com>
Subject Re: ObjectSelect.columnQuery
Date Wed, 04 Oct 2017 12:43:24 GMT
Yes you can add this property:

Property<Cargo> property3 = Property.createSelf(Cargo.class);

But this will eagerly fetch all content of Cargo.

On Wed, Oct 4, 2017 at 3:30 PM, ab@dataloy.com <ab@dataloy.com> wrote:
>
>
> On 2017-10-04 13:57, Nikita Timofeev <ntimofeev@objectstyle.com> wrote:
>> ObjectSelect.columnQuery can select individual columns, as it was
>> designed just for that.
>> However you can also use it to get full entities along with some
>> arbitrary properties (aggregates, dependent objects, etc.).
>> In your case you created property with type of "Cargo" and it returns
>> you collection of Cargo objects.
>> Just use correct type of required column (String, Integer, etc.).
>>
>> However easiest (and also safe) way to use it is via static Properties
>> generated in a superclass of your entity, i.e. something like this:
>>
>> List<String> someStringProperties =
>> ObjectSelect.columnQuery(Cargo.class,
>> Cargo.SOME_STRING_PROPERTY).select(ctx);
>>
>>
>> On Wed, Oct 4, 2017 at 12:45 PM, ab@dataloy.com <ab@dataloy.com> wrote:
>> > Should ObjectSelect.columnQuery  execute a SQL query with just one column selected?
>> >
>> > I am using Cayenne 4.1 but running this code:
>> >
>> > Property<Cargo> property1 = Property.create("area", Cargo.class);
>> >
>> > List<Cargo> select = ObjectSelect.columnQuery(Cargo.class,property1).where(Expression.fromString("area>10")).select(ctx);
>> >
>> > the query executed select all the columns of cargo table.
>> >
>> > I need to specify which columns the queries must return because I have tables
with hundreds of columns that I do not need, returning all the columns every time is very
time consuming.
>> >
>> > Andrea
>>
>>
>>
>> --
>> Best regards,
>> Nikita Timofeev
> But if I do something like this:
>
> Property<String> property1 = Property.create("area", String.class);
> Property<Double> property2 = Property.create("voyage.flCost", Double.class);
> List<Object[]> select = ObjectSelect.query(Cargo.class).columns(property1,property2).select(ctx);
>
> There is the possibility to get a list of Cargo objects?



-- 
Best regards,
Nikita Timofeev

Mime
View raw message