On Thu, Nov 18, 2010 at 1:05 PM, biokys <mulle...@gmail.com> wrote: > Hi, I am trying to find out, how to store data in a local DB and > remotely over HTTP in one transaction. Does exist any native mechanism > in Android phone for transactional behavior? > > Thx Honza
Honza, Short answer is: I don't think so. In order to achieve this, you would need to look at Distributed Transaction Coordinators, if you require full transactionality. Java EE has JTA (Java Transaction API) but it's not present on mobile platforms. To achieve this it relies on few very crucial things: - JDBC 2.0 drivers for each data source you need in your distributed transaction that actually implements XADataSource and XADataConnection - JEE Application Server Android API mentions XADataSource and XAConnection, just have a look at javax.sql.DataSource documentation, but there is nothing else. I am pretty sure that SQLite does not support such mechanisms, but I could be wrong. You can try doing it the garage way: db.beginTransaction(); try { //send data to SQLite //send data to external service db.setTransactionSuccessful(); } catch (SQLException) { //error in DB: contact the server to revert the commit and hope it will do it } catch (IOException) { //error with the external server, and you have no guarantee, whether it has been written or not } finally { db.endTransaction(); } As you can see, you can have guarantees only about the internal SQLite database. As soon as you involve network in your transaction, things get orders of magnitude more complicated. I am not sure, how strict are your requirements on transactionality. You could also implement some timer on your server that is transactionally persisted to a DBMS on that server, so that crash + restart or network outage would not cause it disappear. They you would revert any uncommitted transactions after some timeout. That gets you somwhere, but I am pretty sure it will break in some scenarios. -- Daniel Drozdzewski -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en