use of org.projectnessie.versioned.Hash in project nessie by projectnessie.
the class TxDatabaseAdapter method namedRefs.
public Stream<ReferenceInfo<ByteString>> namedRefs(GetNamedRefsParams params) throws ReferenceNotFoundException {
Preconditions.checkNotNull(params, "Parameter for GetNamedRefsParams must not be null.");
Preconditions.checkArgument(namedRefsAnyRetrieves(params), "Must retrieve branches or tags or both.");
ConnectionWrapper conn = borrowConnection();
boolean failed = true;
try {
Hash defaultBranchHead = namedRefsDefaultBranchHead(conn, params);
Stream<ReferenceInfo<ByteString>> refs = fetchNamedRefs(conn);
refs = namedRefsFilterAndEnhance(conn, params, defaultBranchHead, refs);
failed = false;
return refs.onClose(conn::close);
} finally {
if (failed) {
conn.close();
}
}
}
use of org.projectnessie.versioned.Hash in project nessie by projectnessie.
the class TxDatabaseAdapter method merge.
@Override
public Hash merge(Hash from, BranchName toBranch, Optional<Hash> expectedHead, Function<ByteString, ByteString> updateCommitMetadata) throws ReferenceNotFoundException, ReferenceConflictException {
// creates a new commit-tree that is decoupled from other commit-trees.
try {
return opLoop("merge", toBranch, false, (conn, currentHead) -> {
long timeInMicros = commitTimeInMicros();
Hash toHead = mergeAttempt(conn, timeInMicros, from, toBranch, expectedHead, currentHead, h -> {
}, h -> {
}, updateCommitMetadata);
Hash resultHash = tryMoveNamedReference(conn, toBranch, currentHead, toHead);
commitRefLog(conn, timeInMicros, toHead, toBranch, RefLogEntry.Operation.MERGE, Collections.singletonList(from));
return resultHash;
}, () -> mergeConflictMessage("Conflict", from, toBranch, expectedHead), () -> mergeConflictMessage("Retry-failure", from, toBranch, expectedHead));
} catch (ReferenceNotFoundException | ReferenceConflictException | RuntimeException e) {
throw e;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of org.projectnessie.versioned.Hash in project nessie by projectnessie.
the class TxDatabaseAdapter method doFetchMultipleFromCommitLog.
@Override
protected List<CommitLogEntry> doFetchMultipleFromCommitLog(ConnectionWrapper c, List<Hash> hashes) {
String sql = sqlForManyPlaceholders(SqlStatements.SELECT_COMMIT_LOG_MANY, hashes.size());
try (PreparedStatement ps = c.conn().prepareStatement(sql)) {
ps.setString(1, config.getRepositoryId());
for (int i = 0; i < hashes.size(); i++) {
ps.setString(2 + i, hashes.get(i).asString());
}
Map<Hash, CommitLogEntry> result = new HashMap<>(hashes.size() * 2);
try (ResultSet rs = ps.executeQuery()) {
while (rs.next()) {
CommitLogEntry entry = protoToCommitLogEntry(rs.getBytes(1));
result.put(entry.getHash(), entry);
}
}
return hashes.stream().map(result::get).collect(Collectors.toList());
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
use of org.projectnessie.versioned.Hash in project nessie by projectnessie.
the class TxDatabaseAdapter method doFetchPageFromRefLog.
@Override
protected List<RefLog> doFetchPageFromRefLog(ConnectionWrapper connection, List<Hash> hashes) {
String sql = sqlForManyPlaceholders(SqlStatements.SELECT_REF_LOG_MANY, hashes.size());
try (PreparedStatement ps = connection.conn().prepareStatement(sql)) {
ps.setString(1, config.getRepositoryId());
for (int i = 0; i < hashes.size(); i++) {
ps.setString(2 + i, hashes.get(i).asString());
}
Map<Hash, RefLog> result = new HashMap<>(hashes.size() * 2);
try (ResultSet rs = ps.executeQuery()) {
while (rs.next()) {
RefLog entry = protoToRefLog(rs.getBytes(1));
result.put(Objects.requireNonNull(entry).getRefLogId(), entry);
}
}
return hashes.stream().map(result::get).collect(Collectors.toList());
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
use of org.projectnessie.versioned.Hash in project nessie by projectnessie.
the class TxDatabaseAdapter method fetchNamedRefs.
protected Stream<ReferenceInfo<ByteString>> fetchNamedRefs(ConnectionWrapper conn) {
return JdbcSelectSpliterator.buildStream(conn.conn(), SqlStatements.SELECT_NAMED_REFERENCES, ps -> ps.setString(1, config.getRepositoryId()), (rs) -> {
String type = rs.getString(1);
String ref = rs.getString(2);
Hash head = Hash.of(rs.getString(3));
NamedRef namedRef = namedRefFromRow(type, ref);
if (namedRef != null) {
return ReferenceInfo.of(head, namedRef);
}
return null;
});
}
Aggregations