introduction to sun java db - campus kalvskinnetaitel.hist.no/fag/_sdp/sun/javadb-hist07.pdf ·...
TRANSCRIPT
Sun Confidential: Internal Only 2
Agenda
• Sun Microsystems, Trondheim• Introduction to Java DB• Features• Configurations• Demos• Open-Source Community (Apache Derby)• Database Performance• Q & A
Sun Microsystems,Trondheim
Sun Confidential: Internal Only 4
Suns utviklingsavdeling i Trondheim
● En del av software-divisjonen● Database Center of Excellence● Flere produkter: HADB (Clustra), Java DB (Apache
Derby), PostgreSQL, memcached● 46 ansatte, flesteparten utdannet ved NTNU (hvorav
9 med doktorgrad)
Sun Confidential: Internal Only 5
Internasjonalt miljø
• Trondheim, Bangalore, California• Engelsk• Samarbeid• Åpen
kildekode• Software -
global natur• Kultur
Sun Confidential: Internal Only 6
Programmering
• C/C++• Java SE• Java EE• Databaser• Åpen
kildekode• Dyp
kompetanse
Sun Confidential: Internal Only 7
Infrastruktur og Kvalitet• Lab Engineering• Quality Engineering,
testutvikling• Quality Assurance,
generelt kvalitetsarbeid• Release Engineering,
leveranser
Java DB – Introduction
Sun Confidential: Internal Only 9
What is ?
• The database for Java• Sun's supported distribution of Apache Derby> Same source> Same binaries> Sun-supported
• Bundled in Sun JDK 6• Open source database technology• Derby is a sub-project of the Apache DB Project
Sun Confidential: Internal Only 10
Main Characteristics
• Complete relational database engine• Embeddable and client/server database• Easy to use, zero maintenance• Small footprint (2MB)• Standards-based (JDBC, SQL92/99/2003)• Compact, secure, mature and robust• Pure Java (write once, run anywhere)
Sun Confidential: Internal Only 11
Java DB History
• 1996: Cloudscape founded – Release 1.0 97'• 1999: Cloudscape acquired by Informix• 2001: DB part of Informix acquired by IBM • 2004: IBM donated Cloudscape to Apache as Derby• Early 2005: Sun starts contributing to Apache Derby• July 2005: Derby graduated from Apache Incubator• December 2005: Sun announces Java DB• December 2006: Java DB bundled in Sun JDK 6• Current release: 10.3.1 (August 2007)
Sun Confidential: Internal Only 12
Java DB in Sun Products• Java DB is used by> Java Enterprise System> Java System Application Server (incl. Glassfish)> Java System Portal Server and > Service Registry
• Java DB is supported by Netbeans
• Sun offers support for Java DB http://developers.sun.com/javadb/support/
• Bundled in Sun JDK 6
• Available standalone at:http://developers.sun.com/javadb/downloads/
Java DB – Features
Sun Confidential: Internal Only 14
Pure Java
• Database code written in Java• Write Once Run Anywhere> Requires a J2SE 1.4, J2SE 5.0, or Java SE 6 virtual
machine> Any hardware, any operating system, any vendor
• Single binary runs everywhere> Solaris, Solaris x86, Linux, FreeBSD, Windows, MacOs,
AIX, Z/OS, AS400, OS/390, …
• Database on-disk format is platform independent, too!
Sun Confidential: Internal Only 15
Small Footprint (Compact)• Engine jar file is around 2MB> Optional Jar files
– Network server ~150k– Tools ~200k
• Runtime memory use> Dependent on application, data caching etc.> Can run when Java heap memory restricted to 4MB> Have run in machines with only 16MB physical memory
• Engine jar can be compressed down to ~600K for faster download (Java 5 Pack200)http://blogs.sun.com/roller/page/FrancoisOrsini/20060118
Sun Confidential: Internal Only 16
Complete Relational Engine• Multi-user, transactions, isolation levels, deadlock
detection, crash recovery• SQL> Tables, indexes, views, triggers, procedures, functions> Foreign keys and check constraints> Joins, cost based optimizer
• Data caching, statement caching, write ahead logging, group commit• Online backup/restore• Database encryption
Sun Confidential: Internal Only 17
Java Stored Procedures/Functions
• SQL Standard part 13• To call back into the DB engine, use Standard SQL
connection URL: jdbc:default:connection• May call external Java functions from SQL.
Example:CREATE FUNCTION COS(A DOUBLE) RETURNS DOUBLE
LANGUAGE JAVA PARAMETER STYLE JAVANO SQL EXTERNAL NAME ‘java.lang.Math.cos’
ij> VALUES COS(2.1);1-----------------------0.50484610459985761 row selected
Sun Confidential: Internal Only 18
Security
• On-disk database encryption• Built-in, LDAP, NIS+ and pluggable authentication> Support for various network authentication mechanisms> Authentication provider interface
• Support for strong network client authentication> Derby network client driver
• ANSI grant/revoke privileges support• Java Security Manager enabled by default• SSL / TLS for encryption between client and server
Sun Confidential: Internal Only 19
Standards Based
• SQL> SQL92, SQL99, SQL2003, SQL/XML, …
• Java> J2SE 1.3, 1.4, 5.0, Java SE 6> Java EE> JDBC 2.0 & 3.0 (4.0 as part of Java DB 10.2.2)> Java ME CDC (JSR 169) (JDBC for CDC)
• DRDA V3> OpenGroup (http://www.opengroup.org/)
Java DB – Configurations
Sun Confidential: Internal Only 21
Embedded Java DB
Java Virtual Machine
Java DB
JDBC
Application orApp/Web Server
• Database only accessible from a single JVM• Startup & shutdown
controlled by application• Just one JAR file• Invisible to the user• Easy to use• Zero administration• FastDatabase(s)
on disk
Sun Confidential: Internal Only 22
Starting an Embedded Java DB
• No specific start-up code!• Loading the JDBC driver starts the embedded
engine• Making a connection request to the database starts
that database, if it was not already running
Sun Confidential: Internal Only 23
Start Up CodeString driverClassName =
“org.apache.derby.jdbc.EmbeddedDriver”;
String databaseURL = “jdbc:derby:dbName”;
// Load the JDBC Driver
Class.forName(driverClassName);
// Open a connection to the database
Connection conn =
DriverManager.getConnection(databaseURL);
Sun Confidential: Internal Only 24
JDBC Driver URL
• Format:jdbc:derby:[database][;attribute=value]*
• Attributes: user, password, create, databaseName, logDevice, territory, collation, encryption options, recovery options
• To create a new database, connect with URL:jdbc:derby:dbName;create=true
• Attributes can also be passed in the Properties parameter of DriverManager.getConnection methods.
Sun Confidential: Internal Only 25
Shutting Down an Embedded DB• Do nothing – exiting VM will stop Java DB> Recovery will be run on next start
• Shut down a single database> Make a connection request to the database with URL:
jdbc:derby:dbName;shutdown=true
• Shut down all databases and the engine> Make a connection request without a database name:
jdbc:derby:;shutdown=true
• Note: A connection request for shutdown will throw an exception.
Sun Confidential: Internal Only 26
• Network Server uses embedded driver against Java DB• Standard protocol
(DRDA). May use drivers from other vendors.• Scripts provided to start
and stop a Network Server.
Client/Server
Java DB
Database(s)on disk
NetworkServer
Java VM
AppJDBC
DRDA
JDBC
AppJDBC
Sun Confidential: Internal Only 27
Avoid Network Server Security Risks
• Enable user authentication• Run the network server with the Java 2 Security
Manager enabled (default in 10.3)> Procedures and functions will have no permissions> Application code can be granted permissions
• If Internet access is not needed, ensure your firewall blocks the network server port• May use SSL / TLS for encryption between client
and server
Sun Confidential: Internal Only 28
• Provides access to database from outside the application's VM.• Adds DB reporting and
debugging capabilities to stand-alone application• No code changes to
application. Enabled by setting property derby.drda.startNetworkServer
Embedded Network Server
Java DB
Database(s)on disk
NetworkServer
Java VM
AppJDBC
DRDA
JDBC
App
Sun Confidential: Internal Only 29
Read only DB-in-a-jar (or zip)
Java DB
Generate DBapplication
Embedded JDBC Driver
Java DB
Use DBapplication
Embedded JDBC Driver
jar cvf db.jar foobar
Sun Confidential: Internal Only 30
DB-on-a-stick
Java DB
Application
Embedded JDBC Driver
Sun Confidential: Internal Only 31
DB in a Browser
Browser
Ajax
Applet
• Small enough to fit in a browser• Fast enough for interactive
use• See demo at
http://developers.sun.com/javadb/
Java DB
Embedded JDBC Driver
Sun Confidential: Internal Only 32
Tools
• ij – Interactive SQL/Scripting tool> JDBC neutral, can be used against other JDBC drivers
• dblook – schema extraction tool for Java DB> Generates the DDL to be used to recreate database
schema• sysinfo – Java DB version information> Output useful for bug reporting in Jira
• Third party GUI tool> SQuirreL
Sun Confidential: Internal Only 33
No separate SQL virtual machine
• SQL compiled into Java byte-code• Run on standard Java VM
> Pro: Fast. Utilizes JIT compiler> Con: Compilation + class-loading
SQL BytecodeMachine
instructions
HotSpot compilerQuery Parser & Compiler
Sun Confidential: Internal Only 34
Pluggable Storage Architecture
EmbeddedDriver / NetworkServer
Optional configurable encryption layer using JCE
FileSystem Zip/Jar HTTP? ...Memory
Database Engine
Java DB – Community
Sun Confidential: Internal Only 36
Apache Derby Community
• Apache Software License v2.0• Anyone can contribute• Active contributors become committers through
community vote.• Apache Derby community is> growing at fast pace> a very active one> a great place to learn more about database internals
Sun Confidential: Internal Only 37
Current GA 10.3.1 Release Features
• Security improvements> DBA Powers> Secure Server by Default> SSL / TLS between client and server
• Language Based Ordering (Collation)• Alter Table Enhancements (drop/rename column)• More Performance Improvements• BLOB / CLOB Enhancements• More info at:> http://wiki.apache.org/db-derby/DerbyTenThreeRelease
Sun Confidential: Internal Only 38
Working on Next Release (10.4)
• SQL Roles• System privileges> Restrict who can shutdown engines and create
databases
• SQL OLAP functionality> e.g., ROW_NUMBER()
• Unique constraints on nullable columns• Basic replication for high availability• VTI (Table Functions)• JMX management interface
Sun Confidential: Internal Only 39
Participate!
• http://db.apache.org/derby> Download, read docs
• JIRA http://issues.apache.org/jira/browse/DERBY> Report bugs, submit patches
• [email protected]> Discuss experience, get help, give feedback
• [email protected]> Discuss developer issues
Sun Confidential: Internal Only 40
Derby Integration• ActiveMQ
• AntHill Pro
• Apache Cocoon
• Apache Geronimo
• Apache JDO
• Apache Xalan
• Daffodil Replicator
• Data Direct SequeLink
• DB Visual Architect
• Drone IRC Bot
• Eclipse
• Glassfish
• Hibernate
• IBM Cloudscape
• IBM DB2 Everyplace
• IBM DB2 JDBC Universal Driver
• IBM WebSphere App Server
• ISQL-Viewer
• Java DB
• JBoss
• JPOX
• Jython
• Kodo 3.3.3
• Maven
• Netbeans
• Zimbra
• Red Hat Application Server
• Roller 2.0
• Sequoia (C-JDBC)
• SQuirreL SQL
• Sun Java ES
• Sun Java Portal Server
• Sun Java Studio
• Sun Java EE
• Sun Service Registry
• SUSE Linux 9.3
• Zend core for IBM
• Tomcat
Sun Confidential: Internal Only 41
References
• TaxDemo:> http://developers.sun.com/javadb/overview/product_tour/readme.jsp
• Netbeans Demo:> http://www.netbeans.org/kb/55/derby-demo.html