<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.persist;

import com.sleepycat.db.Database; // for javadoc

/**
 * Determines the file names to use for primary and secondary databases.
 *
 * &lt;p&gt;Each {@link PrimaryIndex} and {@link SecondaryIndex} is represented
 * internally as a Berkeley DB {@link Database}.  The file names of primary and
 * secondary indices must be unique within the environment, so that each index
 * is stored in a separate database file.&lt;/p&gt;
 *
 * &lt;p&gt;By default, the file names of primary and secondary databases are
 * defined as follows.&lt;/p&gt;
 *
 * &lt;p&gt;The syntax of a primary index database file name is:&lt;/p&gt;
 * &lt;pre&gt;   STORE_NAME-ENTITY_CLASS&lt;/pre&gt;
 * &lt;p&gt;Where STORE_NAME is the name parameter passed to {@link
 * EntityStore#EntityStore EntityStore} and ENTITY_CLASS is name of the class
 * passed to {@link EntityStore#getPrimaryIndex getPrimaryIndex}.&lt;/p&gt;
 *
 * &lt;p&gt;The syntax of a secondary index database file name is:&lt;/p&gt;
 * &lt;pre&gt;   STORE_NAME-ENTITY_CLASS-KEY_NAME&lt;/pre&gt;
 * &lt;p&gt;Where KEY_NAME is the secondary key name passed to {@link
 * EntityStore#getSecondaryIndex getSecondaryIndex}.&lt;/p&gt;
 *
 * &lt;p&gt;The default naming described above is implemented by the built-in {@link
 * DatabaseNamer#DEFAULT} object.  An application may supply a custom {@link
 * DatabaseNamer} to overrride the default naming scheme.  For example, a
 * custom namer could place all database files in a subdirectory with the name
 * of the store.  A custom namer could also be used to name files according to
 * specific file system restrictions.&lt;/p&gt;
 *
 * &lt;p&gt;The custom namer object must be an instance of the {@code DatabaseNamer}
 * interface and is configured using {@link StoreConfig#setDatabaseNamer
 * setDatabaseNamer}.&lt;/p&gt;
 *
 * &lt;p&gt;When copying or removing all databases in a store, there is one further
 * consideration.  There are two internal databases that must be kept with the
 * other databases in the store in order for the store to be used.  These
 * contain the data formats and sequences for the store.  Their entity class
 * names are:&lt;/p&gt;
 *
 * &lt;pre&gt;   com.sleepycat.persist.formats&lt;/pre&gt;
 * &lt;pre&gt;   com.sleepycat.persist.sequences&lt;/pre&gt;
 *
 * &lt;p&gt;With default database naming, databases with the following names will be
 * present each store.&lt;/p&gt;
 *
 * &lt;pre&gt;   STORE_NAME-com.sleepycat.persist.formats&lt;/pre&gt;
 * &lt;pre&gt;   STORE_NAME-com.sleepycat.persist.sequences&lt;/pre&gt;
 *
 * &lt;p&gt;These databases must normally be included with copies of other databases
 * in the store.  They should not be modified by the application.&lt;/p&gt;
 */
public interface DatabaseNamer {

    /**
     * Returns the name of the file to be used to store the dataabase for the
     * given store, entity class and key.  This method may not return null.
     *
     * @param storeName the name of the {@link EntityStore}.
     *
     * @param entityClassName the complete name of the entity class for a
     * primary or secondary index.
     *
     * @param keyName the key name identifying a secondary index, or null for
     * a primary index.
     */
    public String getFileName(String storeName,
                              String entityClassName,
                              String keyName);

    /**
     * The default database namer.
     *
     * &lt;p&gt;The {@link #getFileName getFileName} method of this namer returns the
     * {@code storeName}, {@code entityClassName} and {@code keyName}
     * parameters as follows:&lt;p&gt;
     *
     * &lt;pre class="code"&gt;
     * if (keyName != null) {
     *     return storeName + '-' + entityClassName + '-' + keyName;
     * } else {
     *     return storeName + '-' + entityClassName;
     * }&lt;/pre&gt;
     */
    public static final DatabaseNamer DEFAULT = new DatabaseNamer() {

        public String getFileName(String storeName,
                                  String entityClassName,
                                  String keyName) {
            if (keyName != null) {
                return storeName + '-' + entityClassName + '-' + keyName;
            } else {
                return storeName + '-' + entityClassName;
            }
        }
    };
}
</pre></body></html>