public class SpannerTemplate extends Object implements SpannerOperations, org.springframework.context.ApplicationEventPublisherAware
SpannerOperations
.Constructor and Description |
---|
SpannerTemplate(Supplier<DatabaseClient> databaseClientProvider,
SpannerMappingContext mappingContext,
SpannerEntityProcessor spannerEntityProcessor,
SpannerMutationFactory spannerMutationFactory,
SpannerSchemaUtils spannerSchemaUtils) |
Modifier and Type | Method and Description |
---|---|
protected void |
applyMutations(Collection<Mutation> mutations) |
<T> long |
count(Class<T> entityClass)
Count how many objects are stored of the given type.
|
<T> void |
delete(Class<T> entityClass,
Key key)
Deletes an object based on a key.
|
<T> void |
delete(Class<T> entityClass,
KeySet keys)
Deletes objects given a set of keys.
|
void |
delete(Object entity)
Deletes an object from storage.
|
void |
deleteAll(Iterable<?> objects)
Deletes objects from storage in a batch.
|
long |
executeDmlStatement(Statement statement)
Execute a DML statement on Cloud Spanner.
|
long |
executePartitionedDmlStatement(Statement statement)
Execute a DML statement in partitioned mode.
|
ResultSet |
executeQuery(Statement statement,
SpannerQueryOptions options) |
<T> boolean |
existsById(Class<T> entityClass,
Key key)
Returns whether an entity with the given id exists.
|
SpannerMappingContext |
getMappingContext() |
protected ReadContext |
getReadContext() |
protected ReadContext |
getReadContext(TimestampBound timestampBound) |
SpannerEntityProcessor |
getSpannerEntityProcessor() |
void |
insert(Object object)
Insert an object into storage.
|
void |
insertAll(Iterable<?> objects)
Insert objects into storage in batch.
|
<T> T |
performReadOnlyTransaction(Function<SpannerTemplate,T> operations,
SpannerReadOptions readOptions)
Performs multiple read-only operations in a single transaction.
|
<T> T |
performReadWriteTransaction(Function<SpannerTemplate,T> operations)
Performs multiple read and write operations in a single transaction.
|
<T> List<T> |
query(Class<T> entityClass,
Statement statement,
SpannerQueryOptions options)
Finds objects by using an SQL statement.
|
<A> List<A> |
query(Function<Struct,A> rowFunc,
Statement statement,
SpannerQueryOptions options)
Executes a given query string with tags and parameters and applies a given function to
each row of the result.
|
<T> List<T> |
queryAll(Class<T> entityClass,
SpannerPageableQueryOptions options)
Finds all objects of the given type.
|
<T> T |
read(Class<T> entityClass,
Key key)
Finds a single stored object using a key.
|
<T> List<T> |
read(Class<T> entityClass,
KeySet keys)
Finds objects stored from their keys.
|
<T> List<T> |
read(Class<T> entityClass,
KeySet keys,
SpannerReadOptions options)
Finds objects stored from their keys.
|
<T> T |
read(Class<T> entityClass,
Key key,
SpannerReadOptions options)
Finds a single stored object using a key.
|
<T> List<T> |
readAll(Class<T> entityClass)
Finds all objects of the given type.
|
<T> List<T> |
readAll(Class<T> entityClass,
SpannerReadOptions options)
Finds all objects of the given type.
|
void |
setApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher applicationEventPublisher) |
void |
update(Object object)
Update an object already in storage.
|
void |
update(Object object,
Set<String> includeProperties)
Update an object in storage.
|
void |
update(Object object,
String... includeProperties)
Update an object in storage.
|
void |
updateAll(Iterable<?> objects)
Update objects in batch.
|
void |
upsert(Object object)
Update or insert an object into storage.
|
void |
upsert(Object object,
Set<String> includeProperties)
Update or insert an object into storage.
|
void |
upsert(Object object,
String... includeProperties)
Update or insert an object into storage.
|
void |
upsertAll(Iterable<?> objects)
Update or insert objects into storage in batch.
|
public SpannerTemplate(Supplier<DatabaseClient> databaseClientProvider, SpannerMappingContext mappingContext, SpannerEntityProcessor spannerEntityProcessor, SpannerMutationFactory spannerMutationFactory, SpannerSchemaUtils spannerSchemaUtils)
public void setApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher applicationEventPublisher)
setApplicationEventPublisher
in interface org.springframework.context.ApplicationEventPublisherAware
protected ReadContext getReadContext()
protected ReadContext getReadContext(TimestampBound timestampBound)
public SpannerMappingContext getMappingContext()
public SpannerEntityProcessor getSpannerEntityProcessor()
public long executeDmlStatement(Statement statement)
SpannerOperations
SpannerOperations.executePartitionedDmlStatement(Statement)
for executing partitioned DML without a transaction.executeDmlStatement
in interface SpannerOperations
statement
- the DML statement to execute.public long executePartitionedDmlStatement(Statement statement)
SpannerOperations
executePartitionedDmlStatement
in interface SpannerOperations
statement
- the DML statement to execute.public <T> T read(Class<T> entityClass, Key key)
SpannerOperations
read
in interface SpannerOperations
T
- the type of the object to retrieve.entityClass
- the type of the object to retrieve.key
- the key of the object.public <T> boolean existsById(Class<T> entityClass, Key key)
SpannerOperations
existsById
in interface SpannerOperations
T
- the type of the object to check.entityClass
- the type of the entitykey
- the key of the objectpublic <T> T read(Class<T> entityClass, Key key, SpannerReadOptions options)
SpannerOperations
read
in interface SpannerOperations
T
- the type of the object to retrieve.entityClass
- the type of the object to retrieve.key
- the key of the object.options
- the Cloud Spanner read options with which to conduct the read operation.public <T> List<T> read(Class<T> entityClass, KeySet keys)
SpannerOperations
read
in interface SpannerOperations
T
- the type of the object to retrieve.entityClass
- the type of the object to retrieve.keys
- the keys of the objects to retrieve.public <T> List<T> read(Class<T> entityClass, KeySet keys, SpannerReadOptions options)
SpannerOperations
Where
class annotation
or any of the properties is eagerly interleaved, the SQL query will be performed instead of the
ReadContext.read(java.lang.String, com.google.cloud.spanner.KeySet, java.lang.Iterable<java.lang.String>, com.google.cloud.spanner.Options.ReadOption...)
to fetch such properties and satisfy the sql where
condition.read
in interface SpannerOperations
T
- the type of the object to retrieve.entityClass
- the type of the object to retrieve.keys
- the keys of the objects to retrieve.options
- the Cloud Spanner read options with which to conduct the read operation.public <A> List<A> query(Function<Struct,A> rowFunc, Statement statement, SpannerQueryOptions options)
SpannerOperations
query
in interface SpannerOperations
A
- the type to convert each row Struct into.rowFunc
- the function to apply to each row of the result.statement
- the SQL statement used to select the objects.options
- the options with which to run this query.public <T> List<T> query(Class<T> entityClass, Statement statement, SpannerQueryOptions options)
SpannerOperations
query
in interface SpannerOperations
T
- the type of object to retrieve.entityClass
- the type of object to retrieve.statement
- the SQL statement used to select the objects.options
- the Cloud Spanner read options with which to conduct the read operation.public <T> List<T> readAll(Class<T> entityClass, SpannerReadOptions options)
SpannerOperations
readAll
in interface SpannerOperations
T
- the type of the object to retrieve.entityClass
- the type of the object to retrieve.options
- the Cloud Spanner read options with which to conduct the read operation.public <T> List<T> readAll(Class<T> entityClass)
SpannerOperations
readAll
in interface SpannerOperations
T
- the type of the object to retrieve.entityClass
- the type of the object to retrieve.public <T> List<T> queryAll(Class<T> entityClass, SpannerPageableQueryOptions options)
SpannerOperations
queryAll
in interface SpannerOperations
T
- the type of the object to retrieve.entityClass
- the type of the object to retrieve.options
- the Cloud Spanner query options with which to conduct the query operation.public void insert(Object object)
SpannerOperations
insert
in interface SpannerOperations
object
- the object to insert.public void insertAll(Iterable<?> objects)
SpannerOperations
insertAll
in interface SpannerOperations
objects
- the objects to insert.public void update(Object object)
SpannerOperations
update
in interface SpannerOperations
object
- the object to update.public void updateAll(Iterable<?> objects)
SpannerOperations
updateAll
in interface SpannerOperations
objects
- the objects to update.public void update(Object object, String... includeProperties)
SpannerOperations
update
in interface SpannerOperations
object
- the object to update.includeProperties
- the properties to upsert. if none are given then all
properties are usedpublic void update(Object object, Set<String> includeProperties)
SpannerOperations
update
in interface SpannerOperations
object
- the object to update.includeProperties
- the properties to update. If null is given, then all
properties are used. Note that an empty Set
means that no properties will
be used.public void upsert(Object object)
SpannerOperations
upsert
in interface SpannerOperations
object
- the object to update or insert.public void upsertAll(Iterable<?> objects)
SpannerOperations
upsertAll
in interface SpannerOperations
objects
- the objects to update or insert.public void upsert(Object object, String... includeProperties)
SpannerOperations
upsert
in interface SpannerOperations
object
- the object to update or insert.includeProperties
- the properties to upsert. if none are given then all
properties are upserted.public void upsert(Object object, Set<String> includeProperties)
SpannerOperations
upsert
in interface SpannerOperations
object
- the object to update or insert.includeProperties
- the properties to update. If null is given, then all
properties are used. Note that an empty Set
means that no properties will
be used.public void delete(Object entity)
SpannerOperations
delete
in interface SpannerOperations
entity
- the object to delete from storage.public void deleteAll(Iterable<?> objects)
SpannerOperations
deleteAll
in interface SpannerOperations
objects
- the objects to delete from storage.public <T> void delete(Class<T> entityClass, Key key)
SpannerOperations
delete
in interface SpannerOperations
T
- the type of the object to delete.entityClass
- the type of the object to delete.key
- the key of the object to delete from storage.public <T> void delete(Class<T> entityClass, KeySet keys)
SpannerOperations
delete
in interface SpannerOperations
T
- the type of the object to delete.entityClass
- the type of object to delete.keys
- the keys of the objects to delete.public <T> long count(Class<T> entityClass)
SpannerOperations
count
in interface SpannerOperations
T
- the type of the object to count.entityClass
- the type of object to count.public <T> T performReadWriteTransaction(Function<SpannerTemplate,T> operations)
SpannerOperations
performReadWriteTransaction
in interface SpannerOperations
T
- the final return type of the operations.operations
- the function representing the operations to perform using a
SpannerOperations based on a single transaction.public <T> T performReadOnlyTransaction(Function<SpannerTemplate,T> operations, SpannerReadOptions readOptions)
SpannerOperations
performReadOnlyTransaction
in interface SpannerOperations
T
- the final return type of the operations.operations
- the function representing the operations to perform using a
SpannerOperations based on a single transaction.readOptions
- allows the user to specify staleness for the read transactionpublic ResultSet executeQuery(Statement statement, SpannerQueryOptions options)
protected void applyMutations(Collection<Mutation> mutations)
Copyright © 2021. All rights reserved.