if (asb != null && asb.startsWith(REAL_CMT_TYPE) && asb.indexOf("134589") != -1) { if (log.isInfoEnabled()) { log.info("clnTrial found base CMT assembly " + asb + "- skipping"); } continue; }
  private void cleanTrial(String cmtType, String hnaType, String csmiType, String oldTrialId)    throws SQLException  {    // Basically we'll drop the HNA, CSMI assembly and recipes. It will drop    // the CMT assembly too, but only if cmtType is null    // Also drop any CSA in runtime if cmtType is not a CSA    if(log.isDebugEnabled()) {      log.debug("Cleaning all in trial except " + cmtType +", but including " + hnaType+", " + csmiType+", from " + oldTrialId);    }    substitutions.put(":trial_id:", oldTrialId);    substitutions.put(":cmt_type:", cmtType);    substitutions.put(":hna_type:", hnaType);    substitutions.put(":csmi_type:", csmiType);    substitutions.put(":csa_type:", CSATYPE);    // check that each Assembly it finds is not    // referenced by another experiment. If it is, then we only delete from     // trial_assembly and trial_config_assembly    // OK. This will succesfully grab CSMI and CSHNA assemblies in runtime.    // And if the real society is a CMT society, it will also get a CSA assembly.    // So I just need an extra check to delete any CSA assembly in runtime if    // if the input cmtType is "CSA" and the CSA assembly in the runtime    // is not the same as the one in config time (or the one I got as input)    // Question: do those cleanOldConfigSocietyAssemblies, etc methods    // do what I need already? No: It removes from the config/runtime table    // _all_ CSA & CMT assemblies. I could do that after most of this,    // and then re-insert the real society into the runtime, I suppose.    if (log.isDebugEnabled()) {      log.debug("clnTrial subs: " + substitutions);    }    Statement stmt = getStatement();    ResultSet ctrs =            executeQuery(stmt, dbp.getQuery("queryAssembliesToClean", substitutions));    boolean first = true;    StringBuffer assembliesToDelete = new StringBuffer();    assembliesToDelete.append("(");    StringBuffer assembliesToReallyDelete = new StringBuffer();    assembliesToReallyDelete.append("(");    boolean rfirst = true;    String asb = null;    // Loop over the assemblies to clean up    while (ctrs.next()) {      if (first) {	first = false;      } else {	assembliesToDelete.append(", ");      }      asb = ctrs.getString(1);      assembliesToDelete.append(sqlQuote(asb));      // if asb not used other than the current trial      // and not a community assembly      if (! isAssemblyUsed(asb) && COMM_ASB_TYPE != getAssemblyType(asb)) {	if (log.isDebugEnabled()) {	  log.debug("cleanTrial: assembly " + asb + " not used, except in trial " + trialId + " which we are deleting, so well really delete it");	}	if (rfirst) {	  rfirst = false;	} else {	  assembliesToReallyDelete.append(", ");	}	assembliesToReallyDelete.append(sqlQuote(asb));      } else if (log.isDebugEnabled()) {	log.debug("cleanTrial not deleting asb " + asb + " cause its still in use outside trial " + trialId);      }    } // done with loop over assemblies to clean up    ctrs.close();    stmt.close();    assembliesToDelete.append(")");    assembliesToReallyDelete.append(")");    if (! first) {      substitutions.put(":assemblies_to_clean:", assembliesToDelete.toString());      if (log.isDebugEnabled()) {	log.debug("Assemblies to delete from trial " + trialId + ": " + assembliesToDelete);      }      // This deletes the references in the runtime table      executeUpdate(dbp.getQuery("cleanTrialAssembly", substitutions));            // Add delete from config table. Must get rid of the HNA from there      executeUpdate(dbp.getQuery("cleanTrialConfigAssembly", substitutions));    }        // now really delete those that are unused.    // where if this is true there were none    if (! rfirst) {      substitutions.put(":assemblies_to_clean:", assembliesToReallyDelete.toString());      if (log.isDebugEnabled()) {	log.debug("Assemblies to completely delete: " + assembliesToReallyDelete);      }      cleanAssemblies(false);    }    // OK, now if the incoming cmtType is really a CSA, and cmtAssemblyId not in    // runtime, get the CSA assembly in runtime, remove it from runtime, & if not    // used, completely remove it    // However - no need to do this: cleanOldRuntimeAssemblies will already do this    // Delete all recipes out of this Trial - why would I do this?    // Cause I re-add them when I finish saving the experiment    executeUpdate(dbp.getQuery("cleanTrialRecipe", substitutions));  } // end of cleanTrial