// Path: src/main/java/org/springframework/social/salesforce/api/QueryOperations.java
// public interface QueryOperations {
// 
//     /**
//      * Execute SOQL query and return the first page of results
//      * 
//      * @param query The SOQL query to execute
//      * @return QueryResult
//      */
//     QueryResult query(String query);
// 
//     /**
//      * Execute SOQL query and return the first page of results
//      *
//      * @param query The SOQL query to execute
//      * @param includeDeletedItems if result should include deleted items
//      * documentation https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/dome_queryall.htm
//      * @return QueryResult
//      */
//     QueryResult query(String query, boolean includeDeletedItems);
// 
//     /*
//      * Retrieve next page of results based on argument from url (usually from query result "nextRecordsUrl")
//      */
//     QueryResult nextPage(String urlOrToken);
//     
//     /**
//      * Execute SOQL query and return all results.
//      * 
//      * @param query The SOQL query to execute
//      * @return QueryResult
//      */
//     QueryResult queryAll(String query);
// 
// }
// 
// Path: src/main/java/org/springframework/social/salesforce/api/QueryResult.java
// public class QueryResult {
// 
//     private int totalSize;
// 
//     private boolean done;
// 
//     private String nextRecordsUrl;
// 
//     private List<ResultItem> records;
// 
// 
//     public QueryResult(int totalSize, boolean done) {
//         this.totalSize = totalSize;
//         this.done = done;
//     }
// 
// 
//     public int getTotalSize() {
//         return totalSize;
//     }
// 
//     public boolean isDone() {
//         return done;
//     }
// 
//     public List<ResultItem> getRecords() {
//         return records;
//     }
// 
//     public void setRecords(List<ResultItem> records) {
//         this.records = records;
//     }
// 
//     public String getNextRecordsUrl() {
//         return nextRecordsUrl;
//     }
// 
//     public void setNextRecordsUrl(String nextRecordsUrl) {
//         this.nextRecordsUrl = nextRecordsUrl;
//     }
// 
//     public String getNextRecordsToken() {
//         if (this.nextRecordsUrl != null) {
//             return this.nextRecordsUrl.substring(this.nextRecordsUrl.lastIndexOf('/') + 1, this.nextRecordsUrl.length());
//         }
//         return null;
//     }
// 
// }
// 
// Path: src/main/java/org/springframework/social/salesforce/api/Salesforce.java
// public interface Salesforce extends ApiBinding {
// 
//     public ApiOperations apiOperations();
// 
//     public ApiOperations apiOperations(String instanceUrl);
// 
//     public ChatterOperations chatterOperations();
// 
//     public ChatterOperations chatterOperations(String instanceUrl);
// 
//     public QueryOperations queryOperations();
// 
//     public QueryOperations queryOperations(String instanceUrl);
// 
//     public RecentOperations recentOperations();
// 
//     public RecentOperations recentOperations(String instanceUrl);
// 
//     public SearchOperations searchOperations();
// 
//     public SearchOperations searchOperations(String instanceUrl);
// 
//     public SObjectOperations sObjectsOperations();
// 
//     public SObjectOperations sObjectsOperations(String instanceUrl);
// 
//     public UserOperations userOperations();
// 
//     public UserOperations userOperations(String gatewayUrl);
// 
//     public LimitsOperations limitsOperations();
// 
//     public LimitsOperations limitsOperations(String instanceUrl);
// 
//     public <T> List<T> readList(JsonNode jsonNode, Class<T> type);
// 
//     public <T> T readObject(JsonNode jsonNode, Class<T> type);
// 
//     public String getBaseUrl();
// 
//     public String getInstanceUrl();
// 
//     public void setInstanceUrl(String instanceUrl);
// 
//     public String getUserInfoUrl();
// 
//     public String getAuthGatewayUrl();
// 
//     public void setAuthGatewayBaseUrl(String gatewayUrl);
// 
//     public ConnectOperations connectOperations();
// 
//     public ConnectOperations connectOperations(String instanceUrl);
//     
//     public CustomApiOperations customApiOperations();
// 
//     public CustomApiOperations customApiOperations(String instanceUrl);
// }


import java.net.URI;
import org.apache.commons.lang3.StringUtils;
import org.springframework.social.salesforce.api.QueryOperations;
import org.springframework.social.salesforce.api.QueryResult;
import org.springframework.social.salesforce.api.Salesforce;
import org.springframework.social.support.URIBuilder;
import org.springframework.web.client.RestTemplate;
/**
 * Copyright (C) 2017 https://github.com/jottley/spring-social-salesforce
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.springframework.social.salesforce.api.impl;



/**
 * Default implementation of QueryOperations.
 * 
 * @author Umut Utkan
 * @author Jared Ottley
 */
public class QueryTemplate extends AbstractSalesForceOperations<Salesforce> implements QueryOperations {

    private RestTemplate restTemplate;

    public QueryTemplate(Salesforce api, RestTemplate restTemplate) {
        super(api);
        this.restTemplate = restTemplate;
    }

    @Override
// Path: src/main/java/org/springframework/social/salesforce/api/QueryOperations.java
// public interface QueryOperations {
// 
//     /**
//      * Execute SOQL query and return the first page of results
//      * 
//      * @param query The SOQL query to execute
//      * @return QueryResult
//      */
//     QueryResult query(String query);
// 
//     /**
//      * Execute SOQL query and return the first page of results
//      *
//      * @param query The SOQL query to execute
//      * @param includeDeletedItems if result should include deleted items
//      * documentation https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/dome_queryall.htm
//      * @return QueryResult
//      */
//     QueryResult query(String query, boolean includeDeletedItems);
// 
//     /*
//      * Retrieve next page of results based on argument from url (usually from query result "nextRecordsUrl")
//      */
//     QueryResult nextPage(String urlOrToken);
//     
//     /**
//      * Execute SOQL query and return all results.
//      * 
//      * @param query The SOQL query to execute
//      * @return QueryResult
//      */
//     QueryResult queryAll(String query);
// 
// }
// 
// Path: src/main/java/org/springframework/social/salesforce/api/QueryResult.java
// public class QueryResult {
// 
//     private int totalSize;
// 
//     private boolean done;
// 
//     private String nextRecordsUrl;
// 
//     private List<ResultItem> records;
// 
// 
//     public QueryResult(int totalSize, boolean done) {
//         this.totalSize = totalSize;
//         this.done = done;
//     }
// 
// 
//     public int getTotalSize() {
//         return totalSize;
//     }
// 
//     public boolean isDone() {
//         return done;
//     }
// 
//     public List<ResultItem> getRecords() {
//         return records;
//     }
// 
//     public void setRecords(List<ResultItem> records) {
//         this.records = records;
//     }
// 
//     public String getNextRecordsUrl() {
//         return nextRecordsUrl;
//     }
// 
//     public void setNextRecordsUrl(String nextRecordsUrl) {
//         this.nextRecordsUrl = nextRecordsUrl;
//     }
// 
//     public String getNextRecordsToken() {
//         if (this.nextRecordsUrl != null) {
//             return this.nextRecordsUrl.substring(this.nextRecordsUrl.lastIndexOf('/') + 1, this.nextRecordsUrl.length());
//         }
//         return null;
//     }
// 
// }
// 
// Path: src/main/java/org/springframework/social/salesforce/api/Salesforce.java
// public interface Salesforce extends ApiBinding {
// 
//     public ApiOperations apiOperations();
// 
//     public ApiOperations apiOperations(String instanceUrl);
// 
//     public ChatterOperations chatterOperations();
// 
//     public ChatterOperations chatterOperations(String instanceUrl);
// 
//     public QueryOperations queryOperations();
// 
//     public QueryOperations queryOperations(String instanceUrl);
// 
//     public RecentOperations recentOperations();
// 
//     public RecentOperations recentOperations(String instanceUrl);
// 
//     public SearchOperations searchOperations();
// 
//     public SearchOperations searchOperations(String instanceUrl);
// 
//     public SObjectOperations sObjectsOperations();
// 
//     public SObjectOperations sObjectsOperations(String instanceUrl);
// 
//     public UserOperations userOperations();
// 
//     public UserOperations userOperations(String gatewayUrl);
// 
//     public LimitsOperations limitsOperations();
// 
//     public LimitsOperations limitsOperations(String instanceUrl);
// 
//     public <T> List<T> readList(JsonNode jsonNode, Class<T> type);
// 
//     public <T> T readObject(JsonNode jsonNode, Class<T> type);
// 
//     public String getBaseUrl();
// 
//     public String getInstanceUrl();
// 
//     public void setInstanceUrl(String instanceUrl);
// 
//     public String getUserInfoUrl();
// 
//     public String getAuthGatewayUrl();
// 
//     public void setAuthGatewayBaseUrl(String gatewayUrl);
// 
//     public ConnectOperations connectOperations();
// 
//     public ConnectOperations connectOperations(String instanceUrl);
//     
//     public CustomApiOperations customApiOperations();
// 
//     public CustomApiOperations customApiOperations(String instanceUrl);
// }


// Path: src/main/java/org/springframework/social/salesforce/api/impl/QueryTemplate.java
import java.net.URI;
import org.apache.commons.lang3.StringUtils;
import org.springframework.social.salesforce.api.QueryOperations;
import org.springframework.social.salesforce.api.QueryResult;
import org.springframework.social.salesforce.api.Salesforce;
import org.springframework.social.support.URIBuilder;
import org.springframework.web.client.RestTemplate;

/**
 * Copyright (C) 2017 https://github.com/jottley/spring-social-salesforce
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.springframework.social.salesforce.api.impl;



/**
 * Default implementation of QueryOperations.
 * 
 * @author Umut Utkan
 * @author Jared Ottley
 */
public class QueryTemplate extends AbstractSalesForceOperations<Salesforce> implements QueryOperations {

    private RestTemplate restTemplate;

    public QueryTemplate(Salesforce api, RestTemplate restTemplate) {
        super(api);
        this.restTemplate = restTemplate;
    }

    @Override
    public QueryResult query(String query) {