-
Notifications
You must be signed in to change notification settings - Fork 5
/
eventlog.rb
54 lines (46 loc) · 1.21 KB
/
eventlog.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# Basic requires
require 'rubygems'
require 'java'
require 'jdbc/hsqldb'
require 'jruby/core_ext'
# Our requires
require 'hibernate'
Hibernate.dialect = Hibernate::Dialects::HSQL
Hibernate.current_session_context_class = "thread"
Hibernate.connection_driver_class = "org.hsqldb.jdbcDriver"
Hibernate.connection_url = "jdbc:hsqldb:file:jibernate"
Hibernate.connection_username = "sa"
Hibernate.connection_password = ""
Hibernate.properties["hbm2ddl.auto"] = "update"
class Event
extend Hibernate::Model
hibernate_attr :id => :long, :title => :string, :date => :date
hibernate!
end
Hibernate.add_model "Event.hbm.xml"
Hibernate.tx do |session|
# Hack for HSQLDB's write delay
session.createSQLQuery("SET WRITE_DELAY FALSE").execute_update
case ARGV[0]
when /store/
# Create event and store it
event = Event.new
event.title = ARGV[1]
event.date = java.util.Date.new
session.save(event)
puts "Stored!"
when /list/
# List all events
list = session.create_query('from Event').list
puts "Listing all events:"
list.each do |evt|
puts <<EOS
id: #{evt.id}
title: #{evt.title}
date: #{evt.date}"
EOS
end
else
puts "Usage:\n\tstore <title>\n\tlist"
end
end