MapperDao ORM library 0.9.1 released
Hi all,
Getting closer to v1.0, the mapperdao now supports sql server along
with oracle, mysql, derby, postgresql. MapperDao was build in scala
and compared to i.e. hibernate it supports immutability, options, map-
once and run on all supported databases without recompilation or any
code changes, configurable retrieval of entities during queries and no
need to impl equals() or hashCode just for mapperdao. Ofcourse
transactions are supported but best of all, a clean domain model
without code restrictions posed by other ORM tools. Finally, MapperDao
provides mixins to easily create CRUD dao's with options to retreive
paged rows of entities.
https://code.google.com/p/mapperdao/
Please provide feedback on the "Issues" section regarding i.e. which
database should be supported next or any feature that you might wish
to be added.
A quick example:
domain package:
class Person(val name: String, val company: Company)
class Company(val name: String)
dao package:
object PersonEntity extends Entity[IntId, Person](classOf[Person]) {
val id = key("id") autogenerated (_.id)
val name = column("name") to (_.name) // maps column "name" to
Person.name
val company = manytoone(CompanyEntity) to (_.company)
def constructor(implicit m: ValuesMap) = new Person(name,
company) with IntId with Persisted {
val id: Int = PersonEntity.id
}
}
object CompanyEntity extends Entity[IntId, Company](classOf[Company])
{
val id = key("id") autogenerated (_.id)
val name = column("name") to (_.name)
def constructor(implicit m: ValuesMap) = new Company(name)
with IntId with Persisted {
val id: Int = CompanyEntity.id
}
}
now we can use mapperdao straight away to i.e. insert data:
val inserted=mapperDao.insert(PersonEntity,new Person("Kostas",new
Company("My Company"))
println(inserted.id)
or on a real life project we would use the mapperdao mixins to create
our dao's:
abstract class PersonDao extends TransactionalIntIdCRUD[Person] with
IntIdAll[Person] {
val entity = PersonEntity
// aliases
val pe=PersonEntity
val ce=CompanyEntity
// find all Person working for a company. The return type is
List[Person with IntId]
def workingForCompany(name:String) = queryDao.query(
select from pe join (pe,pe.company,ce)
where ce.name===name
}
// PersonDao mixes in the following methods: create(), retrieve(),
update(), delete() and also all():List[Person],
page(page,rowsPerPage):List[Person] etc
mvc package:
val person=personDao.create(new Person("Kostas",new Company("My
Company"))
println(person.id) // autogenerated
...
val people=personDao.page(1,20) // get's the 1st page containing 20
Person entities
MapperDao uses springframework's JdbcTemplate and transaction
infrastructure, featuring full support for transactional features of
each database, propagation and isolation levels along with transaction
timeouts.
Next versions might see optimizations, a pdf tutorial and a head to
head comparison with hibernate (performance, coding patterns, cross
database compatibility etc)
Best Regards,
Kostantinos Kougios