sql.append("select count(*) as theCount ");
sql.append("from community2community ");
sql.append("where child_id=? ");
sql.append("and parent_id=? ");
QueryParser qp = new QueryParser(sql.toString());
qp.addPreparedStmtElementDefinition(childId);
qp.addPreparedStmtElementDefinition(parentId);
if (connection != null) {
qp.setConnection(connection);
}
int preInsertCheck = -1;
try {
Configuration.getConnectionPool().executeQuery(qp);
preInsertCheck = qp.getResult(Integer.class, "theCount");
} catch (DataTypeMismatchException e) {
Logger.error("Couldn't create an int out of an integer "
+ "db result. Shouldn't happen, but...", e);
}
if (preInsertCheck == 0) {
sql = new StringBuffer();
sql.append("insert into community2community ");
sql.append("(child_id, parent_id) values (?, ?) ");
qp.clearForNewSQL();
qp.setSql(sql.toString());
qp.addPreparedStmtElementDefinition(childId);
qp.addPreparedStmtElementDefinition(parentId);
Configuration.getConnectionPool().executeInsertOrUpdate(qp);
}
}