Skip to content

Commit

Permalink
refactoring of all java hooks conversion and adding first part of com…
Browse files Browse the repository at this point in the history
…posite key support
  • Loading branch information
douglasrodrigo committed Nov 15, 2011
1 parent 3246422 commit 6eb24db
Show file tree
Hide file tree
Showing 10 changed files with 271 additions and 211 deletions.
12 changes: 0 additions & 12 deletions Mavenfile
Expand Up @@ -24,18 +24,6 @@ packaging 'java-gem'

build.final_name '${project.artifactId}_ext'

profile(:transient) do |t|
t.plugin(:rspec).configuration[:specSourceDirectory] = 'spec/transient'
end

profile(:adapter) do |t|
t.plugin(:rspec).configuration[:specSourceDirectory] = 'spec/abstract_adapter'
end

profile(:dm) do |t|
t.plugin(:rspec).configuration[:specSourceDirectory] = 'spec/dm_core'
end

# copy the pom to pom.xml so java IDEs can use it
execute_in_phase(:initialize) do
require 'fileutils'
Expand Down
1 change: 1 addition & 0 deletions lib/dm-hibernate-adapter.rb
Expand Up @@ -47,6 +47,7 @@
require 'dm-hibernate-adapter/hibernate/property_shim'
require 'dm-hibernate-adapter/hibernate/dialects'
require 'dm-hibernate-adapter/hibernate/transaction'
require 'dm-hibernate-adapter/hibernate/dynamic_java'
require 'dm-hibernate-adapter/hibernate/model'
require 'dm-hibernate-adapter/data_mapper/adapters/hibernate_adapter'
require 'dm-hibernate-adapter/data_mapper/dm-core'
Expand Down
15 changes: 15 additions & 0 deletions lib/dm-hibernate-adapter/data_mapper/dm-core.rb
@@ -1,3 +1,18 @@
# -*- coding: utf-8 -*-
# Copyright 2011 Douglas Ferreira, Kristian Meier, Piotr Gęga

# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at

# http://www.apache.org/licenses/LICENSE-2.0

# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

module DataMapper
def self.finalize
Model.descendants.each do |model|
Expand Down
59 changes: 59 additions & 0 deletions lib/dm-hibernate-adapter/hibernate/dynamic_java.rb
@@ -0,0 +1,59 @@
# -*- coding: utf-8 -*-
# Copyright 2011 Douglas Ferreira, Kristian Meier, Piotr Gęga

# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at

# http://www.apache.org/licenses/LICENSE-2.0

# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

module Hibernate::DynamicJava

def make_java_class(annotations = {})
add_class_annotation annotations if !annotations.empty?

reload = Hibernate.allow_reload
become_java!(reload)

if reload
unless java.lang.Thread.currentThread.context_class_loader.is_a? JRubyClassLoader
cl = java.lang.Thread.currentThread.context_class_loader
if cl.is_a? org.jruby.util.JRubyClassLoader
java.lang.Thread.currentThread.context_class_loader = JRubyClassLoader.new(cl)
else
java.lang.Thread.currentThread.context_class_loader = 'TODO'
end
end

java.lang.Thread.currentThread.context_class_loader.register(self.java_class)
end
self
end

def add_get_accessor(name, target_type, annotations = {}, &blk)
get_name = "get#{name.to_s.capitalize}"
define_method(get_name.to_sym, &blk)
mapped_type = to_java_type(target_type).java_class
add_method_signature get_name, [mapped_type]
add_method_annotation get_name, annotations if !annotations.empty?
end

def add_set_accessor(name, target_type, annotations = {}, &blk)
set_name = "set#{name.to_s.capitalize}"
define_method(set_name.to_sym, &blk)
mapped_type = to_java_type(target_type).java_class
add_method_signature set_name, [JVoid, mapped_type]
add_method_annotation set_name, annotations if !annotations.empty?
end

def to_java_type(target_type)
target_type = target_type.primitive if target_type.respond_to?(:primitive)
TYPES[target_type] || target_type
end
end

0 comments on commit 6eb24db

Please sign in to comment.