com.sun.sgs.impl.service.data.store
Class DataStoreImpl

java.lang.Object
  extended by com.sun.sgs.impl.service.data.store.AbstractDataStore
      extended by com.sun.sgs.impl.service.data.store.DataStoreImpl
All Implemented Interfaces:
DataStore, TransactionParticipant

public class DataStoreImpl
extends AbstractDataStore

Provides an implementation of DataStore based on the database interface layer defined in the com.sun.sgs.service.store.db package.

Note that, although this class provides support for the TransactionParticipant.prepare method, it does not provide facilities for resolving prepared transactions after a crash. Callers can work around this limitation by insuring that the transaction implementation calls TransactionParticipant.prepareAndCommit to commit transactions on this class. The current transaction implementation calls prepareAndCommit on durable participants, such as this class, so the inability to resolve prepared transactions should have no effect at present.

The constructor supports these public properties.

The constructor also passes the properties to the constructor of the DbEnvironment class chosen at runtime with the com.sun.sgs.impl.service.data.store.db.environment.class property. Each implementation of DbEnvironment may support additional properties.

This class uses the Logger named com.sun.sgs.impl.service.data.store.DataStoreImpl to log information at the following logging levels:

In addition, name and object operations that throw TransactionAbortedException will log the failure to the Logger named com.sun.sgs.impl.service.data.store.DataStoreImpl.abort, to make it easier to debug concurrency conflicts.


Nested Class Summary
protected static interface DataStoreImpl.TxnInfoTable<T>
          Records information about all active transactions.
 
Field Summary
static String DEFAULT_ENVIRONMENT_CLASS
          The default environment class.
static String DIRECTORY_PROPERTY
          The property that specifies the directory in which to store database files.
static String ENVIRONMENT_CLASS_PROPERTY
          The property that specifies the environment class.
(package private)  com.sun.sgs.impl.service.data.store.DataStoreImpl.FreeObjectIds freeObjectIds
          Information about free object IDs.
(package private)  DbDatabase oidsDb
          The database that maps object IDs to object bytes.
(package private)  boolean useAllocationBlockPlaceholders
          Whether object allocations should create a placeholder at the end of each allocation block.
 
Fields inherited from class com.sun.sgs.impl.service.data.store.AbstractDataStore
abortLogger, logger, nameAccesses, objectAccesses
 
Constructor Summary
DataStoreImpl(Properties properties, ComponentRegistry systemRegistry, TransactionProxy txnProxy)
          Creates an instance of this class.
 
Method Summary
protected  void abortInternal(Transaction txn)
          Performs the actual operation for abort.
protected  void commitInternal(Transaction txn)
          Performs the actual operation for commit.
protected  long createObjectInternal(Transaction txn)
          Performs the actual operation for createObject.
protected  BindingValue getBindingInternal(Transaction txn, String name)
          Performs the actual operation for getBinding.
protected  int getClassIdInternal(Transaction txn, byte[] classInfo)
          Performs the actual operation for getClassId.
protected  byte[] getClassInfoInternal(Transaction txn, int classId)
          Performs the actual operation for getClassInfo.
protected  long getLocalNodeIdInternal()
          Performs the actual operation for getLocalNodeId.
protected  long getNextTxnId(int count, long timeout)
          Returns the next available transaction ID, and reserves the specified number of IDs.
protected  byte[] getObjectInternal(Transaction txn, long oid, boolean forUpdate)
          Performs the actual operation for getObject.
(package private)  byte[] getObjectRaw(Transaction txn, long oid)
          Get raw data for the specified object ID.
protected
<T> DataStoreImpl.TxnInfoTable<T>
getTxnInfoTable(Class<T> txnInfoType)
          Returns the table that will be used to store transaction information.
protected  RuntimeException handleException(Transaction txn, Level level, RuntimeException e, String operation)
          Performs any operations needed when an exception is going to be thrown, as well as allowing the implementation to replace the exception with a different one.
(package private) static boolean isPlaceholderValue(byte[] value)
          Checks if an object value read from the database is from a placeholder, meaning there is no object present.
protected  void joinNewTransaction(Transaction txn)
          Explicitly joins a new transaction.
protected  void markForUpdateInternal(Transaction txn, long oid)
          Performs the actual operation for markForUpdate.
protected  long newNodeId()
          Returns a new node ID, for use with a newly started node.
protected  String nextBoundNameInternal(Transaction txn, String name)
          Performs the actual operation for nextBoundName.
protected  long nextObjectIdInternal(Transaction txn, long oid)
          Performs the actual operation for nextObjectId.
(package private)  long nextObjectIdRaw(Transaction txn, long oid)
          Gets the next object ID after the one specified, or -1 if there are no more objects.
protected  void prepareAndCommitInternal(Transaction txn)
          Performs the actual operation for prepareAndCommit.
protected  boolean prepareInternal(Transaction txn)
          Performs the actual operation for prepare.
protected  BindingValue removeBindingInternal(Transaction txn, String name)
          Performs the actual operation for removeBinding.
protected  void removeObjectInternal(Transaction txn, long oid)
          Performs the actual operation for removeObject.
protected  BindingValue setBindingInternal(Transaction txn, String name, long oid)
          Performs the actual operation for setBinding.
protected  void setObjectInternal(Transaction txn, long oid, byte[] data)
          Performs the actual operation for setObject.
(package private)  void setObjectRaw(Transaction txn, long oid, byte[] data)
          Store raw data for the specified object ID.
protected  void setObjectsInternal(Transaction txn, long[] oids, byte[][] dataArray)
          Performs the actual operation for setObjects.
protected  void shutdownInternal()
          Performs the actual operation for shutdown.
 String toString()
          Returns a string representation of this object.
 
Methods inherited from class com.sun.sgs.impl.service.data.store.AbstractDataStore
abort, checkOid, commit, createObject, getBinding, getClassId, getClassInfo, getLocalNodeId, getNameForAccess, getObject, getTypeName, markForUpdate, nextBoundName, nextObjectId, prepare, prepareAndCommit, ready, removeBinding, removeObject, reportNameAccess, reportObjectAccess, setBinding, setBindingDescription, setObject, setObjectDescription, setObjects, shutdown
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DIRECTORY_PROPERTY

public static final String DIRECTORY_PROPERTY
The property that specifies the directory in which to store database files.

See Also:
Constant Field Values

ENVIRONMENT_CLASS_PROPERTY

public static final String ENVIRONMENT_CLASS_PROPERTY
The property that specifies the environment class.

See Also:
Constant Field Values

DEFAULT_ENVIRONMENT_CLASS

public static final String DEFAULT_ENVIRONMENT_CLASS
The default environment class.

See Also:
Constant Field Values

oidsDb

final DbDatabase oidsDb
The database that maps object IDs to object bytes.


useAllocationBlockPlaceholders

final boolean useAllocationBlockPlaceholders
Whether object allocations should create a placeholder at the end of each allocation block. These placeholders help to avoid allocation concurrency conflicts when using BDB Java edition.


freeObjectIds

final com.sun.sgs.impl.service.data.store.DataStoreImpl.FreeObjectIds freeObjectIds
Information about free object IDs.

Constructor Detail

DataStoreImpl

public DataStoreImpl(Properties properties,
                     ComponentRegistry systemRegistry,
                     TransactionProxy txnProxy)
Creates an instance of this class. See the class documentation for a list of supported properties.

Parameters:
properties - the properties for configuring this instance
systemRegistry - the registry of available system components
txnProxy - the transaction proxy
Throws:
DataStoreException - if there is a problem with the database
IllegalArgumentException - if any of the properties are invalid, as specified in the class documentation
Method Detail

getLocalNodeIdInternal

protected long getLocalNodeIdInternal()
Performs the actual operation for getLocalNodeId.

Specified by:
getLocalNodeIdInternal in class AbstractDataStore
Returns:
the local node ID

createObjectInternal

protected long createObjectInternal(Transaction txn)
Performs the actual operation for createObject.

Specified by:
createObjectInternal in class AbstractDataStore
Parameters:
txn - the transaction under which the operation should take place
Returns:
the new object ID

markForUpdateInternal

protected void markForUpdateInternal(Transaction txn,
                                     long oid)
Performs the actual operation for markForUpdate.

Specified by:
markForUpdateInternal in class AbstractDataStore
Parameters:
txn - the transaction under which the operation should take place
oid - the object ID

getObjectInternal

protected byte[] getObjectInternal(Transaction txn,
                                   long oid,
                                   boolean forUpdate)
Performs the actual operation for getObject.

Specified by:
getObjectInternal in class AbstractDataStore
Parameters:
txn - the transaction under which the operation should take place
oid - the object ID
forUpdate - whether the caller intends to modify the object
Returns:
the data associated with the object ID

setObjectInternal

protected void setObjectInternal(Transaction txn,
                                 long oid,
                                 byte[] data)
Performs the actual operation for setObject.

Specified by:
setObjectInternal in class AbstractDataStore
Parameters:
txn - the transaction under which the operation should take place
oid - the object ID
data - the data

setObjectsInternal

protected void setObjectsInternal(Transaction txn,
                                  long[] oids,
                                  byte[][] dataArray)
Performs the actual operation for setObjects.

Specified by:
setObjectsInternal in class AbstractDataStore
Parameters:
txn - the transaction under which the operation should take place
oids - the object IDs
dataArray - the associated data values

removeObjectInternal

protected void removeObjectInternal(Transaction txn,
                                    long oid)
Performs the actual operation for removeObject.

Specified by:
removeObjectInternal in class AbstractDataStore
Parameters:
txn - the transaction under which the operation should take place
oid - the object ID

getBindingInternal

protected BindingValue getBindingInternal(Transaction txn,
                                          String name)
Performs the actual operation for getBinding. If the name is bound, the return value contains the object ID that the name is bound to and a next name of null. If the name is not bound, the return value contains an object ID of -1 and the next name found, which may be null.

Specified by:
getBindingInternal in class AbstractDataStore
Parameters:
txn - the transaction under which the operation should take place
name - the name
Returns:
information about the object ID and the next name

setBindingInternal

protected BindingValue setBindingInternal(Transaction txn,
                                          String name,
                                          long oid)
Performs the actual operation for setBinding. If the name is bound, the return value contains an arbitrary non-negative object ID and a next name of null. If the name is not bound, the return value contains an object ID of -1 and the next name found, which may be null.

Specified by:
setBindingInternal in class AbstractDataStore
Parameters:
txn - the transaction under which the operation should take place
name - the name
oid - the object ID
Returns:
information about the old object ID and the next name

removeBindingInternal

protected BindingValue removeBindingInternal(Transaction txn,
                                             String name)
Performs the actual operation for removeBinding. If the name is bound, the return value contains an arbitrary non-negative object ID, otherwise it contains -1. In all cases, the return value contains the next name found, which may be null.

Specified by:
removeBindingInternal in class AbstractDataStore
Parameters:
txn - the transaction under which the operation should take place
name - the name
Returns:
information about the object ID and the next name

nextBoundNameInternal

protected String nextBoundNameInternal(Transaction txn,
                                       String name)
Performs the actual operation for nextBoundName.

This implementation uses a single cursor, so it provides better performance when used to iterate over names in order.

Specified by:
nextBoundNameInternal in class AbstractDataStore
Parameters:
txn - the transaction under which the operation should take place
name - the name to search after, or null to start at the beginning
Returns:
the next name with a binding following name, or null if there are no more bound names

shutdownInternal

protected void shutdownInternal()
Performs the actual operation for shutdown.

Specified by:
shutdownInternal in class AbstractDataStore

getClassIdInternal

protected int getClassIdInternal(Transaction txn,
                                 byte[] classInfo)
Performs the actual operation for getClassId.

Specified by:
getClassIdInternal in class AbstractDataStore
Parameters:
txn - the transaction under which the operation should take place
classInfo - the class information
Returns:
the associated class ID

getClassInfoInternal

protected byte[] getClassInfoInternal(Transaction txn,
                                      int classId)
                               throws ClassInfoNotFoundException
Performs the actual operation for getClassInfo.

Specified by:
getClassInfoInternal in class AbstractDataStore
Parameters:
txn - the transaction under which the operation should take place
classId - the class ID
Returns:
the associated class information
Throws:
ClassInfoNotFoundException - if the ID is not found

nextObjectIdInternal

protected long nextObjectIdInternal(Transaction txn,
                                    long oid)
Performs the actual operation for nextObjectId.

Specified by:
nextObjectIdInternal in class AbstractDataStore
Parameters:
txn - the transaction under which the operation should take place
oid - the identifier of the object to search after, or -1 to request the first object
Returns:
the identifier of the next object following the object with identifier oid, or -1 if there are no more objects

prepareInternal

protected boolean prepareInternal(Transaction txn)
Performs the actual operation for prepare.

Specified by:
prepareInternal in class AbstractDataStore
Parameters:
txn - the transaction
Returns:
true if this participant is read-only, otherwise false

commitInternal

protected void commitInternal(Transaction txn)
Performs the actual operation for commit.

Specified by:
commitInternal in class AbstractDataStore
Parameters:
txn - the transaction

prepareAndCommitInternal

protected void prepareAndCommitInternal(Transaction txn)
Performs the actual operation for prepareAndCommit.

Specified by:
prepareAndCommitInternal in class AbstractDataStore
Parameters:
txn - the transaction

abortInternal

protected void abortInternal(Transaction txn)
Performs the actual operation for abort.

Specified by:
abortInternal in class AbstractDataStore
Parameters:
txn - the transaction

handleException

protected RuntimeException handleException(Transaction txn,
                                           Level level,
                                           RuntimeException e,
                                           String operation)
Performs any operations needed when an exception is going to be thrown, as well as allowing the implementation to replace the exception with a different one.

This implementation does logging, and aborts the transaction if it is not null and the exception is a TransactionAbortedException.

This implementation converts DbDatabaseException to DataStoreException.

Overrides:
handleException in class AbstractDataStore
Parameters:
txn - the transaction or null
level - the logging level
e - the exception
operation - a description of the operation being performed
Returns:
the exception to throw

toString

public String toString()
Returns a string representation of this object.

Overrides:
toString in class Object
Returns:
a string representation of this object

getTxnInfoTable

protected <T> DataStoreImpl.TxnInfoTable<T> getTxnInfoTable(Class<T> txnInfoType)
Returns the table that will be used to store transaction information. Note that this method will be called during instance construction.

Type Parameters:
T - the type of the information to be stored
Parameters:
txnInfoType - a class representing the type of the information to be stored
Returns:
the table

getNextTxnId

protected long getNextTxnId(int count,
                            long timeout)
Returns the next available transaction ID, and reserves the specified number of IDs.

Parameters:
count - the number of IDs to reserve
timeout - the transaction timeout in milliseconds
Returns:
the next available transaction ID

joinNewTransaction

protected void joinNewTransaction(Transaction txn)
Explicitly joins a new transaction.

Parameters:
txn - the transaction to join

newNodeId

protected long newNodeId()
Returns a new node ID, for use with a newly started node.

Returns:
the new node ID

isPlaceholderValue

static boolean isPlaceholderValue(byte[] value)
Checks if an object value read from the database is from a placeholder, meaning there is no object present.


setObjectRaw

void setObjectRaw(Transaction txn,
                  long oid,
                  byte[] data)
Store raw data for the specified object ID. The value is used as the literal data, without checking for placeholders or quoted values. This method is intended for testing.

Parameters:
txn - the transaction under which the operation should take place
oid - the object ID
data - the data

getObjectRaw

byte[] getObjectRaw(Transaction txn,
                    long oid)
Get raw data for the specified object ID. The value returned is the literal data, without checking for placeholders or quoted values. This method is intended for testing.

Parameters:
txn - the transaction under which the operation should take place
oid - the object ID
Returns:
the data or null if the object ID is not found

nextObjectIdRaw

long nextObjectIdRaw(Transaction txn,
                     long oid)
Gets the next object ID after the one specified, or -1 if there are no more objects. If oid is -1, then returns the first object ID. The values for the object IDs will not be checked, so this method can be used to obtain object IDs for placeholders. This method is intended for testing.

Parameters:
txn - the transaction under which the operation should take place
oid - the object ID or -1
Returns:
the next object ID or -1

RedDwarf, Version 0.10.1
2010-03-14 10:56:12

Copyright © 2010 The RedDwarf Authors. All rights reserved
Copyright © 2007-2010 Sun Microsystems, Inc. All rights reserved