use of org.projectnessie.versioned.NamedRef in project nessie by projectnessie.
the class TxDatabaseAdapter method fetchNamedRef.
protected ReferenceInfo<ByteString> fetchNamedRef(ConnectionWrapper c, String ref) throws ReferenceNotFoundException {
try (Traced ignore = trace("fetchNamedRef");
PreparedStatement ps = c.conn().prepareStatement(SqlStatements.SELECT_NAMED_REFERENCE_ANY)) {
ps.setString(1, config.getRepositoryId());
ps.setString(2, ref);
try (ResultSet rs = ps.executeQuery()) {
if (rs.next()) {
Hash hash = Hash.of(rs.getString(2));
NamedRef namedRef = namedRefFromRow(rs.getString(1), ref);
return ReferenceInfo.of(hash, namedRef);
}
throw referenceNotFound(ref);
}
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
use of org.projectnessie.versioned.NamedRef in project nessie by projectnessie.
the class NonTransactionalDatabaseAdapter method updateGlobalStatePointer.
/**
* Produces an updated copy of {@code pointer}.
*
* <p>Any previous appearance of {@code target.getName()} in the list of named references is
* removed. If {@code toHead} is not null, {@code target} it will appear as the first element in
* the list of named references. In other words, a reference to be deleted will be removed from
* the list of named references, an updated (or created) reference will appear as the first
* element of the list of named references.
*/
protected static GlobalStatePointer updateGlobalStatePointer(NamedRef target, GlobalStatePointer pointer, @Nullable Hash toHead, GlobalStateLogEntry newGlobalHead, RefLogEntry newRefLog) {
GlobalStatePointer.Builder newPointer = GlobalStatePointer.newBuilder().setGlobalId(newGlobalHead.getId()).setRefLogId(newRefLog.getRefLogId());
String refName = target.getName();
if (toHead != null) {
// Most recently updated references first
newPointer.addNamedReferences(NamedReference.newBuilder().setName(refName).setRef(RefPointer.newBuilder().setType(protoTypeForRef(target)).setHash(toHead.asBytes())));
}
pointer.getNamedReferencesList().stream().filter(namedRef -> !refName.equals(namedRef.getName())).forEach(newPointer::addNamedReferences);
newPointer.addRefLogParentsInclHead(newRefLog.getRefLogId()).addAllRefLogParentsInclHead(newRefLog.getParentsList()).addGlobalParentsInclHead(newGlobalHead.getId()).addAllGlobalParentsInclHead(newGlobalHead.getParentsList());
return newPointer.build();
}
Aggregations