DbStorage
Class DbStorageManager

java.lang.Object
  extended byDbStorage.DbStorageManager

public final class DbStorageManager
extends java.lang.Object

This class works as a intermedite between the high level database data structures and, the Storage and LOG modules. The database storage is compound of 5 segments: dictionary segment, id segment, content segment and LOB segment . This class synchonizes its methods to ensure that the basic I/O database operatios will be athomic.


Field Summary
static int CONTENT_SEGMENT
          The number of the content segment.
static int CONTENT_SEGMENT_UNIT_SIZE
          The size of the units in the content segment
static int DICTIONARY_SEGMENT
          The number of the dictionary segment.
static int DICTIONARY_SEGMENT_UNIT_SIZE
          The size of the units in the dictionary segment
static int ID_SEGMENT
          The number of the id segment.
static int ID_SEGMENT_UNIT_SIZE
          The size of the units in the id segment
static int LOB_SEGMENT
          The number of the LOB segment.
 int LOB_SEGMENT_UNIT_SIZE
          The size of the units in the LOB segment
static int PARENTS_SEGMENT
          The number of the parents' segment.
static int PARENTS_SEGMENT_UNIT_SIZE
          The size of the units in the parents' segment
 
Constructor Summary
DbStorageManager(storage.primitiveStorage.PrimitiveStorageManager psm)
          Creates a new database storage manager.
 
Method Summary
 void addSpecifiedUnit(long transactionNumber, int segmentNumber, DbUnitAddress unitAddress)
          Adds (Occups) a specified unit in the segment.
 void addUnit(long transactionNumber, int segmentNumber, DbUnitAddress newUnitAddress)
          Adds (Occups) a new unit in the segment.
 void addUnitAsCloserAsPosibleOf(long transactionNumber, int segmentNumber, DbUnitAddress unitAddress, DbUnitAddress newUnitAddress)
          Tries to add (Occup) a new unit first in the same page, second in the same space and finally in the same segment of a specified unit.
 void createDefaultSettings(java.io.File dbDirectory)
          Creates a default storage organization for a database.
 void dropUnit(long transactionNumber, int segmentNumber, DbUnitAddress unitAddress)
          Drops (Frees) the specified unit.
 storage.advancedStorage.AdvancedStorageManager getAdvancedStorageManager()
          Returns the underlying advanced storage manager.
 storage.intermediateStorage.IntermediateStorageManager getIntermediateStorageManager()
          Returns the underlying intermediate storage manager.
 int getLobSegmentUnitSize()
          Returns the unit size of LOB segment.
 int getPageSize()
          Returns the used page size.
 int getParentsSegmentUnitSize()
          Returns the unit size of Parents' segment.
 storage.primitiveStorage.PrimitiveStorageManager getPrimitiveStorageManager()
          Returns the underlying primitive storage manager.
 storage.tools.StorageToolsManager getStorageToolsManager()
          Returns the underlying storage tools' manager.
 storage.UnitsStorageManager getUnitsStorageManager()
          Returns the underlying units' storage manager.
 boolean isFreeUnit(long transactionNumber, int segmentNumber, DbUnitAddress unitAddress)
          Checks if a unit is free.
 boolean isOccupiedUnit(long transactionNumber, int segmentNumber, DbUnitAddress unitAddress)
          Checks if a unit is occupied.
 byte readByte(long transactionNumber, int segmentNumber, DbUnitAddress unitAddress, int unitOffset)
          Reads a byte inside a unit.
 char readChar(long transactionNumber, int segmentNumber, DbUnitAddress unitAddress, int unitOffset)
          Reads a char inside a unit.
 void readDbUnitAddress(long transactionNumber, int segmentNumber, DbUnitAddress unitAddress, int unitOffset, DbUnitAddress newUnitAddress)
          Reads a DbUnitAddress inside a unit.
 double readDouble(long transactionNumber, int segmentNumber, DbUnitAddress unitAddress, int unitOffset)
          Reads a double inside a unit.
 int readInt(long transactionNumber, int segmentNumber, DbUnitAddress unitAddress, int unitOffset)
          Reads a int inside a unit.
 long readLong(long transactionNumber, int segmentNumber, DbUnitAddress unitAddress, int unitOffset)
          Reads a long inside a unit.
 void readUnit(long transactionNumber, int segmentNumber, DbUnitAddress unitAddress, byte[] b, int off)
          Reads fully a unit.
 void readUnit(long transactionNumber, int segmentNumber, DbUnitAddress unitAddress, int unitOffset, int length, byte[] b, int off)
          Reads partially a unit starting from an offset and reading a specific length.
 void writeByte(long transactionNumber, int segmentNumber, DbUnitAddress unitAddress, int unitOffset, byte b)
          Writes a byte into a unit starting from an offset.
 void writeChar(long transactionNumber, int segmentNumber, DbUnitAddress unitAddress, int unitOffset, char c)
          Writes a char into a unit starting from an offset.
 void writeDbUnitAddress(long transactionNumber, int segmentNumber, DbUnitAddress unitAddress, int unitOffset, DbUnitAddress newUnitAddress)
          Writes a DbUnitAddress into a unit starting from an offset.
 void writeDouble(long transactionNumber, int segmentNumber, DbUnitAddress unitAddress, int unitOffset, double d)
          Writes a double into a unit starting from an offset.
 void writeInt(long transactionNumber, int segmentNumber, DbUnitAddress unitAddress, int unitOffset, int i)
          Writes a int into a unit starting from an offset.
 void writeLong(long transactionNumber, int segmentNumber, DbUnitAddress unitAddress, int unitOffset, long l)
          Writes a long into a unit starting from an offset.
 void writeUnit(long transactionNumber, int segmentNumber, DbUnitAddress unitAddress, byte[] b, int off)
          Writes fully a unit.
 void writeUnit(long transactionNumber, int segmentNumber, DbUnitAddress unitAddress, int unitOffset, int length, byte[] b, int off)
          Writes partially a unit starting from an offset and writing a specific length of bytes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ID_SEGMENT

public static final int ID_SEGMENT
The number of the id segment.

See Also:
Constant Field Values

CONTENT_SEGMENT

public static final int CONTENT_SEGMENT
The number of the content segment.

See Also:
Constant Field Values

LOB_SEGMENT

public static final int LOB_SEGMENT
The number of the LOB segment.

See Also:
Constant Field Values

PARENTS_SEGMENT

public static final int PARENTS_SEGMENT
The number of the parents' segment.

See Also:
Constant Field Values

DICTIONARY_SEGMENT

public static final int DICTIONARY_SEGMENT
The number of the dictionary segment.

See Also:
Constant Field Values

ID_SEGMENT_UNIT_SIZE

public static final int ID_SEGMENT_UNIT_SIZE
The size of the units in the id segment

See Also:
Constant Field Values

CONTENT_SEGMENT_UNIT_SIZE

public static final int CONTENT_SEGMENT_UNIT_SIZE
The size of the units in the content segment

See Also:
Constant Field Values

LOB_SEGMENT_UNIT_SIZE

public int LOB_SEGMENT_UNIT_SIZE
The size of the units in the LOB segment


PARENTS_SEGMENT_UNIT_SIZE

public static final int PARENTS_SEGMENT_UNIT_SIZE
The size of the units in the parents' segment

See Also:
Constant Field Values

DICTIONARY_SEGMENT_UNIT_SIZE

public static final int DICTIONARY_SEGMENT_UNIT_SIZE
The size of the units in the dictionary segment

See Also:
Constant Field Values
Constructor Detail

DbStorageManager

public DbStorageManager(storage.primitiveStorage.PrimitiveStorageManager psm)
                 throws TooSmallPageSizeException
Creates a new database storage manager. Sets the underlying advanced storage manager according to the database needs.

Method Detail

addUnit

public void addUnit(long transactionNumber,
                    int segmentNumber,
                    DbUnitAddress newUnitAddress)
             throws storage.StorageException,
                    java.io.IOException
Adds (Occups) a new unit in the segment.

Parameters:
transactionNumber - The number of transaction.
segmentNumber - The number of the segment.
newUnitAddress - Where the address of the new unit will be stored.
Throws:
storage.StorageException
java.io.IOException

addUnitAsCloserAsPosibleOf

public void addUnitAsCloserAsPosibleOf(long transactionNumber,
                                       int segmentNumber,
                                       DbUnitAddress unitAddress,
                                       DbUnitAddress newUnitAddress)
                                throws storage.StorageException,
                                       java.io.IOException
Tries to add (Occup) a new unit first in the same page, second in the same space and finally in the same segment of a specified unit.

Parameters:
transactionNumber - The number of transaction.
segmentNumber - The number of the segment of the close unit.
unitAddress - The address of the close unit in the segment.
newUnitAddress - Where the address of the new unit will be stored.
Throws:
storage.StorageException
java.io.IOException

addSpecifiedUnit

public void addSpecifiedUnit(long transactionNumber,
                             int segmentNumber,
                             DbUnitAddress unitAddress)
                      throws storage.StorageException,
                             java.io.IOException
Adds (Occups) a specified unit in the segment.

Parameters:
transactionNumber - The number of transaction.
segmentNumber - The number of the segment.
unitAddress - The address of the unit to ocup.
Throws:
storage.StorageException
java.io.IOException

dropUnit

public void dropUnit(long transactionNumber,
                     int segmentNumber,
                     DbUnitAddress unitAddress)
              throws storage.StorageException,
                     java.io.IOException
Drops (Frees) the specified unit.

Parameters:
transactionNumber - The number of transaction.
segmentNumber - The number of the segment.
unitAddress - The address of the unit in the segment.
Throws:
storage.StorageException
java.io.IOException

readUnit

public void readUnit(long transactionNumber,
                     int segmentNumber,
                     DbUnitAddress unitAddress,
                     byte[] b,
                     int off)
              throws storage.StorageException,
                     java.io.IOException
Reads fully a unit. This method does not consider anything about the free status of the unit.

Parameters:
transactionNumber - The number of transaction.
segmentNumber - The number of the segment.
unitAddress - The address of the unit in the segment.
b - The byte array which the content of the readed unit will be stored.
off - The offset of b from which the readed content will be stored.
Throws:
storage.StorageException
java.io.IOException

readUnit

public void readUnit(long transactionNumber,
                     int segmentNumber,
                     DbUnitAddress unitAddress,
                     int unitOffset,
                     int length,
                     byte[] b,
                     int off)
              throws storage.StorageException,
                     java.io.IOException
Reads partially a unit starting from an offset and reading a specific length. This method does not consider anything about the free status of the unit.

Parameters:
transactionNumber - The number of transaction.
segmentNumber - The number of the segment.
unitAddress - The address of the unit in the segment.
unitOffset - The position of the unit from which the reading starts.
length - The number of bytes to be readed.
b - The byte array which the content of the readed unit will be stored.
off - The offset of b from which the readed content will be stored.
Throws:
storage.StorageException
java.io.IOException

writeUnit

public void writeUnit(long transactionNumber,
                      int segmentNumber,
                      DbUnitAddress unitAddress,
                      byte[] b,
                      int off)
               throws storage.StorageException,
                      java.io.IOException
Writes fully a unit. This method does not consider anything about the free status of the unit.

Parameters:
transactionNumber - The number of transaction.
segmentNumber - The number of the segment.
unitAddress - The address of the unit in the segment.
b - The byte array from which the units's content will be get.
off - The offset of b from which the unit's content will be get.
Throws:
storage.StorageException
java.io.IOException

writeUnit

public void writeUnit(long transactionNumber,
                      int segmentNumber,
                      DbUnitAddress unitAddress,
                      int unitOffset,
                      int length,
                      byte[] b,
                      int off)
               throws storage.StorageException,
                      java.io.IOException
Writes partially a unit starting from an offset and writing a specific length of bytes. This method does not consider anything about the free status of the unit.

Parameters:
transactionNumber - The number of transaction.
segmentNumber - The number of the segment.
unitAddress - The address of the unit in the segment.
unitOffset - The position of the unit from which the writing starts.
length - The number of bytes to be wrote.
b - The byte array from which the units's content will be get.
off - The offset of b from which the unit's content will be get.
Throws:
storage.StorageException
java.io.IOException

isFreeUnit

public boolean isFreeUnit(long transactionNumber,
                          int segmentNumber,
                          DbUnitAddress unitAddress)
                   throws storage.StorageException,
                          java.io.IOException
Checks if a unit is free.

Parameters:
transactionNumber - The number of transaction.
segmentNumber - The number of the segment.
unitAddress - The address of the unit in the segment.
Returns:
true if the specified unit is free, false otherwise.
Throws:
storage.StorageException
java.io.IOException

isOccupiedUnit

public boolean isOccupiedUnit(long transactionNumber,
                              int segmentNumber,
                              DbUnitAddress unitAddress)
                       throws storage.StorageException,
                              java.io.IOException
Checks if a unit is occupied.

Parameters:
transactionNumber - The number of transaction.
segmentNumber - The number of the segment.
unitAddress - The address of the unit in the segment.
Returns:
true if the specified unit is occupied, false otherwise.
Throws:
storage.StorageException
java.io.IOException

readByte

public byte readByte(long transactionNumber,
                     int segmentNumber,
                     DbUnitAddress unitAddress,
                     int unitOffset)
              throws storage.StorageException,
                     java.io.IOException
Reads a byte inside a unit.

Parameters:
transactionNumber - The number of transaction.
segmentNumber - The number of the segment.
unitAddress - The address of the unit in the segment.
unitOffset - The position of the byte in the unit.
Returns:
The byte in the specified page's position.
Throws:
storage.StorageException
java.io.IOException

readChar

public char readChar(long transactionNumber,
                     int segmentNumber,
                     DbUnitAddress unitAddress,
                     int unitOffset)
              throws storage.StorageException,
                     java.io.IOException
Reads a char inside a unit.

Parameters:
transactionNumber - The number of transaction.
segmentNumber - The number of the segment.
unitAddress - The address of the unit in the segment.
unitOffset - The position of the char in the unit.
Returns:
The char in the specified page's position.
Throws:
storage.StorageException
java.io.IOException

readInt

public int readInt(long transactionNumber,
                   int segmentNumber,
                   DbUnitAddress unitAddress,
                   int unitOffset)
            throws storage.StorageException,
                   java.io.IOException
Reads a int inside a unit.

Parameters:
transactionNumber - The number of transaction.
segmentNumber - The number of the segment.
unitAddress - The address of the unit in the segment.
unitOffset - The position of the int in the unit.
Returns:
The int in the specified page's position.
Throws:
storage.StorageException
java.io.IOException

readLong

public long readLong(long transactionNumber,
                     int segmentNumber,
                     DbUnitAddress unitAddress,
                     int unitOffset)
              throws storage.StorageException,
                     java.io.IOException
Reads a long inside a unit.

Parameters:
transactionNumber - The number of transaction.
segmentNumber - The number of the segment.
unitAddress - The address of the unit in the segment.
unitOffset - The position of the long in the unit.
Returns:
The long in the specified page's position.
Throws:
storage.StorageException
java.io.IOException

readDouble

public double readDouble(long transactionNumber,
                         int segmentNumber,
                         DbUnitAddress unitAddress,
                         int unitOffset)
                  throws storage.StorageException,
                         java.io.IOException
Reads a double inside a unit.

Parameters:
transactionNumber - The number of transaction.
segmentNumber - The number of the segment.
unitAddress - The address of the unit in the segment.
unitOffset - The position of the double in the unit.
Returns:
The double in the specified page's position.
Throws:
storage.StorageException
java.io.IOException

readDbUnitAddress

public void readDbUnitAddress(long transactionNumber,
                              int segmentNumber,
                              DbUnitAddress unitAddress,
                              int unitOffset,
                              DbUnitAddress newUnitAddress)
                       throws storage.StorageException,
                              java.io.IOException
Reads a DbUnitAddress inside a unit.

Parameters:
transactionNumber - The number of transaction.
segmentNumber - The number of the segment.
unitAddress - The address of the unit in the segment.
unitOffset - The position of the DbUnitAddress in the unit.
newUnitAddress - The DbUnitAddress in the specified page's position.
Throws:
storage.StorageException
java.io.IOException

writeByte

public void writeByte(long transactionNumber,
                      int segmentNumber,
                      DbUnitAddress unitAddress,
                      int unitOffset,
                      byte b)
               throws storage.StorageException,
                      java.io.IOException
Writes a byte into a unit starting from an offset.

Parameters:
transactionNumber - The number of transaction.
segmentNumber - The number of the segment.
unitAddress - The address of the unit in the segment.
unitOffset - The position of the unit from which the writing starts.
b - The byte to be wrote.
Throws:
storage.StorageException
java.io.IOException

writeChar

public void writeChar(long transactionNumber,
                      int segmentNumber,
                      DbUnitAddress unitAddress,
                      int unitOffset,
                      char c)
               throws storage.StorageException,
                      java.io.IOException
Writes a char into a unit starting from an offset.

Parameters:
transactionNumber - The number of transaction.
segmentNumber - The number of the segment.
unitAddress - The address of the unit in the segment.
unitOffset - The position of the unit from which the writing starts.
c - The char to be wrote.
Throws:
storage.StorageException
java.io.IOException

writeInt

public void writeInt(long transactionNumber,
                     int segmentNumber,
                     DbUnitAddress unitAddress,
                     int unitOffset,
                     int i)
              throws storage.StorageException,
                     java.io.IOException
Writes a int into a unit starting from an offset.

Parameters:
transactionNumber - The number of transaction.
segmentNumber - The number of the segment.
unitAddress - The address of the unit in the segment.
unitOffset - The position of the unit from which the writing starts.
i - The int to be wrote.
Throws:
storage.StorageException
java.io.IOException

writeLong

public void writeLong(long transactionNumber,
                      int segmentNumber,
                      DbUnitAddress unitAddress,
                      int unitOffset,
                      long l)
               throws storage.StorageException,
                      java.io.IOException
Writes a long into a unit starting from an offset.

Parameters:
transactionNumber - The number of transaction.
segmentNumber - The number of the segment.
unitAddress - The address of the unit in the segment.
unitOffset - The position of the unit from which the writing starts.
l - The long to be wrote.
Throws:
storage.StorageException
java.io.IOException

writeDouble

public void writeDouble(long transactionNumber,
                        int segmentNumber,
                        DbUnitAddress unitAddress,
                        int unitOffset,
                        double d)
                 throws storage.StorageException,
                        java.io.IOException
Writes a double into a unit starting from an offset.

Parameters:
transactionNumber - The number of transaction.
segmentNumber - The number of the segment.
unitAddress - The address of the unit in the segment.
unitOffset - The position of the unit from which the writing starts.
d - The double to be written.
Throws:
storage.StorageException
java.io.IOException

writeDbUnitAddress

public void writeDbUnitAddress(long transactionNumber,
                               int segmentNumber,
                               DbUnitAddress unitAddress,
                               int unitOffset,
                               DbUnitAddress newUnitAddress)
                        throws storage.StorageException,
                               java.io.IOException
Writes a DbUnitAddress into a unit starting from an offset.

Parameters:
transactionNumber - The number of transaction.
segmentNumber - The number of the segment.
unitAddress - The address of the unit in the segment.
unitOffset - The position of the unit from which the writing starts.
newUnitAddress - The DbUnitAddress to be wrote.
Throws:
storage.StorageException
java.io.IOException

createDefaultSettings

public void createDefaultSettings(java.io.File dbDirectory)
                           throws storage.primitiveStorage.PrimitiveStorageException,
                                  storage.intermediateStorage.IntermediateStorageException,
                                  storage.advancedStorage.AdvancedStorageException,
                                  java.io.IOException
Creates a default storage organization for a database.

Throws:
storage.primitiveStorage.PrimitiveStorageException
storage.intermediateStorage.IntermediateStorageException
storage.advancedStorage.AdvancedStorageException
java.io.IOException

getAdvancedStorageManager

public storage.advancedStorage.AdvancedStorageManager getAdvancedStorageManager()
Returns the underlying advanced storage manager.


getIntermediateStorageManager

public storage.intermediateStorage.IntermediateStorageManager getIntermediateStorageManager()
Returns the underlying intermediate storage manager.


getPrimitiveStorageManager

public storage.primitiveStorage.PrimitiveStorageManager getPrimitiveStorageManager()
Returns the underlying primitive storage manager.


getUnitsStorageManager

public storage.UnitsStorageManager getUnitsStorageManager()
Returns the underlying units' storage manager.


getStorageToolsManager

public storage.tools.StorageToolsManager getStorageToolsManager()
Returns the underlying storage tools' manager.


getLobSegmentUnitSize

public int getLobSegmentUnitSize()
Returns the unit size of LOB segment.


getParentsSegmentUnitSize

public int getParentsSegmentUnitSize()
Returns the unit size of Parents' segment.


getPageSize

public int getPageSize()
Returns the used page size.