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 ); } }
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 ); } }
this.sObjects = getQueryResult().getRecords(); if ( this.sObjects != null ) { this.queryResultSize = this.sObjects.length; this.sObjects = getQueryResult().getRecords(); this.queryResultSize = getQueryResult().getSize(); break;
@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 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 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; }
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; } }
@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(); }
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())); } } }
if(!result.isDone()) { this.results = this.connection.queryMore(results.getQueryLocator(), context.getBatchSize()); this.currentBatch = loadBatch(this.results);
/** * Locates this object in the datastore. * * @param op The ObjectProvider for the object to be found */ @Override public void locateObject(ObjectProvider op) { ForceManagedConnection mconn = (ForceManagedConnection) storeManager.getConnection(op.getExecutionContext()); try { AbstractClassMetaData acmd = op.getClassMetaData(); TableImpl table = storeManager.getTable(acmd); QueryResult qr = ((PartnerConnection) mconn.getConnection()) .query("select count() from " + table.getTableName().getForceApiName() + " where id='" + op.provideField(op.getClassMetaData().getPKMemberPositions()[0]) + "'"); if (qr.getSize() == 0) { throw new NucleusObjectNotFoundException(); } } catch (ConnectionException x) { throw new NucleusDataStoreException(x.getMessage(), x); } finally { mconn.release(); } }
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; }
public QueryResult buildQueryResult(SObject[] objects) { QueryResult result = new QueryResult(); result.setRecords(objects); result.setSize(objects.length); result.setDone(true); return result; }
private void loadFields1(com.sforce.ws.parser.XmlInputStream __in, com.sforce.ws.bind.TypeMapper __typeMapper) throws java.io.IOException, com.sforce.ws.ConnectionException { setDone(__in, __typeMapper); setQueryLocator(__in, __typeMapper); setRecords(__in, __typeMapper); setSize(__in, __typeMapper); }
protected void setDone(com.sforce.ws.parser.XmlInputStream __in, com.sforce.ws.bind.TypeMapper __typeMapper) throws java.io.IOException, com.sforce.ws.ConnectionException { __in.peekTag(); if (__typeMapper.verifyElement(__in, _lookupTypeInfo("done", "urn:partner.soap.sforce.com","done","http://www.w3.org/2001/XMLSchema","boolean",1,1,true))) { setDone(__typeMapper.readBoolean(__in, _lookupTypeInfo("done", "urn:partner.soap.sforce.com","done","http://www.w3.org/2001/XMLSchema","boolean",1,1,true), boolean.class)); } }
@Override public com.sforce.soap.partner.IQueryResult newIQueryResult() { return new com.sforce.soap.partner.QueryResult(); }
@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 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 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(); }
private static String[] fetchApexClassesAsArray(QueryResult queryResult) { Object[] apexClassesObjArr = null; if (queryResult.getDone()) { SObject[] sObjects = queryResult.getRecords(); if (sObjects != null) { ArrayList<String> apexClasses = new ArrayList<String>(); LOG.debug("Fetched Apex classes:"); for (SObject sobject : sObjects) { apexClasses.add(sobject.getField("Id").toString()); // crucial step. Populate apexCLassMap each time a class is // fetched. Will be used for lot of computations apexClassMap.put(sobject.getField("Id").toString(), sobject.getField("Name").toString()); LOG.debug("ApexClassId : " + sobject.getField("Id").toString() + " ApexClassName : " + sobject.getField("Name").toString()); } apexClassesObjArr = apexClasses.toArray(); //line below only works for java 1.6 and above return Arrays.copyOf(apexClassesObjArr, apexClassesObjArr.length, String[].class); } } return null; }