diametric 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/Jarfile +1 -1
- data/Jarfile.lock +50 -42
- data/README.md +26 -10
- data/lib/diametric.rb +1 -0
- data/lib/diametric/entity.rb +17 -0
- data/lib/diametric/errors.rb +13 -0
- data/lib/diametric/persistence/common.rb +13 -0
- data/lib/diametric/persistence/peer.rb +6 -0
- data/lib/diametric/persistence/rest.rb +10 -0
- data/lib/diametric/version.rb +1 -1
- data/spec/diametric/entity_spec.rb +16 -0
- data/spec/integration_spec.rb +10 -0
- data/spec/spec_helper.rb +1 -0
- metadata +4 -9
data/Jarfile
CHANGED
data/Jarfile.lock
CHANGED
@@ -4,7 +4,7 @@ groups:
|
|
4
4
|
default:
|
5
5
|
dependencies:
|
6
6
|
- com.amazonaws:aws-java-sdk:jar:1.3.0
|
7
|
-
- com.datomic:datomic-free:jar:0.8.
|
7
|
+
- com.datomic:datomic-free:jar:0.8.3655
|
8
8
|
- com.google.code.findbugs:jsr305:jar:1.3.9
|
9
9
|
- com.google.guava:guava:jar:12.0.1
|
10
10
|
- com.h2database:h2:jar:1.3.165
|
@@ -19,9 +19,11 @@ groups:
|
|
19
19
|
- org.apache.tomcat:tomcat-juli:jar:7.0.27
|
20
20
|
- org.clojure:clojure:jar:1.4.0
|
21
21
|
- org.clojure:data.json:jar:0.1.2
|
22
|
+
- org.clojure:tools.cli:jar:0.2.2
|
22
23
|
- org.codehaus.jackson:jackson-core-asl:jar:1.8.0
|
23
24
|
- org.codehaus.janino:commons-compiler-jdk:jar:2.6.1
|
24
25
|
- org.codehaus.janino:commons-compiler:jar:2.6.1
|
26
|
+
- org.fressian:fressian:jar:0.6.3
|
25
27
|
- org.hornetq:hornetq-core:jar:2.2.2.Final
|
26
28
|
- org.jboss.netty:netty:jar:3.2.4.Final
|
27
29
|
- org.slf4j:jcl-over-slf4j:jar:1.6.4
|
@@ -32,39 +34,41 @@ groups:
|
|
32
34
|
- postgresql:postgresql:jar:9.1-901.jdbc4
|
33
35
|
- spy:spymemcached:jar:2.8.1
|
34
36
|
artifacts:
|
35
|
-
- jar:com.datomic:datomic-free:jar:0.8.
|
37
|
+
- jar:com.datomic:datomic-free:jar:0.8.3655:
|
36
38
|
transitive:
|
37
|
-
com.h2database:h2:jar:1.3.165: {}
|
38
|
-
org.apache.lucene:lucene-core:jar:3.3.0: {}
|
39
39
|
postgresql:postgresql:jar:9.1-901.jdbc4: {}
|
40
|
+
org.codehaus.jackson:jackson-core-asl:jar:1.8.0: {}
|
41
|
+
org.slf4j:log4j-over-slf4j:jar:1.6.4: {}
|
42
|
+
net.java.dev.jets3t:jets3t:jar:0.8.1:
|
43
|
+
com.jamesmurty.utils:java-xmlbuilder:jar:0.4: {}
|
44
|
+
commons-httpclient:commons-httpclient:jar:3.1: {}
|
45
|
+
org.hornetq:hornetq-core:jar:2.2.2.Final: {}
|
46
|
+
org.slf4j:jcl-over-slf4j:jar:1.6.4: {}
|
40
47
|
spy:spymemcached:jar:2.8.1: {}
|
41
|
-
org.
|
42
|
-
|
43
|
-
|
48
|
+
org.apache.tomcat:tomcat-jdbc:jar:7.0.27:
|
49
|
+
org.apache.tomcat:tomcat-juli:jar:7.0.27: {}
|
50
|
+
com.h2database:h2:jar:1.3.165: {}
|
51
|
+
org.apache.httpcomponents:httpclient:jar:4.2-alpha1:
|
52
|
+
org.apache.httpcomponents:httpcore:jar:4.2-alpha2: {}
|
53
|
+
com.amazonaws:aws-java-sdk:jar:1.3.0:
|
54
|
+
commons-codec:commons-codec:jar:1.3: {}
|
55
|
+
org.fressian:fressian:jar:0.6.3: {}
|
56
|
+
org.slf4j:slf4j-nop:jar:1.6.4: {}
|
57
|
+
org.apache.lucene:lucene-core:jar:3.3.0: {}
|
44
58
|
com.google.guava:guava:jar:12.0.1:
|
45
59
|
com.google.code.findbugs:jsr305:jar:1.3.9: {}
|
46
60
|
org.clojure:data.json:jar:0.1.2: {}
|
47
|
-
org.slf4j:slf4j-nop:jar:1.6.4: {}
|
48
61
|
org.jboss.netty:netty:jar:3.2.4.Final: {}
|
62
|
+
org.clojure:tools.cli:jar:0.2.2: {}
|
63
|
+
org.slf4j:jul-to-slf4j:jar:1.6.4:
|
64
|
+
org.slf4j:slf4j-api:jar:1.6.4: {}
|
65
|
+
org.clojure:clojure:jar:1.4.0: {}
|
49
66
|
org.codehaus.janino:commons-compiler-jdk:jar:2.6.1:
|
50
67
|
org.codehaus.janino:commons-compiler:jar:2.6.1: {}
|
51
|
-
org.apache.tomcat:tomcat-jdbc:jar:7.0.27:
|
52
|
-
org.apache.tomcat:tomcat-juli:jar:7.0.27: {}
|
53
|
-
org.hornetq:hornetq-core:jar:2.2.2.Final: {}
|
54
|
-
org.slf4j:jcl-over-slf4j:jar:1.6.4: {}
|
55
|
-
org.codehaus.jackson:jackson-core-asl:jar:1.8.0: {}
|
56
|
-
net.java.dev.jets3t:jets3t:jar:0.8.1:
|
57
|
-
com.jamesmurty.utils:java-xmlbuilder:jar:0.4: {}
|
58
|
-
commons-httpclient:commons-httpclient:jar:3.1: {}
|
59
|
-
commons-codec:commons-codec:jar:1.3: {}
|
60
|
-
org.slf4j:log4j-over-slf4j:jar:1.6.4: {}
|
61
|
-
com.amazonaws:aws-java-sdk:jar:1.3.0: {}
|
62
|
-
org.apache.httpcomponents:httpclient:jar:4.2-alpha1:
|
63
|
-
org.apache.httpcomponents:httpcore:jar:4.2-alpha2: {}
|
64
68
|
runtime:
|
65
69
|
dependencies:
|
66
70
|
- com.amazonaws:aws-java-sdk:jar:1.3.0
|
67
|
-
- com.datomic:datomic-free:jar:0.8.
|
71
|
+
- com.datomic:datomic-free:jar:0.8.3655
|
68
72
|
- com.google.code.findbugs:jsr305:jar:1.3.9
|
69
73
|
- com.google.guava:guava:jar:12.0.1
|
70
74
|
- com.h2database:h2:jar:1.3.165
|
@@ -79,9 +83,11 @@ groups:
|
|
79
83
|
- org.apache.tomcat:tomcat-juli:jar:7.0.27
|
80
84
|
- org.clojure:clojure:jar:1.4.0
|
81
85
|
- org.clojure:data.json:jar:0.1.2
|
86
|
+
- org.clojure:tools.cli:jar:0.2.2
|
82
87
|
- org.codehaus.jackson:jackson-core-asl:jar:1.8.0
|
83
88
|
- org.codehaus.janino:commons-compiler-jdk:jar:2.6.1
|
84
89
|
- org.codehaus.janino:commons-compiler:jar:2.6.1
|
90
|
+
- org.fressian:fressian:jar:0.6.3
|
85
91
|
- org.hornetq:hornetq-core:jar:2.2.2.Final
|
86
92
|
- org.jboss.netty:netty:jar:3.2.4.Final
|
87
93
|
- org.slf4j:jcl-over-slf4j:jar:1.6.4
|
@@ -92,35 +98,37 @@ groups:
|
|
92
98
|
- postgresql:postgresql:jar:9.1-901.jdbc4
|
93
99
|
- spy:spymemcached:jar:2.8.1
|
94
100
|
artifacts:
|
95
|
-
- jar:com.datomic:datomic-free:jar:0.8.
|
101
|
+
- jar:com.datomic:datomic-free:jar:0.8.3655:
|
96
102
|
transitive:
|
97
|
-
com.h2database:h2:jar:1.3.165: {}
|
98
|
-
org.apache.lucene:lucene-core:jar:3.3.0: {}
|
99
103
|
postgresql:postgresql:jar:9.1-901.jdbc4: {}
|
104
|
+
org.codehaus.jackson:jackson-core-asl:jar:1.8.0: {}
|
105
|
+
org.slf4j:log4j-over-slf4j:jar:1.6.4: {}
|
106
|
+
net.java.dev.jets3t:jets3t:jar:0.8.1:
|
107
|
+
com.jamesmurty.utils:java-xmlbuilder:jar:0.4: {}
|
108
|
+
commons-httpclient:commons-httpclient:jar:3.1: {}
|
109
|
+
org.hornetq:hornetq-core:jar:2.2.2.Final: {}
|
110
|
+
org.slf4j:jcl-over-slf4j:jar:1.6.4: {}
|
100
111
|
spy:spymemcached:jar:2.8.1: {}
|
101
|
-
org.
|
102
|
-
|
103
|
-
|
112
|
+
org.apache.tomcat:tomcat-jdbc:jar:7.0.27:
|
113
|
+
org.apache.tomcat:tomcat-juli:jar:7.0.27: {}
|
114
|
+
com.h2database:h2:jar:1.3.165: {}
|
115
|
+
org.apache.httpcomponents:httpclient:jar:4.2-alpha1:
|
116
|
+
org.apache.httpcomponents:httpcore:jar:4.2-alpha2: {}
|
117
|
+
com.amazonaws:aws-java-sdk:jar:1.3.0:
|
118
|
+
commons-codec:commons-codec:jar:1.3: {}
|
119
|
+
org.fressian:fressian:jar:0.6.3: {}
|
120
|
+
org.slf4j:slf4j-nop:jar:1.6.4: {}
|
121
|
+
org.apache.lucene:lucene-core:jar:3.3.0: {}
|
104
122
|
com.google.guava:guava:jar:12.0.1:
|
105
123
|
com.google.code.findbugs:jsr305:jar:1.3.9: {}
|
106
124
|
org.clojure:data.json:jar:0.1.2: {}
|
107
|
-
org.slf4j:slf4j-nop:jar:1.6.4: {}
|
108
125
|
org.jboss.netty:netty:jar:3.2.4.Final: {}
|
126
|
+
org.clojure:tools.cli:jar:0.2.2: {}
|
127
|
+
org.slf4j:jul-to-slf4j:jar:1.6.4:
|
128
|
+
org.slf4j:slf4j-api:jar:1.6.4: {}
|
129
|
+
org.clojure:clojure:jar:1.4.0: {}
|
109
130
|
org.codehaus.janino:commons-compiler-jdk:jar:2.6.1:
|
110
131
|
org.codehaus.janino:commons-compiler:jar:2.6.1: {}
|
111
|
-
org.apache.tomcat:tomcat-jdbc:jar:7.0.27:
|
112
|
-
org.apache.tomcat:tomcat-juli:jar:7.0.27: {}
|
113
|
-
org.hornetq:hornetq-core:jar:2.2.2.Final: {}
|
114
|
-
org.slf4j:jcl-over-slf4j:jar:1.6.4: {}
|
115
|
-
org.codehaus.jackson:jackson-core-asl:jar:1.8.0: {}
|
116
|
-
net.java.dev.jets3t:jets3t:jar:0.8.1:
|
117
|
-
com.jamesmurty.utils:java-xmlbuilder:jar:0.4: {}
|
118
|
-
commons-httpclient:commons-httpclient:jar:3.1: {}
|
119
|
-
commons-codec:commons-codec:jar:1.3: {}
|
120
|
-
org.slf4j:log4j-over-slf4j:jar:1.6.4: {}
|
121
|
-
com.amazonaws:aws-java-sdk:jar:1.3.0: {}
|
122
|
-
org.apache.httpcomponents:httpclient:jar:4.2-alpha1:
|
123
|
-
org.apache.httpcomponents:httpcore:jar:4.2-alpha2: {}
|
124
132
|
remote_repositories:
|
125
133
|
- http://clojars.org/repo/
|
126
134
|
- https://repository.jboss.org/nexus/content/groups/public/
|
data/README.md
CHANGED
@@ -14,6 +14,14 @@ recommend them for help with your corporate projects.
|
|
14
14
|
|
15
15
|
Special thanks to Mongoid for writing some solid ORM code that was liberally borrowed from to add Rails support to Diametric.
|
16
16
|
|
17
|
+
## Documents
|
18
|
+
|
19
|
+
Other than highlights below, there are documents on Wiki.
|
20
|
+
|
21
|
+
- [Getting Started](https://github.com/relevance/diametric/wiki/Getting-Started)
|
22
|
+
- [Rails Integration](https://github.com/relevance/diametric/wiki/Rails-Integration-%28Experimental%29)
|
23
|
+
|
24
|
+
|
17
25
|
## Entity API
|
18
26
|
|
19
27
|
The `Entity` module is interesting, in that it is primarily made of
|
@@ -133,34 +141,43 @@ query.data
|
|
133
141
|
|
134
142
|
## Persistence API
|
135
143
|
|
136
|
-
The persistence API comes in two flavors: REST- and peer-based.
|
144
|
+
The persistence API comes in two flavors: REST- and peer-based.
|
145
|
+
For the most part, they have the same API.
|
146
|
+
|
147
|
+
The suitable persistent module will be selected based on URI to connect datomic.
|
148
|
+
You don't need to care which module should be included.
|
149
|
+
However, if you like to inlcude REST or Peer module explicitely, you can write it.
|
150
|
+
|
137
151
|
|
138
152
|
### Peer
|
139
153
|
|
140
|
-
With
|
154
|
+
With Peer connection, you can create objects that know how to store themselves to Datomic through a Datomic peer.
|
141
155
|
|
142
|
-
|
156
|
+
Peer connection as well as "require `diametric/persistence/peer`" are only available on JRuby.
|
157
|
+
When you install the `diametric` gem with JRuby, all `.jar` files needed to run Datomic will be downloaded.
|
143
158
|
|
144
159
|
```ruby
|
145
160
|
require 'diametric'
|
146
|
-
require 'diametric/persistence
|
161
|
+
require 'diametric/persistence'
|
147
162
|
|
148
163
|
# database URI
|
149
164
|
# will create database if it does not already exist
|
150
|
-
Diametric::Persistence
|
165
|
+
Diametric::Persistence.establish_base_connection({:uri=>'datomic:mem://sample'})
|
151
166
|
```
|
152
167
|
|
153
168
|
### REST
|
154
169
|
|
155
|
-
With
|
170
|
+
With REST connection, you can create objects that know how to store themselves to Datomic through the Datomic REST API.
|
171
|
+
REST connection is available both on CRuby and JRuby.
|
172
|
+
You need to download Datomic by yourself and start the server before you run the code.
|
156
173
|
|
157
174
|
```ruby
|
158
175
|
require 'diametric'
|
159
|
-
require 'diametric/persistence
|
176
|
+
require 'diametric/persistence'
|
160
177
|
|
161
178
|
# database url, database alias, database name
|
162
179
|
# will create database if it does not already exist
|
163
|
-
Diametric::Persistence
|
180
|
+
Diametric::Persistence.establish_base_connection({:uri => 'http://localhost:9000', :storage => 'free', :database => 'sample'})
|
164
181
|
```
|
165
182
|
|
166
183
|
### Using persisted models
|
@@ -168,8 +185,7 @@ Diametric::Persistence::REST.connect('http://localhost:9000', 'free', 'animals')
|
|
168
185
|
```ruby
|
169
186
|
class Goat
|
170
187
|
include Diametric::Entity
|
171
|
-
include Diametric::Persistence
|
172
|
-
include Diametric::Persistence::Peer # if using JRuby and not using REST
|
188
|
+
include Diametric::Persistence
|
173
189
|
|
174
190
|
attribute :name, String, :index => true
|
175
191
|
attribute :age, Integer
|
data/lib/diametric.rb
CHANGED
data/lib/diametric/entity.rb
CHANGED
@@ -239,6 +239,16 @@ module Diametric
|
|
239
239
|
def namespace(ns, attribute)
|
240
240
|
[ns.to_s, attribute.to_s].join("/").to_sym
|
241
241
|
end
|
242
|
+
|
243
|
+
# Raise an error if validation failed.
|
244
|
+
#
|
245
|
+
# @example Raise the validation error.
|
246
|
+
# Person.fail_validate!(person)
|
247
|
+
#
|
248
|
+
# @param [ Entity ] entity The entity to fail.
|
249
|
+
def fail_validate!(entity)
|
250
|
+
raise Errors::ValidationError.new(entity)
|
251
|
+
end
|
242
252
|
|
243
253
|
private
|
244
254
|
|
@@ -340,6 +350,13 @@ module Diametric
|
|
340
350
|
txes << [:"db/add", (dbid || tempid) , namespaced_attribute, protractions.to_a] unless protractions.empty?
|
341
351
|
txes
|
342
352
|
end
|
353
|
+
|
354
|
+
# Returns hash of all attributes for this object
|
355
|
+
#
|
356
|
+
# @return [Hash<Symbol, object>] Hash of atrributes
|
357
|
+
def attributes
|
358
|
+
Hash[self.class.attribute_names.map {|attribute_name| [attribute_name, self.send(attribute_name)] }]
|
359
|
+
end
|
343
360
|
|
344
361
|
# @return [Array<Symbol>] Names of the entity's attributes.
|
345
362
|
def attribute_names
|
@@ -20,6 +20,19 @@ module Diametric
|
|
20
20
|
end
|
21
21
|
end
|
22
22
|
end
|
23
|
+
|
24
|
+
# Save the entity. If a validation error occurs an error will get raised.
|
25
|
+
#
|
26
|
+
# @example Save the entitiy.
|
27
|
+
# entity.save!
|
28
|
+
#
|
29
|
+
# @return [ true, false ] True if validation passed.
|
30
|
+
def save!
|
31
|
+
unless save
|
32
|
+
self.class.fail_validate!(self) unless errors.empty?
|
33
|
+
end
|
34
|
+
return true
|
35
|
+
end
|
23
36
|
end
|
24
37
|
|
25
38
|
module ClassMethods
|
@@ -82,6 +82,12 @@ module Diametric
|
|
82
82
|
|
83
83
|
extend ClassMethods
|
84
84
|
|
85
|
+
# Save the entity
|
86
|
+
#
|
87
|
+
# @example Save the entity.
|
88
|
+
# entity.save
|
89
|
+
#
|
90
|
+
# @return [ true, false ] True is success, false if not.
|
85
91
|
def save
|
86
92
|
return false unless valid?
|
87
93
|
return true unless changed?
|
@@ -70,6 +70,12 @@ module Diametric
|
|
70
70
|
|
71
71
|
extend ClassMethods
|
72
72
|
|
73
|
+
# Save the entity
|
74
|
+
#
|
75
|
+
# @example Save the entity.
|
76
|
+
# entity.save
|
77
|
+
#
|
78
|
+
# @return [ true, false ] True is success, false if not.
|
73
79
|
def save
|
74
80
|
return false unless valid?
|
75
81
|
return true unless changed?
|
@@ -87,6 +93,10 @@ module Diametric
|
|
87
93
|
res
|
88
94
|
end
|
89
95
|
|
96
|
+
def to_edn
|
97
|
+
self.dbid
|
98
|
+
end
|
99
|
+
|
90
100
|
def retract_entity(dbid)
|
91
101
|
query = [[:"db.fn/retractEntity", dbid.to_i]]
|
92
102
|
self.class.transact(query)
|
data/lib/diametric/version.rb
CHANGED
@@ -86,6 +86,22 @@ describe Diametric::Entity do
|
|
86
86
|
subject.name = "Clinton"
|
87
87
|
subject.name.should == "Clinton"
|
88
88
|
end
|
89
|
+
|
90
|
+
it "should return attribute names" do
|
91
|
+
subject.attribute_names.should eql(Person.attribute_names)
|
92
|
+
end
|
93
|
+
|
94
|
+
it "should return a hash of attributes" do
|
95
|
+
attributes = subject.attributes
|
96
|
+
|
97
|
+
attributes.should be_a Hash
|
98
|
+
attributes.keys.should eql(subject.attribute_names)
|
99
|
+
attributes[:middle_name].should eql("Danger")
|
100
|
+
end
|
101
|
+
|
102
|
+
it "should raise a validation error" do
|
103
|
+
expect { Robin.new.save! }.to raise_error(Diametric::Errors::ValidationError)
|
104
|
+
end
|
89
105
|
|
90
106
|
end
|
91
107
|
|
data/spec/integration_spec.rb
CHANGED
@@ -70,6 +70,16 @@ describe Diametric::Entity, :integration => true do
|
|
70
70
|
end
|
71
71
|
|
72
72
|
let(:query) { Diametric::Query.new(Robin) }
|
73
|
+
it "can create entity" do
|
74
|
+
robin = Robin.new
|
75
|
+
|
76
|
+
expect { robin.save! }.to raise_error(Diametric::Errors::ValidationError)
|
77
|
+
robin.save.should be_false
|
78
|
+
robin.name = "Mary"
|
79
|
+
robin.age = 3
|
80
|
+
expect { robin.save! }.to_not raise_error(Diametric::Errors::ValidationError)
|
81
|
+
robin.persisted?.should be_true
|
82
|
+
end
|
73
83
|
it "can update entity" do
|
74
84
|
robin = Robin.new(:name => "Mary", :age => 2)
|
75
85
|
robin.save
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: diametric
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2012-
|
14
|
+
date: 2012-12-22 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: edn
|
@@ -119,6 +119,7 @@ files:
|
|
119
119
|
- lib/diametric/config/environment.rb
|
120
120
|
- lib/diametric/config.rb
|
121
121
|
- lib/diametric/entity.rb
|
122
|
+
- lib/diametric/errors.rb
|
122
123
|
- lib/diametric/generators/active_model.rb
|
123
124
|
- lib/diametric/persistence/common.rb
|
124
125
|
- lib/diametric/persistence/peer.rb
|
@@ -154,21 +155,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
154
155
|
- - ! '>='
|
155
156
|
- !ruby/object:Gem::Version
|
156
157
|
version: '0'
|
157
|
-
segments:
|
158
|
-
- 0
|
159
|
-
hash: -448457445775991460
|
160
158
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
161
159
|
none: false
|
162
160
|
requirements:
|
163
161
|
- - ! '>='
|
164
162
|
- !ruby/object:Gem::Version
|
165
163
|
version: '0'
|
166
|
-
segments:
|
167
|
-
- 0
|
168
|
-
hash: -448457445775991460
|
169
164
|
requirements: []
|
170
165
|
rubyforge_project:
|
171
|
-
rubygems_version: 1.8.
|
166
|
+
rubygems_version: 1.8.23
|
172
167
|
signing_key:
|
173
168
|
specification_version: 3
|
174
169
|
summary: ActiveModel for Datomic
|