Download Overheads

Document related concepts

Concurrency control wikipedia , lookup

Microsoft Jet Database Engine wikipedia , lookup

Relational algebra wikipedia , lookup

Entity–attribute–value model wikipedia , lookup

Clusterpoint wikipedia , lookup

Relational model wikipedia , lookup

Database model wikipedia , lookup

Transcript
Modules, Assignments, Resources
“Jo wants to keep track of modules, assignments and
useful learning resources. Each module is worth a number
of credits, and each assignment contributes a percentage
to the module assessment. Some modules have no
assignments; others have several. Learning resources
include books, notes, code fragments and web resources.
Jo mainly wants to keep track of resources that are useful
for completing assessed coursework, but also wants to
keep track of interesting resources that are not
necessarily associated with any module or assessment,
but are of more general educational interest.”
From description to application
I
Entity relationship modelling: entities, attributes, relationships
From description to application
I
Entity relationship modelling: entities, attributes, relationships
I
Entity relationship translation
From description to application
I
Entity relationship modelling: entities, attributes, relationships
I
Entity relationship translation
I
Implementation using a relational database
From description to application
I
Entity relationship modelling: entities, attributes, relationships
I
Entity relationship translation
I
Implementation using a relational database
I
Other approaches could have been taken
Entities and attributes
I
Nouns suggest entity classes and attributes
Entities and attributes
I
Nouns suggest entity classes and attributes
I
Sometimes nouns indicate entity instances or attribute values
Entities and attributes
I
Nouns suggest entity classes and attributes
I
Sometimes nouns indicate entity instances or attribute values
I
Nouns: module, assignment, resource, credit, percentage,
book, note, code fragment, web resource
Entities and attributes
I
Nouns suggest entity classes and attributes
I
Sometimes nouns indicate entity instances or attribute values
I
Nouns: module, assignment, resource, credit, percentage,
book, note, code fragment, web resource
I
But which nouns suggest entities, and which attributes?
Entities and attributes
I
Nouns suggest entity classes and attributes
I
Sometimes nouns indicate entity instances or attribute values
I
Nouns: module, assignment, resource, credit, percentage,
book, note, code fragment, web resource
I
But which nouns suggest entities, and which attributes?
I
And we probably don’t have all the facts!
Entities and attributes
I
Nouns suggest entity classes and attributes
I
Sometimes nouns indicate entity instances or attribute values
I
Nouns: module, assignment, resource, credit, percentage,
book, note, code fragment, web resource
I
But which nouns suggest entities, and which attributes?
I
And we probably don’t have all the facts!
I
And there may be some inaccuracies or contradictions in the
facts we do have.
Entities and attributes
I
Nouns suggest entity classes and attributes
I
Sometimes nouns indicate entity instances or attribute values
I
Nouns: module, assignment, resource, credit, percentage,
book, note, code fragment, web resource
I
But which nouns suggest entities, and which attributes?
I
And we probably don’t have all the facts!
I
And there may be some inaccuracies or contradictions in the
facts we do have.
I
Create a model, and discuss it with the client
Entities and their attributes
I
Aim for simplicity; not too many entities, not too many
attributes in each entity.
Entities and their attributes
I
Aim for simplicity; not too many entities, not too many
attributes in each entity.
I
Entities are of interest in their own right
Entities and their attributes
I
Aim for simplicity; not too many entities, not too many
attributes in each entity.
I
Entities are of interest in their own right
I
Attribute values are facts about entity instances
Entities and their attributes
I
Aim for simplicity; not too many entities, not too many
attributes in each entity.
I
Entities are of interest in their own right
I
Attribute values are facts about entity instances
I
Attributes are of interest only insofar as they relate to entities
Entities and their attributes
I
Aim for simplicity; not too many entities, not too many
attributes in each entity.
I
Entities are of interest in their own right
I
Attribute values are facts about entity instances
I
Attributes are of interest only insofar as they relate to entities
I
In this example, choose Module, Assignment, Resource as
entities
Entities and their attributes
I
Aim for simplicity; not too many entities, not too many
attributes in each entity.
I
Entities are of interest in their own right
I
Attribute values are facts about entity instances
I
Attributes are of interest only insofar as they relate to entities
I
In this example, choose Module, Assignment, Resource as
entities
I
‘location’ was not mentioned explicitly in the initial description
Entities and attributes
Module
Module_Code {PK}
Title
Credits
I
Resource
Kind
Name
Location {PK}
UML classes represent entity class
Assignment
Title {PK}
Deadline
Value
Entities and attributes
Module
Module_Code {PK}
Title
Credits
Resource
Kind
Name
Location {PK}
Assignment
Title {PK}
Deadline
Value
I
UML classes represent entity class
I
Primary keys identified - will need revisiting
Entities and attributes
Module
Module_Code {PK}
Title
Credits
Resource
Kind
Name
Location {PK}
Assignment
Title {PK}
Deadline
Value
I
UML classes represent entity class
I
Primary keys identified - will need revisiting
I
No methods
Relationships
I
Verbs suggest relationships, including the relationship between
an attribute and an entity class
I
Sometimes verbs indicate the association between an entity
class and its attributes
I
In this example, model the relationships between modules and
assignments, and between assignments and resources
Modules and Assignments
Module
Module_Code {PK} 1..1
Title
Credits
Assignment
has
0..*
is_for
Title {PK}
Deadline
Value
Resources and Assignments
Resource
Location {PK}
Name
Kind
Assignment
useful_for
0..*
0..*
used_in
Title {PK}
Deadline
Value
Resources and Assignments
Module
Assignment
has
Module_Code {PK} 1..1
Title
Credits
0..*
Title {PK}
Deadline
Value
is_for
r
_fo
l
u
Resource
u
0..*
f
se
Kind
Name
Location {PK} 0..*
us
es
Entity-Relationship Translation
I
Represent entities and relationships as relations
I
0..* to 1..1; place key of 1..1 end in 0..* end of relationship
I
0..* to 0..*; create a new link entity
Module – Assignment
I
Module{module_code, module_title, credits}
I
Assignment{assignment_title, module_code∗, deadline,
value}
I
Conventional notation; underline primary key attributes;
asterisk indicates foreign key reference
Assignment – Resource
I
Resource{location, name, kind}
I
Assignment{assignment_title, module_code∗, deadline,
value}
I
Useful_for{assignment_title∗, location∗}
Decide on types for the attributes
I
Module{module_code varchar(7), title text, credits int}
I
Resource{location text, name text, kind text}
I
Assignment{assignment_title text, module_code∗ varchar(7),
value int, deadline date}
I
Useful_for{assignment_title∗ text, location∗ text}
Review the relations
I
Revisit Assignment
I
Redefine the primary key:
Assignment{assignment_num int, module_code∗ varchar(7),
assignment_title text, value int, deadline date}
I
Update any foreign key references to Assignment (Useful_for)
I
Add reference to assignment brief:
Assignment{Assignment_num int, module_code∗ varchar(7),
assignment_title text, brief text, value int, deadline date}
Final collection of relations
I
Module{module_code varchar(7), module_title text, credits
int}
I
Assignment{Assignment_num int, module_code∗ varchar(7),
assignment_title text, brief text, value int, deadline date}
I
Resource{location text, name text, kind text}
I
Useful_for{(Assignment_num int, module_code varchar(7))∗,
location∗ text}
Implementation
I
Choose a database management system
I
Create and populate the database
I
Decide on the implementation language
I
Create the application
sqlite database, JDBC, GUI
I
Java application
I
Code and script available for download on the
CS27020 pages
Evaluation – the database design
I
Reasonable design
Evaluation – the database design
I
Reasonable design
I
Some improvements could be made
Evaluation – the database design
I
Reasonable design
I
Some improvements could be made
I
Poor choice of key to ‘Resource’
Evaluation – the database design
I
Reasonable design
I
Some improvements could be made
I
Poor choice of key to ‘Resource’
I
What would make a better key?
Evaluation – the database design
I
Reasonable design
I
Some improvements could be made
I
Poor choice of key to ‘Resource’
I
What would make a better key?
I
Are there any other improvements?
Evaluation – sqlite
I
self-contained database
Evaluation – sqlite
I
self-contained database
I
all the data in a single file
Evaluation – sqlite
I
self-contained database
I
all the data in a single file
I
serverless sql engine
Evaluation – sqlite
I
self-contained database
I
all the data in a single file
I
serverless sql engine
I
whole database locks for an update
Evaluation – sqlite
I
self-contained database
I
all the data in a single file
I
serverless sql engine
I
whole database locks for an update
I
... which is fine for a single user
Integrity – sqlite
I
entity integrity ok
Integrity – sqlite
I
entity integrity ok
I
interesting approach to types
Integrity – sqlite
I
entity integrity ok
I
interesting approach to types
I
referential integrity is not enforced (like mysql without
InnoDB)
Integrity – sqlite
I
entity integrity ok
I
interesting approach to types
I
referential integrity is not enforced (like mysql without
InnoDB)
I
in some versions, triggers can be defined to enforce referential
integrity
Integrity – sqlite
I
entity integrity ok
I
interesting approach to types
I
referential integrity is not enforced (like mysql without
InnoDB)
I
in some versions, triggers can be defined to enforce referential
integrity
I
sqlite 3 enables referential integrity checking, but it must be
explicitly switched on
Evaluation – SQLite/Java connection
I
conventional JDB connection
Evaluation – SQLite/Java connection
I
conventional JDB connection
I
convenient prepared statements
Evaluation – SQLite/Java connection
I
conventional JDB connection
I
convenient prepared statements
I
watch out for queries that update the database built on user
input
Evaluation – SQLite/Java connection
I
conventional JDB connection
I
convenient prepared statements
I
watch out for queries that update the database built on user
input
I
for example, the fields of a new assignment should be checked
before the ‘insert’ query is built
Evaluation – SQLite/Java connection
I
conventional JDB connection
I
convenient prepared statements
I
watch out for queries that update the database built on user
input
I
for example, the fields of a new assignment should be checked
before the ‘insert’ query is built
I
especially important because sqlite has so little checking
Evaluation – SQLite/Java
I
the code in ResourceOrganizerSqlite.java needs some work
Evaluation – SQLite/Java
I
the code in ResourceOrganizerSqlite.java needs some work
I
assignment listing could be tidier
Evaluation – SQLite/Java
I
the code in ResourceOrganizerSqlite.java needs some work
I
assignment listing could be tidier
I
and further queries/updates are needed
Evaluation – the GUI
I
proof of concept
Evaluation – the GUI
I
proof of concept
I
but very much a spike solution
Evaluation – the GUI
I
proof of concept
I
but very much a spike solution
I
input in particular needs reworking
Evaluation – the GUI
I
proof of concept
I
but very much a spike solution
I
input in particular needs reworking
I
consider a separate input verifier class for entity class
Evaluation – the GUI
I
proof of concept
I
but very much a spike solution
I
input in particular needs reworking
I
consider a separate input verifier class for entity class
I
review verification, display and connection to the database
Summary
I
Developed a small database system from an outline
description through a working application
I
Revealed some important problems with database integrity
I
Outlined some suggestions to develop a better system