?
Solved

Storing Text type into Datastore

Posted on 2013-11-17
3
Medium Priority
?
489 Views
Last Modified: 2013-11-23
I have a project where I am reading a RSS file and putting it into the GAE Datastore. I run into the problem with the "description" fields of the RSS file because they are more than 500 characters and will not load into Datastore. If I read correctly the workaround is to use the com.google.appengine.api.datastore.Text but I am struggling to make it work.

       DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); 
        URL u = new URL("http://feeds.feedburner.com/HeadlineNewsLiberiaAndItsNeighbors"); // your feed url 
        Document doc = builder.parse(u.openStream()); 
        NodeList nodes = doc.getElementsByTagName("item"); 
        for(int i=0;i<nodes.getLength();i++) { 
            Element element = (Element)nodes.item(i); 
            rssTitle = (String) getElementValue(element, "title");
            rssLink = (String) getElementValue(element, "link");
            rssContent = (String) getElementValue(element, "description");
            
            log.info("Title: " + getElementValue(element, "title"));
            log.info("Link: " + getElementValue(element, "link"));
            log.info("Description: " + getElementValue(element, "description"));
            
            // Add to Datastore
            log.info ("Starting Datastore");
            Key rssLinkKey = KeyFactory.createKey("RSS", "32390djks");
            Entity rssLink = new Entity("RSS", rssLinkKey);
            rssLink.setProperty("title", rssTitle);
            rssLink.setProperty("link", rssLink);
            rssLink.setProperty("description", new Text(rssContent));
            
            DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
            datastore.put(rssLink);
            log.info("Ending Datastore");

Open in new window

0
Comment
Question by:iamkhova
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 36

Expert Comment

by:mccarl
ID: 39655532
but I am struggling to make it work
Can you be a little more specific? Are you getting error messages, or it's just not working? If you are getting error messages/exceptions what are they, post the full message?
0
 

Accepted Solution

by:
iamkhova earned 0 total points
ID: 39656524
The error that I was getting was
String properties must be 500 characters or less. Instead, use com.google.appengine.api.datastore.Text, which can store strings of any length

I looked at my code again this morning and realized that I was not declaring the Text variable correctly.

I have made the modifications and now it correctly stores fields over 500 characters to GAE Datastore.

            
            Text text = new Text(getElementValue(element, "description"));
            rssLink.setProperty("description", text);

Open in new window


Thanks.
0
 

Author Closing Comment

by:iamkhova
ID: 39671072
The error became obvious once I took some time to step away and revisit the code.
0

Featured Post

Get MongoDB database support online, now!

At Percona’s web store you can order your MongoDB database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card. Handle your MongoDB database support now!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Verbose logging is used to diagnose garbage collector problems. By default, -verbose:gc output is written to either native_stderr.log or native_stdout.log.   It is also possible to redirect the logs to a user-specified file. This article will de…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Suggested Courses
Course of the Month13 days, 8 hours left to enroll

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question