org.springframework.data.cassandra.core.AsyncCassandraOperationsExtensions.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of spring-data-cassandra Show documentation
Show all versions of spring-data-cassandra Show documentation
Cassandra support for Spring Data
/*
* Copyright 2018-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.cassandra.core
import com.datastax.oss.driver.api.core.cql.Statement
import org.springframework.data.cassandra.core.query.Query
import org.springframework.data.cassandra.core.query.Update
import org.springframework.data.domain.Slice
import java.util.concurrent.CompletableFuture
import kotlin.reflect.KClass
/**
* Extensions for [AsyncCassandraOperations].
*
* @author Mark Paluch
* @since 2.1
*/
// -------------------------------------------------------------------------
// Methods dealing with static CQL
// -------------------------------------------------------------------------
/**
* Extension for [AsyncCassandraOperations.select] providing a [KClass] based variant.
*/
@Deprecated(
"Since 2.2, use the reified variant",
replaceWith = ReplaceWith("select(cql)")
)
fun AsyncCassandraOperations.select(
cql: String,
entityClass: KClass
): CompletableFuture> =
select(cql, entityClass.java)
/**
* Extension for [AsyncCassandraOperations.select] leveraging reified type parameters.
*/
inline fun AsyncCassandraOperations.select(cql: String): CompletableFuture> =
select(cql, T::class.java)
/**
* Extension for [AsyncCassandraOperations.select] providing a Consumer-like function.
*/
@Deprecated(
"Since 2.2, use the reified variant",
replaceWith = ReplaceWith("select(cql, consumer)")
)
fun AsyncCassandraOperations.select(
cql: String,
entityClass: KClass,
consumer: (T) -> Unit
): CompletableFuture =
select(cql, consumer, entityClass.java)
/**
* Extension for [AsyncCassandraOperations.select] providing a Consumer-like function leveraging reified type parameters.
*/
inline fun AsyncCassandraOperations.select(
cql: String,
crossinline consumer: (T) -> Unit
): CompletableFuture =
select(cql, { consumer(it) }, T::class.java)
/**
* Extension for [AsyncCassandraOperations.selectOne] providing a [KClass] based variant.
*/
@Deprecated(
"Since 2.2, use the reified variant",
replaceWith = ReplaceWith("selectOne(cql)")
)
fun AsyncCassandraOperations.selectOne(
cql: String,
entityClass: KClass
): CompletableFuture =
selectOne(cql, entityClass.java)
/**
* Extension for [AsyncCassandraOperations.selectOne] leveraging reified type parameters.
*/
inline fun AsyncCassandraOperations.selectOne(cql: String): CompletableFuture =
selectOne(cql, T::class.java)
// -------------------------------------------------------------------------
// Methods dealing with com.datastax.oss.driver.api.core.cql.Statement
// -------------------------------------------------------------------------
/**
* Extension for [AsyncCassandraOperations.select] providing a [KClass] based variant.
*/
@Deprecated(
"Since 2.2, use the reified variant",
replaceWith = ReplaceWith("select(statement)")
)
fun AsyncCassandraOperations.select(
statement: Statement<*>,
entityClass: KClass
): CompletableFuture> =
select(statement, entityClass.java)
/**
* Extension for [AsyncCassandraOperations.select] leveraging reified type parameters.
*/
inline fun AsyncCassandraOperations.select(statement: Statement<*>): CompletableFuture> =
select(statement, T::class.java)
/**
* Extension for [AsyncCassandraOperations.select] providing a Consumer-like function.
*/
@Deprecated(
"Since 2.2, use the reified variant",
replaceWith = ReplaceWith("select(statement, consumer)")
)
fun AsyncCassandraOperations.select(
statement: Statement<*>,
entityClass: KClass,
consumer: (T) -> Unit
): CompletableFuture =
select(statement, consumer, entityClass.java)
/**
* Extension for [AsyncCassandraOperations.select] providing a Consumer-like function leveraging reified type parameters.
*/
inline fun AsyncCassandraOperations.select(
statement: Statement<*>,
crossinline consumer: (T) -> Unit
): CompletableFuture =
select(statement, { consumer(it) }, T::class.java)
/**
* Extension for [AsyncCassandraOperations.slice] providing a [KClass] based variant.
*/
@Deprecated(
"Since 2.2, use the reified variant",
replaceWith = ReplaceWith("slice(statement)")
)
fun AsyncCassandraOperations.slice(
statement: Statement<*>,
entityClass: KClass
): CompletableFuture> =
slice(statement, entityClass.java)
/**
* Extension for [AsyncCassandraOperations.slice] leveraging reified type parameters.
*/
inline fun AsyncCassandraOperations.slice(statement: Statement<*>): CompletableFuture> =
slice(statement, T::class.java)
/**
* Extension for [AsyncCassandraOperations.selectOne] providing a [KClass] based variant.
*/
@Deprecated(
"Since 2.2, use the reified variant",
replaceWith = ReplaceWith("selectOne(statement)")
)
fun AsyncCassandraOperations.selectOne(
statement: Statement<*>,
entityClass: KClass
): CompletableFuture =
selectOne(statement, entityClass.java)
/**
* Extension for [AsyncCassandraOperations.selectOne] leveraging reified type parameters.
*/
inline fun AsyncCassandraOperations.selectOne(statement: Statement<*>): CompletableFuture =
selectOne(statement, T::class.java)
// -------------------------------------------------------------------------
// Methods dealing with org.springframework.data.cassandra.core.query.Query
// -------------------------------------------------------------------------
/**
* Extension for [AsyncCassandraOperations.select] providing a [KClass] based variant.
*/
@Deprecated(
"Since 2.2, use the reified variant",
replaceWith = ReplaceWith("select(query)")
)
fun AsyncCassandraOperations.select(
query: Query,
entityClass: KClass
): CompletableFuture> =
select(query, entityClass.java)
/**
* Extension for [AsyncCassandraOperations.select] leveraging reified type parameters.
*/
inline fun AsyncCassandraOperations.select(query: Query): CompletableFuture> =
select(query, T::class.java)
/**
* Extension for [AsyncCassandraOperations.select] providing a Consumer-like function.
*/
@Deprecated(
"Since 2.2, use the reified variant",
replaceWith = ReplaceWith("select(query, consumer)")
)
fun AsyncCassandraOperations.select(
query: Query,
entityClass: KClass,
consumer: (T) -> Unit
): CompletableFuture =
select(query, consumer, entityClass.java)
/**
* Extension for [AsyncCassandraOperations.select] providing a Consumer-like function leveraging reified type parameters.
*/
@Deprecated(
"Since 2.2, use the reified variant",
replaceWith = ReplaceWith("select(query, consumer)")
)
inline fun AsyncCassandraOperations.select(
query: Query,
crossinline consumer: (T) -> Unit
): CompletableFuture =
select(query, { consumer(it) }, T::class.java)
/**
* Extension for [AsyncCassandraOperations.slice] providing a [KClass] based variant.
*/
@Deprecated(
"Since 2.2, use the reified variant",
replaceWith = ReplaceWith("slice(query)")
)
fun AsyncCassandraOperations.slice(
query: Query,
entityClass: KClass
): CompletableFuture> =
slice(query, entityClass.java)
/**
* Extension for [AsyncCassandraOperations.slice] leveraging reified type parameters.
*/
inline fun AsyncCassandraOperations.slice(query: Query): CompletableFuture> =
slice(query, T::class.java)
/**
* Extension for [AsyncCassandraOperations.selectOne] providing a [KClass] based variant.
*/
@Deprecated(
"Since 2.2, use the reified variant",
replaceWith = ReplaceWith("selectOne(query)")
)
fun AsyncCassandraOperations.selectOne(
query: Query,
entityClass: KClass
): CompletableFuture =
selectOne(query, entityClass.java)
/**
* Extension for [AsyncCassandraOperations.selectOne] leveraging reified type parameters.
*/
inline fun AsyncCassandraOperations.selectOne(query: Query): CompletableFuture =
selectOne(query, T::class.java)
/**
* Extension for [AsyncCassandraOperations.update] providing a [KClass] based variant.
*/
@Deprecated(
"Since 2.2, use the reified variant",
replaceWith = ReplaceWith("update(query, update)")
)
fun AsyncCassandraOperations.update(
query: Query,
update: Update,
entityClass: KClass
): CompletableFuture =
update(query, update, entityClass.java)
/**
* Extension for [AsyncCassandraOperations.update] leveraging reified type parameters.
*/
inline fun AsyncCassandraOperations.update(
query: Query,
update: Update
): CompletableFuture =
update(query, update, T::class.java)
/**
* Extension for [AsyncCassandraOperations.delete] providing a [KClass] based variant.
*/
@Deprecated(
"Since 2.2, use the reified variant",
replaceWith = ReplaceWith("delete(query)")
)
fun AsyncCassandraOperations.delete(
query: Query,
entityClass: KClass
): CompletableFuture =
delete(query, entityClass.java)
/**
* Extension for [AsyncCassandraOperations.delete] leveraging reified type parameters.
*/
@Suppress("EXTENSION_SHADOWED_BY_MEMBER")
inline fun AsyncCassandraOperations.delete(query: Query): CompletableFuture =
delete(query, T::class.java)
// -------------------------------------------------------------------------
// Methods dealing with entities
// -------------------------------------------------------------------------
/**
* Extension for [AsyncCassandraOperations.count] providing a [KClass] based variant.
*/
@Deprecated("Since 2.2, use the reified variant", replaceWith = ReplaceWith("count()"))
fun AsyncCassandraOperations.count(entityClass: KClass): CompletableFuture =
count(entityClass.java)
/**
* Extension for [AsyncCassandraOperations.count] leveraging reified type parameters.
*/
inline fun AsyncCassandraOperations.count(): CompletableFuture =
count(T::class.java)
/**
* Extension for [AsyncCassandraOperations.count] providing a [KClass] based variant.
*/
@Deprecated(
"Since 2.2, use the reified variant",
replaceWith = ReplaceWith("count(query)")
)
fun AsyncCassandraOperations.count(
query: Query,
entityClass: KClass
): CompletableFuture =
count(query, entityClass.java)
/**
* Extension for [AsyncCassandraOperations.count] leveraging reified type parameters.
*/
inline fun AsyncCassandraOperations.count(query: Query): CompletableFuture =
count(query, T::class.java)
/**
* Extension for [AsyncCassandraOperations.exists] providing a [KClass] based variant.
*/
@Deprecated(
"Since 2.2, use the reified variant",
replaceWith = ReplaceWith("exists(id)")
)
fun AsyncCassandraOperations.exists(
id: Any,
entityClass: KClass
): CompletableFuture =
exists(id, entityClass.java)
/**
* Extension for [AsyncCassandraOperations.exists] leveraging reified type parameters.
*/
inline fun AsyncCassandraOperations.exists(id: Any): CompletableFuture =
exists(id, T::class.java)
/**
* Extension for [AsyncCassandraOperations.count] providing a [KClass] based variant.
*/
@Deprecated(
"Since 2.2, use the reified variant",
replaceWith = ReplaceWith("exists(query)")
)
fun AsyncCassandraOperations.exists(
query: Query,
entityClass: KClass
): CompletableFuture =
exists(query, entityClass.java)
/**
* Extension for [AsyncCassandraOperations.count] leveraging reified type parameters.
*/
inline fun AsyncCassandraOperations.exists(query: Query): CompletableFuture =
exists(query, T::class.java)
/**
* Extension for [AsyncCassandraOperations.selectOneById] providing a [KClass] based variant.
*/
@Deprecated(
"Since 2.2, use the reified variant",
replaceWith = ReplaceWith("selectOneById(id)")
)
fun AsyncCassandraOperations.selectOneById(
id: Any,
entityClass: KClass
): CompletableFuture =
selectOneById(id, entityClass.java)
/**
* Extension for [AsyncCassandraOperations.selectOneById] leveraging reified type parameters.
*/
inline fun AsyncCassandraOperations.selectOneById(id: Any): CompletableFuture =
selectOneById(id, T::class.java)
/**
* Extension for [AsyncCassandraOperations.deleteById] providing a [KClass] based variant.
*/
@Deprecated(
"Since 2.2, use the reified variant",
replaceWith = ReplaceWith("deleteById(id)")
)
fun AsyncCassandraOperations.deleteById(
id: Any,
entityClass: KClass
): CompletableFuture =
deleteById(id, entityClass.java)
/**
* Extension for [AsyncCassandraOperations.deleteById] leveraging reified type parameters.
*/
inline fun AsyncCassandraOperations.deleteById(id: Any): CompletableFuture =
deleteById(id, T::class.java)
/**
* Extension for [AsyncCassandraOperations.truncate] providing a [KClass] based variant.
*/
@Deprecated(
"Since 2.2, use the reified variant",
replaceWith = ReplaceWith("truncate()")
)
fun AsyncCassandraOperations.truncate(entityClass: KClass): CompletableFuture =
truncate(entityClass.java)
/**
* Extension for [AsyncCassandraOperations.truncate] leveraging reified type parameters.
*/
inline fun AsyncCassandraOperations.truncate(): CompletableFuture =
truncate(T::class.java)