Persistence (computer science)
Persistence (from the Latin persistere “to stay through, for a while”) is the term used in computer science to describe the ability to keep data (or objects ) or logical connections available for a long time (especially after a program has been terminated). A non-volatile storage medium is required for this; The file system or a database as well as a bi-directional and transaction-oriented data transmission secured by protocols can also be regarded as non-volatile media. Since a program can be unexpectedly interrupted at any time, persistent data storage means in particular that every change in the status of the data must be saved immediately on the non-volatile medium.
“Persistent” is used as a well-defined technical term for “not uncontrollably changeable”. This means, for example, that the data remains available (saved) even after the program has ended (possibly also in the event of an unexpected shutdown, e.g. in the event of a power failure) and can be reconstructed and displayed again when the program is called up again. With regard to the logical connections, persistence means that the real connection is restored if necessary / after a failure, if possible without the communication partner noticing the interim separation.
Data that do not have this property, for example, only exist in the main memory of the computer and change or lose their content as soon as the program that created them ends. Such “volatile” data are called transient , they are buffered .
A persistent connection is to be understood as an ongoing, persistent connection that survives brief interruptions without changing its information content.
Persistence in object-oriented programs
Various design patterns such as “ Data Access Object ” support a data-persistent software design, and the observer pattern also supports simple implementation of persistent data storage, which must then also adhere to the ACID principle and work on a transaction-based basis.
There are frameworks that automatically ensure that objects registered with you are stored persistently on a permanent storage medium, so-called persistence providers . There are open source persistence providers (e.g. Hibernate ), and database manufacturers typically also offer implementations for persistence providers. They offer a uniform interface for various persistent storage media (file system, RDBMS, directory service, B2B service and so on).
These frameworks usually require that the objects are either serializable or object-relationally mappable . With serialization, the object can be written as a serial data stream in a persistent storage medium (e.g. using "Java I / O Streams "). The other possibility is the object-relational mapping ( object-relational mapping ).
Responsibility for an existing runtime environment
Within an application server, a distinction is made between container-based persistence (the runtime environment handles saving and restoring) and component-based persistence (the component must save and restore itself). In the Java example, the Enterprise JavaBeans (EJBs) would be responsible for the container-based persistence . Starting with Java Platform, Enterprise Edition 5, each persistent class must be marked with the annotation .