forked from hibernate/hibernate-ogm
-
Notifications
You must be signed in to change notification settings - Fork 2
/
GridDialect.java
135 lines (119 loc) · 5.66 KB
/
GridDialect.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/*
* Hibernate OGM, Domain model persistence for NoSQL datastores
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.ogm.dialect.spi;
import org.hibernate.LockMode;
import org.hibernate.dialect.lock.LockingStrategy;
import org.hibernate.ogm.model.key.spi.AssociationKey;
import org.hibernate.ogm.model.key.spi.AssociationKeyMetadata;
import org.hibernate.ogm.model.key.spi.EntityKey;
import org.hibernate.ogm.model.key.spi.EntityKeyMetadata;
import org.hibernate.ogm.model.spi.Association;
import org.hibernate.ogm.model.spi.Tuple;
import org.hibernate.ogm.type.spi.GridType;
import org.hibernate.ogm.util.Experimental;
import org.hibernate.persister.entity.Lockable;
import org.hibernate.service.Service;
import org.hibernate.type.Type;
/**
* Dialect abstracting Hibernate OGM from the grid implementation.
* <p>
* Specific grid dialects may implement one or more <i>facet interfaces</i>, in order to provide additional
* functionality such as querying or batching support. Rather than implementing this interface directly, it is recommend
* to extend {@link BaseGridDialect}.
*
* @author Emmanuel Bernard
* @author Gunnar Morling
*/
public interface GridDialect extends Service {
LockingStrategy getLockingStrategy(Lockable lockable, LockMode lockMode);
/**
* Return the tuple with the given column for a given key
*/
Tuple getTuple(EntityKey key, TupleContext tupleContext);
/**
* Creates a new tuple for the given entity key.
* <p>
* 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
* {@link #insertOrUpdateTuple(EntityKey, Tuple, TupleContext)} subsequently.
* <p>
* 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.
*/
Tuple createTuple(EntityKey key, TupleContext tupleContext);
/**
* Inserts or updates the tuple corresponding to the given entity key.
*/
void insertOrUpdateTuple(EntityKey key, Tuple tuple, TupleContext tupleContext);
/**
* Remove the tuple for a given key
*/
void removeTuple(EntityKey key, TupleContext tupleContext);
/**
* Return the list of tuples corresponding to a given association and the given context
*/
Association getAssociation(AssociationKey key, AssociationContext associationContext);
/**
* Creates a new (empty) association for storing the tuples representing the rows corresponding to the given key.
* <p>
* 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
* {@link #insertOrUpdateAssociation(AssociationKey, Association, AssociationContext)} subsequently.
*/
Association createAssociation(AssociationKey key, AssociationContext associationContext);
/**
* Inserts or updates the given association in the datastore.
*/
void insertOrUpdateAssociation(AssociationKey key, Association association, AssociationContext associationContext);
/**
* Remove the list of tuples corresponding to a given association
*/
void removeAssociation(AssociationKey key, AssociationContext associationContext);
/**
* Whether the specified association is stored within an entity structure or not. E.g. dialects for document stores
* may support storing associations within entity documents and would have to return {@code true} if this is the
* case for a given association.
*
* @param associationKeyMetadata identifies the association of interest
* @param associationTypeContext provides additional contextual information about the represented association type,
* such as the options effectively applying for it
* @return {@code true} if the specified association is stored within an entity structure, {@code false} otherwise.
*/
boolean isStoredInEntityStructure(AssociationKeyMetadata associationKeyMetadata, AssociationTypeContext associationTypeContext);
/**
* Returns the next value from the specified id generator with the specified increment.
*
* @return the next value from the specified id generator
*/
Number nextValue(NextValueRequest request);
/**
* Whether this dialect supports sequences for id generation or not. If not, a table-based strategy will be used as
* fall-back.
*
* @return {@code true} if this dialect supports sequences, {@code false} otherwise.
*/
boolean supportsSequences();
/**
* Let the dialect override types if required to customize them to the datastore. Returns the GridType instance to
* use to bind the given {@code type} or null if not overridden.
* <p>
* Most types should not be overridden and thus return null
*/
@Experimental( "Custom types including the GridType contract will be re-visited after OGM 4.1.0.Final." )
GridType overrideType(Type type);
/**
* A consumer is called for each tuple matching the selected {@link EntityKeyMetadata}.
*
* @param consumer
* the instance that is going to be called for every {@link Tuple}
* @param entityKeyMetadatas
* the key metadata of the tables for which we want to apply the costumer
*/
void forEachTuple(ModelConsumer consumer, EntityKeyMetadata... entityKeyMetadatas);
}