org.apache.mahout.cf.taste.impl.model
Class AbstractJDBCIDMigrator

java.lang.Object
  extended by org.apache.mahout.cf.taste.impl.model.AbstractIDMigrator
      extended by org.apache.mahout.cf.taste.impl.model.AbstractJDBCIDMigrator
All Implemented Interfaces:
Refreshable, IDMigrator, UpdatableIDMigrator
Direct Known Subclasses:
MySQLJDBCIDMigrator

public abstract class AbstractJDBCIDMigrator
extends AbstractIDMigrator
implements UpdatableIDMigrator

Implementation which stores the reverse long-to-String mapping in a database. Subclasses can override and configure the class to operate with particular databases by supplying appropriate SQL statements to the constructor.


Field Summary
static String DEFAULT_LONG_ID_COLUMN
           
static String DEFAULT_MAPPING_TABLE
           
static String DEFAULT_STRING_ID_COLUMN
           
 
Constructor Summary
protected AbstractJDBCIDMigrator(DataSource dataSource, String getStringIDSQL, String storeMappingSQL)
           
 
Method Summary
 void initialize(Iterable<String> stringIDs)
          Make the mapping aware of the given string IDs.
 void storeMapping(long longID, String stringID)
          Stores the reverse long-to-String mapping in some kind of backing store.
 String toStringID(long longID)
           
 
Methods inherited from class org.apache.mahout.cf.taste.impl.model.AbstractIDMigrator
hash, refresh, toLongID
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.apache.mahout.cf.taste.model.IDMigrator
toLongID
 
Methods inherited from interface org.apache.mahout.cf.taste.common.Refreshable
refresh
 

Field Detail

DEFAULT_MAPPING_TABLE

public static final String DEFAULT_MAPPING_TABLE
See Also:
Constant Field Values

DEFAULT_LONG_ID_COLUMN

public static final String DEFAULT_LONG_ID_COLUMN
See Also:
Constant Field Values

DEFAULT_STRING_ID_COLUMN

public static final String DEFAULT_STRING_ID_COLUMN
See Also:
Constant Field Values
Constructor Detail

AbstractJDBCIDMigrator

protected AbstractJDBCIDMigrator(DataSource dataSource,
                                 String getStringIDSQL,
                                 String storeMappingSQL)
Parameters:
getStringIDSQL - SQL statement which selects one column, the String ID, from a mapping table. The statement should take one long parameter.
storeMappingSQL - SQL statement which saves a mapping from long to String. It should take two parameters, a long and a String.
Method Detail

storeMapping

public final void storeMapping(long longID,
                               String stringID)
                        throws TasteException
Description copied from interface: UpdatableIDMigrator
Stores the reverse long-to-String mapping in some kind of backing store. Note that this must be called directly (or indirectly through UpdatableIDMigrator.initialize(Iterable)) for every String that might be encountered in the application, or else the mapping will not be known.

Specified by:
storeMapping in interface UpdatableIDMigrator
Parameters:
longID - long ID
stringID - string ID that maps to/from that long ID
Throws:
TasteException - if an error occurs while saving the mapping

toStringID

public final String toStringID(long longID)
                        throws TasteException
Specified by:
toStringID in interface IDMigrator
Returns:
the string ID most recently associated with the given long ID, or null if doesn't exist
Throws:
TasteException - if an error occurs while retrieving the mapping

initialize

public void initialize(Iterable<String> stringIDs)
                throws TasteException
Description copied from interface: UpdatableIDMigrator
Make the mapping aware of the given string IDs. This must be called initially before the implementation is used, or else it will not be aware of reverse long-to-String mappings.

Specified by:
initialize in interface UpdatableIDMigrator
Throws:
TasteException - if an error occurs while storing the mappings


Copyright © 2008–2014 The Apache Software Foundation. All rights reserved.