public class SpannerTemplate extends Object implements SpannerOperations
Constructor and Description |
---|
SpannerTemplate(com.google.cloud.spanner.DatabaseClient databaseClient,
SpannerMappingContext mappingContext,
SpannerConverter spannerConverter,
SpannerMutationFactory spannerMutationFactory) |
Modifier and Type | Method and Description |
---|---|
protected <T,U> void |
applyMutationTwoArgs(BiFunction<T,U,com.google.cloud.spanner.Mutation> function,
T arg1,
U arg2) |
long |
count(Class entityClass)
Count how many objects are stored of the given type.
|
<T> void |
delete(Class<T> entityClass,
Iterable<? extends T> entities)
Deletes multiple objects from storage.
|
void |
delete(Class entityClass,
com.google.cloud.spanner.Key key)
Deletes an object based on a key.
|
void |
delete(Class entityClass,
com.google.cloud.spanner.KeySet keys)
Deletes objects given a set of keys.
|
void |
delete(Object entity)
Deletes an object from storage.
|
SpannerMappingContext |
getMappingContext() |
protected com.google.cloud.spanner.ReadContext |
getReadContext() |
protected com.google.cloud.spanner.ReadContext |
getReadContext(com.google.cloud.Timestamp timestamp) |
void |
insert(Object object)
Insert an object into storage.
|
<T> T |
performReadOnlyTransaction(Function<SpannerOperations,T> operations,
SpannerReadOptions readOptions)
Performs multiple read-only operations in a single transaction.
|
<T> T |
performReadWriteTransaction(Function<SpannerOperations,T> operations)
Performs multiple read and write operations in a single transaction.
|
<T> List<T> |
query(Class<T> entityClass,
com.google.cloud.spanner.Statement statement)
Finds objects by using an SQL statement.
|
<T> List<T> |
query(Class<T> entityClass,
com.google.cloud.spanner.Statement statement,
SpannerQueryOptions options)
Finds objects by using an SQL statement.
|
<T> org.springframework.data.domain.Page<T> |
queryAll(Class<T> entityClass,
org.springframework.data.domain.Pageable pageable)
Finds all objects of the given type.
|
<T> org.springframework.data.domain.Page<T> |
queryAll(Class<T> entityClass,
org.springframework.data.domain.Pageable pageable,
SpannerQueryOptions options)
Finds all objects of the given type.
|
<T> List<T> |
queryAll(Class<T> entityClass,
org.springframework.data.domain.Sort sort)
Finds all objects of the given type.
|
<T> List<T> |
queryAll(Class<T> entityClass,
org.springframework.data.domain.Sort sort,
SpannerQueryOptions options)
Finds all objects of the given type.
|
<T> T |
read(Class<T> entityClass,
com.google.cloud.spanner.Key key)
Finds a single stored object using a key.
|
<T> List<T> |
read(Class<T> entityClass,
com.google.cloud.spanner.KeySet keys)
Finds objects stored from their keys.
|
<T> List<T> |
read(Class<T> entityClass,
com.google.cloud.spanner.KeySet keys,
SpannerReadOptions options)
Finds objects stored from their keys.
|
<T> T |
read(Class<T> entityClass,
com.google.cloud.spanner.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 |
update(Object object)
Update an object already in storage.
|
void |
update(Object object,
Optional<Set<String>> includeColumns)
Update an object in storage.
|
void |
update(Object object,
String... includeColumns)
Update an object in storage.
|
void |
upsert(Object object)
Update or insert an object into storage.
|
void |
upsert(Object object,
Optional<Set<String>> includeColumns)
Update or insert an object into storage.
|
void |
upsert(Object object,
String... includeColumns)
Update or insert an object into storage.
|
public SpannerTemplate(com.google.cloud.spanner.DatabaseClient databaseClient, SpannerMappingContext mappingContext, SpannerConverter spannerConverter, SpannerMutationFactory spannerMutationFactory)
protected com.google.cloud.spanner.ReadContext getReadContext()
protected com.google.cloud.spanner.ReadContext getReadContext(com.google.cloud.Timestamp timestamp)
public SpannerMappingContext getMappingContext()
public <T> T read(Class<T> entityClass, com.google.cloud.spanner.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> T read(Class<T> entityClass, com.google.cloud.spanner.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
- Spanner read options with which to conduct the read operation.public <T> List<T> read(Class<T> entityClass, com.google.cloud.spanner.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, com.google.cloud.spanner.KeySet keys, SpannerReadOptions options)
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.options
- Spanner read options with which to conduct the read operation.public <T> List<T> query(Class<T> entityClass, com.google.cloud.spanner.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
- Spanner read options with which to conduct the read operation.public <T> List<T> query(Class<T> entityClass, com.google.cloud.spanner.Statement statement)
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.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
- 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, org.springframework.data.domain.Sort sort)
SpannerOperations
queryAll
in interface SpannerOperations
T
- the type of the object to retrieve.entityClass
- the type of the object to retrieve.sort
- the sorting used for the results.public <T> List<T> queryAll(Class<T> entityClass, org.springframework.data.domain.Sort sort, SpannerQueryOptions options)
SpannerOperations
queryAll
in interface SpannerOperations
T
- the type of the object to retrieve.entityClass
- the type of the object to retrieve.sort
- the sorting used for the results.options
- Spanner query options with which to conduct the query operation.public <T> org.springframework.data.domain.Page<T> queryAll(Class<T> entityClass, org.springframework.data.domain.Pageable pageable, SpannerQueryOptions options)
SpannerOperations
queryAll
in interface SpannerOperations
T
- the type of the object to retrieve.entityClass
- the type of the object to retrieve.pageable
- the paging options for this request.options
- Spanner query options with which to conduct the query operation.public <T> org.springframework.data.domain.Page<T> queryAll(Class<T> entityClass, org.springframework.data.domain.Pageable pageable)
SpannerOperations
queryAll
in interface SpannerOperations
T
- the type of the object to retrieve.entityClass
- the type of the object to retrieve.pageable
- the paging options for this request.public void insert(Object object)
SpannerOperations
insert
in interface SpannerOperations
object
- the object to insert.public void update(Object object)
SpannerOperations
update
in interface SpannerOperations
object
- the object to update.public void update(Object object, String... includeColumns)
SpannerOperations
update
in interface SpannerOperations
object
- the object to update.includeColumns
- the columns to upsert. if none are given then all columns are
usedpublic void update(Object object, Optional<Set<String>> includeColumns)
SpannerOperations
update
in interface SpannerOperations
object
- the object to update.includeColumns
- the columns to update. If null or an empty Optional is given, then
all columns are used. Note that an Optional occupied by an empty Set means that no columns
will be used.public void upsert(Object object)
SpannerOperations
upsert
in interface SpannerOperations
object
- the object to update or insert.public void upsert(Object object, String... includeColumns)
SpannerOperations
upsert
in interface SpannerOperations
object
- the object to update or insert.includeColumns
- the columns to upsert. if none are given then all columns are
upserted.public void upsert(Object object, Optional<Set<String>> includeColumns)
SpannerOperations
upsert
in interface SpannerOperations
object
- the object to update or insert.includeColumns
- the columns to upsert. If null or an empty Optional is given, then
all columns are used. Note that an Optional occupied by an empty Set means that no columns
will be used.public void delete(Object entity)
SpannerOperations
delete
in interface SpannerOperations
entity
- the object to delete from storage.public void delete(Class entityClass, com.google.cloud.spanner.Key key)
SpannerOperations
delete
in interface SpannerOperations
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, Iterable<? extends T> entities)
SpannerOperations
delete
in interface SpannerOperations
T
- the type of the object to delete.entityClass
- the type of the object to delete.entities
- the objects to delete.public void delete(Class entityClass, com.google.cloud.spanner.KeySet keys)
SpannerOperations
delete
in interface SpannerOperations
entityClass
- the type of object to delete.keys
- the keys of the objects to delete.public long count(Class entityClass)
SpannerOperations
count
in interface SpannerOperations
entityClass
- the type of object to count.public <T> T performReadWriteTransaction(Function<SpannerOperations,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<SpannerOperations,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 transactionprotected <T,U> void applyMutationTwoArgs(BiFunction<T,U,com.google.cloud.spanner.Mutation> function, T arg1, U arg2)
Copyright © 2018 Pivotal Software, Inc.. All rights reserved.