diametric 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +6 -14
- data/Gemfile +3 -3
- data/Jarfile +13 -6
- data/LICENSE.txt +2 -2
- data/README.md +57 -26
- data/Rakefile +1 -0
- data/bin/datomic-rest +1 -1
- data/bin/download-datomic +1 -1
- data/datomic_version.yml +2 -2
- data/diametric.gemspec +8 -7
- data/ext/diametric/DiametricCollection.java +45 -38
- data/ext/diametric/DiametricConnection.java +16 -15
- data/ext/diametric/DiametricDatabase.java +9 -8
- data/ext/diametric/DiametricEntity.java +104 -21
- data/ext/diametric/DiametricObject.java +12 -1
- data/ext/diametric/DiametricPeer.java +52 -31
- data/ext/diametric/DiametricService.java +2 -0
- data/ext/diametric/DiametricSet.java +11 -4
- data/ext/diametric/DiametricUUID.java +8 -1
- data/ext/diametric/DiametricUtils.java +90 -62
- data/lib/diametric.rb +1 -0
- data/lib/diametric/associations/collection.rb +103 -0
- data/lib/diametric/entity.rb +166 -103
- data/lib/diametric/persistence/common.rb +0 -44
- data/lib/diametric/persistence/peer.rb +53 -2
- data/lib/diametric/persistence/rest.rb +27 -1
- data/lib/diametric/query.rb +49 -31
- data/lib/diametric/rest_service.rb +8 -9
- data/lib/diametric/service_base.rb +7 -7
- data/lib/diametric/transactor.rb +6 -5
- data/lib/diametric/version.rb +1 -1
- data/lib/diametric_service.jar +0 -0
- data/spec/config/free-transactor-template.properties +6 -6
- data/spec/developer_query_spec.rb +17 -6
- data/spec/diametric/entity_spec.rb +62 -139
- data/spec/diametric/peer_api_spec.rb +23 -23
- data/spec/diametric/persistence/peer_spec.rb +73 -11
- data/spec/diametric/persistence/rest_spec.rb +108 -16
- data/spec/diametric/query_spec.rb +3 -3
- data/spec/diametric/rest_service_spec.rb +4 -4
- data/spec/diametric/schema_spec.rb +526 -0
- data/spec/diametric/transactor_spec.rb +5 -6
- data/spec/integration_spec.rb +7 -7
- data/spec/peer_integration_spec.rb +25 -1
- data/spec/peer_seattle_spec.rb +1 -2
- data/spec/spec_helper.rb +31 -4
- data/spec/support/cardinarity_many_example.rb +37 -0
- data/spec/support/entities.rb +127 -0
- data/spec/support/has_a_example.rb +31 -0
- data/spec/support/has_many_example.rb +79 -0
- data/spec/support/persistence_examples.rb +13 -5
- data/spec/support/various_types_examples.rb +163 -0
- data/spec/test_version_file.yml +2 -2
- metadata +66 -15
checksums.yaml
CHANGED
@@ -1,15 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
metadata.gz: !binary |-
|
9
|
-
YmY3NWU5MmI2ZGJlZWFmMTIyZjU4MjAwYmI0OGI2ZTMyNmIzZmM3YmE5YzY1
|
10
|
-
ZjMwYjgwNmJmYmJjMzQ3OTQyMWU3NDI2YThlMzE0Zjk1MWU1NzE4OTNhZTUz
|
11
|
-
YjRiYjczMTA3NTViMDE2OTkwMmMwMWIwNmViYWI5ZWYzNDY4OWE=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
NDdkN2FiZjU5OWYzNzk0Mjk5YmFmY2Q4YjMwMmRkNmYxZDQzZTRhMzdiNjg0
|
14
|
-
MDE5ZDRiMDU5MWVkZTU2OGIyZDRiNjM0OGQ5ZmIxYjRiODg5YzhmMDZhM2M3
|
15
|
-
OTBmZDMzYWViMTljY2RkNWExZGYyYmM4N2ZiNTZmMWU0NTE0ZWM=
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 8a10531bdc2f742954f1b8d5d01dbec02a8c73ba
|
4
|
+
data.tar.gz: 1a1e4160390b197c99f337dd78be653fda812e5c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 989a368eaf6e0bb69e368b2a8c71b75084023a078ef22b2837bd1c2a93e8ad8d6e4794a4f51d6ae4c458a2cead09ef7b725e30e46b7dc9be9368a2b485a131e3
|
7
|
+
data.tar.gz: 338e5ef2d3a80b841fdeae229f73b070b3bc678b23321fb8c2f1612a0681dea5b42087261111f6fe00ea5caab02c7e64f4aa5ca1d2a3013b3eb54080a3b6cf0b
|
data/Gemfile
CHANGED
@@ -3,13 +3,13 @@
|
|
3
3
|
source 'https://rubygems.org'
|
4
4
|
|
5
5
|
gem 'edn', '~> 1.0.2'
|
6
|
-
gem 'activesupport', '~> 3.2.
|
7
|
-
gem 'activemodel', '~> 3.2.
|
6
|
+
gem 'activesupport', '~> 3.2.16'
|
7
|
+
gem 'activemodel', '~> 3.2.16'
|
8
8
|
gem 'datomic-client', '~> 0.4.1'
|
9
9
|
gem 'rubyzip', '~> 0.9.9'
|
10
10
|
|
11
11
|
gem 'lock_jar', '~> 0.7.5', :platform => :jruby
|
12
|
-
gem 'jruby-openssl',
|
12
|
+
gem 'jruby-openssl', :platform => :jruby
|
13
13
|
gem 'uuid', '~> 2.3.7'
|
14
14
|
|
15
15
|
gem 'rspec', '~> 2.14.1'
|
data/Jarfile
CHANGED
@@ -1,20 +1,27 @@
|
|
1
|
+
# -*- ruby -*-
|
1
2
|
repository 'http://clojars.org/repo/'
|
2
3
|
repository 'https://repository.jboss.org/nexus/content/groups/public/'
|
3
4
|
repository 'http://files.couchbase.com/maven2/'
|
4
5
|
|
5
|
-
|
6
|
+
if ENV["DATOMIC_VERSION_PATH"] &&
|
7
|
+
!ENV["DATOMIC_VERSION_PATH"].empty?
|
8
|
+
File.exists?(ENV["DATOMIC_VERSION_PATH"])
|
9
|
+
datomic_version_path = ENV["DATOMIC_VERSION_PATH"]
|
10
|
+
else
|
11
|
+
datomic_version_path = File.join(File.dirname(__FILE__), "datomic_version.yml")
|
12
|
+
end
|
13
|
+
|
6
14
|
require 'yaml'
|
7
|
-
datomic_versions = YAML.load(
|
15
|
+
datomic_versions = YAML.load(File.read(datomic_version_path))
|
8
16
|
|
9
17
|
if ENV['DIAMETRIC_ENV'] && (ENV['DIAMETRIC_ENV'] == "pro")
|
18
|
+
artifactId = "datomic-pro"
|
10
19
|
datomic_version = datomic_versions["pro"]
|
11
20
|
else
|
21
|
+
artifactId = "datomic-free"
|
12
22
|
datomic_version = datomic_versions["free"]
|
13
23
|
end
|
14
|
-
version = /(\d|\.)+/.match(datomic_version)[0]
|
15
|
-
datomic_version.slice!(version)
|
16
|
-
artifactId = datomic_version.chop
|
17
24
|
|
18
25
|
group :default, :runtime do
|
19
|
-
jar "com.datomic:#{artifactId}:#{
|
26
|
+
jar "com.datomic:#{artifactId}:#{datomic_version}"
|
20
27
|
end
|
data/LICENSE.txt
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
Copyright (c) 2012 Clinton N. Dreisbach
|
1
|
+
Copyright (c) 2012-2014 Clinton N. Dreisbach
|
2
2
|
|
3
3
|
MIT License
|
4
4
|
|
@@ -19,4 +19,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
19
19
|
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
20
|
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
21
|
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
CHANGED
@@ -9,38 +9,27 @@ as entities into a Datomic database.
|
|
9
9
|
|
10
10
|
|
11
11
|
Diametric supports both CRuby and JRuby.
|
12
|
-
When
|
13
|
-
|
14
|
-
When
|
15
|
-
|
12
|
+
When Diametric is used on CRuby, Diametric connects to Datomic's REST service.
|
13
|
+
Using Datomic's REST API, Diametric creates scheam/data and makes a queries to Datomic.
|
14
|
+
When Diametric is used on JRuby, both Datomic's REST and Peer services are supported.
|
15
|
+
The core parts of Peer service are implemented using Datomic API.
|
16
16
|
|
17
17
|
|
18
18
|
For Rubyists who are familiar with object oriented programming, Diametric converts:
|
19
19
|
- Ruby model definition to Datomic schema
|
20
20
|
- Creating, saving and updating model data to Datomic transaction data
|
21
21
|
- Ruby query to Datomic's datalog query
|
22
|
+
- Datomic's dbid to model object (depends on the value of resolve option)
|
22
23
|
|
23
24
|
|
24
25
|
The biggest difference between REST and Peer services is available database types.
|
25
|
-
REST service can use memory database only, which means
|
26
|
+
REST service can use memory database only, which means we can't save data in any file
|
27
|
+
as long as using free version.
|
26
28
|
While Peer service can use memory and free version of transactor,
|
27
|
-
which means
|
29
|
+
which means we can save data in a file through Datomic's transactor.
|
28
30
|
Other than that, Peer service has excellent API to use Datomic's various features.
|
29
31
|
|
30
32
|
|
31
|
-
## Documents
|
32
|
-
|
33
|
-
Other than highlights below, there are documents on Wiki.
|
34
|
-
|
35
|
-
- [Entity API](https://github.com/relevance/diametric/wiki/Entity-API)
|
36
|
-
- [Query API](https://github.com/relevance/diametric/wiki/Query-API)
|
37
|
-
- [Persistence API](https://github.com/relevance/diametric/wiki/Persistence-API)
|
38
|
-
- [Rails Integration](https://github.com/relevance/diametric/wiki/Rails-Integration-%28Experimental%29)
|
39
|
-
- [Seattle Example](https://github.com/relevance/diametric/wiki/Seattle-Example)
|
40
|
-
|
41
|
-
|
42
|
-
This document shows how to use Diametric with simple examples.
|
43
|
-
|
44
33
|
## Installation
|
45
34
|
|
46
35
|
```bash
|
@@ -48,7 +37,7 @@ gem install diametric
|
|
48
37
|
```
|
49
38
|
|
50
39
|
Diametric is a multi-platoform gem. On CRuby, above installs CRuby version of gem.
|
51
|
-
On JRuby,
|
40
|
+
On JRuby, above installed JRuby version of gem with Java extension.
|
52
41
|
|
53
42
|
|
54
43
|
[note]
|
@@ -78,14 +67,14 @@ To learn more about the options in the above command, please go to [http://docs.
|
|
78
67
|
Once the REST server starts running, go to [localhost:9000](localhost:9000) on your browser.
|
79
68
|
You can see Datomic's REST service is running.
|
80
69
|
|
81
|
-
Alternatively, you can download Datomic archive from [
|
70
|
+
Alternatively, you can download Datomic archive from [https://my.datomic.com/downloads/free](https://my.datomic.com/downloads/free),
|
82
71
|
and start REST server using Datomic command, `script/datomic-rest -p 9000 free datomic:mem://`
|
83
72
|
|
84
73
|
|
85
74
|
## Preparation for JRuby
|
86
75
|
|
87
|
-
You have 2 choices on JRuby, Peer and REST
|
88
|
-
Peer service works on the same JVM as JRuby and
|
76
|
+
You have 2 choices on JRuby, Peer and REST services.
|
77
|
+
Peer service works on the same JVM as JRuby and looks like just a Java library for JRuby.
|
89
78
|
|
90
79
|
|
91
80
|
When you choose REST service, follow *Preparation for CRuby* section.
|
@@ -612,7 +601,7 @@ Breeze likes #<Set: {"chocolate", "afternoon", "biking"}>
|
|
612
601
|
```
|
613
602
|
The order is not guaranteed.
|
614
603
|
|
615
|
-
## Association
|
604
|
+
## Association
|
616
605
|
|
617
606
|
On Datomic, association is fairly easy even though it is one to many or many to many.
|
618
607
|
Association is defined by `Ref` type.
|
@@ -678,6 +667,45 @@ Somebody.reify(me.kids.first.mom).name
|
|
678
667
|
=> "Alice Wonderland"
|
679
668
|
```
|
680
669
|
|
670
|
+
## Datomic Verion
|
671
|
+
|
672
|
+
Diametric sets up the default Datomic version.
|
673
|
+
On that version, all Daimetric's tests passes.
|
674
|
+
However, Datomic team frequently releases a new version.
|
675
|
+
Just to update Datomic version, Diametric won't make a new release.
|
676
|
+
From version 0.1.3, Diametric supports user defined Datomic version.
|
677
|
+
|
678
|
+
Here is how a user can use a newer version of Datomic.
|
679
|
+
|
680
|
+
|
681
|
+
Specify a datomic version file by `ENV["DATOMIC_VERSION_PATH"]` *before* `require 'diametric'`.
|
682
|
+
|
683
|
+
For example:
|
684
|
+
```ruby
|
685
|
+
ENV["DATOMIC_VERSION_PATH"] = File.expand_path(File.join(File.dirname(__FILE__), "..", "datomic_version.yml"))
|
686
|
+
require 'diametric'
|
687
|
+
```
|
688
|
+
|
689
|
+
The format of datomic version file is simple yaml. For example:
|
690
|
+
```ruby
|
691
|
+
free:
|
692
|
+
0.9.4532
|
693
|
+
pro:
|
694
|
+
0.9.4470
|
695
|
+
```
|
696
|
+
|
697
|
+
## Other Documents
|
698
|
+
|
699
|
+
More than highlights above, there are documents on Wiki.
|
700
|
+
|
701
|
+
- [Entity API](https://github.com/relevance/diametric/wiki/Entity-API)
|
702
|
+
- [Query API](https://github.com/relevance/diametric/wiki/Query-API)
|
703
|
+
- [Persistence API](https://github.com/relevance/diametric/wiki/Persistence-API)
|
704
|
+
- [Rails Integration](https://github.com/relevance/diametric/wiki/Rails-Integration-%28Experimental%29)
|
705
|
+
- [Seattle Example](https://github.com/relevance/diametric/wiki/Seattle-Example)
|
706
|
+
|
707
|
+
|
708
|
+
|
681
709
|
## Thanks
|
682
710
|
|
683
711
|
Development of Diametric was sponsored by [Relevance][]. They are the
|
@@ -696,7 +724,9 @@ Special thanks to Mongoid for writing some solid ORM code that was liberally bor
|
|
696
724
|
|
697
725
|
## License
|
698
726
|
|
699
|
-
This project uses the [
|
727
|
+
This project uses the [MIT License][].
|
728
|
+
|
729
|
+
When this project is used, a user is considered agreed to the [Datomic Free Edition License][].
|
700
730
|
|
701
731
|
Copyright (c) 2012, Clinton Dreisbach & Relevance Inc. All rights reserved.
|
702
732
|
|
@@ -709,4 +739,5 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
709
739
|
|
710
740
|
[Datomic]: http://www.datomic.com
|
711
741
|
[Relevance]: http://www.thinkrelevance.com
|
712
|
-
[
|
742
|
+
[MIT License]: http://opensource.org/licenses/MIT
|
743
|
+
[Datomic Free Edition License]: https://my.datomic.com/downloads/free
|
data/Rakefile
CHANGED
data/bin/datomic-rest
CHANGED
@@ -23,7 +23,7 @@ opts = OptionParser.new do |opts|
|
|
23
23
|
end
|
24
24
|
opts.parse!
|
25
25
|
|
26
|
-
DATOMIC_NAME = File.read(File.join(File.dirname(__FILE__), "..", "datomic_version.
|
26
|
+
DATOMIC_NAME = File.read(File.join(File.dirname(__FILE__), "..", "datomic_version.yml"))
|
27
27
|
|
28
28
|
require 'diametric/rest_service'
|
29
29
|
|
data/bin/download-datomic
CHANGED
data/datomic_version.yml
CHANGED
data/diametric.gemspec
CHANGED
@@ -8,6 +8,7 @@ Gem::Specification.new do |gem|
|
|
8
8
|
gem.name = "diametric"
|
9
9
|
gem.version = Diametric::VERSION
|
10
10
|
gem.authors = ["Clinton N. Dreisbach", "Ryan K. Neufeld", "Yoko Harada"]
|
11
|
+
gem.license = 'MIT'
|
11
12
|
gem.email = ["crnixon@gmail.com", "ryan@thinkrelevance.com", "yoko@thinkrelevance.com"]
|
12
13
|
gem.summary = %q{ActiveModel for Datomic}
|
13
14
|
gem.description = <<EOF
|
@@ -23,13 +24,13 @@ EOF
|
|
23
24
|
gem.require_paths = ["lib"]
|
24
25
|
gem.executables = ["datomic-rest", "download-datomic"]
|
25
26
|
|
26
|
-
gem.add_dependency 'edn', '~> 1.0.2'
|
27
|
-
gem.add_dependency 'activesupport', '~> 3.2.
|
28
|
-
gem.add_dependency 'activemodel', '~> 3.2.
|
29
|
-
gem.add_dependency 'datomic-client', '~> 0.4.1'
|
30
|
-
gem.add_dependency 'rubyzip', '~> 0.9.9'
|
31
|
-
gem.add_dependency 'uuid', '~> 2.3.7'
|
32
|
-
gem.add_dependency 'rspec', '~> 2.14.1'
|
27
|
+
gem.add_dependency 'edn', '~> 1.0', '>= 1.0.2'
|
28
|
+
gem.add_dependency 'activesupport', '~> 3.2', '>= 3.2.16'
|
29
|
+
gem.add_dependency 'activemodel', '~> 3.2', '>= 3.2.16'
|
30
|
+
gem.add_dependency 'datomic-client', '~> 0.4', '>= 0.4.1'
|
31
|
+
gem.add_dependency 'rubyzip', '~> 0.9', '>= 0.9.9'
|
32
|
+
gem.add_dependency 'uuid', '~> 2.3', '>= 2.3.7'
|
33
|
+
gem.add_dependency 'rspec', '~> 2.3', '>= 2.14.1'
|
33
34
|
|
34
35
|
gem.extensions = ['Rakefile']
|
35
36
|
end
|
@@ -32,6 +32,13 @@ public class DiametricCollection extends RubyObject {
|
|
32
32
|
private Integer count = null; // unable to count the vector size that exceeds Integer
|
33
33
|
private DiametricCommon common = null;
|
34
34
|
|
35
|
+
static IRubyObject getDiametricCollection(ThreadContext context, List value) {
|
36
|
+
RubyClass clazz = (RubyClass)context.getRuntime().getClassFromPath("Diametric::Persistence::Collection");
|
37
|
+
DiametricCollection diametric_collection = (DiametricCollection)clazz.allocate();
|
38
|
+
diametric_collection.init((List)value);
|
39
|
+
return diametric_collection;
|
40
|
+
}
|
41
|
+
|
35
42
|
public DiametricCollection(Ruby runtime, RubyClass klazz) {
|
36
43
|
super(runtime, klazz);
|
37
44
|
}
|
@@ -56,7 +63,7 @@ public class DiametricCollection extends RubyObject {
|
|
56
63
|
try {
|
57
64
|
clojure.lang.PersistentVector value =
|
58
65
|
(clojure.lang.PersistentVector)arg.toJava(clojure.lang.PersistentVector.class);
|
59
|
-
return
|
66
|
+
return DiametricCollection.getDiametricCollection(context, (List)value);
|
60
67
|
} catch (Throwable t) {
|
61
68
|
throw context.getRuntime().newRuntimeError(t.getMessage());
|
62
69
|
}
|
@@ -69,7 +76,7 @@ public class DiametricCollection extends RubyObject {
|
|
69
76
|
(clojure.lang.PersistentVector)arg.toJava(clojure.lang.PersistentVector.class);
|
70
77
|
Var var = DiametricService.getFn("clojure.core", "take");
|
71
78
|
Object value = var.invoke(100, v);
|
72
|
-
return
|
79
|
+
return DiametricCollection.getDiametricCollection(context, (List)value);
|
73
80
|
} catch (Throwable t) {
|
74
81
|
throw context.getRuntime().newRuntimeError(t.getMessage());
|
75
82
|
}
|
@@ -91,21 +98,21 @@ public class DiametricCollection extends RubyObject {
|
|
91
98
|
throw context.getRuntime().newRuntimeError("argument should be array");
|
92
99
|
}
|
93
100
|
List other = (List)arg;
|
94
|
-
Var two_arrays_diff_fn = null;
|
95
|
-
if (DiametricService.fnMap.containsKey("two-arrays-diff")) {
|
96
|
-
two_arrays_diff_fn = DiametricService.fnMap.get("two-arrays-diff");
|
97
|
-
} else {
|
98
|
-
Var var = DiametricService.getFn("clojure.core", "load-string");
|
99
|
-
String fn =
|
100
|
-
"(defn two-arrays-diff [this other]\n" +
|
101
|
-
" (let [f (fn [ary n] (remove (partial = n) ary))]\n"+
|
102
|
-
" (reduce f this other)))";
|
103
|
-
two_arrays_diff_fn = (Var)var.invoke(fn);
|
104
|
-
DiametricService.fnMap.put("two-arrays-diff", two_arrays_diff_fn);
|
105
|
-
}
|
106
101
|
try {
|
102
|
+
Var two_arrays_diff_fn = null;
|
103
|
+
if (DiametricService.fnMap.containsKey("two-arrays-diff")) {
|
104
|
+
two_arrays_diff_fn = DiametricService.fnMap.get("two-arrays-diff");
|
105
|
+
} else {
|
106
|
+
Var var = DiametricService.getFn("clojure.core", "load-string");
|
107
|
+
String fn =
|
108
|
+
"(defn two-arrays-diff [this other]\n" +
|
109
|
+
" (let [f (fn [ary n] (remove (partial = n) ary))]\n"+
|
110
|
+
" (reduce f this other)))";
|
111
|
+
two_arrays_diff_fn = (Var)var.invoke(fn);
|
112
|
+
DiametricService.fnMap.put("two-arrays-diff", two_arrays_diff_fn);
|
113
|
+
}
|
107
114
|
Object value = two_arrays_diff_fn.invoke(vector_or_seq, other);
|
108
|
-
return
|
115
|
+
return DiametricCollection.getDiametricCollection(context, (List)value);
|
109
116
|
} catch (Throwable t) {
|
110
117
|
throw context.getRuntime().newRuntimeError(t.getMessage());
|
111
118
|
}
|
@@ -114,18 +121,18 @@ public class DiametricCollection extends RubyObject {
|
|
114
121
|
@JRubyMethod(name="*")
|
115
122
|
public IRubyObject op_times(ThreadContext context, IRubyObject arg) {
|
116
123
|
if (arg instanceof RubyFixnum) {
|
117
|
-
Var append_n_times_fn = null;
|
118
|
-
if (DiametricService.fnMap.containsKey("append-n-times")) {
|
119
|
-
append_n_times_fn = DiametricService.fnMap.get("append-n-times");
|
120
|
-
} else {
|
121
|
-
Var var = DiametricService.getFn("clojure.core", "load-string");
|
122
|
-
append_n_times_fn = (Var)var.invoke("(defn append-n-times [n array] (reduce concat (replicate n array)))");
|
123
|
-
DiametricService.fnMap.put("append-n-times", append_n_times_fn);
|
124
|
-
}
|
125
|
-
Integer n = (Integer)arg.toJava(Integer.class);
|
126
124
|
try {
|
125
|
+
Var append_n_times_fn = null;
|
126
|
+
if (DiametricService.fnMap.containsKey("append-n-times")) {
|
127
|
+
append_n_times_fn = DiametricService.fnMap.get("append-n-times");
|
128
|
+
} else {
|
129
|
+
Var var = DiametricService.getFn("clojure.core", "load-string");
|
130
|
+
append_n_times_fn = (Var)var.invoke("(defn append-n-times [n array] (reduce concat (replicate n array)))");
|
131
|
+
DiametricService.fnMap.put("append-n-times", append_n_times_fn);
|
132
|
+
}
|
133
|
+
Integer n = (Integer)arg.toJava(Integer.class);
|
127
134
|
Object value = append_n_times_fn.invoke(n, vector_or_seq);
|
128
|
-
return
|
135
|
+
return DiametricCollection.getDiametricCollection(context, (List)value);
|
129
136
|
} catch (Throwable t) {
|
130
137
|
throw context.getRuntime().newRuntimeError(t.getMessage());
|
131
138
|
}
|
@@ -145,7 +152,7 @@ public class DiametricCollection extends RubyObject {
|
|
145
152
|
try {
|
146
153
|
Var var = DiametricService.getFn("clojure.core", "concat");
|
147
154
|
Object value = var.invoke(vector_or_seq, other);
|
148
|
-
return
|
155
|
+
return DiametricCollection.getDiametricCollection(context, (List)value);
|
149
156
|
} catch (Throwable t) {
|
150
157
|
throw context.getRuntime().newRuntimeError(t.getMessage());
|
151
158
|
}
|
@@ -196,8 +203,8 @@ public class DiametricCollection extends RubyObject {
|
|
196
203
|
return commonArefIndex(context, index);
|
197
204
|
} else if (index_or_range instanceof RubyRange) {
|
198
205
|
RubyRange range = (RubyRange)index_or_range;
|
199
|
-
Long start = (Long)range.first().toJava(Long.class);
|
200
|
-
Long last = (Long)range.last().toJava(Long.class);
|
206
|
+
Long start = (Long)range.first(context).toJava(Long.class);
|
207
|
+
Long last = (Long)range.last(context).toJava(Long.class);
|
201
208
|
// subvec returns from 'start' to element (- end 1)
|
202
209
|
if (range.exclude_end_p().isTrue()) {
|
203
210
|
return commonAref(context, start, null, last);
|
@@ -255,7 +262,7 @@ public class DiametricCollection extends RubyObject {
|
|
255
262
|
if (length == null) length = last - start;
|
256
263
|
value = commonArefByDropTake(start, length);
|
257
264
|
}
|
258
|
-
return
|
265
|
+
return DiametricCollection.getDiametricCollection(context, (List)value);
|
259
266
|
} catch (Throwable t) {
|
260
267
|
if (t instanceof IndexOutOfBoundsException) {
|
261
268
|
return retryAref(context, start, length, last);
|
@@ -621,16 +628,16 @@ public class DiametricCollection extends RubyObject {
|
|
621
628
|
|
622
629
|
@JRubyMethod(name="include?")
|
623
630
|
public IRubyObject include_p(ThreadContext context, IRubyObject arg) {
|
624
|
-
Var include_p_fn = null;
|
625
|
-
if (DiametricService.fnMap.containsKey("include?")) {
|
626
|
-
include_p_fn = DiametricService.fnMap.get("include?");
|
627
|
-
} else {
|
628
|
-
Var var = DiametricService.getFn("clojure.core", "load-string");
|
629
|
-
include_p_fn = (Var)var.invoke("(defn include? [v array] (some (partial = v) array))");
|
630
|
-
DiametricService.fnMap.put("include?", include_p_fn);
|
631
|
-
}
|
632
|
-
Object java_object = DiametricUtils.convertRubyToJava(context, arg);
|
633
631
|
try {
|
632
|
+
Var include_p_fn = null;
|
633
|
+
if (DiametricService.fnMap.containsKey("include?")) {
|
634
|
+
include_p_fn = DiametricService.fnMap.get("include?");
|
635
|
+
} else {
|
636
|
+
Var var = DiametricService.getFn("clojure.core", "load-string");
|
637
|
+
include_p_fn = (Var)var.invoke("(defn include? [v array] (some (partial = v) array))");
|
638
|
+
DiametricService.fnMap.put("include?", include_p_fn);
|
639
|
+
}
|
640
|
+
Object java_object = DiametricUtils.convertRubyToJava(context, arg);
|
634
641
|
Object result = include_p_fn.invoke(java_object, vector_or_seq);
|
635
642
|
if ((result instanceof Boolean) && (Boolean)result) {
|
636
643
|
return context.getRuntime().getTrue();
|
@@ -40,7 +40,7 @@ public class DiametricConnection extends RubyObject {
|
|
40
40
|
@JRubyMethod
|
41
41
|
public IRubyObject db(ThreadContext context) {
|
42
42
|
try {
|
43
|
-
Object database =
|
43
|
+
Object database = DiametricService.getFn("datomic.api", "db").invoke(conn);
|
44
44
|
RubyClass clazz = (RubyClass)context.getRuntime().getClassFromPath("Diametric::Persistence::Database");
|
45
45
|
DiametricDatabase diametric_database = (DiametricDatabase)clazz.allocate();
|
46
46
|
diametric_database.init(database);
|
@@ -52,13 +52,14 @@ public class DiametricConnection extends RubyObject {
|
|
52
52
|
|
53
53
|
@JRubyMethod
|
54
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
55
|
try {
|
61
|
-
Object
|
56
|
+
List<Object> tx_data = DiametricUtils.convertRubyTxDataToJava(context, arg); // may raise exception
|
57
|
+
if (tx_data == null) {
|
58
|
+
throw context.getRuntime().newArgumentError("Argument should be Array or clojure.lang.PersistentVector");
|
59
|
+
}
|
60
|
+
|
61
|
+
//System.out.println("tx_data: " + tx_data.toString() + " class: " + tx_data.getClass().getCanonicalName());
|
62
|
+
Object future = DiametricService.getFn("datomic.api", "transact").invoke(conn, tx_data);
|
62
63
|
RubyClass clazz = (RubyClass)context.getRuntime().getClassFromPath("Diametric::Persistence::ListenableFuture");
|
63
64
|
DiametricListenableFuture diametric_listenable = (DiametricListenableFuture)clazz.allocate();
|
64
65
|
diametric_listenable.init(future);
|
@@ -70,13 +71,13 @@ public class DiametricConnection extends RubyObject {
|
|
70
71
|
|
71
72
|
@JRubyMethod
|
72
73
|
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
74
|
try {
|
79
|
-
Object
|
75
|
+
List<Object> tx_data = DiametricUtils.convertRubyTxDataToJava(context, arg); // my raise exception
|
76
|
+
if (tx_data == null) {
|
77
|
+
throw context.getRuntime().newArgumentError("Argument should be Array or clojure.lang.PersistentVector");
|
78
|
+
}
|
79
|
+
|
80
|
+
Object future = DiametricService.getFn("datomic.api", "transact-async").invoke(conn, tx_data);
|
80
81
|
RubyClass clazz = (RubyClass)context.getRuntime().getClassFromPath("Diametric::Persistence::ListenableFuture");
|
81
82
|
DiametricListenableFuture diametric_listenable = (DiametricListenableFuture)clazz.allocate();
|
82
83
|
diametric_listenable.init(future);
|
@@ -94,7 +95,7 @@ public class DiametricConnection extends RubyObject {
|
|
94
95
|
RubyTime rubyTime = (RubyTime) RuntimeHelpers.invoke(context, arg, "to_time");
|
95
96
|
Date olderThan = rubyTime.getJavaDate();
|
96
97
|
try {
|
97
|
-
|
98
|
+
DiametricService.getFn("datomic.api", "gc-strage").invoke(conn, olderThan);
|
98
99
|
} catch (Throwable t) {
|
99
100
|
throw context.getRuntime().newRuntimeError("Datomic error: " + t.getMessage());
|
100
101
|
}
|
@@ -104,7 +105,7 @@ public class DiametricConnection extends RubyObject {
|
|
104
105
|
@JRubyMethod
|
105
106
|
public IRubyObject release(ThreadContext context) {
|
106
107
|
try {
|
107
|
-
|
108
|
+
DiametricService.getFn("datomic.api", "release").invoke(conn);
|
108
109
|
} catch (Throwable t) {
|
109
110
|
throw context.getRuntime().newRuntimeError(t.getMessage());
|
110
111
|
}
|