Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Initial commit of latest jibernate work to its own project.

  • Loading branch information...
commit 91c9d23163e3faa55782a3e5e9025a786bc56878 0 parents
@headius authored
20 Event.hbm.xml
@@ -0,0 +1,20 @@
+<?xml version="1.0"?>
+<!DOCTYPE hibernate-mapping PUBLIC
+ "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
+ "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
+
+<!--
+we'd really want to define this programmatically
+-->
+
+<hibernate-mapping package="ruby">
+
+ <class name="Event" table="EVENTS">
+ <id name="id" column="EVENT_ID">
+ <generator class="native"/>
+ </id>
+ <property name="date" type="timestamp" column="EVENT_DATE"/>
+ <property name="title"/>
+ </class>
+
+</hibernate-mapping>
37 dialects.rb
@@ -0,0 +1,37 @@
+module Hibernate
+ module Dialects
+ Cache71 = "org.hibernate.dialect.Cache71Dialect"
+ DataDirectOracle9 = "org.hibernate.dialect.DataDirectOracle9Dialect"
+ DB2390 = "org.hibernate.dialect.DB2390Dialect"
+ DB2400 = "org.hibernate.dialect.DB2400Dialect"
+ DB2 = "org.hibernate.dialect.DB2Dialect"
+ Derby = "org.hibernate.dialect.DerbyDialect"
+ Firebird = "org.hibernate.dialect.FirebirdDialect"
+ FrontBase = "org.hibernate.dialect.FrontBaseDialect"
+ H2 = "org.hibernate.dialect.H2Dialect"
+ HSQL = "org.hibernate.dialect.HSQLDialect"
+ Informix = "org.hibernate.dialect.InformixDialect"
+ Ingres = "org.hibernate.dialect.IngresDialect"
+ Interbase = "org.hibernate.dialect.InterbaseDialect"
+ JDataStore = "org.hibernate.dialect.JDataStoreDialect"
+ Mckoi = "org.hibernate.dialect.MckoiDialect"
+ MimerSQL = "org.hibernate.dialect.MimerSQLDialect"
+ MySQL5 = "org.hibernate.dialect.MySQL5Dialect"
+ MySQL5InnoDB = "org.hibernate.dialect.MySQL5InnoDBDialect"
+ MySQL = "org.hibernate.dialect.MySQLDialect"
+ MySQLInnoDB = "org.hibernate.dialect.MySQLInnoDBDialect"
+ MySQLMyISAM = "org.hibernate.dialect.MySQLMyISAMDialect"
+ Oracle9 = "org.hibernate.dialect.Oracle9Dialect"
+ Oracle = "org.hibernate.dialect.OracleDialect"
+ Pointbase = "org.hibernate.dialect.PointbaseDialect"
+ PostgreSQL = "org.hibernate.dialect.PostgreSQLDialect"
+ Progress = "org.hibernate.dialect.ProgressDialect"
+ RDMSOS2200 = "org.hibernate.dialect.RDMSOS2200Dialect"
+ SAPDB = "org.hibernate.dialect.SAPDBDialect"
+ SQLServer = "org.hibernate.dialect.SQLServerDialect"
+ Sybase11 = "org.hibernate.dialect.Sybase11Dialect"
+ SybaseAnywhere = "org.hibernate.dialect.SybaseAnywhereDialect"
+ Sybase = "org.hibernate.dialect.SybaseDialect"
+ TimesTen = "org.hibernate.dialect.TimesTenDialect"
+ end
+end
54 eventlog.rb
@@ -0,0 +1,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
132 hibernate.rb
@@ -0,0 +1,132 @@
+require 'java'
+require 'lib/antlr-2.7.6.jar'
+require 'lib/commons-collections-3.1.jar'
+require 'lib/dom4j-1.6.1.jar'
+require 'lib/javassist-3.9.0.GA.jar'
+require 'lib/jta-1.1.jar'
+require 'lib/slf4j-simple-1.5.8.jar'
+require 'lib/slf4j-api-1.5.8.jar'
+require 'lib/hibernate3.jar'
+require 'stringio'
+
+require 'dialects'
+
+module Hibernate
+ import org.hibernate.cfg.Configuration
+ import javax.xml.parsers.DocumentBuilderFactory
+ import org.xml.sax.InputSource
+ JClass = java.lang.Class
+ JVoid = java.lang.Void::TYPE
+ DOCUMENT_BUILDER_FACTORY = DocumentBuilderFactory.new_instance
+ DOCUMENT_BUILDER_FACTORY.validating = false
+ DOCUMENT_BUILDER_FACTORY.expand_entity_references = false
+ DOCUMENT_BUILDER = DOCUMENT_BUILDER_FACTORY.new_document_builder
+
+ def self.dialect=(dialect)
+ config.set_property "hibernate.dialect", dialect
+ end
+
+ def self.current_session_context_class=(ctx_cls)
+ config.set_property "hibernate.current_session_context_class", ctx_cls
+ end
+
+ def self.connection_driver_class=(driver_class)
+ config.set_property "hibernate.connection.driver_class", driver_class
+ end
+
+ def self.connection_url=(url)
+ config.set_property "hibernate.connection.url", url
+ end
+
+ def self.connection_username=(username)
+ config.set_property "hibernate.connection.username", username
+ end
+
+ def self.connection_password=(password)
+ config.set_property "hibernate.connection.password", password
+ end
+
+ class PropertyShim
+ def initialize(config)
+ @config = config
+ end
+
+ def []=(key, value)
+ key = ensure_hibernate_key(key)
+ @config.set_property key, value
+ end
+
+ def [](key)
+ key = ensure_hibernate_key(key)
+ config.get_property key
+ end
+
+ private
+ def ensure_hibernate_key(key)
+ unless key =~ /^hibernate\./
+ key = 'hibernate.' + key
+ end
+ key
+ end
+ end
+
+ def self.properties
+ PropertyShim.new(@config)
+ end
+
+ def self.tx
+ session.begin_transaction
+ if block_given?
+ yield session
+ session.transaction.commit
+ end
+ end
+
+ def self.factory
+ @factory ||= config.build_session_factory
+ end
+
+ def self.session
+ factory.current_session
+ end
+
+ def self.config
+ @config ||= Configuration.new
+ end
+
+ def self.add_model(mapping)
+ config.add_xml(File.read(mapping))
+ end
+
+ module Model
+ TYPES = {
+ :string => java.lang.String,
+ :long => java.lang.Long,
+ :date => java.util.Date
+ }
+
+ def hibernate_sigs
+ @hibernate_sigs ||= {}
+ end
+
+ def hibernate_attr(attrs)
+ attrs.each do |name, type|
+ attr_accessor name
+ get_name = "get#{name.to_s.capitalize}"
+ set_name = "set#{name.to_s.capitalize}"
+
+ alias_method get_name.intern, name
+ add_method_signature get_name, [TYPES[type].java_class]
+ alias_method set_name.intern, :"#{name.to_s}="
+ add_method_signature set_name, [JVoid, TYPES[type].java_class]
+ end
+ end
+
+ def hibernate!
+ become_java!
+
+# Hibernate.mappings.
+# Hibernate.add_mapping reified_class,
+ end
+ end
+end
65 hibernate_config.rb
@@ -0,0 +1,65 @@
+EVENT = <<EVENT
+<?xml version="1.0"?>
+<!DOCTYPE hibernate-mapping PUBLIC
+ "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
+ "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
+
+<!--
+Once again, we'd really want to define this programmatically
+-->
+
+<hibernate-mapping package="ruby">
+
+ <class name="Event" table="EVENTS">
+ <id name="id" column="EVENT_ID">
+ <generator class="native"/>
+ </id>
+ <property name="date" type="timestamp" column="EVENT_DATE"/>
+ <property name="title"/>
+ </class>
+
+</hibernate-mapping>
+EVENT
+
+HBXML = <<HBXML
+<?xml version='1.0' encoding='utf-8'?>
+<!DOCTYPE hibernate-configuration PUBLIC
+ "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
+ "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
+
+<!--
+DEAR GOD, NO!
+Obviously we'd want to define this programmatically
+-->
+
+<hibernate-configuration>
+
+ <session-factory>
+
+ <!-- Database connection settings -->
+ <property name="connection.driver_class">org.hsqldb.jdbcDriver</property>
+ <property name="connection.url">jdbc:hsqldb:file:jibernate</property>
+ <property name="connection.username">sa</property>
+ <property name="connection.password"></property>
+
+ <!-- JDBC connection pool (use the built-in) -->
+ <property name="connection.pool_size">1</property>
+
+ <!-- SQL dialect -->
+ <property name="dialect">org.hibernate.dialect.HSQLDialect</property>
+
+ <!-- Enable Hibernate's automatic session context management -->
+ <property name="current_session_context_class">thread</property>
+
+ <!-- Disable the second-level cache -->
+ <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
+
+ <!-- Echo all executed SQL to stdout -->
+ <property name="show_sql">false</property>
+
+ <!-- Drop and re-create the database schema on startup -->
+ <property name="hbm2ddl.auto">update</property>
+ </session-factory>
+
+</hibernate-configuration>
+HBXML
BIN  lib/antlr-2.7.6.jar
Binary file not shown
BIN  lib/commons-collections-3.1.jar
Binary file not shown
BIN  lib/dom4j-1.6.1.jar
Binary file not shown
BIN  lib/hibernate3.jar
Binary file not shown
BIN  lib/javassist-3.9.0.GA.jar
Binary file not shown
BIN  lib/jta-1.1.jar
Binary file not shown
BIN  lib/slf4j-api-1.5.8.jar
Binary file not shown
BIN  lib/slf4j-simple-1.5.8.jar
Binary file not shown
43 rails_underground.cfg.xml
@@ -0,0 +1,43 @@
+<?xml version='1.0' encoding='utf-8'?>
+<!DOCTYPE hibernate-configuration PUBLIC
+ "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
+ "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
+
+<!--
+DEAR GOD, NO!
+Obviously we'd want to define this programmatically
+-->
+
+<hibernate-configuration>
+
+ <session-factory>
+
+ <!-- Database connection settings -->
+ <property name="connection.driver_class">org.hsqldb.jdbcDriver</property>
+ <property name="connection.url">jdbc:hsqldb:file:jibernate</property>
+ <property name="connection.username">sa</property>
+ <property name="connection.password"></property>
+
+ <!-- JDBC connection pool (use the built-in) -->
+ <property name="connection.pool_size">1</property>
+
+ <!-- SQL dialect -->
+ <property name="dialect">org.hibernate.dialect.HSQLDialect</property>
+
+ <!-- Enable Hibernate's automatic session context management -->
+ <property name="current_session_context_class">thread</property>
+
+ <!-- Disable the second-level cache -->
+ <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
+
+ <!-- Echo all executed SQL to stdout -->
+ <property name="show_sql">false</property>
+
+ <!-- Drop and re-create the database schema on startup -->
+ <property name="hbm2ddl.auto">update</property>
+
+ <mapping resource="Event.hbm.xml"/>
+
+ </session-factory>
+
+</hibernate-configuration>
Please sign in to comment.
Something went wrong with that request. Please try again.