By using couchbase sync_gateway for mobile sync(android,ios) you can still use the database from custom server side app?
My application needs to run on both mobile and web. I have angularjs for browsers and nodejs/express for server side.
If I will update the database form browser->node->couchbase ... mobile clients will get db update?! I think this is with no revisions so?!
if you are using the Node.js smart client for Couchbase Server, you can still co-exist with Couchbase Lite mobile clients using a workflow we call "bucket shadowing". For more information on this, check out: https://github.com/couchbase/sync_gateway/wiki/Bucket-Shadowing
Alternatively, you could use a Node.js library that interfaces directly with the Sync Gateway instead. For example, cradle: https://github.com/flatiron/cradle
But, for most use cases, I would recommend the bucket shadowing method instead.
I've attempted to approach it from a similar direction in PHP.
Sync_gateway is based on CouchDB API but has some changes and missing features in it's architecture when compared to a normal Couchbase or CouchDB instance.
Sync/Admin REST API:
Attachments aren't supported: Sync_gateway runs in memory passing JSON documents to clients and isn't designed to store larger binary files.
Views aren't supported (except for a few special sync_gateway views): A sync_gateway pipes documents through channels to the authenticated users instance of Couchbase Lite. View design documents are passed also then ran on the client to analyse the documents they have locally. Structurally views otherwise have no ability to change their contents based on which user is authenticated, as they are pre-computed indexes.
Get/store docs, adding/removing users, channels, roles, DB compact, registering new databases as sync_gateway and a few other handy features are exposed.
So depending on your needs it is possible to connect a web-app to sync_gateway and retrieve documents, however "bucket shadowing" with separate ACL system for the web-app is likely the solution for most applications.
Alternatively you could compile Couchbase Lite for the server node and have the web-app connect to it, however this Couchbase Lite instance will only represent a single user and contain only their channel's documents.
PHP Client for Sync Gateway: https://github.com/mryellow/PHP-on-CouchSync/
Update: Nowadays probably the best way to go is with PouchDB for the web side. You can monitor changes with AngularJS and make responsive interfaces that will automatically react to your data changes in the browser.
Related
I have installed cloud connector to a server that SQL is installed and i have a couple of databases.
I want to create a native Android app in SMP on SHCP in and use some of the data stored in my on premise SQL server.
Do i have to write an ODATA service provider? Does Cloud Connector provides data from DB as OData automatically?
I have exprerience from SMP 2.3 with MBOs but i dont understand how the new platform works. Is there a really helpful documentation/tutorial?
Do i have to write an ODATA service provider?
No, the only limitation is that you need to provide an HTTP-based API. Plain REST services or SOAP would work as well, for instance. You will need to provide OData in order to leverage the Offline enablement features, however. Christoph's suggestion of replicating and generating OData from HANA would be one valid approach. You could also use SAP Landscape Transform for the same purpose.
Does Cloud Connector provides data from DB as OData automatically?
No, SAP Cloud Connector works like a VPN tunnel between your cloud tenant and your on-premise systems. It does not have any API-related features.
Since OData is also backed by Microsoft, I would also assume that SQL Server supports ways of generating OData feeds from your database. This is not my home turf, but this post on generating WCF OData services might be relevant?
To get data from on premise DB to HCP you could use EIM SDI, see blogs from Ben Hofmans. You can then either consume the tables as virtual tables or replicate them to HANA. See EIM Admin guide for supported DBs. You can also find some open source adapters from github
Consume the virtual or replicated tables via XSodata service on top of the tables, or using cds- or calc views in between
Hope this helps
I am developing an android application. I want to update the local SQLite database with MySQL database on server. I am not able to figure out that what is the most appropriate and standardized way to do so?
Create a webservice (REST is probably best) and serialize your SQLite/MySQL data and PUT/POST/GET it to/from your web service. This will give you a nice layer of abstraction in case you decide to switch from MySQL to something else server side.
You may want to take a look at fyrecloud.com/amsler This is source code for a demonstration Android application that implements MySQL replication between a MySQL server and the SQLite db on an Android device.
Amsler rests on two pillars:
It communicates with the MySQL server using the MySQL Client/Server protocol in order to connect to the server for authentication and for receiving replication events as they occur.
It uses the Antlr lex and parse software in order to lex and parse incoming replication events and then to translate the MySQL commands into equivalent SQLite commands.
This is great for one-way replication. You can simulate two-way replication by modifying the MySQL server indirectly via RESTful type methods and then watching while MySQL sends a new replication event back.
Accessing a server via REST is easy enough. However, modifying an existing MySQL installation in order to support serialization presents too many headaches to enumerate here. Amsler takes advantage of pre-existing replication services. REST also depends upon some polling strategy in order to keep the local device reasonably up-to-date. Again, many problems with this approach. Amsler maintains a TCP/IP connection to the server which enables server-push notification of updates.
The most difficult part of Amsler is in figuring out the lexing/parsing. The Syntax between MySQL, SQLite, and the various versions of the same have many subtle differences. So many differences that it's impractical to provide a shrink-wrap translator and instead you must resort to modifying the grammar yourself.
Nevertheless, good, bad, or ugly, here it is. Take a look and maybe the glove fits.
This is probably going to be helpful: sync databases Mysql SQLite
The real answer is that there is no standard or built in magic way to just copy a MySQL database that lives on a server somewhere to a device. You will have to implement either a webservice or somehow convert the MySQL db on the server to the android sqlite implementation and download that file into your app's data directory (not a route I'd recommend taking).
Late to the party, but http://www.symmetricds.org/ is a good solution.
Java, runs on Android too.
LGPL.
Can handle 10,000's of clients.
There is no standard way. Depending on your needs you can e.g. use webservices in REST or SOAP protocols or more binary data exchange.
I have experience building android applications but now I would like to start building applications that interact with some sort of web database to push and pull data.
What type of database should i set up on a remote server for my application to interact with? From what i understand I need a database on the remote server and some service that my android app can communicate with?
What can i read that will clear up how this works and how i can get started?
The easiest (and often most flexible) combination in my opinion is PHP and MySQL. PHP as the scripting language which is called (via http) from the app, and handles all the database access. MySQL as the database. PostgreSQL is also an option for the database, of course. And if you have access to .NET, JSP or something like that, that's also an option. But a web server with Apache, PHP and MySQL is free, powerful and easy to maintain, and most/many web hosts have them.
The way it works (which is the same no matter what kind of webbased services/servers you chose), is this:
- The database is installed on the server
- You have a web area (on the web server) which has access to the database (this is how it will be with a typical web hotel solution)
- You place your scripts (f.ex. PHP) in the web area
- The web scripts access the databse, with functions for fetching and/or storing information
- Your app uses httpclient or something similar to send http GET or POST requests to the PHP scripts, either sending information or asking for information, or both
It's also quite possible to write database access code directly in your app (this is very easy in Java and C#, compared to languages like C og C++). However, most hosts don't allow remote access to their database servers, so you'd most likely have to set up a database server yourself. Also, accessing the database server directly is a security risk, and I wouldn't recommend it.
As to what you can read, there's lots and lots of tutorials, howtos and concrete examples on the net. Search for "php access mysql databse", f.ex., for ideas on how to write php scripts that handles the database transaction(s). If you have a more detailed decription, I might be able to point you to something more specific.
I strongly suggest adding web service layer between your application and database, using i.e. JSON or XML. Exposing DB directly ma be security risk and is rarely the way to go.
The current solution that I have to adopt uses JDBC and stores the user/password of the database inside the android app. That's as far as I'm concerned not a good solution. I would like to implement a mapping layer on the webserver in the middle.
Is there any best practice or recommended strategy for this? Should I use SOAP or JSON or something completely different (because they're well implemented and/or easy to use in Java)?
Are there any mapping tools for postgresql <-> SOAP/JSON/whatever in PHP or will I need to write these scripts by myself?
Any pointers will be greatly appreciated.
Quick version:
Use a web service midlayer running on a public host you control (possibly but not necessarily the database host). Expose public web service methods to do the limited work you want to permit and nothing else.
Related questions:
Driver JDBC PostgreSQL with Android
How to connect to a PostgreSQL server via JDBC in Android?
Implementation options
Personally I'd use a Java application server like Apache Tomcat or JBoss AS 7 and I'd write my web service methods using JAX-RS to produce a nice REST-style API for my app to use. That's what I'm familiar with and it works well, but you have lots of options including implementations of:
REST-like APIs (Java's JAX-RS impls Jersey and RESTEasy, various other langs tools) that use HTTP requests and produce JSON or XML replies.
SOAP with WSDL, the classic "web service" layer. In Java done with JAX-WS among other options. Most languages have tools for SOAP+WSDL but it's kind of crappy to work with especially on intermittently connected devices like mobiles.
XML-RPC if you like pain
There are some JAX-RS quickstarts on the JBoss AS 7 quickstarts list; just search for "JAX-RS". The "kitchen sink" quickstart is useful, though perhaps not ideal if you're not familiar with the basics of JBoss AS 7 and Jave EE 6. Fort the JAX-RS specifics you're better off with a Jersey or RESTEasy tutorial like this or this.
Important considerations
Use HTTPs if possible, and if access isn't to be public use a suitable HTTP authentication scheme like HTTP Basic auth over HTTPs. Any decent web services implementation will offer authentication options or support those of the platform on which it runs. Avoid the temptation to implement your own authentication and user management at the web services layer, you will screw it up; use the auth at the HTTP layer that's already written and tested. This may require the use of something like Apache's mod_auth_pgsql, JBoss AS 7's JDBC security realms, etc. The only case I'd consider not doing proper per-user HTTP auth is where I don't need to separate my users for security reasons, I only care that it's my app accessing the server, ie if my security requirements are quite weak. In this case I'd use a fixed username/password for the whole app and possibly an X.509 client certificate if Android supports them.
Remember that no matter how you secure things, all credentials are either known to the user or can be extracted trivially from a .apk so you still have to assume anybody could access your web service methods, not just your app. Write them accordingly.
Do not just send SQL from your app over a web service call to the server and return the results as JSON. This is horrifyingly insecure, as well as ugly and clunky. Write a web service method for each individual task you want the app to be able to perform and keep the SQL in the server. Remember to use parameterised queries and be careful of other SQL injection risks. These web service methods may use one or more queries to produce a single reply - for example, you might collect a "Customer" record and all associated "Address" and "Contact" records then return the result in a nice JSON object the Android device can consume, saving numerous slow and unreliable network round trips.
No matter what you use, make sure to do your web service calls in a background worker thread and not to block the user interface. Be prepared for timeouts and errors, and for the need for retries. Test your app by simulating intermittent connection loss, high latency, and high rates of packet loss and make sure it remains usable.
Is there a best practise:
It depends on the person. All have their strength and weakness.
I prefer, and I think many but not all will agree on JSON cause it is really easy to use in Android. It's also lightweight and very easy to use in php. Php has methods to convert an array/object to json and back.
It is indeed not recommended to save your postgres data on an android device.
My strategy is usually:
PHP server side with a POSTGRESQL database, using PDO to communicate between my models and the database.
If you are not familiar with PDO(php data objects), I recommend you make yourself familiar with it.
php.net PDO
Android as client, using JSON as method of transfering data from and to.
There are many examples that can help you.
Android has standard libraries to handle json parsing.
See this answer for an example:
example
I have the following scenario.I need to have an embedded database(nosql) on Android and i have a master database on the server which should ideally be nosql database.There needs to be syncing between the two.All queries from the mobile will go to the iternal database.We have differnt options
1)Use couchDB on the mobile side and also use couchdb on the server side
2)Use couchDb on the mobile side and use Mongodb on the server side
3)Use sqlLite on the mobile side and use MongoDb/CouchDb on the server side.
Please give your views in evaluating the best option and the benifits/problems of using these approaches.
Note:Currently MongoDb does not support for an embedded database on Android.Also Mongo does not provide the REST APIS and we need to use third paty like MongoLabs and SleepyMongoose
You don't mention the methodology you would use to sync changes between the databases especially in the cases in which changes conflict (an update on one side, a delete of the matching record on the other side for example), but it seems like your life will be simpler using the same database on each side.