ch.agent.crnickl.mongodb
Class MongoDatabaseMethods

java.lang.Object
  extended by ch.agent.crnickl.impl.DatabaseMethodsImpl
      extended by ch.agent.crnickl.mongodb.MongoDatabaseMethods
All Implemented Interfaces:
ch.agent.crnickl.impl.DatabaseMethods, ch.agent.crnickl.impl.PermissionChecker
Direct Known Subclasses:
AccessMethodsForAny, AccessMethodsForNumber, ReadMethodsForChroniclesAndSeries, ReadMethodsForProperty, ReadMethodsForSchema, ReadMethodsForValueType, WriteMethodsForValueType

public class MongoDatabaseMethods
extends ch.agent.crnickl.impl.DatabaseMethodsImpl

Author:
jp

Nested Class Summary
static class MongoDatabaseMethods.Operator
           
 
Constructor Summary
MongoDatabaseMethods()
           
 
Method Summary
protected  void addOperation(com.mongodb.DBObject operation, MongoDatabaseMethods.Operator op, Object... arg)
          Add an update operation to a DBObject.
protected
<T> com.mongodb.DBObject
asQuery(ch.agent.crnickl.api.DBObjectId id)
           
protected  String compositeName(String... names)
          Return a composite mongodb identifier.
protected  String extractRegexp(String pattern)
          Remove enclosing slashes from the input pattern.
protected  org.bson.types.ObjectId getId(ch.agent.crnickl.api.DBObject dBObject)
          Return the internal ID of a database object.
 org.bson.types.ObjectId getId(ch.agent.crnickl.api.Surrogate surrogate)
          Extract the internal ID of a database object from its surrogate.
 org.bson.types.ObjectId getIdOrZero(ch.agent.crnickl.api.DBObject dBObject)
          Return the internal ID of a database object or 0 if the object is null or is in construction.
 MongoDB getMongoDB(ch.agent.crnickl.api.Database db)
           
 MongoDB getMongoDB(ch.agent.crnickl.api.DBObject dbObj)
           
 MongoDB getMongoDB(ch.agent.crnickl.api.Surrogate surr)
           
 com.mongodb.DBObject getObject(ch.agent.crnickl.api.Surrogate s, boolean mustExist)
          Return the MongoDB database object corresponding to a surrogate.
 org.bson.types.ObjectId getObjectId(com.mongodb.BasicDBObject bdo)
           
 ch.agent.crnickl.api.Surrogate makeSurrogate(ch.agent.crnickl.api.Database db, ch.agent.crnickl.api.DBObjectType dot, org.bson.types.ObjectId id)
          Create a surrogate for a database object.
protected  com.mongodb.DBObject mongoObject(Object... arg)
          Return an array of key-value pairs as a DBObject.
protected  com.mongodb.DBObject operation(MongoDatabaseMethods.Operator op, Object... arg)
          Return a com.mongodb.DbObject representing an operation object for an operator and list of arguments.
 
Methods inherited from class ch.agent.crnickl.impl.DatabaseMethodsImpl
check, check, check, check, checkIntegrity, makeSurrogate, makeSurrogate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MongoDatabaseMethods

public MongoDatabaseMethods()
Method Detail

getMongoDB

public MongoDB getMongoDB(ch.agent.crnickl.api.Database db)

getMongoDB

public MongoDB getMongoDB(ch.agent.crnickl.api.DBObject dbObj)

getMongoDB

public MongoDB getMongoDB(ch.agent.crnickl.api.Surrogate surr)

getObject

public com.mongodb.DBObject getObject(ch.agent.crnickl.api.Surrogate s,
                                      boolean mustExist)
                               throws ch.agent.crnickl.T2DBException
Return the MongoDB database object corresponding to a surrogate. When mustExist is false the method returns null if the object cannot be found, else an exception is thrown.

Parameters:
s - a surrogate
mustExist - if true throw an exception when the object cannot be found
Returns:
a DBObject object or null
Throws:
ch.agent.crnickl.T2DBException

getObjectId

public org.bson.types.ObjectId getObjectId(com.mongodb.BasicDBObject bdo)
Parameters:
bdo - a BasicDBObject
Returns:
the argument's ObjectId

getIdOrZero

public org.bson.types.ObjectId getIdOrZero(ch.agent.crnickl.api.DBObject dBObject)
Return the internal ID of a database object or 0 if the object is null or is in construction. The internal ID is not exposed to clients.

This method is for use inside the MongoDB implementation and its argument must have a DBObjectId implemented by MongoDBObjectId.

Parameters:
dBObject - a database object or null
Returns:
an id or null

getId

protected org.bson.types.ObjectId getId(ch.agent.crnickl.api.DBObject dBObject)
Return the internal ID of a database object. The internal ID is not exposed to clients.

This method is for use inside the MongoDB implementation and its argument must have a DBObjectId implemented by MongoDBObjectId.

Parameters:
dBObject - a non-null database object
Returns:
a non-null id

getId

public org.bson.types.ObjectId getId(ch.agent.crnickl.api.Surrogate surrogate)
Extract the internal ID of a database object from its surrogate. The internal ID is not exposed to clients.

This method is for use inside the MongoDB implementation and its argument must have a DBObjectId implemented by MongoDBObjectId.

Parameters:
surrogate - the surrogate of a database object
Returns:
a non-null id

makeSurrogate

public ch.agent.crnickl.api.Surrogate makeSurrogate(ch.agent.crnickl.api.Database db,
                                                    ch.agent.crnickl.api.DBObjectType dot,
                                                    org.bson.types.ObjectId id)
Create a surrogate for a database object.

Parameters:
db - the database of the object
dot - the type of the object
id - the internal ID of the database object
Returns:
a surrogate

asQuery

protected <T> com.mongodb.DBObject asQuery(ch.agent.crnickl.api.DBObjectId id)
                                throws ch.agent.crnickl.T2DBException
Throws:
ch.agent.crnickl.T2DBException

extractRegexp

protected String extractRegexp(String pattern)
Remove enclosing slashes from the input pattern. If there are leading and trailing slashes, the method returns the enclosed string, else it returns null.

Parameters:
pattern -
Returns:
the pattern without the leading and trailing slashes or null

addOperation

protected void addOperation(com.mongodb.DBObject operation,
                            MongoDatabaseMethods.Operator op,
                            Object... arg)
Add an update operation to a DBObject. The operation is defined by an operator and a list of arguments. See mongoObject(Object...) for restrictions on the list of arguments.

Parameters:
operation - the operation object
op - the operator
arg - the list of arguments
Throws:
IllegalArgumentException

operation

protected com.mongodb.DBObject operation(MongoDatabaseMethods.Operator op,
                                         Object... arg)
Return a com.mongodb.DbObject representing an operation object for an operator and list of arguments. See mongoObject(Object...) for restrictions on the list of arguments.

Parameters:
op - the operator
arg - the list of arguments
Returns:
an operation
Throws:
IllegalArgumentException

mongoObject

protected com.mongodb.DBObject mongoObject(Object... arg)
Return an array of key-value pairs as a DBObject. The array must be non-empty and its length must be even. Non-even elements (the keys) must be non-null Strings. Even elements must be BSON compatible (this is not enforced by this method but violations are detected later).

Parameters:
arg - an non-empty array of arguments of even length
Returns:
a DBObject
Throws:
IllegalArgumentException

compositeName

protected String compositeName(String... names)
Return a composite mongodb identifier.

Parameters:
names - series of zero or more names
Returns:
a composite name


Copyright © 2013. All Rights Reserved.