Permalink
Browse files

Merge branch 'java-extension'

Conflicts:
	Jarfile
	spec/spec_helper.rb
  • Loading branch information...
2 parents 01a81d4 + 7ee4691 commit 9c1b0773813ff9e859d34762067459e996ff9fa4 @yokolet yokolet committed Apr 3, 2013
Showing with 1,530 additions and 394 deletions.
  1. +1 −1 .travis.yml
  2. +8 −1 Jarfile
  3. +42 −65 Jarfile.lock
  4. +17 −0 Rakefile
  5. +1 −0 datomic_version.cnf
  6. +12 −9 diametric.gemspec
  7. +87 −0 ext/diametric/DiametricConnection.java
  8. +54 −0 ext/diametric/DiametricDatabase.java
  9. +74 −0 ext/diametric/DiametricEntity.java
  10. +51 −0 ext/diametric/DiametricListenableFuture.java
  11. +66 −0 ext/diametric/DiametricObject.java
  12. +303 −0 ext/diametric/DiametricPeer.java
  13. +84 −0 ext/diametric/DiametricService.java
  14. +46 −0 ext/diametric/DiametricUUID.java
  15. +63 −0 ext/diametric/DiametricUtils.java
  16. +18 −0 lib/diametric.rb
  17. +58 −4 lib/diametric/entity.rb
  18. +0 −1 lib/diametric/persistence.rb
  19. +5 −1 lib/diametric/persistence/common.rb
  20. +25 −94 lib/diametric/persistence/peer.rb
  21. +37 −0 lib/diametric/query.rb
  22. +125 −0 lib/diametric/rest_service.rb
  23. +1 −1 lib/diametric/version.rb
  24. BIN lib/diametric_service.jar
  25. +0 −63 lib/jrclj.rb
  26. +0 −28 script/ci
  27. +30 −20 script/datomic-rest
  28. +9 −17 script/vendor-datomic-free
  29. +1 −0 spec/diametric/entity_spec.rb
  30. +133 −0 spec/diametric/peer_api_spec.rb
  31. +9 −22 spec/diametric/persistence/peer_spec.rb
  32. +12 −19 spec/diametric/persistence/rest_spec.rb
  33. +56 −0 spec/diametric/rest_service_spec.rb
  34. +4 −2 spec/integration_spec.rb
  35. +1 −0 spec/peer_integration_spec.rb
  36. +22 −44 spec/spec_helper.rb
  37. +66 −0 spec/support/entities.rb
  38. +2 −0 spec/support/gen_entity_class.rb
  39. +6 −2 spec/support/persistence_examples.rb
  40. +1 −0 spec/test_version_file.cnf
View
@@ -1,7 +1,7 @@
language: ruby
#bundler_args: --without development
before_script: rake prepare
-script: ./script/ci
rvm:
- 1.9.3
- jruby-19mode
+script: INTEGRATION=true bundle exec rspec spec
View
@@ -1,6 +1,13 @@
repository 'http://clojars.org/repo/'
repository 'https://repository.jboss.org/nexus/content/groups/public/'
+local_repo File.join(File.dirname(__FILE__), "repository")
+
+datomic_name = File.read(File.join(File.dirname(__FILE__), "datomic_version.cnf"))
+version = /(\d|\.)+/.match(datomic_name)[0]
+datomic_name.slice!(version)
+artifactId = datomic_name.chop
+
group :default, :runtime do
- jar "com.datomic:datomic-free:0.8.3848"
+ jar "com.datomic:#{artifactId}:#{version}"
end
View
@@ -1,134 +1,111 @@
---
-version: 0.7.2
+version: 0.7.3
+local_repository: "/Users/yoko/Projects/diametric/spec/../repository"
groups:
default:
dependencies:
- com.amazonaws:aws-java-sdk:jar:1.3.0
- - com.datomic:datomic-free:jar:0.8.3664
+ - com.datomic:datomic-free:jar:0.8.3848
- com.google.code.findbugs:jsr305:jar:1.3.9
- com.google.guava:guava:jar:12.0.1
- com.h2database:h2:jar:1.3.165
- com.jamesmurty.utils:java-xmlbuilder:jar:0.4
- commons-codec:commons-codec:jar:1.3
- commons-httpclient:commons-httpclient:jar:3.1
+ - io.netty:netty:jar:3.6.0.Final
- net.java.dev.jets3t:jets3t:jar:0.8.1
- - org.apache.httpcomponents:httpclient:jar:4.2-alpha1
- - org.apache.httpcomponents:httpcore:jar:4.2-alpha2
- org.apache.lucene:lucene-core:jar:3.3.0
- org.apache.tomcat:tomcat-jdbc:jar:7.0.27
- org.apache.tomcat:tomcat-juli:jar:7.0.27
- org.clojure:clojure:jar:1.4.0
- - org.clojure:data.json:jar:0.1.2
- org.clojure:tools.cli:jar:0.2.2
- - org.codehaus.jackson:jackson-core-asl:jar:1.8.0
- org.codehaus.janino:commons-compiler-jdk:jar:2.6.1
- org.codehaus.janino:commons-compiler:jar:2.6.1
- org.fressian:fressian:jar:0.6.3
- - org.hornetq:hornetq-core:jar:2.2.2.Final
- - org.jboss.netty:netty:jar:3.2.4.Final
+ - org.hornetq:hornetq-core:jar:2.2.21.Final
- org.slf4j:jcl-over-slf4j:jar:1.6.4
- org.slf4j:jul-to-slf4j:jar:1.6.4
- org.slf4j:log4j-over-slf4j:jar:1.6.4
- org.slf4j:slf4j-api:jar:1.6.4
- org.slf4j:slf4j-nop:jar:1.6.4
- - postgresql:postgresql:jar:9.1-901.jdbc4
- - spy:spymemcached:jar:2.8.1
artifacts:
- - jar:com.datomic:datomic-free:jar:0.8.3664:
+ - jar:com.datomic:datomic-free:jar:0.8.3848:
transitive:
- org.clojure:data.json:jar:0.1.2: {}
- net.java.dev.jets3t:jets3t:jar:0.8.1:
- commons-httpclient:commons-httpclient:jar:3.1: {}
- com.jamesmurty.utils:java-xmlbuilder:jar:0.4: {}
- org.jboss.netty:netty:jar:3.2.4.Final: {}
- com.h2database:h2:jar:1.3.165: {}
- org.slf4j:slf4j-nop:jar:1.6.4: {}
- org.hornetq:hornetq-core:jar:2.2.2.Final: {}
- postgresql:postgresql:jar:9.1-901.jdbc4: {}
- org.fressian:fressian:jar:0.6.3: {}
- org.apache.httpcomponents:httpclient:jar:4.2-alpha1:
- org.apache.httpcomponents:httpcore:jar:4.2-alpha2: {}
+ org.slf4j:jul-to-slf4j:jar:1.6.4:
+ org.slf4j:slf4j-api:jar:1.6.4: {}
+ org.hornetq:hornetq-core:jar:2.2.21.Final: {}
org.clojure:clojure:jar:1.4.0: {}
- org.codehaus.janino:commons-compiler-jdk:jar:2.6.1:
- org.codehaus.janino:commons-compiler:jar:2.6.1: {}
- org.apache.tomcat:tomcat-jdbc:jar:7.0.27:
- org.apache.tomcat:tomcat-juli:jar:7.0.27: {}
- spy:spymemcached:jar:2.8.1: {}
- org.slf4j:log4j-over-slf4j:jar:1.6.4: {}
- org.codehaus.jackson:jackson-core-asl:jar:1.8.0: {}
+ org.slf4j:jcl-over-slf4j:jar:1.6.4: {}
+ io.netty:netty:jar:3.6.0.Final: {}
com.amazonaws:aws-java-sdk:jar:1.3.0:
commons-codec:commons-codec:jar:1.3: {}
+ org.slf4j:log4j-over-slf4j:jar:1.6.4: {}
+ org.codehaus.janino:commons-compiler-jdk:jar:2.6.1:
+ org.codehaus.janino:commons-compiler:jar:2.6.1: {}
com.google.guava:guava:jar:12.0.1:
com.google.code.findbugs:jsr305:jar:1.3.9: {}
+ org.fressian:fressian:jar:0.6.3: {}
org.clojure:tools.cli:jar:0.2.2: {}
- org.slf4j:jul-to-slf4j:jar:1.6.4:
- org.slf4j:slf4j-api:jar:1.6.4: {}
- org.slf4j:jcl-over-slf4j:jar:1.6.4: {}
+ com.h2database:h2:jar:1.3.165: {}
org.apache.lucene:lucene-core:jar:3.3.0: {}
+ org.slf4j:slf4j-nop:jar:1.6.4: {}
+ org.apache.tomcat:tomcat-jdbc:jar:7.0.27:
+ org.apache.tomcat:tomcat-juli:jar:7.0.27: {}
+ net.java.dev.jets3t:jets3t:jar:0.8.1:
+ com.jamesmurty.utils:java-xmlbuilder:jar:0.4: {}
+ commons-httpclient:commons-httpclient:jar:3.1: {}
runtime:
dependencies:
- com.amazonaws:aws-java-sdk:jar:1.3.0
- - com.datomic:datomic-free:jar:0.8.3664
+ - com.datomic:datomic-free:jar:0.8.3848
- com.google.code.findbugs:jsr305:jar:1.3.9
- com.google.guava:guava:jar:12.0.1
- com.h2database:h2:jar:1.3.165
- com.jamesmurty.utils:java-xmlbuilder:jar:0.4
- commons-codec:commons-codec:jar:1.3
- commons-httpclient:commons-httpclient:jar:3.1
+ - io.netty:netty:jar:3.6.0.Final
- net.java.dev.jets3t:jets3t:jar:0.8.1
- - org.apache.httpcomponents:httpclient:jar:4.2-alpha1
- - org.apache.httpcomponents:httpcore:jar:4.2-alpha2
- org.apache.lucene:lucene-core:jar:3.3.0
- org.apache.tomcat:tomcat-jdbc:jar:7.0.27
- org.apache.tomcat:tomcat-juli:jar:7.0.27
- org.clojure:clojure:jar:1.4.0
- - org.clojure:data.json:jar:0.1.2
- org.clojure:tools.cli:jar:0.2.2
- - org.codehaus.jackson:jackson-core-asl:jar:1.8.0
- org.codehaus.janino:commons-compiler-jdk:jar:2.6.1
- org.codehaus.janino:commons-compiler:jar:2.6.1
- org.fressian:fressian:jar:0.6.3
- - org.hornetq:hornetq-core:jar:2.2.2.Final
- - org.jboss.netty:netty:jar:3.2.4.Final
+ - org.hornetq:hornetq-core:jar:2.2.21.Final
- org.slf4j:jcl-over-slf4j:jar:1.6.4
- org.slf4j:jul-to-slf4j:jar:1.6.4
- org.slf4j:log4j-over-slf4j:jar:1.6.4
- org.slf4j:slf4j-api:jar:1.6.4
- org.slf4j:slf4j-nop:jar:1.6.4
- - postgresql:postgresql:jar:9.1-901.jdbc4
- - spy:spymemcached:jar:2.8.1
artifacts:
- - jar:com.datomic:datomic-free:jar:0.8.3664:
+ - jar:com.datomic:datomic-free:jar:0.8.3848:
transitive:
- org.clojure:data.json:jar:0.1.2: {}
- net.java.dev.jets3t:jets3t:jar:0.8.1:
- commons-httpclient:commons-httpclient:jar:3.1: {}
- com.jamesmurty.utils:java-xmlbuilder:jar:0.4: {}
- org.jboss.netty:netty:jar:3.2.4.Final: {}
- com.h2database:h2:jar:1.3.165: {}
- org.slf4j:slf4j-nop:jar:1.6.4: {}
- org.hornetq:hornetq-core:jar:2.2.2.Final: {}
- postgresql:postgresql:jar:9.1-901.jdbc4: {}
- org.fressian:fressian:jar:0.6.3: {}
- org.apache.httpcomponents:httpclient:jar:4.2-alpha1:
- org.apache.httpcomponents:httpcore:jar:4.2-alpha2: {}
+ org.slf4j:jul-to-slf4j:jar:1.6.4:
+ org.slf4j:slf4j-api:jar:1.6.4: {}
+ org.hornetq:hornetq-core:jar:2.2.21.Final: {}
org.clojure:clojure:jar:1.4.0: {}
- org.codehaus.janino:commons-compiler-jdk:jar:2.6.1:
- org.codehaus.janino:commons-compiler:jar:2.6.1: {}
- org.apache.tomcat:tomcat-jdbc:jar:7.0.27:
- org.apache.tomcat:tomcat-juli:jar:7.0.27: {}
- spy:spymemcached:jar:2.8.1: {}
- org.slf4j:log4j-over-slf4j:jar:1.6.4: {}
- org.codehaus.jackson:jackson-core-asl:jar:1.8.0: {}
+ org.slf4j:jcl-over-slf4j:jar:1.6.4: {}
+ io.netty:netty:jar:3.6.0.Final: {}
com.amazonaws:aws-java-sdk:jar:1.3.0:
commons-codec:commons-codec:jar:1.3: {}
+ org.slf4j:log4j-over-slf4j:jar:1.6.4: {}
+ org.codehaus.janino:commons-compiler-jdk:jar:2.6.1:
+ org.codehaus.janino:commons-compiler:jar:2.6.1: {}
com.google.guava:guava:jar:12.0.1:
com.google.code.findbugs:jsr305:jar:1.3.9: {}
+ org.fressian:fressian:jar:0.6.3: {}
org.clojure:tools.cli:jar:0.2.2: {}
- org.slf4j:jul-to-slf4j:jar:1.6.4:
- org.slf4j:slf4j-api:jar:1.6.4: {}
- org.slf4j:jcl-over-slf4j:jar:1.6.4: {}
+ com.h2database:h2:jar:1.3.165: {}
org.apache.lucene:lucene-core:jar:3.3.0: {}
+ org.slf4j:slf4j-nop:jar:1.6.4: {}
+ org.apache.tomcat:tomcat-jdbc:jar:7.0.27:
+ org.apache.tomcat:tomcat-juli:jar:7.0.27: {}
+ net.java.dev.jets3t:jets3t:jar:0.8.1:
+ com.jamesmurty.utils:java-xmlbuilder:jar:0.4: {}
+ commons-httpclient:commons-httpclient:jar:3.1: {}
remote_repositories:
- http://clojars.org/repo/
- https://repository.jboss.org/nexus/content/groups/public/
View
@@ -1,4 +1,5 @@
begin
+ require 'rake'
require "bundler/gem_tasks"
require 'rspec/core/rake_task'
rescue LoadError
@@ -31,3 +32,19 @@ desc "Run all RSpec tests"
require 'rspec'
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:spec)
+
+
+# setting for rake compiler
+if defined?(RUBY_ENGINE) && RUBY_ENGINE == "jruby"
+ require 'lock_jar'
+ LockJar.lock
+ locked_jars = LockJar.load
+
+ require 'rake/javaextensiontask'
+ Rake::JavaExtensionTask.new('diametric') do |ext|
+ jruby_home = ENV['MY_RUBY_HOME'] # this is available of rvm
+ jars = ["#{jruby_home}/lib/jruby.jar"] + FileList['lib/*.jar'] + locked_jars
+ ext.classpath = jars.map {|x| File.expand_path x}.join ':'
+ ext.name = 'diametric_service'
+ end
+end
View
@@ -0,0 +1 @@
+datomic-free-0.8.3861
View
@@ -16,25 +16,28 @@ as entities into a Datomic database.
EOF
gem.homepage = "https://github.com/relevance/diametric"
- gem.files = %w(Gemfile Jarfile Jarfile.lock LICENSE.txt README.md Rakefile diametric.gemspec) + Dir.glob('lib/**/*')
+ gem.files = %w(Gemfile Jarfile Jarfile.lock LICENSE.txt README.md Rakefile datomic_version.cnf diametric.gemspec) + Dir.glob('lib/**/*') + Dir.glob('ext/**/*') + Dir.glob('spec/**/*')
gem.executables = []
gem.test_files = Dir.glob("spec/**/*.rb")
gem.require_paths = ["lib"]
+ gem.executables = ["datomic-rest", "download-datomic"]
gem.add_dependency 'edn', '~> 1.0'
gem.add_dependency 'activesupport', '>= 3.0.0'
gem.add_dependency 'activemodel', '>= 3.0.0'
gem.add_dependency 'datomic-client', '~> 0.4.1'
- gem.add_dependency 'rspec', '~> 2.12.0'
- gem.add_dependency 'lock_jar', '= 0.7.2' if defined?(RUBY_ENGINE) && RUBY_ENGINE == "jruby"
- gem.add_dependency 'jruby-openssl', '~> 0.8.2' if defined?(RUBY_ENGINE) && RUBY_ENGINE == "jruby"
+ gem.add_dependency 'rubyzip', '~> 0.9.9'
+ gem.add_dependency 'rspec', '~> 2.13.0'
+ gem.add_dependency 'lock_jar', '= 0.7.3' if defined?(RUBY_ENGINE) && RUBY_ENGINE == "jruby"
+ gem.add_dependency 'jruby-openssl', '~> 0.8.7' if defined?(RUBY_ENGINE) && RUBY_ENGINE == "jruby"
+ gem.add_dependency 'rake-compiler', '~> 0.8.2' if defined?(RUBY_ENGINE) && RUBY_ENGINE == "jruby"
gem.add_development_dependency 'pry', '~> 0.9.12'
- gem.add_development_dependency 'guard', '~> 1.6.2'
- gem.add_development_dependency 'guard-rspec', '~> 2.4.0'
- gem.add_development_dependency 'rb-inotify', '~> 0.9.0'
- gem.add_development_dependency 'rb-fsevent', '~> 0.9.3'
- gem.add_development_dependency 'rb-fchange', '~> 0.0.6'
+ gem.add_development_dependency 'guard', '~> 1.6.2' if defined?(RUBY_ENGINE) && RUBY_ENGINE == "ruby"
+ gem.add_development_dependency 'guard-rspec', '~> 2.4.0' if defined?(RUBY_ENGINE) && RUBY_ENGINE == "ruby"
+ gem.add_development_dependency 'rb-inotify', '~> 0.9.0' if defined?(RUBY_ENGINE) && RUBY_ENGINE == "ruby"
+ gem.add_development_dependency 'rb-fsevent', '~> 0.9.3' if defined?(RUBY_ENGINE) && RUBY_ENGINE == "ruby"
+ gem.add_development_dependency 'rb-fchange', '~> 0.0.6' if defined?(RUBY_ENGINE) && RUBY_ENGINE == "ruby"
gem.add_development_dependency 'yard', '~> 0.8.4.1' if defined?(RUBY_ENGINE) && RUBY_ENGINE == "ruby"
gem.add_development_dependency 'redcarpet', '~> 2.2.2' if defined?(RUBY_ENGINE) && RUBY_ENGINE == "ruby"
@@ -0,0 +1,87 @@
+package diametric;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.jruby.Ruby;
+import org.jruby.RubyArray;
+import org.jruby.RubyClass;
+import org.jruby.RubyHash;
+import org.jruby.RubyNil;
+import org.jruby.RubyObject;
+import org.jruby.anno.JRubyClass;
+import org.jruby.anno.JRubyMethod;
+import org.jruby.javasupport.JavaUtil;
+import org.jruby.runtime.ThreadContext;
+import org.jruby.runtime.builtin.IRubyObject;
+
+import datomic.Connection;
+import datomic.Database;
+import datomic.ListenableFuture;
+
+@JRubyClass(name = "Diametric::Persistence::Connection")
+public class DiametricConnection extends RubyObject {
+ private static final long serialVersionUID = 3806301567154638371L;
+ private Connection conn = null;
+
+ public DiametricConnection(Ruby runtime, RubyClass klazz) {
+ super(runtime, klazz);
+ }
+
+ void init(Connection conn) {
+ this.conn = conn;
+ }
+
+ Connection toJava() {
+ return conn;
+ }
+
+ @JRubyMethod
+ public IRubyObject to_java(ThreadContext context) {
+ return JavaUtil.convertJavaToUsableRubyObject(context.getRuntime(), conn);
+ }
+
+ @JRubyMethod
+ public IRubyObject db(ThreadContext context) {
+ Database database = conn.db();
+ RubyClass clazz = (RubyClass)context.getRuntime().getClassFromPath("Diametric::Persistence::Database");
+ DiametricDatabase diametric_database = (DiametricDatabase)clazz.allocate();
+ diametric_database.init(database);
+ return diametric_database;
+ }
+
+ @JRubyMethod
+ public IRubyObject transact(ThreadContext context, IRubyObject arg) {
+ if (!(arg instanceof RubyArray)) return context.getRuntime().getNil();
+ RubyArray ruby_tx_data = (RubyArray)arg;
+ List java_tx_data = new ArrayList();
+ for (int i=0; i<ruby_tx_data.getLength(); i++) {
+ IRubyObject element = (IRubyObject) ruby_tx_data.get(i);
+ if (!(element instanceof RubyHash)) continue;
+ RubyHash ruby_hash = (RubyHash)element;
+ Map keyvals = new HashMap();
+ while(true) {
+ IRubyObject pair = ruby_hash.shift(context);
+ if (pair instanceof RubyNil) break;
+ Object key = DiametricUtils.convertRubyToJava(context, ((RubyArray)pair).shift(context));
+ Object value = DiametricUtils.convertRubyToJava(context, ((RubyArray)pair).shift(context));
+ keyvals.put(key, value);
+ }
+ java_tx_data.add(Collections.unmodifiableMap(keyvals));
+ }
+ ListenableFuture<java.util.Map> future;
+ try {
+ future = conn.transact(java_tx_data);
+ RubyClass clazz = (RubyClass)context.getRuntime().getClassFromPath("Diametric::Persistence::ListenableFuture");
+ DiametricListenableFuture diametric_listenable = (DiametricListenableFuture)clazz.allocate();
+ diametric_listenable.init(future);
+ return diametric_listenable;
+ } catch (Exception e) {
+ context.getRuntime().newRuntimeError(e.getMessage());
+ }
+ return context.getRuntime().getNil();
+ }
+}
Oops, something went wrong.

0 comments on commit 9c1b077

Please sign in to comment.