简体   繁体   中英

How to pre-populate the GAE local database

I'm creating a Google Application Engine using java. For this application I want to pre-populate some information on the database (ex: roles, permissions, etc..) How can I do that on my local datastore? And how do I do that when I upload the application? It seems there are some python tools to work with the server datastore, but not the local database.

Add a servlet to your application that persists the data you need to the datastore. Then, just visit the servlet's URL before you first run your application.

That's the simplest way. If you want to use this approach after you upload your application to GAE, make sure you add a security constraint so that only you can invoke the servlet:

    <security-constraint>
    <web-resource-collection>
        <url-pattern>/admin/*</url-pattern>
    </web-resource-collection>
    <auth-constraint>
        <role-name>admin</role-name>
    </auth-constraint>
</security-constraint>

https://developers.google.com/appengine/docs/java/config/webxml#Security_and_Authentication

You can use the Remote API to communicate with the real datastore.

You write code that runs locally that talks to the datastore. It's rather inefficient and you don't want to transfer a lot of data this way, but if it's only setting it up for a few entities it'll do the job.

https://developers.google.com/appengine/docs/java/tools/remoteapi

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM