Groovy MY-NOTEBOOK

Saturday, January 14, 2012

HSQLDB を key-value ストアとして使うクライアントライブラリ

以前に書いたコード。
なんでこんな回りくどいことをしているんだろう・・・と思うがとりえず残しておこう。
そのうち直そう。

HSQLDB を動かすにはこちらのエントリを参照のこと

Build and Deploy

Get source code from github , build jar using gradle and deploy.


$ git clone git://github.com/osima/datastore.git
$ cd datastore
$ gradle
$ cp build/libs/data-store-version.jar ~/.groovy/lib/

Usage example

Code-1) test.groovy


import jp.osima.blog.datastore.*

createItem = {
	def item=new Item()
	item.setValue(it)
	item
}

db = new Db(new Param())
db.init()
db.put(createItem('(1) hello world!'))
db.put(createItem('(2) hello groovy!'))
db.put(createItem('(3) hello data store!'))

println '--- order by ASC ---'
db.getAll( { println it } as DbListener )

println '--- order by DESC ---'
db.getAll( { println it } as DbListener,true )

Code-2) hsqldbServer.groovy


@Grab(group='org.hsqldb', module='hsqldb', version='2.0.0')

def dbName = 'mydb'
def dbPath = "file:${dbName}"
//def dbPath = "file:/var/hsqldb/${dbName}"

def myargs = ['--database.0',dbPath,'--dbname.0',dbName] as String[]
org.hsqldb.server.Server.main( myargs )

Run

Start hsqldb server before run test.groovy .


$ groovy hsqldbServer

And then , run test.groovy .


$ groovy test
--- order by ASC ---
dacb6a27-093c-4255-96ce-130ce99640eb:(1) hello world!
385a0666-5fb4-4afe-81f0-ea16dd2ce38a:(2) hello groovy!
34e99b04-221c-4d90-9bb1-f606be7357e0:(3) hello data store!
--- order by DESC ---
34e99b04-221c-4d90-9bb1-f606be7357e0:(3) hello data store!
385a0666-5fb4-4afe-81f0-ea16dd2ce38a:(2) hello groovy!
dacb6a27-093c-4255-96ce-130ce99640eb:(1) hello world!

© 2009-2012 Tomoaki Oshima