KandraRepository

class KandraRepository<T : Any>(session: CqlSession, schema: TableSchema, entityClass: KClass<T>, batchEngine: BatchEngine)

Blocking repository for performing CRUD operations on a ScyllaDB table.

Parameters

T

the entity type annotated with @ScyllaTable

Constructors

Link copied to clipboard
constructor(session: CqlSession, schema: TableSchema, entityClass: KClass<T>, batchEngine: BatchEngine)

Functions

Link copied to clipboard
fun <V> append(entity: T, field: KProperty1<T, Collection<V>?>, values: Collection<V>, consistency: KandraConsistency? = null)
Link copied to clipboard
fun decrement(field: KProperty1<T, Long?>, partitionKeys: Map<String, Any>, by: Long = 1, consistency: KandraConsistency? = null)
Link copied to clipboard
fun delete(entity: T)
Link copied to clipboard
fun deleteAll(entities: List<T>)
Link copied to clipboard
fun deleteBy(block: QueryContext.() -> Unit)
Link copied to clipboard
fun deleteById(vararg keyValues: Any)
Link copied to clipboard
fun exists(consistency: KandraConsistency? = null, block: QueryContext.() -> Unit): Boolean
Link copied to clipboard
fun find(consistency: KandraConsistency? = null, block: QueryContext.() -> Unit): T?
Link copied to clipboard
fun findActive(allowFullScan: Boolean = false): List<T>

Returns all rows not yet soft-deleted. Requires @SoftDelete(markerProperty = "...") on T — throws KandraSchemaException otherwise.

Link copied to clipboard
fun findAll(limit: Int? = null, consistency: KandraConsistency? = null, block: QueryContext.() -> Unit): List<T>
Link copied to clipboard
fun findById(vararg idValues: Any, consistency: KandraConsistency? = null): T?
Link copied to clipboard
fun findPage(pageSize: Int, pageToken: String? = null, consistency: KandraConsistency? = null, block: QueryContext.() -> Unit = {}): KandraPage<T>
Link copied to clipboard
fun increment(field: KProperty1<T, Long?>, partitionKeys: Map<String, Any>, by: Long = 1, consistency: KandraConsistency? = null)
Link copied to clipboard
fun <K, V> put(entity: T, field: KProperty1<T, Map<K, V>?>, entries: Map<K, V>, consistency: KandraConsistency? = null)
Link copied to clipboard
fun raw(cql: String, vararg params: Any?): List<Row>
Link copied to clipboard
fun rawQuery(query: KandraRawQuery): List<Row>
Link copied to clipboard
fun <V> remove(entity: T, field: KProperty1<T, Collection<V>?>, values: Collection<V>, consistency: KandraConsistency? = null)
Link copied to clipboard
fun save(entity: T, ttlSeconds: Int? = null, timestampMicros: Long? = null, consistency: KandraConsistency? = null)
Link copied to clipboard
fun saveAll(entities: List<T>, useBatch: Boolean = true, consistency: KandraConsistency? = null)
Link copied to clipboard
fun saveAndGet(entity: T, ttlSeconds: Int? = null, timestampMicros: Long? = null, consistency: KandraConsistency? = null): T

Same write as save, but returns the entity actually persisted — including any @GeneratedUuid/@CreatedAt/@UpdatedAt/@Version values generated for the write, which save computes internally and then discards. Use this whenever the caller needs those generated values (e.g. to build an HTTP response) instead of the placeholder ones on the object it constructed — see GH #132 / ISS-096.

Link copied to clipboard
fun saveIfNotExists(entity: T, serialConsistency: KandraConsistency = KandraConsistency.LOCAL_SERIAL): Boolean
Link copied to clipboard
fun saveIfNotExistsAndGet(entity: T, serialConsistency: KandraConsistency = KandraConsistency.LOCAL_SERIAL): T?

Same LWT write as saveIfNotExists, but returns the entity actually persisted — including any @GeneratedUuid/@CreatedAt/@UpdatedAt values generated for the write, which saveIfNotExists computes internally and then discards behind a bare Boolean. Returns null when the row already existed (the same case saveIfNotExists reports as false) — use this whenever the caller needs the real generated values on the success path, e.g. to build an HTTP response, instead of the placeholder ones on the object it constructed. See GH #138 (same root-cause shape as GH #132 / saveAndGet()).

Link copied to clipboard
fun saveWithNulls(entity: T, ttlSeconds: Int? = null, consistency: KandraConsistency? = null)
Link copied to clipboard
fun update(old: T, new: T, consistency: KandraConsistency? = null, ttlSeconds: Int? = null, serialConsistency: KandraConsistency = KandraConsistency.LOCAL_SERIAL)

Optimistic-locked update: UPDATE ... IF <version> = ? when the entity has an @Version column (otherwise a blind full-row overwrite — see the kandra-runtime skill doc).

Link copied to clipboard
fun updateAndGet(old: T, new: T, consistency: KandraConsistency? = null, ttlSeconds: Int? = null, serialConsistency: KandraConsistency = KandraConsistency.LOCAL_SERIAL): T

Same write as update, but returns the entity actually persisted — including the post-update @Version (and @UpdatedAt) values update computes internally and then discards. Use this whenever the caller needs those generated values, e.g. to make a subsequent optimistic-locked update()/updateAndGet() call against the same row without risking a spurious io.kandra.core.exception.KandraOptimisticLockException from reusing the stale pre-update version it already had — see GH #136.

Link copied to clipboard
fun updateForce(entity: T, consistency: KandraConsistency? = null)