diametric 0.1.2-java → 0.1.3-java

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +3 -3
  3. data/Jarfile +13 -6
  4. data/LICENSE.txt +2 -2
  5. data/README.md +57 -26
  6. data/Rakefile +1 -0
  7. data/bin/datomic-rest +1 -1
  8. data/bin/download-datomic +1 -1
  9. data/datomic_version.yml +2 -2
  10. data/diametric-java.gemspec +11 -10
  11. data/ext/diametric/DiametricCollection.java +45 -38
  12. data/ext/diametric/DiametricConnection.java +16 -15
  13. data/ext/diametric/DiametricDatabase.java +9 -8
  14. data/ext/diametric/DiametricEntity.java +104 -21
  15. data/ext/diametric/DiametricObject.java +12 -1
  16. data/ext/diametric/DiametricPeer.java +52 -31
  17. data/ext/diametric/DiametricService.java +2 -0
  18. data/ext/diametric/DiametricSet.java +11 -4
  19. data/ext/diametric/DiametricUUID.java +8 -1
  20. data/ext/diametric/DiametricUtils.java +90 -62
  21. data/lib/diametric.rb +1 -0
  22. data/lib/diametric/associations/collection.rb +103 -0
  23. data/lib/diametric/entity.rb +166 -103
  24. data/lib/diametric/persistence/common.rb +0 -44
  25. data/lib/diametric/persistence/peer.rb +53 -2
  26. data/lib/diametric/persistence/rest.rb +27 -1
  27. data/lib/diametric/query.rb +49 -31
  28. data/lib/diametric/rest_service.rb +8 -9
  29. data/lib/diametric/service_base.rb +7 -7
  30. data/lib/diametric/transactor.rb +6 -5
  31. data/lib/diametric/version.rb +1 -1
  32. data/lib/diametric_service.jar +0 -0
  33. data/spec/config/free-transactor-template.properties +6 -6
  34. data/spec/developer_query_spec.rb +17 -6
  35. data/spec/diametric/entity_spec.rb +62 -139
  36. data/spec/diametric/peer_api_spec.rb +23 -23
  37. data/spec/diametric/persistence/peer_spec.rb +73 -11
  38. data/spec/diametric/persistence/rest_spec.rb +108 -16
  39. data/spec/diametric/query_spec.rb +3 -3
  40. data/spec/diametric/rest_service_spec.rb +4 -4
  41. data/spec/diametric/schema_spec.rb +526 -0
  42. data/spec/diametric/transactor_spec.rb +5 -6
  43. data/spec/integration_spec.rb +7 -7
  44. data/spec/peer_integration_spec.rb +25 -1
  45. data/spec/peer_seattle_spec.rb +1 -2
  46. data/spec/spec_helper.rb +31 -4
  47. data/spec/support/cardinarity_many_example.rb +37 -0
  48. data/spec/support/entities.rb +127 -0
  49. data/spec/support/has_a_example.rb +31 -0
  50. data/spec/support/has_many_example.rb +79 -0
  51. data/spec/support/persistence_examples.rb +13 -5
  52. data/spec/support/various_types_examples.rb +163 -0
  53. data/spec/test_version_file.yml +2 -2
  54. metadata +147 -75
@@ -55,7 +55,7 @@ public class DiametricDatabase extends RubyObject {
55
55
  throw context.getRuntime().newArgumentError("Argument should be Fixnum or dbid object");
56
56
  }
57
57
  try {
58
- Entity entity = (Entity) clojure.lang.RT.var("datomic.api", "entity").invoke(database, entityId);
58
+ Entity entity = (Entity) DiametricService.getFn("datomic.api", "entity").invoke(database, entityId);
59
59
  RubyClass clazz = (RubyClass)context.getRuntime().getClassFromPath("Diametric::Persistence::Entity");
60
60
  DiametricEntity diametric_entity = (DiametricEntity)clazz.allocate();
61
61
  diametric_entity.init(entity);
@@ -67,12 +67,13 @@ public class DiametricDatabase extends RubyObject {
67
67
 
68
68
  @JRubyMethod
69
69
  public IRubyObject with(ThreadContext context, IRubyObject arg) {
70
- List<Object> tx_data = DiametricUtils.convertRubyTxDataToJava(context, arg);
71
- if (tx_data == null) {
72
- throw context.getRuntime().newArgumentError("Argument should be Array or clojure.lang.PersistentVector");
73
- }
74
70
  try {
75
- Map map = (Map) clojure.lang.RT.var("datomic.api", "with").invoke(database, tx_data);
71
+ List<Object> tx_data = DiametricUtils.convertRubyTxDataToJava(context, arg); // may raise exception
72
+ if (tx_data == null) {
73
+ throw context.getRuntime().newArgumentError("Argument should be Array or clojure.lang.PersistentVector");
74
+ }
75
+
76
+ Map map = (Map) DiametricService.getFn("datomic.api", "with").invoke(database, tx_data);
76
77
  return RubyHash.newHash(context.getRuntime(), map, null);
77
78
  } catch (Throwable t) {
78
79
  throw context.getRuntime().newRuntimeError("Datomic Error: " + t.getMessage());
@@ -83,7 +84,7 @@ public class DiametricDatabase extends RubyObject {
83
84
  public IRubyObject as_of(ThreadContext context, IRubyObject arg) {
84
85
  Object t_value = DiametricUtils.convertRubyToJava(context, arg);
85
86
  try {
86
- Database db_asof_t = (Database) clojure.lang.RT.var("datomic.api", "as-of").invoke(database, t_value);
87
+ Database db_asof_t = (Database) DiametricService.getFn("datomic.api", "as-of").invoke(database, t_value);
87
88
  RubyClass clazz = (RubyClass)context.getRuntime().getClassFromPath("Diametric::Persistence::Database");
88
89
  DiametricDatabase diametric_database = (DiametricDatabase)clazz.allocate();
89
90
  diametric_database.init(db_asof_t);
@@ -97,7 +98,7 @@ public class DiametricDatabase extends RubyObject {
97
98
  public IRubyObject since(ThreadContext context, IRubyObject arg) {
98
99
  Object t_value = DiametricUtils.convertRubyToJava(context, arg);
99
100
  try {
100
- Database db_since_t = (Database) clojure.lang.RT.var("datomic.api", "since").invoke(database, t_value);
101
+ Database db_since_t = (Database) DiametricService.getFn("datomic.api", "since").invoke(database, t_value);
101
102
  RubyClass clazz = (RubyClass)context.getRuntime().getClassFromPath("Diametric::Persistence::Database");
102
103
  DiametricDatabase diametric_database = (DiametricDatabase)clazz.allocate();
103
104
  diametric_database.init(db_since_t);
@@ -1,6 +1,8 @@
1
1
  package diametric;
2
2
 
3
3
  import java.util.Collection;
4
+ import java.util.List;
5
+ import java.util.Map;
4
6
 
5
7
  import org.jruby.Ruby;
6
8
  import org.jruby.RubyArray;
@@ -14,12 +16,21 @@ import org.jruby.javasupport.JavaUtil;
14
16
  import org.jruby.runtime.ThreadContext;
15
17
  import org.jruby.runtime.builtin.IRubyObject;
16
18
 
19
+ import clojure.lang.Var;
20
+
17
21
  @JRubyClass(name = "Diametric::Persistence::Entity")
18
22
  public class DiametricEntity extends RubyObject {
19
23
  private static final long serialVersionUID = 3906852174830144427L;
20
24
  //entity should be datomic.Entity type
21
25
  private Object entity = null;
22
26
 
27
+ static IRubyObject getDiametricEntity(ThreadContext context, Object value) {
28
+ RubyClass clazz = (RubyClass)context.getRuntime().getClassFromPath("Diametric::Persistence::Entity");
29
+ DiametricEntity diametric_entity = (DiametricEntity)clazz.allocate();
30
+ diametric_entity.init(value);
31
+ return diametric_entity;
32
+ }
33
+
23
34
  public DiametricEntity(Ruby runtime, RubyClass klazz) {
24
35
  super(runtime, klazz);
25
36
  }
@@ -40,7 +51,7 @@ public class DiametricEntity extends RubyObject {
40
51
  @JRubyMethod
41
52
  public IRubyObject db(ThreadContext context) {
42
53
  try {
43
- Object database = clojure.lang.RT.var("datomic.api", "db").invoke(entity);
54
+ Object database = DiametricService.getFn("datomic.api", "db").invoke(entity);
44
55
  RubyClass clazz = (RubyClass)context.getRuntime().getClassFromPath("Diametric::Persistence::Database");
45
56
  DiametricDatabase diametric_database = (DiametricDatabase)clazz.allocate();
46
57
  diametric_database.init(database);
@@ -49,29 +60,11 @@ public class DiametricEntity extends RubyObject {
49
60
  throw context.getRuntime().newRuntimeError(t.getMessage());
50
61
  }
51
62
  }
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
-
63
+
71
64
  @JRubyMethod
72
65
  public IRubyObject touch(ThreadContext context) {
73
66
  try {
74
- Object touched_entity = clojure.lang.RT.var("datomic.api", "touch").invoke(entity);
67
+ Object touched_entity = DiametricService.getFn("datomic.api", "touch").invoke(entity);
75
68
  entity = touched_entity;
76
69
  return this;
77
70
  } catch (Throwable t) {
@@ -87,4 +80,94 @@ public class DiametricEntity extends RubyObject {
87
80
  }
88
81
  return context.getRuntime().getNil();
89
82
  }
83
+
84
+ @JRubyMethod(name={"==","eql?"}, required=1)
85
+ public IRubyObject eql_p(ThreadContext context, IRubyObject arg) {
86
+ Object other = DiametricUtils.convertRubyToJava(context, arg);
87
+ try {
88
+ Var var = DiametricService.getFn("clojure.core", "=");
89
+ Boolean value = (Boolean)var.invoke(entity, other);
90
+ return context.getRuntime().newBoolean(value);
91
+ } catch (Throwable t) {
92
+ throw context.getRuntime().newRuntimeError(t.getMessage());
93
+ }
94
+ }
95
+
96
+ @JRubyMethod(name={"[]","get"}, required=1)
97
+ public IRubyObject op_aref(ThreadContext context, IRubyObject arg) {
98
+ String key = (String) arg.toJava(String.class);
99
+ try {
100
+ Var var = DiametricService.getFn("clojure.core", "get");
101
+ Object value = var.invoke(entity, key);
102
+ return DiametricUtils.convertJavaToRuby(context, value);
103
+ } catch (Throwable t) {
104
+ throw context.getRuntime().newRuntimeError(t.getMessage());
105
+ }
106
+ }
107
+
108
+ @JRubyMethod(name={"has_key?","include?", "key?", "member?"}, required=1)
109
+ public IRubyObject has_key_p(ThreadContext context, IRubyObject arg) {
110
+ String key = (String) arg.toJava(String.class);
111
+ try {
112
+ Var var = DiametricService.getFn("clojure.core", "contains?");
113
+ Boolean value = (Boolean)var.invoke(entity, key);
114
+ return context.getRuntime().newBoolean(value);
115
+ } catch (Throwable t) {
116
+ throw context.getRuntime().newRuntimeError(t.getMessage());
117
+ }
118
+ }
119
+
120
+ @JRubyMethod
121
+ public IRubyObject keys(ThreadContext context) {
122
+ try {
123
+ Var var = DiametricService.getFn("clojure.core", "keys");
124
+ List<Object> keys = (List<Object>) var.invoke(entity);
125
+ RubyArray ruby_keys = RubyArray.newArray(context.getRuntime());
126
+ for (Object key : keys) {
127
+ // keys are clojure.lang.Keyword
128
+ ruby_keys.append(RubyString.newString(context.getRuntime(), key.toString()));
129
+ }
130
+ return ruby_keys;
131
+ } catch (Throwable t) {
132
+ throw context.getRuntime().newRuntimeError(t.getMessage());
133
+ }
134
+ }
135
+
136
+ @JRubyMethod
137
+ public IRubyObject values(ThreadContext context) {
138
+ try {
139
+ Var var = DiametricService.getFn("clojure.core", "vals");
140
+ List<Object> keys = (List<Object>) var.invoke(entity);
141
+ RubyArray ruby_keys = RubyArray.newArray(context.getRuntime());
142
+ for (Object key : keys) {
143
+ // keys are clojure.lang.Keyword
144
+ ruby_keys.append(RubyString.newString(context.getRuntime(), key.toString()));
145
+ }
146
+ return ruby_keys;
147
+ } catch (Throwable t) {
148
+ throw context.getRuntime().newRuntimeError(t.getMessage());
149
+ }
150
+ }
151
+
152
+ @JRubyMethod(name={"length", "size"})
153
+ public IRubyObject length(ThreadContext context) {
154
+ try {
155
+ Var var = DiametricService.getFn("clojure.core", "count");
156
+ Integer count = (Integer) var.invoke(entity);
157
+ return context.getRuntime().newFixnum(count);
158
+ } catch (Throwable t) {
159
+ throw context.getRuntime().newRuntimeError(t.getMessage());
160
+ }
161
+ }
162
+
163
+ @JRubyMethod
164
+ public IRubyObject to_s(ThreadContext context) {
165
+ try {
166
+ Var var = DiametricService.getFn("clojure.core", "str");
167
+ String str = (String) var.invoke(entity);
168
+ return context.getRuntime().newString(str);
169
+ } catch (Throwable t) {
170
+ throw context.getRuntime().newRuntimeError(t.getMessage());
171
+ }
172
+ }
90
173
  }
@@ -59,8 +59,19 @@ public class DiametricObject extends RubyObject {
59
59
  }
60
60
  }
61
61
 
62
- @JRubyMethod
62
+ @JRubyMethod(name={"to_s", "to_edn"})
63
63
  public IRubyObject to_s(ThreadContext context) {
64
+ if (java_object == null) {
65
+ return context.getRuntime().getNil();
66
+ }
64
67
  return context.getRuntime().newString(java_object.toString());
65
68
  }
69
+
70
+ @JRubyMethod
71
+ public IRubyObject to_i(ThreadContext context) {
72
+ if (java_object instanceof Long) {
73
+ return context.getRuntime().newFixnum((Long)java_object);
74
+ }
75
+ return context.getRuntime().getNil();
76
+ }
66
77
  }
@@ -18,11 +18,14 @@ import org.jruby.RubyString;
18
18
  import org.jruby.RubySymbol;
19
19
  import org.jruby.anno.JRubyMethod;
20
20
  import org.jruby.anno.JRubyModule;
21
+ import org.jruby.javasupport.util.RuntimeHelpers;
21
22
  import org.jruby.runtime.Block;
22
23
  import org.jruby.runtime.ThreadContext;
23
24
  import org.jruby.runtime.builtin.IRubyObject;
24
25
 
26
+ import clojure.lang.Keyword;
25
27
  import clojure.lang.PersistentHashSet;
28
+ import clojure.lang.PersistentVector;
26
29
  import datomic.Connection;
27
30
  import datomic.Peer;
28
31
 
@@ -55,20 +58,26 @@ public class DiametricPeer extends RubyModule {
55
58
  DiametricConnection rubyConnection = (DiametricConnection)clazz.allocate();
56
59
  try {
57
60
  // what value will be returned when connect fails? API doc doesn't tell anything.
58
- Connection connection = (Connection) clojure.lang.RT.var("datomic.api", "connect").invoke(uriOrMap);
61
+ Connection connection = (Connection) DiametricService.getFn("datomic.api", "connect").invoke(uriOrMap);
59
62
  rubyConnection.init(connection);
60
63
  saved_connection = rubyConnection;
61
64
  return rubyConnection;
62
65
  } catch (Exception e) {
63
66
  // Diametric doesn't require creating database before connect.
64
- if (e.getMessage().contains(":peer/db-not-found") && (Boolean)clojure.lang.RT.var("datomic.api", "create-database").invoke(uriOrMap)) {
65
- Connection connection = (Connection) clojure.lang.RT.var("datomic.api", "connect").invoke(uriOrMap);
66
- rubyConnection.init(connection);
67
- saved_connection = rubyConnection;
68
- return rubyConnection;
67
+ // if database has not yet created, try that first and return the connection
68
+ if (e instanceof clojure.lang.ExceptionInfo) {
69
+ try {
70
+ DiametricService.getFn("datomic.api", "create-database").invoke(uriOrMap);
71
+ Connection connection = (Connection) DiametricService.getFn("datomic.api", "connect").invoke(uriOrMap);
72
+ rubyConnection.init(connection);
73
+ saved_connection = rubyConnection;
74
+ return rubyConnection;
75
+ } catch (Throwable t) {
76
+ throw context.getRuntime().newRuntimeError(t.getMessage());
77
+ }
69
78
  }
79
+ throw context.getRuntime().newRuntimeError(e.getMessage());
70
80
  }
71
- throw context.getRuntime().newRuntimeError("Failed to create connection");
72
81
  }
73
82
 
74
83
  @JRubyMethod(meta=true)
@@ -77,7 +86,7 @@ public class DiametricPeer extends RubyModule {
77
86
  if (uriOrMap == null)
78
87
  throw context.getRuntime().newArgumentError("Argument should be a String");
79
88
  try {
80
- boolean status = (Boolean)clojure.lang.RT.var("datomic.api", "create-database").invoke(uriOrMap);
89
+ boolean status = (Boolean)DiametricService.getFn("datomic.api", "create-database").invoke(uriOrMap);
81
90
  return RubyBoolean.newBoolean(context.getRuntime(), status);
82
91
  } catch (Exception e) {
83
92
  throw context.getRuntime().newRuntimeError("Datomic Error: " + e.getMessage());
@@ -92,7 +101,7 @@ public class DiametricPeer extends RubyModule {
92
101
  String newName = DiametricUtils.rubyStringToJava(args[1]);
93
102
  if (newName == null) return context.getRuntime().getNil();
94
103
  try {
95
- boolean status = (Boolean)clojure.lang.RT.var("datomic.api", "rename-database").invoke(uriOrMap, newName);
104
+ boolean status = (Boolean)DiametricService.getFn("datomic.api", "rename-database").invoke(uriOrMap, newName);
96
105
  return RubyBoolean.newBoolean(context.getRuntime(), status);
97
106
  } catch (Exception e) {
98
107
  throw context.getRuntime().newRuntimeError("Datomic Error: " + e.getMessage());
@@ -104,7 +113,7 @@ public class DiametricPeer extends RubyModule {
104
113
  String uriOrMap = DiametricUtils.rubyStringToJava(arg);
105
114
  if (uriOrMap == null) return context.getRuntime().getNil();
106
115
  try {
107
- boolean status = (Boolean)clojure.lang.RT.var("datomic.api", "delete-database").invoke(uriOrMap);
116
+ boolean status = (Boolean)DiametricService.getFn("datomic.api", "delete-database").invoke(uriOrMap);
108
117
  return RubyBoolean.newBoolean(context.getRuntime(), status);
109
118
  } catch (Exception e) {
110
119
  throw context.getRuntime().newRuntimeError("Datomic Error: " + e.getMessage());
@@ -118,7 +127,7 @@ public class DiametricPeer extends RubyModule {
118
127
  }
119
128
  Boolean shutdownClojure = (Boolean) arg.toJava(Boolean.class);
120
129
  try {
121
- clojure.lang.RT.var("datomic.api", "shutdown").invoke(shutdownClojure);
130
+ DiametricService.getFn("datomic.api", "shutdown").invoke(shutdownClojure);
122
131
  } catch (Exception e) {
123
132
  throw context.getRuntime().newRuntimeError("Datomic Error: " + e.getMessage());
124
133
  }
@@ -137,7 +146,7 @@ public class DiametricPeer extends RubyModule {
137
146
  RubyClass clazz = (RubyClass) context.getRuntime().getClassFromPath("Diametric::Persistence::UUID");
138
147
  diametric.DiametricUUID ruby_uuid = (diametric.DiametricUUID)clazz.allocate();
139
148
  try {
140
- java.util.UUID java_uuid = (UUID) clojure.lang.RT.var("datomic.api", "squuid").invoke();
149
+ java.util.UUID java_uuid = (UUID) DiametricService.getFn("datomic.api", "squuid").invoke();
141
150
  ruby_uuid.init(java_uuid);
142
151
  return ruby_uuid;
143
152
  } catch (Throwable t) {
@@ -162,7 +171,7 @@ public class DiametricPeer extends RubyModule {
162
171
  if (squuid == null) return context.getRuntime().getNil();
163
172
  long value;
164
173
  try {
165
- value = (Long) clojure.lang.RT.var("datomic.api", "squuid-time-millis").invoke(squuid);
174
+ value = (Long) DiametricService.getFn("datomic.api", "squuid-time-millis").invoke(squuid);
166
175
  return RubyFixnum.newFixnum(context.getRuntime(), value);
167
176
  } catch (Throwable t) {
168
177
  throw context.getRuntime().newRuntimeError("Datomic Exception: " + t.getMessage());
@@ -184,11 +193,15 @@ public class DiametricPeer extends RubyModule {
184
193
  if (args.length < 1 || args.length > 2) {
185
194
  throw context.getRuntime().newArgumentError("Wrong number of arguments");
186
195
  }
187
- String partition = DiametricUtils.rubyStringToJava(args[0]);
196
+ if (!(args[0] instanceof RubySymbol)) {
197
+ throw context.getRuntime().newArgumentError("The first argument should be a Symbol");
198
+ }
199
+ RubyString edn_string = (RubyString)RuntimeHelpers.invoke(context, args[0], "to_s");
200
+ Keyword partition = Keyword.intern((String)edn_string.asJavaString());
188
201
  RubyClass clazz = (RubyClass)context.getRuntime().getClassFromPath("Diametric::Persistence::Object");
189
202
  DiametricObject diametric_object = (DiametricObject)clazz.allocate();
190
203
  try {
191
- clojure.lang.Var clj_var = clojure.lang.RT.var("datomic.api", "tempid");
204
+ clojure.lang.Var clj_var = DiametricService.getFn("datomic.api", "tempid");
192
205
  if (args.length > 1 && (args[1] instanceof RubyFixnum)) {
193
206
  long idNumber = (Long) args[1].toJava(Long.class);
194
207
  diametric_object.update(clj_var.invoke(partition, idNumber));
@@ -224,7 +237,7 @@ public class DiametricPeer extends RubyModule {
224
237
  throw context.getRuntime().newArgumentError("Wrong argument type.");
225
238
  }
226
239
  try {
227
- Object dbid = clojure.lang.RT.var("datomic.api", "resolve-tempid")
240
+ Object dbid = DiametricService.getFn("datomic.api", "resolve-tempid")
228
241
  .invoke(map.get(Connection.DB_AFTER), map.get(Connection.TEMPIDS), ruby_object.toJava());
229
242
  ruby_object.update(dbid);
230
243
  return ruby_object;
@@ -239,36 +252,44 @@ public class DiametricPeer extends RubyModule {
239
252
  if (args.length < 2) {
240
253
  throw runtime.newArgumentError("Wrong number of arguments");
241
254
  }
242
- if (!(args[0] instanceof RubyString)) {
243
- throw runtime.newArgumentError("The first arg should be a query string");
255
+ Object query = null;
256
+ if (args[0] instanceof RubyArray) {
257
+ try {
258
+ query = DiametricUtils.fromRubyArray(context, (RubyArray)args[0]);
259
+ } catch (Throwable t) {
260
+ throw runtime.newRuntimeError(t.getMessage());
261
+ }
262
+ } else if (args[0] instanceof RubyString) {
263
+ query = DiametricUtils.rubyStringToJava(args[0]);
264
+ }
265
+ if (query == null) {
266
+ throw runtime.newArgumentError("The first arg should be a query string or array");
244
267
  }
268
+ //System.out.println("query: " + query.toString());
245
269
  if (!(args[1] instanceof DiametricDatabase)) {
246
270
  throw runtime.newArgumentError("The second arg should be a database.");
247
271
  }
248
- String query = (String)args[0].toJava(String.class);
249
272
  Object database = ((DiametricDatabase)args[1]).toJava();
250
273
 
251
274
  Collection<List<Object>> results = null;
252
275
  try {
253
276
  if (args.length == 2) {
254
- results = (Collection<List<Object>>) clojure.lang.RT.var("datomic.api", "q").invoke(query, database);
277
+ results = (Collection<List<Object>>) DiametricService.getFn("datomic.api", "q").invoke(query, database);
255
278
  } else if ((args.length == 3) && (args[2] instanceof RubyArray)) {
256
279
  RubyArray ruby_inputs = (RubyArray)args[2];
257
280
  if (ruby_inputs.getLength() == 0) {
258
281
  results = Peer.q(query, database);
259
282
  } else {
260
- Object[] inputs = new Object[ruby_inputs.getLength()];
261
- for (int i=0; i<inputs.length; i++) {
262
- inputs[i] = DiametricUtils.convertRubyToJava(context, ruby_inputs.shift(context));
263
- }
264
- results = (Collection<List<Object>>) clojure.lang.RT.var("datomic.api", "q").invoke(query, database, inputs);
283
+ PersistentVector clj_args = DiametricUtils.fromRubyArray(context, (RubyArray)ruby_inputs);
284
+ //System.out.println("query args: " + clj_args.toString());
285
+ results = (Collection<List<Object>>) DiametricService.getFn("datomic.api", "q").invoke(query, database, clj_args);
265
286
  }
266
287
  } else {
267
288
  Object[] inputs = new Object[args.length-2];
268
289
  for (int i=0; i<inputs.length; i++) {
269
290
  inputs[i] = DiametricUtils.convertRubyToJava(context, args[i+2]);
270
291
  }
271
- results = (Collection<List<Object>>) clojure.lang.RT.var("datomic.api", "q").invoke(query, database, inputs);
292
+ results = (Collection<List<Object>>) DiametricService.getFn("datomic.api", "q").invoke(query, database, inputs);
272
293
  }
273
294
  } catch (Throwable t) {
274
295
  throw runtime.newRuntimeError("Datomic Exception: " + t.getMessage());
@@ -348,8 +369,8 @@ public class DiametricPeer extends RubyModule {
348
369
  }
349
370
  if (saved_connection == null) throw runtime.newRuntimeError("Connection is not established");
350
371
  try {
351
- Object database = clojure.lang.RT.var("datomic.api", "db").invoke(saved_connection.toJava());
352
- Object entity = clojure.lang.RT.var("datomic.api", "entity").invoke(database, dbid);
372
+ Object database = DiametricService.getFn("datomic.api", "db").invoke(saved_connection.toJava());
373
+ Object entity = DiametricService.getFn("datomic.api", "entity").invoke(database, dbid);
353
374
  RubyClass clazz = (RubyClass) context.getRuntime().getClassFromPath("Diametric::Persistence::Entity");
354
375
  DiametricEntity ruby_entity = (DiametricEntity)clazz.allocate();
355
376
  ruby_entity.init(entity);
@@ -364,7 +385,7 @@ public class DiametricPeer extends RubyModule {
364
385
  Object dbid = DiametricUtils.convertRubyToJava(context, arg);
365
386
  List query = datomic.Util.list((datomic.Util.list(":db.fn/retractEntity", dbid)));
366
387
  try {
367
- clojure.lang.RT.var("datomic.api", "transact-async").invoke(saved_connection.toJava(), query);
388
+ DiametricService.getFn("datomic.api", "transact-async").invoke(saved_connection.toJava(), query);
368
389
  } catch (Throwable t) {
369
390
  throw context.getRuntime().newRuntimeError("Datomic error: " + t.getMessage());
370
391
  }
@@ -388,9 +409,9 @@ public class DiametricPeer extends RubyModule {
388
409
  Long dbid = (Long)DiametricUtils.convertRubyToJava(context, args[1]);
389
410
  String query_string = (String)args[2].toJava(String.class);
390
411
  try {
391
- Object entity = clojure.lang.RT.var("datomic.api", "entity").invoke(database, dbid);
412
+ Object entity = DiametricService.getFn("datomic.api", "entity").invoke(database, dbid);
392
413
  clojure.lang.PersistentHashSet set =
393
- (PersistentHashSet) clojure.lang.RT.var("clojure.core", "get").invoke(entity, query_string);
414
+ (PersistentHashSet) DiametricService.getFn("clojure.core", "get").invoke(entity, query_string);
394
415
 
395
416
  if (set == null) {
396
417
  return RubyArray.newEmptyArray(runtime);
@@ -36,9 +36,11 @@ public class DiametricService implements BasicLibraryService {
36
36
 
37
37
  RubyClass diametric_collection = persistence.defineClassUnder("Collection", runtime.getObject(), COLLECTION_ALLOCATOR);
38
38
  diametric_collection.defineAnnotatedMethods(DiametricCollection.class);
39
+ diametric_collection.includeModule(runtime.getEnumerable());
39
40
 
40
41
  RubyClass diametric_set = persistence.defineClassUnder("Set", runtime.getObject(), SET_ALLOCATOR);
41
42
  diametric_set.defineAnnotatedMethods(DiametricSet.class);
43
+ diametric_set.includeModule(runtime.getEnumerable());
42
44
 
43
45
  RubyClass diametric_listenable = persistence.defineClassUnder("ListenableFuture", runtime.getObject(), LISTENABLE_ALLOCATOR);
44
46
  diametric_listenable.defineAnnotatedMethods(DiametricListenableFuture.class);