Class: ActiveRubic::Cacher

Inherits:
MysqlCache::Base
  • Object
show all
Defined in:
lib/active_rubic/cacher.rb

Overview

:nodoc:

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.read(query, options = {}) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/active_rubic/cacher.rb', line 17

def read( query, options={} )

  case query
  when :all

  db_result = @@rails_db.connection.execute("SELECT * FROM #{table}s")

  results = Array.new
  db_result.each_hash do |h|
    uri = h[ 'uri' ]
    results << RDFS::Resource.new( uri ) if uri
  end

  when RDFS::label

    return [ "my label from mysql" ]

  when :images

    @@rails_db.connection.execute("SELECT i.full, i.preview, i.thumb, i.original, i.license, i.photographer, i.date, l.fi AS label_fi, l.en AS label_en, d.fi AS description_fi, d.en AS description_en, g.lat, g.lon FROM images AS i LEFT JOIN (labels AS l, descriptions AS d, geopoints AS g) ON (i.label=l.id AND i.description=d.id AND i.geopoint=g.id), (SELECT id, uri FROM rdf_resources) AS rdf_r, (SELECT image_id, rdf_resource_id FROM image_rdf_resource) AS i_rdf_r WHERE rdf_r.uri = 'http://testi/uri3' AND i_rdf_r.image_id = i.id AND i_rdf_r.rdf_resource_id = rdf_r.id;")

    return [ "my images from mysql" ]

  when :random_image

    @@rails_db.connection.execute("SELECT i.full, i.preview, i.thumb, i.original, i.license, i.photographer, i.date, l.fi AS label_fi, l.en AS label_en, d.fi AS description_fi, d.en AS description_en, g.lat, g.lon FROM images AS i LEFT JOIN (labels AS l, descriptions AS d, geopoints AS g) ON (i.label=l.id AND i.description=d.id AND i.geopoint=g.id), (SELECT id, uri FROM rdf_resources) AS rdf_r, (SELECT image_id, rdf_resource_id FROM image_rdf_resource) AS i_rdf_r WHERE rdf_r.uri = 'http://testi/uri3' AND i_rdf_r.image_id = i.id AND i_rdf_r.rdf_resource_id = rdf_r.id ORDER BY RAND() LIMIT 1;")

  when :properties

    @@rails_db.connection.execute("p.uri, l.fi AS label_fi, l.en AS label_en FROM property AS p LEFT JOIN (labels AS l) ON (p.label=l.id) WHERE p.uri = 'http://testi/property';");

    return [ "my properties from mysql" ]

  when :parents

    @@rails_db.connection.execute("SELECT sc.uri FROM rdf_resources AS sc, (SELECT id, uri FROM rdf_resources) as rdf_r, (SELECT * FROM rdf_resource_superclass_rdf_resource) AS schelp WHERE rdf_r.uri = 'http://testi/uri2' AND rdf_r.id = schelp.rdf_resource_id AND sc.id = schelp.superclass_rdf_resource_id")

  when :instances_of

    @@rails_db.connection.execute("SELECT inst.uri FROM rdf_resources AS inst, (SELECT id, uri FROM rdf_resources) as rdf_r, (SELECT * FROM rdf_resource_instance_rdf_resource) AS insthelp WHERE rdf_r.uri = 'http://testi/uri2' AND rdf_r.id = insthelp.rdf_resource_id AND inst.id = insthelp.instance_rdf_resource_id;")

  when :range

    @@rails_db.connection.execute("SELECT rdf_r.uri FROM rdf_resources AS rdf_r, (SELECT id, uri FROM property) as p, (SELECT * FROM rdf_resource_range) AS rangehelp WHERE p.uri = 'http://testi/property' AND rdf_r.id = rangehelp.rdf_resource_id AND p.id = rangehelp.property_id;")

  when :domain

    @@rails_db.connection.execute("SELECT rdf_r.uri FROM rdf_resources AS rdf_r, (SELECT id, uri FROM property) as p, (SELECT * FROM rdf_resource_domain) AS domainhelp WHERE p.uri = 'http://testi/property' AND rdf_r.id = domainhelp.rdf_resource_id AND p.id = domainhelp.property_id;")

  end

end

Instance Method Details

#createObject



6
7
8
# File 'lib/active_rubic/cacher.rb', line 6

def create
  MysqlCache::Base.create_db_index
end

#set_options(options = {}) ⇒ Object



9
10
11
12
13
# File 'lib/active_rubic/cacher.rb', line 9

def set_options( options={} )
  if options[ :use_rubic ]
    MysqlCache::Base.use_rubic options[ :use_rubic ]
  end
end

#versionObject



3
4
5
# File 'lib/active_rubic/cacher.rb', line 3

def version
  MysqlCache::Base.version
end