@SuppressWarnings( "unchecked" ) private String buildJsonQueryResult( QueryResult queryResult ) throws KettleException { JSONArray list = new JSONArray(); for ( SObject sobject : queryResult.getRecords() ) { list.add( buildJSONSObject( sobject ) ); } StringWriter sw = new StringWriter(); try { list.writeJSONString( sw ); } catch ( IOException e ) { throw new KettleException( e ); } return sw.toString(); }
public XmlObject[] getElements() throws Exception { // Query first this.qr = getBinding().query( getSQL() ); // and then return records SObject con = getQueryResult().getRecords()[0]; if ( con == null ) { return null; } return getChildren( con ); }
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 ); } }
this.sObjects = getQueryResult().getRecords(); if ( this.sObjects != null ) { this.queryResultSize = this.sObjects.length; this.sObjects = getQueryResult().getRecords(); this.queryResultSize = getQueryResult().getSize(); break;
public SalesforceDataSet(Column[] columns, QueryResult queryResult, PartnerConnection connection) { super(columns); _connection = connection; _queryResult = queryResult; _records = _queryResult.getRecords(); _recordIndex = new AtomicInteger(); _record = null; }
public SalesforceDataSet(List<Column> columns, QueryResult queryResult, PartnerConnection connection) { super(columns.stream().map(SelectItem::new).collect(Collectors.toList())); _connection = connection; _queryResult = queryResult; _records = _queryResult.getRecords(); _recordIndex = new AtomicInteger(); _record = null; }
public SalesforceDataSet(List<Column> columns, QueryResult queryResult, PartnerConnection connection) { super(columns.stream().map(SelectItem::new).collect(Collectors.toList())); _connection = connection; _queryResult = queryResult; _records = _queryResult.getRecords(); _recordIndex = new AtomicInteger(); _record = null; }
private List<List<Object>> loadBatch(QueryResult queryResult) { List<List<Object>> batch = new ArrayList<List<Object>>(); for(SObject sObject : queryResult.getRecords()) { Iterator<XmlObject> fields = sObject.getChildren(); List<Object> row = new ArrayList<Object>(); while (fields.hasNext()) { XmlObject elem = fields.next(); if (elem.getName().getLocalPart().equals("type")) { //$NON-NLS-1$ continue; } Object value = elem.getValue(); row.add(value); } batch.add(row); } return batch; }
private String fetchParentJobId(QueryResult queryResult) { String parentJobId = ""; if (queryResult.getDone()) { SObject[] sObjects = queryResult.getRecords(); if (sObjects != null) { for (SObject sobject : sObjects) { parentJobId = sobject.getField("ParentJobId").toString(); } return parentJobId; } } return null; } }
private void loadBatch() throws TranslatorException { if(null != resultBatch) { // if we have an old batch, then we have to get new results results = connection.queryMore(results.getQueryLocator(), context.getBatchSize()); } resultBatch = new ArrayList<List<Object>>(); topResultIndex = 0; for(SObject sObject : results.getRecords()) { if (sObject == null) { continue; } List<Object[]> result = getObjectData(sObject); for(Iterator<Object[]> i = result.iterator(); i.hasNext(); ) { resultBatch.add(Arrays.asList(i.next())); } } }
@Override public boolean start() throws IOException { try { inputResult = executeSalesforceQuery(); if (inputResult.getSize() == 0) { return false; } inputRecords = inputResult.getRecords(); inputRecordsIndex = 0; boolean start = inputRecords.length > 0; if (start) { dataCount++; } return start; } catch (ConnectionException e) { // Wrap the exception in an IOException. throw new IOException(e); } }
@Override public boolean start() throws IOException { try { inputResult = executeSalesforceQuery(); if (inputResult.getSize() == 0) { return false; } inputRecords = inputResult.getRecords(); inputRecordsIndex = 0; boolean startable = inputRecords.length > 0; if (startable) { dataCount++; } return startable; } catch (ConnectionException e) { // Wrap the exception in an IOException. throw new IOException(e); } }
@Override public boolean start() throws IOException { try { inputResult = executeSalesforceQuery(); if (inputResult.getSize() == 0) { return false; } inputRecords = inputResult.getRecords(); inputRecordsIndex = 0; boolean start = inputRecords.length > 0; if (start) { dataCount++; } return start; } 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(); 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 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 void execute() throws BuildException { checkAttributes(); // prepare where clause try { SalesforceConfig conf = getConfig(); PartnerConnection connection = ConnectionFactory.getPartnerConnection(conf); log(String.format("Getting RecordTypeId: %s.%s", object, developerName)); QueryResult result = connection.query(getCompiledQuery()); if (result.getSize() == 1) { String value = (String) result.getRecords()[0].getField("Id"); getProject().setNewProperty(propertyRef, value); } else { throw new BuildException("Unable to find a unique result"); } } catch (ConnectionException e) { throw new BuildException(e.getLocalizedMessage()); } }