Skip to content

Commit b67e701

Browse files
committed
Implemented embedded columns for where DSL
1 parent 0a40808 commit b67e701

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

bee.persistent.test/src/test/kotlin/com/beeproduced/bee/persistent/test/BeePersistentTestA.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import com.beeproduced.bee.persistent.blaze.meta.dsl.InlineValueUnwrappers
1111
import com.beeproduced.bee.persistent.blaze.selection.BeeSelection
1212
import com.beeproduced.datasource.a.*
1313
import com.beeproduced.datasource.a.dsl.WeirdClassDSL
14+
import com.beeproduced.datasource.b.dsl.ComposerDSL
1415
import jakarta.persistence.EntityManager
1516
import org.junit.jupiter.api.AfterEach
1617
import org.junit.jupiter.api.BeforeAll
@@ -538,7 +539,6 @@ class BeePersistentTestA(
538539
)
539540
}
540541

541-
542542
val w4 = weirdRepository.select {
543543
orderBy(
544544
ValuePath<Foxtrot, String>("foxtrot", Foxtrot::class).asc(),

bee.persistent/src/blaze-processor/kotlin/com/beeproduced/bee/persistent/blaze/processor/codegen/BeePersistentDSLCodegen.kt

+20-8
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import com.beeproduced.bee.persistent.blaze.processor.codegen.BeePersistentDSLCo
1515
import com.beeproduced.bee.persistent.blaze.processor.codegen.BeePersistentDSLCodegen.PoetConstants.VALUE_PATH
1616
import com.beeproduced.bee.persistent.blaze.processor.info.ColumnProperty
1717
import com.beeproduced.bee.persistent.blaze.processor.info.EntityInfo
18-
import com.beeproduced.bee.persistent.blaze.processor.info.Property
1918
import com.beeproduced.bee.persistent.blaze.processor.info.RepoInfo
2019
import com.beeproduced.bee.persistent.blaze.processor.utils.SubProperty
2120
import com.beeproduced.bee.persistent.blaze.processor.utils.viewColumnsWithSubclasses
@@ -26,6 +25,7 @@ import com.squareup.kotlinpoet.*
2625
import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy
2726
import com.squareup.kotlinpoet.ksp.toTypeName
2827
import com.squareup.kotlinpoet.ksp.writeTo
28+
import org.gradle.configurationcache.extensions.capitalized
2929

3030
/**
3131
*
@@ -278,7 +278,7 @@ class BeePersistentDSLCodegen(
278278
path: String = "",
279279
visitedEmbeddedViews: MutableMap<String, String?> = mutableMapOf(),
280280
sort: Boolean = false,
281-
): String = run {
281+
): TypeSpec.Builder {
282282

283283
val (allRelations, allColumns)
284284
= viewColumnsWithSubclasses(entityView, views)
@@ -288,6 +288,10 @@ class BeePersistentDSLCodegen(
288288
viewDSL.addPath(column, path, sort)
289289
}
290290

291+
for (column in embedded) {
292+
viewDSL.addPath(column, path, sort)
293+
}
294+
291295
for ((simpleName, subRelation) in allRelations) {
292296
val innerView = views.entityViews.getValue(subRelation.relationView)
293297
if (innerView.isExtended) continue
@@ -305,17 +309,17 @@ class BeePersistentDSLCodegen(
305309
addType(innerDSL.build())
306310
}
307311

308-
309-
""
312+
return this
310313
}
311314

312315
private fun TypeSpec.Builder.addPath(
313316
subProperty: SubProperty, path: String,
314-
sort: Boolean
317+
sort: Boolean, embeddedPropertyName: String? = null
315318
) {
316319
val column = subProperty.property
317-
val inner = column.innerValue
320+
val propertyName = embeddedPropertyName ?: column.simpleName
318321
val newPath = buildPath(path, column.simpleName, subProperty.subView)
322+
val inner = column.innerValue
319323
if (inner != null) {
320324
val innerType = inner.type.toTypeName().copy(nullable = false)
321325
val columnType = column.type.toTypeName().copy(nullable = false)
@@ -324,7 +328,7 @@ class BeePersistentDSLCodegen(
324328
else poetMap.classMapping(VALUE_EXP).parameterizedBy(columnType, innerType)
325329
val pathType = poetMap.classMapping(VALUE_PATH)
326330

327-
val pathProperty = PropertySpec.builder(column.simpleName, interfaceType)
331+
val pathProperty = PropertySpec.builder(propertyName, interfaceType)
328332
.initializer(CodeBlock.Builder()
329333
.addStatement("%T(%S, %T::class)", pathType, newPath, columnType)
330334
.build()
@@ -337,12 +341,20 @@ class BeePersistentDSLCodegen(
337341
poetMap.classMapping(SORTABLE_EXP).parameterizedBy(columnType)
338342
else poetMap.classMapping(EXP).parameterizedBy(columnType)
339343
val pathType = poetMap.classMapping(PATH)
340-
val pathProperty = PropertySpec.builder(column.simpleName, interfaceType)
344+
val pathProperty = PropertySpec.builder(propertyName, interfaceType)
341345
.initializer(CodeBlock.Builder()
342346
.addStatement("%T(%S)", pathType, newPath)
343347
.build()
344348
)
345349
addProperty(pathProperty.build())
350+
351+
val embedded = column.embedded ?: return
352+
for (embeddedColumn in embedded.jpaProperties) {
353+
val columnProp = ColumnProperty(embeddedColumn.declaration, embeddedColumn.type, embeddedColumn.annotations, null, null)
354+
val embeddedSubProperty = SubProperty(columnProp)
355+
val overrideName = "$propertyName${embeddedColumn.simpleName.capitalized()}"
356+
addPath(embeddedSubProperty, newPath, sort, overrideName)
357+
}
346358
}
347359

348360
private fun buildPath(path: String, simpleName: String, subView: String?): String {

0 commit comments

Comments
 (0)