Search code examples
javagoogle-app-enginegwtgoogle-cloud-datastorerequestfactory

AppEngine Datastore: storing list of strings with more than 500 characters


My GWT Entity contains an attribute myDescriptions which is a list of 10 Strings with more that can have more than 500 characters.

When I try to give value to any element of the list, say element 3, two things can happen: - myDescriptions.get(3) = stringWithLessThan500Chars; -> Is done correctly - myDescriptions.get(3) = stringWithMoreThan500Chars; -> It is stored as element 9 (last) as datastore.Text.

Any solutions for this? I tried creating myDescriptions as a list of datastore.Text, but I cannot access them from EntityProxy.


Solution

  • GAE has two string properties for Datastore types:

    1. Short text string indexed property which stores up to 500 chars. In Java it's converted to String
    2. Long text string unindexed property which stores up to 1MB of chars. In Java it's converted to Text.

    In your case the solution is to iterate through list and replace Text with it's string value:

    if(myDescriptions.get(x) typeof Text) {
        String text = ((Text) myDescriptions.get(x)).getValue();
        myDescriptions.set(x, text);
    }