Professional Documents
Culture Documents
Extensions
Extensions
1 Abstract
The relational model has shown its versatility and
potential over years. For many years, any scenario
demanding data persistence was properly mapped
and implemented according to the relational
principles. Nowadays, we can say that the relational
model is not enough to model any kind of data or
environment. Relational extensions mainly focus on
incorporating complex objects into the database. In
this paper we will focus on tree of these extensions:
the object-oriented. XML and JSON.
2 Object-Oriented Database
Systems
The object oriented database systems (OODBS) Object-Oriented Database System
differ from relational databases in the use of internal
object identifiers or OIDs instead of candidate keys
and provide a natural integration between object- 2.1 Object-Relational Database
oriented programing languages (OOPL) and stored Systems
data. In the OODBS, the OOPL provides a uniform
natural way to access object- oriented data, whereas Although the OO paradigm provides a
relational database have to develop specific object- revolutionary concept for data modeling, all the
oriented interfaces to communicate with SQL. efforts put in the relational technology should not
be put aside. Instead, relational databases should be
The characteristics that any OODBMS should extended with object features to deal with OO
contain are: principles. According to this a ORDBMS should
• OO Data model: Data must be internally provide the following features:
organized according to the object-oriented • User defined data types.
data model. Objects as means to represented
data and universally identified by an object • Objects tables formed from user-defined
identifier (OID). Encapsulation, in terms of types.
function, is mandatory as well as traditional • Hierarchies and support OIDs.
object-oriented features such as inheritance
and extensibility, overriding/overloading A model is composed of a data structure, a set of
operators and late binding. All in all, integrity constraints and a set of operators to handle
providing computational completeness. data. As explained, the object-relational model is an
extension of the relational model and, thus, it relies
• DBMS: A database management system on it.
should provide persistence and therefore, it
must deal with issues such as secondary The operators used to manipulate the object-
storage management, concurrency, recovery relational data are those already available in the
and ad hoc query facilities. relational algebra and, at a higher level of
abstraction, SQL. In this sense , thus, there is no
new contribution.
1
2.4 Object Types and User
Defined Objects
In Oracle, a statement create type is used to create a
new data type (object type) that can be user as a
generic type to create a table using the statement
create table or to create another data type. The
general syntax for this create statements is:
2
Artist automatically inherits all methods and
attributes from person, and extends it with its own
attributes country and genre.
Inheritance is an interesting feature that provides
The create type body … as is used to define those more semantics than object references or foreign
type of methods (functions and procedures) declared keys.
in the fullname object type definition.
Now, we can use this type as any other type. For
example:
2.6 Polymorphism
Object views allow exploiting polymorphism
through type hierarchies. Thus, a polymorphic
expression can take the declared type or any of its
subtypes as values.
For example, suppose we had the following
relational table:
2.5 Inheritance
The under clause can be used to define subtypes.
The syntax is as follows:
3
2.7 References between Objects object-oriented programing languages.
REFs are essential mechanism to reference objects The general syntax to define VARRAYs is as
and therefore, a basic tool to enforce integrity follows:
constraints, like foreign keys in the relational model.
The main differences between both concepts are: Where name is the name of the new VARRAY
• Foreign key points to primary or candidate type, limit is the number of elements this collection
keys, whereas REFs point to objects. can contain and finally, after the OF keyword, we
must specify a built-in datatype or user-defined
• In the object-relational model dangling type this collection is made of.
REFs are allowed (it means that the pointed
object could no longer exists). However, a For example:
foreign key is never dangling and guarantees
that the candidate key pointed does exists.
The REF type allows referencing objects and it is
implemented as an object pointer. This type contains:
• The OID of the referenced object-oriented. Alternatively, we could create the song object type
• The OID of the table or view containing and declare a VARRAY of songs:
that object.
REFs can be defined as scoped or unscoped ones.
Scope REFs are strongly typed and point to an object
table. Oppositely, the pointed object type is unknown
for unscoped REFs.
For example, consider yet another possibility to
model the song and artist types:
2.8.1 Varray
A Varray is an ordered collection of elements where
each element is associated to an index, in other
words, it maps the traditional array concept of
4
Nested tables can have any number of elements
(unlike VARRAYs, which require a maximum
number of elements at definition time) and they are
handle as an ordinary table. We can use triggers,
index or any statement available for regular tables.
For example we can create index over it: If we use the object relational extensions, which
supports inheritance using the under keyword, we
can create Student and Staff subclasses under the
superclass.
5
relationship with another class and the inverse
relationship is also a set, the transformation of such
an association is identical to the many-to-many
relationships’ transformation from relational
modeling to relational tables where a table is created
to represent the set relationship. This transformation
strategy also enforces that each element within a set
cannot be duplicated, which is realized by the Implementation of one-to-one using a primary-key
implementation of the composite primary key of the and foreign-key relationship :
relationship tables.
In one-to-many relationships, as in relational
modeling, the primary key of the one side is copied
to the many side to become a foreign key. In other
words, there is no special treatment necessary for the
transformation of association relationships having a
set semantic.
In Oracle there are two ways of implementing an Implementation of many to many using object
association relationship: by primary-key and foreign- references :
key relationships and by object references. Each of
these methods will be described as follows.
6
Note that there is neither the concept of a primary
key nor the integrity constraint in the part nested
table. For example, if a particular HD controller is
used by another HD from the whole table, then all
the details of the HD controller will be written
again as a separate record within the nested table.
2.11 Case study: Aggregation Nested table also facilitates multilevel and thus can
Relationships using the be used for implementing a multilevel aggregation
Nesting Technique relationship. A PC is an aggregation of several
HDs, and a HD is an aggregation of several HD
Aggregation is a tightly coupled form of association. controllers. In this case, the inner table is a nested
The main difference between aggregation and table of HD controller, and the outer table is a
association is the underlying semantic strength. nested table of HD. The implementation of this
While an aggregation forms a method of aggregation is:
organization that exactly maps human thinking, an
association is a mere mapping between objects in an
application. Aggregation is a composition or part-of
relationship, in which a composite object (whole)
consists of other component objects (parts).
In an aggregation relationship, in which one whole
can have many parts associated with it through a
part-of relationship, the entire part-of relationship is
viewed as one composition, not several association
relationships.
7
2.12 Case study: objects views The object view looks to user like an object table
whose underlying type is comics_t. Each row
Object views are used to access relational data using contains an object of type comics_t. As yo can see,
object-related features, in this way we can access each row has a unique object identifier:
objects that belong to an object view in the same
way if they were objects in an object table. For
example we have a heap table with the following
data and structure:
8
XML represents data in text format and encloses data. XML attributes are name-value pairs that are
data items between user understandable and introduced in the start tag of elements. The
meaningful tags. For example, the address of a following is an example of attributes in use within
student is described as follows: an element description:
The data item in this case is “123 Main Street, Here, the cost of some item is being described. The
Atlanta, GA 30002” and is enclosed between the cost (25.20) is being described using an XML
start tag <address> and the end tag </address>. The element <cost>. The start tag includes a name-
tag name “address” is user-defined and is descriptive value pair currency=”USD” indicating that the
of the data item that it is enclosing. currency of the cost is in US dollars. In contrast to
The entire string starting with the start tag, including XML elements, attribute names cannot be repeated
the data item, and ending with the end tag is referred within the same start-tag. So, the following will be
to as an XML element. XML elements can be nested an error:
as in the following example which includes sub-
components of the address:
9
that is well formed. It satisfies a list of syntax rules Unfortunately, you have also used the element
provided in the specification. The main rules that a name nuclyanalitics in your XML but for a
well-formed XML document should satisfy are: different purpose and thus with a different
structure. In order to avoid these name clashes,
• It contains only properly encoded legal
XML incorporate naming spaces. Using an XML
Unicode characters. Namespace resolves name collisions or ambiguities
• None of the special syntax characters such in an XML document.
as '<' and '&' appear except when performing These alias are usually defined at the beginning of
their mark-up delineation roles. the XML document thought they can be defined for
• The beginning, end and empty-element tags an element and apply to that element and all its
that mark the elements are correctly nested, subelements. Aliases are defined using a special
with none missing and none overlapping. attribute that starts with xmlns: and then the alias.
• The element tags are case-sensitive; the The value of the attribute is the URI it refers to.
beginning and end tags must match exactly. Finally, there is the default namespace, which is
defined using the xmlns attribute and applies to all
• Tag names cannot contain any of the elements that do not explicitly define their
characters " # $ % & ' ( ) * + , / ; < = > ? @ [ namespace. Elements and attributes define their
\ ] ^ ` { | } ~, nor a space character, and namespace by prepending the namespace alias plus
cannot start with - . or a numeral. ':' to the element or attribute name
• There is a single root element that contains
all the other elements, which might be
nested. Altogether, the XML syntax encodes
an underlying tree data structure.
A well-formed XML document is syntactically
correct. This allows it to be processed by generic
processors that traverse the document and create an
internal tree representation.
3.1.2 Namespaces
namespace declaration
A namespace is identified by a URI (Uniform
Resource Identifier) and as long as you define a
unique URI for your namespace, you can then use 3.1.3 Full XML example
whatever element and attribute names inside it. The
best way to get a unique URI is to use part of your One possible XML representation of the
organization or own domain name to build a custom COMPANY database is discussed in this section.
URL for your namespace. For instance, for someone The overall structure of the XML document is as
who works in NULCI it is possible to pick the follows:
nucliexperts.com domain name and build a URI for
the namespace like:
http://www.nucliexperts.com/subjects/adb/ ns/custom#
name ambiguity
The document contains three main sections, one
each for the list of departments, employees, and
Let's imagine that you want to combine a piece of projects. Each section describes the individual
XML with another piece you have generated.
10
entities within the classes along with relationships
with other entities.
The <departments> element contains one or more
<department> elements that describe the individual
department along with its relationships with other
entities. The following XML code fragment shows
the details for department 5:
11
throughput when inserting and retrieving application domain.
entire XML documents. It also provides the
Although XML DTD is quite adequate for
greatest degree of flexibility in terms of the
specifying tree structures with required, optional,
structure of the XML that can be stored.
and repeating elements, and with various types of
XML is stored using CLOB, BLOB, BFILE
attributes, it has several limitations:
or VARCHAR2.
1. The data types in DTD are not very
• Structured storage is based on the general.
XMLType, a new type that makes database
aware that XML is being stored. It has a 2. DTD has its own special syntax and thus
number of advantages, including optimized requires specialized processors. It would be
memory management, reduce storage advantageous to specify XML schema
requirements and B-tree indexing. These documents using the syntax rules of XML
advantages are at cost of a greater itself so that the same processors used for
processing overhead during ingestion and XML documents could process XML
retrieval and reduce flexibility in terms of schema descriptions.
the structure of the XML. 3. All DTD elements are always forced to
To load into Oracle XML DB using an unstructured follow the specified ordering of the
approach: document, so unordered elements are not
permitted.
12
• string type
• int type
• decimal type
• others (boolean, float, integer ...)
The namespace prefix has no significance and can be
anything that you choose. The prefixes in the examples are:
preceding examples are most commonly used. An
XML Schema declares vocabularies; therefore, the
optional targetNamespace attribute helps to uniquely
identify a vocabulary, and requires a matching
namespace declaration to be used with references to
declarations within the same XML Schema. 3.2.3 Declaring a simple types
The <simpleType> declaration includes atomic or
3.2.3 Declaring an element built-in types provided by the XML Schema
The XML Schema language uses the <element> Recommendation. An example of a built-in-type is
component to declare an XML element. The integer, which requires numeric data in a document
attributes of <element> are: instance. A <simpleType> declaration can be:
• The name attribute for specifying the tag • For a derived type that extends a built-in or
name for the element other simpleType declaration .
• The type attribute to specify the content • For an element that contains data, and may
type, or type of data contained in the not contain attributes or child elements .
element • Refined by using facets or properties .
• The ref attribute for referencing global type
names in the schema document
• The form attribute that can be used to
override the elementFormDefault attribute
value used in the <schema> element
In the example:
• The minOccurs attribute that specifies the
minimum number of times the element must • A <simpleType> called empid is declared
appear in the XML instance document. A as a <restriction> type
value of zero indicates that the element is • The <restriction> uses the base attribute to
optional. identify the built-in type from which the
• The maxOccurs attribute that indicates the <simpleType> is derived
maximum number of times the element can • The base type is positiveInteger,
appear in the XML instance document. A representing non-negative values
value of unbounded means that there is no
limit to the number of element occurrences. • The maxInclusive facet sets a maximum
value of 1000 for this data type
• The default attribute that specifies a default
value for the element if it does not appear in • The <element> for employee_id references
the XML instance document. The default is the empid <simpleType> as its data type,
not applied to an element with a value. restricting employee_id elements to
contain positive integers less than or equal
• The fixed attribute indicates that the content to 1000.
of the element must be equal to this value.
13
complex structures. A <complexType> that is XMLType tables or columns can be constrained
declared globally in the XML Schema document and conform to an XML schema. This has several
must be identified by a name attribute. A locally advantages:
declared <complexType> is called an anonymous
• The database will ensure that only XML
complex type, where the name attribute is not
documents that validate against the XML
required. Setting the mixed attribute to true allows
schema can be stored in the column or
both text and element content to be included in the
table.
content for the element.
The <complexType> declaration specifies different • Since the contents of the table or column
content models that enable the content to be mixed, conform to a known XML structure, Oracle
empty, or contain element hierarchies. A content XML DB can use the information
model can contain: contained in the XML schema to provide
more intelligent query and update
• Simple content, for data without child processing of the XML.
elements .
• Constraining the XMLType to an XML
• A <sequence> declaration, to specify an schema provides the option of storing the
ordered sequence of child elements . content of the document using structured-
storage techniques.
• A <choice> declaration, for providing a
choice of child elements . Structured storage decomposes the content of the
XML document and stores it as a set of SQL
• A reference to a global <group>, for reusing objects rather than simply storing the document in
a group of elements to define the complex an unstructured way, such as text in a CLOB.
type structure .
• An <all> declaration, to allow all elements
3.3 XML Languages
in the content model to be used in any
order . There have been several proposals for XML query
languages, and two query language standards have
emerged. The first is XPath, which provides
3.2.5 Registering an XML schema in language constructs for specifying path expressions
Oracle XML DB to identify certain nodes (elements) or attributes
An XML schema must be registered with the Oracle within an XML document that match specific
XML DB before it can make use of it. To register an patterns. The second is XQuery, which is a more
XML schema, the user should call PL/SQL general query language. XQuery uses XPath
procedure DBMS_XMLSCHEMA.register_schema: expressions but has additional constructs. We give
an overview of each of these languages.
3.3.1 XPath
An XPath expression generally returns a sequence
of items that satisfy a certain pattern as specified by
the expression. These items are either values (from
When XML schemas are registered with Oracle leaf nodes) or elements or attributes. The most
XML DB, a set of default tables are created and used common type of XPath expression returns a
to store XML instance documents associated with collection of element or attribute nodes that satisfy
the schemas. These documents can be viewed and certain patterns specified in the expression.
accessed in Oracle XML DB Repository.
The names in the XPath expression are node names
XMLType is a native server datatype that lets the in the XML document tree that are either tag
database understand that a column or table contains (element) names or attribute names, possibly with
XML. This similar to the way that date and additional qualifier conditions to further restrict the
timestamps datatypes let the database understand nodes that satisfy the pattern.
that a columns contains a date. Datatype XMLXType
also provides methods that allow common Two main separators are used when specifying a
operations such as XML schema validation. path: single slash (/) and double slash (//). A single
slash before a tag specifies that the tag must appear
14
as a direct child of the previous (parent) tag, whereas
a double slash specifies that the tag can appear as a
descendant of the previous tag at any level.
RETURN <query result specification> XQuery has very powerful constructs to specify
complex queries. In particular, it can specify
There can be zero or more instances of the FOR universal and existential quantifiers in the
clause, as well as of the LET clause in a single conditions of a query, aggregate functions, ordering
XQuery. The WHERE clause is optional, but can of query results, selection based on position in a
appear at most once, and the RETURN clause must sequence, and even conditional branching. Hence,
appear exactly onc e. Let us illustrate these clauses in some ways, it qualifies as a full-fledged
with the fol- lowing simple example of an XQuery: proramming language.
15
3.4 Case study: XPath and XQuery
to retrieve data from XML
documents
1. For the implementation, we will first create a
schema validation of XML documents
(XSD) for the purpose of the whole XML
document structure meets certain conditions.
An XML schema must be registered with the
Oracle XML DB before it can make use of
it. To register an XML schema, the user
should call PL/SQL procedure
DBMS_XMLSCHEMA.register_schema:
16
XQuery is a query language designed to JSON includes a way to describe arrays. So, the
work with collections of XML data, which JSON text might look like this:
provides tools to extract and manipulate
information from XML documents
Using XQUERY we want to know
which article is more expensive than 100 €
17
describing data, where the schema elements are actually with closing tags, and some other features.
within the data itself. And this is of course typically
Second is complexity most people would say that
more flexible than the to a model.
XML is a bit more complex than JSON. If you look
But there are advantages to having schema? as well, at the subset of XML that people really use, you've
definitely. As far as queries go, one of the nice got attributes, sub elements and text, and that's
features of the relational model is that there are more or less it. If you look at Json, you got your
simple, expressive languages for clearing the basic values and you've got your objects and your
database. In terms of json, although a few New arrays.
things have been proposed; at this point there's
Now let's turn to validity. And by validity, I mean
nothing widely used for querying Jason data.
the ability to specify constraints or restriction or
One aspect of the relational model is that it's an schema on the structure of data in one of these
unordered model. It's based on sets and if we want to models, and have it enforced by tools or by a
see relational data in sorted order then we put that system.
inside a query. In JSON, we have arrays as one of
Specifically in XML we have the notion of
the basic data structures, and arrays are ordered.
document type descriptors, or DTDs, we also have
XML Schema which gives us XSD's, XML Schema
Descriptors. And these are schema like things that
we can specify, and we can have our data checked
to make sure it conforms to the schema.
For JSON, there's something called JSON Schema.
And, you know, similar to XML Schema, it's a way
to specify the structure and then we can check that
JSON conforms
One of the original criticisms of relational database
systems is that the data structures used in the
database, specifically tables, didn't match directly
4.3 Comparing JSON and XML with the data structures and programming
languages.
Both of them are very good for putting semi-
structured data into a file format and using it for data So there had to be some manipulation at the
interchange. And so because there's so much overlap interface between programming languages and the
in what they're used for. database system and that's the mismatch. So that
same impedance mismatch is pretty much present
XML is in general, a little more verbose than Jason.
in XML wherein JSON is really a more direct
So the same data expressed in the 2 formats will tend
mapping between many programming languages
to have more characters in XML than JSON and you
and the structures of JSON.
can see that in the following example:
Finally, let's talk about querying. JSON does not
have any mature, widely used query languages at
this point. for XML we do have XPath, we have
XQuery, we have XSLT. Maybe not all of them are
widely used but there's no question that XPath at
least and XSL are used quiet a bit. As far as Json
goes there is a proposal called Json path. It looks
actually quiet a lot like XPath maybe he'll catch on.
There's something called JSON Query. Doesn't
look so much like XML Query,
As conclusion we can say that JSON is most useful
with simple, structured data. XML is useful for
both structured and semi-structured data. JSON is
generally data-centric, not document-centric; XML
can be either. JSON is not a markup language; it is
XML being a bit more verbose largely has to do designed only for data representation. XML is both
18
a document markup language and a data 3. Querying JSON data
representation language.
6 Bibliography
• Object-oriented Oracle / Wenny Rahayu,
David Taniar and Eric Pardede 2006
• Object-Relational and XML Extensions,
Oscar Romero 2009
19
• XML and JSON data model, Jennifer
Widom 2011
• Oracle Database Online Documentation 11g
Release 1 (11.1) / XML DB Developer's
Guide 2009
• Manejando XMLType en Oracle Database
11gR2 a través del componente XDB,
Francisco Riccio 2013
• Oracle-base, JSON Data in Oracle Database
12c Release 1 (12.1.0.2) 2013
• Oracle Database Online Documentation 12c
Release 1 (12.1) / Application Development
2013
20