-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added cascading attribute ( delete missing )
- Loading branch information
1 parent
92787f2
commit a22596d
Showing
10 changed files
with
142 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
src/main/kotlin/org/sirius/dorm/model/AttributeDescriptor.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package org.sirius.dorm.model | ||
/* | ||
* @COPYRIGHT (C) 2023 Andreas Ernst | ||
* | ||
* All rights reserved | ||
*/ | ||
|
||
import org.sirius.common.type.Type | ||
import org.sirius.dorm.`object`.Attribute | ||
import org.sirius.dorm.`object`.DataObject | ||
import org.sirius.dorm.`object`.Property | ||
import org.sirius.dorm.persistence.entity.PropertyEntity | ||
import org.sirius.dorm.transaction.Status | ||
|
||
class AttributeDescriptor<T:Any>(name: String, val type: Type<T>, val isPrimaryKey : Boolean = false) : PropertyDescriptor<T>(name) { | ||
// public | ||
|
||
fun baseType() : Class<*> { | ||
return type.baseType | ||
} | ||
|
||
// override | ||
|
||
override fun createProperty(obj: DataObject, status: Status, entity: PropertyEntity?) : Property { | ||
return Attribute(entity, defaultValue()!!) | ||
} | ||
|
||
override fun asAttribute() : AttributeDescriptor<T> { | ||
return this | ||
} | ||
|
||
override fun defaultValue() : Any? { | ||
return type.defaultValue() | ||
} | ||
|
||
override fun validate(value: Any?) { | ||
type.validate(value!!) | ||
} | ||
|
||
override fun isAttribute() : Boolean { | ||
return true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package org.sirius.dorm.model | ||
/* | ||
* @COPYRIGHT (C) 2023 Andreas Ernst | ||
* | ||
* All rights reserved | ||
*/ | ||
|
||
enum class Cascade { | ||
DELETE | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package org.sirius.dorm.model | ||
/* | ||
* @COPYRIGHT (C) 2023 Andreas Ernst | ||
* | ||
* All rights reserved | ||
*/ | ||
enum class Multiplicity(val optional: Boolean, val mutliValued: Boolean) { | ||
ZERO_OR_ONE(true, false), | ||
ONE(false, false), | ||
MANY(false, true), | ||
ZERO_OR_MANY(true, true) | ||
} |
1 change: 0 additions & 1 deletion
1
src/main/kotlin/org/sirius/dorm/model/ObjectDescriptorStorage.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
package org.sirius.dorm.model | ||
|
||
/* | ||
* @COPYRIGHT (C) 2023 Andreas Ernst | ||
* | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
src/main/kotlin/org/sirius/dorm/model/RelationDescriptor.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package org.sirius.dorm.model | ||
/* | ||
* @COPYRIGHT (C) 2023 Andreas Ernst | ||
* | ||
* All rights reserved | ||
*/ | ||
|
||
import org.sirius.dorm.ObjectManager | ||
import org.sirius.dorm.`object`.DataObject | ||
import org.sirius.dorm.`object`.MultiValuedRelation | ||
import org.sirius.dorm.`object`.Property | ||
import org.sirius.dorm.`object`.SingleValuedRelation | ||
import org.sirius.dorm.persistence.entity.PropertyEntity | ||
import org.sirius.dorm.transaction.Status | ||
|
||
open class RelationDescriptor<T:Any>(name: String, val target: String, val multiplicity: Multiplicity, val cascade: Cascade?, val inverse: String?) : PropertyDescriptor<T>(name) { | ||
// instance data | ||
|
||
var targetDescriptor: ObjectDescriptor? = null | ||
var inverseRelation : RelationDescriptor<*>? = null | ||
|
||
// override | ||
|
||
override fun createProperty(obj: DataObject, status: Status, entity: PropertyEntity?) : Property { | ||
val relation = if ( multiplicity.mutliValued ) MultiValuedRelation( | ||
this, | ||
status, | ||
obj, | ||
entity, | ||
targetDescriptor!! | ||
) | ||
else SingleValuedRelation(this, status, obj, entity, targetDescriptor!!) | ||
|
||
return relation | ||
} | ||
|
||
override fun resolve(objectManager: ObjectManager, descriptor: ObjectDescriptor) { | ||
targetDescriptor = objectManager.getDescriptor(target) | ||
if ( inverse !== null) { | ||
inverseRelation = targetDescriptor!!.property(inverse) as RelationDescriptor<*> | ||
inverseRelation!!.inverseRelation = this // both directions | ||
} | ||
} | ||
|
||
override fun asRelation() : RelationDescriptor<T> { | ||
return this | ||
} | ||
|
||
override fun defaultValue(): Any? { | ||
TODO("Not yet implemented") | ||
} | ||
|
||
override fun validate(value: Any?) { | ||
TODO("Not yet implemented") | ||
} | ||
|
||
fun isOwner() : Boolean { | ||
return inverse !== null | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters