You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jena.apache.org by rv...@apache.org on 2013/04/29 21:29:41 UTC

svn commit: r1477288 - /jena/Experimental/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/statements/JenaStatement.java

Author: rvesse
Date: Mon Apr 29 19:29:40 2013
New Revision: 1477288

URL: http://svn.apache.org/r1477288
Log:
Add logging to JenaStatement, fix lack of pre-processor support on direct executeQuery() and executeUpdate() methods

Modified:
    jena/Experimental/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/statements/JenaStatement.java

Modified: jena/Experimental/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/statements/JenaStatement.java
URL: http://svn.apache.org/viewvc/jena/Experimental/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/statements/JenaStatement.java?rev=1477288&r1=1477287&r2=1477288&view=diff
==============================================================================
--- jena/Experimental/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/statements/JenaStatement.java (original)
+++ jena/Experimental/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/statements/JenaStatement.java Mon Apr 29 19:29:40 2013
@@ -34,6 +34,8 @@ import org.apache.jena.jdbc.connections.
 import org.apache.jena.jdbc.results.AskResults;
 import org.apache.jena.jdbc.results.SelectResults;
 import org.apache.jena.jdbc.results.TripleIteratorResults;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import com.hp.hpl.jena.query.Query;
 import com.hp.hpl.jena.query.QueryExecution;
@@ -49,6 +51,8 @@ import com.hp.hpl.jena.update.UpdateRequ
  * 
  */
 public abstract class JenaStatement implements Statement {
+    
+    private static final Logger LOGGER = LoggerFactory.getLogger(JenaStatement.class);
 
     protected static final int DEFAULT_HOLDABILITY = ResultSet.CLOSE_CURSORS_AT_COMMIT;
     protected static final int DEFAULT_FETCH_DIRECTION = ResultSet.FETCH_FORWARD;
@@ -166,6 +170,7 @@ public abstract class JenaStatement impl
     public void close() throws SQLException {
         if (this.closed)
             return;
+        LOGGER.info("Closing statement");
         this.closed = true;
         if (this.currResults != null) {
             this.currResults.close();
@@ -180,15 +185,18 @@ public abstract class JenaStatement impl
             rset.close();
         }
         this.openResults.clear();
+        LOGGER.info("Statement was closed");
     }
 
     @Override
     public final boolean execute(String sql) throws SQLException {
         if (this.isClosed())
             throw new SQLException("The Statement is closed");
-        
+                
         // Pre-process the command text
+        LOGGER.info("Received input command text:\n {}", sql);
         sql = this.connection.applyPreProcessors(sql);
+        LOGGER.info("Command text after pre-processing:\n {}", sql);
 
         Query q = null;
         UpdateRequest u = null;
@@ -200,15 +208,18 @@ public abstract class JenaStatement impl
                 // If that fails try as an update instead
                 u = UpdateFactory.create(sql);
             } catch (Exception e2) {
+                LOGGER.error("Command text was not a valid SPARQL query/update", e2);
                 throw new SQLException("Not a valid SPARQL query/update", e);
             }
         }
 
         if (q != null) {
             // Execute as a query
+            LOGGER.info("Treating command text as a query");
             return this.executeQuery(q);
         } else if (u != null) {
             // Execute as an update
+            LOGGER.info("Treating command text as an update");
             this.executeUpdate(u);
             return false;
         } else {
@@ -228,8 +239,10 @@ public abstract class JenaStatement impl
         try {
             // Start a transaction if necessary
             if (needsCommit) {
+                LOGGER.info("Running query in auto-commit mode");
                 this.beginTransaction(ReadWrite.READ);
             } else if (needsBegin) {
+                LOGGER.info("Starting a new transaction to run query, transaction will not be auto-committed");
                 this.beginTransaction(ReadWrite.WRITE);
             }
             
@@ -242,6 +255,7 @@ public abstract class JenaStatement impl
                 // permitted max rows
                 // then we will set the LIMIT to the max rows
                 if (!q.hasLimit() || q.getLimit() > this.maxRows) {
+                    LOGGER.info("Enforced max rows on results by applying LIMIT {} to the query", this.maxRows);
                     q.setLimit(this.maxRows);
                 }
             }
@@ -275,6 +289,7 @@ public abstract class JenaStatement impl
         } catch (SQLException e) {
             throw e;
         } catch (Exception e) {
+            LOGGER.error("SPARQL Query evaluation failed", e);
             throw new SQLException("Error occurred during SPARQL query evaluation", e);
         }
     }
@@ -306,6 +321,11 @@ public abstract class JenaStatement impl
         try {
             // Start a Transaction if necessary
             if (needsCommit || needsBegin) {
+                if (this.autoCommit) {
+                    LOGGER.info("Running update in auto-commit mode");
+                } else {
+                    LOGGER.info("Starting a new transaction to run update, transaction will not be auto-committed");
+                }
                 this.beginTransaction(ReadWrite.WRITE);
             }
             
@@ -320,12 +340,15 @@ public abstract class JenaStatement impl
         } catch (SQLException e) {
             throw e;
         } catch (Exception e) {
+            LOGGER.error("SPARQL Update evaluation failed", e);
             throw new SQLException("Error occurred during SPARQL update evaluation", e);
         } finally {
             if (needsCommit) {
                 if (commit) {
+                    LOGGER.info("Committing update transaction");
                     this.commitTransaction();
                 } else {
+                    LOGGER.warn("Rolling back failed update transaction");
                     this.rollbackTransaction();
                 }
             }
@@ -397,11 +420,17 @@ public abstract class JenaStatement impl
     public final ResultSet executeQuery(String sql) throws SQLException {
         if (this.isClosed())
             throw new SQLException("The Statement is closed");
+        
+        // Pre-process the command text
+        LOGGER.info("Received input command text:\n {}", sql);
+        sql = this.connection.applyPreProcessors(sql);
+        LOGGER.info("Command text after pre-processing:\n {}", sql);
 
         Query q = null;
         try {
             q = QueryFactory.create(sql);
         } catch (Exception e) {
+            LOGGER.error("Invalid SPARQL query", e);
             throw new SQLException("Not a valid SPARQL query", e);
         }
 
@@ -420,10 +449,17 @@ public abstract class JenaStatement impl
             throw new SQLException("The Statement is closed");
         if (this.connection.isReadOnly())
             throw new SQLException("The JDBC connection is currently in read-only mode, updates are not permitted");
+        
+        // Pre-process the command text
+        LOGGER.info("Received input command text:\n {}", sql);
+        sql = this.connection.applyPreProcessors(sql);
+        LOGGER.info("Command text after pre-processing:\n {}", sql);
+        
         UpdateRequest u = null;
         try {
             u = UpdateFactory.create(sql);
         } catch (Exception e) {
+            LOGGER.error("Invalid SPARQL update", e);
             throw new SQLException("Not a valid SPARQL Update", e);
         }
 
@@ -506,6 +542,7 @@ public abstract class JenaStatement impl
             for (ResultSet rset : this.openResults) {
                 rset.close();
             }
+            this.openResults.clear();
             return this.getMoreResults();
         case Statement.KEEP_CURRENT_RESULT:
             if (this.currResults != null) {
@@ -602,6 +639,7 @@ public abstract class JenaStatement impl
      *            Warning
      */
     protected void setWarning(SQLWarning warning) {
+        LOGGER.warn("SQL Warning was issued", warning);
         if (this.warnings == null) {
             this.warnings = warning;
         } else {