Meaningless Drivel is fun!*
The moose likes JDBC and the fly likes Offline/online working of application Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Offline/online working of application" Watch "Offline/online working of application" New topic
Author

Offline/online working of application

sharad goswami
Ranch Hand

Joined: Jan 18, 2001
Posts: 51
Hi! I have developed an application for online purpose.My problem is my client want the same to work in offline also.I am using ms sql server as back end tool.Also the user is restricted to view only some contents .
a)My problem is how do i make it work offline.
b)how to i export database created offline to my server
c)how to restrict imported database only to his/her concerns .
Please help me asap.


Stop The World I Want To Get Off.
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

Sounds like a job for a Design Pattern. You could manage the interface between the program and JDBC bits with an extra level of abstraction - ie it could be viewed as a Decorator for the JDBC bits.
The 'online' bits stay the same, but create a 'Persistence Manager' that wraps around it. When called, the PM checks for a valid network connection. If this succeeeds, it provides a direct interface to the old JDBC code. Otherwise, it invisibly caches the data in the local version for later on.
This solves points 1 and 3. To solve part two, you can have the PM also detect the fact that a connection didn't exist but now daoes and can replicate data back. Or this could be a separate process.
There will be a problem with managing unique keys, but a solution I like is to have each client process have the 'high bits' predetermined, and be allowed to set the 'low bits' itself. eg the local client might have a 'local key base' of 0110-0000 (this is just an 8-bit example) and is then free to allocate all keys from 0110-0000 to 0110-1111.
Now I've thrown this out (from the top of my head, so be gentle ) Arguments?
Dave
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

oh, and I forgot to say:
Stop The World I Want To Get Off

"Charlie Brown" quote?
sharad goswami
Ranch Hand

Joined: Jan 18, 2001
Posts: 51
could u suggest code for that.How do u do it?please
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

You already have some JDBC code.
To manage the 'safe unique key' code, each client needs its own 'high bit' value that it can safely use to hand out primary keys while it isn't connected to the server. ie: A class that knows about the high end,and knows how to generate the low end bits. All this class does is hand out unique keys when they are requested.
Finding the high could also be done as a query the first time a client connects to the server, but it would be easier to crate it via a configuration setting.
To manage the Decorator (ie the tricky bit), you have a class that you delegate to and it handles database operations rather than you making database operations yourself. Exactly what the Decorator looks like depends on what your original database operations look like...
Typically it should look exactly the same from the 'outside'. The difference would be that you have rewritten the methods so that instead of calling your JDBC code directly, it tests to see if it is on or offline, then optionally calls the local or remote database...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Offline/online working of application