@Override public Map<String, String> getAll(final String prefix) { Map<String, String> originals = refDb.getAll(append(this.txOrigNamespace, prefix)); Map<String, String> changed = refDb.getAll(append(this.txChangedNamespace, prefix)); Map<String, String> externalOriginals = toExternal(originals); Map<String, String> externalChanged = toExternal(changed); Map<String, String> composite = Maps.newHashMap(externalOriginals); // Overwrite originals composite.putAll(externalChanged); return composite; }
@Override public Map<String, String> getAll(final String prefix) { Map<String, String> changed = refDb.getAll(append(this.txChangedNamespace, prefix)); return toExternal(changed); }
/** * @return the resolved {@link GeogigTransaction}, or {@link Optional#absent()} if it could not * be resolved */ @Override protected Optional<GeogigTransaction> _call() { Preconditions.checkState(!(context instanceof GeogigTransaction), "Cannot resolve a transaction within a transaction!"); Preconditions.checkArgument(id != null, "No id was specified to resolve!"); final String transactionNamespace = TransactionRefDatabase.buildTransactionNamespace(id); GeogigTransaction transaction = null; if (!context.refDatabase().getAll(transactionNamespace).isEmpty()) { transaction = new GeogigTransaction(context, id); } return Optional.fromNullable(transaction); } }
/** * @return the resolved {@link GeogigTransaction}, or {@link Optional#absent()} if it could not * be resolved */ @Override protected Optional<GeogigTransaction> _call() { Preconditions.checkState(!(context instanceof GeogigTransaction), "Cannot resolve a transaction within a transaction!"); Preconditions.checkArgument(id != null, "No id was specified to resolve!"); final String transactionNamespace = TransactionRefDatabase.buildTransactionNamespace(id); GeogigTransaction transaction = null; if (!context.refDatabase().getAll(transactionNamespace).isEmpty()) { transaction = new GeogigTransaction(context, id); } return Optional.fromNullable(transaction); } }
/** * @return the new value of the ref */ @Override protected ImmutableSet<Ref> _call() { @SuppressWarnings("unchecked") final Predicate<Ref> filter = (Predicate<Ref>) (this.filter == null ? Predicates.alwaysTrue() : this.filter); ImmutableSet.Builder<Ref> refs = new ImmutableSet.Builder<Ref>(); for (String refName : refDatabase().getAll().keySet()) { Optional<Ref> ref = command(RefParse.class).setName(refName).call(); if (ref.isPresent() && filter.apply(ref.get())) { Ref accepted = ref.get(); refs.add(accepted); } } return refs.build(); } }
/** * @return the new value of the ref */ @Override protected ImmutableSet<Ref> _call() { @SuppressWarnings("unchecked") final Predicate<Ref> filter = (Predicate<Ref>) (this.filter == null ? Predicates.alwaysTrue() : this.filter); ImmutableSet.Builder<Ref> refs = new ImmutableSet.Builder<Ref>(); for (String refName : refDatabase().getAll().keySet()) { Optional<Ref> ref = command(RefParse.class).setName(refName).call(); if (ref.isPresent() && filter.apply(ref.get())) { Ref accepted = ref.get(); refs.add(accepted); } } return refs.build(); } }
/** * The names of the refs that either have changed from their original value or didn't exist at * the time this method is called */ public @Deprecated ImmutableSet<String> getChangedRefs() { Map<String, String> externalOriginals; Map<String, String> externalChanged; { Map<String, String> originals = refDb.getAll(this.txOrigNamespace); Map<String, String> changed = refDb.getAll(this.txChangedNamespace); externalOriginals = toExternal(originals); externalChanged = toExternal(changed); } MapDifference<String, String> difference; difference = Maps.difference(externalOriginals, externalChanged); Map<String, String> changes = new HashMap<>(); // include all new refs changes.putAll(difference.entriesOnlyOnRight()); // include all changed refs, with the new values for (Map.Entry<String, ValueDifference<String>> e : difference.entriesDiffering() .entrySet()) { String name = e.getKey(); ValueDifference<String> valueDifference = e.getValue(); String newValue = valueDifference.rightValue(); changes.put(name, newValue); } return ImmutableSet.copyOf(changes.keySet()); }
@Override public void create() { actual.create(); snapshot.create(); snapshot.putAll(actual.getAll()); }
@Override public void create() { actual.create(); snapshot.create(); snapshot.putAll(actual.getAll()); }
public List<ChangedRef> changedRefs() { MapDifference<String, String> difference; { Map<String, String> externalOriginals; Map<String, String> externalChanged; Map<String, String> originals = refDb.getAll(this.txOrigNamespace); Map<String, String> changed = refDb.getAll(this.txChangedNamespace); externalOriginals = toExternal(originals); externalChanged = toExternal(changed); difference = Maps.difference(externalOriginals, externalChanged); } List<ChangedRef> changes = new ArrayList<>(); // include all new refs difference.entriesOnlyOnRight().forEach((k, v) -> changes.add(ChangedRef.of(k, null, v))); // include all changed refs, with the new values for (Map.Entry<String, ValueDifference<String>> e : difference.entriesDiffering() .entrySet()) { String name = e.getKey(); ValueDifference<String> valueDifference = e.getValue(); String oldValue = valueDifference.leftValue(); String newValue = valueDifference.rightValue(); changes.add(ChangedRef.of(name, oldValue, newValue)); } // deleted refs difference.entriesOnlyOnLeft().forEach((k, v) -> changes.add(ChangedRef.of(k, v, null))); return changes; }
@Test public void testGetAll() { Map<String, String> allrefs = createTestRefs(); Map<String, String> allOnNullNamespace = refDb.getAll(); for (Map.Entry<String, String> e : allrefs.entrySet()) { String key = e.getKey(); String value = e.getValue(); if (key.startsWith(Ref.append(Ref.TRANSACTIONS_PREFIX, "txnamespace"))) { // createRefs added txnamespace1 and txnamespace2 assertFalse( key + " is in a transaction namespace, " + "shall not be returned by getAll()", allOnNullNamespace.containsKey(key)); } else { assertTrue(key + " not found", allOnNullNamespace.containsKey(key)); assertEquals(value, allOnNullNamespace.get(key)); } } }
@Test public void testGetAllNonExistentNamespace() { Map<String, String> all; all = refDb.getAll(Ref.append(Ref.TRANSACTIONS_PREFIX, "nonexistentns")); assertNotNull(all); assertTrue(all.isEmpty()); }
@Test public void testGetAll() { Map<String, String> allrefs = createTestRefs(); Map<String, String> allOnNullNamespace = refDb.getAll(); for (Map.Entry<String, String> e : allrefs.entrySet()) { String key = e.getKey(); String value = e.getValue(); if (key.startsWith(Ref.append(Ref.TRANSACTIONS_PREFIX, "txnamespace"))) { // createRefs added txnamespace1 and txnamespace2 assertFalse( key + " is in a transaction namespace, " + "shall not be returned by getAll()", allOnNullNamespace.containsKey(key)); } else { assertTrue(key + " not found", allOnNullNamespace.containsKey(key)); assertEquals(value, allOnNullNamespace.get(key)); } } }
@Test public void testGetAllNullNamespace() { expected.expect(NullPointerException.class); expected.expectMessage("namespace can't be null"); refDb.getAll(null); }
@Test public void testGetAllNamespace() { final String txNamespace1 = Ref.append(Ref.TRANSACTIONS_PREFIX, "txnamespace1"); final String txNamespace2 = Ref.append(Ref.TRANSACTIONS_PREFIX, "txnamespace2"); Map<String, String> allrefs = createTestRefs(); Map<String, String> allOnNamespace; allOnNamespace = refDb.getAll(txNamespace1); assertNamespace(txNamespace1, allrefs, allOnNamespace); allOnNamespace = refDb.getAll(txNamespace2); assertNamespace(txNamespace2, allrefs, allOnNamespace); }
@Test public void testGetAllNonExistentNamespace() { Map<String, String> all; all = refDb.getAll(Ref.append(Ref.TRANSACTIONS_PREFIX, "nonexistentns")); assertNotNull(all); assertTrue(all.isEmpty()); }
@Test public void testGetAllNullNamespace() { expected.expect(NullPointerException.class); expected.expectMessage("namespace can't be null"); refDb.getAll(null); }
@Test public void testGetAllNamespace() { final String txNamespace1 = Ref.append(Ref.TRANSACTIONS_PREFIX, "txnamespace1"); final String txNamespace2 = Ref.append(Ref.TRANSACTIONS_PREFIX, "txnamespace2"); Map<String, String> allrefs = createTestRefs(); Map<String, String> allOnNamespace; allOnNamespace = refDb.getAll(txNamespace1); assertNamespace(txNamespace1, allrefs, allOnNamespace); allOnNamespace = refDb.getAll(txNamespace2); assertNamespace(txNamespace2, allrefs, allOnNamespace); }