com.sleepycat.persist.impl
Class PersistCatalog

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

public class PersistCatalog
extends java.lang.Object

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


Field Summary
static int BETA_VERSION
           
static int CURRENT_VERSION
           
static boolean expectNoClassChanges
          Used by unit tests.
static boolean unevolvedFormatsEncountered
           
 
Constructor Summary
PersistCatalog(Transaction txn, Environment env, java.lang.String storePrefix, java.lang.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.
 
Method Summary
 boolean close()
          Decrements the reference count and closes the catalog DB when it reaches zero.
 java.lang.Object convertRawObject(RawObject o, java.util.IdentityHashMap converted)
           
 Format createFormat(java.lang.Class type, java.util.Map<java.lang.String,Format> newFormats)
          If the given class format is not already present in the given map, creates an uninitialized format, adds it to the map, and also collects related formats in the map.
 Format createFormat(java.lang.String clsName, java.util.Map<java.lang.String,Format> newFormats)
          Convenience method that gets the class for the given class name and calls createFormat with the class object.
 void dump()
           
 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.
 void getEntityFormats(java.util.Collection<Format> entityFormats)
           
 Format getFormat(java.lang.Class cls)
          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(java.lang.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(java.lang.String className)
           
 Mutations getMutations()
          Returns the current merged mutations.
 EntityModel getResolvedModel()
          Returns the model parameter, default model or stored model.
 boolean isRawAccess()
           
 void openExisting()
          Increments the reference count for a catalog that is already open.
 
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

BETA_VERSION

public static final int BETA_VERSION
See Also:
Constant Field Values

CURRENT_VERSION

public static final int CURRENT_VERSION
See Also:
Constant Field Values
Constructor Detail

PersistCatalog

public PersistCatalog(Transaction txn,
                      Environment env,
                      java.lang.String storePrefix,
                      java.lang.String dbName,
                      DatabaseConfig dbConfig,
                      EntityModel modelParam,
                      Mutations mutationsParam,
                      boolean rawAccess,
                      Store store)
               throws 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:
DatabaseException
Method Detail

getEntityFormats

public void getEntityFormats(java.util.Collection<Format> entityFormats)

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.


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(java.lang.String clsName,
                           java.util.Map<java.lang.String,Format> newFormats)
Convenience method that gets the class for the given class name and calls createFormat with the class object.

See Also:
createFormat(java.lang.String, java.util.Map)

createFormat

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

See Also:
createFormat(java.lang.String, java.util.Map)

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.


getFormat

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


getFormat

public Format getFormat(java.lang.Class cls)
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.openSecondaryIndexes so that previously unknown secondary databases can be created, before storing the entity. We do this here while not holding a synchronization mutex, not in addNewFormat, to avoid deadlocks. openSecondaryIndexes synchronizes on the Store. [#15247]


getFormat

public Format getFormat(java.lang.String className)
Returns a format by class name. Unlike getFormat(Class), the format will not be created if it is not already known.


getLatestVersion

public Format getLatestVersion(java.lang.String className)

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

isRawAccess

public boolean isRawAccess()
See Also:
isRawAccess()

convertRawObject

public java.lang.Object convertRawObject(RawObject o,
                                         java.util.IdentityHashMap converted)
See Also:
convertRawObject(com.sleepycat.persist.raw.RawObject, java.util.IdentityHashMap)

dump

public void dump()