class Dynamicloud::API::RecordQuery
Constants
- DEFAULT_COUNT
Public Class Methods
# File lib/dynamic_api.rb, line 29 def initialize(mid) @mid = mid @credentials = nil @order_by = nil @group_by = nil @offset = -1 @count = -1 @current_callback = nil @list_was_called = false @conditions = [] @joins = [] @alias = nil @current_projection = nil end
Public Instance Methods
This method will add a new condition to an AND list of conditions.
@param condition new condition to a list of conditions to use @return this instance of Query
# File lib/dynamic_api.rb, line 93 def add(condition) @conditions.push(condition) self end
Apply a asc ordering to the current order by object An IllegalStateException will be thrown if orderBy object is nil
@return this instance of Query
# File lib/dynamic_api.rb, line 79 def asc if @order_by.nil? raise Exceptions::IllegalStateException, 'You must call order_by method before call this method' end @order_by.asc = true self end
Apply a desc ordering to the current order by object An IllegalStateException will be thrown if orderBy object is nil
@return this instance of Query
# File lib/dynamic_api.rb, line 65 def desc if @order_by.nil? raise Exceptions::IllegalStateException, 'You must call order_by method before call this method' end @order_by.asc = false self end
get the current conditions
@return the conditions
# File lib/dynamic_api.rb, line 186 def get_conditions @conditions end
Gets the current count If count == 0 then will return default count (DEFAULT_COUNT
)
@return the current count
# File lib/dynamic_api.rb, line 130 def get_count @count <= 0 ? DEFAULT_COUNT : @count; end
Gets the current offset so far. This attribute will increase according calls of method next(RecordCallback<T> callback)
@return int of current offset
# File lib/dynamic_api.rb, line 193 def get_current_offset @offset < 0 ? 0 : @offset end
get the current groupBy condition
@return the group by condition
# File lib/dynamic_api.rb, line 226 def get_group_by @group_by end
Returns the current model id associated to this query @return model id
# File lib/dynamic_api.rb, line 206 def get_model_id @mid end
get the current orderBy condition @return the order by condition
# File lib/dynamic_api.rb, line 219 def get_order_by @order_by end
This method will execute a query and returns a list of records @param projection projection to use in this operation
# File lib/dynamic_api.rb, line 136 def get_results(projection = nil) selection = Dynamicloud::API::DynamicloudHelper.build_string(get_conditions, get_group_by, get_order_by, (Dynamicloud::API::DynamicloudHelper.build_projection(projection)), @alias, @joins) @current_projection = projection url = Configuration::PROPERTIES.get_property :url if projection url_get_records = Configuration::PROPERTIES.get_property :url_get_specific_fields else url_get_records = Configuration::PROPERTIES.get_property :url_get_records end url_get_records = url_get_records.gsub '{csk}', URI::encode(@credentials[:csk]) url_get_records = url_get_records.gsub '{aci}', URI::encode(@credentials[:aci]) url_get_records = url_get_records.gsub '{mid}', @mid.to_s url_get_records = url_get_records.gsub '{count}', get_count.to_s url_get_records = url_get_records.gsub '{offset}', get_current_offset.to_s params = { :criteria => selection } response = DynamicService::ServiceCaller.call_service url + url_get_records, params, 'post' Dynamicloud::API::DynamicloudHelper.build_record_results response end
This method create a groupBy condition using attribute
@param attribute attribute by this query will group. @return this instance of Query
# File lib/dynamic_api.rb, line 178 def group_by(attribute) @group_by = Dynamicloud::API::Criteria::GroupByClause.new(attribute) self end
Add a join to the list of joins
@param join_clause join clause @return this instance of Query
# File lib/dynamic_api.rb, line 56 def join(join_clause) @joins.push join_clause self end
Will execute a list operation with an offset += count and will use the same callback object in list method. This method will return a RecordResults
object
# File lib/dynamic_api.rb, line 199 def next @offset = get_current_offset + get_count get_results @current_projection end
This method adds an order by condition. The condition will have an asc ordering by default.
@param attribute attribute by this query will be ordered. @return this instance of Query
# File lib/dynamic_api.rb, line 169 def order_by(attribute) @order_by = Dynamicloud::API::Criteria::OrderByClause.asc(attribute) self end
Attaches a alias to this query, the model in this query will use this alias in Join Clauses or whatever situation where alias is needed.
@param aliass alias to attach @return this instance of Query
# File lib/dynamic_api.rb, line 48 def set_alias(aliass) @alias = aliass end
Sets how many items per page (offset) this def will fetch
@param count how many items @return this instance of Query
# File lib/dynamic_api.rb, line 121 def set_count(count) @count = count self end
Sets the credentials to use
@param credentials credentials to execute operations.
# File lib/dynamic_api.rb, line 213 def set_credentials(credentials) @credentials = credentials end
This method create a groupBy condition using projection
@param attributes projection by this query will group.
# File lib/dynamic_api.rb, line 233 def set_group_by(attributes) @group_by = GroupByClause.new(attributes) end
Sets an offset to this query to indicates the page of a big data result.
@param offset new offset @return this instance of Query
# File lib/dynamic_api.rb, line 112 def set_offset(offset) @offset = offset self end