Skip to content

Commit

Permalink
Fix issue with Dependencies order which could cause crashes on migrat…
Browse files Browse the repository at this point in the history
…ion check.
  • Loading branch information
jurmous committed Oct 25, 2024
1 parent 5deaf02 commit 3d27c5e
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,7 @@ class EmbeddedObjectDefinition<DO : Any, DM : IsTypedObjectDataModel<DO, *, CXI,
}

override fun getAllDependencies(dependencySet: MutableList<MarykPrimitive>) {
if (!dependencySet.contains(dataModel as MarykPrimitive)) {
dependencySet.add(dataModel as MarykPrimitive)
dataModel.getAllDependencies(dependencySet)
}
this.addDataModelToDependencySet(dependencySet)
}

object Model : ContextualDataModel<EmbeddedObjectDefinition<*, *, *, *>, Model, ContainsDefinitionsContext, ModelContext>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,7 @@ class EmbeddedValuesDefinition<DM : IsValuesDataModel>(
}

override fun getAllDependencies(dependencySet: MutableList<MarykPrimitive>) {
if (!dependencySet.contains(dataModel as MarykPrimitive)) {
dependencySet.add(dataModel as MarykPrimitive)
dataModel.getAllDependencies(dependencySet)
}
addDataModelToDependencySet(dependencySet)
}

object Model : ContextualDataModel<EmbeddedValuesDefinition<*>, Model, ContainsDefinitionsContext, ModelContext>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ data class MultiTypeDefinition<E : MultiTypeEnum<out T>, T: Any>(
override fun getAllDependencies(dependencySet: MutableList<MarykPrimitive>) {
if (!dependencySet.contains(typeEnum)) {
dependencySet.add(typeEnum)
typeEnum.getAllDependencies(dependencySet)
}
typeEnum.getAllDependencies(dependencySet)
}

object Model : ContextualDataModel<MultiTypeDefinition<*, *>, Model, ContainsDefinitionsContext, MultiTypeDefinitionContext>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,7 @@ data class ValueObjectDefinition<DO : ValueDataObject, DM : IsValueDataModel<DO,
}

override fun getAllDependencies(dependencySet: MutableList<MarykPrimitive>) {
if (!dependencySet.contains(dataModel as MarykPrimitive)) {
dataModel.getAllDependencies(dependencySet)
dependencySet.add(dataModel as MarykPrimitive)
}
this.addDataModelToDependencySet(dependencySet)
}

object Model : ContextualDataModel<ValueObjectDefinition<*, *>, Model, ContainsDefinitionsContext, ModelContext>(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package maryk.core.properties.definitions

import maryk.core.definitions.MarykPrimitive

internal fun IsDefinitionWithDataModel<*>.addDataModelToDependencySet(
dependencySet: MutableList<MarykPrimitive>
) {
if (!dependencySet.contains(dataModel as MarykPrimitive)) {
// First add it so cyclical deps are not looping
dependencySet.add(dataModel as MarykPrimitive)
dataModel.getAllDependencies(dependencySet)
// Then remove and add it again to have dependencies in right order. This makes sure the dependents are in front
dependencySet.remove(dataModel as MarykPrimitive)
dependencySet.add(dataModel as MarykPrimitive)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,6 @@ internal class RootDataModelTest {
TestMarykModel.getAllDependencies(list)

assertEquals(5, list.size)
assertEquals(mutableListOf(Option, TestValueObject, EmbeddedMarykModel, TestMarykModel, SimpleMarykTypeEnum), list)
assertEquals(mutableListOf(Option, TestValueObject, SimpleMarykTypeEnum, TestMarykModel, EmbeddedMarykModel), list)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ suspend fun HbaseDataStore.storeModelDefinition(

val dependencies = mutableListOf<MarykPrimitive>()
dataModel.getAllDependencies(dependencies)
// Needs to be in reverse order to do sub dependencies first and then the higher up dependencies
dependencies.reverse()

if (dependencies.isNotEmpty()) {
val dependentCache = WriteCache()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ fun storeModelDefinition(

val dependencies = mutableListOf<MarykPrimitive>()
dataModel.getAllDependencies(dependencies)
// Needs to be in reverse order to do sub dependencies first and then the higher up dependencies
dependencies.reverse()

if (dependencies.isNotEmpty()) {
val dependentCache = WriteCache()
Expand Down

0 comments on commit 3d27c5e

Please sign in to comment.