Search in sources :

Example 21 with OrmException

use of com.google.gwtorm.server.OrmException in project gerrit by GerritCodeReview.

the class ConflictsPredicate method predicates.

public static List<Predicate<ChangeData>> predicates(final Arguments args, String value, List<Change> changes) throws QueryParseException, OrmException {
    int indexTerms = 0;
    List<Predicate<ChangeData>> changePredicates = Lists.newArrayListWithCapacity(changes.size());
    final Provider<ReviewDb> db = args.db;
    for (final Change c : changes) {
        final ChangeDataCache changeDataCache = new ChangeDataCache(c, db, args.changeDataFactory, args.projectCache);
        List<String> files = listFiles(c, args, changeDataCache);
        indexTerms += 3 + files.size();
        if (indexTerms > args.indexConfig.maxTerms()) {
            // later on in the query parsing.
            throw new QueryParseException(TOO_MANY_FILES);
        }
        List<Predicate<ChangeData>> filePredicates = Lists.newArrayListWithCapacity(files.size());
        for (String file : files) {
            filePredicates.add(new EqualsPathPredicate(ChangeQueryBuilder.FIELD_PATH, file));
        }
        List<Predicate<ChangeData>> predicatesForOneChange = Lists.newArrayListWithCapacity(5);
        predicatesForOneChange.add(not(new LegacyChangeIdPredicate(c.getId())));
        predicatesForOneChange.add(new ProjectPredicate(c.getProject().get()));
        predicatesForOneChange.add(new RefPredicate(c.getDest().get()));
        predicatesForOneChange.add(or(or(filePredicates), new IsMergePredicate(args, value)));
        predicatesForOneChange.add(new ChangeOperatorPredicate(ChangeQueryBuilder.FIELD_CONFLICTS, value) {

            @Override
            public boolean match(ChangeData object) throws OrmException {
                Change otherChange = object.change();
                if (otherChange == null) {
                    return false;
                }
                if (!otherChange.getDest().equals(c.getDest())) {
                    return false;
                }
                SubmitTypeRecord str = object.submitTypeRecord();
                if (!str.isOk()) {
                    return false;
                }
                ObjectId other = ObjectId.fromString(object.currentPatchSet().getRevision().get());
                ConflictKey conflictsKey = new ConflictKey(changeDataCache.getTestAgainst(), other, str.type, changeDataCache.getProjectState().isUseContentMerge());
                Boolean conflicts = args.conflictsCache.getIfPresent(conflictsKey);
                if (conflicts != null) {
                    return conflicts;
                }
                try (Repository repo = args.repoManager.openRepository(otherChange.getProject());
                    CodeReviewRevWalk rw = CodeReviewCommit.newRevWalk(repo)) {
                    conflicts = !args.submitDryRun.run(str.type, repo, rw, otherChange.getDest(), changeDataCache.getTestAgainst(), other, getAlreadyAccepted(repo, rw));
                    args.conflictsCache.put(conflictsKey, conflicts);
                    return conflicts;
                } catch (IntegrationException | NoSuchProjectException | IOException e) {
                    throw new OrmException(e);
                }
            }

            @Override
            public int getCost() {
                return 5;
            }

            private Set<RevCommit> getAlreadyAccepted(Repository repo, RevWalk rw) throws IntegrationException {
                try {
                    Set<RevCommit> accepted = new HashSet<>();
                    SubmitDryRun.addCommits(changeDataCache.getAlreadyAccepted(repo), rw, accepted);
                    ObjectId tip = changeDataCache.getTestAgainst();
                    if (tip != null) {
                        accepted.add(rw.parseCommit(tip));
                    }
                    return accepted;
                } catch (OrmException | IOException e) {
                    throw new IntegrationException("Failed to determine already accepted commits.", e);
                }
            }
        });
        changePredicates.add(and(predicatesForOneChange));
    }
    return changePredicates;
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) OrPredicate(com.google.gerrit.server.query.OrPredicate) Predicate(com.google.gerrit.server.query.Predicate) OrmException(com.google.gwtorm.server.OrmException) ReviewDb(com.google.gerrit.reviewdb.server.ReviewDb) IntegrationException(com.google.gerrit.server.git.IntegrationException) ObjectId(org.eclipse.jgit.lib.ObjectId) CodeReviewRevWalk(com.google.gerrit.server.git.CodeReviewCommit.CodeReviewRevWalk) Change(com.google.gerrit.reviewdb.client.Change) CodeReviewRevWalk(com.google.gerrit.server.git.CodeReviewCommit.CodeReviewRevWalk) RevWalk(org.eclipse.jgit.revwalk.RevWalk) QueryParseException(com.google.gerrit.server.query.QueryParseException) Repository(org.eclipse.jgit.lib.Repository) SubmitTypeRecord(com.google.gerrit.common.data.SubmitTypeRecord)

Example 22 with OrmException

use of com.google.gwtorm.server.OrmException in project gerrit by GerritCodeReview.

the class ProjectConfigSchemaUpdate method save.

public void save(PersonIdent personIdent, String commitMessage) throws OrmException {
    if (!updated) {
        return;
    }
    update.getCommitBuilder().setAuthor(personIdent);
    update.getCommitBuilder().setCommitter(personIdent);
    update.setMessage(commitMessage);
    try {
        commit(update);
    } catch (IOException e) {
        throw new OrmException(e);
    }
}
Also used : OrmException(com.google.gwtorm.server.OrmException) IOException(java.io.IOException)

Example 23 with OrmException

use of com.google.gwtorm.server.OrmException in project gerrit by GerritCodeReview.

the class SchemaUpdater method update.

public void update(final UpdateUI ui) throws OrmException {
    try (ReviewDb db = ReviewDbUtil.unwrapDb(schema.open())) {
        final SchemaVersion u = updater.get();
        final CurrentSchemaVersion version = getSchemaVersion(db);
        if (version == null) {
            try {
                creator.create(db);
            } catch (IOException | ConfigInvalidException e) {
                throw new OrmException("Cannot initialize schema", e);
            }
        } else {
            try {
                u.check(ui, version, db);
            } catch (SQLException e) {
                throw new OrmException("Cannot upgrade schema", e);
            }
            updateSystemConfig(db);
        }
    }
}
Also used : CurrentSchemaVersion(com.google.gerrit.reviewdb.client.CurrentSchemaVersion) CurrentSchemaVersion(com.google.gerrit.reviewdb.client.CurrentSchemaVersion) ConfigInvalidException(org.eclipse.jgit.errors.ConfigInvalidException) OrmException(com.google.gwtorm.server.OrmException) SQLException(java.sql.SQLException) IOException(java.io.IOException) ReviewDb(com.google.gerrit.reviewdb.server.ReviewDb)

Example 24 with OrmException

use of com.google.gwtorm.server.OrmException in project gerrit by GerritCodeReview.

the class ChangeData method isMergeable.

public Boolean isMergeable() throws OrmException {
    if (mergeable == null) {
        Change c = change();
        if (c == null) {
            return null;
        }
        if (c.getStatus() == Change.Status.MERGED) {
            mergeable = true;
        } else if (c.getStatus() == Change.Status.ABANDONED) {
            return null;
        } else if (c.isWorkInProgress()) {
            return null;
        } else {
            if (!lazyLoad) {
                return null;
            }
            PatchSet ps = currentPatchSet();
            try {
                if (ps == null || !changeControl().isPatchVisible(ps, db)) {
                    return null;
                }
            } catch (OrmException e) {
                if (e.getCause() instanceof NoSuchChangeException) {
                    return null;
                }
                throw e;
            }
            try (Repository repo = repoManager.openRepository(project())) {
                Ref ref = repo.getRefDatabase().exactRef(c.getDest().get());
                SubmitTypeRecord str = submitTypeRecord();
                if (!str.isOk()) {
                    // No need to log, as SubmitRuleEvaluator already did it for us.
                    return false;
                }
                String mergeStrategy = mergeUtilFactory.create(projectCache.get(project())).mergeStrategyName();
                mergeable = mergeabilityCache.get(ObjectId.fromString(ps.getRevision().get()), ref, str.type, mergeStrategy, c.getDest(), repo);
            } catch (IOException e) {
                throw new OrmException(e);
            }
        }
    }
    return mergeable;
}
Also used : Repository(org.eclipse.jgit.lib.Repository) StarRef(com.google.gerrit.server.StarredChangesUtil.StarRef) Ref(org.eclipse.jgit.lib.Ref) NoSuchChangeException(com.google.gerrit.server.project.NoSuchChangeException) SubmitTypeRecord(com.google.gerrit.common.data.SubmitTypeRecord) OrmException(com.google.gwtorm.server.OrmException) PatchSet(com.google.gerrit.reviewdb.client.PatchSet) Change(com.google.gerrit.reviewdb.client.Change) IOException(java.io.IOException)

Example 25 with OrmException

use of com.google.gwtorm.server.OrmException in project gerrit by GerritCodeReview.

the class ChangeData method reloadChange.

public Change reloadChange() throws OrmException {
    try {
        notes = notesFactory.createChecked(db, project, legacyId);
    } catch (NoSuchChangeException e) {
        throw new OrmException("Unable to load change " + legacyId, e);
    }
    change = notes.getChange();
    setPatchSets(null);
    return change;
}
Also used : NoSuchChangeException(com.google.gerrit.server.project.NoSuchChangeException) OrmException(com.google.gwtorm.server.OrmException)

Aggregations

OrmException (com.google.gwtorm.server.OrmException)172 IOException (java.io.IOException)78 Change (com.google.gerrit.reviewdb.client.Change)50 Repository (org.eclipse.jgit.lib.Repository)41 ConfigInvalidException (org.eclipse.jgit.errors.ConfigInvalidException)33 ReviewDb (com.google.gerrit.reviewdb.server.ReviewDb)31 ObjectId (org.eclipse.jgit.lib.ObjectId)29 Account (com.google.gerrit.reviewdb.client.Account)28 RevWalk (org.eclipse.jgit.revwalk.RevWalk)28 PatchSet (com.google.gerrit.reviewdb.client.PatchSet)24 ChangeData (com.google.gerrit.server.query.change.ChangeData)24 Map (java.util.Map)22 ArrayList (java.util.ArrayList)21 ChangeNotes (com.google.gerrit.server.notedb.ChangeNotes)20 Inject (com.google.inject.Inject)18 Provider (com.google.inject.Provider)17 RestApiException (com.google.gerrit.extensions.restapi.RestApiException)16 Set (java.util.Set)16 BatchUpdate (com.google.gerrit.server.update.BatchUpdate)15 CurrentUser (com.google.gerrit.server.CurrentUser)14