我对斯卡拉很陌生。我试图创建一种动态存储库。如何读取简单案例类的属性?
trait Repository[T <:MetaEntity] {
persist(entity:T) : Boolean {
// TO BE IMPLEMENTED
// Pseudo code:
for (attribute <- getAttributes()) {
// Flatten properies to one string...
// Primitives can be converted with attribute.value.toString ?
// Type: attribute.type ?
// Object references should be coverted to object.id.toString ?
}
}
}
abstarct class MetaEntity {}
case class SimpleEntity(id: Int, name: String, version: Int) extends MetaEntity {
}
case class ComplexEntity(id: Int, name: String, simpleChild: SimpleEntity) extends MetaEntity{}
object ComplexEntityRepository extends Repository[ComplexEntity] {}
object SimpleEntityRepository extends Repository[SimpleEntity] {}