<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">/*-
 * See the file LICENSE for redistribution information.
 *
 * Copyright (c) 2002-2009 Oracle.  All rights reserved.
 *
 * $Id$
 */

package com.sleepycat.db;

import java.util.Set;

/**
The interface implemented for extracting multi-valued secondary keys from
primary records.
&lt;p&gt;
The key creator object is specified by calling
{@link SecondaryConfig#setMultiKeyCreator SecondaryConfig.setMultiKeyCreator}.
The secondary database configuration is specified when calling
{@link Environment#openSecondaryDatabase Environment.openSecondaryDatabase}.
&lt;p&gt;
For example:
&lt;pre&gt;
    class MyMultiKeyCreator implements SecondaryMultiKeyCreator {
    public void createSecondaryKeys(SecondaryDatabase secondary,
                                        DatabaseEntry key,
                                        DatabaseEntry data,
                                        Set results)
            throws DatabaseException {
            //
            // DO HERE: Extract the secondary keys from the primary key and
            // data.  For each key extracted, create a DatabaseEntry and add it
            // to the results set.
            //
        }
    }
    ...
    SecondaryConfig secConfig = new SecondaryConfig();
    secConfig.setMultiKeyCreator(new MyMultiKeyCreator());
    // Now pass secConfig to Environment.openSecondaryDatabase
&lt;/pre&gt;
&lt;p&gt;
Use this interface when any number of secondary keys may be present in a single
primary record, in other words, for many-to-many and one-to-many relationships.
When only zero or one secondary key is present (for many-to-one and one-to-one
relationships) you may use the {@link SecondaryKeyCreator} interface instead.
The table below summarizes how to create all four variations of relationships.
&lt;div&gt;
&lt;table border="yes"&gt;
    &lt;tr&gt;&lt;th&gt;Relationship&lt;/th&gt;
        &lt;th&gt;Interface&lt;/th&gt;
        &lt;th&gt;Duplicates&lt;/th&gt;
        &lt;th&gt;Example&lt;/th&gt;
    &lt;/tr&gt;
    &lt;tr&gt;&lt;td&gt;One-to-one&lt;/td&gt;
        &lt;td&gt;{@link SecondaryKeyCreator}&lt;/td&gt;
        &lt;td&gt;No&lt;/td&gt;
        &lt;td&gt;A person record with a unique social security number key.&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;&lt;td&gt;Many-to-one&lt;/td&gt;
        &lt;td&gt;{@link SecondaryKeyCreator}&lt;/td&gt;
        &lt;td&gt;Yes&lt;/td&gt;
        &lt;td&gt;A person record with a non-unique employer key.&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;&lt;td&gt;One-to-many&lt;/td&gt;
        &lt;td&gt;{@link SecondaryMultiKeyCreator}&lt;/td&gt;
        &lt;td&gt;No&lt;/td&gt;
        &lt;td&gt;A person record with multiple unique email address keys.&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;&lt;td&gt;Many-to-many&lt;/td&gt;
        &lt;td&gt;{@link SecondaryMultiKeyCreator}&lt;/td&gt;
        &lt;td&gt;Yes&lt;/td&gt;
        &lt;td&gt;A person record with multiple non-unique organization keys.&lt;/td&gt;
    &lt;/tr&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p&gt;To configure a database for duplicates. pass true to {@link
DatabaseConfig#setSortedDuplicates}.&lt;/p&gt;
&lt;p&gt;
Note that &lt;code&gt;SecondaryMultiKeyCreator&lt;/code&gt; may also be used for single key
secondaries (many-to-one and one-to-one); in this case, at most a single key is
added to the results set.  &lt;code&gt;SecondaryMultiKeyCreator&lt;/code&gt; is only
slightly less efficient than {@link SecondaryKeyCreator} in that two or three
temporary sets must be created to hold the results.
@see SecondaryConfig
*/
public interface SecondaryMultiKeyCreator {
    /**
    Creates a secondary key entry, given a primary key and data entry.
    &lt;p&gt;
    A secondary key may be derived from the primary key, primary data, or a
    combination of the primary key and data.  Zero or more secondary keys may
    be derived from the primary record and returned in the results parameter.
    To ensure the integrity of a secondary database the key creator method must
    always return the same results for a given set of input parameters.
    &lt;p&gt;
    @param secondary the database to which the secondary key will be added.
    This parameter is passed for informational purposes but is not commonly
    used.
    &lt;p&gt;
    @param key the primary key entry.  This parameter must not be modified
    by this method.
    &lt;p&gt;
    @param data the primary data entry.  This parameter must not be modified
    by this method.
    &lt;p&gt;
    @param results the set to contain the the secondary key DatabaseEntry
    objects created by this method.
    &lt;p&gt;
    @throws DatabaseException if an error occurs attempting to create the
    secondary key.
    */
    public void createSecondaryKeys(SecondaryDatabase secondary,
                                    DatabaseEntry key,
                                    DatabaseEntry data,
                                    Set results)
        throws DatabaseException;
}
</pre></body></html>