public void acceptChanges(Connection connection)
throws SyncProviderException {
if (isCursorOnInsert) {
// rowset.11=Illegal operation on an insert row
throw new SyncProviderException(Messages.getString("rowset.11")); //$NON-NLS-1$
}
// Follow RI to assign conn before checking whether conn is null
conn = connection;
if (conn == null) {
throw new SyncProviderException();
}
boolean isShowDeleted = false;
try {
isShowDeleted = getShowDeleted();
} catch (SQLException e) {
// ignore
}
try {
conn.setAutoCommit(false);
CachedRowSetWriter rowSetWriter = (CachedRowSetWriter) syncProvider
.getRowSetWriter();
rowSetWriter.setConnection(conn);
int beforeWriteIndex = currentRowIndex;
// writer use next navigate rowset, so must make all rows visible
setShowDeleted(true);
if (!rowSetWriter.writeData(this)) {
throw rowSetWriter.getSyncException();
}
// must reset curosr before reset showDeleted
absolute(beforeWriteIndex);
setShowDeleted(isShowDeleted);
// record to the next visible row index
int index = getRow();
if (index == 0) {
next();
index = getRow();
if (index == 0) {
index = rows.size() + 1;
}
}
boolean isChanged = false;
for (int i = rows.size() - 1; i >= 0; i--) {
currentRow = rows.get(i);
if (rowDeleted()) {
isChanged = true;
setOriginalRow();
} else if (rowInserted() || rowUpdated()) {
isChanged = true;
setOriginalRow();
}
}
// Set originalResultSet
if (isChanged) {
try {
ArrayList<CachedRow> nowRows = new ArrayList<CachedRow>();
for (int i = 0; i < rows.size(); i++) {
nowRows.add(rows.get(i).createClone());
nowRows.get(i).restoreOriginal();
}
originalResultSet.setRows(nowRows, columnCount);
} catch (CloneNotSupportedException cloneE) {
throw new SyncProviderException(cloneE.getMessage());
}
}
deletedRowCount = 0;
// move cursor
if (index > rows.size()) {
afterLast();
} else if (index <= 0) {
beforeFirst();
} else {
absolute(index);
}
if (isNotifyListener) {
notifyRowSetChanged();
}
} catch (SyncProviderException e) {
throw e;
} catch (SQLException e) {
SyncProviderException ex = new SyncProviderException();
ex.initCause(e);
throw ex;
} finally {
try {
setShowDeleted(isShowDeleted);
} catch (SQLException e) {