diametric 0.1.1-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +28 -0
  3. data/Jarfile +20 -0
  4. data/LICENSE.txt +22 -0
  5. data/README.md +264 -0
  6. data/Rakefile +49 -0
  7. data/bin/datomic-rest +33 -0
  8. data/bin/download-datomic +13 -0
  9. data/datomic_version.yml +4 -0
  10. data/diametric-java.gemspec +39 -0
  11. data/ext/diametric/DiametricCollection.java +147 -0
  12. data/ext/diametric/DiametricConnection.java +113 -0
  13. data/ext/diametric/DiametricDatabase.java +107 -0
  14. data/ext/diametric/DiametricEntity.java +90 -0
  15. data/ext/diametric/DiametricListenableFuture.java +47 -0
  16. data/ext/diametric/DiametricObject.java +66 -0
  17. data/ext/diametric/DiametricPeer.java +414 -0
  18. data/ext/diametric/DiametricService.java +102 -0
  19. data/ext/diametric/DiametricUUID.java +61 -0
  20. data/ext/diametric/DiametricUtils.java +183 -0
  21. data/lib/boolean_type.rb +3 -0
  22. data/lib/diametric.rb +42 -0
  23. data/lib/diametric/config.rb +54 -0
  24. data/lib/diametric/config/environment.rb +42 -0
  25. data/lib/diametric/entity.rb +659 -0
  26. data/lib/diametric/errors.rb +13 -0
  27. data/lib/diametric/generators/active_model.rb +42 -0
  28. data/lib/diametric/persistence.rb +48 -0
  29. data/lib/diametric/persistence/common.rb +82 -0
  30. data/lib/diametric/persistence/peer.rb +154 -0
  31. data/lib/diametric/persistence/rest.rb +107 -0
  32. data/lib/diametric/query.rb +259 -0
  33. data/lib/diametric/railtie.rb +52 -0
  34. data/lib/diametric/rest_service.rb +74 -0
  35. data/lib/diametric/service_base.rb +77 -0
  36. data/lib/diametric/transactor.rb +86 -0
  37. data/lib/diametric/version.rb +3 -0
  38. data/lib/diametric_service.jar +0 -0
  39. data/lib/tasks/create_schema.rb +27 -0
  40. data/lib/tasks/diametric_config.rb +45 -0
  41. data/lib/value_enums.rb +8 -0
  42. data/spec/conf_helper.rb +55 -0
  43. data/spec/config/free-transactor-template.properties +73 -0
  44. data/spec/config/logback.xml +59 -0
  45. data/spec/data/seattle-data0.dtm +452 -0
  46. data/spec/data/seattle-data1.dtm +326 -0
  47. data/spec/developer_create_sample.rb +39 -0
  48. data/spec/developer_query_spec.rb +120 -0
  49. data/spec/diametric/config_spec.rb +60 -0
  50. data/spec/diametric/entity_spec.rb +476 -0
  51. data/spec/diametric/peer_api_spec.rb +147 -0
  52. data/spec/diametric/persistence/peer_many2many_spec.rb +76 -0
  53. data/spec/diametric/persistence/peer_spec.rb +27 -0
  54. data/spec/diametric/persistence/rest_spec.rb +30 -0
  55. data/spec/diametric/persistence_spec.rb +59 -0
  56. data/spec/diametric/query_spec.rb +118 -0
  57. data/spec/diametric/rest_service_spec.rb +56 -0
  58. data/spec/diametric/transactor_spec.rb +68 -0
  59. data/spec/integration_spec.rb +107 -0
  60. data/spec/parent_child_sample.rb +42 -0
  61. data/spec/peer_integration_spec.rb +121 -0
  62. data/spec/peer_seattle_spec.rb +200 -0
  63. data/spec/rc2013_seattle_big.rb +82 -0
  64. data/spec/rc2013_seattle_small.rb +60 -0
  65. data/spec/rc2013_simple_sample.rb +72 -0
  66. data/spec/seattle_integration_spec.rb +106 -0
  67. data/spec/simple_validation_sample.rb +31 -0
  68. data/spec/spec_helper.rb +63 -0
  69. data/spec/support/entities.rb +157 -0
  70. data/spec/support/gen_entity_class.rb +9 -0
  71. data/spec/support/persistence_examples.rb +104 -0
  72. data/spec/test_version_file.yml +4 -0
  73. metadata +290 -0
@@ -0,0 +1,39 @@
1
+ # -*- ruby -*-
2
+ # -*- encoding: utf-8 -*-
3
+ lib = File.expand_path('../lib', __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'diametric/version'
6
+
7
+ Gem::Specification.new do |gem|
8
+ gem.name = "diametric"
9
+ gem.version = Diametric::VERSION
10
+ gem.authors = ["Clinton N. Dreisbach", "Ryan K. Neufeld", "Yoko Harada"]
11
+ gem.email = ["crnixon@gmail.com", "ryan@thinkrelevance.com", "yoko@thinkrelevance.com"]
12
+ gem.summary = %q{ActiveModel for Datomic (JRuby)}
13
+ gem.description = <<EOF
14
+ Diametric is a library for building schemas, queries, and transactions
15
+ for Datomic from Ruby objects. It is also used to map Ruby objects
16
+ as entities into a Datomic database.
17
+ EOF
18
+ gem.homepage = "https://github.com/relevance/diametric"
19
+ gem.platform = 'java'
20
+
21
+ gem.files = %w(Gemfile Jarfile LICENSE.txt README.md Rakefile datomic_version.yml diametric-java.gemspec) + Dir.glob('lib/**/*') + Dir.glob('ext/**/*') + Dir.glob('spec/**/*')
22
+ gem.executables = []
23
+ gem.test_files = Dir.glob("spec/**/*.rb")
24
+ gem.require_paths = ["lib"]
25
+ gem.executables = ["datomic-rest", "download-datomic"]
26
+
27
+ gem.add_dependency 'edn', '~> 1.0.2'
28
+ gem.add_dependency 'activesupport', '~> 3.2.14'
29
+ gem.add_dependency 'activemodel', '~> 3.2.14'
30
+ gem.add_dependency 'datomic-client', '~> 0.4.1'
31
+ gem.add_dependency 'rubyzip', '~> 0.9.9'
32
+ gem.add_dependency 'lock_jar', '~> 0.7.5'
33
+ gem.add_dependency 'jruby-openssl', '~> 0.8.8'
34
+ gem.add_dependency 'uuid', '~> 2.3.7'
35
+ gem.add_dependency 'rspec', '~> 2.14.1'
36
+ gem.add_dependency 'rake-compiler', '~> 0.9.1'
37
+
38
+ gem.extensions = ['Rakefile']
39
+ 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
+ }
@@ -0,0 +1,107 @@
1
+ package diametric;
2
+
3
+ import java.util.List;
4
+ import java.util.Map;
5
+
6
+ import org.jruby.Ruby;
7
+ import org.jruby.RubyClass;
8
+ import org.jruby.RubyFixnum;
9
+ import org.jruby.RubyHash;
10
+ import org.jruby.RubyObject;
11
+ import org.jruby.RubyString;
12
+ import org.jruby.anno.JRubyClass;
13
+ import org.jruby.anno.JRubyMethod;
14
+ import org.jruby.javasupport.JavaUtil;
15
+ import org.jruby.runtime.ThreadContext;
16
+ import org.jruby.runtime.builtin.IRubyObject;
17
+
18
+ import datomic.Database;
19
+ import datomic.Entity;
20
+
21
+ @JRubyClass(name = "Diametric::Persistence::Database")
22
+ public class DiametricDatabase extends RubyObject {
23
+ private static final long serialVersionUID = 6043433195693171937L;
24
+ // database supposed to be datomic.Database type
25
+ private Object database = null;
26
+
27
+ public DiametricDatabase(Ruby runtime, RubyClass klazz) {
28
+ super(runtime, klazz);
29
+ }
30
+
31
+ void init(Object database) {
32
+ this.database = database;
33
+ }
34
+
35
+ Object toJava() {
36
+ return database;
37
+ }
38
+
39
+ @JRubyMethod
40
+ public IRubyObject to_java(ThreadContext context) {
41
+ return JavaUtil.convertJavaToUsableRubyObject(context.getRuntime(), database);
42
+ }
43
+
44
+ @JRubyMethod
45
+ public IRubyObject entity(ThreadContext context, IRubyObject arg) {
46
+ if (!(arg instanceof RubyFixnum)) {
47
+ throw context.getRuntime().newArgumentError("Argument should be Fixnum");
48
+ }
49
+ Long entityId = (Long) arg.toJava(Long.class);
50
+ try {
51
+ Entity entity = (Entity) clojure.lang.RT.var("datomic.api", "entity").invoke(database, entityId);
52
+ RubyClass clazz = (RubyClass)context.getRuntime().getClassFromPath("Diametric::Persistence::Entity");
53
+ DiametricEntity diametric_entity = (DiametricEntity)clazz.allocate();
54
+ diametric_entity.init(entity);
55
+ return diametric_entity;
56
+ } catch (Throwable t) {
57
+ throw context.getRuntime().newRuntimeError("Datomic Error: " + t.getMessage());
58
+ }
59
+ }
60
+
61
+ @JRubyMethod
62
+ public IRubyObject with(ThreadContext context, IRubyObject arg) {
63
+ List<Object> tx_data = DiametricUtils.convertRubyTxDataToJava(context, arg);
64
+ if (tx_data == null) {
65
+ throw context.getRuntime().newArgumentError("Argument should be Array or clojure.lang.PersistentVector");
66
+ }
67
+ try {
68
+ Map map = (Map) clojure.lang.RT.var("datomic.api", "with").invoke(database, tx_data);
69
+ return RubyHash.newHash(context.getRuntime(), map, null);
70
+ } catch (Throwable t) {
71
+ throw context.getRuntime().newRuntimeError("Datomic Error: " + t.getMessage());
72
+ }
73
+ }
74
+
75
+ @JRubyMethod
76
+ public IRubyObject as_of(ThreadContext context, IRubyObject arg) {
77
+ Object t_value = DiametricUtils.convertRubyToJava(context, arg);
78
+ try {
79
+ Database db_asof_t = (Database) clojure.lang.RT.var("datomic.api", "as-of").invoke(database, t_value);
80
+ RubyClass clazz = (RubyClass)context.getRuntime().getClassFromPath("Diametric::Persistence::Database");
81
+ DiametricDatabase diametric_database = (DiametricDatabase)clazz.allocate();
82
+ diametric_database.init(db_asof_t);
83
+ return diametric_database;
84
+ } catch (Throwable t) {
85
+ throw context.getRuntime().newRuntimeError("Datomic Error: " + t.getMessage());
86
+ }
87
+ }
88
+
89
+ @JRubyMethod
90
+ public IRubyObject since(ThreadContext context, IRubyObject arg) {
91
+ Object t_value = DiametricUtils.convertRubyToJava(context, arg);
92
+ try {
93
+ Database db_since_t = (Database) clojure.lang.RT.var("datomic.api", "since").invoke(database, t_value);
94
+ RubyClass clazz = (RubyClass)context.getRuntime().getClassFromPath("Diametric::Persistence::Database");
95
+ DiametricDatabase diametric_database = (DiametricDatabase)clazz.allocate();
96
+ diametric_database.init(db_since_t);
97
+ return diametric_database;
98
+ } catch (Throwable t) {
99
+ throw context.getRuntime().newRuntimeError("Datomic Error: " + t.getMessage());
100
+ }
101
+ }
102
+
103
+ @JRubyMethod
104
+ public IRubyObject id(ThreadContext context) {
105
+ return RubyString.newString(context.getRuntime(), ((Database)database).id());
106
+ }
107
+ }
@@ -0,0 +1,90 @@
1
+ package diametric;
2
+
3
+ import java.util.Collection;
4
+
5
+ import org.jruby.Ruby;
6
+ import org.jruby.RubyArray;
7
+ import org.jruby.RubyClass;
8
+ import org.jruby.RubyFixnum;
9
+ import org.jruby.RubyObject;
10
+ import org.jruby.RubyString;
11
+ import org.jruby.anno.JRubyClass;
12
+ import org.jruby.anno.JRubyMethod;
13
+ import org.jruby.javasupport.JavaUtil;
14
+ import org.jruby.runtime.ThreadContext;
15
+ import org.jruby.runtime.builtin.IRubyObject;
16
+
17
+ @JRubyClass(name = "Diametric::Persistence::Entity")
18
+ public class DiametricEntity extends RubyObject {
19
+ private static final long serialVersionUID = 3906852174830144427L;
20
+ //entity should be datomic.Entity type
21
+ private Object entity = null;
22
+
23
+ public DiametricEntity(Ruby runtime, RubyClass klazz) {
24
+ super(runtime, klazz);
25
+ }
26
+
27
+ void init(Object entity) {
28
+ this.entity = entity;
29
+ }
30
+
31
+ Object toJava() {
32
+ return entity;
33
+ }
34
+
35
+ @JRubyMethod
36
+ public IRubyObject to_java(ThreadContext context) {
37
+ return JavaUtil.convertJavaToUsableRubyObject(context.getRuntime(), entity);
38
+ }
39
+
40
+ @JRubyMethod
41
+ public IRubyObject db(ThreadContext context) {
42
+ try {
43
+ Object database = clojure.lang.RT.var("datomic.api", "db").invoke(entity);
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(name={"[]","get"}, required=1)
54
+ public IRubyObject op_aref(ThreadContext context, IRubyObject arg) {
55
+ String key = (String) arg.toJava(String.class);
56
+ Object value = clojure.lang.RT.var("clojure.core", "get").invoke(entity, key);
57
+ return DiametricUtils.convertJavaToRuby(context, value);
58
+ }
59
+
60
+ @JRubyMethod
61
+ public IRubyObject keys(ThreadContext context) {
62
+ Collection keys = (Collection) clojure.lang.RT.var("clojure.core", "keys").invoke(entity);
63
+ RubyArray ruby_keys = RubyArray.newArray(context.getRuntime());
64
+ for (Object key : keys) {
65
+ // keys are clojure.lang.Keyword
66
+ ruby_keys.append(RubyString.newString(context.getRuntime(), key.toString()));
67
+ }
68
+ return ruby_keys;
69
+ }
70
+
71
+ @JRubyMethod
72
+ public IRubyObject touch(ThreadContext context) {
73
+ try {
74
+ Object touched_entity = clojure.lang.RT.var("datomic.api", "touch").invoke(entity);
75
+ entity = touched_entity;
76
+ return this;
77
+ } catch (Throwable t) {
78
+ throw context.getRuntime().newRuntimeError(t.getMessage());
79
+ }
80
+ }
81
+
82
+ @JRubyMethod
83
+ public IRubyObject eid(ThreadContext context) {
84
+ if (entity instanceof datomic.query.EntityMap) {
85
+ Long eid = (Long) ((datomic.query.EntityMap)entity).eid;
86
+ return RubyFixnum.newFixnum(context.getRuntime(), eid);
87
+ }
88
+ return context.getRuntime().getNil();
89
+ }
90
+ }