Author: srowen
Date: Thu Apr  7 14:39:14 2011
New Revision: 1089894

URL: http://svn.apache.org/viewvc?rev=1089894&view=rev
Log:
Refactor JDBC-related iterators and simplify. Fixes exception from last commit.

Added:
    
mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/common/jdbc/EachRowIterator.java
    
mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/common/jdbc/ResultSetIterator.java
Modified:
    
mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/common/jdbc/AbstractJDBCComponent.java
    
mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/model/jdbc/AbstractJDBCDataModel.java
    
mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/model/jdbc/MySQLBooleanPrefJDBCDataModel.java
    
mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/model/jdbc/MySQLJDBCDataModel.java
    
mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/similarity/jdbc/AbstractJDBCInMemoryItemSimilarity.java
    
mahout/trunk/core/src/main/java/org/apache/mahout/common/iterator/TransformingIterator.java
    
mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/similarity/jdbc/MySQLJDBCInMemoryItemSimilarityTest.java

Modified: 
mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/common/jdbc/AbstractJDBCComponent.java
URL: 
http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/common/jdbc/AbstractJDBCComponent.java?rev=1089894&r1=1089893&r2=1089894&view=diff
==============================================================================
--- 
mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/common/jdbc/AbstractJDBCComponent.java
 (original)
+++ 
mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/common/jdbc/AbstractJDBCComponent.java
 Thu Apr  7 14:39:14 2011
@@ -88,8 +88,4 @@ public abstract class AbstractJDBCCompon
     return DEFAULT_FETCH_SIZE;
   }
   
-  protected void advanceResultSet(ResultSet resultSet, int n) throws 
SQLException {
-    resultSet.relative(n);
-  }
-  
 }

Added: 
mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/common/jdbc/EachRowIterator.java
URL: 
http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/common/jdbc/EachRowIterator.java?rev=1089894&view=auto
==============================================================================
--- 
mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/common/jdbc/EachRowIterator.java
 (added)
+++ 
mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/common/jdbc/EachRowIterator.java
 Thu Apr  7 14:39:14 2011
@@ -0,0 +1,118 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.mahout.cf.taste.impl.common.jdbc;
+
+import javax.sql.DataSource;
+import java.io.Closeable;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.Iterator;
+import java.util.NoSuchElementException;
+
+import org.apache.mahout.common.IOUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Provides an {@link Iterator} over the result of an SQL query, as an 
iteration over the {@link ResultSet}.
+ * While the same object will be returned from the iteration each time, it 
will be returned once for each row
+ * of the result.
+ */
+final class EachRowIterator implements Iterator<ResultSet>, Closeable {
+
+  private static final Logger log = 
LoggerFactory.getLogger(EachRowIterator.class);
+
+  private final Connection connection;
+  private final PreparedStatement statement;
+  private final ResultSet resultSet;
+  private boolean closed;
+  private boolean available;
+
+  EachRowIterator(DataSource dataSource, String sqlQuery) throws SQLException {
+    available = false;
+    closed = false;
+    try {
+      connection = dataSource.getConnection();
+      statement = connection.prepareStatement(sqlQuery, 
ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
+      statement.setFetchDirection(ResultSet.FETCH_FORWARD);
+      //statement.setFetchSize(getFetchSize());
+      log.debug("Executing SQL query: {}", sqlQuery);
+      resultSet = statement.executeQuery();
+    } catch (SQLException sqle) {
+      close();
+      throw sqle;
+    }
+  }
+
+  @Override
+  public boolean hasNext() {
+    if (!available) {
+      if (closed) {
+        return false;
+      }
+      try {
+        available = resultSet.next();
+      } catch (SQLException sqle) {
+        close();
+        throw new IllegalStateException(sqle);
+      }
+      if (!available) {
+        close();
+      }
+    }
+    return available;
+  }
+
+  @Override
+  public ResultSet next() {
+    if (!hasNext()) {
+      throw new NoSuchElementException();
+    }
+    available = false;
+    return resultSet;
+  }
+
+  public void skip(int n) throws SQLException {
+    try {
+      resultSet.relative(n);
+    } catch (SQLException sqle) {
+      // Can't use relative on MySQL Connector/J; try advancing manually
+      int i = 0;
+      while ((i < n) && resultSet.next()) {
+        i++;
+      }
+    }
+  }
+
+  /**
+   * @throws UnsupportedOperationException
+   */
+  @Override
+  public void remove() {
+    throw new UnsupportedOperationException();
+  }
+
+  @Override
+  public void close() {
+    closed = true;
+    IOUtils.quietClose(resultSet, statement, connection);
+  }
+
+}

Added: 
mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/common/jdbc/ResultSetIterator.java
URL: 
http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/common/jdbc/ResultSetIterator.java?rev=1089894&view=auto
==============================================================================
--- 
mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/common/jdbc/ResultSetIterator.java
 (added)
+++ 
mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/common/jdbc/ResultSetIterator.java
 Thu Apr  7 14:39:14 2011
@@ -0,0 +1,53 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.mahout.cf.taste.impl.common.jdbc;
+
+import javax.sql.DataSource;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+
+import org.apache.mahout.common.iterator.TransformingIterator;
+
+public abstract class ResultSetIterator<T> extends 
TransformingIterator<ResultSet,T> {
+
+  protected ResultSetIterator(DataSource dataSource, String sqlQuery) throws 
SQLException {
+    super(new EachRowIterator(dataSource, sqlQuery));
+  }
+
+  @Override
+  protected final T transform(ResultSet in) {
+    try {
+      return parseElement(in);
+    } catch (SQLException sqle) {
+      throw new IllegalStateException(sqle);
+    }
+  }
+
+  protected abstract T parseElement(ResultSet resultSet) throws SQLException;
+
+  public void skip(int n) {
+    if (n >= 1) {
+      try {
+        ((EachRowIterator) getDelegate()).skip(n);
+      } catch (SQLException sqle) {
+        throw new IllegalStateException(sqle);
+      }
+    }
+  }
+
+}

Modified: 
mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/model/jdbc/AbstractJDBCDataModel.java
URL: 
http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/model/jdbc/AbstractJDBCDataModel.java?rev=1089894&r1=1089893&r2=1089894&view=diff
==============================================================================
--- 
mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/model/jdbc/AbstractJDBCDataModel.java
 (original)
+++ 
mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/model/jdbc/AbstractJDBCDataModel.java
 Thu Apr  7 14:39:14 2011
@@ -25,7 +25,6 @@ import java.sql.Statement;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.List;
-import java.util.NoSuchElementException;
 
 import javax.sql.DataSource;
 
@@ -39,6 +38,7 @@ import org.apache.mahout.cf.taste.impl.c
 import org.apache.mahout.cf.taste.impl.common.LongPrimitiveIterator;
 import org.apache.mahout.cf.taste.impl.common.Retriever;
 import org.apache.mahout.cf.taste.impl.common.jdbc.AbstractJDBCComponent;
+import org.apache.mahout.cf.taste.impl.common.jdbc.ResultSetIterator;
 import org.apache.mahout.cf.taste.impl.model.GenericItemPreferenceArray;
 import org.apache.mahout.cf.taste.impl.model.GenericPreference;
 import org.apache.mahout.cf.taste.impl.model.GenericUserPreferenceArray;
@@ -254,7 +254,11 @@ public abstract class AbstractJDBCDataMo
   @Override
   public LongPrimitiveIterator getUserIDs() throws TasteException {
     log.debug("Retrieving all users...");
-    return new ResultSetIDIterator(getUsersSQL);
+    try {
+      return new ResultSetIDIterator(getUsersSQL);
+    } catch (SQLException sqle) {
+      throw new TasteException(sqle);
+    }
   }
 
   /**
@@ -499,7 +503,11 @@ public abstract class AbstractJDBCDataMo
   @Override
   public LongPrimitiveIterator getItemIDs() throws TasteException {
     log.debug("Retrieving all items...");
-    return new ResultSetIDIterator(getItemsSQL);
+    try {
+      return new ResultSetIDIterator(getItemsSQL);
+    } catch (SQLException sqle) {
+      throw new TasteException(sqle);
+    }
   }
 
   @Override
@@ -743,127 +751,30 @@ public abstract class AbstractJDBCDataMo
    * make sure to "drain" the entire set of data to avoid tying up database 
resources.
    * </p>
    */
-  private final class ResultSetIDIterator implements LongPrimitiveIterator {
-
-    private final Connection connection;
-    private final Statement statement;
-    private final ResultSet resultSet;
-    private boolean closed;
+  private final class ResultSetIDIterator extends ResultSetIterator<Long> 
implements LongPrimitiveIterator {
 
-    private ResultSetIDIterator(String sql) throws TasteException {
-      try {
-        connection = dataSource.getConnection();
-        statement = connection.createStatement(ResultSet.TYPE_FORWARD_ONLY, 
ResultSet.CONCUR_READ_ONLY);
-        statement.setFetchDirection(ResultSet.FETCH_FORWARD);
-        statement.setFetchSize(getFetchSize());
-        log.debug("Executing SQL query: {}", sql);
-        resultSet = statement.executeQuery(sql);
-        boolean anyResults = resultSet.next();
-        if (!anyResults) {
-          close();
-        }
-      } catch (SQLException sqle) {
-        close();
-        throw new TasteException(sqle);
-      }
+    private ResultSetIDIterator(String sql) throws SQLException {
+      super(dataSource, sql);
     }
 
     @Override
-    public boolean hasNext() {
-      boolean nextExists = false;
-      if (!closed) {
-        try {
-          if (resultSet.isAfterLast()) {
-            close();
-          } else {
-            nextExists = true;
-          }
-        } catch (SQLException sqle) {
-          log.warn("Unexpected exception while accessing ResultSet; 
continuing...",
-            sqle);
-          close();
-        }
-      }
-      return nextExists;
-    }
-
-    @Override
-    public Long next() {
-      return nextLong();
+    protected Long parseElement(ResultSet resultSet) throws SQLException {
+      return getLongColumn(resultSet, 1);
     }
 
     @Override
     public long nextLong() {
-
-      if (!hasNext()) {
-        throw new NoSuchElementException();
-      }
-
-      try {
-        long id = getLongColumn(resultSet, 1);
-        resultSet.next();
-        return id;
-      } catch (SQLException sqle) {
-        // No good way to handle this since we can't throw an exception
-        log.warn("Exception while iterating", sqle);
-        close();
-        throw new NoSuchElementException("Can't retrieve more due to 
exception: " + sqle);
-      }
-
-    }
-
-    @Override
-    public long peek() {
-      if (!hasNext()) {
-        throw new NoSuchElementException();
-      }
-      try {
-        return getLongColumn(resultSet, 1);
-      } catch (SQLException sqle) {
-        // No good way to handle this since we can't throw an exception
-        log.warn("Exception while iterating", sqle);
-        close();
-        throw new NoSuchElementException("Can't retrieve more due to 
exception: " + sqle);
-      }
-
+      return next();
     }
 
     /**
      * @throws UnsupportedOperationException
      */
     @Override
-    public void remove() {
+    public long peek() {
+      // This could be supported; is it worth it?
       throw new UnsupportedOperationException();
     }
-
-    private void close() {
-      if (!closed) {
-        closed = true;
-        IOUtils.quietClose(resultSet, statement, connection);
-      }
-    }
-    
-    @Override
-    public void skip(int n) {
-      if (n >= 1) {
-        try {
-          advanceResultSet(resultSet, n);
-        } catch (SQLException sqle) {
-          log.warn("Exception while iterating over items", sqle);
-          close();
-        }
-      }
-    }
-
-    @Override
-    protected void finalize() throws Throwable {
-      try {
-        close();
-      } finally {
-        super.finalize();
-      }
-    }
-
   }
 
   private final class ItemPrefCountRetriever implements 
Retriever<Long,Integer> {

Modified: 
mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/model/jdbc/MySQLBooleanPrefJDBCDataModel.java
URL: 
http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/model/jdbc/MySQLBooleanPrefJDBCDataModel.java?rev=1089894&r1=1089893&r2=1089894&view=diff
==============================================================================
--- 
mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/model/jdbc/MySQLBooleanPrefJDBCDataModel.java
 (original)
+++ 
mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/model/jdbc/MySQLBooleanPrefJDBCDataModel.java
 Thu Apr  7 14:39:14 2011
@@ -17,9 +17,6 @@
 
 package org.apache.mahout.cf.taste.impl.model.jdbc;
 
-import java.sql.ResultSet;
-import java.sql.SQLException;
-
 import javax.sql.DataSource;
 
 import org.apache.mahout.cf.taste.common.TasteException;
@@ -161,13 +158,4 @@ public class MySQLBooleanPrefJDBCDataMod
     return Integer.MIN_VALUE;
   }
   
-  @Override
-  protected void advanceResultSet(ResultSet resultSet, int n) throws 
SQLException {
-    // Can't use relative on MySQL Connector/J
-    int i = 0;
-    while ((i < n) && resultSet.next()) {
-      i++;
-    }
-  }
-  
 }
\ No newline at end of file

Modified: 
mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/model/jdbc/MySQLJDBCDataModel.java
URL: 
http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/model/jdbc/MySQLJDBCDataModel.java?rev=1089894&r1=1089893&r2=1089894&view=diff
==============================================================================
--- 
mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/model/jdbc/MySQLJDBCDataModel.java
 (original)
+++ 
mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/model/jdbc/MySQLJDBCDataModel.java
 Thu Apr  7 14:39:14 2011
@@ -17,9 +17,6 @@
 
 package org.apache.mahout.cf.taste.impl.model.jdbc;
 
-import java.sql.ResultSet;
-import java.sql.SQLException;
-
 import javax.sql.DataSource;
 
 import org.apache.mahout.cf.taste.common.TasteException;
@@ -247,13 +244,4 @@ public class MySQLJDBCDataModel extends 
     return Integer.MIN_VALUE;
   }
   
-  @Override
-  protected void advanceResultSet(ResultSet resultSet, int n) throws 
SQLException {
-    // Can't use relative on MySQL Connector/J
-    int i = 0;
-    while ((i < n) && resultSet.next()) {
-      i++;
-    }
-  }
-  
 }

Modified: 
mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/similarity/jdbc/AbstractJDBCInMemoryItemSimilarity.java
URL: 
http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/similarity/jdbc/AbstractJDBCInMemoryItemSimilarity.java?rev=1089894&r1=1089893&r2=1089894&view=diff
==============================================================================
--- 
mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/similarity/jdbc/AbstractJDBCInMemoryItemSimilarity.java
 (original)
+++ 
mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/similarity/jdbc/AbstractJDBCInMemoryItemSimilarity.java
 Thu Apr  7 14:39:14 2011
@@ -20,21 +20,18 @@ package org.apache.mahout.cf.taste.impl.
 import org.apache.mahout.cf.taste.common.Refreshable;
 import org.apache.mahout.cf.taste.common.TasteException;
 import org.apache.mahout.cf.taste.impl.common.jdbc.AbstractJDBCComponent;
+import org.apache.mahout.cf.taste.impl.common.jdbc.ResultSetIterator;
 import org.apache.mahout.cf.taste.impl.model.jdbc.ConnectionPoolDataSource;
 import org.apache.mahout.cf.taste.impl.similarity.GenericItemSimilarity;
 import org.apache.mahout.cf.taste.similarity.ItemSimilarity;
-import org.apache.mahout.common.IOUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import javax.sql.DataSource;
-import java.sql.Connection;
-import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.util.Collection;
 import java.util.Iterator;
-import java.util.NoSuchElementException;
 import java.util.concurrent.locks.ReentrantLock;
 
 /**
@@ -97,88 +94,28 @@ abstract class AbstractJDBCInMemoryItemS
     }
   }
 
-  class JDBCSimilaritiesIterable implements 
Iterable<GenericItemSimilarity.ItemItemSimilarity> {
+  private class JDBCSimilaritiesIterable implements 
Iterable<GenericItemSimilarity.ItemItemSimilarity> {
     @Override
     public Iterator<GenericItemSimilarity.ItemItemSimilarity> iterator() {
-      return new JDBCSimilaritiesIterator();
-    }
-  }
-
-  private class JDBCSimilaritiesIterator implements 
Iterator<GenericItemSimilarity.ItemItemSimilarity> {
-
-    private final Connection connection;
-    private final PreparedStatement statement;
-    private final ResultSet resultSet;
-    private boolean closed;
-
-    private JDBCSimilaritiesIterator() {
       try {
-        connection = dataSource.getConnection();
-        statement = connection.prepareStatement(getAllItemSimilaritiesSQL, 
ResultSet.TYPE_FORWARD_ONLY,
-            ResultSet.CONCUR_READ_ONLY);
-        statement.setFetchDirection(ResultSet.FETCH_FORWARD);
-        statement.setFetchSize(getFetchSize());
-        log.debug("Executing SQL query: {}", getAllItemSimilaritiesSQL);
-        resultSet = statement.executeQuery();
-        boolean anyResults = resultSet.next();
-        if (!anyResults) {
-          close();
-        }
-      } catch (SQLException e) {
-        close();
-        throw new IllegalStateException("Unable to read similarities!", e);
+        return new JDBCSimilaritiesIterator();
+      } catch (SQLException sqle) {
+        throw new IllegalStateException(sqle);
       }
     }
+  }
 
-    @Override
-    public boolean hasNext() {
-      boolean nextExists = false;
-      if (!closed) {
-        try {
-          if (resultSet.isAfterLast()) {
-            close();
-          } else {
-            nextExists = true;
-          }
-        } catch (SQLException sqle) {
-          log.warn("Unexpected exception while accessing ResultSet; 
continuing...", sqle);
-          close();
-        }
-      }
-      return nextExists;
-    }
+  private class JDBCSimilaritiesIterator extends 
ResultSetIterator<GenericItemSimilarity.ItemItemSimilarity> {
 
-    @Override
-    public GenericItemSimilarity.ItemItemSimilarity next() {
-      if (!hasNext()) {
-        throw new NoSuchElementException();
-      }
-      try {
-        GenericItemSimilarity.ItemItemSimilarity similarity = new 
GenericItemSimilarity.ItemItemSimilarity(
-            resultSet.getLong(1), resultSet.getLong(2), 
resultSet.getDouble(3));
-        resultSet.next();
-        return similarity;
-      } catch (SQLException e) {
-        // No good way to handle this since we can't throw an exception
-        log.warn("Exception while iterating", e);
-        close();
-        throw new IllegalStateException("Unable to read similarities!", e);
-      }
+    private JDBCSimilaritiesIterator() throws SQLException {
+      super(dataSource, getAllItemSimilaritiesSQL);
     }
 
-    /**
-     * @throws UnsupportedOperationException
-     */
     @Override
-    public void remove() {
-      throw new UnsupportedOperationException();
-    }
-
-    private void close() {
-      if (!closed) {
-        closed = true;
-        IOUtils.quietClose(resultSet, statement, connection);
-      }
+    protected GenericItemSimilarity.ItemItemSimilarity parseElement(ResultSet 
resultSet) throws SQLException {
+      return new GenericItemSimilarity.ItemItemSimilarity(resultSet.getLong(1),
+                                                          resultSet.getLong(2),
+                                                          
resultSet.getDouble(3));
     }
   }
 

Modified: 
mahout/trunk/core/src/main/java/org/apache/mahout/common/iterator/TransformingIterator.java
URL: 
http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/common/iterator/TransformingIterator.java?rev=1089894&r1=1089893&r2=1089894&view=diff
==============================================================================
--- 
mahout/trunk/core/src/main/java/org/apache/mahout/common/iterator/TransformingIterator.java
 (original)
+++ 
mahout/trunk/core/src/main/java/org/apache/mahout/common/iterator/TransformingIterator.java
 Thu Apr  7 14:39:14 2011
@@ -35,6 +35,10 @@ public abstract class TransformingIterat
    * @return the transformed value returned from this iterator
    */
   protected abstract O transform(I in);
+
+  protected Iterator<? extends I> getDelegate() {
+    return delegate;
+  }
   
   @Override
   public final boolean hasNext() {

Modified: 
mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/similarity/jdbc/MySQLJDBCInMemoryItemSimilarityTest.java
URL: 
http://svn.apache.org/viewvc/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/similarity/jdbc/MySQLJDBCInMemoryItemSimilarityTest.java?rev=1089894&r1=1089893&r2=1089894&view=diff
==============================================================================
--- 
mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/similarity/jdbc/MySQLJDBCInMemoryItemSimilarityTest.java
 (original)
+++ 
mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/similarity/jdbc/MySQLJDBCInMemoryItemSimilarityTest.java
 Thu Apr  7 14:39:14 2011
@@ -41,36 +41,30 @@ public class MySQLJDBCInMemoryItemSimila
     
EasyMock.expect(connection.prepareStatement(MySQLJDBCInMemoryItemSimilarity.DEFAULT_GET_ALL_ITEMSIMILARITIES_SQL,
         ResultSet.TYPE_FORWARD_ONLY, 
ResultSet.CONCUR_READ_ONLY)).andReturn(statement);
     statement.setFetchDirection(ResultSet.FETCH_FORWARD);
-    statement.setFetchSize(Integer.MIN_VALUE);
     EasyMock.expect(statement.executeQuery()).andReturn(resultSet);
 
     EasyMock.expect(resultSet.next()).andReturn(true);
 
-    EasyMock.expect(resultSet.isAfterLast()).andReturn(false);
     EasyMock.expect(resultSet.getLong(1)).andReturn(1L);
     EasyMock.expect(resultSet.getLong(2)).andReturn(2L);
     EasyMock.expect(resultSet.getDouble(3)).andReturn(0.5);
     EasyMock.expect(resultSet.next()).andReturn(true);
 
-    EasyMock.expect(resultSet.isAfterLast()).andReturn(false);
     EasyMock.expect(resultSet.getLong(1)).andReturn(1L);
     EasyMock.expect(resultSet.getLong(2)).andReturn(3L);
     EasyMock.expect(resultSet.getDouble(3)).andReturn(0.4);
     EasyMock.expect(resultSet.next()).andReturn(true);
 
-    EasyMock.expect(resultSet.isAfterLast()).andReturn(false);
     EasyMock.expect(resultSet.getLong(1)).andReturn(3L);
     EasyMock.expect(resultSet.getLong(2)).andReturn(4L);
     EasyMock.expect(resultSet.getDouble(3)).andReturn(0.1);
 
-    EasyMock.expect(resultSet.isAfterLast()).andReturn(true);
+    EasyMock.expect(resultSet.next()).andReturn(false);
 
     resultSet.close();
     statement.close();
     connection.close();
 
-    EasyMock.expect(resultSet.next()).andReturn(false);
-
     EasyMock.replay(dataSource, connection, statement, resultSet);
 
     ItemSimilarity similarity = new 
MySQLJDBCInMemoryItemSimilarity(dataSource);


Reply via email to