Solved

Storing Text type into Datastore

Posted on 2013-11-17
3
487 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

What Is Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

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…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
The viewer will learn how to implement Singleton Design Pattern in Java.

724 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