@Override public boolean deleteObjects( final ByteArrayId primaryId, final ByteArrayId secondaryId, final String... authorizations) { if (primaryId != null) { return accumuloOperations.delete( getTablename(), primaryId, getColumnFamily(), getColumnQualifier(secondaryId), authorizations); } try { final BatchScanner scanner = getScanner(null, secondaryId, authorizations); final Iterator<Entry<Key, Value>> it = scanner.iterator(); try (final CloseableIterator<?> cit = new CloseableIteratorWrapper<T>( new ScannerClosableWrapper(scanner), new DeleteIteratorWrapper(it, authorizations))) { while (cit.hasNext()) { deleteObjectFromCache(getPrimaryId((T) cit.next()), secondaryId); } } catch (final IOException e) { LOGGER.error("Unable to delete objects", e); } } catch (final TableNotFoundException e) { LOGGER.error("Unable to find objects, table '" + getTablename() + "' does not exist", e); } return true; }
protected BatchScanner getScanner( final ByteArrayId primaryId, final ByteArrayId secondaryId, final String... authorizations) throws TableNotFoundException { final BatchScanner scanner = accumuloOperations.createBatchScanner(getTablename(), authorizations); final IteratorSetting[] settings = getScanSettings(); if ((settings != null) && (settings.length > 0)) { for (final IteratorSetting setting : settings) { scanner.addScanIterator(setting); } } final String columnFamily = getColumnFamily(); final String columnQualifier = getColumnQualifier(secondaryId); if (columnFamily != null) { if (columnQualifier != null) { scanner.fetchColumn(new Text(columnFamily), new Text(columnQualifier)); } else { scanner.fetchColumnFamily(new Text(columnFamily)); } } final Collection<Range> ranges = new ArrayList<Range>(); if (primaryId != null) { ranges.add(new Range(new Text(primaryId.getBytes()))); } else { ranges.add(new Range()); } scanner.setRanges(ranges); return scanner; }
@Override protected void addObject(final ByteArrayId id, final ByteArrayId secondaryId, final T object) { addObjectToCache(id, secondaryId, object); try { final Writer writer = accumuloOperations.createWriter(getTablename(), true); synchronized (this) { if (!iteratorsAttached) { iteratorsAttached = true; final IteratorConfig[] configs = getIteratorConfig(); if ((configs != null) && (configs.length > 0)) { accumuloOperations.attachIterators(getTablename(), true, true, true, null, configs); } } } final Mutation mutation = new Mutation(new Text(id.getBytes())); final Text cf = getSafeText(getColumnFamily()); final Text cq = getSafeText(getColumnQualifier(object)); final byte[] visibility = getVisibility(object); if (visibility != null) { mutation.put( cf, cq, new ColumnVisibility(visibility), new Value(PersistenceUtils.toBinary(object))); } else { mutation.put(cf, cq, new Value(PersistenceUtils.toBinary(object))); } writer.write(mutation); try { writer.close(); } catch (final IOException e) { LOGGER.warn("Unable to close metadata writer", e); } } catch (final TableNotFoundException e) { LOGGER.error("Unable add object", e); } }