Solved

Storing Text type into Datastore

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

Portable, direct connect server access

The ATEN CV211 connects a laptop directly to any server allowing you instant access to perform data maintenance and local operations, for quick troubleshooting, updating, service and repair.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
check java version using powershell 13 298
Delete Android all or certain applications data programmatically 9 111
ejb wildfly example 2 73
Setup GlassFish 4 35
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

749 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