public class MongoDbDataContext extends QueryPostprocessDataContext implements UpdateableDataContext
SimpleTableDef
class.INFORMATION_SCHEMA_NAME
Constructor and Description |
---|
MongoDbDataContext(com.mongodb.client.MongoDatabase mongoDb)
Constructs a
MongoDbDataContext and automatically detects the
schema structure/view on all collections (see detectSchema(MongoDatabase) ). |
MongoDbDataContext(com.mongodb.client.MongoDatabase mongoDb,
SimpleTableDef... tableDefs)
Constructs a
MongoDbDataContext . |
Modifier and Type | Method and Description |
---|---|
protected void |
addTable(MutableTable table) |
protected org.bson.Document |
createMongoDbQuery(Table table,
List<FilterItem> whereItems) |
static SimpleTableDef[] |
detectSchema(com.mongodb.client.MongoDatabase mongoDb)
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.client.MongoDatabase mongoDb,
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)
Executes a simple count query, if possible.
|
protected Row |
executePrimaryKeyLookupQuery(Table table,
List<SelectItem> selectItems,
Column primaryKeyColumn,
Object keyValue)
Executes a query which obtains a row by primary key (as defined by
Column.isPrimaryKey() ). |
DataSet |
executeQuery(Query query)
Executes a query against the DataContext.
|
void |
executeUpdate(UpdateScript update)
Submits an
UpdateScript for execution on the DataContext . |
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.client.MongoDatabase |
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)
Executes a simple one-table query against a table in the main schema of
the subclasses of this class.
|
protected DataSet |
materializeMainSchemaTable(Table table,
Column[] columns,
int firstRow,
int maxRows)
Executes a simple one-table query against a table in the main schema of
the subclasses of this class.
|
void |
setWriteConcernAdvisor(WriteConcernAdvisor writeConcernAdvisor)
Sets a global
WriteConcern advisor to use on
executeUpdate(UpdateScript) . |
addConverter, getDefaultSchemaName, getMainSchemaInternal, getSchemaByNameInternal, getSchemaNamesInternal, isMainSchemaTable, isScalarFunctionMaterialized, materializeFromItem, materializeMainSchemaTable, materializeMainSchemaTable, materializeTable, materializeTable
compileQuery, executeQuery, executeQuery, getColumnByQualifiedLabel, getDefaultSchema, getSchemaByName, getSchemaNames, getSchemas, getTableByQualifiedLabel, isQualifiedPathDelim, onSchemaCacheRefreshed, parseQuery, query, refreshSchemas
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
compileQuery, executeQuery, executeQuery, getColumnByQualifiedLabel, getDefaultSchema, getSchemaByName, getSchemaNames, getSchemas, getTableByQualifiedLabel, parseQuery, query, refreshSchemas
public MongoDbDataContext(com.mongodb.client.MongoDatabase mongoDb, SimpleTableDef... tableDefs)
MongoDbDataContext
. This constructor accepts a
custom array of SimpleTableDef
s which allows the user to define
his own view on the collections in the database.mongoDb
- the mongo db connectiontableDefs
- an array of SimpleTableDef
s, which define the table
and column model of the mongo db collections. (consider using
detectSchema(MongoDatabase)
or detectTable(MongoDatabase, String)
).public MongoDbDataContext(com.mongodb.client.MongoDatabase mongoDb)
MongoDbDataContext
and automatically detects the
schema structure/view on all collections (see detectSchema(MongoDatabase)
).mongoDb
- the mongo db connectionpublic static SimpleTableDef[] detectSchema(com.mongodb.client.MongoDatabase mongoDb)
DB
instance and tries to detect the table's structure based on the first
1000 documents in each collection.mongoDb
- the mongo db to inspectdetectTable(MongoDatabase, String)
public static SimpleTableDef detectTable(com.mongodb.client.MongoDatabase mongoDb, String collectionName)
DB
instance and tries to detect the table structure based on the first 1000
documents in the collection.mongoDb
- the mongo DBcollectionName
- the name of the collectionprotected Schema getMainSchema() throws MetaModelException
getMainSchema
in class QueryPostprocessDataContext
MetaModelException
protected String getMainSchemaName() throws MetaModelException
getMainSchemaName
in class QueryPostprocessDataContext
MetaModelException
protected Number executeCountQuery(Table table, List<FilterItem> whereItems, boolean functionApproximationAllowed)
QueryPostprocessDataContext
executeCountQuery
in class QueryPostprocessDataContext
table
- the table on which the count is requested.whereItems
- a (sometimes empty) list of WHERE items.functionApproximationAllowed
- whether approximation is allowed or not.protected Row executePrimaryKeyLookupQuery(Table table, List<SelectItem> selectItems, Column primaryKeyColumn, Object keyValue)
QueryPostprocessDataContext
Column.isPrimaryKey()
). This method is provided to allow
subclasses to optimize lookup queries since they are quite common and
often a datastore can retrieve the row using some specialized means which
is much more performant than scanning all records manually.executePrimaryKeyLookupQuery
in class QueryPostprocessDataContext
table
- the table on which the lookup is requested.selectItems
- the items to select from the lookup query.primaryKeyColumn
- the column that is the primary keykeyValue
- the primary key value that is specified in the lookup query.public DataSet executeQuery(Query query)
DataContext
executeQuery
in interface DataContext
executeQuery
in class QueryPostprocessDataContext
query
- the query object to executeDataSet
produced from executing the queryprotected org.bson.Document createMongoDbQuery(Table table, List<FilterItem> whereItems)
protected DataSet materializeMainSchemaTable(Table table, Column[] columns, int maxRows)
QueryPostprocessDataContext
materializeMainSchemaTable
in class QueryPostprocessDataContext
table
- the table to querycolumns
- the columns of the table to querymaxRows
- the maximum amount of rows needed or -1 if all rows are
wanted.protected DataSet materializeMainSchemaTable(Table table, Column[] columns, int firstRow, int maxRows)
QueryPostprocessDataContext
QueryPostprocessDataContext.materializeMainSchemaTable(Table, Column[], int)
and apply a
FirstRowDataSet
if necessary.materializeMainSchemaTable
in class QueryPostprocessDataContext
public void executeUpdate(UpdateScript update, WriteConcernAdvisor writeConcernAdvisor)
WriteConcernAdvisor
.public void executeUpdate(UpdateScript update, com.mongodb.WriteConcern writeConcern)
WriteConcern
.public void executeUpdate(UpdateScript update)
UpdateableDataContext
UpdateScript
for execution on the DataContext
.
Since implementations of the DataContext
vary quite a lot, there
is no golden rule as to how an update script will be executed. But the
implementors should strive towards handling an UpdateScript
as a
single transactional change to the data store.executeUpdate
in interface UpdateableDataContext
update
- the update script to executepublic WriteConcernAdvisor getWriteConcernAdvisor()
WriteConcernAdvisor
to use on
executeUpdate(UpdateScript)
calls.public void setWriteConcernAdvisor(WriteConcernAdvisor writeConcernAdvisor)
WriteConcern
advisor to use on
executeUpdate(UpdateScript)
.public com.mongodb.client.MongoDatabase getMongoDb()
DB
instance that this DataContext
is backed by.protected void addTable(MutableTable table)
Copyright © 2007–2016 The Apache Software Foundation. All rights reserved.