Package org.eclipse.jgit.lib
Class ObjectDatabase
- java.lang.Object
-
- org.eclipse.jgit.lib.ObjectDatabase
-
- All Implemented Interfaces:
AutoCloseable
- Direct Known Subclasses:
DfsObjDatabase
,ObjectDirectory
public abstract class ObjectDatabase extends Object implements AutoCloseable
Abstraction of arbitrary object storage.An object database stores one or more Git objects, indexed by their unique
ObjectId
.
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
ObjectDatabase()
Initialize a new database instance for access.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract void
close()
Close any resources held by this database.void
create()
Initialize a new object database at this location.boolean
exists()
Does this database exist yet?abstract long
getApproximateObjectCount()
Get a quick, rough count of objects in this repository.Set<ObjectId>
getShallowCommits()
boolean
has(AnyObjectId objectId)
Does the requested object exist in this database?ObjectDatabase
newCachedDatabase()
Create a new cached database instance over this database.abstract ObjectInserter
newInserter()
Create a newObjectInserter
to insert new objects.abstract ObjectReader
newReader()
Create a newObjectReader
to read existing objects.ObjectLoader
open(AnyObjectId objectId)
Open an object from this database.ObjectLoader
open(AnyObjectId objectId, int typeHint)
Open an object from this database.void
setShallowCommits(Set<ObjectId> shallowCommits)
Update the shallow commits of the current repository
-
-
-
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 IOException
Initialize a new object database at this location.- Throws:
IOException
- the database could not be created.
-
newInserter
public abstract ObjectInserter newInserter()
Create a newObjectInserter
to insert new objects.The returned inserter is not itself thread-safe, but multiple concurrent inserter instances created from the same
ObjectDatabase
must be thread-safe.- Returns:
- writer the caller can use to create objects in this database.
-
newReader
public abstract ObjectReader newReader()
Create a newObjectReader
to read existing objects.The returned reader is not itself thread-safe, but multiple concurrent reader instances created from the same
ObjectDatabase
must be thread-safe.- Returns:
- reader the caller can use to load objects from this database.
-
getShallowCommits
public Set<ObjectId> getShallowCommits() throws IOException
- Returns:
- the shallow commits of the current repository
- Throws:
IOException
- the database could not be read- Since:
- 6.3
-
setShallowCommits
public void setShallowCommits(Set<ObjectId> shallowCommits) throws IOException
Update the shallow commits of the current repository- Parameters:
shallowCommits
- the new shallow commits- Throws:
IOException
- the database could not be updated- Since:
- 6.3
-
close
public abstract void close()
Close any resources held by this database.- Specified by:
close
in interfaceAutoCloseable
-
has
public boolean has(AnyObjectId objectId) throws IOException
Does the requested object exist in this database?This is a one-shot call interface which may be faster than allocating a
newReader()
to perform the lookup.- Parameters:
objectId
- identity of the object to test for existence of.- Returns:
- true if the specified object is stored in this database.
- Throws:
IOException
- the object store cannot be accessed.
-
open
public ObjectLoader open(AnyObjectId objectId) throws IOException
Open an object from this database.This is a one-shot call interface which may be faster than allocating a
newReader()
to perform the lookup.- Parameters:
objectId
- identity of the object to open.- Returns:
- a
ObjectLoader
for accessing the object. - Throws:
MissingObjectException
- the object does not exist.IOException
- the object store cannot be accessed.
-
open
public ObjectLoader open(AnyObjectId objectId, int typeHint) throws MissingObjectException, IncorrectObjectTypeException, IOException
Open an object from this database.This is a one-shot call interface which may be faster than allocating a
newReader()
to perform the lookup.- Parameters:
objectId
- identity of the object to open.typeHint
- hint about the type of object being requested, e.g.Constants.OBJ_BLOB
;ObjectReader.OBJ_ANY
if the object type is not known, or does not matter to the caller.- Returns:
- a
ObjectLoader
for accessing the object. - Throws:
MissingObjectException
- the object does not exist.IncorrectObjectTypeException
- typeHint was not OBJ_ANY, and the object's actual type does not match typeHint.IOException
- the object store cannot be accessed.
-
newCachedDatabase
public ObjectDatabase newCachedDatabase()
Create a new cached database instance over this database. This instance might optimize queries by caching some information about database. So some modifications done after instance creation might fail to be noticed.- Returns:
- new cached database instance
-
getApproximateObjectCount
public abstract long getApproximateObjectCount()
Get a quick, rough count of objects in this repository. Ignores loose objects. Returns-1
if an exception occurs.- Returns:
- quick, rough count of objects in this repository,
-1
if an exception occurs - Since:
- 6.1
-
-