Solved

Storing Text type into Datastore

Posted on 2013-11-17
3
485 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
  • 2
3 Comments
 
LVL 35

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
netstat -ano | find "8000" and taskkill /f /pid 2984 3 80
ejb entity bean example 2 7
jmss example java 2 23
restrict decimal places for double datatype 10 19
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Configure Web Service (server application) I. Configure security for Web Services methods First, we need to protect Session bean which implements the service: 1. Open EJB deployment descriptor (ejb-jar.xml) in the EJB project that contains you…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

791 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