@Override public T mutate(T value) { T mutate = tMutator.mutate(value); if (mutate != null) { success[0] = true; } return mutate; } });
@Override public T mutate(T value) { T mutate = tMutator.mutate(value); if (mutate != null) { success[0] = true; } return mutate; } }, tCreator);
@Override public Row<T, K> mutate(K row, Mutator<T> tMutator) throws AvroBaseException { Lock writeLock = writeLock(row); try { File file = getFile(row, true); FileInputStream fis = new FileInputStream(file); FileChannel channel = fis.getChannel(); FileLock fileLock = channel.lock(); try { Row<T, K> tStringRow = _get(row); if (tStringRow == null) return null; T mutate = tMutator.mutate(tStringRow.value); if (mutate != null) { put(row, mutate); return new Row<T, K>(mutate, row); } return tStringRow; } finally { fileLock.release(); channel.close(); fis.close(); } } catch (FileNotFoundException e) { return null; } catch (IOException e) { throw new AvroBaseException("Failed to delete: " + row, e); } finally { writeLock.unlock(); } }
Row<T, K> tStringRow = _get(row); if (tStringRow == null) return null; T mutate = tMutator.mutate(tStringRow.value); if (mutate != null) { put(row, mutate);
@Override public Row<T, K> mutate(K row, Mutator<T> tMutator, Creator<T> tCreator) throws AvroBaseException { Row<T, K> tRow; do { // Grab the current version tRow = get(row); // If it doesn't exist, create a new one if (tRow == null && tCreator != null) { final T newValue = tCreator.create(); if (newValue != null) { tRow = new Row<T,K>(newValue, row, 0); } } if (tRow != null) { T value = tMutator.mutate(tRow.value); // Mutator can abort the mutation if (value == null) return tRow; // Optimistically set the row if (put(row, value, tRow.version)) { return new Row<T, K>(value, row, tRow.version + 1); } } else { return null; } // On failure to set, try again } while (true); }