How to switch (migrate) to Google Cloud SQL from DataStore? - java

I have a Google App Engine Java application, which uses Appengine datastore for its persistence (Using JPA and Datanucleus).
Now I want to migrate my backend(database) to Google Cloud SQL.
I have already created cloud sql account and instance. I also granted permission for my GAE app to use this instance.
Now, how I can i rewrite my app or what are the changes I should make to my application, in order to migrate to cloud sql.
Any good tutorial is there for it?
Any help is greatly welcomed.

I would suggest following Using Google Cloud SQL with App Engine Java SDK. Once you've configured an example database, create new tables for the entities in your datastore.
For the actual data migration you have a few possible routes:
Download your datastore locally, manipulate the entries into SQL INSERT statements, and upload them to Cloud SQL
Write a script that reads through the datastore and writes rows to your SQL datastore (most likely using a task queue and datastore cursor)
Ignore the old data in your app and start from scratch

Related

Why should I use App Engine for such a simple task?

I want to connect to the Google Cloud SQL from my android app.
Is there a way to do this without the App Engine and Endpoints?
If this does not exist, please tell me the most painless way to solve this problem. I'm just in the future does not intend to use the App Engine, and therefore do not understand why waste time on it.
I have actually used Google Cloud SQL with App Engine + Endpoints (Java) so I can weigh in here a little.
You can create a helper class in App Engine and easily connect to Google Cloud SQL. Then, you can create endpoint methods that take in some parameters and inside the method access Cloud SQL and perform some operations securely.
This is highly advisable against interacting with your Cloud SQL database in the Android client app because that is a big security risk. If someone decompiles your app somehow, they now have full access to your database credentials.
If you have not a very large app you can use the above approach. But honestly, I would just the time to learn GAE Datastore and use that instead or Firebase. SQL can run into issues if your app gets big but maybe you aren't trying to build the next huge app so it will suffice. It all depends on you.
Hope that helps.

google app engine : switch sql cloud database instance , keeping the source code same java eclipse

The application is hosted in google app engine, we are using google cloud sql as database.
we are in testing phase of our application,
so we have to database
live database
test database.
so can anyone please suggest a way to switch from live database to test database without changing the source code,
for now we have created 2 different source code with different urls to connect to different database instances and have created 2 instance of application but we want to keep the source code same.
there are many ways to do this. you could pass a url parameter to indicate which db to use. you could also have an admin page where you select which db all will use.

can I call methods from java application that use google cloud datastore in GAE without rewrite the code of connection to Datastore

I created java application (myLocalAPP) to connect and access google cloud datastore.
So, I use Google cloud Datastore API.
However, I'm now finding that I have to use myLocalAPP in a GAE app. (I export myLocalAPP to jar and add it to GAE /lib).
The problem is that GAE has different API to connect to Google datastore and the connection,insert and retrieve methods that I've created them in myLocalAPP aren't working when I call them from GAE application.
I got exception such:
java.lang.Error: compilation problems:
The method beginTransaction(TransactionOptions) in the type DatastoreService is not applicable for the arguments (DatastoreV1.BeginTransactionRequest)
The method lookup(DatastoreV1.LookupRequest) is undefined for the type DatastoreService
Entity.Builder cannot be resolved to a type
Type mismatch: cannot convert from DatastoreV1.Entity to Entity
So, I go back to myLocalAPP and try to change the connection method. I change the datastore object from
Datastore datastore = DatastoreFactory.get().create(DatastoreHelper.getOptionsfromEnv()
.dataset(datasetId).build());
to
Datastore datastore = (Datastore )DatastoreServiceFactory.getDatastoreService();
but casting does not work. I need to use DatastoreService object and I have to rewrite the other methods. I would like to know is there any way other than rewriting the code?? and if I rewrite the code using GAE datastore API, is myLocalAPP will work again locally?? (not on GAE).
Thanks,
The client library for communicating with Google Cloud Datastore is not currently compatible with the API used by App Engine Datastore.
There's an open issue on the Google Cloud Datastore issue tracker to enhance the App Engine Java client library to work on top of Cloud Datastore (this would also enable the use of higher-level libraries like Objectify). You can subscribe to that issue to receive updates.

Google Cloud DataStore Clarification

I know appengine datastore and what is cloud datastore, using cloud datastore is always an confusion for me, following are my questions:
does cloud datastore requires Compute Engine ?
(in google docs i saw like enable compute engine)
how to access cloud datastore from appengine application (this is very needed)
how to enable multiple application to access this common datastore ?
Note: I know how to activate it, but I didn't get clear answers for my questions above.
Your questions:
1) No, cloud datastore can also be user by other platforms
2) App engine has native support to use the (cloud) datastore. The cloud datastore is based on the App Engine datastore to make it available for others.
3) You can share the cloud datastore, but see this issue
Atlast, i can able to access from cloud datastore from appengine application, following are my answer,
Ans For Ques 1:
Cloud Datstore doesn't require compute engine instance.
Ans for Ques 2:
To access cloud datastore, you need either service account credentials or u must have access token for authenticated user with Scopes set to Datastore, and user email.
Use Google api Client library,or simply use ProtoBuf library provided in documentation.
Ans for Ques 3:
simply use create credentials from application u want to access and use it in other applications
https://developers.google.com/datastore/docs/getstarted/overview
Thanks!

google app engine Bigtable

I have doubt using jpa. I defined the datanucleus connection for MYSQL as follows.
datanucleus.ConnectionDriverName=com.mysql.jdbc.Driver
datanucleus.ConnectionURL=jdbc:mysql://localhost/myDB
datanucleus.ConnectionUserName=...
datanucleus.ConnectionPassword=..
My constraint is if I want to connect to google app engine datastore(ie Big table) via jpa
how to give the above connection for bigtable.
You don't need to configure any settings in order to persist to Bigtable using JPA - just run it inside the App Engine environment, and it ought to work fine.
Perhaps jiql would be useful.

Categories