@Override
public Number execute(ISession session, SeConnection connection) throws SeException,
IOException {
final SeInsert insertStream = (SeInsert) createStream(SeInsert.class);
Number newId = null;
try {
final SeRow row;
// ensure we get the next sequence id when the fid is user managed
// and include it in the attributes to set
if (fidReader instanceof FIDReader.UserManagedFidReader) {
newId = getNextAvailableUserManagedId();
if (newId == null) {
LOGGER.finest("There seems not to be a sequence"
+ " for the table, not setting a generated id, "
+ "user ought to be taking care of it");
newId = (Number) newFeature.getAttribute(fidReader.getColumnIndex());
} else {
final int rowIdIndex = fidReader.getColumnIndex();
newFeature.setAttribute(rowIdIndex, newId);
}
}
String[] rowColumnNames = new ArrayList<String>(insertColumns.values())
.toArray(new String[0]);
String typeName = featureType.getTypeName();
insertStream.intoTable(typeName, rowColumnNames);
insertStream.setWriteMode(true);
row = insertStream.getRowToSet();
setRowProperties(newFeature, seCoordRef, insertColumns, row);
insertStream.execute();
if (fidReader instanceof FIDReader.SdeManagedFidReader) {
SeObjectId newRowId = insertStream.lastInsertedRowId();
newId = Long.valueOf(newRowId.longValue());
}
insertStream.flushBufferedWrites(); // jg: my customer wanted this uncommented
versionHandler.editOperationWritten(insertStream);
} catch (Exception e) {
versionHandler.editOperationFailed(insertStream);
if (e instanceof SeException) {
throw (SeException) e;
} else if (e instanceof IOException) {
throw (IOException) e;
}
throw new DataSourceException(e);
}
insertStream.close();
return newId;
}
};
final Number newId;