Professional Documents
Culture Documents
Jorg Janke
Consultant and Coach
jorg.janke@compiere.org
Agenda
What I do
Persistence
Performance
JDBC
Connection
Query
Result
Timing Statistics
Shameless Self-Promotion
I talk tech
Compiere
Agenda -- Persistence
What I do
Persistence
Performance
JDBC
Connection
Query
Result
Persistence
Put a square
in a round
Persistence JDO
Free or Commercial
Often with IDE integration
Examples
Borland
Oracle
Compiere (no IDE)
30 % of
typical IT project:
DB programming &
persistence mgt
Agenda -- Performance
What I do
Persistence
Performance
JDBC
Connection
Query
Result
Performance
#1 Clean design
#2 Tweak performance
Performance Rules
Performance Design
Options
Explicit Constraints
Trigger (in PL/SQL, Java, )
DB Programming Options
PL/SQL
DB Programming Options
SQLJ
Question:
Is SQL a Standard?
DB Independence
DB Incompatibilities (1)
SQL join
FROM
FROM
FROM
FROM
a JOIN b ON (a.id=b.id);
a LEFT OUTER JOIN b ON (a.id=b.id);
a, b WHERE a.id=b.id(+);
a, b WHERE a.id=*b.id;
Pseudo-Columns
..
..
..
..
Sub-Query
SELECT
SELECT
SELECT
SELECT
ROWNUM, SysDate
LIMIT
DB Incompatibilities (2)
Data Types
Commit Strategy
Exception (raise & catch)
Data Dictionary
OLAP Support
Materialized Views,
DB Independence cont.
DB Management Layer
Examples:
I am
talking
to
Oracle
Application
dbPort
Oracle
PG
DB/2 ?
Performance Reality
Testing DB
Driver
Java 1.4.0
SELECT * FROM AD_Column;
Agenda -- JDBC
What I do
Persistence
Performance
JDBC
Connection
Query
Result
Connecting
Connection Options
java.sql.Driver &
java.sql.DriverManager
javax.sql.DataSource
javax.sql.PooledConnection
Connection Cache
Type 1
Type 2
Type 4
Pure
Java
Type 3
Connecting .. Driver
Interface java.sql.Driver
Explicitly
Class.forName(org.postgresql.Driver");
new oracle.jdbc.OracleDriver();
System Properties
jdbc.drivers=
oracle.jdbc.OracleDriver:org.postgresql.Driver
Connecting DriverManager
Connection c = DriverManager.getConnection
("jdbc:oracle:thin:@dev:1521:dev1");
Connection Strings
jdbc:oracle:oci8:@
-- (#1) Bequeath
jdbc:oracle:oci8:@ora
-- (#3) Net8
jdbc:oracle:thin:@dev:1521:ora
-- (#2) Type 4
jdbc:postgresql://dev:5432/compiere
Interface javax.sql.DataSource
Server Source
Alternative to DriverManager
Based on JNDI
DataSource ds = new OracleDataSource();
Context ctx = new Initial Context();
ctx.bind (jdbc/myDB, ds);
Client Source
Connection .. Pool
Optional extension
One Physical Connection
Multiple Logical Connection
Connection c = pool.getConnection();
Statement stmt = c.createStatement(..);
stmt.close();
c.close();
Connection .. Cache
Multi-Thread
Compiere uses
No xxx.getConnection()
Yield surprise
while (rs.next)
yield();
(High) switching costs
Database has result in buffer
just transmitting
Connection Cache
Test Results
Oracle
jdbc:oracle:thin:@dev:1521:ora
"jdbc:oracle:oci8:@
20-40% faster Only works if only one instance
installed
For Server Connections
jdbc:oracle:oci8:@ora
10-20% slower
Net8 conversion Overhead
TRANSACTION_NONE
TRANSACTION_READ_UNCOMMITTED
TRANSACTION_REPEATABLE_READ
TRANSACTION_READ_COMMITTED
Not supported
TRANSACTION_SERIALIZABLE
Connection
conn.setTransactionIsolation
(Connection.TRANSACTION_READ_COMMITTED
);
Data updated by others & Triggers
Set explicitly
Connection is Interface
Default set by Vendor Implementation
Consider
conn.setReadOnly(true);
Querying
Statement conn.createStatement()
ResultSet.TYPE_
ResultSet.CONCUR_
READ_ONLY or _UPDATABLE
stmt.addBatch(Insert ..);
stmt.executeBatch();
setDataType Conversion
Result - ResultSet
Created by stmt.executeQuery()
Fetch Size
Non updateable RS
rs.setFetchSize(int);
stmt.setFetchSize(int);
VendorConnection.setFetchSize(int);
Driver hint
Forward only & read just once
Data Retrieval
No way to
Cancel a
Query
getDataSet Conversion
ResultSet
Navigate
Update
moveToInsertRow();
updateDataType
insertRow(); or cancelRowUpdates();
moveToCurrentRow();
Delete
Insert
deleteRow();
Refresh
refreshRow();
Result - RowSet
Code Example
JDBC
DatabaseMetaData
ParameterMetaData
ResultSetMetaData
Fetch Size
Insert
ResultSet from Prepared Statement (WHERE 1=2)
rs.moveToInsertRow(); rs.insertRow();
rs.updateXX(); rs.updateRow();
or rs.cancelRowUpdates();
Performance Hints
WHERE clause
Scrollable/Updateable/
rs.getString(1);
rs.close(); stmt.close();
Consider Use of
Resources (Selection)
JDBC
http://java.sun.com/products/jdbc
http://www.jguru.com/faq/JDBC
http://www.javaskyline.com/learnjdbc.
html
JDO
http://access1.sun.com/jdo
http://www.jdocentral.com
Thanks
http://www.compiere.org/download/
jorg.janke@compiere.org
(203) 445-8182
Have a look
http://www.compiere.com/consulting.h
tml