Search in sources :

Example 1 with DataPayload

use of org.teiid.translator.salesforce.execution.DataPayload in project teiid by teiid.

the class SalesforceConnectionImpl method create.

public int create(DataPayload data) throws ResourceException {
    SObject toCreate = new SObject();
    toCreate.setType(data.getType());
    for (DataPayload.Field field : data.getMessageElements()) {
        toCreate.addField(field.name, field.value);
    }
    SObject[] objects = new SObject[] { toCreate };
    SaveResult[] result;
    try {
        result = partnerConnection.create(objects);
    } catch (InvalidFieldFault e) {
        throw new ResourceException(e);
    } catch (InvalidSObjectFault e) {
        throw new ResourceException(e);
    } catch (InvalidIdFault e) {
        throw new ResourceException(e);
    } catch (UnexpectedErrorFault e) {
        throw new ResourceException(e);
    } catch (ConnectionException e) {
        throw new ResourceException(e);
    }
    return analyzeResult(result);
}
Also used : InvalidFieldFault(com.sforce.soap.partner.fault.InvalidFieldFault) InvalidSObjectFault(com.sforce.soap.partner.fault.InvalidSObjectFault) SObject(com.sforce.soap.partner.sobject.SObject) DataPayload(org.teiid.translator.salesforce.execution.DataPayload) ResourceException(javax.resource.ResourceException) UnexpectedErrorFault(com.sforce.soap.partner.fault.UnexpectedErrorFault) InvalidIdFault(com.sforce.soap.partner.fault.InvalidIdFault) ConnectionException(com.sforce.ws.ConnectionException)

Example 2 with DataPayload

use of org.teiid.translator.salesforce.execution.DataPayload in project teiid by teiid.

the class SalesforceConnectionImpl method update.

public int update(List<DataPayload> updateDataList) throws ResourceException {
    List<SObject> params = new ArrayList<SObject>(updateDataList.size());
    for (int i = 0; i < updateDataList.size(); i++) {
        DataPayload data = updateDataList.get(i);
        SObject toCreate = new SObject();
        toCreate.setType(data.getType());
        toCreate.setId(data.getID());
        for (DataPayload.Field field : data.getMessageElements()) {
            toCreate.addField(field.name, field.value);
        }
        params.add(i, toCreate);
    }
    SaveResult[] result;
    try {
        result = partnerConnection.update(params.toArray(new SObject[params.size()]));
    } catch (InvalidFieldFault e) {
        throw new ResourceException(e);
    } catch (InvalidSObjectFault e) {
        throw new ResourceException(e);
    } catch (InvalidIdFault e) {
        throw new ResourceException(e);
    } catch (UnexpectedErrorFault e) {
        throw new ResourceException(e);
    } catch (ConnectionException e) {
        throw new ResourceException(e);
    }
    return analyzeResult(result);
}
Also used : InvalidSObjectFault(com.sforce.soap.partner.fault.InvalidSObjectFault) ArrayList(java.util.ArrayList) UnexpectedErrorFault(com.sforce.soap.partner.fault.UnexpectedErrorFault) InvalidFieldFault(com.sforce.soap.partner.fault.InvalidFieldFault) SObject(com.sforce.soap.partner.sobject.SObject) DataPayload(org.teiid.translator.salesforce.execution.DataPayload) ResourceException(javax.resource.ResourceException) InvalidIdFault(com.sforce.soap.partner.fault.InvalidIdFault) ConnectionException(com.sforce.ws.ConnectionException)

Example 3 with DataPayload

use of org.teiid.translator.salesforce.execution.DataPayload in project teiid by teiid.

the class SalesforceConnectionImpl method upsert.

public int upsert(DataPayload data) throws ResourceException {
    SObject toCreate = new SObject();
    toCreate.setType(data.getType());
    for (DataPayload.Field field : data.getMessageElements()) {
        toCreate.addField(field.name, field.value);
    }
    SObject[] objects = new SObject[] { toCreate };
    UpsertResult[] results;
    try {
        results = partnerConnection.upsert(ID_FIELD_NAME, objects);
    } catch (InvalidFieldFault e) {
        throw new ResourceException(e);
    } catch (InvalidSObjectFault e) {
        throw new ResourceException(e);
    } catch (InvalidIdFault e) {
        throw new ResourceException(e);
    } catch (UnexpectedErrorFault e) {
        throw new ResourceException(e);
    } catch (ConnectionException e) {
        throw new ResourceException(e);
    }
    for (UpsertResult result : results) {
        if (!result.isSuccess()) {
            throw new ResourceException(result.getErrors()[0].getMessage());
        }
    }
    return results.length;
}
Also used : InvalidFieldFault(com.sforce.soap.partner.fault.InvalidFieldFault) InvalidSObjectFault(com.sforce.soap.partner.fault.InvalidSObjectFault) SObject(com.sforce.soap.partner.sobject.SObject) DataPayload(org.teiid.translator.salesforce.execution.DataPayload) ResourceException(javax.resource.ResourceException) UnexpectedErrorFault(com.sforce.soap.partner.fault.UnexpectedErrorFault) InvalidIdFault(com.sforce.soap.partner.fault.InvalidIdFault) ConnectionException(com.sforce.ws.ConnectionException)

Aggregations

InvalidFieldFault (com.sforce.soap.partner.fault.InvalidFieldFault)3 InvalidIdFault (com.sforce.soap.partner.fault.InvalidIdFault)3 InvalidSObjectFault (com.sforce.soap.partner.fault.InvalidSObjectFault)3 UnexpectedErrorFault (com.sforce.soap.partner.fault.UnexpectedErrorFault)3 SObject (com.sforce.soap.partner.sobject.SObject)3 ConnectionException (com.sforce.ws.ConnectionException)3 ResourceException (javax.resource.ResourceException)3 DataPayload (org.teiid.translator.salesforce.execution.DataPayload)3 ArrayList (java.util.ArrayList)1