mahout-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sro...@apache.org
Subject svn commit: r684988 - in /lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl: common/IOUtils.java model/jdbc/AbstractJDBCDataModel.java recommender/slopeone/jdbc/AbstractJDBCDiffStorage.java
Date Mon, 11 Aug 2008 23:51:49 GMT
Author: srowen
Date: Mon Aug 11 16:51:49 2008
New Revision: 684988

URL: http://svn.apache.org/viewvc?rev=684988&view=rev
Log:
Some modest improvements to use of JDBC -- better use of prepared statement and reuse of connections
in some situations.

Modified:
    lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/common/IOUtils.java
    lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/model/jdbc/AbstractJDBCDataModel.java
    lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/recommender/slopeone/jdbc/AbstractJDBCDiffStorage.java

Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/common/IOUtils.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/common/IOUtils.java?rev=684988&r1=684987&r2=684988&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/common/IOUtils.java
(original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/common/IOUtils.java
Mon Aug 11 16:51:49 2008
@@ -88,7 +88,7 @@
    * @param statement {@link Statement} to close
    * @param connection {@link Connection} to close
    */
-  public static void safeClose(ResultSet resultSet, Statement statement, Connection connection)
{
+  public static void quietClose(ResultSet resultSet, Statement statement, Connection connection)
{
     quietClose(resultSet);
     quietClose(statement);
     quietClose(connection);

Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/model/jdbc/AbstractJDBCDataModel.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/model/jdbc/AbstractJDBCDataModel.java?rev=684988&r1=684987&r2=684988&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/model/jdbc/AbstractJDBCDataModel.java
(original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/model/jdbc/AbstractJDBCDataModel.java
Mon Aug 11 16:51:49 2008
@@ -218,7 +218,7 @@
       log.warn("Exception while retrieving user", sqle);
       throw new TasteException(sqle);
     } finally {
-      IOUtils.safeClose(rs, stmt, conn);
+      IOUtils.quietClose(rs, stmt, conn);
     }
 
   }
@@ -260,7 +260,7 @@
       log.warn("Exception while retrieving item", sqle);
       throw new TasteException(sqle);
     } finally {
-      IOUtils.safeClose(rs, stmt, conn);
+      IOUtils.quietClose(rs, stmt, conn);
     }
   }
 
@@ -298,7 +298,7 @@
       log.warn("Exception while retrieving prefs for item", sqle);
       throw new TasteException(sqle);
     } finally {
-      IOUtils.safeClose(rs, stmt, conn);
+      IOUtils.quietClose(rs, stmt, conn);
     }
   }
 
@@ -347,7 +347,7 @@
       log.warn("Exception while retrieving number of " + name, sqle);
       throw new TasteException(sqle);
     } finally {
-      IOUtils.safeClose(rs, stmt, conn);
+      IOUtils.quietClose(rs, stmt, conn);
     }
   }
 
@@ -383,7 +383,7 @@
       log.warn("Exception while setting preference", sqle);
       throw new TasteException(sqle);
     } finally {
-      IOUtils.safeClose(null, stmt, conn);
+      IOUtils.quietClose(null, stmt, conn);
     }
   }
 
@@ -412,7 +412,7 @@
       log.warn("Exception while removing preference", sqle);
       throw new TasteException(sqle);
     } finally {
-      IOUtils.safeClose(null, stmt, conn);
+      IOUtils.quietClose(null, stmt, conn);
     }
   }
 
@@ -473,17 +473,17 @@
   private final class ResultSetUserIterator implements Iterator<User> {
 
     private final Connection connection;
-    private final Statement statement;
+    private final PreparedStatement statement;
     private final ResultSet resultSet;
     private boolean closed;
 
     private ResultSetUserIterator(DataSource dataSource, String getUsersSQL) throws TasteException
{
       try {
         connection = dataSource.getConnection();
-        statement = connection.createStatement();
+        statement = connection.prepareStatement(getUsersSQL);
         statement.setFetchDirection(ResultSet.FETCH_UNKNOWN);
         log.debug("Executing SQL query: {}", getUsersSQL);
-        resultSet = statement.executeQuery(getUsersSQL);
+        resultSet = statement.executeQuery();
       } catch (SQLException sqle) {
         close();
         throw new TasteException(sqle);
@@ -558,7 +558,7 @@
 
     private void close() {
       closed = true;
-      IOUtils.safeClose(resultSet, statement, connection);
+      IOUtils.quietClose(resultSet, statement, connection);
     }
 
   }
@@ -574,17 +574,17 @@
   private final class ResultSetItemIterator implements Iterator<Item> {
 
     private final Connection connection;
-    private final Statement statement;
+    private final PreparedStatement statement;
     private final ResultSet resultSet;
     private boolean closed;
 
     private ResultSetItemIterator(DataSource dataSource, String getItemsSQL) throws TasteException
{
       try {
         connection = dataSource.getConnection();
-        statement = connection.createStatement();
+        statement = connection.prepareStatement(getItemsSQL);
         statement.setFetchDirection(ResultSet.FETCH_FORWARD);
         log.debug("Executing SQL query: {}", getItemsSQL);
-        resultSet = statement.executeQuery(getItemsSQL);
+        resultSet = statement.executeQuery();
       } catch (SQLException sqle) {
         close();
         throw new TasteException(sqle);
@@ -640,7 +640,7 @@
 
     private void close() {
       closed = true;
-      IOUtils.safeClose(resultSet, statement, connection);
+      IOUtils.quietClose(resultSet, statement, connection);
     }
 
   }

Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/recommender/slopeone/jdbc/AbstractJDBCDiffStorage.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/recommender/slopeone/jdbc/AbstractJDBCDiffStorage.java?rev=684988&r1=684987&r2=684988&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/recommender/slopeone/jdbc/AbstractJDBCDiffStorage.java
(original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/recommender/slopeone/jdbc/AbstractJDBCDiffStorage.java
Mon Aug 11 16:51:49 2008
@@ -135,7 +135,7 @@
       log.warn("Exception while retrieving diff", sqle);
       throw new TasteException(sqle);
     } finally {
-      IOUtils.safeClose(rs, stmt, conn);
+      IOUtils.quietClose(rs, stmt, conn);
     }
   }
 
@@ -170,7 +170,7 @@
       log.warn("Exception while retrieving diff", sqle);
       throw new TasteException(sqle);
     } finally {
-      IOUtils.safeClose(rs, stmt, conn);
+      IOUtils.quietClose(rs, stmt, conn);
     }
     return result;
   }
@@ -196,7 +196,7 @@
       log.warn("Exception while retrieving average item pref", sqle);
       throw new TasteException(sqle);
     } finally {
-      IOUtils.safeClose(rs, stmt, conn);
+      IOUtils.quietClose(rs, stmt, conn);
     }
   }
 
@@ -208,16 +208,20 @@
       conn = dataSource.getConnection();
       if (remove) {
         stmt = doPartialUpdate(removeDiffSQLs[0], itemID, prefDelta, conn);
+        IOUtils.quietClose(stmt);
         stmt = doPartialUpdate(removeDiffSQLs[1], itemID, prefDelta, conn);
+        IOUtils.quietClose(stmt);
       } else {
         stmt = doPartialUpdate(updateDiffSQLs[0], itemID, prefDelta, conn);
+        IOUtils.quietClose(stmt);        
         stmt = doPartialUpdate(updateDiffSQLs[1], itemID, prefDelta, conn);
+        IOUtils.quietClose(stmt);
       }
     } catch (SQLException sqle) {
       log.warn("Exception while updating item diff", sqle);
       throw new TasteException(sqle);
     } finally {
-      IOUtils.safeClose(null, stmt, conn);
+      IOUtils.quietClose(null, stmt, conn);
     }
   }
 
@@ -254,35 +258,35 @@
       log.warn("Exception while retrieving recommendable items", sqle);
       throw new TasteException(sqle);
     } finally {
-      IOUtils.safeClose(rs, stmt, conn);
+      IOUtils.quietClose(rs, stmt, conn);
     }
   }
 
   private void buildAverageDiffs() throws TasteException {
     Connection conn = null;
-    PreparedStatement stmt = null;
-    try {
-      conn = dataSource.getConnection();
-      stmt = conn.prepareStatement(deleteDiffsSQL);
-      log.debug("Executing SQL update: {}", deleteDiffsSQL);
-      stmt.executeUpdate();
-    } catch (SQLException sqle) {
-      log.warn("Exception while deleting diffs", sqle);
-      throw new TasteException(sqle);
-    } finally {
-      IOUtils.safeClose(null, stmt, conn);
-    }
     try {
       conn = dataSource.getConnection();
-      stmt = conn.prepareStatement(createDiffsSQL);
-      stmt.setInt(1, minDiffCount);
-      log.debug("Executing SQL update: {}", createDiffsSQL);
-      stmt.executeUpdate();
+      PreparedStatement stmt = null;
+      try {
+        stmt = conn.prepareStatement(deleteDiffsSQL);
+        log.debug("Executing SQL update: {}", deleteDiffsSQL);
+        stmt.executeUpdate();
+      } finally {
+        IOUtils.quietClose(stmt);
+      }
+      try {
+        stmt = conn.prepareStatement(createDiffsSQL);
+        stmt.setInt(1, minDiffCount);
+        log.debug("Executing SQL update: {}", createDiffsSQL);
+        stmt.executeUpdate();
+      } finally {
+        IOUtils.quietClose(stmt);
+      }
     } catch (SQLException sqle) {
-      log.warn("Exception while creating diffs", sqle);
+      log.warn("Exception while updating/deleting diffs", sqle);
       throw new TasteException(sqle);
     } finally {
-      IOUtils.safeClose(null, stmt, conn);
+      IOUtils.quietClose(conn);
     }
   }
 
@@ -301,7 +305,7 @@
       log.warn("Exception while deleting diffs", sqle);
       throw new TasteException(sqle);
     } finally {
-      IOUtils.safeClose(rs, stmt, conn);
+      IOUtils.quietClose(rs, stmt, conn);
     }
   }
 



Mime
View raw message