Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 7 additions & 12 deletions yawn-api/src/main/kotlin/com/faire/yawn/YawnDef.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package com.faire.yawn

import com.faire.yawn.project.YawnQueryProjection
import com.faire.yawn.project.ProjectionNode
import com.faire.yawn.project.YawnValueProjector
import com.faire.yawn.query.YawnCompilationContext
import org.hibernate.criterion.Projection
import org.hibernate.criterion.Projections

/**
* A Yawn definition that can be queried, i.e. either a [YawnTableDef] or a [com.faire.yawn.project.YawnProjectionDef].
Expand All @@ -17,22 +16,18 @@ abstract class YawnDef<SOURCE : Any, D : Any> {
* Base class for all Yawn Column-like definitions.
* This can be either a column from a table or a projection.
*
* Implements [YawnValueProjector] so that columns can be used directly as projections
* in both the v2 [ProjectionNode] tree and as arguments to [com.faire.yawn.project.YawnProjections] methods.
*
* @param F the type of the column.
*/
abstract inner class YawnColumnDef<F> : YawnQueryProjection<SOURCE, F> {
abstract inner class YawnColumnDef<F> : YawnValueProjector<SOURCE, F> {
abstract fun generatePath(context: YawnCompilationContext): String

open fun adaptValue(value: F): Any? {
return value
}

override fun compile(context: YawnCompilationContext): Projection {
return Projections.property(generatePath(context))
}

override fun project(value: Any?): F {
@Suppress("UNCHECKED_CAST")
return value as F
}
override fun projection(): ProjectionNode.Value<SOURCE, F> = ProjectionNode.property(this)
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package com.faire.yawn.criteria.query

import com.faire.yawn.YawnTableDef
import com.faire.yawn.project.ProjectorResolver
import com.faire.yawn.project.ResolvedProjectionAdapter
import com.faire.yawn.project.YawnProjector
import com.faire.yawn.project.YawnQueryProjection
import com.faire.yawn.query.YawnQuery

Expand Down Expand Up @@ -36,6 +39,10 @@ private constructor(
projection: YawnQueryProjection<SOURCE, PROJECTION>,
): YawnQueryProjection<SOURCE, PROJECTION> {
ensureUniqueProjection()
if (projection is YawnProjector) {
val resolved = ProjectorResolver<SOURCE>().resolve(projection)
return ResolvedProjectionAdapter(resolved)
}
return projection
}

Expand Down

This file was deleted.

Loading
Loading