Java Serialization
The persistence of the data, which are created by business transactions and social events, supports the continuity of an enterprise. These data support not only the daily operations but also the smart decision, such as predicting business trends, deepening customer engagement or optimising operations. Thus data persistence is the critical part of an enterprise information system. In this assignment, you are to write a research report to critically review the data persistence technologies from Java platform. To complete this report, you need to have good understanding of the listed issues in this specification and are expected to do personal research.
The report is to be structured as an academic report and the sections must be titled and numbered. Your work must be appropriately referenced using the Harvard (author-date) referencing style. The length of the report should be about 2,500 words. An Exemplar for Writing a Simple Academic Technical Report is available on the unit web site; you should read it before writing the report.
In your report, you must address the following issues of Java data persistence technologies.
- What is data persistence and why is it important for enterprise information systems? Outline the 4 options to Java persistence technologies: Java Serialization, Java Database Connectivity (JDBC), Java Data Object (JDO) and Java Persistence APIs.
- What are you going to cover in the remainder of this report?
In this section, you will need to describe in detail about Java Serialization, its advantages and disadvantages/limitations. You will need to use Java code examples to show the important features of Java Serialization. After that you will need to introduce the next technology JDBC in order to solve the limitations of Java Serialization.
In this section, you will need to describe in detail about JDBC, its advantages and disadvantages/limitations. You will need to use Java code examples to show the important features of JDBC. After that you will need to introduce the next technologies Java Data Object (JDO) and Java Persistence APIs in order to solve the limitations of JDBC.
In this section, you will need to describe in detail about Object Databases (ODBs) and JDO and the software architecture of JDO. You will need to use Java code examples to show the important features of JDO when accessing an ODB.
In this section, you will need to describe in detail about Object-Relational Mapping (ORM) and JPA and the software architecture of JPA. You will need to use Java code examples to show the important features of JPA when accessing a relational database.
Note the assignment is not a programming assignment so the example code required for Section 2 to 5 is not checked for compiling and execution. The example code is just included in the assignment document to show your understanding of the features of the 4 Java persistence technologies. In addition, the example code is not included in the length count of this report.
Section 6: Conclusion
In this section, you will need to include a short summary of the 4 data persistence technologies and conclude the applicability of them.
Data persistence is a type of data which is used in data processing to denote information of any data and it is infrequently accessed. In computer system persistence data is defined as a data which outlives the method that produced it. There are many methods through which data persistence in java can create such as serialization, JCA, JDBC, and JPA. It is estimated that many data is persistence in any database and a relational database is the best example of data persistence. Java data persistence involves numbers, date, byte, bit, strings, arrays, image, and any Java object (Ang, and Wen, 2005). There are many applications of Java database that uses data persistence in their model framework. There are many reasons to use data persistence in any database such as it improves the productivity of database model, independent database, through this database parameter of java can be handled, and it also avoids unnecessary queries. Java is defined as an object-oriented language which is used to store data objects and it uses data persistence process to persisting data in any model (Barmpis, and Kolovos, 2012). This report is explaining about data persistence, use of data persistence in Java, and different type of data persistence such as Java serialization, JDBC, JDO, and JPA. The main objective of this report is to understand the role of data persistence in java and evaluating various types of data persistence.
Serialization in Java is defined as a process which is used to convert the state of any object into a byte stream. Deserialization is inversely proportional to the serialization process in which byte stream is converted into java object. Serialization is also used to persistence data in the java language (Birk, Chao, and Chung, 2006). The byte stream process produced an independent platform and serialization us one of the processes which provide object serialization in java programming. To produce java object through the serialization process we used the java.io.serializable method. There are some points to remember when serialization method is used in java such as-
- If any parent class has evaluated through serialization process then child class does not require implementing.
- In serialization process only non-static information or data are used.
- Related objects must be evaluated through the serialization process.
- Transient data and static data are not saved through the serialization method.
Figure: Java Serialization process
(Source: Geeks for Geeks, 2018)
Example: Java code for serialization and deserialization
// of a Java object
import java.io.*;
class Emp implements Serializable {
private static final long serialversionUID =
129348938L;
transient int a;
static int b;
String name;
int age;
// Default constructor
public Emp(String name, int age, int a, int b)
{
this.name = name;
this.age = age;
this.a = a;
this.b = b;
}
}
public class SerialExample {
public static void printdata(Emp object1)
{
JDBC
System.out.println("name = " + object1.name);
System.out.println("age = " + object1.age);
System.out.println("a = " + object1.a);
System.out.println("b = " + object1.b);
}
public static void main(String[] args)
{
Emp object = new Emp("ab", 20, 2, 1000);
String filename = "shubham.txt";
// Serialization
try {
// Saving of object in a file
FileOutputStream file = new FileOutputStream
(filename);
ObjectOutputStream out = new ObjectOutputStream
(file);
// Method for serialization of object
out.writeObject(object);
out.close();
file.close();
System.out.println("Object has been serializedn"
+ "Data before Deserialization.");
printdata(object);
// value of static variable changed
object.b = 2000;
}
catch (IOException ex) {
System.out.println("IOException is caught");
}
object = null;
// Deserialization
try {
// Reading the object from a file
FileInputStream file = new FileInputStream
(filename);
ObjectInputStream in = new ObjectInputStream
(file);
// Method for deserialization of object
object = (Emp)in.readObject();
in.close();
file.close();
System.out.println("Object has been deserializedn"
+ "Data after Deserialization.");
printdata(object);
// System.out.println("z = " + object1.z);
}
catch (IOException ex) {
System.out.println("IOException is caught");
}
catch (ClassNotFoundException ex) {
System.out.println("ClassNotFoundException" +
" is caught");
}
}
}
The output of java code-
The object has been serialized
Data before Deserialization
Name = ab
Age = 20
a = 2
b = 1000
The object has been Deserialization
Data after Deserialization
Name = ab
Age = 20
a = 0
b = 2000
- To provide persist the state of any Java object
- To travel any java object with a network system
- Very slow process
- Not more efficient
- Depend upon deployment size
JDBC is defined as an application programming interface for Java language and it describes a platform to access database (Dominguez, Moellenhoff, and Chan, 2007). It is also used for Java database model in java language and it is a part of java standard platform (Keyse, et al., 2018). The main role of the application program interface is to encode access data in SQL language. It is related to ODNC and it can be used to access the database model by using ODBC process (Lawrence, Brandsberg, and Lee, 2017). It provides a platform to write the java program for any database and it controls three activities such as
- Provide access to the database
- Send queries and modify database model
- Process-outcome acknowledged from the database
To connect the database with JDBC, it requires drivers system for each database model. There are four types of drivers are used in JDBC such as type 1, type 2, type 3, and type 4. Type 1 and type 2 are used for programmers; type 3 and type 4 are utilized by database vendors (Pater, and Moss, 2018).
Example: To connect JDBC with MySQL database
import java.sql.*;
class MysqlCon{
public static void main(String args[]){
try{
Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection(
"jdbc:mysql://localhost:3306/sonoo","root","root");
//here sonoo is database name, root is username and password
Java Data Object (JDO)
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery("select * from emp");
while(rs.next())
System.out.println(rs.getInt(1)+" "+rs.getString(2)+" "+rs.getString(3));
con.close();
}catch(Exception e){ System.out.println(e);}
}
}
- Provide XML structure of any database
- No content translation needed
- Can be utilized for synchronous and Asynchronous systems
- Also produce enterprise data
- Does not require any installation system
- Cannot modify
- Produce random sequence (McCain, and Therrien, 2011).
JDO is defined as Java data objects which are used to developed data persistence for any database model (Lafore, 2017). It is a platform to describe persistence data in any database by using plain old java object and it also creates object persistence data for java language. There are mainly three types of JDO classes such as persistence capable, persistence aware, and normal. Capable type of class is used to provide persisted data for any database, Aware is used to manipulate persistence data, and normal class does not need any JDO metadata.
An object database is defined as a database model in this method data or information is characterized in the form of an object which is used in the object-oriented program (Maeda, 2012). ODBs are very different from the relational database model because relational databases are table oriented but object databases are object-oriented. There are main two components of this database such as state and behaviour. State considers as a value and behaviour considered as operations, the operation defined into main two parts such as implementation and signature (Roos, 2018).
Figure: JDO Architecture
(Source: Oracle, 2010)
JDO helper is used to helping persistence data to provide an object for any database, and persistence manager factory is a factory for persistence database. The persistence manager is defined as primary JDO which is used for the application process, and persistence capable is a class of JDO which is used to provide persistence data in the java language (Schreter, SAP 2015). The transaction provides a platform to perform persistence data in any database, and extent is a class of JDO which exist in the database. A query is performed by the JDO vendor to determine persistence object, and fetch plan control eager fetching and other data behaviour.
Example: This is the example of JDO which indicate how utilize execute with array in JDO database.
/**
* Get all shipment for a specific order
*
* @param orderId Order Id
* @return -
*/
@Override
@Suppress Warnings("unchecked")
public List<IShipment> getShipmentsByOrderId(Long orderId, Persistence Manager pm) {
Query query = null;
try {
query = pm.newQuery("javax.jdo.query.SQL", "SELECT * FROM SHIPMENT WHERE ORDERID = ?");
query.setClass(JDOUtils.getImplClass(IShipment.class));
List list = (List) query.executeWithArray(orderId);
List<IShipment> shipments = new ArrayList<>(list.size());
for (Object shipment : list) {
Java Persistence APIs (JPA)
shipments.add((IShipment) shipment);
}
return shipments;
} catch (Exception e) {
xLogger.severe("Error while fetching shipments by order id: {0}", orderId, e);
} finally {
if (query != null) {
query.closeAll();
}
}
return null;
}
JPA is defined as a java persistence API which is a specification of Java in terms of accessing, managing data, and persisting data between Java objects and relational object (Maeda, 2012). JPA is considered as ORM in java programming, and it is a specification of Java language in terms of object and relational database. JPA provides plain old java object which produces persistence data without using any class to evaluate data interface. JPA also define how Java classes map with a relational object database. At that time the numbers of persistence, vendors have published for evaluation of JPA by users, and industries. It also provides a platform to manage a relational database in java language and it consists of four parts such as the persistence java API, java persistence criteria, query language, and object mapping metadata.
ORM is an object-relational mapping which is a programming process to convert data between incompatible type systems by the object-oriented program. In ORM, data management mission directly acts on an object-oriented program which is a non-scalar value. ORM provides a platform to utilize java object to represent relational database and it uses two methods such as object-oriented, and relational oriented program. There are many advantages of ORM such as
- Hide all information on SQL from the object-oriented program
- It is based on JDBC process
- It does not require evaluating database
- Automatic key generation
- Fast process for development of any application
Figure: Architecture of JPA
(Source: Tutorial point, 2018)
This figure shows the architecture of JPA and also indicates the core classes of JPA and interface of java persistence API. Entity manager factory is used to produce manager factory and also manage multiple entities of JPA factory. The entity manager is used to managing persistence database, and an entity is used to store the database. Entity transaction is providing a relationship with an entity manager and persistence is used to obtain the entity manager factory. The query is used to providing persistence vendor to implement relational object program.
Example: This is the example to create users entity in JPA
Package com.example.jpa.model;
Import javax.persistence.*;
Import javax.validation.constraints.NotNull;
Import javax.validation.constraints.Size;
Import javax.validation.constraints.Email;
Import java.io.Serializable;
@Entity
@Table (name = "users")
Public class User implements Serializable {
@Id
@Generated Value(strategy = GenerationType.IDENTITY)
Private Long id;
@Not Null
@Size (max = 65)
@Column (name = "first_name")
Private String firstName;
@Size (max = 65)
@Column (name = "last_name")
Summary and Conclusion
Private String lastName;
@NotNull
@Size(max = 100)
@Column(unique = true)
private String email;
@NotNull
@Size(max = 128)
private String password;
@OneToOne(fetch = FetchType.LAZY,
cascade = CascadeType.ALL,
mappedBy = "user")
private UserProfile userProfile;
// Hibernate requires a no-arg constructor
public User() {
}
public User(String firstName, String lastName, String email, String password) {
this.firstName = firstName;
this.lastName = lastName;
this.email = email;
this.password = password;
}
// Getters and Setters (Omitted for brevity)
}
Conclusion
The data persistence is a process to produce information of any database and it is generally used in java language to produce database using oriented objective and relational objective program. There are many types of data persistence method available in java programmings such as Java serialization, java database connectivity, java data object, and Java persistence JPA. Java serialization is used to convert data object into the data stream and deserialization is the opposite process of serialization that means this process converts data stream into java objects. The main role of JDBC in Java programming is that it encodes access data into SQL database. This report explained the role of data persistence in java programming and different types of data persistence used in java. This report also researched how data convert into java objects by using the object-oriented program. Java serialization should produce persistence state of any Java object and JDBC should provide XML structure of any Java object. Through data, persistence process programmer should produce objective oriented and relational objected database and it should improve the overall efficiency of the database. The main advantage of Java data object (JDO) is that it can produce data persistence of any database by using plain old java object process.
References
Ang, G.A.O. and Wen-xue, W.E.I., (2005) Application of Java data persistence with Hibernate and Struts framework [J]. Computer Applications, 12, 2.
Barmpis, K. and Kolovos, D.S., (2012) Comparative analysis of data persistence technologies for large-scale models. In Proceedings of the 2012 Extreme Modelling Workshop, 12(1), pp. 33-38
Birk, P., Chao, C.Y. and Chung, H., (2006) Method and apparatus for handling custom token propagation without Java serialization. U.S. Patent Application 10/882,118.
Dominguez Jr, F., Moellenhoff, D., and Chan, E., (2007) Java object cache server for databases, U.S. Patent, 7, 209,929.
Geeks for Geeks (2018) Serialization and Deserialization in Java with Example. [online] Available from: https://www.geeksforgeeks.org/serialization-in-java/ [Accessed 30/07/18].
Java T Point (2012) Java JDBC Tutorial. [online] Available from: https://www.javatpoint.com/java-jdbc [Accessed 30/07/18].
Keyse, J., Treml, E.A., Huelsken, T., Barber, P.H., DeBoer, T., Kochzius, M., Nuryanto, A., Gardner, J.P., Liu, L.L., Penny, S. and Riginos, C., (2018) Historical divergences associated with intermittent land bridges overshadow isolation by larval dispersal in co?distributed species of Tridacna giant clams. Journal of Biogeography, 45(4), pp.848-858.
Lafore, R., (2017) Data structures and algorithms in Java. Sams Publishing.
Lawrence, R., Brandsberg, E., and Lee, R., (2017) Next generation JDBC database drivers for performance, transparent caching, load balancing, and scale-out. In Proceedings of the Symposium on Applied Computing, 22, pp. 915-918.
Maeda, K., (2012) Performance evaluation of object serialization libraries in XML, JSON, and binary formats. In Digital Information and Communication Technology and it's Applications (DICTAP), 2012 Second International Conference on, 13(2), pp. 177-182.
McCain, B.S., and Therrien, A.L., (2011) Method and system for providing version control of parameters in a command-based API using java serialization. U.S. Patent, 7,921,433.
Oracle (2010) JDO Architecture. [online] Available from: https://docs.oracle.com/cd/E13189_01/kodo/docs303/jdo_overview_arch.html [Accessed 30/07/18].
Pater, P. and Moss, K., (2018) Java database programming with JDBC. US: Coriolis.
Roos, R.M., (2018) Java Data Objects. US: Addison-Wesley.
Schreter, I., SAP S. E., (2015) Object storage and synchronization hooks for occasionally-connected devices. U.S. Patent, 9,152,398.
Tutorial point (2018) JPA tutorial. [online] Available from: https://www.tutorialspoint.com/jpa/ [Accessed 30/07/18].
To export a reference to this article please select a referencing stye below:
My Assignment Help. (2021). A Critical Review Of Java Data Persistence Technologies Essay. (70 Characters). Retrieved from https://myassignmenthelp.com/free-samples/nit5130-database-analysis-and-design/data-persistence-and-its-importance.html.
"A Critical Review Of Java Data Persistence Technologies Essay. (70 Characters)." My Assignment Help, 2021, https://myassignmenthelp.com/free-samples/nit5130-database-analysis-and-design/data-persistence-and-its-importance.html.
My Assignment Help (2021) A Critical Review Of Java Data Persistence Technologies Essay. (70 Characters) [Online]. Available from: https://myassignmenthelp.com/free-samples/nit5130-database-analysis-and-design/data-persistence-and-its-importance.html
[Accessed 14 November 2024].
My Assignment Help. 'A Critical Review Of Java Data Persistence Technologies Essay. (70 Characters)' (My Assignment Help, 2021) <https://myassignmenthelp.com/free-samples/nit5130-database-analysis-and-design/data-persistence-and-its-importance.html> accessed 14 November 2024.
My Assignment Help. A Critical Review Of Java Data Persistence Technologies Essay. (70 Characters) [Internet]. My Assignment Help. 2021 [cited 14 November 2024]. Available from: https://myassignmenthelp.com/free-samples/nit5130-database-analysis-and-design/data-persistence-and-its-importance.html.