Skip to content

Commit

Permalink
Add documentation for generated entity extension functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Thijsiez committed Dec 10, 2024
1 parent 457edd1 commit 33620fa
Show file tree
Hide file tree
Showing 6 changed files with 295 additions and 103 deletions.
283 changes: 261 additions & 22 deletions src/main/kotlin/ch/icken/processor/PanacheCompanionBaseProcessor.kt

Large diffs are not rendered by default.

22 changes: 22 additions & 0 deletions src/main/kotlin/ch/icken/processor/PanacheEntityBaseProcessor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package ch.icken.processor

import ch.icken.query.Column
import com.google.devtools.ksp.processing.*
import com.google.devtools.ksp.symbol.KSAnnotated
import com.google.devtools.ksp.symbol.KSClassDeclaration
Expand All @@ -25,6 +26,7 @@ import com.squareup.kotlinpoet.*
import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.plusParameter
import com.squareup.kotlinpoet.ksp.toClassName
import com.squareup.kotlinpoet.ksp.writeTo
import jakarta.persistence.*

class PanacheEntityBaseProcessor(
options: Map<String, String>,
Expand Down Expand Up @@ -114,6 +116,26 @@ class PanacheEntityBaseProcessor(
.build()
.writeTo(codeGenerator, Dependencies(false))
}

companion object {
//region Class Names
internal val ColumnClassName = Column::class.asClassName()
internal val StringClassName = String::class.asClassName()
//endregion
//region Constants
internal const val PARAM_NAME_COLUMNS_BASE_CLASS = "parent"
internal const val PARAM_NAME_MAPPED_BY = "mappedBy"
internal const val SUFFIX_CLASS_COLUMNS_BASE = "Base"
internal const val TYPE_VARIABLE_NAME_COLUMNS = "Columns"
//endregion
//region Names
internal val JakartaPersistenceJoinColumn: String = JoinColumn::class.java.name
internal val JakartaPersistenceManyToMany: String = ManyToMany::class.java.name
internal val JakartaPersistenceOneToMany: String = OneToMany::class.java.name
internal val JakartaPersistenceOneToOne: String = OneToOne::class.java.name
internal val JakartaPersistenceTransient: String = Transient::class.java.name
//endregion
}
}

class PanacheEntityBaseProcessorProvider : SymbolProcessorProvider {
Expand Down
71 changes: 1 addition & 70 deletions src/main/kotlin/ch/icken/processor/ProcessorCommon.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,11 @@

package ch.icken.processor

import ch.icken.query.Column
import ch.icken.query.Component.QueryComponent
import ch.icken.query.Component.UpdateComponent.InitialUpdateComponent
import ch.icken.query.Component.UpdateComponent.InitialUpdateComponent.SetterExpression
import ch.icken.query.Component.UpdateComponent.LogicalUpdateComponent
import ch.icken.query.Expression
import ch.icken.query.PanacheSingleResult
import com.squareup.kotlinpoet.AnnotationSpec
import com.squareup.kotlinpoet.asClassName
import io.quarkus.hibernate.orm.panache.kotlin.PanacheCompanionBase
import io.quarkus.hibernate.orm.panache.kotlin.PanacheEntityBase
import io.quarkus.hibernate.orm.panache.kotlin.PanacheQuery
import io.quarkus.panache.common.Sort
import jakarta.persistence.*
import jakarta.persistence.Entity
import java.time.LocalDateTime
import java.util.stream.Stream

abstract class ProcessorCommon(options: Map<String, String>) {

Expand All @@ -50,79 +39,21 @@ abstract class ProcessorCommon(options: Map<String, String>) {
.addMember("%S", LocalDateTime.now().toString())
.addMember("%S", "Generated using panache-kotlin-dsl")
.build()

protected fun jvmNameAnnotation(name: String) = AnnotationSpec.builder(JvmNameClassName)
.addMember("%S", name)
.build()
//endregion

companion object {
//region Class Names
internal val ColumnClassName = Column::class.asClassName()
internal val ExpressionClassName = Expression::class.asClassName()
internal val GeneratedClassName = Generated::class.asClassName()
internal val InitialUpdateComponentClassName = InitialUpdateComponent::class.asClassName()
internal val IntClassName = Int::class.asClassName()
internal val JvmNameClassName = JvmName::class.asClassName()
internal val ListClassName = List::class.asClassName()
internal val LogicalUpdateComponentClassName = LogicalUpdateComponent::class.asClassName()
internal val LongClassName = Long::class.asClassName()
internal val PanacheQueryClassName = PanacheQuery::class.asClassName()
internal val PanacheSingleResultClassName = PanacheSingleResult::class.asClassName()
internal val QueryComponentClassName = QueryComponent::class.asClassName()
internal val SetterExpressionClassName = SetterExpression::class.asClassName()
internal val SortClassName = Sort::class.asClassName()
internal val StreamClassName = Stream::class.asClassName()
internal val StringClassName = String::class.asClassName()
internal val SuppressClassName = Suppress::class.asClassName()
//endregion
//region Constants
internal const val CLASS_NAME_COMPANION = "Companion"
internal const val FUNCTION_NAME_AND = "and"
internal const val FUNCTION_NAME_AND_EXPRESSION = "andExpression"
internal const val FUNCTION_NAME_AND_UPDATE = "andUpdate"
internal const val FUNCTION_NAME_COUNT = "count"
internal const val FUNCTION_NAME_DELETE = "delete"
internal const val FUNCTION_NAME_FIND = "find"
internal const val FUNCTION_NAME_FIND_SORTED = "findSorted"
internal const val FUNCTION_NAME_MULTIPLE = "multiple"
internal const val FUNCTION_NAME_MULTIPLE_SORTED = "multipleSorted"
internal const val FUNCTION_NAME_OR = "or"
internal const val FUNCTION_NAME_OR_EXPRESSION = "orExpression"
internal const val FUNCTION_NAME_OR_UPDATE = "orUpdate"
internal const val FUNCTION_NAME_SINGLE = "single"
internal const val FUNCTION_NAME_SINGLE_SAFE = "singleSafe"
internal const val FUNCTION_NAME_STREAM = "stream"
internal const val FUNCTION_NAME_STREAM_SORTED = "streamSorted"
internal const val FUNCTION_NAME_UPDATE = "update"
internal const val FUNCTION_NAME_UPDATE_ALL = "updateAll"
internal const val FUNCTION_NAME_UPDATE_ALL_MULTIPLE = "updateAllMultiple"
internal const val FUNCTION_NAME_UPDATE_MULTIPLE = "updateMultiple"
internal const val FUNCTION_NAME_WHERE = "where"
internal const val FUNCTION_NAME_WHERE_UPDATE = "whereUpdate"
internal const val PARAM_NAME_COLUMNS_BASE_CLASS = "parent"
internal const val PARAM_NAME_EXPRESSION = "expression"
internal const val PARAM_NAME_MAPPED_BY = "mappedBy"
internal const val PARAM_NAME_SETTER = "setter"
internal const val PARAM_NAME_SETTERS = "setters"
internal const val PARAM_NAME_SORT = "sort"
internal const val PARAM_NAME_TYPE = "type"
internal const val SUFFIX_CLASS_COLUMNS_BASE = "Base"
internal const val SUFFIX_FILE_EXTENSIONS = "Extensions"
internal const val SUFFIX_OBJECT_COLUMNS = "Columns"
internal const val SUFFIX_PACKAGE_GENERATED = ".generated"
internal const val TYPE_VARIABLE_NAME_COLUMNS = "Columns"
//endregion
//region Names
internal val HibernatePanacheCompanionBase: String = PanacheCompanionBase::class.java.name
internal val HibernatePanacheEntityBase: String = PanacheEntityBase::class.java.name
internal val JakartaPersistenceEntity: String = Entity::class.java.name
internal val JakartaPersistenceId: String = Id::class.java.name
internal val JakartaPersistenceJoinColumn: String = JoinColumn::class.java.name
internal val JakartaPersistenceManyToMany: String = ManyToMany::class.java.name
internal val JakartaPersistenceOneToMany: String = OneToMany::class.java.name
internal val JakartaPersistenceOneToOne: String = OneToOne::class.java.name
internal val JakartaPersistenceTransient: String = Transient::class.java.name
internal val ProcessorColumnType: String = ColumnType::class.java.name
//endregion
//region Options
Expand Down
6 changes: 3 additions & 3 deletions src/main/kotlin/ch/icken/query/Component.kt
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ sealed class Component<Entity : PanacheEntityBase, Id : Any, Columns> private co
/**
* Updates all entities of this type.
*
* WARNING: this function updates ALL entities without a WHERE clause
* WARNING: this function updates ALL entities without a WHERE clause.
*
* WARNING: this function requires a transaction to be active.
*
Expand Down Expand Up @@ -269,9 +269,9 @@ sealed class Component<Entity : PanacheEntityBase, Id : Any, Columns> private co

//region Terminal operations
/**
* Updates all entities matching the preceding query
* Updates all entities matching the preceding query.
*
* WARNING: this function requires a transaction to be active
* WARNING: this function requires a transaction to be active.
*
* @return the number of entities updated
* @see io.quarkus.hibernate.orm.panache.kotlin.PanacheCompanionBase.update
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@

package ch.icken.processor

import ch.icken.processor.ProcessorCommon.Companion.HibernatePanacheCompanionBase
import ch.icken.processor.PanacheCompanionBaseProcessor.Companion.HibernatePanacheCompanionBase
import ch.icken.processor.PanacheCompanionBaseProcessor.Companion.JakartaPersistenceId
import ch.icken.processor.PanacheCompanionBaseProcessor.Companion.LongClassName
import ch.icken.processor.ProcessorCommon.Companion.HibernatePanacheEntityBase
import ch.icken.processor.ProcessorCommon.Companion.JakartaPersistenceEntity
import ch.icken.processor.ProcessorCommon.Companion.JakartaPersistenceId
import ch.icken.processor.ProcessorCommon.Companion.LongClassName
import ch.icken.processor.ProcessorCommon.Companion.OPTION_ADD_GENERATED_ANNOTATION
import com.google.devtools.ksp.processing.CodeGenerator
import com.google.devtools.ksp.processing.KSPLogger
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@

package ch.icken.processor

import ch.icken.processor.PanacheCompanionBaseProcessor.Companion.ListClassName
import ch.icken.processor.PanacheEntityBaseProcessor.Companion.JakartaPersistenceJoinColumn
import ch.icken.processor.PanacheEntityBaseProcessor.Companion.JakartaPersistenceTransient
import ch.icken.processor.PanacheEntityBaseProcessor.Companion.PARAM_NAME_MAPPED_BY
import ch.icken.processor.PanacheEntityBaseProcessor.Companion.StringClassName
import ch.icken.processor.ProcessorCommon.Companion.HibernatePanacheEntityBase
import ch.icken.processor.ProcessorCommon.Companion.JakartaPersistenceEntity
import ch.icken.processor.ProcessorCommon.Companion.JakartaPersistenceJoinColumn
import ch.icken.processor.ProcessorCommon.Companion.JakartaPersistenceTransient
import ch.icken.processor.ProcessorCommon.Companion.ListClassName
import ch.icken.processor.ProcessorCommon.Companion.OPTION_ADD_GENERATED_ANNOTATION
import ch.icken.processor.ProcessorCommon.Companion.PARAM_NAME_MAPPED_BY
import ch.icken.processor.ProcessorCommon.Companion.PARAM_NAME_TYPE
import ch.icken.processor.ProcessorCommon.Companion.ProcessorColumnType
import ch.icken.processor.ProcessorCommon.Companion.StringClassName
import com.google.devtools.ksp.processing.CodeGenerator
import com.google.devtools.ksp.processing.KSPLogger
import com.google.devtools.ksp.processing.Resolver
Expand Down

0 comments on commit 33620fa

Please sign in to comment.