// block
Connection myConn = null;
try {
myConn = ConnectionPoolFactory.getConnectionPool().getConnection();
} catch (NoAvailablePoolException e1) {
throw new NoSuchMetadataException(
"Couldn't get metadata b/c of a connection pool problem: "
+ e1.toString());
}
myConn.setAutoCommit(false);
qp.setConnection(myConn);
qp.addPreparedStmtElementDefinition(projectHandle);
qp.addPreparedStmtElementDefinition(type.getValue());
qp.addPreparedStmtElementDefinition(metadataId);
try {
if (!Configuration.getConnectionPool().executeInsertOrUpdate(qp)) {
throw new NoSuchMetadataException(
"No matching row was found to update");
} else {
// if that worked, then set the rest of the fields for
// this projectId+contentType combination to false
qp.clearForNewSQL();
sql = new StringBuffer();
sql.append("update metadata_registry ");
sql.append("set is_key_field=false ");
sql.append("where project_id=");
sql.append(" (select project_id ");
sql.append(" from projects ");
sql.append(" where handle=?) ");
sql.append("and content_type=? ");
sql.append("and metadata_id!=? ");
qp.setSql(sql.toString());
qp.addPreparedStmtElementDefinition(projectHandle);
qp.addPreparedStmtElementDefinition(type.getValue());
qp.addPreparedStmtElementDefinition(metadataId);
Configuration.getConnectionPool().executeInsertOrUpdate(qp);
qp.getConnection().commit();
}
} catch (SQLException e) {
Logger.error(
"Metadata record couldn't be updated ... rolling back", e);
qp.getConnection().rollback();
throw new NoSuchMetadataException(
"SQLException prevented metadata record update: "
+ e.getMessage());
} finally {
qp.setConnection(null);
myConn.setAutoCommit(true); // reset to true before returning it