Search in sources :

Example 76 with OrmException

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

the class AllAccountsIndexer method indexAll.

@Override
public SiteIndexer.Result indexAll(final AccountIndex index) {
    ProgressMonitor progress = new TextProgressMonitor(new PrintWriter(progressOut));
    progress.start(2);
    Stopwatch sw = Stopwatch.createStarted();
    List<Account.Id> ids;
    try {
        ids = collectAccounts(progress);
    } catch (OrmException e) {
        log.error("Error collecting accounts", e);
        return new SiteIndexer.Result(sw, false, 0, 0);
    }
    return reindexAccounts(index, ids, progress);
}
Also used : ProgressMonitor(org.eclipse.jgit.lib.ProgressMonitor) TextProgressMonitor(org.eclipse.jgit.lib.TextProgressMonitor) SiteIndexer(com.google.gerrit.server.index.SiteIndexer) OrmException(com.google.gwtorm.server.OrmException) Stopwatch(com.google.common.base.Stopwatch) TextProgressMonitor(org.eclipse.jgit.lib.TextProgressMonitor) PrintWriter(java.io.PrintWriter)

Example 77 with OrmException

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

the class ChangeField method toProtos.

private static <T> List<byte[]> toProtos(ProtobufCodec<T> codec, Collection<T> objs) throws OrmException {
    List<byte[]> result = Lists.newArrayListWithCapacity(objs.size());
    ByteArrayOutputStream out = new ByteArrayOutputStream(256);
    try {
        for (T obj : objs) {
            out.reset();
            CodedOutputStream cos = CodedOutputStream.newInstance(out);
            codec.encode(obj, cos);
            cos.flush();
            result.add(out.toByteArray());
        }
    } catch (IOException e) {
        throw new OrmException(e);
    }
    return result;
}
Also used : OrmException(com.google.gwtorm.server.OrmException) CodedOutputStream(com.google.protobuf.CodedOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException)

Example 78 with OrmException

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

the class IndexedChangeQuery method read.

@Override
public ResultSet<ChangeData> read() throws OrmException {
    final DataSource<ChangeData> currSource = source;
    final ResultSet<ChangeData> rs = currSource.read();
    return new ResultSet<ChangeData>() {

        @Override
        public Iterator<ChangeData> iterator() {
            return Iterables.transform(rs, cd -> {
                fromSource.put(cd, currSource);
                return cd;
            }).iterator();
        }

        @Override
        public List<ChangeData> toList() {
            List<ChangeData> r = rs.toList();
            for (ChangeData cd : r) {
                fromSource.put(cd, currSource);
            }
            return r;
        }

        @Override
        public void close() {
            rs.close();
        }
    };
}
Also used : Iterables(com.google.common.collect.Iterables) OrmException(com.google.gwtorm.server.OrmException) Change(com.google.gerrit.reviewdb.client.Change) HashMap(java.util.HashMap) IndexedQuery(com.google.gerrit.server.index.IndexedQuery) Matchable(com.google.gerrit.server.query.Matchable) HashSet(java.util.HashSet) IndexConfig(com.google.gerrit.server.index.IndexConfig) CHANGE(com.google.gerrit.server.index.change.ChangeField.CHANGE) ResultSet(com.google.gwtorm.server.ResultSet) DataSource(com.google.gerrit.server.query.DataSource) Map(java.util.Map) ChangeDataSource(com.google.gerrit.server.query.change.ChangeDataSource) ImmutableSet(com.google.common.collect.ImmutableSet) Iterator(java.util.Iterator) Set(java.util.Set) Preconditions.checkState(com.google.common.base.Preconditions.checkState) Predicate(com.google.gerrit.server.query.Predicate) QueryParseException(com.google.gerrit.server.query.QueryParseException) ChangeData(com.google.gerrit.server.query.change.ChangeData) List(java.util.List) PROJECT(com.google.gerrit.server.index.change.ChangeField.PROJECT) QueryOptions(com.google.gerrit.server.index.QueryOptions) VisibleForTesting(com.google.common.annotations.VisibleForTesting) IndexPredicate(com.google.gerrit.server.index.IndexPredicate) ResultSet(com.google.gwtorm.server.ResultSet) ChangeData(com.google.gerrit.server.query.change.ChangeData)

Example 79 with OrmException

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

the class DbGroupMemberAuditListener method onDeleteAccountsFromGroup.

@Override
public void onDeleteAccountsFromGroup(Account.Id me, Collection<AccountGroupMember> removed) {
    List<AccountGroupMemberAudit> auditInserts = new ArrayList<>();
    List<AccountGroupMemberAudit> auditUpdates = new ArrayList<>();
    try (ReviewDb db = schema.open()) {
        for (AccountGroupMember m : removed) {
            AccountGroupMemberAudit audit = null;
            for (AccountGroupMemberAudit a : db.accountGroupMembersAudit().byGroupAccount(m.getAccountGroupId(), m.getAccountId())) {
                if (a.isActive()) {
                    audit = a;
                    break;
                }
            }
            if (audit != null) {
                audit.removed(me, TimeUtil.nowTs());
                auditUpdates.add(audit);
            } else {
                audit = new AccountGroupMemberAudit(m, me, TimeUtil.nowTs());
                audit.removedLegacy();
                auditInserts.add(audit);
            }
        }
        db.accountGroupMembersAudit().update(auditUpdates);
        db.accountGroupMembersAudit().insert(auditInserts);
    } catch (OrmException e) {
        logOrmExceptionForAccounts("Cannot log delete accounts from group event performed by user", me, removed, e);
    }
}
Also used : AccountGroupMember(com.google.gerrit.reviewdb.client.AccountGroupMember) OrmException(com.google.gwtorm.server.OrmException) AccountGroupMemberAudit(com.google.gerrit.reviewdb.client.AccountGroupMemberAudit) ArrayList(java.util.ArrayList) ReviewDb(com.google.gerrit.reviewdb.server.ReviewDb)

Example 80 with OrmException

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

the class DbGroupMemberAuditListener method onAddGroupsToGroup.

@Override
public void onAddGroupsToGroup(Account.Id me, Collection<AccountGroupById> added) {
    List<AccountGroupByIdAud> includesAudit = new ArrayList<>();
    for (AccountGroupById groupInclude : added) {
        AccountGroupByIdAud audit = new AccountGroupByIdAud(groupInclude, me, TimeUtil.nowTs());
        includesAudit.add(audit);
    }
    try (ReviewDb db = schema.open()) {
        db.accountGroupByIdAud().insert(includesAudit);
    } catch (OrmException e) {
        logOrmExceptionForGroups("Cannot log add groups to group event performed by user", me, added, e);
    }
}
Also used : AccountGroupByIdAud(com.google.gerrit.reviewdb.client.AccountGroupByIdAud) OrmException(com.google.gwtorm.server.OrmException) ArrayList(java.util.ArrayList) AccountGroupById(com.google.gerrit.reviewdb.client.AccountGroupById) ReviewDb(com.google.gerrit.reviewdb.server.ReviewDb)

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