org.ejdb.driver
Class EJDBCollection

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

public class EJDBCollection
extends java.lang.Object

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

Nested Class Summary
static class EJDBCollection.Index
          Index meta information
static class EJDBCollection.IndexType
          Index types
static class EJDBCollection.Options
          Collection meta information (and creation options)
 
Field Summary
static int JBIDXARR
          Array token index.
static int JBIDXDROP
          Drop index.
static int JBIDXDROPALL
          Drop index for all types.
static int JBIDXISTR
          Case insensitive string index
static int JBIDXNUM
          Number index.
static int JBIDXOP
          Optimize index.
static int JBIDXREBLD
          Rebuild index.
static int JBIDXSTR
          String index.
protected static int JBTXBEGIN
           
protected static int JBTXCOMMIT
           
protected static int JBTXROLLBACK
           
protected static int JBTXSTATUS
           
 
Method Summary
 void beginTransaction()
          Begin collection transaction.
 void commitTransaction()
          Commit collection transaction.
 EJDBQuery createQuery(BSONObject query)
          Deprecated.  
 EJDBQuery createQuery(BSONObject query, BSONObject hints)
          Deprecated.  
 EJDBQuery createQuery(BSONObject query, BSONObject[] qors)
          Deprecated.  
 EJDBQuery createQuery(BSONObject query, BSONObject[] qors, BSONObject hints)
          Deprecated.  
 EJDBQuery createQuery(EJDBQueryBuilder query)
          Creates new EJDB Query for current collection.
 void drop()
          Drop collection.
 void drop(boolean prune)
          Drop collection.
 void dropArrayIndex(java.lang.String path)
          Drop index of Array type for BSON field path.
 void dropIndexes(java.lang.String path)
          Drops indexes of all types for BSON field path.
 void dropIStringIndex(java.lang.String path)
          Drop case insensitive String index for BSON field path.
 void dropNumderIndex(java.lang.String path)
          Drop index of Number type for BSON field path.
 void dropStringIndex(java.lang.String path)
          Drop index of String type for BSON field path.
 void ensureArrayIndex(java.lang.String path)
          Ensure index presence of Array type for BSON field path
 void ensureExists()
          Automatically creates new collection if it does't exists with using default collection options.
 void ensureExists(EJDBCollection.Options opts)
          Automatically creates new collection if it does't exists.
 void ensureIStringIndex(java.lang.String path)
          Ensure case insensitive String index for BSON field path
 void ensureNumderIndex(java.lang.String path)
          Ensure index presence of Number type for BSON field path
 void ensureStringIndex(java.lang.String path)
          Ensure index presence of String type for BSON field path
 EJDB getDB()
          Returns EJDB object
 java.util.Collection<EJDBCollection.Index> getIndexes()
          Returns indexes info
 java.lang.String getName()
          Returns collection name
 EJDBCollection.Options getOptions()
          Returns collection options EJDBCollection.Options
 boolean isExists()
          Returns collection exists status
 boolean isTransactionActive()
          Get collection transaction status.
 BSONObject load(ObjectId oid)
          Loads BSON object identified by OID from the collection.
 void optimizeIndexes(java.lang.String path)
          Optimize indexes of all types for BSON field path
 void rebuildArrayIndex(java.lang.String path)
          Rebuild index of Array type for BSON field path.
 void rebuildIStringIndex(java.lang.String path)
          Rebuild case insensitive String index for BSON field path.
 void rebuildNumderIndex(java.lang.String path)
          Rebuild index of Number type for BSON field path.
 void rebuildStringIndex(java.lang.String path)
          Rebuild index of String type for BSON field path.
 void remove(ObjectId oid)
          Remove BSON object from collection by OID
 void rollbackTransaction()
          Abort collection transaction.
 ObjectId save(BSONObject object)
          Save/update specified BSON object in the collection.
 java.util.List<ObjectId> save(java.util.List<BSONObject> objects)
          Save/update specified BSON objects in the collection.
protected  void setIndex(java.lang.String path, int flags)
           
 void sync()
          Synchronize entire collection with storage.
 java.lang.String toString()
          
protected  boolean txControl(int mode)
           
 void updateMeta()
          Update collection metainformation from storage
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

JBIDXDROP

public static final int JBIDXDROP
Drop index.

See Also:
Constant Field Values

JBIDXDROPALL

public static final int JBIDXDROPALL
Drop index for all types.

See Also:
Constant Field Values

JBIDXOP

public static final int JBIDXOP
Optimize index.

See Also:
Constant Field Values

JBIDXREBLD

public static final int JBIDXREBLD
Rebuild index.

See Also:
Constant Field Values

JBIDXNUM

public static final int JBIDXNUM
Number index.

See Also:
Constant Field Values

JBIDXSTR

public static final int JBIDXSTR
String index.

See Also:
Constant Field Values

JBIDXARR

public static final int JBIDXARR
Array token index.

See Also:
Constant Field Values

JBIDXISTR

public static final int JBIDXISTR
Case insensitive string index

See Also:
Constant Field Values

JBTXBEGIN

protected static final int JBTXBEGIN
See Also:
Constant Field Values

JBTXCOMMIT

protected static final int JBTXCOMMIT
See Also:
Constant Field Values

JBTXROLLBACK

protected static final int JBTXROLLBACK
See Also:
Constant Field Values

JBTXSTATUS

protected static final int JBTXSTATUS
See Also:
Constant Field Values
Method Detail

getDB

public EJDB getDB()
Returns EJDB object

Returns:
EJDB object

getName

public java.lang.String getName()
Returns collection name

Returns:
collection name

isExists

public boolean isExists()
Returns collection exists status

Returns:
collection exists status

getOptions

public EJDBCollection.Options getOptions()
Returns collection options EJDBCollection.Options

Returns:
collection options EJDBCollection.Options

getIndexes

public java.util.Collection<EJDBCollection.Index> getIndexes()
Returns indexes info

Returns:
indexes info

ensureExists

public void ensureExists()
                  throws EJDBException
Automatically creates new collection if it does't exists with using default collection options.

Throws:
EJDBException
See Also:
ensureExists(org.ejdb.driver.EJDBCollection.Options)

ensureExists

public void ensureExists(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:
opts - Collection options.
Throws:
EJDBException

drop

public void drop()
          throws EJDBException
Drop collection.

Throws:
EJDBException

drop

public void drop(boolean prune)
          throws EJDBException
Drop collection.

Parameters:
prune - If true the collection data will erased from disk.
Throws:
EJDBException

sync

public void sync()
          throws EJDBException
Synchronize entire collection with storage.

Throws:
EJDBException

updateMeta

public void updateMeta()
                throws EJDBException
Update collection metainformation from storage

Throws:
EJDBException

load

public BSONObject load(ObjectId oid)
                throws EJDBException
Loads BSON object identified by OID from the collection.

Parameters:
oid - Object identifier (OID)
Throws:
EJDBException

save

public ObjectId save(BSONObject object)
              throws EJDBException
Save/update specified BSON object in the collection.

Object has unique identifier (OID) placed in the `_id` property. If a saved object does not have `_id` it will be autogenerated. To identify and update object it should contains `_id` property.

NOTE: Field names of passed BSON objects may not contain `$` and `.` characters, error condition will be fired in this case.

Parameters:
object - BSON object to save
Returns:
OID of saved object
Throws:
EJDBException

save

public java.util.List<ObjectId> save(java.util.List<BSONObject> objects)
                              throws EJDBException
Save/update specified BSON objects in the collection.

Each persistent object has unique identifier (OID) placed in the `_id` property. If a saved object does not have `_id` it will be autogenerated. To identify and update object it should contains `_id` property.

NOTE: Field names of passed BSON objects may not contain `$` and `.` characters, error condition will be fired in this case.

Parameters:
objects - array of JSON objects to save
Returns:
OIDs of saved objects
Throws:
EJDBException

remove

public void remove(ObjectId oid)
            throws EJDBException
Remove BSON object from collection by OID

Parameters:
oid - OID of removed object
Throws:
EJDBException

setIndex

protected void setIndex(java.lang.String path,
                        int flags)
                 throws EJDBException
Parameters:
path - BSON field path
flags -
Throws:
EJDBException

dropIndexes

public void dropIndexes(java.lang.String path)
                 throws EJDBException
Drops indexes of all types for BSON field path.

Parameters:
path - BSON field path
Throws:
EJDBException

optimizeIndexes

public void optimizeIndexes(java.lang.String path)
                     throws EJDBException
Optimize indexes of all types for BSON field path

Parameters:
path - BSON field path
Throws:
EJDBException

ensureStringIndex

public void ensureStringIndex(java.lang.String path)
                       throws EJDBException
Ensure index presence of String type for BSON field path

Parameters:
path - BSON field path
Throws:
EJDBException

rebuildStringIndex

public void rebuildStringIndex(java.lang.String path)
                        throws EJDBException
Rebuild index of String type for BSON field path.

Parameters:
path - BSON field path
Throws:
EJDBException

dropStringIndex

public void dropStringIndex(java.lang.String path)
                     throws EJDBException
Drop index of String type for BSON field path.

Parameters:
path - BSON field path
Throws:
EJDBException

ensureIStringIndex

public void ensureIStringIndex(java.lang.String path)
                        throws EJDBException
Ensure case insensitive String index for BSON field path

Parameters:
path - BSON field path
Throws:
EJDBException

rebuildIStringIndex

public void rebuildIStringIndex(java.lang.String path)
                         throws EJDBException
Rebuild case insensitive String index for BSON field path.

Parameters:
path - BSON field path
Throws:
EJDBException

dropIStringIndex

public void dropIStringIndex(java.lang.String path)
                      throws EJDBException
Drop case insensitive String index for BSON field path.

Parameters:
path - BSON field path
Throws:
EJDBException

ensureNumderIndex

public void ensureNumderIndex(java.lang.String path)
                       throws EJDBException
Ensure index presence of Number type for BSON field path

Parameters:
path - BSON field path
Throws:
EJDBException

rebuildNumderIndex

public void rebuildNumderIndex(java.lang.String path)
                        throws EJDBException
Rebuild index of Number type for BSON field path.

Parameters:
path - BSON field path
Throws:
EJDBException

dropNumderIndex

public void dropNumderIndex(java.lang.String path)
                     throws EJDBException
Drop index of Number type for BSON field path.

Parameters:
path - BSON field path
Throws:
EJDBException

ensureArrayIndex

public void ensureArrayIndex(java.lang.String path)
                      throws EJDBException
Ensure index presence of Array type for BSON field path

Parameters:
path - BSON field path
Throws:
EJDBException

rebuildArrayIndex

public void rebuildArrayIndex(java.lang.String path)
                       throws EJDBException
Rebuild index of Array type for BSON field path.

Parameters:
path - BSON field path
Throws:
EJDBException

dropArrayIndex

public void dropArrayIndex(java.lang.String path)
                    throws EJDBException
Drop index of Array type for BSON field path.

Parameters:
path - BSON field path
Throws:
EJDBException

createQuery

public EJDBQuery createQuery(EJDBQueryBuilder query)
Creates new EJDB Query for current collection.


createQuery

@Deprecated
public EJDBQuery createQuery(BSONObject query)
Deprecated. 

See Also:
createQuery(org.ejdb.bson.BSONObject, org.ejdb.bson.BSONObject[], org.ejdb.bson.BSONObject)

createQuery

@Deprecated
public EJDBQuery createQuery(BSONObject query,
                                        BSONObject[] qors)
Deprecated. 

See Also:
createQuery(org.ejdb.bson.BSONObject, org.ejdb.bson.BSONObject[], org.ejdb.bson.BSONObject)

createQuery

@Deprecated
public EJDBQuery createQuery(BSONObject query,
                                        BSONObject hints)
Deprecated. 

See Also:
createQuery(org.ejdb.bson.BSONObject, org.ejdb.bson.BSONObject[], org.ejdb.bson.BSONObject)

createQuery

@Deprecated
public EJDBQuery createQuery(BSONObject query,
                                        BSONObject[] qors,
                                        BSONObject hints)
Deprecated. 

Create EJDB query

EJDB queries inspired by MongoDB (mongodb.org) and follows same philosophy.

Parameters:
query - Main BSON query object
qors - Array of additional OR query objects (joined with OR predicate).
hints - BSON object with query hints.

beginTransaction

public void beginTransaction()
                      throws EJDBException
Begin collection transaction.

Throws:
EJDBException

commitTransaction

public void commitTransaction()
                       throws EJDBException
Commit collection transaction.

Throws:
EJDBException

rollbackTransaction

public void rollbackTransaction()
                         throws EJDBException
Abort collection transaction.

Throws:
EJDBException

isTransactionActive

public boolean isTransactionActive()
                            throws EJDBException
Get collection transaction status.

Throws:
EJDBException

txControl

protected boolean txControl(int mode)
                     throws EJDBException
Throws:
EJDBException

toString

public java.lang.String toString()

Overrides:
toString in class java.lang.Object