BaseContext

2013-02-14 Thread Rich Tuers
Hello,

We are using Cayenne 3.0 and recently implemented the
WebApplicationContextFilter and we are using
BaseContext.getThreadObjectContext().

This is working great for our JSF Web Application.  However we introduced
Apache Camel into our tech stack.  Our Front-End Web Application post a
message to a queue that our backend picks up, processes the request and
then puts the return results back on a queue which the front end is
listening too.  When the Front-End receives the information I then want
to insert new records into the database.  Therefore I try to get a
BaseContext.getThreadObjectContext() however it throws a
java.lang.IllegalStateException: Current thread has no bound
ObjectContext.  So it appears the there is no ThreadLocal to attach to
and we are likely outside of the WebApplicationContext.  Everything works
great, when I am within our JSF application flow.

I've tried to catch the illegal state error and then return a
DataContext.createDataContext().   Unfortunately this did not work
either, I get an error saying something like the object is not part of
this DataContext.  So I already have the parent object from the original
request, I then use camel to send a request to the back-end, which
returns me data that I need to create the children.  I try setting the
parent on the child and I get this error.

So I'm not sure what to try next.  Any suggestions would be greatly
appreciated.

Thank you,
Rich



Re: BaseContext

2013-02-14 Thread John Huss
Try:

parentObject = myNewContext.localObject(parentObject);

Then proceed with the rest.  Then both objects will be in the same
ObjectContext.


On Thu, Feb 14, 2013 at 9:08 AM, Rich Tuers rtu...@oildex.com wrote:

 Hello,
 
 We are using Cayenne 3.0 and recently implemented the
 WebApplicationContextFilter and we are using
 BaseContext.getThreadObjectContext().
 
 This is working great for our JSF Web Application.  However we introduced
 Apache Camel into our tech stack.  Our Front-End Web Application post a
 message to a queue that our backend picks up, processes the request and
 then puts the return results back on a queue which the front end is
 listening too.  When the Front-End receives the information I then want
 to insert new records into the database.  Therefore I try to get a
 BaseContext.getThreadObjectContext() however it throws a
 java.lang.IllegalStateException: Current thread has no bound
 ObjectContext.  So it appears the there is no ThreadLocal to attach to
 and we are likely outside of the WebApplicationContext.  Everything works
 great, when I am within our JSF application flow.
 
 I've tried to catch the illegal state error and then return a
 DataContext.createDataContext().   Unfortunately this did not work
 either, I get an error saying something like the object is not part of
 this DataContext.  So I already have the parent object from the original
 request, I then use camel to send a request to the back-end, which
 returns me data that I need to create the children.  I try setting the
 parent on the child and I get this error.
 
 So I'm not sure what to try next.  Any suggestions would be greatly
 appreciated.
 
 Thank you,
 Rich




Re: BaseContext

2013-02-14 Thread Rich Tuers
Yes, I thought about doing that and this will probably address this one
issue.  I guess my real question is how do I keep from
BaseContext.getThreadObjectContext() from throwing that
IllegalStateException.  I hit the save button in the UI, create the
Parent objects which does get the ObjectContext back from
BaseContext.getThreadObjectContext().   However before I create the child
objects I put a message on a queue that Camel picks up, processes the
information and then puts the child object data back on the queue.  Which
I then pickup and try to create the new children with, using the
BaseContext.getThreadObjectContext().  At this point, it throws the
Illegal state exception.  I'm assuming once I go to Camel I lose the
ThreadLocal and therefore get this exception.

Basic Event Flow
---
1. User hits Save
2. Controller calls Front-End service to create Parent Object.  Parent
is successfully saved to the database.
3. Front-end service makes a call to the back-end service via Camel (to
get child data).
4. back-end service sends data back to the front-end service.
5. Front-end service tries to create the child objects but gets the
IllegalStateException.


public ObjectContext getDataContext() {
try {
// Successful when creating the parent
return BaseContext.getThreadObjectContext();
} catch (Exception ex) {
// Added this code since I was getting the exception.
// Trying to figure out how to avoid this exception
return DataContext.createDataContext();
}
}



Thanks,
Rich


   


On 2/14/13 8:24 AM, John Huss johnth...@gmail.com wrote:

Try:

parentObject = myNewContext.localObject(parentObject);

Then proceed with the rest.  Then both objects will be in the same
ObjectContext.


On Thu, Feb 14, 2013 at 9:08 AM, Rich Tuers rtu...@oildex.com wrote:

 Hello,
 
 We are using Cayenne 3.0 and recently implemented the
 WebApplicationContextFilter and we are using
 BaseContext.getThreadObjectContext().
 
 This is working great for our JSF Web Application.  However we
introduced
 Apache Camel into our tech stack.  Our Front-End Web Application post a
 message to a queue that our backend picks up, processes the request and
 then puts the return results back on a queue which the front end is
 listening too.  When the Front-End receives the information I then want
 to insert new records into the database.  Therefore I try to get a
 BaseContext.getThreadObjectContext() however it throws a
 java.lang.IllegalStateException: Current thread has no bound
 ObjectContext.  So it appears the there is no ThreadLocal to attach to
 and we are likely outside of the WebApplicationContext.  Everything
works
 great, when I am within our JSF application flow.
 
 I've tried to catch the illegal state error and then return a
 DataContext.createDataContext().   Unfortunately this did not work
 either, I get an error saying something like the object is not part of
 this DataContext.  So I already have the parent object from the
original
 request, I then use camel to send a request to the back-end, which
 returns me data that I need to create the children.  I try setting the
 parent on the child and I get this error.
 
 So I'm not sure what to try next.  Any suggestions would be greatly
 appreciated.
 
 Thank you,
 Rich





Re: BaseContext

2013-02-14 Thread John Huss
You have to bind a context to the thread:
http://cayenne.apache.org/docs/3.0/api/org/apache/cayenne/BaseContext.html#bindThreadObjectContext(org.apache.cayenne.ObjectContext)

Usually this is done by WebApplicationContextFilter.  But if you thread
isn't associated with a request or isn't covered by the filter then you
need to create and context and bind it yourself.  Also remember to unbind
at some point as well.


On Thu, Feb 14, 2013 at 9:40 AM, Rich Tuers rtu...@oildex.com wrote:

 Yes, I thought about doing that and this will probably address this one
 issue.  I guess my real question is how do I keep from
 BaseContext.getThreadObjectContext() from throwing that
 IllegalStateException.  I hit the save button in the UI, create the
 Parent objects which does get the ObjectContext back from
 BaseContext.getThreadObjectContext().   However before I create the child
 objects I put a message on a queue that Camel picks up, processes the
 information and then puts the child object data back on the queue.  Which
 I then pickup and try to create the new children with, using the
 BaseContext.getThreadObjectContext().  At this point, it throws the
 Illegal state exception.  I'm assuming once I go to Camel I lose the
 ThreadLocal and therefore get this exception.

 Basic Event Flow
 ---
 1. User hits Save
 2. Controller calls Front-End service to create Parent Object.  Parent
 is successfully saved to the database.
 3. Front-end service makes a call to the back-end service via Camel (to
 get child data).
 4. back-end service sends data back to the front-end service.
 5. Front-end service tries to create the child objects but gets the
 IllegalStateException.


 public ObjectContext getDataContext() {
 try {
 // Successful when creating the parent
 return BaseContext.getThreadObjectContext();
 } catch (Exception ex) {
 // Added this code since I was getting the exception.
 // Trying to figure out how to avoid this exception
 return DataContext.createDataContext();
 }
 }



 Thanks,
 Rich





 On 2/14/13 8:24 AM, John Huss johnth...@gmail.com wrote:

 Try:
 
 parentObject = myNewContext.localObject(parentObject);
 
 Then proceed with the rest.  Then both objects will be in the same
 ObjectContext.
 
 
 On Thu, Feb 14, 2013 at 9:08 AM, Rich Tuers rtu...@oildex.com wrote:
 
  Hello,
  
  We are using Cayenne 3.0 and recently implemented the
  WebApplicationContextFilter and we are using
  BaseContext.getThreadObjectContext().
  
  This is working great for our JSF Web Application.  However we
 introduced
  Apache Camel into our tech stack.  Our Front-End Web Application post a
  message to a queue that our backend picks up, processes the request and
  then puts the return results back on a queue which the front end is
  listening too.  When the Front-End receives the information I then want
  to insert new records into the database.  Therefore I try to get a
  BaseContext.getThreadObjectContext() however it throws a
  java.lang.IllegalStateException: Current thread has no bound
  ObjectContext.  So it appears the there is no ThreadLocal to attach to
  and we are likely outside of the WebApplicationContext.  Everything
 works
  great, when I am within our JSF application flow.
  
  I've tried to catch the illegal state error and then return a
  DataContext.createDataContext().   Unfortunately this did not work
  either, I get an error saying something like the object is not part of
  this DataContext.  So I already have the parent object from the
 original
  request, I then use camel to send a request to the back-end, which
  returns me data that I need to create the children.  I try setting the
  parent on the child and I get this error.
  
  So I'm not sure what to try next.  Any suggestions would be greatly
  appreciated.
  
  Thank you,
  Rich
 
 




Re: BaseContext

2013-02-14 Thread Rich Tuers
Thank you. Just tried this and it works great.  Thanks again.




On 2/14/13 8:47 AM, John Huss johnth...@gmail.com wrote:

You have to bind a context to the thread:
http://cayenne.apache.org/docs/3.0/api/org/apache/cayenne/BaseContext.html
#bindThreadObjectContext(org.apache.cayenne.ObjectContext)

Usually this is done by WebApplicationContextFilter.  But if you thread
isn't associated with a request or isn't covered by the filter then you
need to create and context and bind it yourself.  Also remember to unbind
at some point as well.


On Thu, Feb 14, 2013 at 9:40 AM, Rich Tuers rtu...@oildex.com wrote:

 Yes, I thought about doing that and this will probably address this one
 issue.  I guess my real question is how do I keep from
 BaseContext.getThreadObjectContext() from throwing that
 IllegalStateException.  I hit the save button in the UI, create the
 Parent objects which does get the ObjectContext back from
 BaseContext.getThreadObjectContext().   However before I create the
child
 objects I put a message on a queue that Camel picks up, processes the
 information and then puts the child object data back on the queue.
Which
 I then pickup and try to create the new children with, using the
 BaseContext.getThreadObjectContext().  At this point, it throws the
 Illegal state exception.  I'm assuming once I go to Camel I lose the
 ThreadLocal and therefore get this exception.

 Basic Event Flow
 ---
 1. User hits Save
 2. Controller calls Front-End service to create Parent Object.  Parent
 is successfully saved to the database.
 3. Front-end service makes a call to the back-end service via Camel
(to
 get child data).
 4. back-end service sends data back to the front-end service.
 5. Front-end service tries to create the child objects but gets the
 IllegalStateException.


 public ObjectContext getDataContext() {
 try {
 // Successful when creating the parent
 return BaseContext.getThreadObjectContext();
 } catch (Exception ex) {
 // Added this code since I was getting the exception.
 // Trying to figure out how to avoid this exception
 return DataContext.createDataContext();
 }
 }



 Thanks,
 Rich





 On 2/14/13 8:24 AM, John Huss johnth...@gmail.com wrote:

 Try:
 
 parentObject = myNewContext.localObject(parentObject);
 
 Then proceed with the rest.  Then both objects will be in the same
 ObjectContext.
 
 
 On Thu, Feb 14, 2013 at 9:08 AM, Rich Tuers rtu...@oildex.com wrote:
 
  Hello,
  
  We are using Cayenne 3.0 and recently implemented the
  WebApplicationContextFilter and we are using
  BaseContext.getThreadObjectContext().
  
  This is working great for our JSF Web Application.  However we
 introduced
  Apache Camel into our tech stack.  Our Front-End Web Application
post a
  message to a queue that our backend picks up, processes the request
and
  then puts the return results back on a queue which the front end is
  listening too.  When the Front-End receives the information I then
want
  to insert new records into the database.  Therefore I try to get a
  BaseContext.getThreadObjectContext() however it throws a
  java.lang.IllegalStateException: Current thread has no bound
  ObjectContext.  So it appears the there is no ThreadLocal to
attach to
  and we are likely outside of the WebApplicationContext.  Everything
 works
  great, when I am within our JSF application flow.
  
  I've tried to catch the illegal state error and then return a
  DataContext.createDataContext().   Unfortunately this did not work
  either, I get an error saying something like the object is not
part of
  this DataContext.  So I already have the parent object from the
 original
  request, I then use camel to send a request to the back-end, which
  returns me data that I need to create the children.  I try setting
the
  parent on the child and I get this error.
  
  So I'm not sure what to try next.  Any suggestions would be greatly
  appreciated.
  
  Thank you,
  Rich
 
 





partially hollow objects

2013-02-14 Thread Aristedes Maniatis

In our Cayenne ROP application we have some tables with very large BLOB fields. 
We want to be able to fetch the remaining columns to the client, without the 
BLOBs. I am after some ideas on how to best approach this:


1. Create two tables and two Cayenne Java entities to match

Cons: makes the code and database messy since we are dealing with one-to-one 
relationships where there isn't really any logical relation


2. Create one database table and use single-table inheritance: the superclass 
(say 'Painting') has all the fields and the subclass ('PaintingInfo') only the 
lightweight fields

Cons: the code is still messy since casting a PaintingInfo to Painting (should 
you want to view the BLOB) isn't really possible. You would have to get the PK 
and then perform another full fetch on the parent. And I'd be concerned about 
having two objects in memory at the same time which point to the same data, but 
aren't synchronised to each other.


3. Devise some mechanism for Cayenne to have not just hollow objects (like what 
happens with paged queries) but hollow attributes. Then we only lazily fetch 
the attribute data when it is needed (if at all). This could be ROP specific 
(that is, the BLOB attributes are fully fetched from the database but not sent 
to the client until needed) or perhaps this approach would also be useful in a 
non-ROP environment for lazily loading columns.



Any thoughts from people who have run into similar issues? I'd like to avoid 
DataRows and all that since that just makes the code really messy again.



Ari



--
--
Aristedes Maniatis
ish
http://www.ish.com.au
Level 1, 30 Wilson Street Newtown 2042 Australia
phone +61 2 9550 5001   fax +61 2 9550 4001
GPG fingerprint CBFB 84B4 738D 4E87 5E5C  5EFA EF6A 7D2E 3E49 102A