openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From e33238 <e33...@hotmail.com>
Subject Re: RemoteCommitProviders (was Re: Using MethodQL)
Date Wed, 27 Jun 2007 17:08:51 GMT

I noticed that the default behavior is to send the ObjectIDs only in the
notification. If I want to send the entire object, how can I do that? Do I
need to implement RemoteCommitProvider or RemoteCommitManager, and subclass
RemoteCommitEvent?

Thanks.


Patrick Linskey-2 wrote:
> 
>> Also, I'm trying to find out how to use the RemoteCommitProvider.
>> Basically
>> everytime a commit happens, I'd like to send some notification to a
>> remote
>> server to track the changes. Sounds like RemoteCommitProvider is exactly
>> what I wanted, so any examples of how to implement my own
>> RemoteCommitProvier and how it's used would really help. Thanks!! =)
> 
> You mention that you want to track changes on a remote server.
> Presumably you mean that you want to receive notifications of commits
> in a callback that you write that's running on the remote machine,
> right?
> 
> If that's the case, you'll want to create an implementation of the
> RemoteCommitListener interface, and register it with your
> OpenJPAEntityManagerFactory's Configuration's
> RemoteCommitEventManager:
> 
> OpenJPAPersistence.cast(emf).getConfiguration().getRemoteCommitEventManager()
>     .addListener(new MyRemoteCommitListener());
> 
> -Patrick
> 
> On 6/26/07, e33238 <e33238@hotmail.com> wrote:
>>
>> I'm tracing through the code to find out what the problem was, and it
>> seems
>> that it'll work if I do this:
>>
>> OpenJPAQuery q =
>> oem.createQuery("openjpa.MethodQL","com.xyz.Finder.getByName");
>> q.setResultClass(Person.class);
>> q.setParameter("firstName", "Fred").setParameter("lastName", "Lucas");
>> ((QueryImpl)q).getDelegate().declareParameters("String firstName, String
>> lastName"); //<== additional line
>> List results = q.getResultList();
>>
>> Now getByName() will be called correctly, with "firstName" and "lastName"
>> in
>> the "params" map. I'm sure this is not the correct way, but I couldn't
>> figure out how else I can call declareParameters(). Without calling
>> declareParameters(), I'll get the ArgumentException.
>>
>> Also, I'm trying to find out how to use the RemoteCommitProvider.
>> Basically
>> everytime a commit happens, I'd like to send some notification to a
>> remote
>> server to track the changes. Sounds like RemoteCommitProvider is exactly
>> what I wanted, so any examples of how to implement my own
>> RemoteCommitProvier and how it's used would really help. Thanks!! =)
>>
>>
>> Marc Prud'hommeaux wrote:
>> >
>> >
>> > MethodQL is not a widely-used feature, so I wouldn't be surprised if
>> > there might be a bug in there somewhere.
>> >
>> > What does your getByName() method look like? Also, if you just
>> > exclude the parameter declaration from the code, do you still get the
>> > same exception?
>> >
>> >> BTW, the UserGuide does not give examples or go into details on a
>> >> lot of the
>> >> features. Any other documentation available besides the UserGuide and
>> >> Javadoc?
>> >
>> > The user guide and javadoc are the 2 main sources of documentation.
>> > There are occasional examples on the wiki at openjpa.apache.org, but
>> > there aren't that many at this time.
>> >
>> > Are there other features that you find under-documented? We are
>> > always looking to improve the docs.
>> >
>> >
>> >
>> > On Jun 25, 2007, at 3:31 PM, e33238 wrote:
>> >
>> >>
>> >> I'm trying to figure out how to use MethodQL. This is the example
>> >> given in
>> >> the UserGuide:
>> >>
>> >> // the method query language is 'openjpa.MethodQL'.
>> >> // set the query string to the method to execute, including full
>> >> class name;
>> >> if
>> >> // the class is in the candidate class' package or in the query
>> >> imports, you
>> >> // can omit the package; if the method is in the candidate class,
>> >> you can
>> >> omit
>> >> // the class name and just specify the method name
>> >> OpenJPAEntityManager oem = OpenJPAPersistence.cast(emf);
>> >> OpenJPAQuery q = oem.createQuery("openjpa.MethodQL",
>> >> "com.xyz.Finder.getByName");
>> >>
>> >> // set the type of objects that the method returns
>> >> q.setResultClass(Person.class);
>> >>
>> >> // parameters are passed the same way as in standard queries
>> >> q.setParameter("firstName", "Fred").setParameter("lastName", "Lucas");
>> >>
>> >> // this executes your method to get the results
>> >> List results = q.getResultList();
>> >>
>> >>
>> >> I created a Person class (that has "firstName" and "lastName") and
>> >> a Finder
>> >> class that has a static getByName() method. But I got an error when
>> >> q.getResultList() is called:--
>> >>
>> >> <0.9.7-incubating nonfatal user error>
>> >> org.apache.openjpa.persistence.ArgumentException: The parameter
>> >> name or
>> >> position "firstName" passed to execute() is not valid.  All map
>> >> keys must be
>> >> a declared parameter name or a number matching the parameter position.
>> >>
>> >> Any suggestions on what I may be doing wrong?
>> >>
>> >> BTW, the UserGuide does not give examples or go into details on a
>> >> lot of the
>> >> features. Any other documentation available besides the UserGuide and
>> >> Javadoc?
>> >>
>> >> Thanks!
>> >> --
>> >> View this message in context: http://www.nabble.com/Using-MethodQL-
>> >> tf3979366.html#a11296891
>> >> Sent from the OpenJPA Users mailing list archive at Nabble.com.
>> >>
>> >
>> >
>> >
>>
>> --
>> View this message in context:
>> http://www.nabble.com/Using-MethodQL-tf3979366.html#a11312798
>> Sent from the OpenJPA Users mailing list archive at Nabble.com.
>>
>>
> 
> 
> -- 
> Patrick Linskey
> 202 669 5907
> 
> 

-- 
View this message in context: http://www.nabble.com/RemoteCommitProviders-%28was-Re%3A-Using-MethodQL%29-tf3987826.html#a11328597
Sent from the OpenJPA Users mailing list archive at Nabble.com.


Mime
View raw message