2004-05-19

Quick and Easy Object Persistence

pBeans + GroovyBeans

So, here's a basic object persistence example in 20 lines of Groovy:


import net.sourceforge.pbeans.data.*
import net.sourceforge.pbeans.*

dataSource = new GenericDataSource()
dataSource.setDriverClassName("com.mysql.jdbc.Driver")
dataSource.setUrl("jdbc:mysql://localhost/test?user=test&password=test")

store = new Store(dataSource)

class User implements Persistent {
Integer id
String name
Integer age
String hometown
}

joe = new User(name:"Joe User", age:43, hometown:"Bay Minette, AL")
store.insert(joe)
newjoe = store.selectSingle(User.class, "name", "Joe User")
assert newjoe.hometown == "Bay Minette, AL"


Link via TheServerSide.

1 comment:

  1. Hmm and what about complex structures like:

    A purchase order that HASA collection of
    orderitems

    ReplyDelete