EndpointsModel vs ndb.Model - google-app-engine

So I stumbled on EndpointsModel as a means of creating models. When I look online, there is basically no tutorial about it. For people who have used it, what's the advantage? Instead of ndb.Model I mean.
Edit:
Also, I tried to mimic the code at What is the best way to auth, identify and store delicate information about users? just to check it out, but my eclipse red-lines it:
from endpoints_proto_datastore.ndb import EndpointsModel

The Endpoints Proto Datastore API is not an official part of the App Engine SDK, but a library I have been working on.
It is documented and I'm happy to come on here and answer your questions. As it turns out, EndpointsModel is a subclass of ndb.Model, so you are getting the best of both worlds:
>>> from endpoints_proto_datastore.ndb import EndpointsModel
>>> from google.appengine.ext import ndb
>>> EndpointsModel.__bases__ == (ndb.Model,)
True
As mentioned on the docs landing page, the advantage is that the library:
...allows existing model classes to be used with Google Cloud
Endpoints. By extending the functionality provided by ndb.Model class
and the endpoints library, this library allows you to directly
interact with model entities in your API methods rather than ProtoRPC
requests.
We have also given a talk on using the library. In it, we explicitly mention that you'll need to add the endpoints_proto_datastore library to your application.
$ cd path/to/your/application/code
$ wget https://endpoints-proto-datastore.googlecode.com/files/endpoints_proto_datastore.zip
$ unqip -q endpoints_proto_datastore.zip

Related

Unable to generate cloud endpoint class

Dear fellow programmers,
I am very new to programming and i am following the tutorial on using app engine backend tutorial. However i face some problem along the way.
I have Setup App Engine Backend Application Project, created a CheckIn entity class.
After which, i follow the instruction to create a new class with the name CheckInEndPoint.java
I copy the code from the snippet over to the Class.
When i try to Generate Cloud Endpoint Class, i faced an error message.
Error Generating API
This is not a JDO/JPA entity class.
Kindly seek your advice on how to troubleshoot it.
https://cloud.google.com/developers/articles/how-to-build-mobile-app-with-app-engine-backend-tutorial#ecdp
The instructions as provided by Google are confusing. What the instructions intended to say is after creating CheckIn.java, right-click on the CheckIn.java file and select Google->Generate Cloud Endpoint Class. This will then automatically create the CheckInEndpoint.java file.
Read through the entire "Entity Design Class Pattern" paragraph as given in the link you provided. You'll recognise that their instructions are ambiguous and is actually meant to be carried out from point 6.
Try adding this annotation to your CheckIn class:
import javax.jdo.annotations.PersistenceCapable;
#PersistenceCapable
public class CheckIn ...
This way it will find it as a JDO entity class and it will generate your CheckInEndPoint class.
I had the same error, I have first renamed the class CheckInEndPoint I've created manually to avoid any kind of conflicts. After that I have right clicked on
CheckIn class -> Google ->Generate Cloud Endpoint Class.
If you get some dependencies errors, please try check whether all the classes like ApiKeysAndIds.java, UserAccount.java are in the package.

Is there any detailed documentation on the Endpoint class generator?

The only docs I can find say say "click 'generate endpoint class' and then something magic happens".
I'm looking for a bit more detail.
Specifically what I am trying to achieve is to generate Endpoint classes that use Objectify in place of JDO for persistence.
For clarity, I am not interested in generating client classes since I will be accessing the endpoints from Erlang.
All the features that you describe are things you need to do in your own server-side logic. Those are not generated for you. After that, you need to annotate your APIs (entry points).
Then you can use the endpoint tools to generate the endpoint classes on the client side.
https://developers.google.com/appengine/docs/java/endpoints/annotations

Accessing sqlite datastore from command line

I've been accessing the traditional datastore from the command line as follows:
from google.appengine.api import apiproxy_stub_map
from google.appengine.api.datastore_file_stub import DatastoreFileStub
os.environ['APPLICATION_ID']="myapp"
apiproxy_stub_map.apiproxy=apiproxy_stub_map.APIProxyStubMap()
stubname, stub = 'datastore_v3', DatastoreFileStub(os.environ["APPLICATION_ID"], Datastore, "/")
apiproxy_stub_map.apiproxy.RegisterStub(stubname, stub)
I've upgraded to the sqlite datastore and need to update the stub (and maybe stubname), presumably with DatastoreSqliteStub, but can't seem to initialise it; any suggestions ?
Thanks!
Here is a little module I often reuse in my AppEngine projects: ae.py
It lets me just do:
import ae
ae.connect_local_datastore()
at the top of scripts. or with remote_api setup you can also do:
ae.connect_remote_datastore()
A simple console.py script that makes use of this can be found here
Hope they help.

GWT: Where (how) to define POJOs to make em available for client and server? (and to use datastore on serverside)

I try to get an application running which should interact with a server via RPC (JDO in Google DataStore). So I defined a persistent POJO on the server-side to get it put in the datastore via the PersistenceManager (as shown in the gwt rpc tuts). Everything works fine. But I am not able to receive the callback POJO on the client side because the POJO is only defined on server-side. How can I realize it, that the client knows that kind of object??
(sry for my bad english)
Lars
Put your POJOs in a separate package/directory (e.g. com.example.common) and then add source declaration to your GWT module descriptor (xyz.gwt.xml):
<source path="common"/> //relative to your xyz.gwt.xml location
GWT compiler will then also compile POJOs and they will be seen by your other GWT code.
Edited:
#Lars - now I understand your problem. As I see it you have several options:
If possible use Objectify instead of JDO. Objectify uses pure POJOs and they play nicely with GWT. I use this in my projects. One nice thing that Objectify gives you is #PostLoad & # PrePersist on methods to run some code before/after POJOs are loaded/saved to datastore. I use this to handle serialization of GeoPoint for instance.
Use JDO and make copies of your domain classes. This is a pain but it would work. Use 'transient' java keyword in your server JDO classes to exclude fields you do not want to RPC.
Edit #2: There is a third option that you might prefer:
Create "fake" JDO annotation classes using super-sourcing. This is a common technique to replace classes with a GWT version. Described here: http://fredsa.allen-sauer.com/2009/04/1st-look-at-app-engine-using-jdo.html
You can use DTO(stackoverflow, moar) for transferring data to client.
Basic sample here (method getTenLatestEntries() in your case).
Or you can use some third-party libraries like objectify and stop worry about making DTO`s.

How to run the CherryPy web server in the Google App Engine

The CherryPy web server can supposedly be deployed in the Google App Engine.
Who has done it, and what was the experience like?
What special effort was required (configuration, etc.)?
Would you recommend it to others?
The article is a good example but its slightly out of date now as the patch is no longer required, the latest version of Cherrypy should run without it, I've gotten the sample below running in the development environment.
I've included cherrypy inside a zip file as the google app engine has a limit of one thousand files per application, it also makes it easier to deploy.
I'm also using the cherrypy dispatch handler to route the request.
import sys
sys.path.insert(0, 'cherrypy.zip')
import cherrypy
import wsgiref.handlers
class Root:
exposed = True
def GET(self):
return "give a basic description of the service"
d = cherrypy.dispatch.MethodDispatcher()
conf = {'/':
{
'request.dispatch': d
}
}
app = cherrypy.tree.mount(Root(), "/",conf)
wsgiref.handlers.CGIHandler().run(app)
So far I've not come across any particular issues but I have read some people have had issues with sessions.
See boodebr.org article (missing, but here on the Wayback machine) It works for me.
If you are looking for an example, look for the condition that accepts ServerMode.GAE in ServerInterface.auto in this example.
There is a good article on how to do this over here now here. I haven't actually tried this yet, I stuck with django on App Engine, but it seems to be a solid example.

Resources