public class MongoDBDialect extends BaseGridDialect implements QueryableGridDialect<org.hibernate.ogm.datastore.mongodb.query.impl.MongoDBQueryDescriptor>, BatchableGridDialect, IdentityColumnAwareGridDialect, MultigetGridDialect, OptimisticLockingAwareGridDialect, StoredProcedureAwareGridDialect
Modifier and Type | Class and Description |
---|---|
static class |
MongoDBDialect.SingleTupleIterator |
Modifier and Type | Field and Description |
---|---|
static String |
ASSOCIATIONS_COLLECTION_PREFIX |
static String |
ID_FIELDNAME |
static String |
PROPERTY_SEPARATOR |
static String |
ROWS_FIELDNAME |
static String |
TABLE_FIELDNAME |
Constructor and Description |
---|
MongoDBDialect(org.hibernate.ogm.datastore.mongodb.impl.MongoDBDatastoreProvider provider) |
Modifier and Type | Method and Description |
---|---|
ClosableIterator<Tuple> |
callStoredProcedure(String storedProcedureName,
ProcedureQueryParameters params,
TupleContext tupleContext)
In MongoDB the equivalent of a stored procedure is a stored Javascript.
|
Association |
createAssociation(AssociationKey key,
AssociationContext associationContext)
Creates a new (empty) association for storing the tuples representing the rows corresponding to the given key.
|
Tuple |
createTuple(EntityKeyMetadata entityKeyMetadata,
OperationContext operationContext)
Creates an empty tuple of the specified entity type.
|
Tuple |
createTuple(EntityKey key,
OperationContext OperationContext)
Creates a new tuple for the given entity key.
|
ClosableIterator<Tuple> |
executeBackendQuery(BackendQuery<org.hibernate.ogm.datastore.mongodb.query.impl.MongoDBQueryDescriptor> backendQuery,
QueryParameters queryParameters,
TupleContext tupleContext)
Returns the result of a native query executed on the backend.
|
int |
executeBackendUpdateQuery(BackendQuery<org.hibernate.ogm.datastore.mongodb.query.impl.MongoDBQueryDescriptor> backendQuery,
QueryParameters queryParameters,
TupleContext tupleContext)
Returns the result of a native update query executed on the backend.
|
void |
executeBatch(OperationsQueue queue)
Executes the batched operations using the mechanism provided by the db
|
void |
forEachTuple(ModelConsumer consumer,
TupleTypeContext tupleTypeContext,
EntityKeyMetadata entityKeyMetadata)
A consumer is called for each tuple matching the selected
EntityKeyMetadata . |
Association |
getAssociation(AssociationKey key,
AssociationContext associationContext)
Return the list of tuples corresponding to a given association and the given context
|
DuplicateInsertPreventionStrategy |
getDuplicateInsertPreventionStrategy(EntityKeyMetadata entityKeyMetadata)
Returns this dialect's strategy for detecting the insertion of several entity tuples of the given type with the
same primary key.
|
ParameterMetadataBuilder |
getParameterMetadataBuilder()
Returns a builder for retrieving parameter meta-data from native queries in this datastore's format.
|
Tuple |
getTuple(EntityKey key,
OperationContext operationContext)
Return the tuple with the given column for a given key
|
List<Tuple> |
getTuples(EntityKey[] keys,
TupleContext tupleContext)
Return the list of tuples with the given columns for a given list of keys.
|
void |
insertOrUpdateAssociation(AssociationKey key,
Association association,
AssociationContext associationContext)
Inserts or updates the given association in the datastore.
|
void |
insertOrUpdateTuple(EntityKey key,
org.hibernate.ogm.entityentry.impl.TuplePointer tuplePointer,
TupleContext tupleContext)
Inserts or updates the tuple corresponding to the given entity key.
|
void |
insertTuple(EntityKeyMetadata entityKeyMetadata,
Tuple tuple,
TupleContext tupleContext)
Inserts the given tuple into the datastore, generating an id while doing so.
|
boolean |
isStoredInEntityStructure(AssociationKeyMetadata associationKeyMetadata,
AssociationTypeContext associationTypeContext)
Whether the specified association is stored within an entity structure or not.
|
Number |
nextValue(NextValueRequest request)
Returns the next value from the specified id generator with the specified increment.
|
GridType |
overrideType(Type type)
If the datastore does not support a
Type the dialect might override it with a custom one. |
org.hibernate.ogm.datastore.mongodb.query.impl.MongoDBQueryDescriptor |
parseNativeQuery(String nativeQuery)
Parses the given native query into a representation executable by this dialect.
|
void |
removeAssociation(AssociationKey key,
AssociationContext associationContext)
Remove the list of tuples corresponding to a given association
|
void |
removeTuple(EntityKey key,
TupleContext tupleContext)
Remove the tuple for a given key
|
boolean |
removeTupleWithOptimisticLock(EntityKey entityKey,
Tuple oldLockState,
TupleContext tupleContext)
Removes the given tuple.
|
boolean |
updateTupleWithOptimisticLock(EntityKey entityKey,
Tuple oldLockState,
Tuple tuple,
TupleContext tupleContext)
Updates the given tuple.
|
getLockingStrategy, isInTheInsertionQueue, supportsSequences, usesNavigationalInformationForInverseSideOfAssociations
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getLockingStrategy, supportsSequences, usesNavigationalInformationForInverseSideOfAssociations
public static final String ID_FIELDNAME
public static final String PROPERTY_SEPARATOR
public static final String ROWS_FIELDNAME
public static final String TABLE_FIELDNAME
public static final String ASSOCIATIONS_COLLECTION_PREFIX
public MongoDBDialect(org.hibernate.ogm.datastore.mongodb.impl.MongoDBDatastoreProvider provider)
public Tuple getTuple(EntityKey key, OperationContext operationContext)
GridDialect
getTuple
in interface GridDialect
key
- The tuple identifieroperationContext
- Contains additional information that might be used to create the tuplepublic List<Tuple> getTuples(EntityKey[] keys, TupleContext tupleContext)
MultigetGridDialect
All the keys provided will have the same EntityKeyMetadata
.
In other words they target the same "table".
getTuples
in interface MultigetGridDialect
keys
- The array of tuple identifiertupleContext
- Contains additional information that might be used to create the tuplespublic Tuple createTuple(EntityKeyMetadata entityKeyMetadata, OperationContext operationContext)
IdentityColumnAwareGridDialect
createTuple
in interface IdentityColumnAwareGridDialect
entityKeyMetadata
- Represents the entity type for which the tuple should be createdoperationContext
- Provides additional meta-data useful for tuple creationpublic Tuple createTuple(EntityKey key, OperationContext OperationContext)
GridDialect
Only invoked if no tuple is present yet for the given key. Implementations should not perform a round-trip to the
datastore but rather return a transient instance. The OGM engine will invoke
GridDialect.insertOrUpdateTuple(EntityKey, TuplePointer, TupleContext)
subsequently.
Columns in the tuple may represent properties of the corresponding entity as well as *-to-one associations to other entities. Implementations may choose to persist the latter e.g. in form of fields or as actual links/relationships to the element representing the associated entity. In case of multi-column keys, the corresponding association role for a given column can be obtained from the passed tuple context.
createTuple
in interface GridDialect
key
- The tuple identifierOperationContext
- Contains additional information that might be used to create the tuplepublic void insertOrUpdateTuple(EntityKey key, org.hibernate.ogm.entityentry.impl.TuplePointer tuplePointer, TupleContext tupleContext)
GridDialect
insertOrUpdateTuple
in interface GridDialect
key
- The tuple identifiertuplePointer
- A pointer to the list of operations to executetupleContext
- Contains additional information that might be used to create or update the tuplepublic boolean updateTupleWithOptimisticLock(EntityKey entityKey, Tuple oldLockState, Tuple tuple, TupleContext tupleContext)
OptimisticLockingAwareGridDialect
updateTupleWithOptimisticLock
in interface OptimisticLockingAwareGridDialect
entityKey
- The key of the entity to saveoldLockState
- A tuple with all those column values identifying the previous version of the record in the
datastore. Implementations are expected to apply all the contained columns to select the record to be updated.tuple
- The entity column values to savetupleContext
- Provides additional meta-data useful for the tuple updatetrue
if the update succeeded, false
otherwise (e.g. if the entity has been updated in the
datastore in parallel, so it has a newer version then the given one).public void insertTuple(EntityKeyMetadata entityKeyMetadata, Tuple tuple, TupleContext tupleContext)
IdentityColumnAwareGridDialect
insertTuple
in interface IdentityColumnAwareGridDialect
entityKeyMetadata
- The type of the entity to savetuple
- The entity column values to savetupleContext
- Provides additional meta-data useful for tuple insertionpublic void removeTuple(EntityKey key, TupleContext tupleContext)
GridDialect
removeTuple
in interface GridDialect
key
- The tuple identifiertupleContext
- Contains additional information that might be used to remove the tuplepublic boolean removeTupleWithOptimisticLock(EntityKey entityKey, Tuple oldLockState, TupleContext tupleContext)
OptimisticLockingAwareGridDialect
removeTupleWithOptimisticLock
in interface OptimisticLockingAwareGridDialect
entityKey
- The key of the entity to saveoldLockState
- A tuple with all those column values identifying the previous version of the record in the
datastore. Implementations are expected to apply all the contained columns to select the record to be removed.tupleContext
- Provides additional meta-data useful for the tuple removaltrue
if the deletion succeeded, false
otherwise (e.g. if the entity has been removed or
updated in the datastore in parallel, so it has a newer version then the given one).public Association getAssociation(AssociationKey key, AssociationContext associationContext)
GridDialect
getAssociation
in interface GridDialect
key
- Identifies the associationassociationContext
- Contains additional information that might be used to get the associationpublic Association createAssociation(AssociationKey key, AssociationContext associationContext)
GridDialect
Only invoked if the association does not yet exist in the datastore. Implementations should not perform a
round-trip to the datastore but rather return a transient instance. The OGM engine will invoke
GridDialect.insertOrUpdateAssociation(AssociationKey, Association, AssociationContext)
subsequently.
createAssociation
in interface GridDialect
key
- Identifies the associationassociationContext
- Contains additional information that might be used to create the associationpublic void insertOrUpdateAssociation(AssociationKey key, Association association, AssociationContext associationContext)
GridDialect
insertOrUpdateAssociation
in interface GridDialect
key
- Identifies the associationassociation
- The list of operations to executeassociationContext
- Contains additional information that might be used to create the associationpublic void removeAssociation(AssociationKey key, AssociationContext associationContext)
GridDialect
removeAssociation
in interface GridDialect
key
- Identifies the associationassociationContext
- Contains additional information that might be used to remove an associationpublic Number nextValue(NextValueRequest request)
GridDialect
nextValue
in interface GridDialect
request
- Identifies a specific id generatorpublic boolean isStoredInEntityStructure(AssociationKeyMetadata associationKeyMetadata, AssociationTypeContext associationTypeContext)
GridDialect
true
if this is the
case for a given association.isStoredInEntityStructure
in interface GridDialect
associationKeyMetadata
- identifies the association of interestassociationTypeContext
- provides additional contextual information about the represented association type,
such as the options effectively applying for ittrue
if the specified association is stored within an entity structure, false
otherwise.public GridType overrideType(Type type)
GridDialect
Type
the dialect might override it with a custom one.overrideType
in interface GridDialect
overrideType
in class BaseGridDialect
type
- The Type
that might need to be overriddentype
or null if the type does not need to be
overriddenpublic void forEachTuple(ModelConsumer consumer, TupleTypeContext tupleTypeContext, EntityKeyMetadata entityKeyMetadata)
GridDialect
EntityKeyMetadata
. The tuples must be of the
same indexed type.forEachTuple
in interface GridDialect
consumer
- the instance that is going to be called for every Tuple
tupleTypeContext
- contains additional information that might be used to build the tupleentityKeyMetadata
- the key metadata of the table for which we want to apply the consumerpublic ClosableIterator<Tuple> executeBackendQuery(BackendQuery<org.hibernate.ogm.datastore.mongodb.query.impl.MongoDBQueryDescriptor> backendQuery, QueryParameters queryParameters, TupleContext tupleContext)
QueryableGridDialect
executeBackendQuery
in interface QueryableGridDialect<org.hibernate.ogm.datastore.mongodb.query.impl.MongoDBQueryDescriptor>
backendQuery
- the query to execute in a representation understood by the underlying datastore. May have been
created by converting a JP-QL query or from a (named) native query.queryParameters
- parameters passed for this querytupleContext
- the tuple contextClosableIterator
with the result of the querypublic int executeBackendUpdateQuery(BackendQuery<org.hibernate.ogm.datastore.mongodb.query.impl.MongoDBQueryDescriptor> backendQuery, QueryParameters queryParameters, TupleContext tupleContext)
QueryableGridDialect
Precise semantics of an update are subject to design choices made for the actual database system in the backend. In particular, it may implement non-classical notions of consistency such as eventual consistency (rather than (conflict) serializablity as in most relational SQL database systems).
executeBackendUpdateQuery
in interface QueryableGridDialect<org.hibernate.ogm.datastore.mongodb.query.impl.MongoDBQueryDescriptor>
backendQuery
- the query to execute in a representation understood by the underlying datastore. May have been
created by converting a JP-QL query or from a (named) native query.queryParameters
- parameters passed for this querytupleContext
- the tuple contextpublic org.hibernate.ogm.datastore.mongodb.query.impl.MongoDBQueryDescriptor parseNativeQuery(String nativeQuery)
QueryableGridDialect
parseNativeQuery
in interface QueryableGridDialect<org.hibernate.ogm.datastore.mongodb.query.impl.MongoDBQueryDescriptor>
nativeQuery
- the native query to parsepublic DuplicateInsertPreventionStrategy getDuplicateInsertPreventionStrategy(EntityKeyMetadata entityKeyMetadata)
GridDialect
getDuplicateInsertPreventionStrategy
in interface GridDialect
getDuplicateInsertPreventionStrategy
in class BaseGridDialect
entityKeyMetadata
- meta-data identifying the entity type of interestpublic void executeBatch(OperationsQueue queue)
BatchableGridDialect
executeBatch
in interface BatchableGridDialect
queue
- The batched operationspublic ParameterMetadataBuilder getParameterMetadataBuilder()
QueryableGridDialect
getParameterMetadataBuilder
in interface QueryableGridDialect<org.hibernate.ogm.datastore.mongodb.query.impl.MongoDBQueryDescriptor>
public ClosableIterator<Tuple> callStoredProcedure(String storedProcedureName, ProcedureQueryParameters params, TupleContext tupleContext)
callStoredProcedure
in interface StoredProcedureAwareGridDialect
storedProcedureName
- name of stored procedureparams
- query parameterstupleContext
- the tuple contextClosableIterator
Copyright © 2010-2024 Red Hat, Inc. and others. Licensed under the GNU Lesser General Public License (LGPL), version 2.1 or later.