com.sleepycat.persist.impl
Class Store

java.lang.Object
  extended by com.sleepycat.persist.impl.Store

public class Store
extends Object

Base implementation for EntityStore and RawStore. The methods here correspond directly to those in EntityStore; see EntityStore documentation for details.

Author:
Mark Hayes

Nested Class Summary
static interface Store.SyncHook
          For unit testing.
 
Field Summary
static String NAME_SEPARATOR
           
 
Constructor Summary
Store(Environment env, String storeName, StoreConfig config, boolean rawAccess)
           
 
Method Summary
 boolean attemptRefresh()
          Attempts to refresh metadata and returns whether a refresh occurred.
(package private)  void checkEntitySubclassSecondaries(EntityMetadata entityMeta, String subclassName)
          Checks that all secondary indexes defined in the given entity metadata are already open.
 void close()
           
 void closeClass(Class entityClass)
           
 EvolveStats evolve(EvolveConfig config)
           
 StoreConfig getConfig()
           
(package private)  String getDbNameMessage(String[] names)
          Creates a message identifying the database from the pair of strings returned by parseDbName.
 Environment getEnvironment()
           
 EntityModel getModel()
           
 Mutations getMutations()
           
 DatabaseConfig getPrimaryConfig(Class entityClass)
           
<PK,E> PrimaryIndex<PK,E>
getPrimaryIndex(Class<PK> primaryKeyClass, String primaryKeyClassName, Class<E> entityClass, String entityClassName)
          A getPrimaryIndex with extra parameters for opening a raw store.
 SecondaryConfig getSecondaryConfig(Class entityClass, String keyName)
           
<SK,PK,E1,E2 extends E1>
SecondaryIndex<SK,PK,E2>
getSecondaryIndex(PrimaryIndex<PK,E1> primaryIndex, Class<E2> entityClass, String entityClassName, Class<SK> keyClass, String keyClassName, String keyName)
          A getSecondaryIndex with extra parameters for opening a raw store.
 Sequence getSequence(String name)
           
 SequenceConfig getSequenceConfig(String name)
           
 String getStoreName()
           
static Set<String> getStoreNames(Environment env)
           
(package private) static String makePriDbName(String storePrefix, String entityClsName)
           
(package private) static String makeSecDbName(String storePrefix, String entityClsName, String keyName)
           
 String[] parseDbName(String wholeName)
          Parses a whole DB name and returns an array of 2 strings where element 0 is the file name (always null for JE, always non-null for DB core) and element 1 is the logical DB name (always non-null for JE, may be null for DB core).
static String[] parseDbName(String wholeName, DatabaseNamer namer)
          Allows passing a namer to a static method for testing.
(package private)  PersistCatalog refresh(PersistCatalog oldCatalog, int errorFormatId)
          Called via RefreshException.refresh when handling the RefreshException in the binding methods, when a Replica detects that its in-memory metadata is stale.
 void setPrimaryConfig(Class entityClass, DatabaseConfig config)
           
 void setSecondaryConfig(Class entityClass, String keyName, SecondaryConfig config)
           
 void setSequenceConfig(String name, SequenceConfig config)
           
static void setSyncHook(Store.SyncHook hook)
          For unit testing.
 void sync()
           
 void truncateClass(Class entityClass)
           
 void truncateClass(Transaction txn, Class entityClass)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NAME_SEPARATOR

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

Store

public Store(Environment env,
             String storeName,
             StoreConfig config,
             boolean rawAccess)
      throws StoreExistsException,
             StoreNotFoundException,
             IncompatibleClassException,
             DatabaseException
Throws:
StoreExistsException
StoreNotFoundException
IncompatibleClassException
DatabaseException
Method Detail

getEnvironment

public Environment getEnvironment()

getConfig

public StoreConfig getConfig()

getStoreName

public String getStoreName()

getStoreNames

public static Set<String> getStoreNames(Environment env)
                                 throws DatabaseException
Throws:
DatabaseException

getModel

public EntityModel getModel()

getMutations

public Mutations getMutations()

getPrimaryIndex

public <PK,E> PrimaryIndex<PK,E> getPrimaryIndex(Class<PK> primaryKeyClass,
                                                 String primaryKeyClassName,
                                                 Class<E> entityClass,
                                                 String entityClassName)
                                   throws DatabaseException,
                                          IndexNotAvailableException
A getPrimaryIndex with extra parameters for opening a raw store. primaryKeyClass and entityClass are used for generic typing; for a raw store, these should always be Object.class and RawObject.class. primaryKeyClassName is used for consistency checking and should be null for a raw store only. entityClassName is used to identify the store and may not be null.

Throws:
DatabaseException
IndexNotAvailableException

getSecondaryIndex

public <SK,PK,E1,E2 extends E1> SecondaryIndex<SK,PK,E2> getSecondaryIndex(PrimaryIndex<PK,E1> primaryIndex,
                                                                           Class<E2> entityClass,
                                                                           String entityClassName,
                                                                           Class<SK> keyClass,
                                                                           String keyClassName,
                                                                           String keyName)
                                                      throws DatabaseException,
                                                             IndexNotAvailableException
A getSecondaryIndex with extra parameters for opening a raw store. keyClassName is used for consistency checking and should be null for a raw store only.

Throws:
DatabaseException
IndexNotAvailableException

checkEntitySubclassSecondaries

void checkEntitySubclassSecondaries(EntityMetadata entityMeta,
                                    String subclassName)
                              throws DatabaseException
Checks that all secondary indexes defined in the given entity metadata are already open. This method is called when a new entity subclass is encountered when an instance of that class is stored. [#16399]

Throws:
IllegalArgumentException - if a secondary is not open.
DatabaseException

sync

public void sync()
          throws DatabaseException
Throws:
DatabaseException

truncateClass

public void truncateClass(Class entityClass)
                   throws DatabaseException
Throws:
DatabaseException

truncateClass

public void truncateClass(Transaction txn,
                          Class entityClass)
                   throws DatabaseException
Throws:
DatabaseException

closeClass

public void closeClass(Class entityClass)
                throws DatabaseException
Throws:
DatabaseException

close

public void close()
           throws DatabaseException
Throws:
DatabaseException

getSequence

public Sequence getSequence(String name)
                     throws DatabaseException
Throws:
DatabaseException

getSequenceConfig

public SequenceConfig getSequenceConfig(String name)

setSequenceConfig

public void setSequenceConfig(String name,
                              SequenceConfig config)

getPrimaryConfig

public DatabaseConfig getPrimaryConfig(Class entityClass)

setPrimaryConfig

public void setPrimaryConfig(Class entityClass,
                             DatabaseConfig config)

getSecondaryConfig

public SecondaryConfig getSecondaryConfig(Class entityClass,
                                          String keyName)

setSecondaryConfig

public void setSecondaryConfig(Class entityClass,
                               String keyName,
                               SecondaryConfig config)

makePriDbName

static String makePriDbName(String storePrefix,
                            String entityClsName)

makeSecDbName

static String makeSecDbName(String storePrefix,
                            String entityClsName,
                            String keyName)

parseDbName

public String[] parseDbName(String wholeName)
Parses a whole DB name and returns an array of 2 strings where element 0 is the file name (always null for JE, always non-null for DB core) and element 1 is the logical DB name (always non-null for JE, may be null for DB core).


parseDbName

public static String[] parseDbName(String wholeName,
                                   DatabaseNamer namer)
Allows passing a namer to a static method for testing.


getDbNameMessage

String getDbNameMessage(String[] names)
Creates a message identifying the database from the pair of strings returned by parseDbName.


evolve

public EvolveStats evolve(EvolveConfig config)
                   throws DatabaseException
Throws:
DatabaseException

setSyncHook

public static void setSyncHook(Store.SyncHook hook)
For unit testing.


attemptRefresh

public boolean attemptRefresh()
Attempts to refresh metadata and returns whether a refresh occurred. May be called when we expect that updated metadata may be available on disk, and if so could be used to satisfy the user's request. For example, if an index is requested and not available, we can try a refresh and the check for the index again.


refresh

PersistCatalog refresh(PersistCatalog oldCatalog,
                       int errorFormatId)
Called via RefreshException.refresh when handling the RefreshException in the binding methods, when a Replica detects that its in-memory metadata is stale. During refresh, objects that are visible to the user must not be re-created, since the user may have a reference to them. The PersistCatalog is re-created by this method, and the additional objects listed below are refreshed without creating a new instance. The refresh() method of non-indented classes is called, and these methods forward the call to indented classes. PersistCatalog EntityModel PrimaryIndex PersistEntityBinding PersistKeyAssigner SecondaryIndex PersistKeyCreator PersistKeyBinding These objects have volatile catalog and format fields. When a refresh in one thread changes these fields, other threads should notice the changes ASAP. However, it is not necessary that all access to these fields is synchronized. It is Ok for a mix of old and new fields to be used at any point in time. If an old object is used after a refresh, the need for a refresh may be detected, causing another call to this method. In most cases the redundant refresh will be avoided (see check below), but in some cases an extra unnecessary refresh may be performed. This is undesriable, but is not dangerous. Sychrnoization must be avoided to prevent blocking during read/write operations. [#16655]



Copyright (c) 2004-2010 Oracle. All rights reserved.