You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@openjpa.apache.org by Todd Nine <to...@spidertracks.com> on 2011/03/16 04:15:41 UTC

Help with Collection Proxies

Hi guys,
  I have a few questions regarding large sets and ordering and could use
some help from the developers.


First, everything in Cassandra needs to be write ordering.  I must have
the properties of the values that have changed on write in order to
correctly build our indexes to support the "OrderBy" annotation
properly.   If I were to define an annotation such as this 

@OrderBy("following.firstName, following.lastName")

Are there are core API's that exist I can use to pass an object and
retrieve the value?  I've had a look at the MetaDataRepository, but I'm
unsure how to go about getting the values loaded when the case is a
nested object such as above. 



Second, we're doing very little when we create our own store
configuration.

https://github.com/riptano/hector-jpa/blob/master/src/main/java/com/datastax/hectorjpa/store/CassandraStoreConfiguration.java

By default, will all collections/maps get wrapped in a Proxy instance
once it's been attached to the EM?  We have the potential for huge
collections, so they must be proxies after the initial save and we need
to be sure that we wrap the collection in a proxy.  Any guidance would
be greatly appreciated. 

Thanks,
Todd

Re: Help with Collection Proxies

Posted by Todd Nine <to...@spidertracks.com>.
Hi Michael,
  Thanks for your responses.  The proxy info was very helpful.  Here is
the exact flow I have to implement in order to have persistence ordering
working properly in Cassandra.  Cassandra uses insertion ordering and
sets have the potential to be far too large to sort in memory.  I think
an example would be more appropriate to demonstrate what I'm trying to
accomplish.

User Entity with a One to Many for other users.  We'll name the property
"friends", so we would have this object.


@Entity
public class User{

@Id
private UUID id;


@Persistent
private String firstName;

@Persistent
private String lastName;


@OneToMany
@OrderBy("firstName, lastName")
private List<User> friends;
}


Here is the flow I need

1.Meta data graph is built.
2.  Object is stored
3. For each property with an OrderBy  in the meta data, I must retrieve
the values in the orderBy in the storeObject operation not post save.  


Cassandra is insertion ordering, so I must have the value when I insert
them. 

As I persist the user, I need to retrieve the "firstName" property and
the "lastName" property of each instance of dirty entities in my friends
proxy.  This way I can build columns in the format of 

friends+ 0x00 + firstName+0x00 +lastName+0x00 +friend.Id with the
underlying bytes of the properties

When the user loads this collection, it will be pre-sorted by Cassandra
by firstName, then lastName.  Getting field for a name is easy enough
with class and field meta data, however order clauses that are nested
with a "." operation are a bit more difficult.  This is where my
question for utilities stems from.  Is there a method I can call where I
could use something like this.

public Object getValue(OpenJPAStateManager stateManager, String
propertyPath);

This would return the runtime value of the field with the given property
path.  

Thanks again for the help!

Todd

On Wed, 2011-03-16 at 09:06 -0500, Michael Dick wrote:
> On Tue, Mar 15, 2011 at 10:15 PM, Todd Nine <to...@spidertracks.com>
> wrote:
> 
>         Hi guys,
>          I have a few questions regarding large sets and ordering and
>         could use
>         some help from the developers.
>         
>         
>         First, everything in Cassandra needs to be write ordering.  I
>         must have
>         the properties of the values that have changed on write in
>         order to
>         correctly build our indexes to support the "OrderBy"
>         annotation
>         properly.   If I were to define an annotation such as this
>         
>         @OrderBy("following.firstName, following.lastName")
>         
> 
> I'm not entirely sure where you were going with this, but here goes. 
> 
> The OrderBy annotation is used to order the elements of a collection
> when an entity is loaded from the database. If you're using the
> OpenJPA internals to get a list of changed attributes they may also
> follow that order, but I think that would be a 'happy coincidence' and
> not something you can rely upon.
> 
> I haven't looked into this in any depth (at least not recently), but I
> think you'd want to start by looking at the
> OperationOrderUpdateManager and ConstraintUpdateManager. 
>  
>         
>         Are there are core API's that exist I can use to pass an
>         object and
>         retrieve the value?  I've had a look at the
>         MetaDataRepository, but I'm
>         unsure how to go about getting the values loaded when the case
>         is a
>         nested object such as above.
>         
> 
> The MetaDataRepository contains data about the entity (how it's fields
> map to the database, column names, etc.). To access the values of a
> particular entity instance you'll probably want to start with its
> StateManager. 
> 
> 
>         
>         Second, we're doing very little when we create our own store
>         configuration.
>         
>         https://github.com/riptano/hector-jpa/blob/master/src/main/java/com/datastax/hectorjpa/store/CassandraStoreConfiguration.java
>         
>         By default, will all collections/maps get wrapped in a Proxy
>         instance
>         once it's been attached to the EM?  We have the potential for
>         huge
>         collections, so they must be proxies after the initial save
>         and we need
>         to be sure that we wrap the collection in a proxy.  Any
>         guidance would
>         be greatly appreciated.
>         
> 
> All second class objects (collections, Date/Timestamps, etc.) are
> wrappered with Proxy classes for better state tracking. The proxies
> are inserted at persist time in OpenJPA 2.0 (it's slightly different
> in earlier versions). 
> 
> Would you need your own proxy? Or are you just interested in ensuring
> we insert an OpenJPA proxy? 
>  
> Hope this helps,
> 
> -mike
> 
> 
> 
> 

Re: Help with Collection Proxies

Posted by Michael Dick <mi...@gmail.com>.
On Tue, Mar 15, 2011 at 10:15 PM, Todd Nine <to...@spidertracks.com> wrote:

> Hi guys,
>  I have a few questions regarding large sets and ordering and could use
> some help from the developers.
>
>
> First, everything in Cassandra needs to be write ordering.  I must have
> the properties of the values that have changed on write in order to
> correctly build our indexes to support the "OrderBy" annotation
> properly.   If I were to define an annotation such as this
>
> @OrderBy("following.firstName, following.lastName")


I'm not entirely sure where you were going with this, but here goes.

The OrderBy annotation is used to order the elements of a collection when an
entity is loaded from the database. If you're using the OpenJPA internals to
get a list of changed attributes they may also follow that order, but I
think that would be a 'happy coincidence' and not something you can rely
upon.

I haven't looked into this in any depth (at least not recently), but I think
you'd want to start by looking at the
OperationOrderUpdateManager<http://openjpa.apache.org/builds/latest/docs/javadoc/org/apache/openjpa/jdbc/kernel/OperationOrderUpdateManager.html>and
ConstraintUpdateManager<http://openjpa.apache.org/builds/latest/docs/javadoc/org/apache/openjpa/jdbc/kernel/ConstraintUpdateManager.html>.



> Are there are core API's that exist I can use to pass an object and
> retrieve the value?  I've had a look at the MetaDataRepository, but I'm
> unsure how to go about getting the values loaded when the case is a
> nested object such as above.
>

The MetaDataRepository contains data about the entity (how it's fields map
to the database, column names, etc.). To access the values of a particular
entity instance you'll probably want to start with its
StateManager<http://openjpa.apache.org/builds/latest/docs/javadoc/index.html>.


Second, we're doing very little when we create our own store
> configuration.
>
>
> https://github.com/riptano/hector-jpa/blob/master/src/main/java/com/datastax/hectorjpa/store/CassandraStoreConfiguration.java
>
> By default, will all collections/maps get wrapped in a Proxy instance
> once it's been attached to the EM?  We have the potential for huge
> collections, so they must be proxies after the initial save and we need
> to be sure that we wrap the collection in a proxy.  Any guidance would
> be greatly appreciated.


All second class objects (collections, Date/Timestamps, etc.) are wrappered
with Proxy classes for better state tracking. The proxies are inserted at
persist time in OpenJPA 2.0 (it's slightly different in earlier versions).

Would you need your own proxy? Or are you just interested in ensuring we
insert an OpenJPA proxy?

Hope this helps,

-mike