org.ejdb.driver
Class EJDB

java.lang.Object
  extended by org.ejdb.driver.EJDB

public class EJDB
extends java.lang.Object

Version:
$Id$
Author:
Tyutyunkov Vyacheslav (tve@softmotions.com)

Field Summary
static int JBO_DEFAULT
          Default open mode
static int JBOCREAT
          Create if db file not exists.
static int JBOLCKNB
          Lock without blocking.
static int JBONOLCK
          Open without locking.
static int JBOREADER
          Open as a reader.
static int JBOTRUNC
          Truncate db on open.
static int JBOTSYNC
          Synchronize every transaction.
static int JBOWRITER
          Open as a writer.
 
Constructor Summary
EJDB()
           
 
Method Summary
 void close()
          Close database.
 void dropCollection(java.lang.String cname)
          Drop collection by name.
 void dropCollection(java.lang.String cname, boolean prune)
          Drop collection.
 EJDBCollection ensureCollection(java.lang.String cname)
          Automatically creates new collection if it does't exists with using default collection options
 EJDBCollection ensureCollection(java.lang.String cname, EJDBCollection.Options opts)
          Automatically creates new collection if it does't exists.
 BSONObject executeCommand(BSONObject command)
          Executes ejdb database command.
protected  void finalize()
          
 EJDBCollection getCollection(java.lang.String cname)
          Returns collection object (without automatical creation)
 EJDBCollection getCollection(java.lang.String cname, boolean ecreate)
          Returns collection object
 EJDBCollection getCollection(java.lang.String cname, boolean ecreate, EJDBCollection.Options opts)
          Returns collection object
 java.util.Collection<java.lang.String> getCollectionNames()
          Returns names of existed collections
 java.util.Collection<EJDBCollection> getCollections()
          Returns collection objects for all existed collections
 java.lang.String getPath()
          Returns EJDB path
 boolean isOpen()
          Check if database in opened state.
 void open(java.lang.String path)
          Open database using default open mode.
 void open(java.lang.String path, int mode)
          Open database.
 void sync()
          Synchronize entire EJDB database and all its collections with storage.
 java.lang.String toString()
          
 void updateMeta()
          Update description of EJDB database and its collections.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

JBOREADER

public static final int JBOREADER
Open as a reader.

See Also:
Constant Field Values

JBOWRITER

public static final int JBOWRITER
Open as a writer.

See Also:
Constant Field Values

JBOCREAT

public static final int JBOCREAT
Create if db file not exists.

See Also:
Constant Field Values

JBOTRUNC

public static final int JBOTRUNC
Truncate db on open.

See Also:
Constant Field Values

JBONOLCK

public static final int JBONOLCK
Open without locking.

See Also:
Constant Field Values

JBOLCKNB

public static final int JBOLCKNB
Lock without blocking.

See Also:
Constant Field Values

JBOTSYNC

public static final int JBOTSYNC
Synchronize every transaction.

See Also:
Constant Field Values

JBO_DEFAULT

public static final int JBO_DEFAULT
Default open mode

See Also:
Constant Field Values
Constructor Detail

EJDB

public EJDB()
Method Detail

getPath

public java.lang.String getPath()
Returns EJDB path

Returns:
EJDB path

open

public void open(java.lang.String path)
          throws EJDBException
Open database using default open mode.

Default open mode: JBOWRITER | JBOCREAT

Parameters:
path - EJDB path
Throws:
EJDBException

open

public void open(java.lang.String path,
                 int mode)
          throws EJDBException
Open database.

Default open mode: JBOWRITER | JBOCREAT

Parameters:
path - EJDB path
mode - Open mode
Throws:
EJDBException

isOpen

public boolean isOpen()
Check if database in opened state.


close

public void close()
           throws EJDBException
Close database. If database was not opened it does nothing.

Throws:
EJDBException

sync

public void sync()
          throws EJDBException
Synchronize entire EJDB database and all its collections with storage.

Throws:
EJDBException

updateMeta

public void updateMeta()
                throws EJDBException
Update description of EJDB database and its collections.

Throws:
EJDBException

ensureCollection

public EJDBCollection ensureCollection(java.lang.String cname)
                                throws EJDBException
Automatically creates new collection if it does't exists with using default collection options

Parameters:
cname - Collection name
Throws:
EJDBException
See Also:
EJDBCollection.ensureExists()

ensureCollection

public EJDBCollection ensureCollection(java.lang.String cname,
                                       EJDBCollection.Options opts)
                                throws EJDBException
Automatically creates new collection if it does't exists. Collection options `opts` are applied only for newly created collection. For existing collections `opts` takes no effect.

Parameters:
cname - Collection name
opts - Collection options
Throws:
EJDBException
See Also:
EJDBCollection.ensureExists(org.ejdb.driver.EJDBCollection.Options)

dropCollection

public void dropCollection(java.lang.String cname)
                    throws EJDBException
Drop collection by name.

Parameters:
cname - Collection name
Throws:
EJDBException
See Also:
EJDBCollection.drop()

dropCollection

public void dropCollection(java.lang.String cname,
                           boolean prune)
                    throws EJDBException
Drop collection.

Parameters:
cname - Collection name
prune - If true the collection data will erased from disk.
Throws:
EJDBException
See Also:
EJDBCollection.drop(boolean)

getCollection

public EJDBCollection getCollection(java.lang.String cname)
                             throws EJDBException
Returns collection object (without automatical creation)

Parameters:
cname - Collection name
Returns:
collection object
Throws:
EJDBException
See Also:
getCollection(String, boolean, org.ejdb.driver.EJDBCollection.Options)

getCollection

public EJDBCollection getCollection(java.lang.String cname,
                                    boolean ecreate)
                             throws EJDBException
Returns collection object

Parameters:
cname - Collection name
ecreate - Automatically collection creation flag
Returns:
collection object
Throws:
EJDBException
See Also:
getCollection(String, boolean, org.ejdb.driver.EJDBCollection.Options)

getCollection

public EJDBCollection getCollection(java.lang.String cname,
                                    boolean ecreate,
                                    EJDBCollection.Options opts)
                             throws EJDBException
Returns collection object

Parameters:
cname - Collection name
ecreate - Automatically collection creation flag
opts - Collection options
Returns:
collection object
Throws:
EJDBException

executeCommand

public BSONObject executeCommand(BSONObject command)
                          throws EJDBException
Executes ejdb database command. Supported commands: 1) Exports database collections data. See ejdbexport() method. "export" : { "path" : string, //Exports database collections data "cnames" : [string array]|null, //List of collection names to export "mode" : int|null //Values: null|`JBJSONEXPORT` See ejdb.h#ejdbexport() method } Command response: { "log" : string, //Diagnostic log about executing this command "error" : string|null, //ejdb error message "errorCode" : int|0, //ejdb error code } 2) Imports previously exported collections data into ejdb. "import" : { "path" : string //The directory path in which data resides "cnames" : [string array]|null, //List of collection names to import "mode" : int|null //Values: null| JBIMPORTUPDATE`|`JBIMPORTREPLACE` See ejdb.h#ejdbimport() method } Command response: { "log" : string, //Diagnostic log about executing this command "error" : string|null, //ejdb error message "errorCode" : int|0, //ejdb error code }

Parameters:
command - Command BSON object
Returns:
command response BSON object
Throws:
EJDBException

getCollectionNames

public java.util.Collection<java.lang.String> getCollectionNames()
Returns names of existed collections


getCollections

public java.util.Collection<EJDBCollection> getCollections()
Returns collection objects for all existed collections


toString

public java.lang.String toString()

Overrides:
toString in class java.lang.Object

finalize

protected void finalize()
                 throws java.lang.Throwable

Overrides:
finalize in class java.lang.Object
Throws:
java.lang.Throwable