Search in sources :

Example 11 with NamedRef

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);
    }
}
Also used : Traced(org.projectnessie.versioned.persist.adapter.spi.Traced) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) DatabaseAdapterUtil.verifyExpectedHash(org.projectnessie.versioned.persist.adapter.spi.DatabaseAdapterUtil.verifyExpectedHash) Hash(org.projectnessie.versioned.Hash) DatabaseAdapterUtil.randomHash(org.projectnessie.versioned.persist.adapter.spi.DatabaseAdapterUtil.randomHash) NamedRef(org.projectnessie.versioned.NamedRef)

Example 12 with NamedRef

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();
}
Also used : Type(org.projectnessie.versioned.persist.serialize.AdapterTypes.RefPointer.Type) DatabaseAdapterUtil.referenceNotFound(org.projectnessie.versioned.persist.adapter.spi.DatabaseAdapterUtil.referenceNotFound) KeyListEntity(org.projectnessie.versioned.persist.adapter.KeyListEntity) DatabaseAdapterUtil.deleteConflictMessage(org.projectnessie.versioned.persist.adapter.spi.DatabaseAdapterUtil.deleteConflictMessage) DatabaseAdapterUtil.takeUntilExcludeLast(org.projectnessie.versioned.persist.adapter.spi.DatabaseAdapterUtil.takeUntilExcludeLast) GetNamedRefsParams(org.projectnessie.versioned.GetNamedRefsParams) GlobalStateLogEntry(org.projectnessie.versioned.persist.serialize.AdapterTypes.GlobalStateLogEntry) CommitAttempt(org.projectnessie.versioned.persist.adapter.CommitAttempt) Map(java.util.Map) Traced(org.projectnessie.versioned.persist.adapter.spi.Traced) ContentIdWithBytes(org.projectnessie.versioned.persist.serialize.AdapterTypes.ContentIdWithBytes) AdapterTypes(org.projectnessie.versioned.persist.serialize.AdapterTypes) DatabaseAdapterUtil.mergeConflictMessage(org.projectnessie.versioned.persist.adapter.spi.DatabaseAdapterUtil.mergeConflictMessage) NamedRef(org.projectnessie.versioned.NamedRef) ProtoSerialization(org.projectnessie.versioned.persist.serialize.ProtoSerialization) DatabaseAdapterUtil.createConflictMessage(org.projectnessie.versioned.persist.adapter.spi.DatabaseAdapterUtil.createConflictMessage) ImmutableMap(com.google.common.collect.ImmutableMap) RefType(org.projectnessie.versioned.persist.serialize.AdapterTypes.RefLogEntry.RefType) DatabaseAdapterUtil.verifyExpectedHash(org.projectnessie.versioned.persist.adapter.spi.DatabaseAdapterUtil.verifyExpectedHash) Collection(java.util.Collection) Set(java.util.Set) DatabaseAdapterUtil.takeUntilIncludeLast(org.projectnessie.versioned.persist.adapter.spi.DatabaseAdapterUtil.takeUntilIncludeLast) ReferenceAlreadyExistsException(org.projectnessie.versioned.ReferenceAlreadyExistsException) Collectors(java.util.stream.Collectors) ByteString(com.google.protobuf.ByteString) BranchName(org.projectnessie.versioned.BranchName) ReferenceConflictException(org.projectnessie.versioned.ReferenceConflictException) List(java.util.List) Stream(java.util.stream.Stream) Difference(org.projectnessie.versioned.persist.adapter.Difference) NamedReference(org.projectnessie.versioned.persist.serialize.AdapterTypes.NamedReference) DatabaseAdapterUtil.hashCollisionDetected(org.projectnessie.versioned.persist.adapter.spi.DatabaseAdapterUtil.hashCollisionDetected) TryLoopState.newTryLoopState(org.projectnessie.versioned.persist.adapter.spi.TryLoopState.newTryLoopState) Optional(java.util.Optional) Spliterator(java.util.Spliterator) TryLoopState(org.projectnessie.versioned.persist.adapter.spi.TryLoopState) DatabaseAdapterUtil.referenceAlreadyExists(org.projectnessie.versioned.persist.adapter.spi.DatabaseAdapterUtil.referenceAlreadyExists) NON_TRANSACTIONAL_OPERATION_CONTEXT(org.projectnessie.versioned.persist.nontx.NonTransactionalOperationContext.NON_TRANSACTIONAL_OPERATION_CONTEXT) DatabaseAdapterUtil.commitConflictMessage(org.projectnessie.versioned.persist.adapter.spi.DatabaseAdapterUtil.commitConflictMessage) RepoDescription(org.projectnessie.versioned.persist.adapter.RepoDescription) DatabaseAdapterUtil.repoDescUpdateConflictMessage(org.projectnessie.versioned.persist.adapter.spi.DatabaseAdapterUtil.repoDescUpdateConflictMessage) RefLogNotFoundException(org.projectnessie.versioned.RefLogNotFoundException) DatabaseAdapterUtil.assignConflictMessage(org.projectnessie.versioned.persist.adapter.spi.DatabaseAdapterUtil.assignConflictMessage) TagName(org.projectnessie.versioned.TagName) KeyListEntry(org.projectnessie.versioned.persist.adapter.KeyListEntry) HashMap(java.util.HashMap) Function(java.util.function.Function) Supplier(java.util.function.Supplier) AbstractDatabaseAdapter(org.projectnessie.versioned.persist.adapter.spi.AbstractDatabaseAdapter) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) RepoMaintenanceParams(org.projectnessie.versioned.persist.adapter.RepoMaintenanceParams) KeyFilterPredicate(org.projectnessie.versioned.persist.adapter.KeyFilterPredicate) DatabaseAdapterUtil.transplantConflictMessage(org.projectnessie.versioned.persist.adapter.spi.DatabaseAdapterUtil.transplantConflictMessage) RefLog(org.projectnessie.versioned.persist.adapter.RefLog) CommitLogEntry(org.projectnessie.versioned.persist.adapter.CommitLogEntry) Builder(org.projectnessie.versioned.persist.serialize.AdapterTypes.GlobalStateLogEntry.Builder) StreamSupport(java.util.stream.StreamSupport) ContentVariantSupplier(org.projectnessie.versioned.persist.adapter.ContentVariantSupplier) Nullable(javax.annotation.Nullable) RefPointer(org.projectnessie.versioned.persist.serialize.AdapterTypes.RefPointer) Operation(org.projectnessie.versioned.persist.serialize.AdapterTypes.RefLogEntry.Operation) ContentIdAndBytes(org.projectnessie.versioned.persist.adapter.ContentIdAndBytes) Hash(org.projectnessie.versioned.Hash) Traced.trace(org.projectnessie.versioned.persist.adapter.spi.Traced.trace) VersionStoreException(org.projectnessie.versioned.VersionStoreException) RefLogEntry(org.projectnessie.versioned.persist.serialize.AdapterTypes.RefLogEntry) Key(org.projectnessie.versioned.Key) GlobalStatePointer(org.projectnessie.versioned.persist.serialize.AdapterTypes.GlobalStatePointer) ReferenceNotFoundException(org.projectnessie.versioned.ReferenceNotFoundException) DatabaseAdapterUtil.randomHash(org.projectnessie.versioned.persist.adapter.spi.DatabaseAdapterUtil.randomHash) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) ContentAndState(org.projectnessie.versioned.persist.adapter.ContentAndState) ReferenceInfo(org.projectnessie.versioned.ReferenceInfo) Preconditions(com.google.common.base.Preconditions) GlobalLogCompactionParams(org.projectnessie.versioned.persist.adapter.GlobalLogCompactionParams) Collections(java.util.Collections) ContentId(org.projectnessie.versioned.persist.adapter.ContentId) GlobalStatePointer(org.projectnessie.versioned.persist.serialize.AdapterTypes.GlobalStatePointer) ByteString(com.google.protobuf.ByteString)

Aggregations

NamedRef (org.projectnessie.versioned.NamedRef)12 ReferenceNotFoundException (org.projectnessie.versioned.ReferenceNotFoundException)6 NessieReferenceNotFoundException (org.projectnessie.error.NessieReferenceNotFoundException)5 CommitMeta (org.projectnessie.model.CommitMeta)5 Hash (org.projectnessie.versioned.Hash)5 List (java.util.List)4 Collectors (java.util.stream.Collectors)4 Content (org.projectnessie.model.Content)4 Principal (java.security.Principal)3 Map (java.util.Map)3 Nullable (javax.annotation.Nullable)3 NessieNotFoundException (org.projectnessie.error.NessieNotFoundException)3 ContentKey (org.projectnessie.model.ContentKey)3 RefUtil.toNamedRef (org.projectnessie.services.impl.RefUtil.toNamedRef)3 BranchName (org.projectnessie.versioned.BranchName)3 ReferenceAlreadyExistsException (org.projectnessie.versioned.ReferenceAlreadyExistsException)3 Preconditions (com.google.common.base.Preconditions)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 ByteString (com.google.protobuf.ByteString)2 Collections (java.util.Collections)2