public boolean queryMore() throws KettleException { try { // check the done attribute on the QueryResult and call QueryMore // with the QueryLocator if there are more records to be retrieved if ( !getQueryResult().isDone() ) { this.qr = getBinding().queryMore( getQueryResult().getQueryLocator() ); this.sObjects = getQueryResult().getRecords(); if ( this.sObjects != null ) { this.recordsCount = this.sObjects.length; } this.queryResultSize = getQueryResult().getSize(); return true; } else { // Query is done .. we finished ! return false; } } catch ( Exception e ) { throw new KettleException( BaseMessages.getString( PKG, "SalesforceInput.Error.QueringMore" ), e ); } }
@Override public com.sforce.soap.partner.IQueryResult queryMore(java.lang.String queryLocator) throws com.sforce.ws.ConnectionException { return connection.queryMore( queryLocator); }
@Override public boolean next() { final int index = _recordIndex.getAndIncrement(); if (index >= _records.length) { if (_queryResult.isDone()) { _record = null; return false; } // go to next page String queryLocator = _queryResult.getQueryLocator(); try { _queryResult = _connection.queryMore(queryLocator); _records = _queryResult.getRecords(); _recordIndex.set(0); return next(); } catch (ConnectionException e) { throw SalesforceUtils.wrapException(e, "Failed to invoke queryMore service"); } } _record = _records[index]; return true; }
@Override public boolean next() { final int index = _recordIndex.getAndIncrement(); if (index >= _records.length) { if (_queryResult.isDone()) { _record = null; return false; } // go to next page String queryLocator = _queryResult.getQueryLocator(); try { _queryResult = _connection.queryMore(queryLocator); _records = _queryResult.getRecords(); _recordIndex.set(0); return next(); } catch (ConnectionException e) { throw SalesforceUtils.wrapException(e, "Failed to invoke queryMore service"); } } _record = _records[index]; return true; }
@Override public boolean next() { final int index = _recordIndex.getAndIncrement(); if (index >= _records.length) { if (_queryResult.isDone()) { _record = null; return false; } // go to next page String queryLocator = _queryResult.getQueryLocator(); try { _queryResult = _connection.queryMore(queryLocator); _records = _queryResult.getRecords(); _recordIndex.set(0); return next(); } catch (ConnectionException e) { throw SalesforceUtils.wrapException(e, "Failed to invoke queryMore service"); } } _record = _records[index]; return true; }
@Override public boolean advance() throws IOException { inputRecordsIndex++; // Fast return conditions. if (inputRecordsIndex < inputRecords.length) { dataCount++; return true; } if (inputResult.isDone()) { return false; } try { inputResult = getConnection().queryMore(inputResult.getQueryLocator()); inputRecords = inputResult.getRecords(); inputRecordsIndex = 0; return inputResult.getSize() > 0; } catch (ConnectionException e) { // Wrap the exception in an IOException. throw new IOException(e); } }
@Override public boolean start() throws IOException { try { result = getResult(); queryStringList = getQueryStringList(result); if (queryStringList.size() == 0) { return false; } inputResult = getConnection().queryAll(queryStringList.get(queryIndex++)); inputRecords = inputResult.getRecords(); while (!inputResult.isDone()) { inputResult = getConnection().queryMore(inputResult.getQueryLocator()); inputRecords = ArrayUtils.addAll(inputRecords, inputResult.getRecords()); } inputRecordsIndex = 0; } catch (ConnectionException e) { throw new IOException(e); } boolean startable = inputRecords.length > 0; if (startable) { dataCount++; } return startable; }
@Override public boolean advance() throws IOException { inputRecordsIndex++; // Fast return conditions. if (inputRecordsIndex < inputRecords.length) { dataCount++; return true; } if (inputResult.isDone()) { return false; } try { // Get a new result set based on batch size inputResult = getConnection().queryMore(inputResult.getQueryLocator()); inputRecords = inputResult.getRecords(); inputRecordsIndex = 0; boolean advance = inputResult.getSize() > 0; if (advance) { // New result set available to retrieve dataCount++; } return advance; } catch (ConnectionException e) { // Wrap the exception in an IOException. throw new IOException(e); } }
@Override public boolean start() throws IOException { try { result = getResult(); queryStringList = getQueryStringList(result); if (queryStringList.size() == 0) { return false; } inputResult = getConnection().queryAll(queryStringList.get(queryIndex++)); inputRecords = inputResult.getRecords(); while (!inputResult.isDone()) { inputResult = getConnection().queryMore(inputResult.getQueryLocator()); inputRecords = ArrayUtils.addAll(inputRecords, inputResult.getRecords()); } inputRecordsIndex = 0; } catch (ConnectionException e) { throw new IOException(e); } boolean startable = inputRecords.length > 0; if (startable) { dataCount++; } return startable; }
@Override public boolean advance() throws IOException { inputRecordsIndex++; // Fast return conditions. if (inputRecordsIndex < inputRecords.length) { dataCount++; return true; } if (inputResult.isDone()) { return false; } try { // Get a new result set based on batch size inputResult = getConnection().queryMore(inputResult.getQueryLocator()); inputRecords = inputResult.getRecords(); inputRecordsIndex = 0; boolean advance = inputResult.getSize() > 0; if (advance) { // New result set available to retrieve dataCount++; } return advance; } catch (ConnectionException e) { // Wrap the exception in an IOException. throw new IOException(e); } }
@Override public boolean advance() throws IOException { inputRecordsIndex++; // Fast return conditions. if (inputRecordsIndex < inputRecords.length) { dataCount++; return true; } if ((inputResult == null || inputResult.isDone()) && queryIndex < queryStringList.size()) { try { inputResult = getConnection().queryAll(queryStringList.get(queryIndex++)); inputRecords = inputResult.getRecords(); while (!inputResult.isDone()) { inputResult = getConnection().queryMore(inputResult.getQueryLocator()); inputRecords = ArrayUtils.addAll(inputRecords, inputResult.getRecords()); } inputRecordsIndex = 0; boolean isAdvanced = inputResult.getSize() > 0; if (isAdvanced) { dataCount++; } return isAdvanced; } catch (ConnectionException e) { throw new IOException(e); } } return false; }
@Override public boolean advance() throws IOException { inputRecordsIndex++; // Fast return conditions. if (inputRecordsIndex < inputRecords.length) { dataCount++; return true; } if ((inputResult == null || inputResult.isDone()) && queryIndex < queryStringList.size()) { try { inputResult = getConnection().queryAll(queryStringList.get(queryIndex++)); inputRecords = inputResult.getRecords(); while (!inputResult.isDone()) { inputResult = getConnection().queryMore(inputResult.getQueryLocator()); inputRecords = ArrayUtils.addAll(inputRecords, inputResult.getRecords()); } inputRecordsIndex = 0; boolean isAdvanced = inputResult.getSize() > 0; if (isAdvanced) { dataCount++; } return isAdvanced; } catch (ConnectionException e) { throw new IOException(e); } } return false; }
public QueryResult queryMore(String queryLocator, int batchSize) throws ResourceException { if(batchSize > 2000) { batchSize = 2000; LogManager.logDetail(LogConstants.CTX_CONNECTOR, "reduced.batch.size"); //$NON-NLS-1$ } partnerConnection.setQueryOptions(batchSize); try { return partnerConnection.queryMore(queryLocator); } catch (InvalidFieldFault e) { throw new ResourceException(e); } catch (UnexpectedErrorFault e) { throw new ResourceException(e); } catch (InvalidQueryLocatorFault e) { throw new ResourceException(e); } catch (ConnectionException e) { throw new ResourceException(e); } finally { partnerConnection.clearQueryOptions(); } }
@Override public void execute() throws BuildException { try { PartnerConnection pc = ConnectionFactory.getPartnerConnection(getConfig()); String soql = String.format(FORMAT_SOQL, objectApiName); QueryResult qr = pc.query(soql); Boolean done = false; log(String.format(FORMAT_DELETE_MSG, qr.getSize(), objectApiName)); if (qr.getSize() > 0) { while (!done) { com.sforce.soap.partner.sobject.SObject[] records = qr.getRecords(); String[] ids = new String[records.length]; for (int i = 0; i<records.length; ++i) { ids[i] = (String)records[i].getField("Id"); } pc.delete(ids); if (qr.isDone()) { done = true; } else { qr = pc.queryMore(qr.getQueryLocator()); } } } } catch (ConnectionException e) { handleException(e); } }