org.eclipse.jgit.lib
Class ObjectDatabase

java.lang.Object
  extended by org.eclipse.jgit.lib.ObjectDatabase
Direct Known Subclasses:
AlternateRepositoryDatabase, ObjectDirectory

public abstract class ObjectDatabase
extends java.lang.Object

Abstraction of arbitrary object storage.

An object database stores one or more Git objects, indexed by their unique ObjectId. Optionally an object database can reference one or more alternates; other ObjectDatabase instances that are searched in addition to the current database.

Databases are usually divided into two halves: a half that is considered to be fast to search, and a half that is considered to be slow to search. When alternates are present the fast half is fully searched (recursively through all alternates) before the slow half is considered.


Field Summary
protected static ObjectDatabase[] NO_ALTERNATES
          Constant indicating no alternate databases exist.
 
Constructor Summary
protected ObjectDatabase()
          Initialize a new database instance for access.
 
Method Summary
 void close()
          Close any resources held by this database and its active alternates.
 void closeAlternates()
          Fully close all loaded alternates and clear the alternate list.
protected  void closeAlternates(ObjectDatabase[] alt)
          Close the list of alternates returned by loadAlternates().
 void closeSelf()
          Close any resources held by this database only; ignoring alternates.
 void create()
          Initialize a new object database at this location.
 boolean exists()
          Does this database exist yet?
 ObjectDatabase[] getAlternates()
          Get the alternate databases known to this database.
 boolean hasObject(AnyObjectId objectId)
          Does the requested object exist in this database?
protected abstract  boolean hasObject1(AnyObjectId objectId)
          Fast half of hasObject(AnyObjectId).
protected  boolean hasObject2(java.lang.String objectName)
          Slow half of hasObject(AnyObjectId).
protected  ObjectDatabase[] loadAlternates()
          Load the list of alternate databases into memory.
 ObjectLoader openObject(WindowCursor curs, AnyObjectId objectId)
          Open an object from this database.
protected abstract  ObjectLoader openObject1(WindowCursor curs, AnyObjectId objectId)
          Fast half of openObject(WindowCursor, AnyObjectId).
protected  ObjectLoader openObject2(WindowCursor curs, java.lang.String objectName, AnyObjectId objectId)
          Slow half of openObject(WindowCursor, AnyObjectId).
protected  boolean tryAgain1()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NO_ALTERNATES

protected static final ObjectDatabase[] NO_ALTERNATES
Constant indicating no alternate databases exist.

Constructor Detail

ObjectDatabase

protected ObjectDatabase()
Initialize a new database instance for access.

Method Detail

exists

public boolean exists()
Does this database exist yet?

Returns:
true if this database is already created; false if the caller should invoke create() to create this database location.

create

public void create()
            throws java.io.IOException
Initialize a new object database at this location.

Throws:
java.io.IOException - the database could not be created.

close

public final void close()
Close any resources held by this database and its active alternates.


closeSelf

public void closeSelf()
Close any resources held by this database only; ignoring alternates.

To fully close this database and its referenced alternates, the caller should instead invoke close().


closeAlternates

public final void closeAlternates()
Fully close all loaded alternates and clear the alternate list.


hasObject

public final boolean hasObject(AnyObjectId objectId)
Does the requested object exist in this database?

Alternates (if present) are searched automatically.

Parameters:
objectId - identity of the object to test for existence of.
Returns:
true if the specified object is stored in this database, or any of the alternate databases.

hasObject1

protected abstract boolean hasObject1(AnyObjectId objectId)
Fast half of hasObject(AnyObjectId).

Parameters:
objectId - identity of the object to test for existence of.
Returns:
true if the specified object is stored in this database.

hasObject2

protected boolean hasObject2(java.lang.String objectName)
Slow half of hasObject(AnyObjectId).

Parameters:
objectName - identity of the object to test for existence of.
Returns:
true if the specified object is stored in this database.

openObject

public final ObjectLoader openObject(WindowCursor curs,
                                     AnyObjectId objectId)
                              throws java.io.IOException
Open an object from this database.

Alternates (if present) are searched automatically.

Parameters:
curs - temporary working space associated with the calling thread.
objectId - identity of the object to open.
Returns:
a ObjectLoader for accessing the data of the named object, or null if the object does not exist.
Throws:
java.io.IOException

openObject1

protected abstract ObjectLoader openObject1(WindowCursor curs,
                                            AnyObjectId objectId)
                                     throws java.io.IOException
Fast half of openObject(WindowCursor, AnyObjectId).

Parameters:
curs - temporary working space associated with the calling thread.
objectId - identity of the object to open.
Returns:
a ObjectLoader for accessing the data of the named object, or null if the object does not exist.
Throws:
java.io.IOException

openObject2

protected ObjectLoader openObject2(WindowCursor curs,
                                   java.lang.String objectName,
                                   AnyObjectId objectId)
                            throws java.io.IOException
Slow half of openObject(WindowCursor, AnyObjectId).

Parameters:
curs - temporary working space associated with the calling thread.
objectName - name of the object to open.
objectId - identity of the object to open.
Returns:
a ObjectLoader for accessing the data of the named object, or null if the object does not exist.
Throws:
java.io.IOException

tryAgain1

protected boolean tryAgain1()
Returns:
true if the fast-half search should be tried again.

getAlternates

public final ObjectDatabase[] getAlternates()
Get the alternate databases known to this database.

Returns:
the alternate list. Never null, but may be an empty array.

loadAlternates

protected ObjectDatabase[] loadAlternates()
                                   throws java.io.IOException
Load the list of alternate databases into memory.

This method is invoked by getAlternates() if the alternate list has not yet been populated, or if closeAlternates() has been called on this instance and the alternate list is needed again.

If the alternate array is empty, implementors should consider using the constant NO_ALTERNATES.

Returns:
the alternate list for this database.
Throws:
java.io.IOException - the alternate list could not be accessed. The empty alternate array NO_ALTERNATES will be assumed by the caller.

closeAlternates

protected void closeAlternates(ObjectDatabase[] alt)
Close the list of alternates returned by loadAlternates().

Parameters:
alt - the alternate list, from loadAlternates().