Class: DataMapper::Adapters::AppEngineAdapter::QueryBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/appengine-paginator/datamapper_ext.rb

Instance Method Summary collapse

Instance Method Details

#get_entitiesObject



43
44
45
46
47
48
49
# File 'lib/appengine-paginator/datamapper_ext.rb', line 43

def get_entities
  if is_get?
    Datastore.get(@keys)
  else
    prepare_java_query.collect { |e| e }
  end
end

#old_runObject



41
# File 'lib/appengine-paginator/datamapper_ext.rb', line 41

alias :old_run :run

#prepare_java_queryObject



51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/appengine-paginator/datamapper_ext.rb', line 51

def prepare_java_query
  begin
    chunk_size = FetchOptions::DEFAULT_CHUNK_SIZE
    options    = FetchOptions::Builder.with_chunk_size(
        chunk_size)
    options.limit(@limit) if @limit
    options.offset(@offset) if @offset
    options.cursor(@dm_query.cursor) if @dm_query.respond_to?(:cursor) && @dm_query.cursor
    @query.pquery.as_query_result_list(options)
  rescue java.lang.IllegalArgumentException => ex
    raise ArgumentError, ex.message
  end
end

#runObject



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/appengine-paginator/datamapper_ext.rb', line 65

def run
  resources = old_run

  class << resources;
    def singleton_class;
      self.class;
    end

    ;
  end


  cursor    = prepare_java_query.cursor
  resources.singleton_class.send :define_method, :cursor do
    Paginator::Cursor.new(cursor)
  end

  resources
end