[appengine-java] Re: Appsstats for cronjob

2011-08-26 Thread Sydney
I had a Guice filter and I fixed it by putting the AppStats filter before 
the Guice filter

-- 
You received this message because you are subscribed to the Google Groups 
Google App Engine for Java group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/google-appengine-java/-/0OkWXPwEuoMJ.
To post to this group, send email to google-appengine-java@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.



[appengine-java] Re: Appsstats for cronjob

2011-08-25 Thread Sydney
The only difference between my web.xml and the one on the documentation page 
is the url-pattern element. Mine is set to /cron/*, so can you confirm that 
the appstats filter is applied to all the URLs starting by /cron/* (e.g. 
/cron/myjob).

Is there something else to configure so appstats events will be recorded?

-- 
You received this message because you are subscribed to the Google Groups 
Google App Engine for Java group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/google-appengine-java/-/vaG0XcdrY0YJ.
To post to this group, send email to google-appengine-java@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.



[appengine-java] Appsstats for cronjob

2011-08-21 Thread Sydney
I configured my web.xml to enable appstats for my cron job. My cron job is 
handled by a servlet at the URL /cron/myjob and execute once an hour. When I 
access the appstats admin interface. I can see stats about /appstats URLs 
but not about /cron. I was expecting appstats to record events everytime the 
cron job has been executed. Here is my web.xml conf:

filter
filter-nameappstats/filter-name
filter-classcom.google.appengine.tools.appstats.AppstatsFilter/filter-class
init-param
param-namelogMessage/param-name
param-valueAppstats available: /appstats/details?time={ID}/param-value
/init-param
/filter
filter-mapping
filter-nameappstats/filter-name
url-pattern/cron/*/url-pattern
/filter-mapping
!-- AppStats Servlet --
servlet
servlet-nameappstats/servlet-name
servlet-classcom.google.appengine.tools.appstats.AppstatsServlet/servlet-class
/servlet
servlet-mapping
servlet-nameappstats/servlet-name
url-pattern/appstats/*/url-pattern
/servlet-mapping


-- 
You received this message because you are subscribed to the Google Groups 
Google App Engine for Java group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/google-appengine-java/-/hBl7C4q6Aj0J.
To post to this group, send email to google-appengine-java@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.



[appengine-java] openId with user service redirection clarification

2011-02-26 Thread Sydney
I want to implement openId using a popup as the UI. So in my view I create a 
popup that redirect to a servlet using javascript:

   public void onLogin(String provider, String username) {
   String url = /openid/mylogin?provider= + provider;
   if (username != null) {
   url = url + username= + username;
   }
   String features = 
width=450,height=500,location=1,status=1,resizable=yes;
   JavaScriptObject window = WindowUtil.newWindow(url, login, 
features);
   }

   public static native JavaScriptObject newWindow(String url, String name,
   String features)/*-{
 var window = $wnd.open(url, name, features);
 // Center the window
 var width = @com.google.gwt.user.client.Window::getClientWidth()();
 var height = @com.google.gwt.user.client.Window::getClientHeight()();
 window.moveTo((width - 450) / 2, (height - 500) / 2);
 return window;
   }-*/;

The servlet:

   @Override
   public void doPost(HttpServletRequest request, HttpServletResponse 
response)
   throws IOException, ServletException {

   UserService userService = UserServiceFactory.getUserService();
   User user = userService.getCurrentUser();

   String provider = request.getParameter(provider);
   if (user == null) {
   if (provider != null) {
   // Provider
   MapString, String authDomainMap = new HashMapString, 
String();
   authDomainMap.put(google, google.com);
   authDomainMap.put(yahoo, yahoo.com);
   // URL
   MapString, String federatedIdentityMap = new 
HashMapString, String();
   federatedIdentityMap.put(google,
   https://www.google.com/accounts/o8/id;);
   federatedIdentityMap.put(yahoo,
   
http://open.login.yahooapis.com/openid20/www.yahoo.com/xrds;);
   // Attributes
   SetString attributesRequest = new HashSetString();
   // attributesRequest.add(openid.mode=checkid_immediate);
   // 
attributesRequest.add(openid.ns=http://specs.openid.net/auth/2.0;);
   // 
attributesRequest.add(openid.return_to=http://www.google.com;);

   String loginURL = userService.createLoginURL(
   request.getRequestURI(), authDomainMap.get(provider),
   federatedIdentityMap.get(provider), 
attributesRequest);
   System.out.println(loginURL);
   response.sendRedirect(loginURL);
   }
   } else {
   // Associate the session to the current user
   userDao.get().setCurrentUser(user);
   }
   }

During the execution, the dummy form is displayed and then I click on Log 
In. The loginURL is /_ah/login?continue=%2Fopenid%2Fmylogin

After clicking on Log In, the popup is closed and nothing happen, except 
that the user is now logged in. At that point I was expecting that _ah/login 
was called to set the user, and then it would redirect to the 
/openid/mylogin (continue parameter), so I could assign the user to the 
current session.

I know that the user has been logged in because then when I open the popup 
again, the user is not null and I can assign the user to the current 
session. I only tested my code on my dev server and not on app engine.

-- 
You received this message because you are subscribed to the Google Groups 
Google App Engine for Java group.
To post to this group, send email to google-appengine-java@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.



[appengine-java] Re: openId with user service redirection clarification

2011-02-26 Thread Sydney
After clicking the Log In button, the popup should be redirected to 
/openid/mylogin and User should be set. Is that correct? If so, it seems 
that the popup is not redirected (no stop at the breakpoint in the servlet).

-- 
You received this message because you are subscribed to the Google Groups 
Google App Engine for Java group.
To post to this group, send email to google-appengine-java@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.



[appengine-java] Re: openId with user service redirection clarification

2011-02-26 Thread Sydney
Seems that it is firefox related. It's working well with Chrome. In FF it's 
working the first time when working with a clean session (like private 
browsing). But the second time, the redirection is not done. It might be a 
problem of cache. Here is the sequence of execution

Clean FF session
Popup displays the dummy form
Click on Log In
Redirection OK
Logout
Redirection OK
Popup displays the dummy form
Click on Log In
Redirection is not done
Refresh I can see the user is logged in
Logout
Redirection OK

This is weird because the redirection for the logout is working but not for 
the login.

Any ideas.

Thanks

-- 
You received this message because you are subscribed to the Google Groups 
Google App Engine for Java group.
To post to this group, send email to google-appengine-java@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.



[appengine-java] Denormalization model help

2011-01-09 Thread Sydney
I have the following model:

Country (name*, ListCity)
City (name*, ListEvent)
Event (id*, description, timeGMT, ListTicket, ListPerformer)
Ticket (id*, type, price, quantity)
Performer(id*, band, startTime)

So this is a 4-level deep model. Here is some of the query I want to run:
All Country that has Event that occurs after a specific date
All City from a specific Country that has Event that occurs after a specific 
date
All Event from a specific City that has Event that occurs after a specific 
date

With these 3 queries I can create an interface where a user select a 
country, then the city and finally gets the events. I won’t be able to do 
these queries with my current model but I read that denormalization is 
usually the answer. Is there a reference document explaining 
denormalization?

From what I read, to run the query I want, I will have to duplicate the 
country and city name in the event entity. Then I will be able to run the 
query with no join. Denormalization looks like a SQL View except that it is 
stored.

Thanks

-- 
You received this message because you are subscribed to the Google Groups 
Google App Engine for Java group.
To post to this group, send email to google-appengine-j...@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.



[appengine-java] url fetch quota: ResponseTooLargeException

2010-12-15 Thread Sydney
Hello, 

I got a ResponseTooLargeException when using the url fetch service. I 
checked the quota (
http://code.google.com/appengine/docs/java/urlfetch/overview.html#Quotas_and_Limits)
 and 
my request and response are within these quotas. Here is the response header 
when fetching the url in a browser:

Date Wed, 15 Dec 2010 23:45:05 GMT
Server Microsoft-IIS/6.0
X-Powered-By ASP.NET
X-AspNet-Version 2.0.50727
Cache-Control private
Content-Type text/xml; charset=utf-8
Content-Length 1141487

My app is not deployed on app engine, so I just tested locally. I am using 
app engine 1.4.0

Thanks

-- 
You received this message because you are subscribed to the Google Groups 
Google App Engine for Java group.
To post to this group, send email to google-appengine-j...@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.



[appengine-java] Persistent Local Datastore

2010-07-29 Thread Sydney
I have a question that seems trivial but I can't figure out how to do
it. I would like to be able to test my application but with persistent
data. So I need to create a local environment to store the data. I
read the documentation about unit testing but the default behavior is
to store the data in memory and then wipe out everything. Is there a
way to have an environment where the data would be persistent on the
disk. I don't know if it matters but I am using twig-persist to deal
with the datastore.

-- 
You received this message because you are subscribed to the Google Groups 
Google App Engine for Java group.
To post to this group, send email to google-appengine-j...@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.



[appengine-java] Re: One-to-many querying for a child instance

2010-01-30 Thread Sydney
The thread 
http://groups.google.com/group/google-appengine-java/browse_thread/thread/2acea43161d8ac5/96c77de6c686526d?lnk=gst
is dealing with the same kind of problem. Basically it's not possible
to filter on the name property. So I guess I have two ways of doing
it.

1/ Creating the key by hand bu I have to know the parent key.

Key key = new KeyFactory.Builder(A, A).addChild(B,
B).getKey();
B bp = pm.getObjectById(B.class, key);

2/ Using an extent and filter the name property if I don't know the
parent key

B bp = null;
ExtentB e = pm.getExtent(B.class);
IteratorB it = e.iterator();
while (it.hasNext()) {
B rsb = it.next();
if (B.equals(rsb.getName())) {
bp = rsb;
break;
}
}
e.closeAll();


On Jan 27, 11:47 pm, Rusty Wright rwright.li...@gmail.com wrote:
 Yes, as you can surmise, I'm guessing.

 What's this annotation on the name property for?

 @Extension(vendorName=datanucleus, key=gae.pk-name, value=true)





 Sydneywrote:
  Since I declared the parameter with query.declareParameters(String
  nameParam);, the colon is not valid. As expected I got an exception
  org.datanucleus.store.query.QueryCompilerSyntaxException: Explicit
  parameters defined for query, yet implicit parameter syntax
  (:nameParam) found

  On Jan 27, 4:39 pm, Rusty Wright rwright.li...@gmail.com wrote:
  Do you need a colon in front of nameParam?

              query.setFilter(name == :nameParam);

  Sydneywrote:
  The query returns no result.
              ApiProxy.setEnvironmentForCurrentThread(new TestEnvironment
  ());
              ApiProxy.setDelegate(new ApiProxyLocalImpl(new File(.))
  {
              });
              A a = new A(A);
              B b = new B(B);
              a.getBs().add(b);
              PersistenceManagerFactory pmf =
  JDOHelper.getPersistenceManagerFactory(transactions-optional);
              PersistenceManager pm = pmf.getPersistenceManager();
              Transaction tx = pm.currentTransaction();
              try {
                  tx.begin();
                  pm.makePersistent(a);
                  tx.commit();
              } finally {
                  if (tx.isActive()) {
                      tx.rollback();
                  }
              }
              System.out.println(a.getKey());
              A ap = pm.getObjectById(A.class, A);
              System.out.println(ap.getKey());
              Query query = pm.newQuery(B.class);
              query.setFilter(name == nameParam);
              query.declareParameters(String nameParam);
              ListB rs = (ListB) query.execute(B);
              System.out.println(rs.size());
  On Jan 23, 12:20 am, John Patterson jdpatter...@gmail.com wrote:
  Execute a query on the name property of B rather than loading it by  
  key.  If the name is unique the result should only contain one B.
  On 23 Jan 2010, at 11:41,Sydneywrote:
  I have a one to many relationship. There is a problem in the way I
  query for a B object. I was wondering what is the best way (most
  efficient) to do that.
  A a = new A(A);
  B b = new B(B);
  a.getBs().add(b);
  pm.makePersistent(a); // it's done inside a transaction
  A ap = pm.getObjectById(A.class, A); // FINE
  B bp = pm.getObjectById(B.class, B); // NOT FOUND Exception
  I guess B is not found because the real key is not B but B + A key.
  How do you get the B object when you don't know nothing about A?
  public class A {
    �...@primarykey
    �...@persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    �...@extension(vendorName = datanucleus, key = gae.encoded-pk,
  value = true)
     private String key;
    �...@persistent
    �...@extension(vendorName = datanucleus, key = gae.pk-name, value
  = true)
     private String name;
    �...@persistent(mappedBy = a)
     private ListB bs;
     public A(String name) {
         this.name = name;
         bs = new ArrayListB();
     }
  ... Getter/Setter
  }
  @PersistenceCapable(identityType =
  javax.jdo.annotations.IdentityType.APPLICATION)
  public class B {
    �...@primarykey
    �...@persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    �...@extension(vendorName = datanucleus, key = gae.encoded-pk,
  value = true)
     private String key;
    �...@persistent
    �...@extension(vendorName = datanucleus, key = gae.pk-name, value
  = true)
     private String name;
    �...@persistent
     private A a;
     public B(String name) {
         this.name = name;
     }
  ... Getter/Setter
  }
  --
  You received this message because you are subscribed to the Google  
  Groups Google App Engine for Java group.
  To post to this group, send email to 
  google-appengine-java@googlegroups.com
  .
  To unsubscribe from this group, send email to 
  google-appengine-java+unsubscr...@googlegroups.com
  .
  For more options, visit this group 
  

[appengine-java] Re: One-to-many querying for a child instance

2010-01-27 Thread Sydney
Since I declared the parameter with query.declareParameters(String
nameParam);, the colon is not valid. As expected I got an exception
org.datanucleus.store.query.QueryCompilerSyntaxException: Explicit
parameters defined for query, yet implicit parameter syntax
(:nameParam) found

On Jan 27, 4:39 pm, Rusty Wright rwright.li...@gmail.com wrote:
 Do you need a colon in front of nameParam?

             query.setFilter(name == :nameParam);



 Sydneywrote:
  The query returns no result.

              ApiProxy.setEnvironmentForCurrentThread(new TestEnvironment
  ());
              ApiProxy.setDelegate(new ApiProxyLocalImpl(new File(.))
  {
              });
              A a = new A(A);
              B b = new B(B);
              a.getBs().add(b);
              PersistenceManagerFactory pmf =
  JDOHelper.getPersistenceManagerFactory(transactions-optional);
              PersistenceManager pm = pmf.getPersistenceManager();
              Transaction tx = pm.currentTransaction();
              try {
                  tx.begin();
                  pm.makePersistent(a);
                  tx.commit();
              } finally {
                  if (tx.isActive()) {
                      tx.rollback();
                  }
              }

              System.out.println(a.getKey());
              A ap = pm.getObjectById(A.class, A);
              System.out.println(ap.getKey());
              Query query = pm.newQuery(B.class);
              query.setFilter(name == nameParam);
              query.declareParameters(String nameParam);
              ListB rs = (ListB) query.execute(B);
              System.out.println(rs.size());

  On Jan 23, 12:20 am, John Patterson jdpatter...@gmail.com wrote:
  Execute a query on the name property of B rather than loading it by  
  key.  If the name is unique the result should only contain one B.

  On 23 Jan 2010, at 11:41,Sydneywrote:

  I have a one to many relationship. There is a problem in the way I
  query for a B object. I was wondering what is the best way (most
  efficient) to do that.
  A a = new A(A);
  B b = new B(B);
  a.getBs().add(b);
  pm.makePersistent(a); // it's done inside a transaction
  A ap = pm.getObjectById(A.class, A); // FINE
  B bp = pm.getObjectById(B.class, B); // NOT FOUND Exception
  I guess B is not found because the real key is not B but B + A key.
  How do you get the B object when you don't know nothing about A?
  public class A {
    �...@primarykey
    �...@persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    �...@extension(vendorName = datanucleus, key = gae.encoded-pk,
  value = true)
     private String key;
    �...@persistent
    �...@extension(vendorName = datanucleus, key = gae.pk-name, value
  = true)
     private String name;
    �...@persistent(mappedBy = a)
     private ListB bs;
     public A(String name) {
         this.name = name;
         bs = new ArrayListB();
     }
  ... Getter/Setter
  }
  @PersistenceCapable(identityType =
  javax.jdo.annotations.IdentityType.APPLICATION)
  public class B {
    �...@primarykey
    �...@persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    �...@extension(vendorName = datanucleus, key = gae.encoded-pk,
  value = true)
     private String key;
    �...@persistent
    �...@extension(vendorName = datanucleus, key = gae.pk-name, value
  = true)
     private String name;
    �...@persistent
     private A a;
     public B(String name) {
         this.name = name;
     }
  ... Getter/Setter
  }
  --
  You received this message because you are subscribed to the Google  
  Groups Google App Engine for Java group.
  To post to this group, send email to 
  google-appengine-java@googlegroups.com
  .
  To unsubscribe from this group, send email to 
  google-appengine-java+unsubscr...@googlegroups.com
  .
  For more options, visit this group 
  athttp://groups.google.com/group/google-appengine-java?hl=en
  .

-- 
You received this message because you are subscribed to the Google Groups 
Google App Engine for Java group.
To post to this group, send email to google-appengine-j...@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.



[appengine-java] Re: One-to-many querying for a child instance

2010-01-27 Thread Sydney
I used an extent to verify that a B with a B name exists.

ExtentB e = pm.getExtent(B.class);
IteratorB it = e.iterator();
while (it.hasNext()) {
B rsb = it.next();
System.out.println(rsb.getName());
System.out.println(rsb.getKey());
}
e.closeAll();

The output:

B
agR0ZXN0chALEgFBIgFBDAsSAUIiAUIM

On Jan 27, 6:41 pm, Sydney sydney.henr...@gmail.com wrote:
 Since I declared the parameter with query.declareParameters(String
 nameParam);, the colon is not valid. As expected I got an exception
 org.datanucleus.store.query.QueryCompilerSyntaxException: Explicit
 parameters defined for query, yet implicit parameter syntax
 (:nameParam) found

 On Jan 27, 4:39 pm, Rusty Wright rwright.li...@gmail.com wrote:



  Do you need a colon in front of nameParam?

              query.setFilter(name == :nameParam);

  Sydneywrote:
   The query returns no result.

               ApiProxy.setEnvironmentForCurrentThread(new TestEnvironment
   ());
               ApiProxy.setDelegate(new ApiProxyLocalImpl(new File(.))
   {
               });
               A a = new A(A);
               B b = new B(B);
               a.getBs().add(b);
               PersistenceManagerFactory pmf =
   JDOHelper.getPersistenceManagerFactory(transactions-optional);
               PersistenceManager pm = pmf.getPersistenceManager();
               Transaction tx = pm.currentTransaction();
               try {
                   tx.begin();
                   pm.makePersistent(a);
                   tx.commit();
               } finally {
                   if (tx.isActive()) {
                       tx.rollback();
                   }
               }

               System.out.println(a.getKey());
               A ap = pm.getObjectById(A.class, A);
               System.out.println(ap.getKey());
               Query query = pm.newQuery(B.class);
               query.setFilter(name == nameParam);
               query.declareParameters(String nameParam);
               ListB rs = (ListB) query.execute(B);
               System.out.println(rs.size());

   On Jan 23, 12:20 am, John Patterson jdpatter...@gmail.com wrote:
   Execute a query on the name property of B rather than loading it by  
   key.  If the name is unique the result should only contain one B.

   On 23 Jan 2010, at 11:41,Sydneywrote:

   I have a one to many relationship. There is a problem in the way I
   query for a B object. I was wondering what is the best way (most
   efficient) to do that.
   A a = new A(A);
   B b = new B(B);
   a.getBs().add(b);
   pm.makePersistent(a); // it's done inside a transaction
   A ap = pm.getObjectById(A.class, A); // FINE
   B bp = pm.getObjectById(B.class, B); // NOT FOUND Exception
   I guess B is not found because the real key is not B but B + A key.
   How do you get the B object when you don't know nothing about A?
   public class A {
     �...@primarykey
     �...@persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
     �...@extension(vendorName = datanucleus, key = gae.encoded-pk,
   value = true)
      private String key;
     �...@persistent
     �...@extension(vendorName = datanucleus, key = gae.pk-name, value
   = true)
      private String name;
     �...@persistent(mappedBy = a)
      private ListB bs;
      public A(String name) {
          this.name = name;
          bs = new ArrayListB();
      }
   ... Getter/Setter
   }
   @PersistenceCapable(identityType =
   javax.jdo.annotations.IdentityType.APPLICATION)
   public class B {
     �...@primarykey
     �...@persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
     �...@extension(vendorName = datanucleus, key = gae.encoded-pk,
   value = true)
      private String key;
     �...@persistent
     �...@extension(vendorName = datanucleus, key = gae.pk-name, value
   = true)
      private String name;
     �...@persistent
      private A a;
      public B(String name) {
          this.name = name;
      }
   ... Getter/Setter
   }
   --
   You received this message because you are subscribed to the Google  
   Groups Google App Engine for Java group.
   To post to this group, send email to 
   google-appengine-java@googlegroups.com
   .
   To unsubscribe from this group, send email to 
   google-appengine-java+unsubscr...@googlegroups.com
   .
   For more options, visit this group 
   athttp://groups.google.com/group/google-appengine-java?hl=en
   .

-- 
You received this message because you are subscribed to the Google Groups 
Google App Engine for Java group.
To post to this group, send email to google-appengine-j...@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.



[appengine-java] Re: One-to-many querying for a child instance

2010-01-26 Thread Sydney
The query returns no result.

ApiProxy.setEnvironmentForCurrentThread(new TestEnvironment
());
ApiProxy.setDelegate(new ApiProxyLocalImpl(new File(.))
{
});
A a = new A(A);
B b = new B(B);
a.getBs().add(b);
PersistenceManagerFactory pmf =
JDOHelper.getPersistenceManagerFactory(transactions-optional);
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
pm.makePersistent(a);
tx.commit();
} finally {
if (tx.isActive()) {
tx.rollback();
}
}

System.out.println(a.getKey());
A ap = pm.getObjectById(A.class, A);
System.out.println(ap.getKey());
Query query = pm.newQuery(B.class);
query.setFilter(name == nameParam);
query.declareParameters(String nameParam);
ListB rs = (ListB) query.execute(B);
System.out.println(rs.size());


On Jan 23, 12:20 am, John Patterson jdpatter...@gmail.com wrote:
 Execute a query on the name property of B rather than loading it by  
 key.  If the name is unique the result should only contain one B.

 On 23 Jan 2010, at 11:41,Sydneywrote:



  I have a one to many relationship. There is a problem in the way I
  query for a B object. I was wondering what is the best way (most
  efficient) to do that.

  A a = new A(A);
  B b = new B(B);
  a.getBs().add(b);
  pm.makePersistent(a); // it's done inside a transaction
  A ap = pm.getObjectById(A.class, A); // FINE
  B bp = pm.getObjectById(B.class, B); // NOT FOUND Exception

  I guess B is not found because the real key is not B but B + A key.
  How do you get the B object when you don't know nothing about A?

  public class A {

    �...@primarykey
    �...@persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    �...@extension(vendorName = datanucleus, key = gae.encoded-pk,
  value = true)
     private String key;
    �...@persistent
    �...@extension(vendorName = datanucleus, key = gae.pk-name, value
  = true)
     private String name;
    �...@persistent(mappedBy = a)
     private ListB bs;

     public A(String name) {
         this.name = name;
         bs = new ArrayListB();
     }
  ... Getter/Setter
  }

  @PersistenceCapable(identityType =
  javax.jdo.annotations.IdentityType.APPLICATION)
  public class B {

    �...@primarykey
    �...@persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    �...@extension(vendorName = datanucleus, key = gae.encoded-pk,
  value = true)
     private String key;
    �...@persistent
    �...@extension(vendorName = datanucleus, key = gae.pk-name, value
  = true)
     private String name;
    �...@persistent
     private A a;

     public B(String name) {
         this.name = name;
     }
  ... Getter/Setter
  }

  --
  You received this message because you are subscribed to the Google  
  Groups Google App Engine for Java group.
  To post to this group, send email to google-appengine-java@googlegroups.com
  .
  To unsubscribe from this group, send email to 
  google-appengine-java+unsubscr...@googlegroups.com
  .
  For more options, visit this group 
  athttp://groups.google.com/group/google-appengine-java?hl=en
  .

-- 
You received this message because you are subscribed to the Google Groups 
Google App Engine for Java group.
To post to this group, send email to google-appengine-j...@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.



[appengine-java] One-to-many querying for a child instance

2010-01-22 Thread Sydney
I have a one to many relationship. There is a problem in the way I
query for a B object. I was wondering what is the best way (most
efficient) to do that.

A a = new A(A);
B b = new B(B);
a.getBs().add(b);
pm.makePersistent(a); // it's done inside a transaction
A ap = pm.getObjectById(A.class, A); // FINE
B bp = pm.getObjectById(B.class, B); // NOT FOUND Exception

I guess B is not found because the real key is not B but B + A key.
How do you get the B object when you don't know nothing about A?

public class A {

@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
@Extension(vendorName = datanucleus, key = gae.encoded-pk,
value = true)
private String key;
@Persistent
@Extension(vendorName = datanucleus, key = gae.pk-name, value
= true)
private String name;
@Persistent(mappedBy = a)
private ListB bs;

public A(String name) {
this.name = name;
bs = new ArrayListB();
}
... Getter/Setter
}

@PersistenceCapable(identityType =
javax.jdo.annotations.IdentityType.APPLICATION)
public class B {

@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
@Extension(vendorName = datanucleus, key = gae.encoded-pk,
value = true)
private String key;
@Persistent
@Extension(vendorName = datanucleus, key = gae.pk-name, value
= true)
private String name;
@Persistent
private A a;

public B(String name) {
this.name = name;
}
... Getter/Setter
}

-- 
You received this message because you are subscribed to the Google Groups 
Google App Engine for Java group.
To post to this group, send email to google-appengine-j...@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.