org.springframework.data.cassandra.core.cql.AsyncCqlOperationsExtensions.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-2022 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.cql
import com.datastax.oss.driver.api.core.cql.AsyncResultSet
import com.datastax.oss.driver.api.core.cql.Row
import com.datastax.oss.driver.api.core.cql.Statement
import org.springframework.util.concurrent.ListenableFuture
import kotlin.reflect.KClass
/**
* Extensions for [AsyncCqlOperations].
*
* @author Mark Paluch
* @since 2.1
*/
/**
* Extension for [AsyncCqlOperations.queryForObject] providing a [KClass] based variant.
*/
@Deprecated("Since 2.2, use the reified variant", replaceWith = ReplaceWith("queryForObject(cql)"))
fun AsyncCqlOperations.queryForObject(cql: String, entityClass: KClass): ListenableFuture =
queryForObject(cql, entityClass.java)
/**
* Extension for [AsyncCqlOperations.queryForObject] leveraging reified type parameters.
*/
inline fun AsyncCqlOperations.queryForObject(cql: String): ListenableFuture =
queryForObject(cql, T::class.java)
/**
* Extension for [AsyncCqlOperations.queryForObject] providing a [KClass] based variant.
*/
@Deprecated("Since 2.2, use the reified variant", replaceWith = ReplaceWith("queryForObject(cql, args)"))
fun AsyncCqlOperations.queryForObject(cql: String, entityClass: KClass, vararg args: Any): ListenableFuture =
queryForObject(cql, entityClass.java, args)
/**
* Extension for [AsyncCqlOperations.queryForObject] leveraging reified type parameters.
*/
inline fun AsyncCqlOperations.queryForObject(cql: String, vararg args: Any): ListenableFuture =
queryForObject(cql, T::class.java, args)
/**
* Extension for [AsyncCqlOperations.queryForObject] leveraging reified type parameters.
*/
fun AsyncCqlOperations.queryForObject(cql: String, vararg args: Any, function: (Row, Int) -> T): ListenableFuture =
queryForObject(cql, RowMapper { row, i -> function(row, i) }, *args)
/**
* Extension for [AsyncCqlOperations.queryForObject] providing a [KClass] based variant.
*/
@Deprecated("Since 2.2, use the reified variant", replaceWith = ReplaceWith("queryForObject(statement)"))
fun AsyncCqlOperations.queryForObject(statement: Statement<*>, entityClass: KClass): ListenableFuture =
queryForObject(statement, entityClass.java)
/**
* Extension for [AsyncCqlOperations.queryForObject] leveraging reified type parameters.
*/
inline fun AsyncCqlOperations.queryForObject(statement: Statement<*>): ListenableFuture =
queryForObject(statement, T::class.java)
/**
* Extension for [AsyncCqlOperations.queryForList] leveraging reified type parameters.
*/
@Suppress("EXTENSION_SHADOWED_BY_MEMBER")
inline fun AsyncCqlOperations.queryForList(cql: String): ListenableFuture> =
queryForList(cql, T::class.java)
/**
* Extension for [AsyncCqlOperations.queryForList] leveraging reified type parameters.
*/
@Suppress("EXTENSION_SHADOWED_BY_MEMBER")
inline fun AsyncCqlOperations.queryForList(cql: String, vararg args: Any): ListenableFuture> =
queryForList(cql, T::class.java, args)
/**
* Extension for [AsyncCqlOperations.queryForList] providing a [KClass] based variant.
*/
@Deprecated("Since 2.2, use the reified variant", replaceWith = ReplaceWith("queryForList(statement)"))
fun AsyncCqlOperations.queryForList(statement: Statement<*>, entityClass: KClass): ListenableFuture> =
queryForList(statement, entityClass.java)
/**
* Extension for [AsyncCqlOperations.queryForList] leveraging reified type parameters.
*/
@Suppress("EXTENSION_SHADOWED_BY_MEMBER")
inline fun AsyncCqlOperations.queryForList(statement: Statement<*>): ListenableFuture> =
queryForList(statement, T::class.java)
/**
* Extension for [AsyncCqlOperations.query] providing a ResultSetExtractor-like function
* variant: `query("...", arg1, argN){ rs -> }`.
*/
inline fun AsyncCqlOperations.query(cql: String, vararg args: Any, crossinline function: (AsyncResultSet) -> ListenableFuture): ListenableFuture =
query(cql, AsyncResultSetExtractor { function(it) }, *args)
/**
* Extension for [AsyncCqlOperations.query] providing a RowMapper-like function
* variant: `query("...", arg1, argN){ row, i -> }`.
*/
fun AsyncCqlOperations.query(cql: String, vararg args: Any, function: (Row, Int) -> T): ListenableFuture> =
query(cql, RowMapper { row, i -> function(row, i) }, *args)