Permalink
Browse files

refactoring of all java hooks conversion and adding first part of com…

…posite key support
  • Loading branch information...
1 parent 3246422 commit 6eb24dbb2ba703b3cf3522fea8bcc10ebf44b4a9 @douglasrodrigo douglasrodrigo committed Nov 15, 2011
View
@@ -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'
@@ -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'
@@ -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|
@@ -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
Oops, something went wrong.

0 comments on commit 6eb24db

Please sign in to comment.