Class MongoDbDataContext
- java.lang.Object
-
- org.apache.metamodel.AbstractDataContext
-
- org.apache.metamodel.QueryPostprocessDataContext
-
- org.apache.metamodel.mongodb.mongo3.MongoDbDataContext
-
- All Implemented Interfaces:
org.apache.metamodel.convert.HasReadTypeConverters,org.apache.metamodel.DataContext,org.apache.metamodel.UpdateableDataContext
public class MongoDbDataContext extends org.apache.metamodel.QueryPostprocessDataContext implements org.apache.metamodel.UpdateableDataContextDataContext 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 theSimpleTableDefclass.
-
-
Constructor Summary
Constructors Constructor Description MongoDbDataContext(com.mongodb.client.MongoDatabase mongoDb)Constructs aMongoDbDataContextand automatically detects the schema structure/view on all collections (seedetectSchema(MongoDatabase)).MongoDbDataContext(com.mongodb.client.MongoDatabase mongoDb, org.apache.metamodel.util.SimpleTableDef... tableDefs)Constructs aMongoDbDataContext.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidaddTable(org.apache.metamodel.schema.MutableTable table)protected org.bson.DocumentcreateMongoDbQuery(org.apache.metamodel.schema.Table table, List<org.apache.metamodel.query.FilterItem> whereItems, Consumer<org.apache.metamodel.query.FilterItem> whereItemToPostProcessConsumer)static org.apache.metamodel.util.SimpleTableDef[]detectSchema(com.mongodb.client.MongoDatabase mongoDb)Performs an analysis of the available collections in a MongoDBinstance and tries to detect the table's structure based on the first 1000 documents in each collection.static org.apache.metamodel.util.SimpleTableDefdetectTable(com.mongodb.client.MongoDatabase mongoDb, String collectionName)Performs an analysis of an available collection in a MongoDBinstance and tries to detect the table structure based on the first 1000 documents in the collection.protected NumberexecuteCountQuery(org.apache.metamodel.schema.Table table, List<org.apache.metamodel.query.FilterItem> whereItems, boolean functionApproximationAllowed)protected org.apache.metamodel.data.RowexecutePrimaryKeyLookupQuery(org.apache.metamodel.schema.Table table, List<org.apache.metamodel.query.SelectItem> selectItems, org.apache.metamodel.schema.Column primaryKeyColumn, Object keyValue)org.apache.metamodel.data.DataSetexecuteQuery(org.apache.metamodel.query.Query query)org.apache.metamodel.UpdateSummaryexecuteUpdate(org.apache.metamodel.UpdateScript update)org.apache.metamodel.UpdateSummaryexecuteUpdate(org.apache.metamodel.UpdateScript update, com.mongodb.WriteConcern writeConcern)Executes an update with a specificWriteConcern.org.apache.metamodel.UpdateSummaryexecuteUpdate(org.apache.metamodel.UpdateScript update, WriteConcernAdvisor writeConcernAdvisor)Executes an update with a specificWriteConcernAdvisor.protected org.apache.metamodel.schema.SchemagetMainSchema()protected StringgetMainSchemaName()com.mongodb.client.MongoDatabasegetMongoDb()Gets theDBinstance that thisDataContextis backed by.WriteConcernAdvisorgetWriteConcernAdvisor()Gets theWriteConcernAdvisorto use onexecuteUpdate(UpdateScript)calls.protected org.apache.metamodel.data.DataSetmaterializeMainSchemaTable(org.apache.metamodel.schema.Table table, List<org.apache.metamodel.schema.Column> columns, int maxRows)protected org.apache.metamodel.data.DataSetmaterializeMainSchemaTable(org.apache.metamodel.schema.Table table, List<org.apache.metamodel.schema.Column> columns, int firstRow, int maxRows)voidsetWriteConcernAdvisor(WriteConcernAdvisor writeConcernAdvisor)Sets a globalWriteConcernadvisor to use onexecuteUpdate(UpdateScript).-
Methods inherited from class org.apache.metamodel.QueryPostprocessDataContext
addConverter, getDefaultSchemaName, getSchemaByNameInternal, getSchemaNamesInternal, isMainSchemaTable, isScalarFunctionMaterialized, materializeFromItem, materializeMainSchemaTable, materializeMainSchemaTableSelect, materializeTable
-
Methods inherited from class org.apache.metamodel.AbstractDataContext
compileQuery, executeQuery, executeQuery, getColumnByQualifiedLabel, getDefaultSchema, getSchemaByName, getSchemaNames, getSchemas, getTableByQualifiedLabel, isQualifiedPathDelim, onSchemaCacheRefreshed, parseQuery, query, refreshSchemas
-
-
-
-
Constructor Detail
-
MongoDbDataContext
public MongoDbDataContext(com.mongodb.client.MongoDatabase mongoDb, org.apache.metamodel.util.SimpleTableDef... tableDefs)Constructs aMongoDbDataContext. This constructor accepts a custom array ofSimpleTableDefs which allows the user to define his own view on the collections in the database.- Parameters:
mongoDb- the mongo db connectiontableDefs- an array ofSimpleTableDefs, which define the table and column model of the mongo db collections. (consider usingdetectSchema(MongoDatabase)ordetectTable(MongoDatabase, String)).
-
MongoDbDataContext
public MongoDbDataContext(com.mongodb.client.MongoDatabase mongoDb)
Constructs aMongoDbDataContextand automatically detects the schema structure/view on all collections (seedetectSchema(MongoDatabase)).- Parameters:
mongoDb- the mongo db connection
-
-
Method Detail
-
detectSchema
public static org.apache.metamodel.util.SimpleTableDef[] detectSchema(com.mongodb.client.MongoDatabase mongoDb)
Performs an analysis of the available collections in a MongoDBinstance and tries to detect the table's structure based on the first 1000 documents in each collection.- Parameters:
mongoDb- the mongo db to inspect- Returns:
- a mutable schema instance, useful for further fine tuning by the user.
- See Also:
detectTable(MongoDatabase, String)
-
detectTable
public static org.apache.metamodel.util.SimpleTableDef detectTable(com.mongodb.client.MongoDatabase mongoDb, String collectionName)Performs an analysis of an available collection in a MongoDBinstance and tries to detect the table structure based on the first 1000 documents in the collection.- Parameters:
mongoDb- the mongo DBcollectionName- the name of the collection- Returns:
- a table definition for mongo db.
-
getMainSchema
protected org.apache.metamodel.schema.Schema getMainSchema() throws org.apache.metamodel.MetaModelException- Specified by:
getMainSchemain classorg.apache.metamodel.QueryPostprocessDataContext- Throws:
org.apache.metamodel.MetaModelException
-
getMainSchemaName
protected String getMainSchemaName() throws org.apache.metamodel.MetaModelException
- Specified by:
getMainSchemaNamein classorg.apache.metamodel.QueryPostprocessDataContext- Throws:
org.apache.metamodel.MetaModelException
-
executeCountQuery
protected Number executeCountQuery(org.apache.metamodel.schema.Table table, List<org.apache.metamodel.query.FilterItem> whereItems, boolean functionApproximationAllowed)
- Overrides:
executeCountQueryin classorg.apache.metamodel.QueryPostprocessDataContext
-
executePrimaryKeyLookupQuery
protected org.apache.metamodel.data.Row executePrimaryKeyLookupQuery(org.apache.metamodel.schema.Table table, List<org.apache.metamodel.query.SelectItem> selectItems, org.apache.metamodel.schema.Column primaryKeyColumn, Object keyValue)- Overrides:
executePrimaryKeyLookupQueryin classorg.apache.metamodel.QueryPostprocessDataContext
-
executeQuery
public org.apache.metamodel.data.DataSet executeQuery(org.apache.metamodel.query.Query query)
- Specified by:
executeQueryin interfaceorg.apache.metamodel.DataContext- Overrides:
executeQueryin classorg.apache.metamodel.QueryPostprocessDataContext
-
createMongoDbQuery
protected org.bson.Document createMongoDbQuery(org.apache.metamodel.schema.Table table, List<org.apache.metamodel.query.FilterItem> whereItems, Consumer<org.apache.metamodel.query.FilterItem> whereItemToPostProcessConsumer)
-
materializeMainSchemaTable
protected org.apache.metamodel.data.DataSet materializeMainSchemaTable(org.apache.metamodel.schema.Table table, List<org.apache.metamodel.schema.Column> columns, int maxRows)- Specified by:
materializeMainSchemaTablein classorg.apache.metamodel.QueryPostprocessDataContext
-
materializeMainSchemaTable
protected org.apache.metamodel.data.DataSet materializeMainSchemaTable(org.apache.metamodel.schema.Table table, List<org.apache.metamodel.schema.Column> columns, int firstRow, int maxRows)- Overrides:
materializeMainSchemaTablein classorg.apache.metamodel.QueryPostprocessDataContext
-
executeUpdate
public org.apache.metamodel.UpdateSummary executeUpdate(org.apache.metamodel.UpdateScript update, WriteConcernAdvisor writeConcernAdvisor)Executes an update with a specificWriteConcernAdvisor.
-
executeUpdate
public org.apache.metamodel.UpdateSummary executeUpdate(org.apache.metamodel.UpdateScript update, com.mongodb.WriteConcern writeConcern)Executes an update with a specificWriteConcern.
-
executeUpdate
public org.apache.metamodel.UpdateSummary executeUpdate(org.apache.metamodel.UpdateScript update)
- Specified by:
executeUpdatein interfaceorg.apache.metamodel.UpdateableDataContext
-
getWriteConcernAdvisor
public WriteConcernAdvisor getWriteConcernAdvisor()
Gets theWriteConcernAdvisorto use onexecuteUpdate(UpdateScript)calls.
-
setWriteConcernAdvisor
public void setWriteConcernAdvisor(WriteConcernAdvisor writeConcernAdvisor)
Sets a globalWriteConcernadvisor to use onexecuteUpdate(UpdateScript).
-
getMongoDb
public com.mongodb.client.MongoDatabase getMongoDb()
Gets theDBinstance that thisDataContextis backed by.- Returns:
-
addTable
protected void addTable(org.apache.metamodel.schema.MutableTable table)
-
-