View
216
Download
1
Embed Size (px)
Citation preview
COMS W3156:Software Engineering, Fall 2001
Lecture #19: Databases, CVE’s
Janak J Parekh
Next class
• Guest lecture!• It’s my friend, so you have to come • After that:
– Continue discussion on languages• Begin pointers
• C++
– Smooth your transition to future semesters
– Will anyone actually attend next Tues.? I really hope so
Today’s class
• Finish look at Swing/AWT– Recitation!
• Discuss side-topic of virtual environments in the software engineering world
• Brief discussion of databases
• Start C, the language
Swing/AWT layout management
• Need to lay out various components• Might use IDE for this, though I don’t• BorderLayout, GridLayout, CardLayout,
FlowLayout, GridBagLayout– Last one pain to do by hand
• Use JPanels to embed one in another• setPreferredSize()• Tip: draw out on paper first
Images (I)
• http://java.sun.com/docs/books/tutorial/uiswing/painting/usingImages.html
• Toolkit.getDefaultToolkit().loadImage(…)• Create a MediaTracker to wait for image to
load• Caching images: Java or you?• Drawing images: g.drawImage(…)
– Override paint method in the class
Images (II)
• Image transparency– Needed for object-on-tile– Use Photoshop or even the GIMP to edit
images– We linked to a set on the webboard– May release our modifications/subset
• Consider laying out tiles in a GridLayout
Images (III)
• Alternative image construct: ImageIcon
• Can embed in a JLabel
• Useful for buttons and other places where you don’t have access to Graphics context
• More awkward for actual game board
JTables
• Capable of showing complex data constructs fairly easily
• Set up a data model behind the table• Extend AbstractTableModel
– Specify the number of rows and columns– Specify what data is in each cell– Let the JTable do the rest
• JLists are similar: AbstractListModel• Can use Default{Table,List}Model: less useful
Actions
• JButton– addActionListener(new ActionListener()…)
• Keyboard– addKeyListener(new KeyAdapter()…)
– KeyEvent lets you check for most any key plus modifiers
• Right-click– addMouseListener(new MouseAdapter()…)
– Uses button masks (1.4 supports wheel!)
Miscellany
• JMenu/JMenuBar for menus– JPopupMenu – the name implies it all
• repaint(), revalidate()• JScrollPane to support scrolling of large areas
– Grid, perhaps? – Jsp.getViewport().setViewPosition(…) to force the
scrollpane around– Ideally, have it “follow” the player– Really necessary for JTables– http://java.sun.com/docs/books/tutorial/uiswing/componen
ts/scrollpane.html
Demos!
• JDK 1.3.1 demos– SwingSet: shows you all that’s out there– SampleTree– Only problem: these are large examples
Running Swing on CUNIX• Don’t• Why not?
– CUNIX is an old version of Solaris: 5.5.1 (SunOS 2.5.1), the latest version is 8 (SunOS 2.8)
• Double-versioning? Yes
– Apparently, AWT problems with JDK 1.3 and Solaris 5.5.1
– They’ve developed a horrible remote hack, but it doesn’t work properly
• Solutions: – if in 251, use local machine (xterm)
– if at home, download the JDK: it’s much faster anyway
– if you must use CUNIX, can try newcpunix.cc.columbia.edu
Sidebar: Collaborative Virtual Environments (CVE’s)
• Software development, if not done physically in teams, is a tricky proposition
• In fact, any work is a tricky proposition• Would like to see who else is working on a
project• Would like to see relation of data to each
other, and to people• 3D optimizes visual perception of data
Challenge
• How to present data in 3D in a meaningful way?
• Video conferencing?– Uhh, not quite– Phil sez: “Brady Bunch Model”
• Virtual “environments”– Avatars– Environment
• Traditionally static
CVE’s problem domains
• Web: why not look at it in 3D?– VRML – but it flopped: too frustrating– One of my startup ideas: from which our
Thursday speaker is coming
• Military simulations– Actually, already being used here
• Distributed software development– CHIME (interested?)
Databases: Overview
• One of the most popular and oldest computer applications
• A way of organizing data– File system is a “database” of sorts– Built off manual filing by clerks– Founded off 1890 census inventions
• Military and Social Security pushed dev– Social Security, 1935 (26 million records)
History
• http://www.nap.edu/readingroom/books/far/ch6.html
• 1950s: Notion of database as a separate entity from hardware, e.g. a database “system”
• 1960: COBOL established• 1968: IBM’s IMS for Apollo project• 1971: Codasyl (Conference on Data Systems
Languages) model
IMS and Codasyl
• IMS is/was a hierarchical database– Data has parents, children, siblings
– Move through a tree-like structure
• Codasyl model: “Network Data Model (NDM)”– Essentially, pointers between linked lists
– http://coronet.iicm.edu/Dbase1/courses/netdb/nur_html/ndm1.htm
• “The Programmer as Navigator”, Bachman, et. al., 1973
Rise of the Relational Model
• Ted Codd, at IBM
• “A Relational Model of Data for Large Shared Data Banks”, 1970
• Data independent of storage
• Queries are non-procedural and specified against the entire data set
• Not an immediately successful idea…
Relational Model Controversy• IBM had massive investments in IMS
– “Sole strategic product” == Codd is evil
• Codd was at IBM San Jose– Supposed to be building disk drives, not coming
up with new software paradigms– http://www.nap.edu/readingroom/books/far/ch6.ht
ml
• 10 years pass– 1973-9: Ingres at Berkeley with NSF/mil funding
• Open source success story!
– 1974-9: IBM develops System R SQL
Modern Databases
• Most everybody comes from Ingres– Oracle, Sybase, Informix
• SQL first commercially released by Oracle– Despite having been developed by IBM, they
blew the commercial market
• 1980: First relational database from IBM
• Ingres lives on: first postgres, then postgresql
Relational database fundamentals
• Data is stored as rows (records) in tables• Tables have columns (fields)• Here’s our current employee database:
• Set of tables organized into database
Name Address ID # Salary
Phil 118th St 3456 15000
Janak Long Island 5678 120000
SQL is Easy: Four Commands
• Select, Insert, Update, and Delete– “where” clauses can get tricky, though
• Select * from employee where salary > 20000• Insert into employee values(‘Suhit’,
‘Roosevelt Island’, 1010, 60000)• Update employee set salary = 120000 where
name = ‘Phil’• Delete from employee where id=1010
Manipulating databases
• Can use a front-end, like Access– Access has its own backend (the Jet database
engine) or can use a SQL backend
• Can programmatically work with a database– ODBC (Open Database Connectivity)– JDBC (Java Database Connectivity)– About as hard to work with as LDAP, more or
less
Theoretically Clean• All operations are on tables
• All return values are “rowsets”
• Query is actually sent as ASCII over the wire– Best strategy to answer is computed by database– Better than many traditional database mechanisms, which
actually move the whole database around (*cough*Access/Jet*cough*)
• Structure of database also stored in “system” tables
• There exists a Table of Tables, of course
Joins
• Why are databases relational?• Relate two tables based on common data column• Table with author-ID, author-full-name• Table with paper-title, date, author-ID• Print out paper-title, author-full-name• Normalized: author changes name, only gets
changed once• Beware Social Security Numbers!
Who cares about databases?
• Software Engineering deals with large-scale systems
• Virtually all large-scale systems have a database component
• Often the centerpiece of a system– And an organization
• Also, DBAs have the highest salaries in the IT field
• Hey, look at Larry Ellison
Remember IMS?
• Remind you of anything?• Anything else?• Everything comes back in style• We all thought IMS was dead, right?
– IMS serves 200 million end users, managing over 15 billion Gigabytes of production data and processing over 50 billion transactions every day.
– One customer reports 3000 days uptime– Legacy code really is out there
Future of databases?
• Object-oriented DBMS’s (OODBMS)– Why not just store objects in a database?
– Persistent stores
– Numerous companies out there doing this
– Java can serialize to a database as well
• Combine: Object-Relational DBMS (ORDBMS)– Relational model good for joins, etc., more so than
object-oriented models
• Take the Advanced DB class…
Languages
• Easily too much to cover in ~ two classes• We’ll focus on the fundamental differences
between Java and C/C++• Give you a start for later courses• Big hint: HW4 will probably include a small C/C+
+ program• Really don’t have time to cover Perl, Python, etc.• Eventual goal: you should be able to abstract the
language away
Hello, World in C
#include <stdio.h>int main(void) {
printf(“Hello, world!”);
}
• OK, how much of the above is C, the language?
• cpp, libc
C compilers are stupid (or simple)
• C compilers cannot auto-compile dependencies• Couldn’t find run-time libraries• #include is precisely literal• Compiles to native code
– No interpreter! Very fast and small!– No garbage collection
• Compiles top-down: need prototypes• Linking: “object code” statically or dynamically
linked to each other in special process
C for the Java programmer
• Java “ripped off” C– Java widely considered “C with classes”– More like C than C++
• for/while, if-then-else, switch (broken) all adopted perfectly from C
• Operators, ++/--, etc.• Functions very similar to methods• But no objects!
C’s data types
• Similar to Java’s lower-case types– char, int, short, long, single, double– no boolean – use 0 or 1
• Common practice: #define TRUE 1
• C is not strongly typed– int i = ‘c’;– As a matter of fact, chars are just bytes
• Different structures have different sizes• Formal mechanism for references: pointers
– Address of structure in machine’s memory!