Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
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.model.jdbc;
 
 

See also MySQLJDBCDataModel -- same except deals with a table without preference info:

 CREATE TABLE taste_preferences (
   user_id BIGINT NOT NULL,
   item_id BIGINT NOT NULL,
   PRIMARY KEY (user_id, item_id),
   INDEX (user_id),
   INDEX (item_id)
 )
 
 
 
   private static final String NO_SUCH_COLUMN = "NO_SUCH_COLUMN";

  
 
     this();
   }

  

Creates a MySQLBooleanPrefJDBCDataModel using the default javax.sql.DataSource found under the given name, and using default table/column names.

Parameters:
dataSourceName name of javax.sql.DataSource to look up
Throws:
org.apache.mahout.cf.taste.common.TasteException if javax.sql.DataSource can't be found
 
   public MySQLBooleanPrefJDBCDataModel(String dataSourceNamethrows TasteException {
     this(lookupDataSource(dataSourceName),
         ,
         ,
         );
   }

  

Creates a MySQLBooleanPrefJDBCDataModel using the given javax.sql.DataSource and default table/column names.

Parameters:
dataSource javax.sql.DataSource to use
 
   public MySQLBooleanPrefJDBCDataModel(DataSource dataSource) {
     this(dataSource,
         ,
         ,
         );
   }

  

Creates a MySQLBooleanPrefJDBCDataModel using the given javax.sql.DataSource and default table/column names.

Parameters:
dataSource javax.sql.DataSource to use
preferenceTable name of table containing preference data
userIDColumn user ID column name
itemIDColumn item ID column name
 
   public MySQLBooleanPrefJDBCDataModel(DataSource dataSource,
                                        String preferenceTable,
                                        String userIDColumn,
                                        String itemIDColumn) {
     super(dataSource,
         preferenceTable,
         userIDColumn,
         itemIDColumn,
         ,
        // getPreferenceSQL
        "SELECT 1 FROM " + preferenceTable + " WHERE " + userIDColumn + "=? AND " + itemIDColumn + "=?",
        // getUserSQL
        "SELECT " + userIDColumn + ", " + itemIDColumn + " FROM " + preferenceTable + " WHERE " + userIDColumn + "=?",
        // getAllUsersSQL
        "SELECT " + userIDColumn + ", " + itemIDColumn + " FROM " + preferenceTable + " ORDER BY " + userIDColumn,
        // getNumItemsSQL
        "SELECT COUNT(DISTINCT " + itemIDColumn + ") FROM " + preferenceTable,
        // getNumUsersSQL
        "SELECT COUNT(DISTINCT " + userIDColumn + ") FROM " + preferenceTable,
        // setPreferenceSQL
        "INSERT IGNORE INTO " + preferenceTable + '(' + userIDColumn + ',' + itemIDColumn + ") VALUES (?,?)",
        // removePreference SQL
        "DELETE FROM " + preferenceTable + " WHERE " + userIDColumn + "=? AND " + itemIDColumn + "=?",
        // getUsersSQL
        "SELECT DISTINCT " + userIDColumn + " FROM " + preferenceTable + " ORDER BY " + userIDColumn,
        // getItemsSQL
        "SELECT DISTINCT " + itemIDColumn + " FROM " + preferenceTable + " ORDER BY " + itemIDColumn,
        // getPrefsForItemSQL
        "SELECT " + userIDColumn + ", " + itemIDColumn + " FROM " +
            preferenceTable + " WHERE " + itemIDColumn + "=? ORDER BY " + userIDColumn,
        // getNumPreferenceForItemSQL
        "SELECT COUNT(1) FROM " + preferenceTable + " WHERE " + itemIDColumn + "=?",
        // getNumPreferenceForItemsSQL
        "SELECT COUNT(1) FROM " + preferenceTable + " tp1 JOIN " + preferenceTable + " tp2 " +
            "USING (" + userIDColumn + ") WHERE tp1." + itemIDColumn + "=? and tp2." + itemIDColumn + "=?");
  }
  protected int getFetchSize() {
    // Need to return this for MySQL Connector/J to make it use streaming mode
    return .;
  }
  protected void advanceResultSet(ResultSet resultSetint nthrows SQLException {
    // Can't use relative on MySQL Connector/J
    int i = 0;
    while (i < n && resultSet.next()) {
      i++;
    }
  }
New to GrepCode? Check out our FAQ X