com.sleepycat.persist.impl
Class PersistCatalog

java.lang.Object
  extended by com.sleepycat.persist.impl.PersistCatalog
All Implemented Interfaces:
Catalog

public class PersistCatalog
extends Object
implements Catalog

The catalog of class formats for a store, along with its associated model and mutations.

Author:
Mark Hayes

Field Summary
static boolean expectNoClassChanges
          Used by unit tests.
static boolean unevolvedFormatsEncountered
           
 
Fields inherited from interface com.sleepycat.persist.impl.Catalog
BETA_VERSION, CURRENT_VERSION
 
Constructor Summary
PersistCatalog(Transaction txn, Environment env, String storePrefix, String dbName, DatabaseConfig dbConfig, EntityModel modelParam, Mutations mutationsParam, boolean rawAccess, Store store)
          Creates a new catalog, opening the database and reading it from a given catalog database if it already exists.
PersistCatalog(Transaction txn, PersistCatalog oldCatalog, String storePrefix)
          Creates a new catalog when a Replica refresh occurs.
 
Method Summary
(package private)  void checkWriteInReplicaUpgradeMode()
          Metadata needs refreshing when a Replica with stale metadata is elected master, and then a user write operation is attempted.
 boolean close()
          Decrements the reference count and closes the catalog DB when it reaches zero.
 Object convertRawObject(RawObject o, IdentityHashMap converted)
           
 Format createFormat(Class type, Map<String,Format> newFormats)
          If the given class format is not already present in the given map and a format for this class name does not already exist, creates an uninitialized format, adds it to the map, and also collects related formats in the map.
 Format createFormat(String clsName, Map<String,Format> newFormats)
          Convenience method that gets the class for the given class name and calls createFormat with the class object.
 void flush()
          Used to write the catalog when a format has been changed, for example, when Store.evolve has updated a Format's EvolveNeeded property.
 List<RawType> getAllRawTypes()
          Returns all formats as RawTypes.
 String getDatabaseClassName(String className)
          Returns the name of an entity class to be used to form the database name.
 String getDatabaseKeyName(String className, String keyName)
          Similar to getDatabaseClassName but instead handles an earlier version of a renamed key.
 void getEntityFormats(Collection<Format> entityFormats)
           
 Format getFormat(Class cls, boolean checkEntitySubclassIndexes)
          Get a format for a given class, creating it if it does not exist.
 Format getFormat(int formatId)
          Returns a format for a given ID, or throws an exception.
 Format getFormat(String className)
          Returns a format by class name.
 int getInitVersion(Format format, boolean forReader)
          When a format is intialized, this method is called to get the version of the serialized object to be initialized.
 Format getLatestVersion(String className)
           
(package private)  Set<String> getModelClasses()
          Returns a set of all persistent (non-simple type) class names.
 Mutations getMutations()
          Returns the current merged mutations.
(package private)  int getNFormats()
          Returns the number of stored formats.
 EntityModel getResolvedModel()
          Returns the model parameter, default model or stored model.
(package private)  Map<Format,Set<Format>> getSubclassMap()
          Returns a map from format to a set of its superclass formats.
 boolean isRawAccess()
           
 boolean isReadOnly()
          Returns true if the user opened the store read-only, or we're running in Replica upgrade mode.
 void openExisting()
          Increments the reference count for a catalog that is already open.
(package private)  void useExistingFormat(Format oldFormat)
          Installs an existing format when no evolution is needed, i.e, when the new and old formats are identical.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

expectNoClassChanges

public static boolean expectNoClassChanges
Used by unit tests.


unevolvedFormatsEncountered

public static boolean unevolvedFormatsEncountered
Constructor Detail

PersistCatalog

public PersistCatalog(Transaction txn,
                      Environment env,
                      String storePrefix,
                      String dbName,
                      DatabaseConfig dbConfig,
                      EntityModel modelParam,
                      Mutations mutationsParam,
                      boolean rawAccess,
                      Store store)
               throws StoreExistsException,
                      StoreNotFoundException,
                      IncompatibleClassException,
                      DatabaseException
Creates a new catalog, opening the database and reading it from a given catalog database if it already exists. All predefined formats and formats for the given model are added. For modified classes, old formats are defined based on the rules for compatible class changes and the given mutations. If any format is changed or added, and the database is not read-only, write the initialized catalog to the database.

Throws:
StoreExistsException
StoreNotFoundException
IncompatibleClassException
DatabaseException

PersistCatalog

PersistCatalog(Transaction txn,
               PersistCatalog oldCatalog,
               String storePrefix)
         throws DatabaseException
Creates a new catalog when a Replica refresh occurs. Uses some information from the old catalog directly in the new catalog, but all formats are created from scratch and class evolution is attempted.

Throws:
DatabaseException
Method Detail

getEntityFormats

public void getEntityFormats(Collection<Format> entityFormats)

getSubclassMap

Map<Format,Set<Format>> getSubclassMap()
Returns a map from format to a set of its superclass formats. The format for simple types, enums and class Object are not included. Only complex types have superclass formats as defined by Format.getSuperFormat.


getResolvedModel

public EntityModel getResolvedModel()
Returns the model parameter, default model or stored model.


openExisting

public void openExisting()
Increments the reference count for a catalog that is already open.


isReadOnly

public boolean isReadOnly()
Returns true if the user opened the store read-only, or we're running in Replica upgrade mode.


close

public boolean close()
              throws DatabaseException
Decrements the reference count and closes the catalog DB when it reaches zero. Returns true if the database was closed or false if the reference count is still non-zero and the database was left open.

Throws:
DatabaseException

getMutations

public Mutations getMutations()
Returns the current merged mutations.


createFormat

public Format createFormat(String clsName,
                           Map<String,Format> newFormats)
Convenience method that gets the class for the given class name and calls createFormat with the class object.

Specified by:
createFormat in interface Catalog
See Also:
createFormat(java.lang.String, java.util.Map)

createFormat

public Format createFormat(Class type,
                           Map<String,Format> newFormats)
If the given class format is not already present in the given map and a format for this class name does not already exist, creates an uninitialized format, adds it to the map, and also collects related formats in the map.

Specified by:
createFormat in interface Catalog
See Also:
createFormat(java.lang.String, java.util.Map)

useExistingFormat

void useExistingFormat(Format oldFormat)
Installs an existing format when no evolution is needed, i.e, when the new and old formats are identical.


getModelClasses

Set<String> getModelClasses()
Returns a set of all persistent (non-simple type) class names.


getAllRawTypes

public List<RawType> getAllRawTypes()
Returns all formats as RawTypes.


getInitVersion

public int getInitVersion(Format format,
                          boolean forReader)
When a format is intialized, this method is called to get the version of the serialized object to be initialized. See Catalog.

Specified by:
getInitVersion in interface Catalog

getFormat

public Format getFormat(int formatId)
Description copied from interface: Catalog
Returns a format for a given ID, or throws an exception. This method is used when reading an object from the byte array format.

Specified by:
getFormat in interface Catalog

getFormat

public Format getFormat(Class cls,
                        boolean checkEntitySubclassIndexes)
Get a format for a given class, creating it if it does not exist.

This method is called for top level entity instances by PersistEntityBinding. When a new entity subclass format is added we call Store.checkEntitySubclassSecondaries to ensure that all secondary databases have been opened, before storing the entity. We do this here while not holding a synchronization mutex, not in addNewFormat, to avoid deadlocks. checkEntitySubclassSecondaries synchronizes on the Store. [#16399]

Historical note: At one time we opened / created the secondary databases rather than requiring the user to open them, see [#15247]. Later we found this to be problematic since a user txn may have locked primary records, see [#16399].

Specified by:
getFormat in interface Catalog
checkEntitySubclassIndexes - is true if we're expecting this format to be an entity subclass and therefore subclass secondary indexes should be opened.

getFormat

public Format getFormat(String className)
Description copied from interface: Catalog
Returns a format by class name. Unlike #getFormat(Class), the format will not be created if it is not already known.

Specified by:
getFormat in interface Catalog

getLatestVersion

public Format getLatestVersion(String className)

getDatabaseClassName

public String getDatabaseClassName(String className)
Returns the name of an entity class to be used to form the database name. Normally this is the same as the class name, but in replica upgrade mode it may be an earlier version of a renamed class. Returns null if there is no stored version of the class. [#16655]


getDatabaseKeyName

public String getDatabaseKeyName(String className,
                                 String keyName)
Similar to getDatabaseClassName but instead handles an earlier version of a renamed key. [#16655]


checkWriteInReplicaUpgradeMode

void checkWriteInReplicaUpgradeMode()
Metadata needs refreshing when a Replica with stale metadata is elected master, and then a user write operation is attempted. [#16655]


flush

public void flush()
           throws DatabaseException
Used to write the catalog when a format has been changed, for example, when Store.evolve has updated a Format's EvolveNeeded property. Uses auto-commit.

Throws:
DatabaseException

getNFormats

int getNFormats()
Returns the number of stored formats.


isRawAccess

public boolean isRawAccess()
Specified by:
isRawAccess in interface Catalog
See Also:
isRawAccess()

convertRawObject

public Object convertRawObject(RawObject o,
                               IdentityHashMap converted)
Specified by:
convertRawObject in interface Catalog
See Also:
convertRawObject(com.sleepycat.persist.raw.RawObject, com.sleepycat.je.utilint.IdentityHashMap)


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