Developing enterprise applications involves a lot of efforts to store the business objects in the database. Usually,70% of the efforts to develop enterprise applications are writing the code to maintain database connections and save the entities to database. Most of the enterprise applications are developed using Object Oriented techniques. The business logic inside the application flows in the form of objects instead of textual messages as it used to be in the days of structural programming where we had set of variable to perform operations or indicate the state of an entity. Today,Object Oriented technologies are used to solve the complex problems and maintain the business flow. Only saving the objects to the database is a stage where the objects are transformed back to text and stored to the database. To understand this problem,consider the following code snippets.
This is typically how the connection is obtained in Java language.
Class.forName(driverClass);
java.sql.Connection connection = java.sql.DriverManager.getConnection(databaseUrl,databaseUser,databasePassword);
Suppose we have an object of User class,and we need to store this object to the database. Consider the following function:
private void saveUser(User user) throws SQLException
{
PreparedStatement pstmt = connection.prepareStatement("insert into users values(?,?,?)");
pstmt.setInt(1,user.getId());
pstmt.setString(2,user.getName());
pstmt.setString(3,user.getEmail());
pstmt.setString(4,user.getAddress());
pstmt.execute();
}
The problem with this code is that this is scattered everywhere in the application which affects the maintainability of the application. There are many problems with this approach like:
- Code is scattered at different un-manageable places.
- If your design changes after developing the application,it will be too expensive to identify the places where changes are required.
- Difficult to identify and fix the bugs
- Managing the database connections is a difficult task since the SQL code is scattered,so are the database connections.
- Managing the transactions is a complex task.
Due to these problems,bug fixing is an accepted stage of an application development process which makes the application too expensive even after the successful completion of development cycle.
It is highly needed to have a mechanism to isolate the database persistent code and write it so efficiently that when there is a change in the database design,it can be easily implemented with the belief that there is no un-identified place which may show a bug later.
Benefits of Relational Database Systems:
searching and sorting is fast
Work with large amounts of data
Work with groups of data
Joining, aggregating
Sharing across multiple users and multiple locations
Concurrency (Transactions)
Support for multiple applications
Consistent Integrity
Constraints at different levels
Transaction isolation
Issues with Relational Database systems:
Database Modeling does not support polymorphism
Business logic in the application server could be duplicated in the database as stored procedures
Does not make use of real world objects
Extra code required to map the Java objects to database objects.