You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by Borut Bolčina <bo...@gmail.com> on 2009/04/06 13:37:03 UTC
API wish(es)
Hi,
would it be possible to add one method in DataObjectUtils,
DataObjectA dataObjectA = DataObjectUtils.objectForPK(dataContext,
DataObjectA.class, 1, QueryCacheStrategy.NO_CACHE);
which would always return a fresh object.
By the way, is this the correct way of fetching an object directly
from database?
Expression e = ExpressionFactory.matchExp(DataObjectA.ID_PK_COLUMN, "1");
SelectQuery query = new SelectQuery(DataObjectA.class, e);
query.setCacheStrategy(QueryCacheStrategy.NO_CACHE);
List list = dataContext.performQuery(query);
DataObjectA objectA= null;
if (list.size() > 0) {
objectA= (DataObjectA) list.get(0);
}
The above code would still use object cache, right, so I will not be
getting the object with values as set in database (maybe changed by
3rd party process). How to overcome this in the above code?
Also, wouldn't it be convenient if performQuery could return just one
object so we do not have to always type the boilerplate
if(list.size>0) ?
Regards,
Borut
Re: API wish(es)
Posted by Borut Bolčina <bo...@gmail.com>.
OK, RTFM to myself http://cayenne.apache.org/doc/objectidquery.html
2009/4/6 Borut Bolčina <bo...@gmail.com>
> Hi,
>
> so if this is the table:
>
> create table health_monitor (id int not null, date_check datetime, primary
> key (id)) engine=InnoDB;
>
> then this
>
> ObjectId id = new ObjectId("health_monitor", HealthMonitor.ID_PK_COLUMN,
> 1);
> HealthMonitor healthMonitor = (HealthMonitor)
> DataObjectUtils.objectForQuery(dataContext, new ObjectIdQuery(id,
> false, ObjectIdQuery.CACHE_REFRESH));
> Date date = healthMonitor.getDateCheck();
>
> would be equivalent for
>
> select date_check from health_monitor where id=1;
>
> in plain old sql?
>
> I did not actually try the above code, so I don't know if it really works,
> but I feel there must be a simpler way?!?
>
> Regards,
> Borut
>
> 2009/4/6 Andrey Razumovsky <ra...@gmail.com>:
> > The correct way to get fresh object is similiar to the method in
> > DataObjectUtils:
> >
> > public static Object freshObjectForPK(ObjectContext context, ObjectId id)
> {
> > return DataObjectUtils.objectForQuery(context, new ObjectIdQuery(
> > id,
> > false,
> > ObjectIdQuery.REFRESH));
> > }
> >
> > BTW right here's a method which returns one object of query result
> >
> > 2009/4/6 Borut Bolčina <bo...@gmail.com>
> >
> >> Hi,
> >>
> >> would it be possible to add one method in DataObjectUtils,
> >>
> >> DataObjectA dataObjectA = DataObjectUtils.objectForPK(dataContext,
> >> DataObjectA.class, 1, QueryCacheStrategy.NO_CACHE);
> >>
> >> which would always return a fresh object.
> >>
> >>
> >> By the way, is this the correct way of fetching an object directly
> >> from database?
> >>
> >> Expression e = ExpressionFactory.matchExp(DataObjectA.ID_PK_COLUMN,
> "1");
> >> SelectQuery query = new SelectQuery(DataObjectA.class, e);
> >> query.setCacheStrategy(QueryCacheStrategy.NO_CACHE);
> >> List list = dataContext.performQuery(query);
> >>
> >> DataObjectA objectA= null;
> >> if (list.size() > 0) {
> >> objectA= (DataObjectA) list.get(0);
> >> }
> >>
> >> The above code would still use object cache, right, so I will not be
> >> getting the object with values as set in database (maybe changed by
> >> 3rd party process). How to overcome this in the above code?
> >>
> >> Also, wouldn't it be convenient if performQuery could return just one
> >> object so we do not have to always type the boilerplate
> >> if(list.size>0) ?
> >>
> >> Regards,
> >> Borut
> >>
> >
>
>
Re: API wish(es)
Posted by Borut Bolčina <bo...@gmail.com>.
Hi,
so if this is the table:
create table health_monitor (id int not null, date_check datetime, primary
key (id)) engine=InnoDB;
then this
ObjectId id = new ObjectId("health_monitor", HealthMonitor.ID_PK_COLUMN, 1);
HealthMonitor healthMonitor = (HealthMonitor)
DataObjectUtils.objectForQuery(dataContext, new ObjectIdQuery(id,
false, ObjectIdQuery.CACHE_REFRESH));
Date date = healthMonitor.getDateCheck();
would be equivalent for
select date_check from health_monitor where id=1;
in plain old sql?
I did not actually try the above code, so I don't know if it really works,
but I feel there must be a simpler way?!?
Regards,
Borut
2009/4/6 Andrey Razumovsky <ra...@gmail.com>:
> The correct way to get fresh object is similiar to the method in
> DataObjectUtils:
>
> public static Object freshObjectForPK(ObjectContext context, ObjectId id)
{
> return DataObjectUtils.objectForQuery(context, new ObjectIdQuery(
> id,
> false,
> ObjectIdQuery.REFRESH));
> }
>
> BTW right here's a method which returns one object of query result
>
> 2009/4/6 Borut Bolčina <bo...@gmail.com>
>
>> Hi,
>>
>> would it be possible to add one method in DataObjectUtils,
>>
>> DataObjectA dataObjectA = DataObjectUtils.objectForPK(dataContext,
>> DataObjectA.class, 1, QueryCacheStrategy.NO_CACHE);
>>
>> which would always return a fresh object.
>>
>>
>> By the way, is this the correct way of fetching an object directly
>> from database?
>>
>> Expression e = ExpressionFactory.matchExp(DataObjectA.ID_PK_COLUMN, "1");
>> SelectQuery query = new SelectQuery(DataObjectA.class, e);
>> query.setCacheStrategy(QueryCacheStrategy.NO_CACHE);
>> List list = dataContext.performQuery(query);
>>
>> DataObjectA objectA= null;
>> if (list.size() > 0) {
>> objectA= (DataObjectA) list.get(0);
>> }
>>
>> The above code would still use object cache, right, so I will not be
>> getting the object with values as set in database (maybe changed by
>> 3rd party process). How to overcome this in the above code?
>>
>> Also, wouldn't it be convenient if performQuery could return just one
>> object so we do not have to always type the boilerplate
>> if(list.size>0) ?
>>
>> Regards,
>> Borut
>>
>
Re: API wish(es)
Posted by Andrey Razumovsky <ra...@gmail.com>.
I mean that the way to get single result from query is via DataObjectUtils.
objectForQuery(...)
2009/4/6 John Armstrong <si...@gmail.com>
> Andrey, you left me in suspense :)
>
> > BTW right here's a method which returns one object of query result
>
> Are you saying use ObjectIdQuery to get one result or is there another
> normal query that will do it?
>
> John-
>
> 2009/4/6 Andrey Razumovsky <ra...@gmail.com>:
> > The correct way to get fresh object is similiar to the method in
> > DataObjectUtils:
> >
> > public static Object freshObjectForPK(ObjectContext context, ObjectId id)
> {
> > return DataObjectUtils.objectForQuery(context, new ObjectIdQuery(
> > id,
> > false,
> > ObjectIdQuery.REFRESH));
> > }
> >
> > BTW right here's a method which returns one object of query result
> >
> > 2009/4/6 Borut Bolčina <bo...@gmail.com>
> >
> >> Hi,
> >>
> >> would it be possible to add one method in DataObjectUtils,
> >>
> >> DataObjectA dataObjectA = DataObjectUtils.objectForPK(dataContext,
> >> DataObjectA.class, 1, QueryCacheStrategy.NO_CACHE);
> >>
> >> which would always return a fresh object.
> >>
> >>
> >> By the way, is this the correct way of fetching an object directly
> >> from database?
> >>
> >> Expression e = ExpressionFactory.matchExp(DataObjectA.ID_PK_COLUMN,
> "1");
> >> SelectQuery query = new SelectQuery(DataObjectA.class, e);
> >> query.setCacheStrategy(QueryCacheStrategy.NO_CACHE);
> >> List list = dataContext.performQuery(query);
> >>
> >> DataObjectA objectA= null;
> >> if (list.size() > 0) {
> >> objectA= (DataObjectA) list.get(0);
> >> }
> >>
> >> The above code would still use object cache, right, so I will not be
> >> getting the object with values as set in database (maybe changed by
> >> 3rd party process). How to overcome this in the above code?
> >>
> >> Also, wouldn't it be convenient if performQuery could return just one
> >> object so we do not have to always type the boilerplate
> >> if(list.size>0) ?
> >>
> >> Regards,
> >> Borut
> >>
> >
>
Re: API wish(es)
Posted by John Armstrong <si...@gmail.com>.
Andrey, you left me in suspense :)
> BTW right here's a method which returns one object of query result
Are you saying use ObjectIdQuery to get one result or is there another
normal query that will do it?
John-
2009/4/6 Andrey Razumovsky <ra...@gmail.com>:
> The correct way to get fresh object is similiar to the method in
> DataObjectUtils:
>
> public static Object freshObjectForPK(ObjectContext context, ObjectId id) {
> return DataObjectUtils.objectForQuery(context, new ObjectIdQuery(
> id,
> false,
> ObjectIdQuery.REFRESH));
> }
>
> BTW right here's a method which returns one object of query result
>
> 2009/4/6 Borut Bolčina <bo...@gmail.com>
>
>> Hi,
>>
>> would it be possible to add one method in DataObjectUtils,
>>
>> DataObjectA dataObjectA = DataObjectUtils.objectForPK(dataContext,
>> DataObjectA.class, 1, QueryCacheStrategy.NO_CACHE);
>>
>> which would always return a fresh object.
>>
>>
>> By the way, is this the correct way of fetching an object directly
>> from database?
>>
>> Expression e = ExpressionFactory.matchExp(DataObjectA.ID_PK_COLUMN, "1");
>> SelectQuery query = new SelectQuery(DataObjectA.class, e);
>> query.setCacheStrategy(QueryCacheStrategy.NO_CACHE);
>> List list = dataContext.performQuery(query);
>>
>> DataObjectA objectA= null;
>> if (list.size() > 0) {
>> objectA= (DataObjectA) list.get(0);
>> }
>>
>> The above code would still use object cache, right, so I will not be
>> getting the object with values as set in database (maybe changed by
>> 3rd party process). How to overcome this in the above code?
>>
>> Also, wouldn't it be convenient if performQuery could return just one
>> object so we do not have to always type the boilerplate
>> if(list.size>0) ?
>>
>> Regards,
>> Borut
>>
>
Re: API wish(es)
Posted by Andrey Razumovsky <ra...@gmail.com>.
The correct way to get fresh object is similiar to the method in
DataObjectUtils:
public static Object freshObjectForPK(ObjectContext context, ObjectId id) {
return DataObjectUtils.objectForQuery(context, new ObjectIdQuery(
id,
false,
ObjectIdQuery.REFRESH));
}
BTW right here's a method which returns one object of query result
2009/4/6 Borut Bolčina <bo...@gmail.com>
> Hi,
>
> would it be possible to add one method in DataObjectUtils,
>
> DataObjectA dataObjectA = DataObjectUtils.objectForPK(dataContext,
> DataObjectA.class, 1, QueryCacheStrategy.NO_CACHE);
>
> which would always return a fresh object.
>
>
> By the way, is this the correct way of fetching an object directly
> from database?
>
> Expression e = ExpressionFactory.matchExp(DataObjectA.ID_PK_COLUMN, "1");
> SelectQuery query = new SelectQuery(DataObjectA.class, e);
> query.setCacheStrategy(QueryCacheStrategy.NO_CACHE);
> List list = dataContext.performQuery(query);
>
> DataObjectA objectA= null;
> if (list.size() > 0) {
> objectA= (DataObjectA) list.get(0);
> }
>
> The above code would still use object cache, right, so I will not be
> getting the object with values as set in database (maybe changed by
> 3rd party process). How to overcome this in the above code?
>
> Also, wouldn't it be convenient if performQuery could return just one
> object so we do not have to always type the boilerplate
> if(list.size>0) ?
>
> Regards,
> Borut
>