Download presentation
Presentation is loading. Please wait.
Published byClyde Clarke Modified over 9 years ago
1
Creating and using Persistent Data From before – Where does the data come from? – Why is it kept? – How is it used? Affects design and implementation choices – Modelling choices – Storage choices – Applications programming
2
Influence of source Data volume Rate of arrival
3
Why the data is kept Human reasons for storing data Who needs it? Does it matter if others see it? Does it matter if it is lost or corrupted? How closely does it need to model reality? Does it need to be up-to-date?
4
Data usage How frequently is the data updated? How frequently is it queried? Are there patterns of use?
5
Other factors Budget Platform Licensing Level of support required
6
Modelling choices Entity-relationship model Object model Name-value pairs
7
Contacts See Contact.java at http://www.aber.ac.uk/~dcswww/Dept/Teachi ng/CourseNotes/current/CS12230/code/1- week1-in-lab/0-simple-examples/Contact.java http://www.aber.ac.uk/~dcswww/Dept/Teachi ng/CourseNotes/current/CS12230/code/1- week1-in-lab/0-simple-examples/Contact.java What if we want the contacts data to persist?
8
Contact – OO model UML class diagram Attributes name and phone Operation toString()
9
Contact – ER model Just the attributes No operations Still a UML class diagram
10
Key-value pairs Name is the key Phone is the value Data model is a kind of persistent hash table
11
Storage choices Text file Spreadsheet Browser Database – Relational – Object oriented – NoSQL – Native XML – …
12
Browser HTML5 localStorage localStorage.setItem(key, value) localStorage.getItem(key) For offline use, use appcache Benefits Limitations Example
13
SQLite Create the SQLite database http://www.sqlite.org/ Use a shell tool – a convenient way to create the database in the first place Or write a program
14
Applications Programming with SQL/CLI Obtain a handle on the database Send SQL queries to the database management system using query functions Process the results of those queries – Results are tables and must be transformed into types that the application program can use
15
Java JDBC image from http://www.cse.unsw.edu.au/~jas/talks/jdbc/notes.html accessed 15/Oct/2012http://www.cse.unsw.edu.au/~jas/talks/jdbc/notes.html
16
Java JDBC Driver manager provides implementations of Connection, Statement and ResultSet Connection acts as database handle Statement enables creation and execution of SQL queries ResultSet maintains a cursor that enables access to current row of data returned by query
17
SQLite with Java JDBC Suppose you have a database and a jdbc driver In your Java program – Initialize the jdbc driver Class.forName("org.sqlite.JDBC"); causes org.sqlite.JDBC to be loaded at runtime – Get a connection this.connection = DriverManager.getConnection("jdbc:sqlite:"+dbname); – Use the connection to send SQL queries to the database Contacts example
18
Java Persistence API Alternative to call level interface Work directly with the object oriented data model We’ll revisit this later in the course
19
Summary First think about – Where the data comes from – Why the data is stored – How it is to be used Then think about – Data models – Data storage options – Applications programming
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.