Data Persistence

What  is Data Persistence

Data persistence is the storing of data for later use.It must be stored in a non-volatile storage.

 Role of Information System over Data Persistence

Data persistence is one of a fundamental  concept in information systems.
 Data are only the raw facts, the material for obtaining information. Information systems use data stored in computer databases to provide needed information. A database is an organized collection of interrelated data reflecting a major aspect of a firm's activities. 

1. Information systems capture data from the organization (internal data) and its environment (external data).
2. They store the database items over an extensive period of time.
3. When specific information is needed, the appropriate data items are manipulated as necessary, and the user receives the resulting information.
4. Depending on the type of information system, the information output may take the form a query response, decision outcome, expert-system advice, transaction document, or a report.

 Terms regarding Data Persistence

Data 

Data is a collection row facts which are not processed. And data is use ogbtain information by processing them.

Database

A database is a collection of information that is organized so that it can be easily accessed, managed and updated. Data is organized into rows, columns and tables, and it is indexed to make it easier to find relevant information.

Database Server

 A database server is a computer system that provides other computers with services related to accessing and retrieving data from a database. Access to the database server may occur via a "front end" running locally a user's machine (e.g., phpMyAdmin), or "back end" running on the database server itself, accessed by remote shell. After the information in the database is retrieved, it is outputted to the user requesting the data.

Database management system

Database Management System (also known as DBMS) is a software for storing and retrieving users' data by considering appropriate security measures. It allows users to create their own databases as per their requirement.


Files and Database

 

Different types of Databases

 

Relational Database

The relational database is the most common and widely used database out of all. A relational database stores different data in the form of a data table.

Operational Database

Operational database, which has garnered huge popularity from different organizations, generally includes customer database, inventory database, and personal database.

Data Warehouse

There are many organizations that need to keep all their important data for a long span of time. This is where the importance of the data warehouse comes into play.

Distributed Database

As its name suggests, the distributed databases are meant for those organizations that have different workplace venues and need to have different databases for each location.

End-user Database

To meet the needs of the end-users of an organization, the end-user database is used.


 Data warehouse and big data



SQL statements vs Prepared statements vs Callable statements

SQL statements

Statement interface is used to execute normal SQL queries. You can’t pass the parameters to SQL query at run time using this interface. This interface is preferred over other two interfaces if you are executing a particular SQL query only once. The performance of this interface is also very less compared to other two interfaces. In most of time, Statement interface is used for DDL statements like CREATE, ALTER, DROP etc. For example,

Prepared Statements


 Prepared Statement is used to execute dynamic or parameterized SQL queries. Prepared Statement extends Statement interface. You can pass the parameters to SQL query at run time using this interface. It is recommended to use Prepared Statement if you are executing a particular SQL query multiple times. It gives better performance than Statement interface. Because, Prepared Statement are pre-compiled and the query plan is created only once irrespective of how many times you are executing that query. This will save lots of time.

Callable Statements


Callable Statement is used to execute the stored procedures. Callable Statement extends Prepared Statement. Using Callable Statement, you can pass 3 types of parameters to stored procedures. They are : IN – used to pass the values to stored procedure, OUT – used to hold the result returned by the stored procedure and IN OUT – acts as both IN and OUT parameter. Before calling the stored procedure, you must register OUT parameters using registerOutParameter() method of Callable Statement. The performance of this interface is higher than the other two interfaces. Because, it calls the stored procedures which are already compiled and stored in the database server.

ORM frameworks

Object-relational mapping (ORM, O/RM, and O/R mapping tool) in computer science is a programming technique for converting data between incompatible type systems using object-oriented programming languages. This creates, in effect, a "virtual object database" that can be used from within the programming language.



Some other advantages of using ORM frameworks

1. Harmonization of data types between the OO language (in our case, PHP) and the SQL database. All relational databases use data types for each of the fields, for example: int, small int, blob, char etc. The thing is, that sometimes you have to convert the data types on the fly to properly add a record to the database. A good ORM will take care of these details for you.

2. Using an ORM will create a consistent code base for your application since much (if not all) of the code used to interact with the database will be PHP – no SQL code to mess things up. This makes it easier to write and debug your application, especially if you have more programmers on a job.

3. ORM frameworks will shield your application from SQL injection attacks since the framework will be filtering the data for you.

4. Database Abstraction; I am a little hesitant to make this point because in practice, over the last 10-15 years, I have only seen it once where we switched databases on an application. That said, ORM will make this much easier since it takes care of writing all the SQL code, data type conversions etc …


When to use an ORM framework?

ORM framework becomes more useful as the size and complexity of the project increases. If you just have a simple database with say 5 tables and 5-6 queries setting up an ORM framework may be overkill. 


Some ORM tools

Hibernate

Hibernate is an object-relational mapping (ORM) library for the Java language, providing a framework for mapping an object-oriented domain model to a traditional relational database. Hibernate solves object-relational impedance mismatch problems by replacing direct persistence-related database accesses with high-level object handling functions.

Hibernate's primary feature is mapping from Java classes to database tables (and from Java data types to SQL data types). Hibernate also provides data query and retrieval facilities. Hibernate generates the SQL calls and attempts to relieve the developer from manual result set handling and object conversion and keep the application portable to all supported SQL databases with little performance overhead.

Features of Hibernate:
  • Transparent persistence without byte code processing
  • Object-oriented query language
  • Object / Relational mappings
  • Automatic primary key generation
  • Object/Relational mapping definition
  • HDLCA (Hibernate Dual-Layer Cache Architecture)
  • High performance
  • J2EE integration
  • JMX support, Integration with J2EE architecture

 

 IBatis / MyBatis


iBATIS is a persistence framework which automates the mapping between SQL databases and objects in Java, .NET, and Ruby on Rails. In Java, the objects are POJOs (Plain Old Java Objects). The mappings are decoupled from the application logic by packaging the SQL statements in XML configuration files. The result is a significant reduction in the amount of code that a developer needs to access a relational database using lower level APIs like JDBC and ODBC. 
Other persistence frameworks such as Hibernate allow the creation of an object model (in Java, say) by the user, and create and maintain the relational database automatically. iBATIS takes the reverse approach: the developer starts with an SQL database and iBATIS automates the creation of the Java objects. Both approaches have advantages, and iBATIS is a good choice when the developer does not have full control over the SQL database schema. 

For example, an application may need to access an existing SQL database used by other software, or access a new database whose schema is not fully under the application developer's control, such as when a specialized database design team has created the schema and carefully optimized it for high performance.

Features of IBatis:
  • Support for Unit of work / object level transactions
  • In memory object filtering
  • Providing an ODMG compliant API and/or OCL and/or OPath
  • Supports multiservers (clustering) and simultaneous access by other applications without loss of transaction integrity
  • uery Caching - Built-in support
  • Supports disconnected operations
  • Support for Remoting. Distributed Objects.

TopLink

In computing, TopLink is an object-relational mapping (ORM) package for Java developers. It provides a framework for storing Java objects in a relational database or for converting Java objects to XML documents. 
TopLink Essentials is the reference implementation of the EJB 3.0 Java Persistence API (JPA) and the open-source community edition of Oracle's TopLink product. TopLink Essentials is a limited version of the proprietary product. For example, TopLink Essentials doesn't provide cache synchronization between clustered applications, some cache invalidation policy, and query Cache.

Features of Toplink:
  • Query framework that supports an object-oriented expression framework, Query by Example (QBE), EJB QL, SQL, and stored procedures
  • Object-level transaction framework
  • Caching to ensure object identity
  • Set of direct and relational mappings
  • EIS/JCA support for non-relational datasources
  • Visual mapping editor (Mapping Workbench)
  • Database and JEE Architecture independent

Comments

Popular posts from this blog

Distrbuted Systems

Client Side Development 2 - RiWAs