Object-Relational Mapping: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
Line 17: Line 17:
==Simple Example with ORM==
==Simple Example with ORM==
==Simple Explanation==
==Simple Explanation==
===Swing application===
{{Main|Swing (Java)}}
[[Swing (Java)|Swing]] is a graphical user interface [[library (computing)|library]] for the Java SE platform. It is possible to specify a different look and feel through the [[pluggable look and feel]] system of Swing. Clones of [[Microsoft Windows|Windows]], [[GTK+]] and [[Motif (software)|Motif]] are supplied by Sun. [[Apple Inc.|Apple]] also provides an [[Aqua (user interface)|Aqua]] look and feel for [[Mac OS X]]. Where prior implementations of these looks and feels may have been considered lacking, Swing in Java SE 6 addresses this problem by using more native [[GUI widget]] drawing routines of the underlying platforms.
This example Swing application creates a single window with "Hello, world!" inside:
<source lang="java">
// Hello.java (Java SE 5)
import javax.swing.*;
public class Hello extends JFrame {
    public Hello() {
        super("hello");
        super.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        super.add(new JLabel("Hello, world!"));
        super.pack();
        super.setVisible(true);
    }
    public static void main(final String[] args) {
        new Hello();
    }
}
</source>
The first '''<code>import</code>''' includes all of the public classes and interfaces from the '''{{Javadoc:SE|package=javax.swing|javax/swing}}''' package.
The <code>'''Hello'''</code> class <code>'''extends'''</code> the '''{{Javadoc:SE|javax/swing|JFrame}}''' class; the <code>JFrame</code> class implements a [[window (computing)|window]] with a [[title bar]] and a close [[GUI widget|control]].
The <code>'''Hello()'''</code> [[constructor (object-oriented programming)|constructor]] initializes the frame by first calling the superclass constructor, passing the parameter <code>"hello"</code>, which is used as the window's title. It then calls the '''{{Javadoc:SE|name=setDefaultCloseOperation(int)|javax/swing|JFrame|setDefaultCloseOperation(int)}}''' method inherited from <code>JFrame</code> to set the default operation when the close control on the title bar is selected to '''{{Javadoc:SE|javax/swing|WindowConstants|EXIT_ON_CLOSE}}''' — this causes the <code>JFrame</code> to be disposed of when the frame is closed (as opposed to merely hidden), which allows the Java virtual machine to exit and the program to terminate. Next, a '''{{Javadoc:SE|javax/swing|JLabel}}''' is created for the string '''"Hello, world!"''' and the '''{{Javadoc:SE|name=add(Component)|java/awt|Container|add(java.awt.Component)}}''' method inherited from the {{Javadoc:SE|java/awt|Container}} superclass is called to add the label to the frame. The '''{{Javadoc:SE|name=pack()|java/awt|Window|pack()}}''' method inherited from the {{Javadoc:SE|java/awt|Window}} superclass is called to size the window and lay out its contents.
The <code>'''main()'''</code> method is called by the Java virtual machine when the program starts. It [[Object (computer science)|instantiates]] a new '''<code>Hello</code>''' frame and causes it to be displayed by calling the '''{{Javadoc:SE|name=setVisible(boolean)|java/awt|Component|setVisible(boolean)}}''' method inherited from the {{Javadoc:SE|java/awt|Component}} superclass with the boolean parameter <code>'''true'''</code>. Once the frame is displayed, exiting the <code>main</code> method does not cause the program to terminate because the AWT [[event dispatching thread]] remains active until all of the Swing top-level windows have been disposed.


==ORM Language==
==ORM Language==

Revision as of 15:36, 13 September 2014

ORM Definition

Object-relational mapping(ORM,O/RM,and O/R mapping) is a programming technique for converting data between incompatible type systems in object-oriented programming languages.

Object-relational mapping (ORM, O/RM, and O/R mapping) in computer science is a programming technique for converting data between incompatible type systems in object-oriented programming languages. This creates, in effect, a "virtual object database" that can be used from within the programming language. There are both free and commercial packages available that perform object-relational mapping, although some programmers opt to create their own ORM tools.

Overview

In object-oriented programming, data management tasks act on object-oriented (OO) objects that are almost always non-scalar values. For example, consider an address book entry that represents a single person along with zero or more phone numbers and zero or more addresses. This could be modeled in an object-oriented implementation by a "Person object" with attributes/fields to hold each data item that the entry comprises: the person's name, a list of phone numbers, and a list of addresses. The list of phone numbers would itself contain "PhoneNumber objects" and so on. The address book entry is treated as a single object by the programming language (it can be referenced by a single variable containing a pointer to the object, for instance). Various methods can be associated with the object, such as a method to return the preferred phone number, the home address, and so on.

However, many popular database products such as structured query language database management systems (SQL DBMS) can only store and manipulate scalar values such as integers and strings organized within tables. The programmer must either convert the object values into groups of simpler values for storage in the database (and convert them back upon retrieval), or only use simple scalar values within the program. Object-relational mapping is used to implement the first approach.[1]

The heart of the problem is translating the logical representation of the objects into an atomized form that is capable of being stored in the database, while preserving the properties of the objects and their relationships so that they can be reloaded as objects when needed. If this storage and retrieval functionality is implemented, the objects are said to be persistent.<ref>abc</ref>

ORM Architecture and Framework

Comparison with Traditional Methods

Simple Example with ORM

Simple Explanation

ORM Language

ORM Tools

Comparison between ORM tools

ORM Advantage and Disadvantage

Advantage

ORM is a rapidly growing and popular methodology that provides clear advantages to the developer: Eliminates the fragility of coding CRUD statements to persist data to and from the database Allows logic, business rules and validation to be introduced to the data Provides domain objects that are easy to customise and manage in code Hides the differences between various databases or data sources Saves vast amounts of coding effort

Disadvantage

Database Support

See Also

References

<references>abc</references>

External Links