Enterprise Application Architecture
Data Persistence:
Representing data permanently in back-end systems is called as “Data Persistence”.
To achieve data persistence in enterprise applications we will use the following technologies or tools…
1. Serialization and Deserialization
2. JDBC
3. ORM Tools like Hibernate.
1) Data persistence through Serialization and Deserialization:
The process of separating data from an object is called as Serialization.
The process of reconstructing an object on the basis of the data is called as Deserialization.
In the Serialization, after separating data we will store that data in a flat file.
In Deserialization, we will get Serialized data from the flat file and we will perform Deserialization.
In Java applications, if we want to serialize any object, first, we have to check whether that object is eligible for Serialization or not, if the Object is not eligible for Serialization then make that object eligible for Serialization and Deserialization.
To make eligible any object for Serialization, simply, we must implement java.io.Serializable marker interface in the respective class
Note:
Marker interface is Java interface, it does not have methods, but, by implementing it, it will provide some abilities to the object at runtime.
EX:
In Java, by default, all objects are not eligible for Serialization and Deserialization, only the objects which are implementing java.io.Serializable interface are eligible for Serialization and Deserialization.
class Employee implements Serializable{
— -
}
In Java , to perform Serialization and Deserialization , JAVA has provided the following two Byte oriented Streams.
1. ObjectOutputStream for Serialization
2. ObjectInputStream for Deserialization
Employee emp1 = new Employee();
Steps to perform Serialization:
1. Prepare Serializable class by implementing java.io.Serializable marker interfae:
class Employee implements Serializable{
— — — -
}
Employee emp1=new Employee();
2. Create FileOutputStream object:
FileOutputStream fos = new FileOutputStream(“emp.txt”);
3. Create ObjectOutputStream for Serialization.
ObjectOutputStream oos = new ObjectOutputStream(fos);
4. Write Serializable Object in ObjectOutputStream:
oos.writeObject(emp1);
Steps to perform Deserialization:
1. Create FileInputStream from Source File:
FileInputStream fis = new FileInputStream(“emp.txt”);
2. Create ObjectInputStream for Deserialization:
ObjectInputStream ois = new ObjectinputStream(fis);
3.Read Deserialized Object from ObjectInputStream:
Get Sanjay Agarwal’s stories in your inbox
Join Medium for free to get updates from this writer.
Employee emp2 = (Employee)ois.readObject();
→In Serialization and Deserialization Data Persistency mechanism, we will store data in file system ,where file system is providing permanent storage for our data, so that, Serialization and Deserialization is a Data Persistency Mechanism.
-> In Serialization and Deserialization data persistency mechanism, we will use a flat file to store data, it is platform dependent, it is not suitable for the platform independent front end technologies like JAVA, .NET,….
-> In Serialization and Deserialization Data Persistency mechanism, we will use two byte oriented streams like ObjectOutputStream and ObjectInputStream to perform Serialization and Deserialization, so that, this data persistency mechanism is suitable for only byte oriented data.
-> In this data persistency mechanism, we are using file system to store data , it able to store less data , it able to provide less security and it able to increase data redundancy, it is not suggestible in applications.
->This persistency mechanism is suitable for Standalone applications, not suitable for enterprise applications.
-> If we use this data persistency mechanism in Enterprise applications then we have to provide lot of java code.
-> In Serialization and Deserialization data persistency mechanism we are able to perform only insertion and retrieval operations, we are unable to perform update, delete, operations.
- > In this data persistency mechanism, query language support is not existed so that database operations are very much difficult.
Drawbacks of Serialization and Deserialization:
1. It is not suitable for enterprise applications, it may be suitable for simple standalone Applications.
2. We must use Byte Oriented Streams in Serialization and Deserialization, it is supporting for only Byte Oriented Data, not supporting for Other Data.
3. With Serialization and Deserialization we are able to perform only insert and read operations, not Possible to perform Updations and Deletions, ….
4. Query Language Support is not existed , so Database operations are complex.
2) Data Persistency through JDBC:
JDBC is a step by step process or a technology or an API or the collection of predefined classes and interfaces or an abstraction, it will provide very good environment to interact with database from java applications in order to perform database operations from java applications.
To prepare JDBC applications we have to use the following steps.
1. Load and Register Driver:
Class.forName(“oracle.jdbc.OracleDriver”);
2. Enstablish Connection between Java application and Database
Connection con = DriverManager.getConnection(“ jdbc:oracle:thin:@localhost:1521:xe”, “system”, “oracle”);
3. Create either Statement or PreparedStatement or CallableStatement as per the requirement.
Statement st = con.createStatement();
4. Write and execute SQL Queries.
ResultSet rs = st.executeQuery(“select * from emp1”);
5. Close the resources.
rs.close();
st.close();
con.close();
→ In Jdbc Applications, when we establish Connection between java application and database , automatically, the generated Connection will be available in “Auto-Commit” mode, in this mode, if we submit an sql query to the Connection then Connection will carry that sql query to Database Engine and Connection will make Database Engine to execute SQL Query and to results in Database Permanently, this Nature of Connection is able to achieve Data Persistency in JDBC Applications.
Drawback of JDBC:
→ In JDBC applications, we have provided SQL Queries explicitly to perform database Operations, So that, Developers must require SQL Awareness.
→ In JDBC applications, developers must have explicitly concentration on Driver Management, Connection Management and Statement Management.
→ In JDBC Applications, the steps like Load and Register Driver, Establish Connection , Create Statement and Close resources … are common in every JDBC Application, we must write Repeatedly, it will increase Code duplication .
→ In Jdbc applications, we have to hardcode the JDBC Parameters like Driver class name, Driver URL, Database User Name and Database password,…
→ In JDBC, Transactions support is not good.
→ In JDBC almost all the exceptions are checked exceptions, we must handle them by Providing JAVA code.
→ In JDBC applications, if we retrieve data from database then that will be stored in ResultSet object at java applications, it is not implementing java.io.Serializable interface and which is not eligible to carry in network.
3) Data Persistency through ORM:
In general, in Enterprise Applications to represent data we will use more than one data model like Object Oriented Data Model, Relational data Model…






