org.eobjects.metamodel.mongodb
Class MongoDbDataContext

java.lang.Object
  extended by org.eobjects.metamodel.AbstractDataContext
      extended by org.eobjects.metamodel.QueryPostprocessDataContext
          extended by org.eobjects.metamodel.mongodb.MongoDbDataContext
All Implemented Interfaces:
HasReadTypeConverters, DataContext, UpdateableDataContext

public class MongoDbDataContext
extends QueryPostprocessDataContext
implements UpdateableDataContext

DataContext implementation for MongoDB. Since MongoDB has no schema, a virtual schema will be used in this DataContext. This implementation supports either automatic discovery of a schema or manual specification of a schema, through the MongoDbTableDef class.

Author:
Kasper Sørensen

Field Summary
 
Fields inherited from class org.eobjects.metamodel.QueryPostprocessDataContext
INFORMATION_SCHEMA_NAME
 
Constructor Summary
MongoDbDataContext(com.mongodb.DB mongoDb)
          Constructs a MongoDbDataContext and automatically detects the schema structure/view on all collections (see detectSchema(DB)).
MongoDbDataContext(com.mongodb.DB mongoDb, MongoDbTableDef... tableDefs)
          Deprecated. use MongoDbDataContext(DB, SimpleTableDef...) instead
MongoDbDataContext(com.mongodb.DB mongoDb, SimpleTableDef... tableDefs)
          Constructs a MongoDbDataContext.
 
Method Summary
protected  void addTable(MutableTable table)
           
protected  com.mongodb.BasicDBObject createMongoDbQuery(Table table, List<FilterItem> whereItems)
           
static SimpleTableDef[] detectSchema(com.mongodb.DB db)
          Performs an analysis of the available collections in a Mongo DB instance and tries to detect the table's structure based on the first 1000 documents in each collection.
static SimpleTableDef detectTable(com.mongodb.DB db, String collectionName)
          Performs an analysis of an available collection in a Mongo DB instance and tries to detect the table structure based on the first 1000 documents in the collection.
protected  Number executeCountQuery(Table table, List<FilterItem> whereItems, boolean functionApproximationAllowed)
           
 DataSet executeQuery(Query query)
           
 void executeUpdate(UpdateScript update)
           
 void executeUpdate(UpdateScript update, com.mongodb.WriteConcern writeConcern)
          Executes an update with a specific WriteConcern.
 void executeUpdate(UpdateScript update, WriteConcernAdvisor writeConcernAdvisor)
          Executes an update with a specific WriteConcernAdvisor.
protected  Schema getMainSchema()
           
protected  String getMainSchemaName()
           
 com.mongodb.DB getMongoDb()
          Gets the DB instance that this DataContext is backed by.
 WriteConcernAdvisor getWriteConcernAdvisor()
          Gets the WriteConcernAdvisor to use on executeUpdate(UpdateScript) calls.
protected  DataSet materializeMainSchemaTable(Table table, Column[] columns, int maxRows)
           
protected  DataSet materializeMainSchemaTable(Table table, Column[] columns, int firstRow, int maxRows)
           
 void setWriteConcernAdvisor(WriteConcernAdvisor writeConcernAdvisor)
          Sets a global WriteConcern advisor to use on executeUpdate(UpdateScript).
 
Methods inherited from class org.eobjects.metamodel.QueryPostprocessDataContext
addConverter, getDefaultSchemaName, getMainSchemaInternal, getSchemaByNameInternal, getSchemaNamesInternal, isMainSchemaTable, materializeFromItem, materializeMainSchemaTable, materializeTable
 
Methods inherited from class org.eobjects.metamodel.AbstractDataContext
compileQuery, executeQuery, executeQuery, getColumnByQualifiedLabel, getDefaultSchema, getSchemaByName, getSchemaNames, getSchemas, getTableByQualifiedLabel, isQualifiedPathDelim, parseQuery, query, refreshSchemas
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.eobjects.metamodel.DataContext
compileQuery, executeQuery, executeQuery, getColumnByQualifiedLabel, getDefaultSchema, getSchemaByName, getSchemaNames, getSchemas, getTableByQualifiedLabel, parseQuery, query, refreshSchemas
 

Constructor Detail

MongoDbDataContext

@Deprecated
public MongoDbDataContext(com.mongodb.DB mongoDb,
                                     MongoDbTableDef... tableDefs)
Deprecated. use MongoDbDataContext(DB, SimpleTableDef...) instead

Constructor available for backwards compatibility

Parameters:
mongoDb -
tableDefs -

MongoDbDataContext

public MongoDbDataContext(com.mongodb.DB mongoDb,
                          SimpleTableDef... tableDefs)
Constructs a MongoDbDataContext. This constructor accepts a custom array of MongoDbTableDefs which allows the user to define his own view on the collections in the database.

Parameters:
mongoDb - the mongo db connection
tableDefs - an array of MongoDbTableDefs, which define the table and column model of the mongo db collections. (consider using detectSchema(DB) or detectTable(DB, String) ).

MongoDbDataContext

public MongoDbDataContext(com.mongodb.DB mongoDb)
Constructs a MongoDbDataContext and automatically detects the schema structure/view on all collections (see detectSchema(DB)).

Parameters:
mongoDb - the mongo db connection
Method Detail

detectSchema

public static SimpleTableDef[] detectSchema(com.mongodb.DB db)
Performs an analysis of the available collections in a Mongo DB instance and tries to detect the table's structure based on the first 1000 documents in each collection.

Parameters:
db - the mongo db to inspect
Returns:
a mutable schema instance, useful for further fine tuning by the user.
See Also:
detectTable(DB, String)

detectTable

public static SimpleTableDef detectTable(com.mongodb.DB db,
                                         String collectionName)
Performs an analysis of an available collection in a Mongo DB instance and tries to detect the table structure based on the first 1000 documents in the collection.

Parameters:
db - the mongo DB
collectionName - the name of the collection
Returns:
a table definition for mongo db.

getMainSchema

protected Schema getMainSchema()
                        throws MetaModelException
Specified by:
getMainSchema in class QueryPostprocessDataContext
Throws:
MetaModelException

getMainSchemaName

protected String getMainSchemaName()
                            throws MetaModelException
Specified by:
getMainSchemaName in class QueryPostprocessDataContext
Throws:
MetaModelException

executeCountQuery

protected Number executeCountQuery(Table table,
                                   List<FilterItem> whereItems,
                                   boolean functionApproximationAllowed)
Overrides:
executeCountQuery in class QueryPostprocessDataContext

executeQuery

public DataSet executeQuery(Query query)
Specified by:
executeQuery in interface DataContext
Overrides:
executeQuery in class QueryPostprocessDataContext

createMongoDbQuery

protected com.mongodb.BasicDBObject createMongoDbQuery(Table table,
                                                       List<FilterItem> whereItems)

materializeMainSchemaTable

protected DataSet materializeMainSchemaTable(Table table,
                                             Column[] columns,
                                             int maxRows)
Specified by:
materializeMainSchemaTable in class QueryPostprocessDataContext

materializeMainSchemaTable

protected DataSet materializeMainSchemaTable(Table table,
                                             Column[] columns,
                                             int firstRow,
                                             int maxRows)
Overrides:
materializeMainSchemaTable in class QueryPostprocessDataContext

executeUpdate

public void executeUpdate(UpdateScript update,
                          WriteConcernAdvisor writeConcernAdvisor)
Executes an update with a specific WriteConcernAdvisor.

Parameters:
update -
writeConcernAdvisor -

executeUpdate

public void executeUpdate(UpdateScript update,
                          com.mongodb.WriteConcern writeConcern)
Executes an update with a specific WriteConcern.

Parameters:
update -
writeConcern -

executeUpdate

public void executeUpdate(UpdateScript update)
Specified by:
executeUpdate in interface UpdateableDataContext

getWriteConcernAdvisor

public WriteConcernAdvisor getWriteConcernAdvisor()
Gets the WriteConcernAdvisor to use on executeUpdate(UpdateScript) calls.

Returns:

setWriteConcernAdvisor

public void setWriteConcernAdvisor(WriteConcernAdvisor writeConcernAdvisor)
Sets a global WriteConcern advisor to use on executeUpdate(UpdateScript).

Parameters:
writeConcernAdvisor -

getMongoDb

public com.mongodb.DB getMongoDb()
Gets the DB instance that this DataContext is backed by.

Returns:

addTable

protected void addTable(MutableTable table)


Copyright © 2007-2013. All Rights Reserved.