私はscalaにかなり慣れていません。一種の動的リポジトリを作成しようとしました。単純なケースクラスの属性を読み取るにはどうすればよいですか?
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] {}