*/
if (!fm.isDirty()) return;
ObjectManager om = ((ObjectProviderImpl) op).getStateManager().getObjectManager();
boolean isAllOrNothingMode =
om instanceof ForceObjectManagerImpl && ((ForceObjectManagerImpl) om).isInAllOrNothingMode();
SObject toSave;
if (!isAllOrNothingMode) {
PartnerConnection connection = getPartnerConnection(mconn, op);
try {
toSave = fm.getSObject(false);
if (LOGGER.isDebugEnabled()) {
if (fieldNumbers != null) {
LOGGER.debug("Updating object: " + toSave.getType() + " id: " + toSave.getId());
} else {
LOGGER.debug("Creating object: " + toSave.getType());
}
}
SaveResult[] results = fieldNumbers != null ? connection.update(new SObject[]{toSave})
: ((PartnerConnection) mconn.getConnection()).create(new SObject[]{toSave});
checkForErrors(results);
if (fieldNumbers == null) {
op.setPostStoreNewObjectId(results[0].getId());
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Created object id: " + results[0].getId());
}
}
} finally {
connection.clearConditionalRequestHeader();
}
} else {
if (fieldNumbers != null) {
//When we do all-or-nothing with optimistic transactions, per jpa spec we need to save properly
// even if some objects are missing @Version,
// so if op.getVersion is null, we give a Calendar set to System.currentTimeMilis + 1 HOUR so
// the if-modified-before check for the object without @Version will always succeed
toSave = fm.getSObject(false);
((ForceObjectManagerImpl) om).addToUpdateList(toSave,
op.getVersion() != null ? (Calendar) op.getVersion() : getVersionForUnversioned());
} else {
toSave = fm.getSObject(true);
((ForceObjectManagerImpl) om).addToCreateList(toSave, op);
}
if (LOGGER.isDebugEnabled()) {
if (fieldNumbers != null) {
LOGGER.debug("Queuing for A-O-N update object: " + toSave.getType() + " id: " + toSave.getId());
} else {
LOGGER.debug("Queuing for A-O-N create object: " + toSave.getType());
}
}
}
} catch (ApiFault af) {
throw ForceApiExceptionMap.mapToNucleusException(af, false /* isQuery */,