[appengine-java] Batch load from DataStore?

2010-02-21 Thread Ftaylor
Is this the fastest way to load all of the Elements of a given type
from the DataStore?

@SuppressWarnings(unchecked)
public static final ListPage loadAllPagesFromDataStore() {
ListPage pages = new ArrayListPage();
PersistenceManager pm = PMF.get().getPersistenceManager();
Query query = null;
try {
query = pm.newQuery(Page.class);
ListPage results = (ListPage)query.execute();
if(results.iterator().hasNext()) {
IteratorPage it = results.iterator();
while(it.hasNext())
pages.add(pm.detachCopy(it.next()));
}
} finally {
query.closeAll();
pm.close();
}
return pages;
}

I ask because the datastore is meant to be very fast at reading huge
amounts of data, but slow at writing huge amounts of data, yet this
query is quite slow for only 100 elements.

Thanks,

Finbarr

-- 
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: Unsupported method contains while parsing expression:

2010-02-03 Thread Ftaylor
There actually seems to be a mistake in the documentation:

 // Give me all Employees with lastName equal to Smith or Jones
Query query = pm.newQuery(Employee.class,
  :p.contains(lastName));
query.execute(Arrays.asList(Smith, Jones));

Surely it should be:

 // Give me all Employees with lastName equal to Smith or Jones
Query query = pm.newQuery(Employee.class,
  p.contains(:lastName));
query.execute(Arrays.asList(Smith, Jones));


On Feb 2, 10:29 pm, Ikai L (Google) ika...@google.com wrote:
 Oy, this is what I get for not running code before posting it. Good looking
 out.

 On Tue, Feb 2, 2010 at 1:06 AM, datanucleus andy_jeffer...@yahoo.comwrote:





      query.setFilter(aliases == alias);

  That is invalid JDOQL syntax; the spec is the spec and JDOQL uses Java
  syntax.
  If you have a collection field then the filter should be

  aliases.contains(:alias)

  The poster put the colon in front of a field name (wrong), and
  declared a parameter as a variable (wrong).

  --
  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.comgoogle-appengine-java%2B 
  unsubscr...@googlegroups.com
  .
  For more options, visit this group at
 http://groups.google.com/group/google-appengine-java?hl=en.

 --
 Ikai Lan
 Developer Programs Engineer, Google App 
 Enginehttp://googleappengine.blogspot.com|http://twitter.com/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-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: Unsupported method contains while parsing expression:

2010-02-03 Thread Ftaylor
Wow that mistake in the documentation wasted days of my time. Thankyou
datanucleus.

On Feb 3, 5:40 pm, Ftaylor finbarrtay...@googlemail.com wrote:
 There actually seems to be a mistake in the documentation:

  // Give me all Employees with lastName equal to Smith or Jones

     Query query = pm.newQuery(Employee.class,
                               :p.contains(lastName));
     query.execute(Arrays.asList(Smith, Jones));

 Surely it should be:

  // Give me all Employees with lastName equal to Smith or Jones

     Query query = pm.newQuery(Employee.class,
                               p.contains(:lastName));
     query.execute(Arrays.asList(Smith, Jones));

 On Feb 2, 10:29 pm, Ikai L (Google) ika...@google.com wrote:



  Oy, this is what I get for not running code before posting it. Good looking
  out.

  On Tue, Feb 2, 2010 at 1:06 AM, datanucleus andy_jeffer...@yahoo.comwrote:

   query.setFilter(aliases == alias);

   That is invalid JDOQL syntax; the spec is the spec and JDOQL uses Java
   syntax.
   If you have a collection field then the filter should be

   aliases.contains(:alias)

   The poster put the colon in front of a field name (wrong), and
   declared a parameter as a variable (wrong).

   --
   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.comgoogle-appengine-java%2B
unsubscr...@googlegroups.com
   .
   For more options, visit this group at
  http://groups.google.com/group/google-appengine-java?hl=en.

  --
  Ikai Lan
  Developer Programs Engineer, Google App 
  Enginehttp://googleappengine.blogspot.com|http://twitter.com/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-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] Unsupported method contains while parsing expression:

2010-01-28 Thread Ftaylor
Code:

Class Page {

ListString aliases;

...

query = pm.newQuery(Page.class);
query.setFilter(:aliases.contains(alias));
query.declareVariables(String alias);
ListPage results = (ListPage)query.execute(alias);

...

}

I want to select Page objects where the aliases property contains a
given alias String value. Is there any way to do this? I tried as
above and got an exception:

Problem with query SELECT FROM getimgs.Page WHERE :aliases.contains
(alias) VARIABLES String alias: Unsupported method contains while
parsing expression: InvokeExpression{[ParameterExpression
{aliases}].contains(VariableExpression{alias})}

If this cannot be done with JDOQL, the only solution I can think of is
selecting every Page object, then looping through them and using
Java's contains method, but this sucks somewhat.

Anyone?

Cheers,

Finbarr

-- 
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] Help with One to Many owned relationship and Datastore

2010-01-13 Thread Ftaylor
I have a class Page with a variable ListIMG images.

@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class Page {
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Key key;

@Persistent
private final ListIMG images;

...

}

My IMG class looks like this:

@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class IMG {

...

@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private final int number;

...

}

I don't fully understand how the one to many key using
KeyFactory.Builder works. In order to make an instance of Page
persistent using the datastore, do I need to loop through every IMG
instance like this:

for(IMG image : images) {
KeyFactory.Builder keyBuilder = new KeyFactory.Builder
(Page.class.getSimpleName(), page-id);
keyBuilder.addChild(IMG.class.getSimpleName(), image.getID());
Key key = keyBuilder.getKey();
image.setKey(key);
pm.makePersistent(image);
}

or can I do this?

KeyFactory.Builder keyBuilder = new KeyFactory.Builder
(Page.class.getSimpleName(), page-id);
for(IMG image : images) {
keyBuilder.addChild(IMG.class.getSimpleName(), image.getID());
}
Key key = keyBuilder.getKey();
for(IMG image : images) {
image.setKey(key);
pm.makePersistent(image);
}

or can I just do this?

Page p;
...
Key key = KeyFactory.createKey(Page.class.getSimpleName(), page.getID
());
pm.makePersistent(page);
-- 
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] Need Help with One to Many relationships in Datastore

2010-01-13 Thread Ftaylor
I have a class Page with a variable ListIMG images.

code
@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class Page {

@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Key key;

@Persistent
private final ListIMG images;
...
}
/code

My IMG class looks like this:

code
@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class IMG {
...

@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Key key;

...
}
/code

I don't fully understand how the one to many key using
KeyFactory.Builder works. In order to make an instance of Page
persistent using the datastore, do I need to loop through every IMG
instance like this:

code
for(IMG image : images) {
KeyFactory.Builder keyBuilder = new KeyFactory.Builder
(Page.class.getSimpleName(), page-id);
keyBuilder.addChild(IMG.class.getSimpleName(), image.getID());
Key key = keyBuilder.getKey();
image.setKey(key);
pm.makePersistent(image);
}
/code

or can I do this?

code
KeyFactory.Builder keyBuilder = new KeyFactory.Builder
(Page.class.getSimpleName(), page-id);
for(IMG image : images) {
keyBuilder.addChild(IMG.class.getSimpleName(), image.getID());
}

Key key = keyBuilder.getKey();
for(IMG image : images) {
image.setKey(key);
pm.makePersistent(image);
}
/code

or can I just do this?

code
Page page;
...
Key key = KeyFactory.createKey(Page.class.getSimpleName(), page.getID
());
pm.makePersistent(page);
/code

I never want to be able to access the IMG instances without the Page
instance, do I even need to give the IMG instances keys at all?

Thanks,

Finbarr
-- 
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: java.lang.NullPointerException cannot be cast to javax.servlet.ServletException

2010-01-07 Thread Ftaylor
This problem still exists.

On Dec 16 2009, 9:42 pm, polyurethan vette...@googlemail.com wrote:
 Hey there,

 I still get this ClassCastException. When will the JVM be fixed?
 It's Dec and the issue was raised in Jul. Is there any progress?

 Thanks,
 Alexander

 On Oct 22, 10:13 am, Marc Guillemot mguille...@yahoo.fr wrote:



  Don,

  I've tried to produce a unit test to open an issue for Jasper... and failed.

  I'm now quite sure that this is a bug in the JVM used for GAE.

  The JavaDoc of AccessController.doPrivileged (which is a native method)
  says that it propagates unchecked exceptions and throws a
  PrivilegedActionException only if a *checked* exception was thrown.
  Therefore Jasper code is correct not to await a RuntimeException as a
  PrivilegedActionException can't contain a NullPointerException and GAE's
  JVM is buggy here.

  Cheers,
  Marc.

  Don Schwarz a écrit : Ah, you're right actually.  I hadn't looked closely 
  enough at that bug.

   We'll have to get the Jasper guys to fix that and then upgrade.

   Thanks,
   Don

   On Mon, Oct 19, 2009 at 10:39 AM, Marc Guillemot mguille...@yahoo.fr
   mailto:mguille...@yahoo.fr wrote:

       This seems to be a really old issue that relates to something
       different... or do you mean that GAE uses a 5 years old version of
       Jasper?

       I've just look at the current sources of PageContextImpl
      
   http://svn.apache.org/repos/asf/tomcat/trunk/java/org/apache/jasper/r...
       and it seems to me that the problem still exists there.

       Cheers,
       Marc.

       Don Schwarz a écrit :
         Yes, this is:

        https://issues.apache.org/bugzilla/show_bug.cgi?id=31171

         We need to bundle a later version of Jasper with the App Engine
       SDK to
         fix this.

         On Mon, Oct 19, 2009 at 10:24 AM, Marc Guillemot
       mguille...@yahoo.fr mailto:mguille...@yahoo.fr
         mailto:mguille...@yahoo.fr mailto:mguille...@yahoo.fr wrote:

             Hi,

             any progress on this issue?

             Is it possible that it comes from a bug in Jasper, not able
       to recognize
             RuntimeException occurring in a PrivilegedExceptionAction?

             // org.apache.jasper.runtime.PageContextImpl

             public void handlePageException(final Throwable t) throws
       IOException,
                 ServletException {
               if (t == null)
                 throw new NullPointerException(null Throwable);

               if (SecurityUtil.isPackageProtectionEnabled()) {
                 try {
                   AccessController.doPrivileged(
                       new PrivilegedExceptionActionVoid() {
                     public Void run() throws Exception {
                       doHandlePageException(t);
                       return null;
                     }
                   });
                 } catch (PrivilegedActionException e) {
                   Exception ex = e.getException();
                   if (ex instanceof IOException) {
                     throw (IOException) ex;
                   } else {
                     throw (ServletException) ex; -- here?
                   }
                 }
               } else {
                 doHandlePageException(t);
               }

             }

             Cheers,
             Marc.

             Toby Reyelts a écrit :
               There's an outstanding issue in the version of Jasper App
       Engine is
               currently using that can cause exceptions escaping a JSP to 
   be
               incorrectly cast to ServletException. As a temporary
       workaround,
             you can
               wrap the body of your JSP in a try-catch block to get the
       actual
             exception.

               On Thu, Jul 30, 2009 at 1:13 PM, Blessed Geek
             blessedg...@gmail.com mailto:blessedg...@gmail.com
       mailto:blessedg...@gmail.com mailto:blessedg...@gmail.com
               mailto:blessedg...@gmail.com
       mailto:blessedg...@gmail.com mailto:blessedg...@gmail.com
       mailto:blessedg...@gmail.com wrote:

      http://cuckooberra.blessed-are-the-geek.com/TableMgr/TableMgr.jsp

                   Any idea what this error log means? LoggedIn.jsp is a
       rather
             simple
                   jsp, getting a temp authtoken and exchanging it for a
             permanent one.
                   My app runs fine on local eclipse plugin, but on
       deployment
             this error
                   resulted.

                   07-30 07:30AM 49.848
                   /TableMgr/LoggedIn.jsp
                   java.lang.ClassCastException:
       java.lang.NullPointerException
             cannot be
                   cast to javax.servlet.ServletException
                          at
             org.apache.jasper.runtime.PageContextImpl.handlePageException
                   (PageContextImpl.java:754)
-- 
You received this message because you are 

[appengine-java] Re: File path in App Engine

2010-01-07 Thread Ftaylor
Hello,

I have tried this but I always get a
java.security.AccessControlException: access denied
(java.io.FilePermission /names.txt read)

Anyone know how to resolve this?

Thanks,

Finbarr

On Jan 7, 3:32 am, m seleron seler...@gmail.com wrote:
 Hi,

 It might be solved by this though is not a direct answer.

 Follow this 
 thread:http://groups.google.co.jp/group/google-appengine-java/browse_thread/...

 Please Try.
 thanks.



  Hello,

  I have recently started using App Engine for a project I am working
  on, and I have a simple question.

  I have a file in the war/WEB-INF directory of my app filename.txt.
  When I try BufferedReader b = new BufferedReader(new FileReader(new
  File(filename.txt))); I get a FileNotFoundException.

  What path should I use when trying to access files in the war/WEB-INF
  directory? I have tried what seem to me to be the obvious ones and I
  have read the faq on this (which just tells you to put files in that
  directory).

  Thanks,

  Finbarr
-- 
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: File path in App Engine

2010-01-07 Thread Ftaylor
I got it to work by just using a File. Didn't change anything, it just
seemed to start working of its own accord.

Finbarr

On Jan 7, 10:46 am, Ftaylor finbarrtay...@googlemail.com wrote:
 Hello,

 I have tried this but I always get a
 java.security.AccessControlException: access denied
 (java.io.FilePermission /names.txt read)

 Anyone know how to resolve this?

 Thanks,

 Finbarr

 On Jan 7, 3:32 am, m seleron seler...@gmail.com wrote:



  Hi,

  It might be solved by this though is not a direct answer.

  Follow this 
  thread:http://groups.google.co.jp/group/google-appengine-java/browse_thread/...

  Please Try.
  thanks.

   Hello,

   I have recently started using App Engine for a project I am working
   on, and I have a simple question.

   I have a file in the war/WEB-INF directory of my app filename.txt.
   When I try BufferedReader b = new BufferedReader(new FileReader(new
   File(filename.txt))); I get a FileNotFoundException.

   What path should I use when trying to access files in the war/WEB-INF
   directory? I have tried what seem to me to be the obvious ones and I
   have read the faq on this (which just tells you to put files in that
   directory).

   Thanks,

   Finbarr
-- 
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.