Your SlideShare is downloading. ×
0
High Performance Jdbc
High Performance Jdbc
High Performance Jdbc
High Performance Jdbc
High Performance Jdbc
High Performance Jdbc
High Performance Jdbc
High Performance Jdbc
High Performance Jdbc
High Performance Jdbc
High Performance Jdbc
High Performance Jdbc
High Performance Jdbc
High Performance Jdbc
High Performance Jdbc
High Performance Jdbc
High Performance Jdbc
High Performance Jdbc
High Performance Jdbc
High Performance Jdbc
High Performance Jdbc
High Performance Jdbc
High Performance Jdbc
High Performance Jdbc
High Performance Jdbc
High Performance Jdbc
High Performance Jdbc
High Performance Jdbc
High Performance Jdbc
High Performance Jdbc
High Performance Jdbc
High Performance Jdbc
High Performance Jdbc
High Performance Jdbc
High Performance Jdbc
High Performance Jdbc
High Performance Jdbc
High Performance Jdbc
High Performance Jdbc
High Performance Jdbc
High Performance Jdbc
High Performance Jdbc
High Performance Jdbc
High Performance Jdbc
High Performance Jdbc
High Performance Jdbc
High Performance Jdbc
High Performance Jdbc
High Performance Jdbc
High Performance Jdbc
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

High Performance Jdbc

2,615

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
2,615
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
57
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. High Performance JDBC Jorg Janke Consultant and Coach [email_address]
  • 2. Agenda <ul><li>What I do </li></ul><ul><li>Persistence </li></ul><ul><li>Performance </li></ul><ul><li>JDBC </li></ul><ul><ul><li>Connection </li></ul></ul><ul><ul><li>Query </li></ul></ul><ul><ul><li>Result </li></ul></ul>Timing Statistics
  • 3. Shameless Self-Promotion <ul><li>Consultant & Coach (available) </li></ul><ul><li>I talk business </li></ul><ul><ul><li>Trained Accountant, MBA </li></ul></ul><ul><ul><li>VP Product Marketing </li></ul></ul><ul><li>I talk tech </li></ul><ul><ul><li>Started programming PL/I, SmallTalk, Oracle5 </li></ul></ul><ul><ul><li>Director in Oracle Apps Development </li></ul></ul><ul><ul><li>Certified Oracle DBA, Sun Java Pr/Dev/Arch </li></ul></ul>
  • 4. Compiere <ul><li>The Open Source Business Solution </li></ul><ul><ul><li>More than 240.000 downloads </li></ul></ul><ul><ul><li>Usually among Top 10 in SourceForce </li></ul></ul><ul><li>Targeting Small-Medium Enterprise </li></ul><ul><ul><li>ASP Solution </li></ul></ul><ul><ul><li>Accounting, Inventory, … </li></ul></ul><ul><ul><li>Worldwide (Language, Law, …) </li></ul></ul><ul><li>J2EE compliant Application </li></ul><ul><ul><li>Swing or HTML interface </li></ul></ul>
  • 5. Agenda -- Persistence <ul><li>What I do </li></ul><ul><li>Persistence </li></ul><ul><li>Performance </li></ul><ul><li>JDBC </li></ul><ul><ul><li>Connection </li></ul></ul><ul><ul><li>Query </li></ul></ul><ul><ul><li>Result </li></ul></ul>
  • 6. Persistence <ul><li>Object meets Database </li></ul><ul><ul><li>Put a square in a round </li></ul></ul><ul><li>JDBC is not a Persistence Framework </li></ul><ul><li>Object-relational Mapping </li></ul><ul><ul><li>Container Managed Persistence </li></ul></ul><ul><ul><li>Java Data Objects </li></ul></ul>
  • 7. Persistence – Entity Bean CMP <enterprise-beans> <entity> <description>Models a music CD</description> <ejb-name>CDBean</ejb-name> <home>com.web_tomorrow.cd.CDHome</home> <remote>com.web_tomorrow.cd.CD</remote> <ejb-class>com.web_tomorrow.cd.CDBean</ejb-class> <persistence-type>Container</persistence-type> <prim-key-class> java.lang.String </prim-key-class> <reentrant>False</reentrant> <cmp-field><field-name> id </field-name></cmp-field> <cmp-field><field-name> title </field-name></cmp-field> <cmp-field><field-name> artist </field-name></cmp-field> <primkey-field> id </primkey-field> </entity> </entity-beans>
  • 8. Persistence – JDO <ul><li>Java Data Objects </li></ul><ul><ul><li>Transparent database access </li></ul></ul><ul><ul><li>Code that accesses the underlying data store, without using database-specific code </li></ul></ul><ul><li>Use of JDO in J2EE </li></ul><ul><ul><li>Persistent helper classes for Session Beans </li></ul></ul><ul><ul><li>Delegate classes for Bean or Container Managed Persistence Entity Beans </li></ul></ul>
  • 9. JDBC Based Frameworks <ul><li>Everyone (… and their Grandmother) writes JDBC based Persistence Libraries </li></ul><ul><ul><li>Free or Commercial </li></ul></ul><ul><ul><li>Often with IDE integration </li></ul></ul><ul><ul><li>Examples </li></ul></ul><ul><ul><ul><li>Borland </li></ul></ul></ul><ul><ul><ul><li>Oracle </li></ul></ul></ul><ul><ul><ul><li>Compiere (no IDE) </li></ul></ul></ul>30 % of typical IT project: DB programming & persistence mgt
  • 10. Agenda -- Performance <ul><li>What I do </li></ul><ul><li>Persistence </li></ul><ul><li>Performance </li></ul><ul><li>JDBC </li></ul><ul><ul><li>Connection </li></ul></ul><ul><ul><li>Query </li></ul></ul><ul><ul><li>Result </li></ul></ul>
  • 11. Performance <ul><li>Is a side effect of good OO design </li></ul><ul><ul><li>Schema should be ≥ 3 rd Normal Form </li></ul></ul><ul><ul><li>That is want Optimizers recognize </li></ul></ul><ul><li>For high-end databases (e.g. Oracle) there is no need for de-normalization </li></ul><ul><li>Performance Rules </li></ul><ul><ul><li>#1 Clean design </li></ul></ul><ul><ul><li>#2 Tweak performance </li></ul></ul>Don’t Design for Performance
  • 12. Performance Rules <ul><li>Tune the Design </li></ul><ul><li>Tune the Application </li></ul><ul><li>Tune the OS </li></ul><ul><li>Tune Memory Structure </li></ul><ul><li>Tune Disk I/O Usage </li></ul><ul><li>Detect and Eliminate Resource Contention </li></ul>
  • 13. Performance Design Options <ul><li>Data Intensive Routines in DB Server </li></ul><ul><ul><li>Within DB Engine - Low Switching Cost </li></ul></ul><ul><ul><li>No Communication Overhead </li></ul></ul><ul><ul><li>PL/SQL, Java Stored Procedures, C++, … </li></ul></ul><ul><li>“Automatic” data consistency (Helps the Optimizer) </li></ul><ul><ul><li>Explicit Constraints </li></ul></ul><ul><ul><li>Trigger (in PL/SQL, Java, …) </li></ul></ul>
  • 14. DB Programming Options <ul><li>Set Processing outperforms everything else </li></ul><ul><ul><li>Not your beginner SQL </li></ul></ul><ul><ul><ul><li>Complex UPDATE statements </li></ul></ul></ul><ul><li>PL/SQL </li></ul><ul><ul><li>Dependency Management (*) </li></ul></ul><ul><ul><li>Data intensive manipulations </li></ul></ul><ul><li>Java Stored Procedures </li></ul><ul><ul><li>Special VMs – Upload, Debugging </li></ul></ul><ul><ul><li>Special JDBC Driver “always connected” </li></ul></ul>
  • 15. DB Programming Options <ul><li>SQLJ </li></ul><ul><ul><li>Java Language SQL Pre-compiler </li></ul></ul><ul><ul><li>High level SQLJ-Language </li></ul></ul><ul><ul><li>Converted to “normal” JDBC code </li></ul></ul><ul><ul><li>Supported by IBM, Oracle, … </li></ul></ul>
  • 16. Question: Is SQL a Standard?
  • 17. DB Independence <ul><li>Lowest common denominator </li></ul><ul><ul><li>Use Access Functionality with Oracle ? </li></ul></ul><ul><li>You have to design & program differently for the database / camps </li></ul><ul><ul><li>Oracle, DB2, (PostgreSQL), … </li></ul></ul><ul><ul><li>Microsoft SQL Server, Sybase, … </li></ul></ul><ul><ul><li>MS Access, mySQL, … </li></ul></ul>
  • 18. DB Incompatibilities (1) <ul><li>SQL join </li></ul><ul><ul><li>SELECT .. FROM a JOIN b ON (a.id=b.id); </li></ul></ul><ul><ul><li>SELECT .. FROM a LEFT OUTER JOIN b ON (a.id=b.id); </li></ul></ul><ul><ul><li>SELECT .. FROM a, b WHERE a.id=b.id(+); </li></ul></ul><ul><ul><li>SELECT .. FROM a, b WHERE a.id=*b.id; </li></ul></ul><ul><li>Sub-Query </li></ul><ul><ul><li>SELECT .. FROM a, (SELECT .. FROM b) AS b WHERE … </li></ul></ul><ul><li>Pseudo-Columns </li></ul><ul><ul><li>ROWNUM, SysDate </li></ul></ul><ul><ul><li>LIMIT </li></ul></ul><ul><li>Reserved Words – Optional Syntax – Alias </li></ul>
  • 19. DB Incompatibilities (2) <ul><li>Data Types </li></ul><ul><ul><li>Not just naming (NUMBER vs. DECIMAL) </li></ul></ul><ul><ul><li>BLOB, CLOB, … </li></ul></ul><ul><li>PL/SQL - Syntax/Functionality for Packages, Functions, Procedures, Triggers, … </li></ul><ul><ul><li>Commit Strategy </li></ul></ul><ul><ul><li>Exception (raise & catch) </li></ul></ul><ul><li>Data Dictionary </li></ul><ul><li>OLAP Support </li></ul><ul><ul><li>Materialized Views, … </li></ul></ul>
  • 20. DB Independence – cont. <ul><li>DB Management Layer </li></ul><ul><ul><li>Lowest Common SQL Denominator Alternative </li></ul></ul><ul><ul><li>Application Dependent </li></ul></ul><ul><ul><ul><li>Uses Database specific Functionality </li></ul></ul></ul><ul><ul><li>Examples: </li></ul></ul><ul><ul><ul><li>SAP’s DB Access Layer </li></ul></ul></ul><ul><ul><ul><li>(CMP Products) </li></ul></ul></ul><ul><ul><ul><li>Compiere’s dbPort </li></ul></ul></ul><ul><ul><ul><li>… </li></ul></ul></ul>Oracle PG dbPort Application I am talking to Oracle DB/2 ?
  • 21. Performance Reality <ul><li>You can’t have everything </li></ul><ul><ul><li>High functionality & Ability to fine-tune </li></ul></ul><ul><ul><li>Database independence </li></ul></ul><ul><ul><ul><li>Automatic Object Mapping </li></ul></ul></ul><ul><li>You need skill-mix </li></ul><ul><ul><li>(Traditional) Database Design </li></ul></ul><ul><ul><li>Database Programming Environment </li></ul></ul><ul><ul><li>Object Design </li></ul></ul><ul><ul><li>Java Programming Environment </li></ul></ul>
  • 22. The Test Environment <ul><li>Windows 2000 SP 2 Server </li></ul><ul><ul><li>Dual 450MHz CPU </li></ul></ul><ul><ul><li>Oracle 8.1.7 (parallel option not enabled) </li></ul></ul><ul><ul><li>JDBC driver for 9i </li></ul></ul><ul><li>RedHat Linux 7.2 </li></ul><ul><ul><li>Single 500 MHz CPU </li></ul></ul><ul><ul><li>PostgreSQL 7.1.3 </li></ul></ul><ul><ul><li>JDBC driver for 7.2 </li></ul></ul><ul><li>Java 1.4.0 </li></ul><ul><li>SELECT * FROM AD_Column; </li></ul><ul><ul><li>4,800 Rows - 38 Columns – ca. 1,2 MB </li></ul></ul>Testing DB Driver
  • 23. Agenda -- JDBC <ul><li>What I do </li></ul><ul><li>Persistence </li></ul><ul><li>Performance </li></ul><ul><li>JDBC </li></ul><ul><ul><li>Connection </li></ul></ul><ul><ul><li>Query </li></ul></ul><ul><ul><li>Result </li></ul></ul>
  • 24. Connecting <ul><li>Connection Options </li></ul><ul><ul><li>java.sql.Driver & java.sql.DriverManager </li></ul></ul><ul><ul><li>javax.sql.DataSource </li></ul></ul><ul><ul><li>javax.sql.PooledConnection </li></ul></ul><ul><ul><li>Connection Cache </li></ul></ul>
  • 25. JDBC Driver Types Type 4 Pure Java Type 3 Type 1 Type 2
  • 26. Connecting .. Driver <ul><li>Type 1..4 Driver </li></ul><ul><ul><li>Type 4: Pure Java Driver </li></ul></ul><ul><ul><li>DB/2 does not provide Type 4 driver </li></ul></ul><ul><li>Interface java.sql.Driver </li></ul><ul><ul><li>Explicitly </li></ul></ul><ul><ul><ul><li>Class.forName(“org.postgresql.Driver&quot;); </li></ul></ul></ul><ul><ul><ul><li>new oracle.jdbc.OracleDriver(); </li></ul></ul></ul><ul><ul><li>System Properties </li></ul></ul><ul><ul><ul><li>jdbc.drivers= oracle.jdbc.OracleDriver:org.postgresql.Driver </li></ul></ul></ul>
  • 27. Connecting DriverManager <ul><li>Basic service for managing a set of JDBC drivers </li></ul><ul><li>JDBC Drivers register with the DriverManager </li></ul><ul><li>Source </li></ul><ul><ul><li>Connection c = DriverManager.getConnection (&quot;jdbc:oracle:thin:@dev:1521:dev1&quot;); </li></ul></ul><ul><li>Connection Strings </li></ul><ul><ul><li>jdbc:oracle:oci8:@ -- (#1) Bequeath </li></ul></ul><ul><ul><li>jdbc:oracle:oci8:@ora -- (#3) Net8 </li></ul></ul><ul><ul><li>jdbc:oracle:thin:@dev:1521:ora -- (#2) Type 4 </li></ul></ul><ul><ul><li>jdbc:postgresql://dev:5432/compiere </li></ul></ul>
  • 28. Connecting .. Data Source <ul><li>Interface javax.sql.DataSource </li></ul><ul><ul><li>Alternative to DriverManager </li></ul></ul><ul><ul><li>Based on JNDI </li></ul></ul><ul><li>Server Source </li></ul><ul><ul><li>DataSource ds = new OracleDataSource(); Context ctx = new Initial Context(); ctx.bind (“jdbc/myDB”, ds); </li></ul></ul><ul><li>Client Source </li></ul><ul><ul><li>Context ctx = new Initial Context(); DataSource ds = (DataSource)ctx.lookup(“jdbc/myDB”); Connection c = ds.getConnection(); </li></ul></ul>
  • 29. Connection .. Pool <ul><li>Optional extension </li></ul><ul><li>One Physical Connection </li></ul><ul><li>Multiple Logical Connection </li></ul><ul><ul><li>Connection.close() makes it available </li></ul></ul><ul><li>Eliminates overhead of creating physical connection: </li></ul><ul><ul><li>Connection c = pool.getConnection(); Statement stmt = c.createStatement(..); stmt.close(); c.close(); </li></ul></ul>
  • 30. Connection .. Cache <ul><li>Optional Extension … no standard (!) </li></ul><ul><li>Multiple Physical Connections </li></ul><ul><li>We wrote own Connection Cache </li></ul><ul><ul><li>Connection not closed in code </li></ul></ul>
  • 31. Multi-Thread <ul><li>Most JDBC implementations synchronize on Connection </li></ul><ul><ul><li>You need multiple connections for multi-threaded applications </li></ul></ul><ul><li>Compiere uses </li></ul><ul><ul><li>2 “read-only” never closed Cached Connections (w. health check) </li></ul></ul><ul><ul><li>1 “update” never closed Connection </li></ul></ul>
  • 32. Test Results (10 Threads)
  • 33. Test Results (10 Threads) <ul><li>Multiple Pre-Created Connections </li></ul><ul><ul><li>No xxx.getConnection() </li></ul></ul><ul><ul><li>Yield ‘surprise’ </li></ul></ul><ul><ul><ul><li>while (rs.next) yield(); </li></ul></ul></ul><ul><ul><ul><li>(High) switching costs </li></ul></ul></ul><ul><ul><ul><li>Database has result in buffer </li></ul></ul></ul><ul><ul><ul><ul><li>just transmitting </li></ul></ul></ul></ul><ul><li>Connection Cache </li></ul><ul><ul><li>Optimum Cache Size 2-4 </li></ul></ul>
  • 34. Test Results <ul><li>Oracle </li></ul><ul><ul><li>Use Thin Driver </li></ul></ul><ul><ul><ul><li>jdbc:oracle:thin:@dev:1521:ora </li></ul></ul></ul><ul><ul><li>Fastest Driver – Bequeath </li></ul></ul><ul><ul><ul><li>&quot;jdbc:oracle:oci8:@“ </li></ul></ul></ul><ul><ul><ul><li>20-40% faster – Only works if only one instance installed </li></ul></ul></ul><ul><ul><ul><li>For Server Connections </li></ul></ul></ul><ul><ul><li>Slowest Driver – Net8 </li></ul></ul><ul><ul><ul><li>jdbc:oracle:oci8:@ora </li></ul></ul></ul><ul><ul><ul><li>10-20% slower </li></ul></ul></ul><ul><ul><ul><li>Net8 conversion Overhead </li></ul></ul></ul>
  • 35. Connection – Trx Level <ul><li>Transaction Isolation Level </li></ul><ul><ul><li>TRANSACTION_NONE </li></ul></ul><ul><ul><ul><li>Not supported </li></ul></ul></ul><ul><ul><li>TRANSACTION_READ_UNCOMMITTED </li></ul></ul><ul><ul><ul><li>Get: dirty, non-repeatable, phantom reads </li></ul></ul></ul><ul><ul><li>TRANSACTION_READ_COMMITTED </li></ul></ul><ul><ul><ul><li>No: dirty reads (uncommitted data) </li></ul></ul></ul><ul><ul><ul><li>Get: non-repeatable, phantom reads </li></ul></ul></ul><ul><ul><li>TRANSACTION_REPEATABLE_READ </li></ul></ul><ul><ul><ul><li>No: dirty, non-repeatable (data changed) reads </li></ul></ul></ul><ul><ul><ul><li>Get: phantom reads </li></ul></ul></ul><ul><ul><li>TRANSACTION_SERIALIZABLE </li></ul></ul><ul><ul><ul><li>No: dirty reads, non-repeatable, phantom (WHERE changed) reads </li></ul></ul></ul>
  • 36. Connection <ul><li>You probably want to get the latest data </li></ul><ul><ul><li>conn.setTransactionIsolation (Connection.TRANSACTION_READ_COMMITTED); </li></ul></ul><ul><ul><li>Data updated by others & Triggers </li></ul></ul><ul><ul><li>Set explicitly </li></ul></ul><ul><ul><ul><li>Connection is Interface </li></ul></ul></ul><ul><ul><ul><li>Default set by Vendor Implementation </li></ul></ul></ul><ul><li>Consider </li></ul><ul><ul><li>Read Only – Hint to Driver/Database </li></ul></ul><ul><ul><ul><li>conn.setReadOnly(true); </li></ul></ul></ul>
  • 37. Querying <ul><li>Statement – conn.createStatement() </li></ul><ul><ul><li>ResultSet.TYPE_ </li></ul></ul><ul><ul><ul><li>FORWARD_ONLY, SCROLL_INSENSITIVE, SCROLL_SENSITIVE </li></ul></ul></ul><ul><ul><li>ResultSet.CONCUR_ </li></ul></ul><ul><ul><ul><li>READ_ONLY or _UPDATABLE </li></ul></ul></ul><ul><li>Prepared Statement – conn.prepareStatement() </li></ul><ul><ul><li>Database dependent statement caching </li></ul></ul><ul><ul><li>“ UPDATE EMPLOYEES SET SALARY = ? WHERE ID = ?” </li></ul></ul><ul><ul><li>pstmt.setDataType (pos, value); </li></ul></ul><ul><li>Callable Statement – conn.prepareCall() </li></ul><ul><ul><li>“ {?= call myProcedure (?,?)}” </li></ul></ul><ul><li>Batch [implementation not mandatory] </li></ul><ul><ul><li>stmt.addBatch(“Insert ..”); </li></ul></ul><ul><ul><li>stmt.executeBatch(); </li></ul></ul>
  • 38. set DataType Conversion
  • 39. Result - ResultSet <ul><li>Created by stmt.executeQuery() </li></ul><ul><li>Fetch Size </li></ul><ul><ul><li>rs.setFetchSize(int); </li></ul></ul><ul><ul><li>stmt.setFetchSize(int); </li></ul></ul><ul><ul><li>VendorConnection.setFetchSize(int); </li></ul></ul><ul><ul><li>Driver hint </li></ul></ul><ul><li>Non updateable RS </li></ul><ul><ul><li>Forward only & read just once </li></ul></ul><ul><li>Data Retrieval </li></ul><ul><ul><li>get DataType (int pos); </li></ul></ul><ul><ul><li>get DataType (String columnName); </li></ul></ul><ul><ul><li>wasNull(); </li></ul></ul>No way to Cancel a Query
  • 40. get DataSet Conversion
  • 41. ResultSet <ul><li>Navigate </li></ul><ul><ul><li>absolute(int), relative(int) – first(), last(), next(), previous() </li></ul></ul><ul><li>Update </li></ul><ul><ul><li>updateDataType (pos, data); updateDataType (columnName, data); </li></ul></ul><ul><ul><li>updateRow(); – or – cancelRowUpdates(); </li></ul></ul><ul><li>Insert </li></ul><ul><ul><li>moveToInsertRow(); updateDataType insertRow(); – or – cancelRowUpdates(); </li></ul></ul><ul><ul><li>moveToCurrentRow(); </li></ul></ul><ul><li>Delete </li></ul><ul><ul><li>deleteRow(); </li></ul></ul><ul><li>Refresh </li></ul><ul><ul><li>refreshRow(); </li></ul></ul>
  • 42. Result - RowSet <ul><li>JavaBean - Extends ResultSet </li></ul><ul><li>Types – Implementation Optional </li></ul><ul><ul><li>Cached – serialized - disconnected - X-JVM - Synchronize </li></ul></ul><ul><ul><li>JDBC </li></ul></ul><ul><ul><li>Web </li></ul></ul><ul><li>Code Example </li></ul><ul><ul><li>RowSet rowset = new OracleCachedRowSet(); rowset.setUrl (CONNECTION); rowset.setUsername (UID); rowset.setPassword (PWD); rowset.setFetchSize (fetchSize); rowset. setCommand (SQL_STATEMENT); rowset. execute (); </li></ul></ul>Client … RMI … no JDBC
  • 43. Meta Data Interfaces <ul><li>DatabaseMetaData </li></ul><ul><ul><li>Driver JDBC compatibility </li></ul></ul><ul><ul><li>Data Dictionary Queries </li></ul></ul><ul><li>ParameterMetaData </li></ul><ul><ul><li>Prepared Statement </li></ul></ul><ul><li>ResultSetMetaData </li></ul><ul><ul><li>Get Column Name, Data Type of “SELECT *” query </li></ul></ul>
  • 44. Connection - Query - Retrieve First Connection, (Query) & Retrieval took significantly longer – 4,800 records
  • 45. Fetch Size
  • 46. Compiere JDBC Use <ul><li>Async worker to load data </li></ul><ul><li>Select </li></ul><ul><ul><li>Prepared Statement - Read-Only, Forward Only </li></ul></ul><ul><ul><li>Statement & ResultSet (cursor) closed after read </li></ul></ul><ul><li>Insert </li></ul><ul><ul><li>ResultSet from Prepared Statement (WHERE 1=2) </li></ul></ul><ul><ul><li>rs.moveToInsertRow(); rs.insertRow(); </li></ul></ul><ul><ul><li>Re-read from Database using PK (trigger, ..) </li></ul></ul><ul><li>Update </li></ul><ul><ul><li>Re-read using ROWID or OID (“for update”) </li></ul></ul><ul><ul><li>Check, if data* not changed </li></ul></ul><ul><ul><ul><li>rs.updateXX(); rs.updateRow(); </li></ul></ul></ul><ul><ul><ul><li>or rs.cancelRowUpdates(); </li></ul></ul></ul><ul><ul><li>Re-read from Database using PK </li></ul></ul>deterministic, optimistic locking
  • 47. Performance Hints <ul><li>Qualify Columns in SELECT Clause </li></ul><ul><ul><li>Gets only data needed </li></ul></ul><ul><li>Use position of Column – not Name </li></ul><ul><ul><li>rs.getString(1); </li></ul></ul><ul><li>Give as much info as possible </li></ul><ul><ul><li>WHERE clause </li></ul></ul><ul><ul><li>Scrollable/Updateable/… </li></ul></ul><ul><li>Use Locks carefully </li></ul><ul><ul><li>… and release them explicitly </li></ul></ul><ul><li>Close Statements & ResultSets – closes DB cursors </li></ul><ul><ul><li>rs.close(); stmt.close(); </li></ul></ul>
  • 48. Performance Hints (2) <ul><li>Use Batches where possible </li></ul><ul><li>Connection.setAutoCommit (false) </li></ul><ul><li>Database Meta-Data Queries are slow </li></ul><ul><ul><li>Quantify arguments, search patterns </li></ul></ul><ul><li>Consider Use of </li></ul><ul><ul><li>Statement.setFetchSize (int no) </li></ul></ul><ul><ul><li>Statement.setMaxRows (int no) </li></ul></ul><ul><ul><li>Statement.setQueryTimeout (int seconds) </li></ul></ul><ul><ul><li>Statement.setMaxFieldSize (int byte) </li></ul></ul><ul><ul><li>Hidden unique ID: RowID, OID </li></ul></ul><ul><ul><li>RowSet for complex mass update </li></ul></ul><ul><li>Use Prepared Statements (*) </li></ul>
  • 49. Resources (Selection) <ul><li>JDBC </li></ul><ul><ul><li>http://java.sun.com/products/jdbc </li></ul></ul><ul><ul><ul><li>Several courses and introductions </li></ul></ul></ul><ul><ul><li>http://www.jguru.com/faq/JDBC </li></ul></ul><ul><ul><li>http://www.javaskyline.com/learnjdbc.html </li></ul></ul><ul><li>JDO </li></ul><ul><ul><li>http://access1.sun.com/jdo </li></ul></ul><ul><ul><li>http://www.jdocentral.com </li></ul></ul>
  • 50. Thanks <ul><li>You can download the presentation </li></ul><ul><ul><li>http://www.compiere.org/download/ </li></ul></ul><ul><li>If you have questions </li></ul><ul><ul><li>[email_address] </li></ul></ul><ul><ul><li>(203) 445-8182 </li></ul></ul><ul><li>Have a look </li></ul><ul><ul><li>http://www.compiere.com/consulting.html </li></ul></ul>

×