Skip to content

Commit

Permalink
Merge pull request #32100 from geoand/kotlin
Browse files Browse the repository at this point in the history
Fix Kotlin formatting
  • Loading branch information
gsmet authored Mar 24, 2023
2 parents b4a92c8 + e6baa3c commit 125f884
Show file tree
Hide file tree
Showing 33 changed files with 1,033 additions and 896 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import io.quarkus.panache.common.impl.GenerateBridge
import io.smallrye.common.annotation.CheckReturnValue
import io.smallrye.mutiny.Uni
import jakarta.persistence.LockModeType
import org.hibernate.reactive.mutiny.Mutiny
import java.util.stream.Stream
import org.hibernate.reactive.mutiny.Mutiny

/**
* Defines methods to be used via the companion objects of entities.
Expand All @@ -32,8 +32,7 @@ interface PanacheCompanionBase<Entity : PanacheEntityBase, Id : Any> {
* @param id the ID of the entity to find.
* @return the entity found, or `null` if not found.
*/
@GenerateBridge
fun findById(id: Id): Uni<Entity?> = injectionMissing()
@GenerateBridge fun findById(id: Id): Uni<Entity?> = injectionMissing()

/**
* Find an entity of this type by ID and lock it.
Expand Down Expand Up @@ -67,7 +66,8 @@ interface PanacheCompanionBase<Entity : PanacheEntityBase, Id : Any> {
* @see [list] list
*/
@GenerateBridge
fun find(query: String, sort: Sort, vararg params: Any): PanacheQuery<Entity> = injectionMissing()
fun find(query: String, sort: Sort, vararg params: Any): PanacheQuery<Entity> =
injectionMissing()

/**
* Find entities using a query, with named parameters.
Expand All @@ -90,7 +90,8 @@ interface PanacheCompanionBase<Entity : PanacheEntityBase, Id : Any> {
* @see [list] list
*/
@GenerateBridge
fun find(query: String, sort: Sort, params: Map<String, Any>): PanacheQuery<Entity> = injectionMissing()
fun find(query: String, sort: Sort, params: Map<String, Any>): PanacheQuery<Entity> =
injectionMissing()

/**
* Find entities using a query, with named parameters.
Expand All @@ -113,16 +114,16 @@ interface PanacheCompanionBase<Entity : PanacheEntityBase, Id : Any> {
* @see [list] list
*/
@GenerateBridge
fun find(query: String, sort: Sort, params: Parameters): PanacheQuery<Entity> = injectionMissing()
fun find(query: String, sort: Sort, params: Parameters): PanacheQuery<Entity> =
injectionMissing()

/**
* Find all entities of this type.
*
* @return a new [PanacheQuery] instance to find all entities of this type.
* @see [listAll] listAll
*/
@GenerateBridge
fun findAll(): PanacheQuery<Entity> = injectionMissing()
@GenerateBridge fun findAll(): PanacheQuery<Entity> = injectionMissing()

/**
* Find all entities of this type, in the given order.
Expand All @@ -131,12 +132,11 @@ interface PanacheCompanionBase<Entity : PanacheEntityBase, Id : Any> {
* @return a new [PanacheQuery] instance to find all entities of this type.
* @see [listAll] listAll
*/
@GenerateBridge
fun findAll(sort: Sort): PanacheQuery<Entity> = injectionMissing()
@GenerateBridge fun findAll(sort: Sort): PanacheQuery<Entity> = injectionMissing()

/**
* Find entities matching a query, with optional indexed parameters.
* This method is a shortcut for `find(query, params).list()`.
* Find entities matching a query, with optional indexed parameters. This method is a shortcut
* for `find(query, params).list()`.
*
* @param query a query string
* @param params optional sequence of indexed parameters
Expand All @@ -162,8 +162,8 @@ interface PanacheCompanionBase<Entity : PanacheEntityBase, Id : Any> {
fun list(query: String, sort: Sort, vararg params: Any): Uni<List<Entity>> = injectionMissing()

/**
* Find entities matching a query, with named parameters.
* This method is a shortcut for `find(query, params).list()`.
* Find entities matching a query, with named parameters. This method is a shortcut for
* `find(query, params).list()`.
*
* @param query a query string
* @param params [Map] of named parameters
Expand All @@ -175,8 +175,8 @@ interface PanacheCompanionBase<Entity : PanacheEntityBase, Id : Any> {
fun list(query: String, params: Map<String, Any>): Uni<List<Entity>> = injectionMissing()

/**
* Find entities matching a query and the given sort options, with named parameters.
* This method is a shortcut for `find(query, sort, params).list()`.
* Find entities matching a query and the given sort options, with named parameters. This method
* is a shortcut for `find(query, sort, params).list()`.
*
* @param query a query string
* @param sort the sort strategy to use
Expand All @@ -186,11 +186,12 @@ interface PanacheCompanionBase<Entity : PanacheEntityBase, Id : Any> {
*/
@CheckReturnValue
@GenerateBridge
fun list(query: String, sort: Sort, params: Map<String, Any>): Uni<List<Entity>> = injectionMissing()
fun list(query: String, sort: Sort, params: Map<String, Any>): Uni<List<Entity>> =
injectionMissing()

/**
* Find entities matching a query, with named parameters.
* This method is a shortcut for `find(query, params).list()`.
* Find entities matching a query, with named parameters. This method is a shortcut for
* `find(query, params).list()`.
*
* @param query a query string
* @param params [Parameters] of named parameters
Expand All @@ -202,8 +203,8 @@ interface PanacheCompanionBase<Entity : PanacheEntityBase, Id : Any> {
fun list(query: String, params: Parameters): Uni<List<Entity>> = injectionMissing()

/**
* Find entities matching a query and the given sort options, with named parameters.
* This method is a shortcut for `find(query, sort, params).list()`.
* Find entities matching a query and the given sort options, with named parameters. This method
* is a shortcut for `find(query, sort, params).list()`.
*
* @param query a query string
* @param sort the sort strategy to use
Expand All @@ -216,19 +217,16 @@ interface PanacheCompanionBase<Entity : PanacheEntityBase, Id : Any> {
fun list(query: String, sort: Sort, params: Parameters): Uni<List<Entity>> = injectionMissing()

/**
* Find all entities of this type.
* This method is a shortcut for `findAll().list()`.
* Find all entities of this type. This method is a shortcut for `findAll().list()`.
*
* @return a [List] containing all results, without paging
* @see [findAll] findAll
*/
@CheckReturnValue
@GenerateBridge
fun listAll(): Uni<List<Entity>> = injectionMissing()
@CheckReturnValue @GenerateBridge fun listAll(): Uni<List<Entity>> = injectionMissing()

/**
* Find all entities of this type, in the given order.
* This method is a shortcut for `findAll(sort).list()`.
* Find all entities of this type, in the given order. This method is a shortcut for
* `findAll(sort).list()`.
*
* @param sort the sort order to use
* @return a [List] containing all results, without paging
Expand All @@ -243,12 +241,11 @@ interface PanacheCompanionBase<Entity : PanacheEntityBase, Id : Any> {
*
* @return the number of this type of entity in the database.
*/
@CheckReturnValue
@GenerateBridge
fun count(): Uni<Long> = injectionMissing()
@CheckReturnValue @GenerateBridge fun count(): Uni<Long> = injectionMissing()

/**
* Counts the number of this type of entity matching the given query, with optional indexed parameters.
* Counts the number of this type of entity matching the given query, with optional indexed
* parameters.
*
* @param query a query string
* @param params optional sequence of indexed parameters
Expand Down Expand Up @@ -289,19 +286,15 @@ interface PanacheCompanionBase<Entity : PanacheEntityBase, Id : Any> {
* @return the number of entities deleted.
* @see [delete] delete
*/
@CheckReturnValue
@GenerateBridge
fun deleteAll(): Uni<Long> = injectionMissing()
@CheckReturnValue @GenerateBridge fun deleteAll(): Uni<Long> = injectionMissing()

/**
* Delete an entity of this type by ID.
*
* @param id the ID of the entity to delete.
* @return false if the entity was not deleted (not found).
*/
@CheckReturnValue
@GenerateBridge
fun deleteById(id: Any): Uni<Boolean> = injectionMissing()
@CheckReturnValue @GenerateBridge fun deleteById(id: Any): Uni<Boolean> = injectionMissing()

/**
* Delete all entities of this type matching the given query, with optional indexed parameters.
Expand Down Expand Up @@ -354,17 +347,15 @@ interface PanacheCompanionBase<Entity : PanacheEntityBase, Id : Any> {
* @param entities the entities to persist
* @return
*/
@CheckReturnValue
fun persist(entities: Iterable<Entity>) = INSTANCE.persist(entities)
@CheckReturnValue fun persist(entities: Iterable<Entity>) = INSTANCE.persist(entities)

/**
* Persist all given entities.
*
* @param entities the entities to persist
* @return
*/
@CheckReturnValue
fun persist(entities: Stream<Entity>) = INSTANCE.persist(entities)
@CheckReturnValue fun persist(entities: Stream<Entity>) = INSTANCE.persist(entities)

/**
* Persist all given entities.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,12 @@ import jakarta.persistence.MappedSuperclass
@MappedSuperclass
open class PanacheEntity : PanacheEntityBase {
/**
* The auto-generated ID field. This field is set by Hibernate ORM when this entity
* is persisted.
* The auto-generated ID field. This field is set by Hibernate ORM when this entity is
* persisted.
*
* @see [PanacheEntity.persist]
*/
@Id
@GeneratedValue
open var id: Long? = null
@Id @GeneratedValue open var id: Long? = null

/**
* Default toString() implementation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,14 @@ import jakarta.json.bind.annotation.JsonbTransient

interface PanacheEntityBase {
/**
* Returns true if this entity is persistent in the database. If yes, all modifications to
* its persistent fields will be automatically committed to the database at transaction
* commit time.
* Returns true if this entity is persistent in the database. If yes, all modifications to its
* persistent fields will be automatically committed to the database at transaction commit time.
*
* @return true if this entity is persistent in the database.
*/
@JsonbTransient
@JsonIgnore
fun isPersistent(): Boolean = INSTANCE.isPersistent(this)
@JsonbTransient @JsonIgnore fun isPersistent(): Boolean = INSTANCE.isPersistent(this)

/**
* Persist this entity in the database.
* This will set its ID field if not already set.
*/
/** Persist this entity in the database. This will set its ID field if not already set. */
@CheckReturnValue
fun <T : PanacheEntityBase> persist(): Uni<T> {
return INSTANCE.persist(this).map { this as T }
Expand All @@ -38,8 +32,8 @@ interface PanacheEntityBase {
}

/**
* Persist this entity in the database, if not already persisted. This will set your ID field if it is not already set.
* Then flushes all pending changes to the database.
* Persist this entity in the database, if not already persisted. This will set your ID field if
* it is not already set. Then flushes all pending changes to the database.
*
* @see [isPersistent] isPersistent
* @see [flush] flush
Expand All @@ -48,10 +42,7 @@ interface PanacheEntityBase {
@Suppress("UNCHECKED_CAST")
@CheckReturnValue
fun <T : PanacheEntityBase> persistAndFlush(): Uni<T> {
return INSTANCE
.persist(this)
.flatMap { INSTANCE.flush() }
.map { this as T }
return INSTANCE.persist(this).flatMap { INSTANCE.flush() }.map { this as T }
}

/**
Expand Down
Loading

0 comments on commit 125f884

Please sign in to comment.