use of net.jforum.exceptions.DatabaseException in project jforum2 by rafaelsteil.
the class GenericCategoryDAO method delete.
/**
* @see net.jforum.dao.CategoryDAO#delete(int)
*/
public void delete(int categoryId) {
PreparedStatement p = null;
try {
p = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("CategoryModel.delete"));
p.setInt(1, categoryId);
p.executeUpdate();
} catch (SQLException e) {
throw new DatabaseException(e);
} finally {
DbUtils.close(p);
}
}
use of net.jforum.exceptions.DatabaseException in project jforum2 by rafaelsteil.
the class GenericCategoryDAO method setOrder.
/**
* @param category Category
* @param otherCategory Category
*/
private void setOrder(Category category, Category otherCategory) {
int tmpOrder = otherCategory.getOrder();
otherCategory.setOrder(category.getOrder());
category.setOrder(tmpOrder);
PreparedStatement p = null;
try {
p = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("CategoryModel.setOrderById"));
p.setInt(1, otherCategory.getOrder());
p.setInt(2, otherCategory.getId());
p.executeUpdate();
p.close();
p = null;
p = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("CategoryModel.setOrderById"));
p.setInt(1, category.getOrder());
p.setInt(2, category.getId());
p.executeUpdate();
} catch (SQLException e) {
throw new DatabaseException(e);
} finally {
DbUtils.close(p);
}
}
use of net.jforum.exceptions.DatabaseException in project jforum2 by rafaelsteil.
the class GenericCategoryDAO method addNew.
/**
* @see net.jforum.dao.CategoryDAO#addNew(net.jforum.entities.Category)
*/
public int addNew(Category category) {
int order = 1;
ResultSet rs = null;
PreparedStatement p = null;
try {
p = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("CategoryModel.getMaxOrder"));
rs = p.executeQuery();
if (rs.next()) {
order = rs.getInt(1) + 1;
}
rs.close();
rs = null;
p.close();
p = null;
p = this.getStatementForAutoKeys("CategoryModel.addNew");
p.setString(1, category.getName());
p.setInt(2, order);
p.setInt(3, category.isModerated() ? 1 : 0);
this.setAutoGeneratedKeysQuery(SystemGlobals.getSql("CategoryModel.lastGeneratedCategoryId"));
int id = this.executeAutoKeysQuery(p);
category.setId(id);
category.setOrder(order);
return id;
} catch (SQLException e) {
throw new DatabaseException(e);
} finally {
DbUtils.close(rs, p);
}
}
use of net.jforum.exceptions.DatabaseException in project jforum2 by rafaelsteil.
the class GenericConfigDAO method update.
/**
* @see net.jforum.dao.ConfigDAO#update(net.jforum.entities.Config)
*/
public void update(Config config) {
PreparedStatement p = null;
try {
p = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("ConfigModel.update"));
p.setString(1, config.getValue());
p.setString(2, config.getName());
p.executeUpdate();
} catch (SQLException e) {
throw new DatabaseException(e);
} finally {
DbUtils.close(p);
}
}
use of net.jforum.exceptions.DatabaseException in project jforum2 by rafaelsteil.
the class GenericApiDAO method isValid.
/**
* @see net.jforum.dao.ApiDAO#isValid(java.lang.String)
*/
public boolean isValid(String apiKey) {
boolean status = false;
PreparedStatement p = null;
ResultSet rs = null;
try {
p = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("ApiModel.isValid"));
p.setString(1, apiKey);
rs = p.executeQuery();
status = rs.next();
} catch (Exception e) {
throw new DatabaseException(e);
} finally {
DbUtils.close(rs, p);
}
return status;
}
Aggregations