@Override /** when a record is updated/deleted, need to use this to */ public void removeRecordFromMatcher(InputRecord ir) { Long id = new Long(ir.getId()); List<String> isbns = inputId2isbn.get(id); if (isbns != null) { for (String isbn : isbns) { List<Long> inputIds = isbn2inputIds.get(isbn); if (inputIds != null) { inputIds.remove(id); if (inputIds.size() > 0) { isbn2inputIds.put(isbn, inputIds); } else { isbn2inputIds.remove(isbn); } } } } inputId2isbn.remove(id); // keep database in sync. Don't worry about the one-off performance hit...yet. getMAS() .getMarcAggregationServiceDAO() .deleteMergeRow(MarcAggregationServiceDAO.matchpoints_020a_table, id); }
public boolean matchpointsHaveChanged(SaxMarcXmlRecord r, InputRecord ir) { LOG.debug("isbn matchpointsHaveChanged? ID: " + ir.getId()); Map<Long, List<String>> cachedListId2isbn = getMAS() .getMarcAggregationServiceDAO() .get1StrMatchpointsRecordsCache( Long.valueOf(ir.getId()), MarcAggregationServiceDAO.matchpoints_020a_table); LOG.debug("cachedListId2isbn: " + cachedListId2isbn); List<String> cachedId2isbn = new ArrayList<String>(); if (cachedListId2isbn.containsKey(ir.getId())) { cachedId2isbn = cachedListId2isbn.get(ir.getId()); LOG.debug("cachedId2isbn: " + cachedId2isbn); } List<String> thisId2isbn = new ArrayList<String>(); List<Field> fields = r.getDataFields(20); for (Field field : fields) { List<String> subfields = SaxMarcXmlRecord.getSubfieldOfField(field, 'a'); for (String subfield : subfields) { String isbn = getIsbn(subfield); if (!isIsbnValid(isbn)) { continue; // bad data will cause trouble up the road. } LOG.debug("adding thisId2isbn: " + isbn); thisId2isbn.add(isbn); } } LOG.error( "gonna compare cachedId2isbn: " + cachedId2isbn + " ...with... thisId2isbn: " + thisId2isbn); Set<String> setA = new HashSet<String>(cachedId2isbn); Set<String> setB = new HashSet<String>(thisId2isbn); boolean same = setA.containsAll(thisId2isbn) && setB.containsAll(cachedId2isbn); return (!same); }