diametric 0.0.4 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/Gemfile +21 -18
- data/Jarfile +15 -1
- data/README.md +22 -14
- data/Rakefile +17 -1
- data/bin/datomic-rest +33 -0
- data/bin/download-datomic +13 -0
- data/datomic_version.yml +4 -0
- data/diametric.gemspec +9 -6
- data/ext/diametric/DiametricCollection.java +147 -0
- data/ext/diametric/DiametricConnection.java +113 -0
- data/ext/diametric/DiametricDatabase.java +107 -0
- data/ext/diametric/DiametricEntity.java +90 -0
- data/ext/diametric/DiametricListenableFuture.java +47 -0
- data/ext/diametric/DiametricObject.java +66 -0
- data/ext/diametric/DiametricPeer.java +414 -0
- data/ext/diametric/DiametricService.java +102 -0
- data/ext/diametric/DiametricUUID.java +61 -0
- data/ext/diametric/DiametricUtils.java +183 -0
- data/lib/boolean_type.rb +3 -0
- data/lib/diametric.rb +24 -0
- data/lib/diametric/entity.rb +219 -14
- data/lib/diametric/generators/active_model.rb +2 -2
- data/lib/diametric/persistence.rb +0 -1
- data/lib/diametric/persistence/common.rb +28 -9
- data/lib/diametric/persistence/peer.rb +122 -87
- data/lib/diametric/persistence/rest.rb +4 -3
- data/lib/diametric/query.rb +94 -23
- data/lib/diametric/rest_service.rb +74 -0
- data/lib/diametric/service_base.rb +77 -0
- data/lib/diametric/transactor.rb +86 -0
- data/lib/diametric/version.rb +1 -1
- data/lib/diametric_service.jar +0 -0
- data/lib/value_enums.rb +8 -0
- data/spec/conf_helper.rb +55 -0
- data/spec/config/free-transactor-template.properties +73 -0
- data/spec/config/logback.xml +59 -0
- data/spec/data/seattle-data0.dtm +452 -0
- data/spec/data/seattle-data1.dtm +326 -0
- data/spec/developer_create_sample.rb +39 -0
- data/spec/developer_query_spec.rb +120 -0
- data/spec/diametric/config_spec.rb +1 -1
- data/spec/diametric/entity_spec.rb +263 -0
- data/spec/diametric/peer_api_spec.rb +147 -0
- data/spec/diametric/persistence/peer_many2many_spec.rb +76 -0
- data/spec/diametric/persistence/peer_spec.rb +13 -22
- data/spec/diametric/persistence/rest_spec.rb +12 -19
- data/spec/diametric/query_spec.rb +4 -5
- data/spec/diametric/rest_service_spec.rb +56 -0
- data/spec/diametric/transactor_spec.rb +68 -0
- data/spec/integration_spec.rb +5 -3
- data/spec/parent_child_sample.rb +42 -0
- data/spec/peer_integration_spec.rb +106 -22
- data/spec/peer_seattle_spec.rb +200 -0
- data/spec/rc2013_seattle_big.rb +82 -0
- data/spec/rc2013_seattle_small.rb +60 -0
- data/spec/rc2013_simple_sample.rb +72 -0
- data/spec/seattle_integration_spec.rb +106 -0
- data/spec/simple_validation_sample.rb +31 -0
- data/spec/spec_helper.rb +31 -45
- data/spec/support/entities.rb +157 -0
- data/spec/support/gen_entity_class.rb +2 -0
- data/spec/support/persistence_examples.rb +9 -5
- data/spec/test_version_file.yml +4 -0
- metadata +131 -75
- data/Jarfile.lock +0 -134
- data/lib/jrclj.rb +0 -63
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
N2Y1ODQ4NGMzNjA0ZjY3ODIzNDk2NjIwMGUxNDA4YjViYjM2ZmE5Mg==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
NTA1YWRhN2YwM2M0Y2RhOGJlN2NmMGNlMTZmY2E4NWQwZjE2OTc2Nw==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
YjA4N2I5ZWNkMWZiZTE4NDlkODRmMTYwMjM2ZGNlYjEzNzVlZTY5ZWMzYWM0
|
10
|
+
MjcyZWZjMGYyNWNjMzZjMTNiYTRmODI0ZGJiMjlhMDIyMmEyMWM0M2RiYjhl
|
11
|
+
MjA1NzdiYTdjMDExYmZhYmZlNzlkMWI4YjQ1NWEwODIxYzQzZDc=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
N2U0NzQ0NjM2YWRkMjU2NTM4ODM2Njc3NWY0NzVlOTVlMDMzYWVmNmI4MTI5
|
14
|
+
ZGUzNDFmZjQ3ZGFhNWZmMzIzMWJiNjNlMWI1MmUxNzJhZjgxOTAwODFkNTQ1
|
15
|
+
YzBiZTJlYTcxOTU2MmY5MTVkZWU1N2YzYWFmMTY1MDU3OWQwN2U=
|
data/Gemfile
CHANGED
@@ -1,25 +1,28 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
|
1
3
|
source 'https://rubygems.org'
|
2
4
|
|
3
|
-
|
4
|
-
|
5
|
+
gem 'edn', '~> 1.0.2'
|
6
|
+
gem 'activesupport', '~> 3.2.14'
|
7
|
+
gem 'activemodel', '~> 3.2.14'
|
8
|
+
gem 'datomic-client', '~> 0.4.1'
|
9
|
+
gem 'rubyzip', '~> 0.9.9'
|
5
10
|
|
6
|
-
|
7
|
-
gem '
|
8
|
-
gem '
|
9
|
-
gem 'pry'
|
11
|
+
gem 'lock_jar', '~> 0.7.5', :platform => :jruby
|
12
|
+
gem 'jruby-openssl', '~> 0.8.8', :platform => :jruby
|
13
|
+
gem 'uuid', '~> 2.3.7'
|
10
14
|
|
11
|
-
gem '
|
12
|
-
gem '
|
13
|
-
gem 'rb-inotify', :require => false
|
14
|
-
gem 'rb-fsevent', :require => false
|
15
|
-
gem 'rb-fchange', :require => false
|
15
|
+
gem 'rspec', '~> 2.14.1'
|
16
|
+
gem 'pry', '~> 0.9.12.2'
|
16
17
|
|
17
|
-
|
18
|
-
gem '
|
19
|
-
gem '
|
18
|
+
group :test, :development do
|
19
|
+
gem 'rake-compiler', '~> 0.9.1', :platform => :jruby
|
20
|
+
gem 'guard', '~> 1.8.2'
|
21
|
+
gem 'guard-rspec', '~> 3.0.2'
|
22
|
+
gem 'rb-inotify', :platform => :mri
|
23
|
+
gem 'rb-fsevent', :platform => :mri
|
24
|
+
gem 'rb-fchange', :platform => :mri
|
25
|
+
gem 'yard', :platform => :mri
|
26
|
+
gem 'redcarpet', :platform => :mri
|
20
27
|
end
|
21
28
|
|
22
|
-
platform :jruby do
|
23
|
-
gem 'jruby-openssl'
|
24
|
-
gem 'lock_jar'
|
25
|
-
end
|
data/Jarfile
CHANGED
@@ -1,6 +1,20 @@
|
|
1
1
|
repository 'http://clojars.org/repo/'
|
2
2
|
repository 'https://repository.jboss.org/nexus/content/groups/public/'
|
3
|
+
repository 'http://files.couchbase.com/maven2/'
|
4
|
+
|
5
|
+
datomic_names = File.read(File.join(File.dirname(__FILE__), "datomic_version.yml"))
|
6
|
+
require 'yaml'
|
7
|
+
datomic_versions = YAML.load(datomic_names)
|
8
|
+
|
9
|
+
if ENV['DIAMETRIC_ENV'] && (ENV['DIAMETRIC_ENV'] == "pro")
|
10
|
+
datomic_version = datomic_versions["pro"]
|
11
|
+
else
|
12
|
+
datomic_version = datomic_versions["free"]
|
13
|
+
end
|
14
|
+
version = /(\d|\.)+/.match(datomic_version)[0]
|
15
|
+
datomic_version.slice!(version)
|
16
|
+
artifactId = datomic_version.chop
|
3
17
|
|
4
18
|
group :default, :runtime do
|
5
|
-
jar "com.datomic
|
19
|
+
jar "com.datomic:#{artifactId}:#{version}"
|
6
20
|
end
|
data/README.md
CHANGED
@@ -20,6 +20,7 @@ Other than highlights below, there are documents on Wiki.
|
|
20
20
|
|
21
21
|
- [Getting Started](https://github.com/relevance/diametric/wiki/Getting-Started)
|
22
22
|
- [Rails Integration](https://github.com/relevance/diametric/wiki/Rails-Integration-%28Experimental%29)
|
23
|
+
- [Seattle Example](https://github.com/relevance/diametric/wiki/Seattle-Example)
|
23
24
|
|
24
25
|
|
25
26
|
## Entity API
|
@@ -46,11 +47,12 @@ class Person
|
|
46
47
|
attribute :email, String, :cardinality => :many
|
47
48
|
attribute :birthday, DateTime
|
48
49
|
attribute :iq, Integer
|
49
|
-
attribute :website, URI
|
50
50
|
end
|
51
51
|
|
52
|
+
# To see what schema data will be produced:
|
52
53
|
Person.schema
|
53
|
-
|
54
|
+
|
55
|
+
# The schema will be mapped to Datomic transaction data below:
|
54
56
|
# [{:db/id #db/id[:db.part/db]
|
55
57
|
# :db/ident :person/name
|
56
58
|
# :db/valueType :db.type/string
|
@@ -71,33 +73,38 @@ Person.schema
|
|
71
73
|
# :db/ident :person/iq
|
72
74
|
# :db/valueType :db.type/long
|
73
75
|
# :db/cardinality :db.cardinality/one
|
74
|
-
# :db.install/_attribute :db.part/db}
|
75
|
-
# {:db/id #db/id[:db.part/db]
|
76
|
-
# :db/ident :person/website
|
77
|
-
# :db/valueType :db.type/uri
|
78
|
-
# :db/cardinality :db.cardinality/one
|
79
76
|
# :db.install/_attribute :db.part/db}]
|
80
77
|
|
81
|
-
Person
|
82
|
-
|
78
|
+
# To check what attributes are in Person model:
|
79
|
+
Person.attributes.keys
|
80
|
+
# [:dbid, :name, :email, :birthday, :iq]
|
83
81
|
|
82
|
+
# To create an instance from a query result
|
84
83
|
person = Person.new(Hash[*(Person.attributes.zip(results_from_query).flatten)])
|
85
84
|
# or
|
86
85
|
person = Person.from_query(results_from_query)
|
87
86
|
|
87
|
+
# To update/set values of a model:
|
88
88
|
person.iq = 180
|
89
|
+
|
90
|
+
# Below will help to understand what transaction data will be produced:
|
89
91
|
person.tx_data(:iq)
|
90
|
-
|
92
|
+
|
93
|
+
# It will be mapped to the Datomic transaction data:
|
91
94
|
# [{:db/id person.dbid
|
92
95
|
# :person/iq 180}]
|
93
96
|
|
97
|
+
# To create new model instance:
|
94
98
|
person = Person.new(:name => "Peanut")
|
95
99
|
person.tx_data
|
96
|
-
# Datomic transaction:
|
100
|
+
# Datomic transaction data will be:
|
97
101
|
# [{:db/id #db/id[:db.part/user]
|
98
102
|
# :person/name "Peanut"}]
|
99
103
|
```
|
100
104
|
|
105
|
+
In addition to `attribute`, Diametric supports `enum` type. This is often used on Datomic.
|
106
|
+
For details, see [Seattle Example](https://github.com/relevance/diametric/wiki/Seattle-Example)
|
107
|
+
|
101
108
|
## Query API
|
102
109
|
|
103
110
|
The query API is used for generating Datomic queries, whether to send via an external client or via the persistence API. The two methods used to generate a query are `.where` and `.filter`, both of which are chainable.
|
@@ -141,8 +148,9 @@ query.data
|
|
141
148
|
|
142
149
|
## Persistence API
|
143
150
|
|
144
|
-
The persistence API comes in two flavors: REST- and
|
145
|
-
|
151
|
+
The persistence API comes in two flavors: REST- and Peer-based.
|
152
|
+
Although REST-bases API supports CRUD operations like a legacy RDBMS,
|
153
|
+
it is a subset of Peer-based API.
|
146
154
|
|
147
155
|
The suitable persistent module will be selected based on URI to connect datomic.
|
148
156
|
You don't need to care which module should be included.
|
@@ -151,7 +159,7 @@ However, if you like to inlcude REST or Peer module explicitely, you can write i
|
|
151
159
|
|
152
160
|
### Peer
|
153
161
|
|
154
|
-
With Peer connection, you can create objects that know how to store themselves to Datomic through a Datomic
|
162
|
+
With Peer connection, you can create objects that know how to store themselves to Datomic through a Datomic Peer.
|
155
163
|
|
156
164
|
Peer connection as well as "require `diametric/persistence/peer`" are only available on JRuby.
|
157
165
|
When you install the `diametric` gem with JRuby, all `.jar` files needed to run Datomic will be downloaded.
|
data/Rakefile
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
begin
|
2
|
-
require
|
2
|
+
require 'rake'
|
3
3
|
require 'rspec/core/rake_task'
|
4
4
|
rescue LoadError
|
5
5
|
end
|
@@ -31,3 +31,19 @@ desc "Run all RSpec tests"
|
|
31
31
|
require 'rspec'
|
32
32
|
require 'rspec/core/rake_task'
|
33
33
|
RSpec::Core::RakeTask.new(:spec)
|
34
|
+
|
35
|
+
|
36
|
+
# setting for rake compiler
|
37
|
+
if defined?(RUBY_ENGINE) && RUBY_ENGINE == "jruby"
|
38
|
+
require 'lock_jar'
|
39
|
+
LockJar.lock
|
40
|
+
locked_jars = LockJar.load
|
41
|
+
|
42
|
+
require 'rake/javaextensiontask'
|
43
|
+
Rake::JavaExtensionTask.new('diametric') do |ext|
|
44
|
+
jruby_home = ENV['MY_RUBY_HOME'] # this is available of rvm
|
45
|
+
jars = ["#{jruby_home}/lib/jruby.jar"] + FileList['lib/*.jar'] + locked_jars
|
46
|
+
ext.classpath = jars.map {|x| File.expand_path x}.join ':'
|
47
|
+
ext.name = 'diametric_service'
|
48
|
+
end
|
49
|
+
end
|
data/bin/datomic-rest
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'optparse'
|
3
|
+
|
4
|
+
options = {}
|
5
|
+
|
6
|
+
opts = OptionParser.new do |opts|
|
7
|
+
opts.define_head "Usage: datomic-rest -p port -a db_alias -u uri"
|
8
|
+
opts.separator ""
|
9
|
+
opts.separator "Example:"
|
10
|
+
opts.separator " datomc-rest -p 9000 -a free -u datomic:mem://"
|
11
|
+
|
12
|
+
opts.on("-p", "--port [port]", Integer, "Port number") do |v|
|
13
|
+
options[:port] = v
|
14
|
+
end
|
15
|
+
|
16
|
+
opts.on("-a", "--alias [alias]", String, "Alias name") do |v|
|
17
|
+
options[:db_alias] = v
|
18
|
+
end
|
19
|
+
|
20
|
+
opts.on("-u", "--uri [uri]", String, "URI") do |v|
|
21
|
+
options[:uri] = v
|
22
|
+
end
|
23
|
+
end
|
24
|
+
opts.parse!
|
25
|
+
|
26
|
+
DATOMIC_NAME = File.read(File.join(File.dirname(__FILE__), "..", "datomic_version.cnf"))
|
27
|
+
|
28
|
+
require 'diametric/rest_service'
|
29
|
+
|
30
|
+
service = Diametric::RestService.new
|
31
|
+
PID = service.start(options)
|
32
|
+
|
33
|
+
puts "Datomic REST service is running (PID = #{PID})" unless PID.nil?
|
@@ -0,0 +1,13 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
DATOMIC_NAME = File.read(File.join(File.dirname(__FILE__), "..", "datomic_version.cnf"))
|
4
|
+
|
5
|
+
require 'diametric/rest_service'
|
6
|
+
|
7
|
+
if Diametric::RestService.downloaded?
|
8
|
+
puts "Datomic #{DATOMIC_NAME} is already present in vendor/datomic"
|
9
|
+
else
|
10
|
+
puts "Now, downloading..."
|
11
|
+
Diametric::RestService.download
|
12
|
+
puts "Done. #{DATOMIC_NAME} has been downloaded in vendor/datomic"
|
13
|
+
end
|
data/datomic_version.yml
ADDED
data/diametric.gemspec
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# -*- ruby -*-
|
1
2
|
# -*- encoding: utf-8 -*-
|
2
3
|
lib = File.expand_path('../lib', __FILE__)
|
3
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
@@ -16,17 +17,19 @@ as entities into a Datomic database.
|
|
16
17
|
EOF
|
17
18
|
gem.homepage = "https://github.com/relevance/diametric"
|
18
19
|
|
19
|
-
gem.files = %w(Gemfile Jarfile
|
20
|
+
gem.files = %w(Gemfile Jarfile LICENSE.txt README.md Rakefile datomic_version.yml diametric.gemspec) + Dir.glob('lib/**/*') + Dir.glob('ext/**/*') + Dir.glob('spec/**/*')
|
20
21
|
gem.executables = []
|
21
22
|
gem.test_files = Dir.glob("spec/**/*.rb")
|
22
23
|
gem.require_paths = ["lib"]
|
24
|
+
gem.executables = ["datomic-rest", "download-datomic"]
|
23
25
|
|
24
|
-
gem.add_dependency 'edn', '~> 1.0'
|
25
|
-
gem.add_dependency 'activesupport', '
|
26
|
-
gem.add_dependency 'activemodel', '
|
26
|
+
gem.add_dependency 'edn', '~> 1.0.2'
|
27
|
+
gem.add_dependency 'activesupport', '~> 3.2.14'
|
28
|
+
gem.add_dependency 'activemodel', '~> 3.2.14'
|
27
29
|
gem.add_dependency 'datomic-client', '~> 0.4.1'
|
28
|
-
gem.add_dependency '
|
29
|
-
gem.add_dependency '
|
30
|
+
gem.add_dependency 'rubyzip', '~> 0.9.9'
|
31
|
+
gem.add_dependency 'uuid', '~> 2.3.7'
|
32
|
+
gem.add_dependency 'rspec', '~> 2.14.1'
|
30
33
|
|
31
34
|
gem.extensions = ['Rakefile']
|
32
35
|
end
|
@@ -0,0 +1,147 @@
|
|
1
|
+
package diametric;
|
2
|
+
|
3
|
+
import java.util.Collection;
|
4
|
+
import java.util.Iterator;
|
5
|
+
|
6
|
+
import org.jruby.Ruby;
|
7
|
+
import org.jruby.RubyClass;
|
8
|
+
import org.jruby.RubyObject;
|
9
|
+
import org.jruby.anno.JRubyClass;
|
10
|
+
import org.jruby.anno.JRubyMethod;
|
11
|
+
import org.jruby.javasupport.JavaUtil;
|
12
|
+
import org.jruby.runtime.Block;
|
13
|
+
import org.jruby.runtime.ThreadContext;
|
14
|
+
import org.jruby.runtime.builtin.IRubyObject;
|
15
|
+
|
16
|
+
@JRubyClass(name = "Diametric::Persistence::Collection")
|
17
|
+
public class DiametricCollection extends RubyObject {
|
18
|
+
// should be a Ruby's Enumerable
|
19
|
+
private static final long serialVersionUID = 7656855654760249694L;
|
20
|
+
private Collection query_result = null;
|
21
|
+
|
22
|
+
public DiametricCollection(Ruby runtime, RubyClass klazz) {
|
23
|
+
super(runtime, klazz);
|
24
|
+
}
|
25
|
+
|
26
|
+
void init(Object result) {
|
27
|
+
if (result instanceof Collection) {
|
28
|
+
this.query_result = (Collection)result;
|
29
|
+
} else {
|
30
|
+
throw new RuntimeException("Wrong type of query result");
|
31
|
+
}
|
32
|
+
}
|
33
|
+
|
34
|
+
Object toJava() {
|
35
|
+
return query_result;
|
36
|
+
}
|
37
|
+
|
38
|
+
@JRubyMethod
|
39
|
+
public IRubyObject to_java(ThreadContext context) {
|
40
|
+
return JavaUtil.convertJavaToUsableRubyObject(context.getRuntime(), query_result);
|
41
|
+
}
|
42
|
+
|
43
|
+
@JRubyMethod(name="==", required=1)
|
44
|
+
public IRubyObject op_equal(ThreadContext context, IRubyObject arg) {
|
45
|
+
Ruby runtime = context.getRuntime();
|
46
|
+
if (arg instanceof DiametricCollection) {
|
47
|
+
DiametricCollection other = (DiametricCollection)arg;
|
48
|
+
if (query_result.toString().equals(other.toJava().toString())) {
|
49
|
+
return runtime.getTrue();
|
50
|
+
} else {
|
51
|
+
return runtime.getFalse();
|
52
|
+
}
|
53
|
+
} else {
|
54
|
+
return runtime.getFalse();
|
55
|
+
}
|
56
|
+
}
|
57
|
+
|
58
|
+
@JRubyMethod
|
59
|
+
public IRubyObject to_s(ThreadContext context) {
|
60
|
+
return context.getRuntime().newString(query_result.toString());
|
61
|
+
}
|
62
|
+
|
63
|
+
@JRubyMethod(name = "all?")
|
64
|
+
public static IRubyObject all_p(ThreadContext context, IRubyObject self, final Block block) {
|
65
|
+
return context.getRuntime().getNil();
|
66
|
+
}
|
67
|
+
|
68
|
+
@JRubyMethod(name = "any?")
|
69
|
+
public static IRubyObject any_p(ThreadContext context, IRubyObject self, final Block block) {
|
70
|
+
return context.getRuntime().getNil();
|
71
|
+
}
|
72
|
+
|
73
|
+
@JRubyMethod
|
74
|
+
public static IRubyObject chunk(ThreadContext context, IRubyObject self, final Block block) {
|
75
|
+
return context.getRuntime().getNil();
|
76
|
+
}
|
77
|
+
|
78
|
+
@JRubyMethod
|
79
|
+
public static IRubyObject chunk(ThreadContext context, IRubyObject self, final IRubyObject initialState, final Block block) {
|
80
|
+
return context.getRuntime().getNil();
|
81
|
+
}
|
82
|
+
|
83
|
+
@JRubyMethod
|
84
|
+
public static IRubyObject collect(ThreadContext context, IRubyObject self, final Block block) {
|
85
|
+
return context.getRuntime().getNil();
|
86
|
+
}
|
87
|
+
|
88
|
+
@JRubyMethod
|
89
|
+
public static IRubyObject collect_concat(ThreadContext context, IRubyObject self, final Block block) {
|
90
|
+
return context.getRuntime().getNil();
|
91
|
+
}
|
92
|
+
|
93
|
+
@JRubyMethod
|
94
|
+
public static IRubyObject count(ThreadContext context, IRubyObject self, final Block block) {
|
95
|
+
return context.getRuntime().getNil();
|
96
|
+
}
|
97
|
+
|
98
|
+
@JRubyMethod
|
99
|
+
public static IRubyObject count(ThreadContext context, IRubyObject self, final IRubyObject methodArg, final Block block) {
|
100
|
+
return context.getRuntime().getNil();
|
101
|
+
}
|
102
|
+
|
103
|
+
@JRubyMethod
|
104
|
+
public static IRubyObject cycle(ThreadContext context, IRubyObject self, final Block block) {
|
105
|
+
return context.getRuntime().getNil();
|
106
|
+
}
|
107
|
+
|
108
|
+
@JRubyMethod
|
109
|
+
public static IRubyObject cycle(ThreadContext context, IRubyObject self, IRubyObject arg, final Block block) {
|
110
|
+
return context.getRuntime().getNil();
|
111
|
+
}
|
112
|
+
|
113
|
+
@JRubyMethod
|
114
|
+
public static IRubyObject detect(ThreadContext context, IRubyObject self, final Block block) {
|
115
|
+
return context.getRuntime().getNil();
|
116
|
+
}
|
117
|
+
|
118
|
+
@JRubyMethod
|
119
|
+
public static IRubyObject detect(ThreadContext context, IRubyObject self, IRubyObject ifnone, final Block block) {
|
120
|
+
return context.getRuntime().getNil();
|
121
|
+
}
|
122
|
+
|
123
|
+
@JRubyMethod
|
124
|
+
public static IRubyObject drop(ThreadContext context, IRubyObject self, IRubyObject n, final Block block) {
|
125
|
+
return context.getRuntime().getNil();
|
126
|
+
}
|
127
|
+
|
128
|
+
@JRubyMethod
|
129
|
+
public static IRubyObject drop_while(ThreadContext context, IRubyObject self, final Block block) {
|
130
|
+
return context.getRuntime().getNil();
|
131
|
+
}
|
132
|
+
|
133
|
+
@JRubyMethod
|
134
|
+
public static IRubyObject each_cons(ThreadContext context, IRubyObject self, IRubyObject arg, final Block block) {
|
135
|
+
return context.getRuntime().getNil();
|
136
|
+
}
|
137
|
+
|
138
|
+
@JRubyMethod(rest = true)
|
139
|
+
public static IRubyObject each_entry(ThreadContext context, final IRubyObject self, final IRubyObject[] args, final Block block) {
|
140
|
+
return context.getRuntime().getNil();
|
141
|
+
}
|
142
|
+
|
143
|
+
@JRubyMethod
|
144
|
+
public static IRubyObject each_slice(ThreadContext context, IRubyObject self, IRubyObject arg, final Block block) {
|
145
|
+
return context.getRuntime().getNil();
|
146
|
+
}
|
147
|
+
}
|
@@ -0,0 +1,113 @@
|
|
1
|
+
package diametric;
|
2
|
+
|
3
|
+
import java.util.Date;
|
4
|
+
import java.util.List;
|
5
|
+
|
6
|
+
import org.jruby.Ruby;
|
7
|
+
import org.jruby.RubyClass;
|
8
|
+
import org.jruby.RubyObject;
|
9
|
+
import org.jruby.RubyTime;
|
10
|
+
import org.jruby.anno.JRubyClass;
|
11
|
+
import org.jruby.anno.JRubyMethod;
|
12
|
+
import org.jruby.javasupport.JavaUtil;
|
13
|
+
import org.jruby.javasupport.util.RuntimeHelpers;
|
14
|
+
import org.jruby.runtime.ThreadContext;
|
15
|
+
import org.jruby.runtime.builtin.IRubyObject;
|
16
|
+
|
17
|
+
@JRubyClass(name = "Diametric::Persistence::Connection")
|
18
|
+
public class DiametricConnection extends RubyObject {
|
19
|
+
private static final long serialVersionUID = 3806301567154638371L;
|
20
|
+
//conn should a datomic.Connection type
|
21
|
+
private Object conn = null;
|
22
|
+
|
23
|
+
public DiametricConnection(Ruby runtime, RubyClass klazz) {
|
24
|
+
super(runtime, klazz);
|
25
|
+
}
|
26
|
+
|
27
|
+
void init(Object conn) {
|
28
|
+
this.conn = conn;
|
29
|
+
}
|
30
|
+
|
31
|
+
Object toJava() {
|
32
|
+
return conn;
|
33
|
+
}
|
34
|
+
|
35
|
+
@JRubyMethod
|
36
|
+
public IRubyObject to_java(ThreadContext context) {
|
37
|
+
return JavaUtil.convertJavaToUsableRubyObject(context.getRuntime(), conn);
|
38
|
+
}
|
39
|
+
|
40
|
+
@JRubyMethod
|
41
|
+
public IRubyObject db(ThreadContext context) {
|
42
|
+
try {
|
43
|
+
Object database = clojure.lang.RT.var("datomic.api", "db").invoke(conn);
|
44
|
+
RubyClass clazz = (RubyClass)context.getRuntime().getClassFromPath("Diametric::Persistence::Database");
|
45
|
+
DiametricDatabase diametric_database = (DiametricDatabase)clazz.allocate();
|
46
|
+
diametric_database.init(database);
|
47
|
+
return diametric_database;
|
48
|
+
} catch (Throwable t) {
|
49
|
+
throw context.getRuntime().newRuntimeError(t.getMessage());
|
50
|
+
}
|
51
|
+
}
|
52
|
+
|
53
|
+
@JRubyMethod
|
54
|
+
public IRubyObject transact(ThreadContext context, IRubyObject arg) {
|
55
|
+
List<Object> tx_data = DiametricUtils.convertRubyTxDataToJava(context, arg);
|
56
|
+
if (tx_data == null) {
|
57
|
+
throw context.getRuntime().newArgumentError("Argument should be Array or clojure.lang.PersistentVector");
|
58
|
+
}
|
59
|
+
|
60
|
+
try {
|
61
|
+
Object future = clojure.lang.RT.var("datomic.api", "transact").invoke(conn, tx_data);
|
62
|
+
RubyClass clazz = (RubyClass)context.getRuntime().getClassFromPath("Diametric::Persistence::ListenableFuture");
|
63
|
+
DiametricListenableFuture diametric_listenable = (DiametricListenableFuture)clazz.allocate();
|
64
|
+
diametric_listenable.init(future);
|
65
|
+
return diametric_listenable;
|
66
|
+
} catch (Throwable t) {
|
67
|
+
throw context.getRuntime().newRuntimeError(t.getMessage());
|
68
|
+
}
|
69
|
+
}
|
70
|
+
|
71
|
+
@JRubyMethod
|
72
|
+
public IRubyObject transact_async(ThreadContext context, IRubyObject arg) {
|
73
|
+
List<Object> tx_data = DiametricUtils.convertRubyTxDataToJava(context, arg);
|
74
|
+
if (tx_data == null) {
|
75
|
+
throw context.getRuntime().newArgumentError("Argument should be Array or clojure.lang.PersistentVector");
|
76
|
+
}
|
77
|
+
|
78
|
+
try {
|
79
|
+
Object future = clojure.lang.RT.var("datomic.api", "transact-async").invoke(conn, tx_data);
|
80
|
+
RubyClass clazz = (RubyClass)context.getRuntime().getClassFromPath("Diametric::Persistence::ListenableFuture");
|
81
|
+
DiametricListenableFuture diametric_listenable = (DiametricListenableFuture)clazz.allocate();
|
82
|
+
diametric_listenable.init(future);
|
83
|
+
return diametric_listenable;
|
84
|
+
} catch (Throwable t) {
|
85
|
+
throw context.getRuntime().newRuntimeError(t.getMessage());
|
86
|
+
}
|
87
|
+
}
|
88
|
+
|
89
|
+
@JRubyMethod
|
90
|
+
public IRubyObject gc_storage(ThreadContext context, IRubyObject arg) {
|
91
|
+
if (!(arg.respondsTo("to_time"))) {
|
92
|
+
throw context.getRuntime().newArgumentError("Wrong argument type");
|
93
|
+
}
|
94
|
+
RubyTime rubyTime = (RubyTime) RuntimeHelpers.invoke(context, arg, "to_time");
|
95
|
+
Date olderThan = rubyTime.getJavaDate();
|
96
|
+
try {
|
97
|
+
clojure.lang.RT.var("datomic.api", "gc-strage").invoke(conn, olderThan);
|
98
|
+
} catch (Throwable t) {
|
99
|
+
throw context.getRuntime().newRuntimeError("Datomic error: " + t.getMessage());
|
100
|
+
}
|
101
|
+
return context.getRuntime().getNil();
|
102
|
+
}
|
103
|
+
|
104
|
+
@JRubyMethod
|
105
|
+
public IRubyObject release(ThreadContext context) {
|
106
|
+
try {
|
107
|
+
clojure.lang.RT.var("datomic.api", "release").invoke(conn);
|
108
|
+
} catch (Throwable t) {
|
109
|
+
throw context.getRuntime().newRuntimeError(t.getMessage());
|
110
|
+
}
|
111
|
+
return context.getRuntime().getNil();
|
112
|
+
}
|
113
|
+
}
|