sql.append("from collection2collection ");
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();
if (parentType == ContentType.COMMUNITY) {
sql.append("insert into collection2community ");
sql.append("(collection_id, community_id) values (?, ?) ");
} else if (parentType == ContentType.COLLECTION) {
sql.append("insert into collection2collection ");
sql.append("(child_id, parent_id) values (?, ?) ");
}
qp.clearForNewSQL();
qp.setSql(sql.toString());
qp.addPreparedStmtElementDefinition(childId);
qp.addPreparedStmtElementDefinition(parentId);
Configuration.getConnectionPool().executeInsertOrUpdate(qp);
}
}