List of usage examples for org.eclipse.jgit.lib Ref getStorage
@NonNull Storage getStorage();
From source file:com.benhumphreys.jgitcassandra.repo.CassandraRefDatabase.java
License:Apache License
/** * Compare a reference, and put if it matches. * * @param oldRef old value to compare to. If the reference is expected * to not exist the old value has a storage of * Ref.Storage.NEW and an ObjectId value of null. * @param newRef new reference to store. * @return true if the put was successful; false otherwise. * @throws IOException the reference cannot be put due to a system error. *//*from ww w. j a v a2s .c om*/ @Override protected boolean compareAndPut(Ref oldRef, Ref newRef) throws IOException { String name = newRef.getName(); if (oldRef == null || oldRef.getStorage() == Ref.Storage.NEW) return refs.putIfAbsent(name, newRef) == null; Ref cur = refs.get(name); if (cur != null && Utils.refsHaveEqualObjectId(cur, oldRef)) { return refs.replace(name, cur, newRef); } else { return false; } }
From source file:org.chodavarapu.jgitaws.repositories.RefRepository.java
License:Eclipse Distribution License
public Observable<Boolean> compareAndPut(String repositoryName, Ref oldRef, Ref newRef) { boolean isSymbolic = newRef.isSymbolic(); boolean isPeeled = newRef.isPeeled(); String target = newRef.isSymbolic() ? newRef.getTarget().getName() : newRef.getObjectId().name(); logger.debug("Saving ref {} -> {} in repository {}", newRef.getName(), target, repositoryName); UpdateItemSpec updateSpec = new UpdateItemSpec() .withPrimaryKey(new PrimaryKey(new KeyAttribute(REPOSITORY_NAME_ATTRIBUTE, repositoryName), new KeyAttribute(NAME_ATTRIBUTE, newRef.getName()))); StringBuilder updateExpression = new StringBuilder(COMPARE_AND_PUT_EXPRESSION); ValueMap valueMap = new ValueMap().withString(":target", target).withBoolean(":isSymbolic", isSymbolic) .withBoolean(":isPeeled", isPeeled); if (isPeeled && newRef.getPeeledObjectId() != null) { updateExpression.append(", "); updateExpression.append(PEELED_TARGET_ATTRIBUTE); updateExpression.append(" = :peeledTarget"); valueMap = valueMap.withString(":peeledTarget", newRef.getPeeledObjectId().name()); }/*w w w. j av a2s .c o m*/ if (oldRef != null && oldRef.getStorage() != Ref.Storage.NEW) { String expected = oldRef.isSymbolic() ? oldRef.getTarget().getName() : oldRef.getObjectId().name(); updateSpec = updateSpec.withConditionExpression("#target = :expected") .withNameMap(new NameMap().with("#target", TARGET_ATTRIBUTE)); valueMap = valueMap.withString(":expected", expected); } updateSpec = updateSpec.withUpdateExpression(updateExpression.toString()).withValueMap(valueMap); return configuration.getDynamoClient() .updateItem(configuration.getRefsTableName(), updateSpec, tableCreator).map(v -> true) .doOnNext(v -> logger.debug("Saved ref {} in repository {}", newRef.getName(), repositoryName)) .onErrorReturn(t -> false); }