All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.sleepycat.persist.DatabaseNamer Maven / Gradle / Ivy

The newest version!
/*-
 * Copyright (C) 2002, 2018, Oracle and/or its affiliates. All rights reserved.
 *
 * This file was distributed by Oracle as part of a version of Oracle Berkeley
 * DB Java Edition made available at:
 *
 * http://www.oracle.com/technetwork/database/database-technologies/berkeleydb/downloads/index.html
 *
 * Please see the LICENSE file included in the top-level directory of the
 * appropriate version of Oracle Berkeley DB Java Edition for a copy of the
 * license and additional information.
 */

package com.sleepycat.persist;

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

/**
 * 
 * @hidden
 * 
 * Determines the file names to use for primary and secondary databases.
 *
 * 

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.

* *

By default, the file names of primary and secondary databases are * defined as follows.

* *

The syntax of a primary index database file name is:

*
   STORE_NAME-ENTITY_CLASS
*

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}.

* *

The syntax of a secondary index database file name is:

*
   STORE_NAME-ENTITY_CLASS-KEY_NAME
*

Where KEY_NAME is the secondary key name passed to {@link * EntityStore#getSecondaryIndex getSecondaryIndex}.

* *

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.

* *

The custom namer object must be an instance of the {@code DatabaseNamer} * interface and is configured using {@link StoreConfig#setDatabaseNamer * setDatabaseNamer}.

* *

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:

* *
   com.sleepycat.persist.formats
*
   com.sleepycat.persist.sequences
* *

With default database naming, databases with the following names will be * present each store.

* *
   STORE_NAME-com.sleepycat.persist.formats
*
   STORE_NAME-com.sleepycat.persist.sequences
* *

These databases must normally be included with copies of other databases * in the store. They should not be modified by the application.

*/ 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. * * @return the file name. */ public String getFileName(String storeName, String entityClassName, String keyName); /** * The default database namer. * *

The {@link #getFileName getFileName} method of this namer returns the * {@code storeName}, {@code entityClassName} and {@code keyName} * parameters as follows:

* *
     * if (keyName != null) {
     *     return storeName + '-' + entityClassName + '-' + keyName;
     * } else {
     *     return storeName + '-' + entityClassName;
     * }
*/ 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; } } }; }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy