Java Doc for SQLCache.java in  » RSS-RDF » Jena-2.5.5 » com » hp » hpl » jena » db » impl » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » RSS RDF » Jena 2.5.5 » com.hp.hpl.jena.db.impl 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   com.hp.hpl.jena.db.impl.SQLCache

SQLCache
public class SQLCache (Code)
Stores a set of sql statements loaded from a resource file. Caches prepared versions of the statements for a given db connection.

The resource file is located on the classpath and has the format:

 # comment at start of line
 operationName1
 sql code line 1
 ...
 sql code last line
 operationName2
 ...
 
where the blank lines delimit one sql block from the next.

The sql code is typically a single SQL statement but some operations, specifically database initialization and cleanup may require a variable number of statments. To cater for this terminate each statement in those groups with the string ";;". Note that a single ";" is not used because these compound statements are often stored procedure definitions which end to have ";" line terminators!
author:
   Dave Reynolds. Updated by hkuno to support GraphRDB.
version:
   $Revision: 1.18 $ on $Date: 2008/01/02 12:08:23 $



Field Summary
protected  booleanCACHE_PREPARED_STATEMENTS
     Set to true to enable cache of pre-prepared statements.
final protected static  intMAX_PS_CACHE
     Maximum number of pre-prepared statements to keep for each operator.
protected static  Loglogger
    
protected  Mapm_cachedStmtInUse
     Track which cached, prepared statements are in use and the corresponding list to which the statement should be returned.
protected  IDBConnectionm_connection
     the packaged jdbc connection to the database itself.
protected  Mapm_preparedStatements
     Cache of prepared versions of the statements.
protected  Propertiesm_sql
     Set of sql statements indexed by operation name.

Constructor Summary
public  SQLCache(String sqlFile, Properties defaultOps, IDBConnection connection, String idType)
     Constructor.

Method Summary
public  voidclose()
    
public static  StringconcatOpName(String opName, String attr)
    
public static  StringconcatOpName(String opName, String attrA, String attrB)
    
protected  ResultSetIteratorexecuteSQL(PreparedStatement ps, String opname, ResultSetIterator iterator)
    
public  voidflushPreparedStatementCache()
     Flush the cache of all currently prepared statements.
protected  StringgenSQLStatement(String opname)
     Return dynamically generated SQL for the specified operation.
Parameters:
  opname - the command to generate; must start with "*", the opname and then op params.
protected  StringgenSQLStmtFindReif(String op, String args)
     Return generate SQL for finding reified statements from a triple pattern.
Parameters:
  op - the command to generate.
public  booleangetCachePreparedStatements()
     Return true if cache of pre-prepared statements is enabled.
public  ConnectiongetConnection()
     Return the associated jdbc connection.
public synchronized  PreparedStatementgetPreparedSQLStatement(String opname, String[] attr)
     Return a prepared SQL statement corresponding to the named operation.
public synchronized  PreparedStatementgetPreparedSQLStatement(String opname)
    
public synchronized  PreparedStatementgetPreparedSQLStatement(String opname, String attr)
     Variant on SQLCache.getPreparedSQLStatement getPreparedSQLStatement which accesses the attribute variant correspond to the given attribute suffix.
public synchronized  PreparedStatementgetPreparedSQLStatement(String opname, String attrA, String attrB)
     Variant on SQLCache.getPreparedSQLStatement getPreparedSQLStatement which access the attribute variant correspond to the given attribute suffix.
public  StringgetSQLStatement(String opname)
     Return the raw SQL statement corresponding to the named operation.
public  StringgetSQLStatement(String opname, String[] attr)
     Return the raw SQL statement corresponding to the named operation.
public  StringgetSQLStatement(String opname, String attr)
    
public  StringgetSQLStatement(String opname, String attrA, String attrB)
     Return the raw SQL statement corresponding to the named operation.
public  CollectiongetSQLStatementGroup(String opname)
     Return a set of raw SQL statements corresponding to the named operation. This is used for compound operations where more than one SQL command is needed to implement the operation (e.g.
protected  PropertiesgetSQLTable()
     Accessor.
public static  PropertiesloadSQLFile(String sqlFile, Properties defaultOps, String idType)
     Load in a defined set of sql statements - see class comment for format. The loaded file is return as a Property table.
public static  BufferedReaderopenResourceFile(String filename)
     Open a resource file for reading.
public synchronized  PreparedStatementprepareSQLStatement(String sql)
     Return a prepared SQL statement for the given statement string. The statement should either be closed after use.

Only works for single statements, not compound statements.
Parameters:
  stmt - the sql statement to prepare.

public synchronized  voidreturnPreparedSQLStatement(PreparedStatement ps)
     Return a prepared statement to the statement pool for reuse by another caller.
public  voidrunSQLGroup(String opname, String[] attr)
     Run a group of sql statements - normally used for db formating and clean up.
public  voidrunSQLGroup(String opname)
     Run a group of sql statements - normally used for db formating and clean up.
public  voidrunSQLGroup(String opname, String attr)
     Run a group of sql statements - normally used for db formating and clean up.
public  voidrunSQLGroup(String opname, String attrA, String attrB)
     Run a group of sql statements - normally used for db formating and clean up.
public  ResultSetIteratorrunSQLQuery(String opname, Object[] args)
     Execute a named pre-prepared SQL query statement taking a set of arguments and return a set of results as an iterator (probably a subclass of ResultSetIterator.
public  ResultSetIteratorrunSQLQuery(String opname, String attr, Object[] args)
     Variant on SQLCache.runSQLQuery which access the attribute variant correspond to the given attribute suffix.
public  ResultSetIteratorrunSQLQuery(String opname, String attrA, String attrB, Object[] args)
     Variant on SQLCache.runSQLQuery which access the attribute variant correspond to the given attribute suffix.
public  ResultSetIteratorrunSQLQuery(String opname, Object[] args, ResultSetIterator iterator)
     Execute a named pre-prepared SQL query statement taking a set of arguments and return a set of results as an iterator (probably a subclass of ResultSetIterator.
public  ResultSetIteratorrunSQLQuery(String opname, String attrA, Object[] args, ResultSetIterator iterator)
     Variant on SQLCache.runSQLQuery which access the attribute variant correspond to the given attribute suffix.
public  ResultSetIteratorrunSQLQuery(String opname, String attrA, String attrB, Object[] args, ResultSetIterator iterator)
     Variant on SQLCache.runSQLQuery which access the attribute variant correspond to the given attribute suffix.
public  intrunSQLUpdate(String opname, Object[] args)
     Execute a named pre-prepared SQL update statement taking a set of arguments and returning the update count.
public  intrunSQLUpdate(String opname, String attrA, Object[] args)
     Variant on SQLCache.runSQLUpdate which access the attribute variant correspond to the given attribute suffix.
public  intrunSQLUpdate(String opname, String attrA, String attrB, Object[] args)
     Variant on SQLCache.runSQLUpdate which access the attribute variant correspond to the given attribute suffix.
public  voidsetCachePreparedStatements(boolean state)
     Set to true to enable cache of pre-prepared statements.
public  voidsetConnection(IDBConnection connection)
     Set the associated jdbc connection.
public static  Stringsubstitute(String line, String macro, String subs)
    

Field Detail
CACHE_PREPARED_STATEMENTS
protected boolean CACHE_PREPARED_STATEMENTS(Code)
Set to true to enable cache of pre-prepared statements.



MAX_PS_CACHE
final protected static int MAX_PS_CACHE(Code)
Maximum number of pre-prepared statements to keep for each operator.



logger
protected static Log logger(Code)



m_cachedStmtInUse
protected Map m_cachedStmtInUse(Code)
Track which cached, prepared statements are in use and the corresponding list to which the statement should be returned.



m_connection
protected IDBConnection m_connection(Code)
the packaged jdbc connection to the database itself.



m_preparedStatements
protected Map m_preparedStatements(Code)
Cache of prepared versions of the statements. Each map entry is a list of copies of the prepared statement for multi-threaded apps.



m_sql
protected Properties m_sql(Code)
Set of sql statements indexed by operation name.




Constructor Detail
SQLCache
public SQLCache(String sqlFile, Properties defaultOps, IDBConnection connection, String idType) throws IOException(Code)
Constructor. Creates a new cache sql statements for interfacing to a specific database.
Parameters:
  sqlFile - the name of the file of sql statements to load, this isloaded from the classpath.
Parameters:
  defaultOps - Properties table which provides the defaultsql statements, any definitions of a given operation in the loaded filewill override the default.
Parameters:
  connection - the jdbc connection to the database itself
Parameters:
  idType - the sql string to use for id types (substitutes for $id in files)




Method Detail
close
public void close() throws SQLException(Code)
Close all prepared statements



concatOpName
public static String concatOpName(String opName, String attr)(Code)
Helper function calculate op name given substitutions



concatOpName
public static String concatOpName(String opName, String attrA, String attrB)(Code)
Helper function calculate op name given substitutions



executeSQL
protected ResultSetIterator executeSQL(PreparedStatement ps, String opname, ResultSetIterator iterator) throws SQLException(Code)
Execute the given statement, return null if the statement appears to be just an update or return an iterator for the result set if the statement appears to be a query



flushPreparedStatementCache
public void flushPreparedStatementCache() throws RDFRDBException(Code)
Flush the cache of all currently prepared statements.



genSQLStatement
protected String genSQLStatement(String opname) throws SQLException(Code)
Return dynamically generated SQL for the specified operation.
Parameters:
  opname - the command to generate; must start with "*", the opname and then op params. the generated command as a String.



genSQLStmtFindReif
protected String genSQLStmtFindReif(String op, String args) throws SQLException(Code)
Return generate SQL for finding reified statements from a triple pattern.
Parameters:
  op - the command to generate. should be findReif.
Parameters:
  args - a string describing which command to generate. it has the form [N][PS|PP|PO|PT][O[C]] where N means to searchfor the statement URI; Px means to search for reified subjects, properties,objects or types; O means to search for reified objects; OC means the objectvalue is rdf:Statement.



getCachePreparedStatements
public boolean getCachePreparedStatements()(Code)
Return true if cache of pre-prepared statements is enabled.



getConnection
public Connection getConnection() throws SQLException(Code)
Return the associated jdbc connection.



getPreparedSQLStatement
public synchronized PreparedStatement getPreparedSQLStatement(String opname, String[] attr) throws SQLException(Code)
Return a prepared SQL statement corresponding to the named operation. The statement should either be closed after use or returned to the prepared statement pool using SQLCache.returnPreparedSQLStatement returnPreparedSQLStatement

Only works for single statements, not compound statements.
Parameters:
  con - the jdbc connection to use for preparing statements
Parameters:
  opname - the name of the sql operation to locate a prepared SQL statement appropriate for the JDBC connectionused when this SQLCache was constructed or null if there is no suchoperation or no such connection




getPreparedSQLStatement
public synchronized PreparedStatement getPreparedSQLStatement(String opname) throws SQLException(Code)



getPreparedSQLStatement
public synchronized PreparedStatement getPreparedSQLStatement(String opname, String attr) throws SQLException(Code)
Variant on SQLCache.getPreparedSQLStatement getPreparedSQLStatement which accesses the attribute variant correspond to the given attribute suffix.



getPreparedSQLStatement
public synchronized PreparedStatement getPreparedSQLStatement(String opname, String attrA, String attrB) throws SQLException(Code)
Variant on SQLCache.getPreparedSQLStatement getPreparedSQLStatement which access the attribute variant correspond to the given attribute suffix.



getSQLStatement
public String getSQLStatement(String opname) throws SQLException(Code)
Return the raw SQL statement corresponding to the named operation.



getSQLStatement
public String getSQLStatement(String opname, String[] attr) throws SQLException(Code)
Return the raw SQL statement corresponding to the named operation. Substitute the ${a} attribute macro for the current attribute number.



getSQLStatement
public String getSQLStatement(String opname, String attr) throws SQLException(Code)



getSQLStatement
public String getSQLStatement(String opname, String attrA, String attrB) throws SQLException(Code)
Return the raw SQL statement corresponding to the named operation. Attribute version - substitute the ${a} attribute macro for the current attribute number.



getSQLStatementGroup
public Collection getSQLStatementGroup(String opname) throws SQLException(Code)
Return a set of raw SQL statements corresponding to the named operation. This is used for compound operations where more than one SQL command is needed to implement the operation (e.g. database formating and clean up). The individual statements should be separated by double-semicolons at the end of the line.

Needs refactoring to clarify what operations are and are not compound but for now it is assumed the caller knows which is correct. Compound statements are not called repeatedly so don't currently cache the parsed statement set.




getSQLTable
protected Properties getSQLTable()(Code)
Accessor. Returns the Properties table which maps operation names to the plain text sql statements. This is using internally in the constructor.



loadSQLFile
public static Properties loadSQLFile(String sqlFile, Properties defaultOps, String idType) throws IOException(Code)
Load in a defined set of sql statements - see class comment for format. The loaded file is return as a Property table. This call is static to support the loading of a default sql mapping.
Parameters:
  sqlFile - the name of the file of sql statements to load, this isloaded from the classpath.
Parameters:
  defaultOps - a Properties table of default sql definitions.
Parameters:
  idType - the sql string to use for id types (substitutes for $id in files)



openResourceFile
public static BufferedReader openResourceFile(String filename) throws IOException(Code)
Open a resource file for reading. The file is found on the classpath.



prepareSQLStatement
public synchronized PreparedStatement prepareSQLStatement(String sql) throws SQLException(Code)
Return a prepared SQL statement for the given statement string. The statement should either be closed after use.

Only works for single statements, not compound statements.
Parameters:
  stmt - the sql statement to prepare. a prepared SQL statement appropriate for the JDBC connectionused when this SQLCache was constructed or null if there is no suchconnection.




returnPreparedSQLStatement
public synchronized void returnPreparedSQLStatement(PreparedStatement ps)(Code)
Return a prepared statement to the statement pool for reuse by another caller. Any close problems logged rather than raising exception so that iterator close() operations can be silent so that they can meet the ClosableIterator signature.



runSQLGroup
public void runSQLGroup(String opname, String[] attr) throws SQLException(Code)
Run a group of sql statements - normally used for db formating and clean up. All statements are executed even if one raises an error then the error is reported at the end. Attribute version -- substitute the ${a} attribute macro for the current attribute



runSQLGroup
public void runSQLGroup(String opname) throws SQLException(Code)
Run a group of sql statements - normally used for db formating and clean up. All statements are executed even if one raises an error then the error is reported at the end.



runSQLGroup
public void runSQLGroup(String opname, String attr) throws SQLException(Code)
Run a group of sql statements - normally used for db formating and clean up. All statements are executed even if one raises an error then the error is reported at the end. Attribute version -- substitute the ${a} attribute macro for the current attribute



runSQLGroup
public void runSQLGroup(String opname, String attrA, String attrB) throws SQLException(Code)
Run a group of sql statements - normally used for db formating and clean up. All statements are executed even if one raises an error then the error is reported at the end. Attribute version -- substitute the ${a} attribute macro for the current attribute



runSQLQuery
public ResultSetIterator runSQLQuery(String opname, Object[] args) throws SQLException(Code)
Execute a named pre-prepared SQL query statement taking a set of arguments and return a set of results as an iterator (probably a subclass of ResultSetIterator. Returns null if they query is an update (as opposed to an empty iterator for a true query which happens to return no answers).

Not sure this is a good design. Reducing this to a general interface leads to lots of clunky wrapping and unwrapping of primitive types, coercions and lack of compile-time type checking. On the other hand letting the clients do this themselves with direct jdbc calls leaves us up to the mercy of the client to correctly use returnPreparedSQLStatement and on average seems to lead to more duplication of boiler plate code. Currently the client can chose either approach.

The calling arguments are passed in as an array.




runSQLQuery
public ResultSetIterator runSQLQuery(String opname, String attr, Object[] args) throws SQLException(Code)
Variant on SQLCache.runSQLQuery which access the attribute variant correspond to the given attribute suffix.



runSQLQuery
public ResultSetIterator runSQLQuery(String opname, String attrA, String attrB, Object[] args) throws SQLException(Code)
Variant on SQLCache.runSQLQuery which access the attribute variant correspond to the given attribute suffix.



runSQLQuery
public ResultSetIterator runSQLQuery(String opname, Object[] args, ResultSetIterator iterator) throws SQLException(Code)
Execute a named pre-prepared SQL query statement taking a set of arguments and return a set of results as an iterator (probably a subclass of ResultSetIterator. Returns null if they query is an update (as opposed to an empty iterator for a true query which happens to return no answers).

Not sure this is a good design. Reducing this to a general interface leads to lots of clunky wrapping and unwrapping of primitive types, coercions and lack of compile-time type checking. On the other hand letting the clients do this themselves with direct jdbc calls leaves us up to the mercy of the client to correctly use returnPreparedSQLStatement and on average seems to lead to more duplication of boiler plate code. Currently the client can chose either approach.


Parameters:
  opname - the name of the SQL operation to perform
Parameters:
  args - the arguments to pass to the SQL operation as an array of Objects
Parameters:
  iterator - the iterator to use to return the results




runSQLQuery
public ResultSetIterator runSQLQuery(String opname, String attrA, Object[] args, ResultSetIterator iterator) throws SQLException(Code)
Variant on SQLCache.runSQLQuery which access the attribute variant correspond to the given attribute suffix.



runSQLQuery
public ResultSetIterator runSQLQuery(String opname, String attrA, String attrB, Object[] args, ResultSetIterator iterator) throws SQLException(Code)
Variant on SQLCache.runSQLQuery which access the attribute variant correspond to the given attribute suffix.



runSQLUpdate
public int runSQLUpdate(String opname, Object[] args) throws SQLException(Code)
Execute a named pre-prepared SQL update statement taking a set of arguments and returning the update count.



runSQLUpdate
public int runSQLUpdate(String opname, String attrA, Object[] args) throws SQLException(Code)
Variant on SQLCache.runSQLUpdate which access the attribute variant correspond to the given attribute suffix.



runSQLUpdate
public int runSQLUpdate(String opname, String attrA, String attrB, Object[] args) throws SQLException(Code)
Variant on SQLCache.runSQLUpdate which access the attribute variant correspond to the given attribute suffix.



setCachePreparedStatements
public void setCachePreparedStatements(boolean state)(Code)
Set to true to enable cache of pre-prepared statements.



setConnection
public void setConnection(IDBConnection connection)(Code)
Set the associated jdbc connection.



substitute
public static String substitute(String line, String macro, String subs)(Code)
Helper function substitute all occurances of macro with subs



Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.