{
if (null == bot) throw new IllegalArgumentException("bot can't be null.");
if (null == faqData) throw new IllegalArgumentException("faqData can't be null.");
if (!faqData.validate())
{
throw new AddFaqErrorException(faqData);
}
final int[] result = new int[] {-1};
try
{
if (0 == executeUpdate(mAddFaq, new DbPreparedStatementHandler() {
public DbPreparedStatement getPreparedStatement(Query query, DbConnection connection)
{
return connection.getPreparedStatement(query, Statement.RETURN_GENERATED_KEYS);
}
public void setParameters(DbPreparedStatement statement)
{
statement
.setString("botname", bot.getName())
.setBean(faqData);
}
public int performUpdate(DbPreparedStatement statement)
{
setParameters(statement);
int query_result = statement.executeUpdate();
result[0] = statement.getFirstGeneratedIntKey();
return query_result;
}
}))
{
throw new AddFaqErrorException(faqData);
}
}
catch (InnerClassException e)
{
throw ((FaqManagerException)e.getCause());
}
catch (DatabaseException e)
{
throw new AddFaqErrorException(faqData, e);
}
assert result[0] >= 0;
return result[0];