You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by Dirk Lattermann <dl...@alqualonde.de> on 2008/05/19 21:16:42 UTC

SelectQuery and new objects

Hello list,

as small first steps (again) with Cayenne, I created some data objects
via DataContext's newObject(MyDataObject.class). Then, without
committing, I created an unqualified SelectQuery to fetch all objects of
class MyDataObject. Executing it on the DataContext, only objects from
the database are included in the returned list.

Is this expected? I couldn't find something explicit in the docs. To my
understanding, running the query on the DataContext should return all
objects known to it, even if they aren't in the database yet. This would
be like uncommitted data in a database session, which is visible for
queries in this same session.

Thank you.
Dirk


Re: SelectQuery and new objects

Posted by Dirk Lattermann <dl...@alqualonde.de>.
Am Montag, den 19.05.2008, 16:27 -0400 schrieb Mike Kienenberger:
> Oops.
> That's "filterObjects()"
> 
> And here's a link to the docs:
> 
> http://cayenne.apache.org/doc12/in-memory-evaluation.html
> 

Great! Thank you!


Re: SelectQuery and new objects

Posted by Mike Kienenberger <mk...@gmail.com>.
Oops.
That's "filterObjects()"

And here's a link to the docs:

http://cayenne.apache.org/doc12/in-memory-evaluation.html


On 5/19/08, Mike Kienenberger <mk...@gmail.com> wrote:
> You can use Expression.filterObject() to apply an expression to a set
>  of in-memory objects, such as the results of newObjects().
>
>  I had forgotten about that functionality until you mentioned "filtered
>  by hand", but that's going to be close to SelectQuery behavior.
>
>
>
>  On 5/19/08, Dirk Lattermann <dl...@alqualonde.de> wrote:
>  > Am Montag, den 19.05.2008, 15:34 -0400 schrieb Mike Kienenberger:
>  >
>  > > It's true for all queries, but you can always ask the ObjectContext or
>  >  > DataContext for the list of new objects:
>  >  >
>  >  > public interface ObjectContext extends Serializable {
>  >  >
>  >  >     /**
>  >  >      * Returns a collection of objects that are registered with this
>  >  > ObjectContext and
>  >  >      * have a state PersistenceState.NEW
>  >  >      */
>  >  >     Collection<?> newObjects();
>  >
>  >
>  > Ok, thanks.
>  >  This always returns all new objects, though. So it seems they must be
>  >  filtered by hand to get something like the result of a qualified query.
>  >
>  >  Thank you anyway,
>  >
>  > Dirk
>  >
>  >
>  >  > On 5/19/08, Dirk Lattermann <dl...@alqualonde.de> wrote:
>  >  > > Am Montag, den 19.05.2008, 14:20 -0500 schrieb Robert Zeigler:
>  >  > >
>  >  > > > The select query is going to run against data in the database, and
>  >  > >  > will therefore /not/ return newly created but as yet uncommitted
>  >  > >  > objects.
>  >  > >  >
>  >  > >
>  >  > >
>  >  > > Aha, thank you! Is this true for all Query classes in Cayenne? In other
>  >  > >  words, is there a Query (or some other means) to fetch uncommitted
>  >  > >  objects?
>  >  > >
>  >  > >
>  >
>  >
>

Re: SelectQuery and new objects

Posted by Mike Kienenberger <mk...@gmail.com>.
You can use Expression.filterObject() to apply an expression to a set
of in-memory objects, such as the results of newObjects().

I had forgotten about that functionality until you mentioned "filtered
by hand", but that's going to be close to SelectQuery behavior.


On 5/19/08, Dirk Lattermann <dl...@alqualonde.de> wrote:
> Am Montag, den 19.05.2008, 15:34 -0400 schrieb Mike Kienenberger:
>
> > It's true for all queries, but you can always ask the ObjectContext or
>  > DataContext for the list of new objects:
>  >
>  > public interface ObjectContext extends Serializable {
>  >
>  >     /**
>  >      * Returns a collection of objects that are registered with this
>  > ObjectContext and
>  >      * have a state PersistenceState.NEW
>  >      */
>  >     Collection<?> newObjects();
>
>
> Ok, thanks.
>  This always returns all new objects, though. So it seems they must be
>  filtered by hand to get something like the result of a qualified query.
>
>  Thank you anyway,
>
> Dirk
>
>
>  > On 5/19/08, Dirk Lattermann <dl...@alqualonde.de> wrote:
>  > > Am Montag, den 19.05.2008, 14:20 -0500 schrieb Robert Zeigler:
>  > >
>  > > > The select query is going to run against data in the database, and
>  > >  > will therefore /not/ return newly created but as yet uncommitted
>  > >  > objects.
>  > >  >
>  > >
>  > >
>  > > Aha, thank you! Is this true for all Query classes in Cayenne? In other
>  > >  words, is there a Query (or some other means) to fetch uncommitted
>  > >  objects?
>  > >
>  > >
>
>

Re: SelectQuery and new objects

Posted by Dirk Lattermann <dl...@alqualonde.de>.
Am Montag, den 19.05.2008, 15:34 -0400 schrieb Mike Kienenberger:
> It's true for all queries, but you can always ask the ObjectContext or
> DataContext for the list of new objects:
> 
> public interface ObjectContext extends Serializable {
> 
>     /**
>      * Returns a collection of objects that are registered with this
> ObjectContext and
>      * have a state PersistenceState.NEW
>      */
>     Collection<?> newObjects();

Ok, thanks.
This always returns all new objects, though. So it seems they must be
filtered by hand to get something like the result of a qualified query.

Thank you anyway,
Dirk

> On 5/19/08, Dirk Lattermann <dl...@alqualonde.de> wrote:
> > Am Montag, den 19.05.2008, 14:20 -0500 schrieb Robert Zeigler:
> >
> > > The select query is going to run against data in the database, and
> >  > will therefore /not/ return newly created but as yet uncommitted
> >  > objects.
> >  >
> >
> >
> > Aha, thank you! Is this true for all Query classes in Cayenne? In other
> >  words, is there a Query (or some other means) to fetch uncommitted
> >  objects?
> >
> >


Re: SelectQuery and new objects

Posted by Mike Kienenberger <mk...@gmail.com>.
It's true for all queries, but you can always ask the ObjectContext or
DataContext for the list of new objects:

public interface ObjectContext extends Serializable {

    /**
     * Returns a collection of objects that are registered with this
ObjectContext and
     * have a state PersistenceState.NEW
     */
    Collection<?> newObjects();



public class DataContext extends BaseContext implements DataChannel {

    /**
     * Returns a list of objects that are registered with this
DataContext and have a
     * state PersistenceState.NEW
     */
    @Override
    public Collection<?> newObjects() {
        return getObjectStore().objectsInState(PersistenceState.NEW);
    }

On 5/19/08, Dirk Lattermann <dl...@alqualonde.de> wrote:
> Am Montag, den 19.05.2008, 14:20 -0500 schrieb Robert Zeigler:
>
> > The select query is going to run against data in the database, and
>  > will therefore /not/ return newly created but as yet uncommitted
>  > objects.
>  >
>
>
> Aha, thank you! Is this true for all Query classes in Cayenne? In other
>  words, is there a Query (or some other means) to fetch uncommitted
>  objects?
>
>

Re: SelectQuery and new objects

Posted by Dirk Lattermann <dl...@alqualonde.de>.
Am Montag, den 19.05.2008, 14:20 -0500 schrieb Robert Zeigler:
> The select query is going to run against data in the database, and  
> will therefore /not/ return newly created but as yet uncommitted  
> objects.
> 

Aha, thank you! Is this true for all Query classes in Cayenne? In other
words, is there a Query (or some other means) to fetch uncommitted
objects?


Re: SelectQuery and new objects

Posted by Robert Zeigler <ro...@puregumption.com>.
The select query is going to run against data in the database, and  
will therefore /not/ return newly created but as yet uncommitted  
objects.

Robert

On May 19, 2008, at 5/192:16 PM , Dirk Lattermann wrote:

> Hello list,
>
> as small first steps (again) with Cayenne, I created some data objects
> via DataContext's newObject(MyDataObject.class). Then, without
> committing, I created an unqualified SelectQuery to fetch all  
> objects of
> class MyDataObject. Executing it on the DataContext, only objects from
> the database are included in the returned list.
>
> Is this expected? I couldn't find something explicit in the docs. To  
> my
> understanding, running the query on the DataContext should return all
> objects known to it, even if they aren't in the database yet. This  
> would
> be like uncommitted data in a database session, which is visible for
> queries in this same session.
>
> Thank you.
> Dirk
>