rubernate 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.Rhistory +2 -0
- data/.document +5 -0
- data/Gemfile +16 -0
- data/Gemfile.lock +28 -0
- data/LICENSE.txt +21 -0
- data/README.rdoc +47 -0
- data/Rakefile +49 -0
- data/VERSION +1 -0
- data/lib/.DS_Store +0 -0
- data/lib/native/.DS_Store +0 -0
- data/lib/native/lib/.DS_Store +0 -0
- data/lib/native/lib/antlr-2.7.6.jar +0 -0
- data/lib/native/lib/c3p0-0.9.1.jar +0 -0
- data/lib/native/lib/commons-collections-3.1.jar +0 -0
- data/lib/native/lib/dom4j-1.6.1.jar +0 -0
- data/lib/native/lib/hibernate-jpa-2.0-api-1.0.1.Final.jar +0 -0
- data/lib/native/lib/hibernate3.jar +0 -0
- data/lib/native/lib/javaee.jar +0 -0
- data/lib/native/lib/javassist.jar +0 -0
- data/lib/native/lib/javax.persistence.jar +0 -0
- data/lib/native/lib/jta-1.1.jar +0 -0
- data/lib/native/lib/mysql-connector-java-5.1.15-bin.jar +0 -0
- data/lib/native/lib/slf4j-api-1.6.1.jar +0 -0
- data/lib/native/lib/slf4j-simple-1.6.1.jar +0 -0
- data/lib/native/src/net/devmask/rubernate/ClassBuilder.java +24 -0
- data/lib/rubernate.rb +10 -0
- data/lib/rubernate/bytecode.rb +120 -0
- data/lib/rubernate/class_parser.rb +43 -0
- data/lib/rubernate/connection.rb +46 -0
- data/lib/rubernate/entity.rb +21 -0
- data/lib/rubernate/init.rb +44 -0
- data/lib/rubernate/relations.rb +71 -0
- data/out/production/Rubernate/net/devmask/rubernate/ClassBuilder.class +0 -0
- data/rubernate.gemspec +93 -0
- data/test/helper.rb +18 -0
- data/test/test_rubernate.rb +7 -0
- metadata +171 -0
data/.Rhistory
ADDED
data/.document
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
5
|
+
gem 'jruby-openssl'
|
6
|
+
|
7
|
+
# Add dependencies to develop your gem here.
|
8
|
+
# Include everything needed to run rake, tests, features, etc.
|
9
|
+
group :development do
|
10
|
+
gem "shoulda", ">= 0"
|
11
|
+
gem "bundler", "~> 1.0.0"
|
12
|
+
gem "yard", "~> 0.6.0"
|
13
|
+
gem "jeweler", "~> 1.6.4"
|
14
|
+
gem "rcov", ">= 0"
|
15
|
+
gem 'smart_colored'
|
16
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
bouncy-castle-java (1.5.0146.1)
|
5
|
+
git (1.2.5)
|
6
|
+
jeweler (1.6.4)
|
7
|
+
bundler (~> 1.0)
|
8
|
+
git (>= 1.2.5)
|
9
|
+
rake
|
10
|
+
jruby-openssl (0.7.4)
|
11
|
+
bouncy-castle-java
|
12
|
+
rake (0.9.2)
|
13
|
+
rcov (0.9.9-java)
|
14
|
+
shoulda (2.11.3)
|
15
|
+
smart_colored (1.0.2)
|
16
|
+
yard (0.6.8)
|
17
|
+
|
18
|
+
PLATFORMS
|
19
|
+
java
|
20
|
+
|
21
|
+
DEPENDENCIES
|
22
|
+
bundler (~> 1.0.0)
|
23
|
+
jeweler (~> 1.6.4)
|
24
|
+
jruby-openssl
|
25
|
+
rcov
|
26
|
+
shoulda
|
27
|
+
smart_colored
|
28
|
+
yard (~> 0.6.0)
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
Copyright (c) 2011 Jonathan Garay
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
|
+
|
data/README.rdoc
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
= rubernate
|
2
|
+
|
3
|
+
Create a class with common java values
|
4
|
+
'''ruby
|
5
|
+
class User < Rubernate::Entity
|
6
|
+
integer :id , :id=>true , :generated => [:auto=>true, :strategy=>:auto]
|
7
|
+
string :name
|
8
|
+
float :float_otra
|
9
|
+
double :double_otra
|
10
|
+
boolean :active
|
11
|
+
end
|
12
|
+
'''
|
13
|
+
rubernate = Rubernate::Init.new
|
14
|
+
rubernate.load_classes(User)
|
15
|
+
|
16
|
+
connection_properties = Hash[
|
17
|
+
:dialect=>"org.hibernate.dialect.MySQLDialect',
|
18
|
+
:url=>'jdbc:mysql://localhost:3306/rubernate',
|
19
|
+
:driver=>'com.mysql.jdbc.Driver',
|
20
|
+
:username=>'root',
|
21
|
+
:password=>'',
|
22
|
+
:auto_ddl=>'update',
|
23
|
+
]
|
24
|
+
|
25
|
+
rubernate.connect connection_properties
|
26
|
+
|
27
|
+
User.all.each do |user|
|
28
|
+
puts user
|
29
|
+
end
|
30
|
+
|
31
|
+
User.find(1)
|
32
|
+
'''
|
33
|
+
== Contributing to rubernate
|
34
|
+
|
35
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
36
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
37
|
+
* Fork the project
|
38
|
+
* Start a feature/bugfix branch
|
39
|
+
* Commit and push until you are happy with your contribution
|
40
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
41
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
42
|
+
|
43
|
+
== Copyright
|
44
|
+
|
45
|
+
Copyright (c) 2011 Jonathan Garay. See LICENSE.txt for
|
46
|
+
further details.
|
47
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
+
gem.name = "rubernate"
|
18
|
+
gem.homepage = "http://github.com/netmask/rubernate"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = %Q{Hibernate for Ruby}
|
21
|
+
gem.description = %Q{Library for Mapping Ruby Classes has Hibernate classes }
|
22
|
+
gem.email = "jonathan@devmask.net"
|
23
|
+
gem.authors = ["Jonathan Garay"]
|
24
|
+
# dependencies defined in Gemfile
|
25
|
+
end
|
26
|
+
Jeweler::RubygemsDotOrgTasks.new
|
27
|
+
|
28
|
+
require 'rake/testtask'
|
29
|
+
Rake::TestTask.new(:test) do |test|
|
30
|
+
test.libs << 'lib' << 'test'
|
31
|
+
test.pattern = 'test/**/test_*.rb'
|
32
|
+
test.verbose = true
|
33
|
+
end
|
34
|
+
|
35
|
+
require 'rcov/rcovtask'
|
36
|
+
Rcov::RcovTask.new do |test|
|
37
|
+
test.libs << 'test'
|
38
|
+
test.pattern = 'test/**/test_*.rb'
|
39
|
+
test.verbose = true
|
40
|
+
test.rcov_opts << '--exclude "gems/*"'
|
41
|
+
end
|
42
|
+
|
43
|
+
task :default => :test
|
44
|
+
|
45
|
+
require 'yard'
|
46
|
+
YARD::Rake::YardocTask.new
|
47
|
+
|
48
|
+
Jeweler::GemcutterTasks.new
|
49
|
+
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.2
|
data/lib/.DS_Store
ADDED
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
@@ -0,0 +1,24 @@
|
|
1
|
+
package net.devmask.rubernate;
|
2
|
+
|
3
|
+
/**
|
4
|
+
* @author <a href="mailto:jonathan@devmask.net"> Jonathan Garay </a>
|
5
|
+
* 7/31/11 Creado
|
6
|
+
*/
|
7
|
+
import javassist.*;
|
8
|
+
import javassist.bytecode.annotation.StringMemberValue;
|
9
|
+
import org.hibernate.annotations.Entity;
|
10
|
+
import org.hibernate.ejb.Ejb3Configuration;
|
11
|
+
|
12
|
+
import javax.jws.Oneway;
|
13
|
+
|
14
|
+
public class ClassBuilder {
|
15
|
+
|
16
|
+
|
17
|
+
|
18
|
+
public String foa;
|
19
|
+
public void foo(){
|
20
|
+
new CtField().getFieldInfo().addAttribute();
|
21
|
+
}
|
22
|
+
|
23
|
+
|
24
|
+
}
|
data/lib/rubernate.rb
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
2
|
+
$LOAD_PATH << "#{File.dirname(__FILE__)}/../lib/native/lib/"
|
3
|
+
|
4
|
+
#load all the jars !!
|
5
|
+
|
6
|
+
Dir.glob("#{File.dirname(__FILE__)}/../lib/native/lib/*.jar").each do |jar|
|
7
|
+
require jar
|
8
|
+
end
|
9
|
+
|
10
|
+
require 'rubernate/init'
|
@@ -0,0 +1,120 @@
|
|
1
|
+
module Rubernate
|
2
|
+
|
3
|
+
# This utilit class creates the java 'classes'
|
4
|
+
class Bytecode
|
5
|
+
|
6
|
+
require 'java'
|
7
|
+
|
8
|
+
attr_accessor :class_pool
|
9
|
+
|
10
|
+
# NOT IMPLEMENTED
|
11
|
+
DEFAULT_NAMESPACE = "rubernate.models"
|
12
|
+
|
13
|
+
def initialize
|
14
|
+
java_import 'javassist.CtClass'
|
15
|
+
|
16
|
+
@@mapped_types = Hash[:integer => "Integer" ,
|
17
|
+
:long => "Long",
|
18
|
+
:short => "Short",
|
19
|
+
:float => "Float",
|
20
|
+
:double => "Double",
|
21
|
+
:string => "String" ,
|
22
|
+
:char => "char",
|
23
|
+
:boolean=> "Boolean"]
|
24
|
+
end
|
25
|
+
|
26
|
+
class << self
|
27
|
+
def mapped_types
|
28
|
+
@@mapped_types
|
29
|
+
end
|
30
|
+
end
|
31
|
+
# Creates a new class
|
32
|
+
# @param[String] class name
|
33
|
+
# @returns[ProxyClass]
|
34
|
+
def create_class(name)
|
35
|
+
java_import 'javassist.ClassPool'
|
36
|
+
java_import 'javassist.CtClass'
|
37
|
+
java_import 'javax.persistence.Entity'
|
38
|
+
|
39
|
+
|
40
|
+
self.class_pool = ClassPool.get_default
|
41
|
+
ProxyClass.new(self.class_pool.makeClass("#{name}"))
|
42
|
+
end
|
43
|
+
|
44
|
+
# Representation of the generated class
|
45
|
+
class ProxyClass
|
46
|
+
|
47
|
+
attr_accessor :clazz, :ct_class, :frozen, :class_file, :const_pool
|
48
|
+
|
49
|
+
def initialize(ct_class)
|
50
|
+
self.ct_class = ct_class
|
51
|
+
self.frozen = false
|
52
|
+
|
53
|
+
java_import 'javassist.bytecode.ClassFile'
|
54
|
+
java_import 'javassist.bytecode.AnnotationsAttribute'
|
55
|
+
java_import 'javassist.bytecode.annotation.Annotation'
|
56
|
+
java_import 'javassist.bytecode.annotation.StringMemberValue'
|
57
|
+
|
58
|
+
self.class_file = self.ct_class.getClassFile
|
59
|
+
self.const_pool = self.class_file.getConstPool
|
60
|
+
|
61
|
+
ann_attr = AnnotationsAttribute.new(self.const_pool, AnnotationsAttribute.visibleTag)
|
62
|
+
ann = Annotation.new("javax.persistence.Entity",self.const_pool)
|
63
|
+
ann.add_member_value "name", StringMemberValue.new(self.ct_class.name,self.const_pool)
|
64
|
+
|
65
|
+
|
66
|
+
ann_attr.set_annotation ann
|
67
|
+
self.class_file.addAttribute(ann_attr)
|
68
|
+
end
|
69
|
+
|
70
|
+
# adds full qulified java annotation to a field
|
71
|
+
# @param[CtField] javassist field
|
72
|
+
# @param[String] field name
|
73
|
+
def add_annotation(field,name)
|
74
|
+
ann_attr = AnnotationsAttribute.new(self.const_pool, AnnotationsAttribute.visibleTag)
|
75
|
+
ann = Annotation.new(name,self.const_pool)
|
76
|
+
|
77
|
+
ann_attr.set_annotation ann
|
78
|
+
field.getFieldInfo.addAttribute ann_attr
|
79
|
+
end
|
80
|
+
|
81
|
+
# add simple parameter to a field
|
82
|
+
# (see #add_parameter)
|
83
|
+
def add_simple(type,name)
|
84
|
+
add_parameter(Rubernate::Bytecode.mapped_types[type],name)
|
85
|
+
end
|
86
|
+
|
87
|
+
|
88
|
+
# This wild add a parammeter to given class and generates te setter
|
89
|
+
#
|
90
|
+
# @param[String] java type
|
91
|
+
# @Param[String] name of the field
|
92
|
+
# @return[CtField] Generated field
|
93
|
+
def add_parameter(type,name)
|
94
|
+
java_import 'javassist.CtField'
|
95
|
+
java_import 'javassist.CtMethod'
|
96
|
+
java_import 'javassist.Modifier'
|
97
|
+
java_import 'javax.persistence.Basic'
|
98
|
+
|
99
|
+
field = CtField.make("private #{type} #{name};",self.ct_class)
|
100
|
+
self.ct_class.add_field(field)
|
101
|
+
|
102
|
+
get = CtMethod.make(" public #{type} get#{name.capitalize}(){ return #{name}; }",self.ct_class)
|
103
|
+
set = CtMethod.make(" public void set#{name.capitalize}(#{type} #{name}){ this.#{name} = #{name}; }",self.ct_class)
|
104
|
+
self.ct_class.add_method(get)
|
105
|
+
self.ct_class.add_method(set)
|
106
|
+
|
107
|
+
return field
|
108
|
+
end
|
109
|
+
|
110
|
+
# @return[Class] java byte code generated class
|
111
|
+
def to_class
|
112
|
+
self.ct_class.to_class
|
113
|
+
end
|
114
|
+
|
115
|
+
end
|
116
|
+
|
117
|
+
end
|
118
|
+
|
119
|
+
|
120
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module Rubernate
|
2
|
+
|
3
|
+
class ClassParser
|
4
|
+
|
5
|
+
attr_accessor :clazz,:bytecode,:proxy_class
|
6
|
+
|
7
|
+
def initialize(clazz,bytecode)
|
8
|
+
puts "Class"
|
9
|
+
self.clazz = clazz
|
10
|
+
self.bytecode = bytecode
|
11
|
+
self.proxy_class = bytecode.create_class(name)
|
12
|
+
initialize_simples
|
13
|
+
end
|
14
|
+
|
15
|
+
#TODO need to correct this behaivor
|
16
|
+
def initialize_simples
|
17
|
+
clazz.fields.each do |field|
|
18
|
+
proxy_field = proxy_class.add_simple(field[:type],field[:name].to_s)
|
19
|
+
field[:args].each do |f1|
|
20
|
+
if f1.length > 0
|
21
|
+
build_id_for proxy_field if f1[0][:id]
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def build_id_for(field)
|
28
|
+
self.proxy_class.add_annotation field,"javax.persistence.Id"
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
def name
|
34
|
+
self.clazz.name
|
35
|
+
end
|
36
|
+
|
37
|
+
def to_class
|
38
|
+
self.proxy_class.to_class
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module Rubernate
|
2
|
+
|
3
|
+
|
4
|
+
class Connection
|
5
|
+
|
6
|
+
|
7
|
+
attr_accessor :connecion, :factory, :configuration
|
8
|
+
|
9
|
+
|
10
|
+
def initialize(connection,*classes)
|
11
|
+
|
12
|
+
import org.hibernate.Session
|
13
|
+
import org.hibernate.SessionFactory
|
14
|
+
import org.hibernate.Transaction
|
15
|
+
import org.hibernate.cfg.AnnotationConfiguration
|
16
|
+
import org.hibernate.ejb.Ejb3Configuration
|
17
|
+
|
18
|
+
|
19
|
+
self.configuration = Ejb3Configuration.new
|
20
|
+
|
21
|
+
self.configuration.set_property "hibernate.dialect",connection[:dialect]
|
22
|
+
self.configuration.set_property "hibernate.connection.url", connection[:url]
|
23
|
+
self.configuration.set_property "hibernate.connection.driver_class", connection[:driver]
|
24
|
+
self.configuration.set_property "hibernate.connection.user", "root"
|
25
|
+
self.configuration.set_property "hibernate.connection.password", ""
|
26
|
+
self.configuration.set_property "javax.persistence.provider ","org.hibernate.ejb.HibernatePersistence"
|
27
|
+
self.configuration.set_property "hibernate.hbm2ddl.auto", connection[:auto_ddl]
|
28
|
+
self.configuration.set_property "hibernate.connection.provider_class","org.hibernate.connection.DriverManagerConnectionProvider"
|
29
|
+
classes.each do |clazz|
|
30
|
+
clazz.each do |c1|
|
31
|
+
configuration.addAnnotatedClass c1
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
def entity_manager_factory
|
39
|
+
@@factory = configuration.buildEntityManagerFactory
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.entity_manager
|
43
|
+
@@factory.createEntityManager
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'java'
|
2
|
+
module Rubernate
|
3
|
+
class Entity < java.lang.Object
|
4
|
+
include Relations
|
5
|
+
|
6
|
+
attr_accessor :proxy_class
|
7
|
+
|
8
|
+
def self.find(id)
|
9
|
+
Connection.entity_manager.create_query("SELECT e FROM #{self} as e where e.id = :id").set_parameter(id).get_single_result
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.all()
|
13
|
+
Connection.entity_manager.create_query("SELECT e FROM #{self} as e ").result_list
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.by_hql(hql)
|
17
|
+
Connection.entity_manager.create_query(hql)
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
|
2
|
+
require 'rubernate/relations'
|
3
|
+
require 'rubernate/entity'
|
4
|
+
require "rubernate/connection"
|
5
|
+
require 'rubernate/bytecode'
|
6
|
+
require 'rubernate/class_parser'
|
7
|
+
|
8
|
+
require 'java'
|
9
|
+
require 'rubygems'
|
10
|
+
|
11
|
+
module Rubernate
|
12
|
+
class Init
|
13
|
+
attr_accessor :connection, :bytecode, :parser,:hibernate_classes
|
14
|
+
|
15
|
+
def initialize
|
16
|
+
self.hibernate_classes = []
|
17
|
+
|
18
|
+
bytecode_provider
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
|
23
|
+
def load_classes(*classes)
|
24
|
+
classes.each do |clazz|
|
25
|
+
self.hibernate_classes << ClassParser.new(clazz,self.bytecode).to_class
|
26
|
+
end
|
27
|
+
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
def connect(connection)
|
32
|
+
self.connection= Connection.new(connection, self.hibernate_classes)
|
33
|
+
self.connection.entity_manager_factory
|
34
|
+
end
|
35
|
+
|
36
|
+
def bytecode_provider
|
37
|
+
self.bytecode ||= Bytecode.new
|
38
|
+
self.bytecode
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
|
@@ -0,0 +1,71 @@
|
|
1
|
+
module Rubernate
|
2
|
+
module Relations
|
3
|
+
class << self
|
4
|
+
def included(base)
|
5
|
+
base.extend ClassMethods
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
module ClassMethods
|
10
|
+
#Defines a 'basic' Supporte tipes
|
11
|
+
@@supported_types = [:integer,:long,:short,:float,:double,:string,:char,:boolean]
|
12
|
+
@@supported_associations = [:one_to_one,:one_to_many,:many_to_one,:many_to_many]
|
13
|
+
|
14
|
+
#TODO merge to a single loop ;) i love ruby
|
15
|
+
@@supported_types.each do | function |
|
16
|
+
method = "#{function}".to_sym
|
17
|
+
send :define_method, method do |name,*arguments|
|
18
|
+
add_field(name,function,arguments)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
@@supported_associations.each do |function|
|
23
|
+
method = "#{function}".to_sym
|
24
|
+
send :define_method, method do |name,*arguments|
|
25
|
+
map = arguments.first
|
26
|
+
add_relation(name,map.delete(:class),function,arguments)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def bind_class(clazz)
|
31
|
+
@from_java_class = clazz
|
32
|
+
end
|
33
|
+
|
34
|
+
def fields
|
35
|
+
@fields
|
36
|
+
end
|
37
|
+
|
38
|
+
def relations
|
39
|
+
@relations
|
40
|
+
end
|
41
|
+
|
42
|
+
def add_field(name,type,*args)
|
43
|
+
@fields ||= []
|
44
|
+
@fields << Hash[:name=>name,:type=>type,:args=>args]
|
45
|
+
end
|
46
|
+
|
47
|
+
def table_name
|
48
|
+
@table_name
|
49
|
+
end
|
50
|
+
|
51
|
+
def table_name=(table_name)
|
52
|
+
@table_name=table_name
|
53
|
+
end
|
54
|
+
|
55
|
+
def add_relation(name,clazz,type,params)
|
56
|
+
@relations ||= []
|
57
|
+
@relations << Hash[:name=>name,:class=>clazz,:type=>type,:params=>params]
|
58
|
+
end
|
59
|
+
|
60
|
+
def supported_types
|
61
|
+
@@supported_types
|
62
|
+
end
|
63
|
+
|
64
|
+
def supported_associations
|
65
|
+
@@supported_associations
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
71
|
+
end
|
Binary file
|
data/rubernate.gemspec
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{rubernate}
|
8
|
+
s.version = "0.0.2"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Jonathan Garay"]
|
12
|
+
s.date = %q{2011-08-04}
|
13
|
+
s.description = %q{Library for Mapping Ruby Classes has Hibernate classes }
|
14
|
+
s.email = %q{jonathan@devmask.net}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE.txt",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".Rhistory",
|
21
|
+
".document",
|
22
|
+
"Gemfile",
|
23
|
+
"Gemfile.lock",
|
24
|
+
"LICENSE.txt",
|
25
|
+
"README.rdoc",
|
26
|
+
"Rakefile",
|
27
|
+
"VERSION",
|
28
|
+
"lib/.DS_Store",
|
29
|
+
"lib/native/.DS_Store",
|
30
|
+
"lib/native/lib/.DS_Store",
|
31
|
+
"lib/native/lib/antlr-2.7.6.jar",
|
32
|
+
"lib/native/lib/c3p0-0.9.1.jar",
|
33
|
+
"lib/native/lib/commons-collections-3.1.jar",
|
34
|
+
"lib/native/lib/dom4j-1.6.1.jar",
|
35
|
+
"lib/native/lib/hibernate-jpa-2.0-api-1.0.1.Final.jar",
|
36
|
+
"lib/native/lib/hibernate3.jar",
|
37
|
+
"lib/native/lib/javaee.jar",
|
38
|
+
"lib/native/lib/javassist.jar",
|
39
|
+
"lib/native/lib/javax.persistence.jar",
|
40
|
+
"lib/native/lib/jta-1.1.jar",
|
41
|
+
"lib/native/lib/mysql-connector-java-5.1.15-bin.jar",
|
42
|
+
"lib/native/lib/slf4j-api-1.6.1.jar",
|
43
|
+
"lib/native/lib/slf4j-simple-1.6.1.jar",
|
44
|
+
"lib/native/src/net/devmask/rubernate/ClassBuilder.java",
|
45
|
+
"lib/rubernate.rb",
|
46
|
+
"lib/rubernate/bytecode.rb",
|
47
|
+
"lib/rubernate/class_parser.rb",
|
48
|
+
"lib/rubernate/connection.rb",
|
49
|
+
"lib/rubernate/entity.rb",
|
50
|
+
"lib/rubernate/init.rb",
|
51
|
+
"lib/rubernate/relations.rb",
|
52
|
+
"out/production/Rubernate/net/devmask/rubernate/ClassBuilder.class",
|
53
|
+
"rubernate.gemspec",
|
54
|
+
"test/helper.rb",
|
55
|
+
"test/test_rubernate.rb"
|
56
|
+
]
|
57
|
+
s.homepage = %q{http://github.com/netmask/rubernate}
|
58
|
+
s.licenses = ["MIT"]
|
59
|
+
s.require_paths = ["lib"]
|
60
|
+
s.rubygems_version = %q{1.5.1}
|
61
|
+
s.summary = %q{Hibernate for Ruby}
|
62
|
+
|
63
|
+
if s.respond_to? :specification_version then
|
64
|
+
s.specification_version = 3
|
65
|
+
|
66
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
67
|
+
s.add_runtime_dependency(%q<jruby-openssl>, [">= 0"])
|
68
|
+
s.add_development_dependency(%q<shoulda>, [">= 0"])
|
69
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
70
|
+
s.add_development_dependency(%q<yard>, ["~> 0.6.0"])
|
71
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
|
72
|
+
s.add_development_dependency(%q<rcov>, [">= 0"])
|
73
|
+
s.add_development_dependency(%q<smart_colored>, [">= 0"])
|
74
|
+
else
|
75
|
+
s.add_dependency(%q<jruby-openssl>, [">= 0"])
|
76
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
77
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
78
|
+
s.add_dependency(%q<yard>, ["~> 0.6.0"])
|
79
|
+
s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
|
80
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
81
|
+
s.add_dependency(%q<smart_colored>, [">= 0"])
|
82
|
+
end
|
83
|
+
else
|
84
|
+
s.add_dependency(%q<jruby-openssl>, [">= 0"])
|
85
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
86
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
87
|
+
s.add_dependency(%q<yard>, ["~> 0.6.0"])
|
88
|
+
s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
|
89
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
90
|
+
s.add_dependency(%q<smart_colored>, [">= 0"])
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
data/test/helper.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'test/unit'
|
11
|
+
require 'shoulda'
|
12
|
+
|
13
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
14
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
15
|
+
require 'rubernate'
|
16
|
+
|
17
|
+
class Test::Unit::TestCase
|
18
|
+
end
|
metadata
ADDED
@@ -0,0 +1,171 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rubernate
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.0.2
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Jonathan Garay
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2011-08-04 00:00:00 -06:00
|
14
|
+
default_executable:
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: jruby-openssl
|
18
|
+
version_requirements: &id001 !ruby/object:Gem::Requirement
|
19
|
+
none: false
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
requirement: *id001
|
25
|
+
prerelease: false
|
26
|
+
type: :runtime
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: shoulda
|
29
|
+
version_requirements: &id002 !ruby/object:Gem::Requirement
|
30
|
+
none: false
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: "0"
|
35
|
+
requirement: *id002
|
36
|
+
prerelease: false
|
37
|
+
type: :development
|
38
|
+
- !ruby/object:Gem::Dependency
|
39
|
+
name: bundler
|
40
|
+
version_requirements: &id003 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 1.0.0
|
46
|
+
requirement: *id003
|
47
|
+
prerelease: false
|
48
|
+
type: :development
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
name: yard
|
51
|
+
version_requirements: &id004 !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ~>
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: 0.6.0
|
57
|
+
requirement: *id004
|
58
|
+
prerelease: false
|
59
|
+
type: :development
|
60
|
+
- !ruby/object:Gem::Dependency
|
61
|
+
name: jeweler
|
62
|
+
version_requirements: &id005 !ruby/object:Gem::Requirement
|
63
|
+
none: false
|
64
|
+
requirements:
|
65
|
+
- - ~>
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: 1.6.4
|
68
|
+
requirement: *id005
|
69
|
+
prerelease: false
|
70
|
+
type: :development
|
71
|
+
- !ruby/object:Gem::Dependency
|
72
|
+
name: rcov
|
73
|
+
version_requirements: &id006 !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: "0"
|
79
|
+
requirement: *id006
|
80
|
+
prerelease: false
|
81
|
+
type: :development
|
82
|
+
- !ruby/object:Gem::Dependency
|
83
|
+
name: smart_colored
|
84
|
+
version_requirements: &id007 !ruby/object:Gem::Requirement
|
85
|
+
none: false
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: "0"
|
90
|
+
requirement: *id007
|
91
|
+
prerelease: false
|
92
|
+
type: :development
|
93
|
+
description: "Library for Mapping Ruby Classes has Hibernate classes "
|
94
|
+
email: jonathan@devmask.net
|
95
|
+
executables: []
|
96
|
+
|
97
|
+
extensions: []
|
98
|
+
|
99
|
+
extra_rdoc_files:
|
100
|
+
- LICENSE.txt
|
101
|
+
- README.rdoc
|
102
|
+
files:
|
103
|
+
- .Rhistory
|
104
|
+
- .document
|
105
|
+
- Gemfile
|
106
|
+
- Gemfile.lock
|
107
|
+
- LICENSE.txt
|
108
|
+
- README.rdoc
|
109
|
+
- Rakefile
|
110
|
+
- VERSION
|
111
|
+
- lib/.DS_Store
|
112
|
+
- lib/native/.DS_Store
|
113
|
+
- lib/native/lib/.DS_Store
|
114
|
+
- lib/native/lib/antlr-2.7.6.jar
|
115
|
+
- lib/native/lib/c3p0-0.9.1.jar
|
116
|
+
- lib/native/lib/commons-collections-3.1.jar
|
117
|
+
- lib/native/lib/dom4j-1.6.1.jar
|
118
|
+
- lib/native/lib/hibernate-jpa-2.0-api-1.0.1.Final.jar
|
119
|
+
- lib/native/lib/hibernate3.jar
|
120
|
+
- lib/native/lib/javaee.jar
|
121
|
+
- lib/native/lib/javassist.jar
|
122
|
+
- lib/native/lib/javax.persistence.jar
|
123
|
+
- lib/native/lib/jta-1.1.jar
|
124
|
+
- lib/native/lib/mysql-connector-java-5.1.15-bin.jar
|
125
|
+
- lib/native/lib/slf4j-api-1.6.1.jar
|
126
|
+
- lib/native/lib/slf4j-simple-1.6.1.jar
|
127
|
+
- lib/native/src/net/devmask/rubernate/ClassBuilder.java
|
128
|
+
- lib/rubernate.rb
|
129
|
+
- lib/rubernate/bytecode.rb
|
130
|
+
- lib/rubernate/class_parser.rb
|
131
|
+
- lib/rubernate/connection.rb
|
132
|
+
- lib/rubernate/entity.rb
|
133
|
+
- lib/rubernate/init.rb
|
134
|
+
- lib/rubernate/relations.rb
|
135
|
+
- out/production/Rubernate/net/devmask/rubernate/ClassBuilder.class
|
136
|
+
- rubernate.gemspec
|
137
|
+
- test/helper.rb
|
138
|
+
- test/test_rubernate.rb
|
139
|
+
has_rdoc: true
|
140
|
+
homepage: http://github.com/netmask/rubernate
|
141
|
+
licenses:
|
142
|
+
- MIT
|
143
|
+
post_install_message:
|
144
|
+
rdoc_options: []
|
145
|
+
|
146
|
+
require_paths:
|
147
|
+
- lib
|
148
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
149
|
+
none: false
|
150
|
+
requirements:
|
151
|
+
- - ">="
|
152
|
+
- !ruby/object:Gem::Version
|
153
|
+
hash: 2
|
154
|
+
segments:
|
155
|
+
- 0
|
156
|
+
version: "0"
|
157
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
158
|
+
none: false
|
159
|
+
requirements:
|
160
|
+
- - ">="
|
161
|
+
- !ruby/object:Gem::Version
|
162
|
+
version: "0"
|
163
|
+
requirements: []
|
164
|
+
|
165
|
+
rubyforge_project:
|
166
|
+
rubygems_version: 1.5.1
|
167
|
+
signing_key:
|
168
|
+
specification_version: 3
|
169
|
+
summary: Hibernate for Ruby
|
170
|
+
test_files: []
|
171
|
+
|