executeUpdate(dbp.getQuery("insertAlibComponent", substitutions));
while(true) {  ResultSet rs2 = executeQuery(stmt, dbp.getQuery("checkAlibComponent", substitutions)); if (!rs2.next()) { if (log.isDebugEnabled()) log.debug("New ALIB ID is OK, will insert"); rs2.close(); executeUpdate(dbp.getQuery("insertAlibComponent", substitutions)); break; } else { if (log.isInfoEnabled()) log.info("New ALIB ID already there (bug 1977)!"); dbname = rs2.getString(1); dblibid = rs2.getString(2); dbtype = rs2.getString(3); rs2.close(); if (mapName.equals(dbname) && mapLib.equals(dblibid) && mapType.equals(dbtype)) {  if (log.isDebugEnabled()) log.debug("2 entries are identical. Just use it"); break; } else {  if (log.isInfoEnabled()) log.info("2 entries differ somehow? Need yet another one!"); id = id + "1"; data.setAlibID(id); substitutions.put(":component_alib_id:", sqlQuote(id)); if (log.isInfoEnabled()) log.info("Adding new ALIB ID " + id); } } }
  private String insureAlib(ComponentData data) throws SQLException {    String id = (String) substitutions.get(":component_alib_id:");    if (alibComponents.contains(id)) return id; // Already present    // may need to be added    insureLib();    String query1 = dbp.getQuery("checkAlibComponent", substitutions);//     if (log.isDebugEnabled()) {//       log.debug("insureAlib doing query " + query1);//     }    Statement stmt = getStatement();    ResultSet rs = executeQuery(stmt, query1);    if (!rs.next()) {      if (log.isDebugEnabled()) {	log.debug("insureAlib query got nothing - will insert alibcomponent " + id);      }      executeUpdate(dbp.getQuery("insertAlibComponent", substitutions));    } else {      // Bug 1810: If the component_name has changed      // and what differs is the part before a vertical bar,      // consider a new ALIB ID.      // Look at col 1: If it differs from what's in subst, but rest are same,      // then I want to reset the ALIB ID (data.setAlibID(null)) and re-save      // -- call getComponentDataSubstitutions      // but note interaction with where this is called from Populate      String dbname = rs.getString(1);      String mapName = data.getName();      String dblibid = rs.getString(2);      String mapLib = data.getLibID();      String mapType = data.getType();      String dbtype = rs.getString(3);      if (dbname != null && ! dbname.equals(mapName) && dblibid != null && dblibid.equals(mapLib) && dbtype != null && dbtype.equals(mapType)) {	if (log.isInfoEnabled()) {	  log.info("insureAlib: Bug 1810: For ALIB ID " + id + " have old name " + dbname + " and new: " + mapName);	  log.info(".. and Lib ID and type both same. LibID: " + dblibid);	}	// Get a new ALIB ID and save that to the DB	// and mark it on the ComponentData somehow	data.setAlibID(null);	id = getComponentAlibId(data);	substitutions.put(":component_alib_id:", sqlQuote(id));	if (log.isInfoEnabled())	  log.info("Adding new ALIB ID " + id);	executeUpdate(dbp.getQuery("insertAlibComponent", substitutions));      } else {	// Something else is different. Ask user what to do	String[] subvars = {	  ":component_name:",	  ":component_lib_id:",	  ":component_category:",	  ":clone_set_id:"	};	StringBuffer diff = compareQueryResults(rs, subvars);	if (diff == null) {	  // Value is ok	} else if (conflictHandler != null) {	  Object[] msg = {	    "You are attempting to redefine alib component: " + id,	    diff,	    "Do you want to overwrite the definition?"	  };	  if (isOverwrite(msg)) {	    String query = dbp.getQuery("updateAlibComponent", substitutions);	    executeUpdate(query);	  }	}      } // find differences to handle conflicts    } // it was there but different    alibComponents.add(id); // Avoid re-querying later    rs.close();    stmt.close();    return id;  }