Final Unit-4 ADBMS
Final Unit-4 ADBMS
1
Object Oriented Database
Object-oriented databases (OODB) are databases
that represent data in the form of objects and classes.
In object-oriented terminology, an object is a real-
world entity, and a class is a collection of objects.
4
The data domains in a relational system can be represented
in relational databases as standard data types defined in
the SQL. However, the relational model does not allow
extending these data types or creating the user’s own data
types. Thus, limiting the types of data that may be
represented using relational databases.
Another major weakness of the RDBMS is that, concepts
like inheritance/hierarchy need to be represented with a
series of tables with the required referential constraint.
Thus they are not very natural for objects requiring
inheritance or hierarchy.
5
B. The Need for Object Oriented Databases
1. The objects may be complex, or they may consists of
low-level object
However, to represent the data of these complex objects
through relational database models you would require
many tables – at least one each for each inherited class
and a table for the base class.
In order to ensure that these tables operate correctly we
would need to set up referential integrity constraints as
well.
On the other hand, object oriented models would
represent such a system Object Oriented Database very
naturally through, an inheritance hierarchy. Thus, it is a
very natural choice for such complex objects.
6
2. Consider a situation where you want to design a class,
(let us say a Date class), the advantage of object oriented
database management for such situations would be that
they allow representation of not only the structure but
also the operation on newer user defined database type
such as finding the difference of two dates.
Thus, object oriented database technologies are ideal
for implementing such systems that support complex
inherited objects, user defined data types
7
3. Another major reason for the need of object oriented
database system would be the seamless integration of this
database technology with object-oriented applications.
Software design is now, mostly based on object oriented
technologies. Thus, object oriented database may provide a
seamless interface for combining the two technologies.
8
5. An object oriented database is presently being used
for various applications in areas such as, e-commerce,
engineering product data management; and special
purpose databases in areas such as, securities and
medicine.
6. Some of the major concerns of object oriented
database technologies include access optimization,
integrity enforcement, archive, backup and recovery
operations etc.
9
10
11
Differentiate OBJECT ORIENTED DATABASE and
Traditional Database?
BASIS RDBMS OODBMS
Stands for Relational Database Stands for Object Oriented
Long Form
Management System. Database Management System.
13
In relational databases, connections between concepts
are represented by relations. There’s no
inherent notion of cardinality in databases.
A link between two tables is just that - a link. There’s
nothing in that link telling us whether it is a one-to-
many, many-to-many, or some other relationship.
It is us who put a meaning into it and interpret that
link one way or another depending on the context.
14
2. Flat vs hierarchical structure
In the OO world, the fact that you operate direct
references often leads to hierarchical data structures.
In OO there are clusters of classes: a root, the main
class so to speak, and some number of descendants.
Moreover, this hierarchy may be a cycled graph. A
structure where some group of classes reference each
other forming a cycle.
In relational databases, the situation is different. As
there’s no such things as uni- or bi-directional
relationships and no inherent notion of cardinality, a
relational model tends to result in a flat structure
where each table is of the same rank as any other one.
Cycles can occur in databases too but they are not as
common and generally are frown upon.
15
In OOP, you can choose to declare a particular cluster
of classes a single thing, an aggregate, and then decide
to operate that thing transactionally.
The problem here is that in the relational data store,
there’s nothing we can do to enforce this kind of
separation. All tables are made equal, so any
transaction can update any number of tables at once.
Because of that, it’s easy to introduce a race condition.
A situation where one transaction updates two tables
and another transaction updates one of those tables as
part of another routine, leaving an inconsistency
between the two.
16
3. Encapsulation
In the relational modeling, there’s just no such
notion. Encapsulation is not something you worry
about when trying to come up with a database
scheme.
On the other hand, encapsulation is huge when it
comes to objects. You usually want to hide as much
information as possible by default and reveal it
only when necessary. And even then probably
change the form of that information to something
customer-friendly and not expose its underlying
structure.
17
loading and storing graph of object
using RDBMS
Granularity problem
OODBMS: various levels like Coarse and fine grained
ORDBMS: 2 levels only (table and record)
Subtypes
OODBMS: inheritance
ORDBMS: no
Identity
OODBMS: object identity and object equality
ORDBMS:
Associations
OODBMS: object references (bidirectional)
ORDBMS: foreign key (not directional)
Data Navigation
OODBMS: obj1.getbar().getv(); or obj1.getbar().getv().getz();
ORDBMS: joins
18
Document Oriented Database
A document-oriented database is a specific kind of
database that works on the principle of dealing with
'documents’ rather than strictly defined tables of
information.
The document-oriented database plays an important
role is aggregating data from documents and getting
them into a searchable, organized form.
A document-oriented database, as a particular kind of
NoSQL database, is able to 'parse’ data from
documents that store that data under certain 'keys,’
with sophisticated support for retrieval.
19
For example, suppose one document has two names,
one address, and a list of ages of a home’s occupants. A
second document might have four names, two
addresses, and no age information. A document-
oriented database will take the data in both and store
them according to type, able to handle non-fixed
length data sets.
20
Need of Document Oriented
Database
A Document Data Model is a lot different than other data
models because it stores data in JSON, BSON, or XML
documents.
In this data model, we can move documents under one
document and apart from this, any particular elements
can be indexed to run queries faster.
Often documents are stored and retrieved in such a way
that it becomes close to the data objects which are used
in many applications which means very less translations
are required to use data in applications.
JSON is a native language that is often used to store and
query data too.
So in the document data model, each document has a key-value pair below is an
example for the same.
{
"Name" : "Yashodhra",
"Address" : "Near Patel Nagar",
"Email" : "[email protected]",
"Contact" : "12345"
}
Features:
• Document Type Model: As we all know data is stored in
documents rather than tables or graphs, so it becomes
easy to map things in many programming languages.
• Flexible Schema: Overall schema is very much flexible
to support this statement one must know that not all
documents in a collection need to have the same fields.
• Distributed and Resilient: Document data models are
very much dispersed which is the reason behind
horizontal scaling and distribution of data.
• Manageable Query Language: These data models are
the ones in which query language allows the developers
to perform CRUD (Create Read Update Destroy)
operations on the data model.
Difference between Document
Oriented Database and Traditional
database
1. Relational Model:
2. Document Model:
In the document model, the data is stored in the form of documents. The documents
consist of the records which describe the actual and data of the document. A nested
document can be used to provide information about subcategories of the data.
Document can also be used to represent real-world objects.
S. No. Relational Model Document Model
1. It is row-based. It is document-based.
Not suitable for hierarchical data Generally used for hierarchical data
2.
storage. storage.
ACID properties are followed by this CAP theorem are followed by this
4. model. (Atomicity, Consistency, model. (Consistency, Availability,
Isolation, and Durability). and Partition tolerance).
5. It is slower . It is faster than Relational Model.
7. It is column-based. It is field-based.
9. Fast replication support is not provided. They provide easy replication support
UTF-8 Syntax
<?xml version = "1.0" encoding = "UTF-8" standalone =
"no" ?>
28
UTF-16 Syntax
If suppose a document includes a Unicode like (0XX…)
they are considered to be UTF-16 encodings with 16bits.
29
Types of Encoding in XML
?xml version="1.0" encoding="UTF-8"
standalone="no" ?>
<?xml-stylesheet href="clock.css"
type="text/css"?>
<Clocks timezone="GMT">
<timehour>11</timehour>
<timeminute>50</timeminute>
<timesecond>40</timesecond>
<timemeridian>p.m.</timemeridian>
</Clocks>
<?xml version="1.0" encoding="UTF-16"?>
<college>
<Professor>
<fullname>Evangeline MAC</fullname>
<Dept>Science-1</Dept>
</Professor>
<!--
<Professor>
<fullname>Antony Jay</fullname>
<Dept>Mathematics</Dept>
</Professor>
-->
</college>
30
1. UTF-8
For specific Document types, certain detections rules
are given one such rule is for XML, DTD If no
character encoding is specified then UTF-8 is used and
java, SQL, XQuery uses this encoding as they have
compression format.
For numeric character reference in XML, this UTF-8 is
been assigned with variable-length encoding. The
BYTE ORDER MASKS for UTF-8 is EF BB BF.
It is said that for languages like Chinese scripts the
good choice is to use UTF-16 as there is a trouble with
UTF-8 is as they make larger files yet not a universal
solution. The significant bit of UTF-8 is defined as 7,
11,16,21 as they are encoded as one to four bytes.
31
Example
<?xml version="1.0" encoding="UTF-8"
standalone="no" ?>
<?xml-stylesheet href="clock.css" type="text/css"?>
<Clocks timezone="GMT">
<timehour>11</timehour>
<timeminute>50</timeminute>
<timesecond>40</timesecond>
<timemeridian>p.m.</timemeridian>
</Clocks>
O/P
32
2. UTF-16
This type takes two bytes for each character and
should be smaller also incompatible with ASCII. UTF-
16 doesn’t follow uniform width which may use 2 or 4
bytes.
It faces some issues while processing in older
programming languages like C version as they process
zero-harder machine address.
Here the significant bit is represented as 16, 20. But
UTF-16 supports only for selected specification by xml
parser.
For national data items (COBOL) parsed in XML
documents, it is suggested to prefer UTF-16. They are
used mostly in java and windows.
33
Example
<?xml version="1.0" encoding="UTF-16"?>
<college>
<Professor>
<fullname>Evangeline MAC</fullname>
<Dept>Science-1</Dept>
</Professor>
<!--
<Professor>
<fullname>Antony Jay</fullname>
<Dept>Mathematics</Dept>
</Professor>
-->
</college>
34
O/p
35
UTF 8 UTF 16
Definition A variable length character A variable length character
encoding for Unicode that uses encoding for Unicode that uses
8-bit, 16-bit, 24-bit, 32-bit 16-bit or 32-bit encoding
encoding depending on the depending on the character
character
length UTF-8 uses a byte at the UTF-16 uses 2 byte at the
minimum in encoding the minimum in encoding the
characters characters
encoded file size A UTF-8 encoded file tends UTF-16 encoded file tends
to be smaller to be bigger than UTF-8
Compatibility with ASCII UTF-8 is compatible with UTF-16 is incompatible
ASCII with ASCII
Byte oriented UTF-8 is byte oriented while UTF-16 is not
Error recovery UTF-8 is better in UTF-16 is not better in
recovering from errors recovering from errors
compared to UTF-16 compared to UTF-8
36
JSON - Introduction
JSON stands for JavaScript Object Notation
JSON is a text format for storing and transporting data
JSON is "self-describing" and easy to understand
This example is a JSON string:
'{"name":"John", "age":30, "car":null}'
It defines an object with 3 properties:
• name
• age
• car
Each property has a value.
If you parse the JSON string with a JavaScript
program, you can access the data as an object:
let personName = obj.name;
let personAge = obj.age; 37
JSON
JSON (short for JavaScript Object Notation) is yet another text-based data-interchange
format which uses text and number data types to represent objects. It’s an open-standard
format based on the subset of JavaScript programming language and is completely
language-independent.
It’s a way to transmit data objects consisting of array data types and attribute-value
pairs between a server and the web browser. It uses a human-readable format to
represent simple data structures in web application-based code.
Because of its flexibility, JSON is better suited for data-interchange between web
applications and web services. As a markup language, XML only adds extra
information to a plain text, whereas JSON, as the name suggests, is a way of representing
data objects.
It is also used in desktop as well as server-side programming environments. Unlike
XML, JSON takes a simple approach to represent structure data without complex
mathematical notation and algorithms, plus it’s easy to learn which makes it an ideal way
to create more interactive pages.
As they say, problem of one is the advantage of other. XML syntax is semantics-free, but
it’s verbose which means its complexity makes it hard to be used for every
application.
XML was designed to improve readability, but not to be efficient. JSON syntax is much
more compact with its established semantics which makes it a preferred data format over
XML.
38
What is JSON?
39
Why Use JSON?
The JSON format is syntactically similar to the code for creating
JavaScript objects. Because of this, a JavaScript program can
easily convert JSON data into JavaScript objects.
Since the format is text only, JSON data can easily be sent
between computers, and used by any programming language.
JSON.parse()
JSON.stringify()
40
Storing Data
41
JSON - Objects
Creating Simple Objects
JSON objects can be created with JavaScript.
Let us see the various ways of creating JSON objects using
JavaScript −
<html>
<head>
<title>Creating Object JSON with JavaScript</title>
<script language = "javascript" >
var JSONObj = { "name" : “RCPIT", "year" : 2005 };
<body>
</body>
</html>
43
O/p
JSON with JavaScript example
44
Creating Array Objects
The following example shows creation of an array object in javascript using JSON, save the below code as json_array_object.htm
<html>
<head>
<title>Creation of array object in javascript using JSON</title>
<script language = "javascript" >
document.writeln("<h2>JSON array object</h2>");
var books = { "Pascal" : [
{ "Name" : "Pascal Made Simple", "price" : 700 },
{ "Name" : "Guide to Pascal", "price" : 400 }],
"Scala" : [
{ "Name" : "Scala for the Impatient", "price" : 1000 },
{ "Name" : "Scala in Depth", "price" : 1300 }]
}
var i = 0
document.writeln("<table border = '2'><tr>");
for(i = 0;i<books.Pascal.length;i++) {
document.writeln("<td>");
document.writeln("<table border = '1' width = 100 >");
document.writeln("<tr><td><b>Name</b></td><td width = 50>" + books.Pascal[i].Name+"</td></tr>");
document.writeln("<tr><td><b>Price</b></td><td width = 50>" + books.Pascal[i].price +"</td></tr>");
document.writeln("</table>");
document.writeln("</td>");
}
45
for(i = 0;i<books.Scala.length;i++) {
document.writeln("<td>");
document.writeln("<table border = '1' width = 100 >");
document.writeln("<tr><td><b>Name</b></td><td width = 50>" +
books.Scala[i].Name+"</td></tr>");
document.writeln("<tr><td><b>Price</b></td><td width = 50>" +
books.Scala[i].price+"</td></tr>");
document.writeln("</table>");
document.writeln("</td>");
}
document.writeln("</tr></table>");
</script>
</head>
<body>
</body>
</html>
46
47
XML JSON
Definition XML is a simplified version of the SGML JSON, on the other hand, is a lightweight
(standard generalized markup language) used data-interchange format used to represent
to store and represent structured data in a format hierarchical data and is based on JavaScript
that is both machine-readable and human- object syntax.
readable. It’s designed to improve readability as
it’s a markup language which adds extra
information to plain text.
Meaning XML is short for “Extensive Markup Language” JSON stands for “JavaScript Object Notation”
and is a document-oriented technology used to and as the name suggests, it’s based on the
encode data in a human-readable format. It’s a JavaScript programming language.
flexible file format suitable for web use.
Purpose XML was developed by the World Wide Web JSON was developed by Douglas Crockford
Consortium as a well-documented open standard
format containing a set of rules on how to encode as a simple, lightweight file format for data
documents in both human-readable and interchange.
machine-readable format.
Syntax XML, on the other hand, takes more characters to JSON has no start and end tags and the
represent same data. It’s not as lightweight as syntax is lighter than XML as it’s data-
JSON. oriented with less redundancy which makes
it an ideal alternative for interchanging data
over XML.
Data Type XML has no direct support for array type but it JSON supports text and number data type
supports many data types such as number, text, including integer and strings. Structured
images, graphs, charts, etc. data is represented using arrays and objects.
48
What is BSON ?
BSON stands for Binary JSON.
It is a binary file format that is used to store
serialized JSON documents in a binary-encoded format.
It was developed in 2009 by MongoDB.
The MongoDB database had several scalar data formats that
were of special interest only for MongoDB, hence they
developed the BSON data format to be used while
transferring files over the network.
It has several similarities with JSON for instance BSON too
supports nested documents and arrays within other
documents, but yet has a lot of striking differences.
49
Sample BSON document
• Consider the following JSON document:
{ "hello" : "world" }
It’s BSON equivalent will be:
\x16\x00\x00\x00 // Size of the Document
\x02 // 0x02 = type String
hello\x00 // field name
\x06\x00\x00\x00world\x00 // field value
\x00 // Used to represent end of object
51
Data Types supported by BSON:
Following are the data types supported by BSON –
S No Data Type Size (bytes)
1 byte 1
2 int32 4
3 int64 8
4 uint64 8
5 double 8
6 decimal128 16
7 date 8
8 objectId 12
54
The basis Of
Comparison
JSON BSON
57
MariaDB : Database Model
59
Ring Replication
Scales read and write operations.
Doesn’t know how to deal with disagreements.
Replication is halted if one of the primary servers fails.
60
Star Replication
Read and write scaling is available.
Doesn’t seem to be able to deal with disagreements.
To prevent data duplication, replication filters must be
used.
61
MultiSource Replication
It is possible to combine data from various sources.
On all replicas, various domains ran in parallel.
62
MariaDB : SQL Syntax
MariaDB is based on ANSI SQL, and hence its syntax
is traditional SQL syntax to query and analyze the
data.
For example, to query the data from a sample
employee table, the user can run the following
command to get the data –
SELECT * FROM employee;
MariaDB: Referential Integrity
MariaDB is an RDBMS system, and the concept of
Foreign key exists. Hence, different tables are very well
linked together, which helps to grab the data from any
table
63
MariaDB : Programming Language
MariaDB had support for only a few languages, and hence
sometimes, it isn’t easy to interact with every system. The
programming language MariaDB supports is Python, Java,
and C/C++.