So, in order to practice it I've chosen to develop a simple pastebin like application using Gaelyk.
I started it by modeling the main entity: Snippet, which is a very simple POGO with only 3 properties:
class Snippet implements Serializable { String name String text String language }
The groovylet below ilustrates how we can easily instantiate a new entity from the posted request parameters and then persist it into the data store.
def snippet = new Snippet(params); // coerce a POJO into an entity def snippetEntity = snippet as Entity snippetEntity.save() forward "/snippet.gptl"
So far so good. After some tests I got the following error:
Error: GroovyServlet Error: script: '/WEB-INF/groovy/snippet/create.groovy': Script processing failed.name: String properties must be 500 characters or less. Instead, use com.google.appengine.api.datastore.Text, which can store strings of any length.com.google.appengine.api.datastore.DataTypeUtils.checkSupportedSingleValue(DataTypeUtils.java:192)
The message is very self explanatory. I changed the Snippet and the groovylet respectively to:
import com.google.appengine.api.datastore.Text class Snippet implements Serializable { String name Text text String language } // create.groovy def snippet = new Snippet(); snippet.name = params.name; snippet.language = params.language; snippet.text = params.text as Text; def snippetEntity = snippet as Entity snippetEntity.save()
Note that I changed property type from String to Text and had to set each property separately in the groovylet because there is no autocasting support for Text types.
You can check the last deployed version in AppEngine here: Snippetr
And the source code here: http://code.google.com/p/snippetr/
Nenhum comentário:
Postar um comentário