public class Nitrite
extends java.lang.Object
implements java.io.Closeable
An in-memory, single-file based embedded nosql persistent document store. The store can contains multiple named document collections.
It supports following features:
Embedded key-value/document and object store
In-memory or single data file
Very fast and lightweight MongoDB like API
Indexing
Full text search capability
Full Android compatibility
Observable store
Both way replication via Nitrite DataGate server
|
NitriteBuilder
Modifier and Type | Method and Description |
---|---|
static NitriteBuilder |
builder()
Provides a builder utility to create a
Nitrite database
instance. |
void |
close()
Closes the database.
|
void |
commit()
Commits the changes.
|
void |
compact()
Compacts store by moving all chunks next to each other.
|
NitriteCollection |
getCollection(java.lang.String name)
Opens a named collection from the store.
|
NitriteContext |
getContext()
Provides contextual information for the nitrite database instance.
|
<T> ObjectRepository<T> |
getRepository(java.lang.Class<T> type)
Opens a type-safe object repository from the store.
|
boolean |
hasCollection(java.lang.String name)
Checks whether a particular
NitriteCollection exists in the store. |
<T> boolean |
hasRepository(java.lang.Class<T> type)
Checks whether a particular
ObjectRepository exists in the store. |
boolean |
hasUnsavedChanges()
Checks whether the store has any unsaved changes.
|
boolean |
isClosed()
Checks whether the store is closed.
|
java.util.Set<java.lang.String> |
listCollectionNames()
Gets the set of all
NitriteCollection s' names saved in the store. |
java.util.Set<java.lang.String> |
listRepositories()
Gets the set of all fully qualified class names corresponding
to all
ObjectRepository s in the store. |
boolean |
validateUser(java.lang.String userId,
java.lang.String password)
Checks if a specific username and password combination is valid to access
the database.
|
public static NitriteBuilder builder()
Provides a builder utility to create a Nitrite
database
instance.
NitriteBuilder
instance.public NitriteCollection getCollection(java.lang.String name)
Opens a named collection from the store. If the collections does not exist it will be created automatically and returned. If a collection is already opened, it is returned as is. Returned collection is thread-safe for concurrent use.
The name can not contain below reserved strings: |
name
- the name of the collectionNitriteCollection
public <T> ObjectRepository<T> getRepository(java.lang.Class<T> type)
Opens a type-safe object repository from the store. If the repository does not exist it will be created automatically and returned. If a repository is already opened, it is returned as is.
Returned repository is thread-safe for concurrent use. |
T
- the type parametertype
- the type of the objectT
.ObjectRepository
public java.util.Set<java.lang.String> listCollectionNames()
Gets the set of all NitriteCollection
s' names saved in the store.
public java.util.Set<java.lang.String> listRepositories()
Gets the set of all fully qualified class names corresponding
to all ObjectRepository
s in the store.
public boolean hasCollection(java.lang.String name)
Checks whether a particular NitriteCollection
exists in the store.
name
- the name of the collection.true
if the collection exists; otherwise false
.public <T> boolean hasRepository(java.lang.Class<T> type)
Checks whether a particular ObjectRepository
exists in the store.
T
- the type parametertype
- the type of the objecttrue
if the repository exists; otherwise false
.public boolean hasUnsavedChanges()
Checks whether the store has any unsaved changes.
true
if there are unsaved changes; otherwise false
.public void compact()
Compacts store by moving all chunks next to each other.
public void commit()
Commits the changes. For file based store, it saves the changes to disk if there are any unsaved changes.
No need to call it after every change, if auto-commit is not disabled while opening the db. However, it may still be called to flush all changes to disk. |
public void close()
Closes the database. Unsaved changes are written to disk and compacted first for a file based store.
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
public boolean isClosed()
Checks whether the store is closed.
true
if closed; otherwise false
.public boolean validateUser(java.lang.String userId, java.lang.String password)
Checks if a specific username and password combination is valid to access the database.
userId
- the user idpassword
- the passwordtrue
if valid; otherwise false
.@Generated(value="lombok") public NitriteContext getContext()
Provides contextual information for the nitrite database instance.