Do you have a
facade[
^] in your aplication?
if so it's simple, you would only have to extend the write/read and delete mechanisms.
How to implement a facade into an existing application:
- set up a class "FacadeService". that one is triggered BEFORE your GUI starts.
- FacadeService
implements Serializable
. the class needs a methode "getInstance()" which gives back a instance of FacadeService.
This is your general entrance point. FacadeService pulls up the rest of the facade (in this example a facade to store Customers in):
import java.io.Serializable;
public class FacadeService implements Serializable {
private static final long serialVersionUID = 1L;
private static final FacadeService oFacadeService = new FacadeService();
private final CustomerFacade oCustomerFacade = new CustomerFacade();
public FacadeService(){
}
public static FacadeService getInstance(){
return oFacadeService;
}
public CustomerFacade getCustomerFacade(){
return oCustomerFacade;
}
}
import java.io.Serializable;
public class CustomerFacade implements Serializable {
private static final long serialVersionUID = 1L;
private final CustomerFacade oCustomerFacade = new CustomerFacade();
public CustomerFacade(){
this.ignition();
}
private void ignition() {
}
public CustomerFacade getInstance(){
return oCustomerFacade;
}
}
- now your complete GUI should read from this facade:
private CustomerFacade getCustomerFacade(){
return FacadeService.getInstance().getCustomerFacade();
}
- Make sure you can store everything at runtime. Create objects that dublicate each object in the database.
- make sure you are reading the DB at startup to fill your facade.
- make sure you are writing to the DB each time a value changes. You can set up for that general methods that help you. Even a class "DatabaseConnector" would be helpful to gather all the read/write/modify methods. make sure the DB actions are made asynchronous (
Threading[
^]) so they do not block your application.
- make sure your GUI is not reading from the DB aside of the facade. Your application should be able to run without the DB/just from the Facade data (the facade is empty if the database could not be read).
NOTE:
I know that this is not the intended use of Serializable and the design is not general applicable. But it's a simple, easy to implement approach to add a facade to an existing application.