// Execute Statement
PreparedStatement stmt = getInsertStatement(folder, allColumns);
int rows = stmt.executeUpdate();
if (rows != 1) {
throw new WGBackendException("Insert failed. Wrong number of inserted rows returned: " + rows);
}
if (keyToGenerate == null) {
return true;
}
// Try to retrieve generated key and store it at the bean and the key map
if (!stmt.getConnection().getMetaData().supportsGetGeneratedKeys()) {
throw new WGBackendException("Row was inserted but JDBC Driver does not support returning of generated keys. Usage of a table with generated key is not possible with this driver.");
}
ResultSet generatedKeys = stmt.getGeneratedKeys();
generatedKeys.first();
Object generatedKey = generatedKeys.getObject(1);
valuesMap.put(keyToGenerate, generatedKey);
keyMap.put(keyToGenerate, generatedKey);
if (getConnection().getAutoCommit() == false) {
getConnection().commit();
}
return true;
/*String whereClause = getWhereClause(folder, key);
resultSet = getTableResultSet(folder, whereClause, true);
if (resultSet != null) {
startResultSet(resultSet);
if (!resultSet.next()) {
resultSet.moveToInsertRow();
pushRowData(resultSet, (Map) bean);
resultSet.insertRow();
if (getConnection().getAutoCommit() == false) {
getConnection().commit();
}
return true;
}
else {
throw new WGBackendException("The key '" + key + "' already exists in table '" + folder + "'");
}
}
else {
return false;
}*/
}
catch (SQLException e) {
try {
if (getConnection().getAutoCommit() == false) {
getConnection().rollback();
}
} catch (SQLException e1) {
Logger.getLogger(LOGGER_NAME).error("Error rolling back content insertion", e);
}
throw new WGBackendException("Error inserting row", e);
}
finally {
closeResultSet(resultSet);
}