Re: [appengine-java] Re: Weird results for JOD query with List item filter (List.contains(....))
any update ? I'm desperately waiting for its solution.. -- 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.
Re: [appengine-java] Re: any plans for deferred.defer in Java?
Hi Vince, I haven't had a chance to integrate your code yet, so feel free to continue making modifications. In particular, I think it would be useful to provide the same set of options the Python deferred API accepts, which include 'eta' and 'countdown' parameters, as well as specifying the queue and URL. -Nick On Wed, Nov 25, 2009 at 7:03 PM, Vince Bonfanti vbonfa...@gmail.com wrote: Hi Jeff, Thanks for the suggestions and the code. David Chandler sent me a patch to support user-specified queue names (almost exactly the same as your changes), and I've committed that patch to SVN. Regarding your other changes: - I've probably make the url-pattern init parameter optional and have it default to /_ah/queue_name rather than throw an exception from the init method if it's missing. - While we're at it, the default queue name could be optionally specified by an init parameter also. - I'm not sure a stacktrace from the doPost method is really going to give you much more information, but would be open to that change. It looks like the Deferred class is going to be added to the official GAE/J SDK, though I'm not sure when. Rather than make any more changes to the code right now, I'd rather wait to see what shows up the SDK and then work through normal Google channels to get any further modifications made. In the mean time, I'm glad it's working for you. Vince On Tue, Nov 24, 2009 at 8:09 PM, Jeff Schnitzer j...@infohazard.orgwrote: Attached is a modified version of that class that lets you define any path you want for the servlet and lets you specify which queue to use like this: Deferred.defer(task, queueName); (I needed this for my own purposes) Do with it as you wish :-) The only other major change I would make is to stop masking all the exceptions during the task processing. Or at least, if you're going to log the exception and stop propagation, log the whole thing so we get a stacktrace in the logs. Jeff On Fri, Nov 20, 2009 at 1:03 PM, David Chandler turboman...@gmail.com wrote: Vince, this is great! I hadn't been watching my own issue, so didn't see this until now. Thanks so much! Only enhancement I would suggest is to enable multiple deferred queues. For example. I would like to defer tasks in an email throttle queue separately from a general background queue. Perhaps the Deferrable interface could have a getQueueName() method, or Deferred.defer could have an additional signature defer(Deferrable task, String queueName). Thanks again, /dmc -- -- 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%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/google-appengine-java?hl=en. -- Nick Johnson, Developer Programs Engineer, App Engine Google Ireland Ltd. :: Registered in Dublin, Ireland, Registration Number: 368047 -- 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] Using Long as a natural key
I store a record that has a natural Long primary key (a facebook user id). I currently create a Key with that id and insert this record. I just noticed this comment on the Entity(Key) constructor: Creating an entity for the purpose of insertion (as opposed to update) with a key that has its id field set is strongly discouraged unless the key was returned by a KeyRange. Is this strongly discouraged because the author of that comment is afraid I will accidentally insert an entity with a null key and the resulting generated key might conflict with existing data? Or is this strongly discouraged because there is an actual performance problem doing this on the server? I expect a staggering large write volume, all of which will overwrite the old records without any need to load them first. I need to do this the most efficient way possible. Is my current solution the best performing, or is it better to stringify the user id and use that as a keyname? Thanks in advance, Jeff -- 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] storing SetKey in datastore
Hello, In my application I have a class which has a field of type Setcom.google.appengine.api.datastore.Key. I want to store objects of that class in datastore, but I can't make it work. At first my class looked like this: @PersistenceCapable(identityType=IdentityType.APPLICATION) public class Kuku { @PrimaryKey @Persistent(valueStrategy=IdGeneratorStrategy.IDENTITY) protected Key id; public Key getId() { return id; } @Persistent protected SetKey mySet = new HashSetKey(); public int getMySetSize() { return mySet.size(); } public void addToSet(Key what) { mySet.add(what); } } In some JSP page I tried to create a new object of that class, then store it in a datastore, then fetch it back from datastore and add some elements to its mySet, the fetch it again and see how many elements there are in mySet: %@ page contentType=text/html;charset=UTF-8 language=java % %@ page import=psobolewski.Kuku % %@ page import=psobolewski.PMF % %@ page import=javax.jdo.PersistenceManager % %@ page import=com.google.appengine.api.datastore.Key % html body % Kuku kuku; javax.jdo.PersistenceManager pm; Key kukuId; String result; kuku = new Kuku(); pm = PMF.get().getPersistenceManager(); pm.makePersistent(kuku); kukuId = kuku.getId(); pm.close(); % % pm = PMF.get().getPersistenceManager(); kuku = pm.getObjectById(Kuku.class, kukuId); kuku.addToSet(kukuId.getChild(kukuId.getKind(), 0)); kuku.addToSet(kukuId.getChild(kukuId.getKind(), 1)); kuku.addToSet(kukuId.getChild(kukuId.getKind(), 2)); pm.close(); pm = PMF.get().getPersistenceManager(); kuku = pm.getObjectById(Kuku.class, kukuId); result = size: + kuku.getMySetSize(); pm.close(); % %= result % /body /html However, when I try to run it, I get java.lang.NullPointerException in this place: public void addToSet(Key what) { mySet.add(what); } Then I decided to change my class this way: @Persistent(defaultFetchGroup = true) protected SetKey mySet = new HashSetKey(); However, this didn't help - I still get this NullPointerException. So I decided to change my class this way: @Persistent(defaultFetchGroup = true, serialized = true) protected SetKey mySet = new HashSetKey(); Now I don't get NullPointerException any more, but the reported size of mySet is zero, as if I haven't added any elements to it. What do I do wrong? How can I keep such field in a 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: Null pointer exception when accessing keys of unowned 1..n relation
Hi Ikai, The issue was with the order in which I was invoking persistence. Thanks. Its resolved now. -Ic On Nov 21, 2:53 am, Ikai L (Google) ika...@google.com wrote: Can you post code? My assumption is that you are using JSP dispatch. Child objects are lazy loaded, so if this is what you are doing: 1. Fetch persistence manager instance 2. Make query on parent object 3. Store query results in a request attribute 4. Close persistence manager 5. dispatch.forward() to JSP 6. Iterate over entities and retrieve related entities This won't work. You'll have to retrieve the related entities before the persistence manager has closed. On Fri, Nov 20, 2009 at 5:58 AM, Icarus pr.a...@gmail.com wrote: Hello, I am trying to get a m:n unowned relation working on google java app engine datastore. In the test cases, I am able to commit to datastore through persistence manager and get back the data. But when I do the same on a jsp page , the listKey of the related entity is always null ( when I retrieve the other related entity from datastore.) Is anyone facing similar issue ? I used the google datastore docs for reference for this. Thanks, Ic -- 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%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/google-appengine-java?hl=. -- Ikai Lan Developer Programs Engineer, Google 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] Parent Child GrandChild relationship, cannot get Grandchild object
Hi, I have a Parent Class with a List of Child Objects. This is an owned one to many relation and I am able to get the child objects from the Parent Object after I get the Parent Object from the DataStore. Now, the Child Objects in turn have a List of Objects ( so they are the grandchildren)... now when I create a GrandChild object and try to call makePersistent() on it, they key is always null. Is there something very basic that I am missing ? Thanks, -Ic -- 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] Change of Attribute in an object wasn't saved in datastore sometimes.
I am developing my App with GWT + GAE. today i met a strange thing. I am using Eclipse Galileo with GWT 1.7 and Google plugin 1.26. i have a class A, which is defined like the following one; public Class A { protected Long id; protected ArrayListString usernames; public ArrayListString getUsernames() return usernames; } public void setUsernames(ArrayListString usernames) { this.usernames = usernames; } public void addUsername(String username) { if(!this.usernames.contains(username)) { this.usernames.add(username); } } } on the Server side i have method called share. public void share(A a, String username) { PersistenceManager pm = PMF.get().getPersistenceManager(); try { A a1 = pm.getObjectById(A.class, a.getId()); a1.addUsername(username); System.out.println(tag.getUsernames()); } catch (Exception e) { LOG.logp(Level.FINE, WorkitemServiceImpl, save, e.toString()); } finally { pm.close(); } } public void share(A a, String username) { PersistenceManager pm = PMF.get().getPersistenceManager(); try { A a1 = pm.getObjectById(A.class, a.getId()); a1.getUsernames().add(username); System.out.println(tag.getUsernames()); } catch (Exception e) { LOG.logp(Level.FINE, WorkitemServiceImpl, save, e.toString()); } finally { pm.close(); } } when i call the method share on the client side, like share(a, test); the first one prints [], the second one prints [test]. can anybody explain why this happens? thanks in advance! ray -- 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: Can't send mail with attachment using JavaMail API
Thanks Ikai. It did NOT work before because I set the dataHandler before I set the FileName. Just have to set the FileName and then set the DataHandler. attachment.setFileName(ticker.png); attachment.setDataHandler(new DataHandler(mimePartDataSource)); Is this behaviour intentional? Many thanks Don On Nov 24, 10:15 am, Ikai L (Google) ika...@google.com wrote: Don, First, a word of caution: you'll probably want to contact the creators of the site you are trying to fetch the image from if you haven't done so already. Their terms of service prohibit the use of automatic downloading of images:http://support.stockcharts.com/forums/31090/entries/20485 To fetch an image from a URL and send it via the Mail Service, this what you need to do: 1. Fetch your URL 2. Find the content type 3. Read the stream into a byte[] 4. Create a message and a data handler 5. Pass the byte[] into the data source, then into the data handler Example code:http://pastie.org/712159 import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.ServletException; import javax.mail.*; import javax.mail.util.ByteArrayDataSource; import javax.mail.internet.MimeMultipart; import javax.mail.internet.MimeBodyPart; import javax.mail.internet.MimeMessage; import javax.mail.internet.InternetAddress; import javax.activation.DataHandler; import java.io.IOException; import java.io.InputStream; import java.io.ByteArrayOutputStream; import java.net.URL; import java.util.Properties; public class GetStockServlet extends HttpServlet { private static final String SENDER = your.sen...@domain.com; private static final String RECIPIENT = your.recipi...@domain.com; protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { URL url = new URL(http://yoururl.com/image.png;); InputStream in = url.openStream(); byte[] rawData; int len; byte[] buffer = new byte[8192]; ByteArrayOutputStream output = new ByteArrayOutputStream(); try { while ((len = in.read(buffer, 0, buffer.length)) != -1) output.write(buffer, 0, len); rawData = output.toByteArray(); } finally { output.close(); } response.setContentType(image/png); response.getOutputStream().write(rawData); response.getOutputStream().flush(); String htmlBody = Here is the quote you wanted; Properties props = new Properties(); Session session = Session.getDefaultInstance(props, null); Message message = new MimeMessage(session); Multipart mp = new MimeMultipart(); MimeBodyPart htmlPart = new MimeBodyPart(); try { message.setFrom(new InternetAddress(SENDER, Stock Service)); message.addRecipient(Message.RecipientType.TO, new InternetAddress(RECIPIENT)); message.setSubject(Stock Quote: + symbol); htmlPart.setContent(htmlBody, text/html); mp.addBodyPart(htmlPart); ByteArrayDataSource dataSource = new ByteArrayDataSource(rawData, image/png); MimeBodyPart attachment = new MimeBodyPart(); attachment.setFileName(symbol + .png); attachment.setDataHandler(new DataHandler(dataSource)); mp.addBodyPart(attachment); message.setContent(mp); Transport.send(message); } catch (MessagingException e) { throw new IOException(e); } } } On Sun, Nov 22, 2009 at 9:04 AM, Don lydonchan...@gmail.com wrote: Hi Ikai, I tried your example code, but I cannot attach an image on the email that I send. There is no conversion error either. Here is snippets of the code, please help.. //Retrieving image: URL url = new URL(http://stockcharts.com/c-sc/sc?s=; + ticker + p=DAILYb=5g=0i=0r=3528); //Sending mail SendMail sendmail = new SendMail(customerEmail, url.openStream()); // send mail function public SendMail(String recipient, InputStream imagestream) { msg.setFrom( new InternetAddress(lydonchan...@gmail.com, dons service)); msg.addRecipient(Message.RecipientType.TO, new InternetAddress (recipient)); msg.setSubject(dons service daily charts); Multipart multipart = new MimeMultipart(); MimeBodyPart htmlPart = new MimeBodyPart(); htmlPart.setContent( url2: , text/html); multipart.addBodyPart(htmlPart); // append png image? ByteArrayDataSource mimePartDataSource = new ByteArrayDataSource (imagestream, image/png); MimeBodyPart attachment = new MimeBodyPart();
[appengine-java] HttpSession and setMaxInactiveInterval
Hi, I am writing a custom authentication process and like the app to leave the user signed in after the browser closes (i.e., when the user revisits the app she is directly signed in). I thought the following piece of code would accomplish this: HttpSession session = req.getSession(true); session.setMaxInactiveInterval(60*60*24*14); // 2 weeks session.setAttribute(Username, username); But when I restart the browser and visit the app a user has to sign in again. What is missing to keep user signed in after browser restarts? Thanks. Regards, Peter -- 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: HttpSession and setMaxInactiveInterval
The session cookie is lost when you close your browser. So no way to get back to the original session once you reconnect. Nothing in common with an eventual authentication cookie. On 26 nov, 22:32, Peter Hulsen hul...@gmail.com wrote: Hi, I am writing a custom authentication process and like the app to leave the user signed in after the browser closes (i.e., when the user revisits the app she is directly signed in). I thought the following piece of code would accomplish this: HttpSession session = req.getSession(true); session.setMaxInactiveInterval(60*60*24*14); // 2 weeks session.setAttribute(Username, username); But when I restart the browser and visit the app a user has to sign in again. What is missing to keep user signed in after browser restarts? Thanks. Regards, Peter -- 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] Filtering by Date using the Datastore Low Level API
Good Evening Everyone, I am working on creating an event calendar type of page and am having trouble using the low level API and applying a filter to select events that occur in the future. The data that I am selecting has a property of display_until that holds a date in -mm-dd hh:mm:ss format. To select future events I started with the following code: SimpleDateFormat formatter; formatter = new SimpleDateFormat(-mm-dd hh:mm:ss); Date date = new Date(); String query_date = formatter.format(date); query.addSort(display_until, Query.SortDirection.ASCENDING); query.addFilter(display_until, com.google.appengine.api.datastore.Query.FilterOperator.GREATER_THAN, query_date); When I ran this code it did select future events, but not all of them. Currently I have some 2009 and some 2010 events. It selected the 2010 events, but not the December 2009 events. Anyone have any suggestions for how I can select all of the future events? Thanks, Doug -- 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.