activerdf 1.6 → 1.6.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +3 -0
- data/lib/active_rdf/objectmanager/resource.rb +38 -3
- data/test/objectmanager/test_resource_reading.rb +36 -8
- data/test/small-one.nt +2 -0
- data/test/small-two.nt +2 -0
- metadata +4 -2
data/CHANGELOG
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
== activerdf (1.6.1) Thu, 19 Apr 2007 22:57:01 +0100
|
2
|
+
* fix bug 107280: add support for full query options (including context) in dynamic finders
|
3
|
+
|
1
4
|
== activerdf (1.6) Thu, 12 Apr 2007 23:12:40 +0100
|
2
5
|
* no need for ObjectManager.construct_classes anymore (classes exist automagically after Namespace.register)
|
3
6
|
* added resource.localname (alias for Namespace.localname(resource))
|
@@ -129,7 +129,15 @@ module RDFS
|
|
129
129
|
if options.include? :where
|
130
130
|
raise ActiveRdfError, "where clause should be hash of predicate => object" unless options[:where].is_a? Hash
|
131
131
|
options[:where].each do |p,o|
|
132
|
-
|
132
|
+
if options.include? :context
|
133
|
+
query.where(:s, p, o, options[:context])
|
134
|
+
else
|
135
|
+
query.where(:s, p, o)
|
136
|
+
end
|
137
|
+
end
|
138
|
+
else
|
139
|
+
if options[:context]
|
140
|
+
query.where(:s, :p, :o, options[:context])
|
133
141
|
end
|
134
142
|
end
|
135
143
|
|
@@ -402,6 +410,7 @@ class DynamicFinderProxy
|
|
402
410
|
@where = nil
|
403
411
|
@value = nil
|
404
412
|
attr_reader :value
|
413
|
+
private(:type)
|
405
414
|
|
406
415
|
# construct proxy from find_by text
|
407
416
|
# foaf::name
|
@@ -457,18 +466,44 @@ class DynamicFinderProxy
|
|
457
466
|
|
458
467
|
# construct and execute finder query
|
459
468
|
def query(*args)
|
469
|
+
# extract options from args or use an empty hash (no options given)
|
470
|
+
options = args.last.is_a?(Hash) ? args.last : {}
|
471
|
+
|
472
|
+
# build query
|
460
473
|
query = Query.new.distinct(:s)
|
461
474
|
@where.each_with_index do |predicate, i|
|
462
|
-
|
475
|
+
# specify where clauses, use context if given
|
476
|
+
if options[:context]
|
477
|
+
query.where(:s, predicate, args[i], options[:context])
|
478
|
+
else
|
479
|
+
query.where(:s, predicate, args[i])
|
480
|
+
end
|
463
481
|
end
|
464
482
|
|
483
|
+
# use sort order if given
|
484
|
+
if options.include? :order
|
485
|
+
sort_predicate = options[:order]
|
486
|
+
query.sort(:sort_value)
|
487
|
+
# add sort predicate where clause unless we have it already
|
488
|
+
query.where(:s, sort_predicate, :sort_value) unless @where.include? sort_predicate
|
489
|
+
end
|
490
|
+
|
491
|
+
if options.include? :reverse_order
|
492
|
+
sort_predicate = options[:reverse_order]
|
493
|
+
query.reverse_sort(:sort_value)
|
494
|
+
query.where(:s, sort_predicate, :sort_value) unless @where.include? sort_predicate
|
495
|
+
end
|
496
|
+
|
497
|
+
query.limit(options[:limit]) if options[:limit]
|
498
|
+
query.offset(options[:offset]) if options[:offset]
|
499
|
+
|
465
500
|
$activerdflog.debug "executing dynamic finder: #{query.to_sp}"
|
466
501
|
|
467
502
|
# store the query results so that caller (Resource.method_missing) can
|
468
503
|
# retrieve them (we cannot return them here, since we were invoked from
|
469
504
|
# the initialize method so all return values are ignored, instead the proxy
|
470
505
|
# itself is returned)
|
471
|
-
@value = query.execute
|
506
|
+
@value = query.execute
|
472
507
|
return value
|
473
508
|
end
|
474
509
|
end
|
@@ -88,16 +88,16 @@ class TestResourceReading < Test::Unit::TestCase
|
|
88
88
|
end
|
89
89
|
|
90
90
|
def test_find_methods
|
91
|
-
assert_equal @eyal, RDFS::Resource.find_by_eye('blue')
|
92
|
-
assert_equal @eyal, RDFS::Resource.find_by_test::eye('blue')
|
91
|
+
assert_equal [@eyal], RDFS::Resource.find_by_eye('blue')
|
92
|
+
assert_equal [@eyal], RDFS::Resource.find_by_test::eye('blue')
|
93
93
|
|
94
|
-
assert_equal @eyal, RDFS::Resource.find_by_age(27)
|
95
|
-
assert_equal @eyal, RDFS::Resource.find_by_test::age(27)
|
94
|
+
assert_equal [@eyal], RDFS::Resource.find_by_age(27)
|
95
|
+
assert_equal [@eyal], RDFS::Resource.find_by_test::age(27)
|
96
96
|
|
97
|
-
assert_equal @eyal, RDFS::Resource.find_by_age_and_eye(27, 'blue')
|
98
|
-
assert_equal @eyal, RDFS::Resource.find_by_test::age_and_test::eye(27, 'blue')
|
99
|
-
assert_equal @eyal, RDFS::Resource.find_by_test::age_and_eye(27, 'blue')
|
100
|
-
assert_equal @eyal, RDFS::Resource.find_by_age_and_test::eye(27, 'blue')
|
97
|
+
assert_equal [@eyal], RDFS::Resource.find_by_age_and_eye(27, 'blue')
|
98
|
+
assert_equal [@eyal], RDFS::Resource.find_by_test::age_and_test::eye(27, 'blue')
|
99
|
+
assert_equal [@eyal], RDFS::Resource.find_by_test::age_and_eye(27, 'blue')
|
100
|
+
assert_equal [@eyal], RDFS::Resource.find_by_age_and_test::eye(27, 'blue')
|
101
101
|
end
|
102
102
|
|
103
103
|
# test for writing if no write adapter is defined (like only sparqls)
|
@@ -106,4 +106,32 @@ class TestResourceReading < Test::Unit::TestCase
|
|
106
106
|
get_read_only_adapter
|
107
107
|
assert_raises(ActiveRdfError) { @eyal.test::age = 18 }
|
108
108
|
end
|
109
|
+
|
110
|
+
def test_finders_with_options
|
111
|
+
ConnectionPool.clear
|
112
|
+
adapter = get_adapter
|
113
|
+
file_one = "#{File.dirname(__FILE__)}/../small-one.nt"
|
114
|
+
file_two = "#{File.dirname(__FILE__)}/../small-two.nt"
|
115
|
+
adapter.load file_one
|
116
|
+
adapter.load file_two
|
117
|
+
|
118
|
+
one = RDFS::Resource.new("file:#{file_one}")
|
119
|
+
two = RDFS::Resource.new("file:#{file_two}")
|
120
|
+
|
121
|
+
assert_equal 2, RDFS::Resource.find.size
|
122
|
+
assert_equal 2, RDFS::Resource.find(:all).size
|
123
|
+
assert_equal 2, RDFS::Resource.find(:all, :limit => 10).size
|
124
|
+
assert_equal 1, RDFS::Resource.find(:all, :limit => 1).size
|
125
|
+
assert_equal 1, RDFS::Resource.find(:all, :context => one).size
|
126
|
+
assert_equal 1, RDFS::Resource.find(:all, :context => one, :limit => 1).size
|
127
|
+
assert_equal 0, RDFS::Resource.find(:all, :context => one, :limit => 0).size
|
128
|
+
|
129
|
+
assert_equal 1, RDFS::Resource.find_by_eye('blue').size
|
130
|
+
assert_equal 1, RDFS::Resource.find_by_eye('blue', :context => one).size
|
131
|
+
assert_equal 0, RDFS::Resource.find_by_eye('blue', :context => two).size
|
132
|
+
|
133
|
+
assert_equal 2, RDFS::Resource.find_by_rdf::type(RDFS::Resource).size
|
134
|
+
assert_equal 1, RDFS::Resource.find_by_rdf::type(RDFS::Resource, :context => one).size
|
135
|
+
assert_equal 1, RDFS::Resource.find_by_eye_and_rdf::type('blue', RDFS::Resource, :context => one).size
|
136
|
+
end
|
109
137
|
end
|
data/test/small-one.nt
ADDED
data/test/small-two.nt
ADDED
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.2
|
|
3
3
|
specification_version: 1
|
4
4
|
name: activerdf
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version:
|
7
|
-
date: 2007-04-
|
6
|
+
version: 1.6.1
|
7
|
+
date: 2007-04-19 00:00:00 +01:00
|
8
8
|
summary: Offers object-oriented access to RDF (with adapters to several datastores).
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -38,6 +38,8 @@ files:
|
|
38
38
|
- test/common.rb
|
39
39
|
- test/test_adapters.rb
|
40
40
|
- test/test_person_data.nt
|
41
|
+
- test/small-one.nt
|
42
|
+
- test/small-two.nt
|
41
43
|
- test/federation/test_federation_manager.rb
|
42
44
|
- test/federation/test_connection_pool.rb
|
43
45
|
- test/objectmanager/test_resource_reading.rb
|