public void close() throws KettleException { try { if ( !getQueryResult().isDone() ) { this.qr.setDone( true ); this.qr = null; } if ( this.sObjects != null ) { this.sObjects = null; } if ( this.binding != null ) { this.binding = null; } if ( this.loginResult != null ) { this.loginResult = null; } if ( this.userInfo != null ) { this.userInfo = null; } if ( this.getDeletedList != null ) { getDeletedList.clear(); getDeletedList = null; } if ( log.isDetailed() ) { log.logDetailed( BaseMessages.getString( PKG, "SalesforceInput.Log.ConnectionClosed" ) ); } } catch ( Exception e ) { throw new KettleException( BaseMessages.getString( PKG, "SalesforceInput.Error.ClosingConnection" ), e ); } }
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 ); } }
private List<Object> getRow(QueryResult result) throws TranslatorException { List<Object> row; if(null == resultBatch) { loadBatch(); } if(resultBatch.size() == topResultIndex) { row = null; } else { row = resultBatch.get(topResultIndex); topResultIndex++; if(resultBatch.size() == topResultIndex) { if(!result.isDone()) { loadBatch(); } } } return row; }
@Override protected Number executeCountQuery(Table table, List<FilterItem> whereItems, boolean functionApproximationAllowed) { final String query; try { final StringBuilder sb = new StringBuilder(); sb.append("SELECT COUNT() FROM "); sb.append(table.getName()); boolean firstWhere = true; for (FilterItem filterItem : whereItems) { if (firstWhere) { sb.append(" WHERE "); firstWhere = false; } else { sb.append(" AND "); } rewriteFilterItem(sb, filterItem); } query = sb.toString(); } catch (UnsupportedOperationException e) { logger.debug("Failed to rewrite count query, falling back to client side counting", e); // unable to rewrite to SOQL, counting will be done client side. return null; } final QueryResult queryResult = executeSoqlQuery(query); assert queryResult.isDone(); return queryResult.getSize(); }
@Override protected Number executeCountQuery(Table table, List<FilterItem> whereItems, boolean functionApproximationAllowed) { final String query; try { final StringBuilder sb = new StringBuilder(); sb.append("SELECT COUNT() FROM "); sb.append(table.getName()); boolean firstWhere = true; for (FilterItem filterItem : whereItems) { if (firstWhere) { sb.append(" WHERE "); firstWhere = false; } else { sb.append(" AND "); } rewriteFilterItem(sb, filterItem); } query = sb.toString(); } catch (UnsupportedOperationException e) { logger.debug("Failed to rewrite count query, falling back to client side counting", e); // unable to rewrite to SOQL, counting will be done client side. return null; } final QueryResult queryResult = executeSoqlQuery(query); assert queryResult.isDone(); return queryResult.getSize(); }
public synchronized int hashCode() { if (__hashCodeCalc) { return 0; } __hashCodeCalc = true; int _hashCode = 1; _hashCode += (isDone() ? Boolean.TRUE : Boolean.FALSE).hashCode(); if (getQueryLocator() != null) { _hashCode += getQueryLocator().hashCode(); } if (getRecords() != null) { for (int i = 0; i < java.lang.reflect.Array.getLength(getRecords()); i++) { java.lang.Object obj = java.lang.reflect.Array.get(getRecords(), i); if (obj != null && !obj.getClass().isArray()) { _hashCode += obj.hashCode(); } } } _hashCode += getSize(); __hashCodeCalc = false; return _hashCode; }
@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(); inputRecordsIndex = 0; boolean isAdvanced = inputResult.getSize() > 0; if (isAdvanced) { dataCount++; } return isAdvanced; } catch (ConnectionException e) { throw new IOException(e); } } return false; }
if(!result.isDone()) {
@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 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; }
public synchronized boolean equals(java.lang.Object obj) { if (!(obj instanceof QueryResult)) return false; QueryResult other = (QueryResult) obj; if (obj == null) return false; if (this == obj) return true; if (__equalsCalc != null) { return (__equalsCalc == obj); } __equalsCalc = obj; boolean _equals; _equals = true && this.done == other.isDone() && ((this.queryLocator == null && other.getQueryLocator() == null) || (this.queryLocator != null && this.queryLocator.equals(other.getQueryLocator()))) && ((this.records == null && other.getRecords() == null) || (this.records != null && java.util.Arrays.equals(this.records, other.getRecords()))) && this.size == other.getSize(); __equalsCalc = null; return _equals; }
@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; }
public String getParentJobIdForTestQueueItems(List<SaveResult> bulkResults, PartnerConnection conn) { String parentJobId = null; if (bulkResults != null && bulkResults.size() > 0) { SaveResult sr = bulkResults.get(0); String testQueueItemId = sr.getId(); String soql = QueryConstructor.fetchParentJobIdForApexTestQueueItem(testQueueItemId); LOG.debug("Query used for fetching parent job ID for bulk results: " + soql); QueryResult queryResult = null; try{ queryResult = conn.query(soql); }catch (ConnectionException e) { ApexUnitUtils.shutDownWithDebugLog(e, ConnectionHandler .logConnectionException(e, conn, soql)); } if (queryResult.isDone()) { // TODO: We need to verify what's the limit of records that the // bulk api can insert in one transaction. multiple transactions // mean multiple parent job ids parentJobId = fetchParentJobId(queryResult); LOG.info("Async test parent job Id : " + parentJobId); } } else { ApexUnitUtils.shutDownWithErrMsg("Invalid bulk results. No bulk results returned."); } return parentJobId; }
@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 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.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 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); } }