Package com.google.gerrit.reviewdb.server

Examples of com.google.gerrit.reviewdb.server.ReviewDb


      @Override
      public void run() {
        PatchSet patchSet;
        PatchSetApproval submitter;
        try {
          ReviewDb reviewDb = schemaFactory.open();
          try {
            patchSet = reviewDb.patchSets().get(c.currentPatchSetId());
            submitter = getSubmitter(reviewDb, c.currentPatchSetId());
          } finally {
            reviewDb.close();
          }
        } catch (Exception e) {
          log.error("Cannot send email notifications about merge failure", e);
          return;
        }
View Full Code Here


   *         cannot be unlinked at this time.
   */
  public AuthResult unlink(final Account.Id from, AuthRequest who)
      throws AccountException {
    try {
      final ReviewDb db = schema.open();
      try {
        who = realm.unlink(db, from, who);

        final AccountExternalId.Key key = id(who);
        AccountExternalId extId = db.accountExternalIds().get(key);
        if (extId != null) {
          if (!extId.getAccountId().equals(from)) {
            throw new AccountException("Identity in use by another account");
          }
          db.accountExternalIds().delete(Collections.singleton(extId));

          if (who.getEmailAddress() != null) {
            final Account a = db.accounts().get(from);
            if (a.getPreferredEmail() != null
                && a.getPreferredEmail().equals(who.getEmailAddress())) {
              a.setPreferredEmail(null);
              db.accounts().update(Collections.singleton(a));
            }
            byEmailCache.evict(who.getEmailAddress());
            byIdCache.evict(from);
          }

        } else {
          throw new AccountException("Identity not found");
        }

        return new AuthResult(from, key, false);

      } finally {
        db.close();
      }
    } catch (OrmException e) {
      throw new AccountException("Cannot unlink identity", e);
    }
  }
View Full Code Here

    this.version = version;
  }

  public void start() {
    try {
      final ReviewDb db = schema.open();
      try {
        final CurrentSchemaVersion sVer = getSchemaVersion(db);
        final int eVer = version.get().getVersionNbr();

        if (sVer == null) {
          throw new ProvisionException("Schema not yet initialized."
              + "  Run init to initialize the schema.");
        }
        if (sVer.versionNbr != eVer) {
          throw new ProvisionException("Unsupported schema version "
              + sVer.versionNbr + "; expected schema version " + eVer
              + ".  Run init to upgrade.");
        }
      } finally {
        db.close();
      }
    } catch (OrmException e) {
      throw new ProvisionException("Cannot read schema_version", e);
    }
  }
View Full Code Here

    this.creator = creator;
    this.updater = update;
  }

  public void update(final UpdateUI ui) throws OrmException {
    final ReviewDb db = schema.open();
    try {
      final SchemaVersion u = updater.get();
      final CurrentSchemaVersion version = getSchemaVersion(db);
      if (version == null) {
        try {
          creator.create(db);
        } catch (IOException e) {
          throw new OrmException("Cannot initialize schema", e);
        } catch (ConfigInvalidException e) {
          throw new OrmException("Cannot initialize schema", e);
        }

      } else {
        try {
          u.check(ui, version, db, true);
        } catch (SQLException e) {
          throw new OrmException("Cannot upgrade schema", e);
        }

        updateSystemConfig(db);
      }
    } finally {
      db.close();
    }
  }
View Full Code Here

  }

  @Override
  public Iterable<AccountGroup> all() {
    try {
      ReviewDb db = schema.open();
      try {
        return Collections.unmodifiableList(db.accountGroups().all().toList());
      } finally {
        db.close();
      }
    } catch (OrmException e) {
      log.warn("Cannot list internal groups", e);
      return Collections.emptyList();
    }
View Full Code Here

    }

    @Override
    public Optional<AccountGroup> load(final AccountGroup.Id key)
        throws Exception {
      final ReviewDb db = schema.open();
      try {
        return Optional.fromNullable(db.accountGroups().get(key));
      } finally {
        db.close();
      }
    }
View Full Code Here

    }

    @Override
    public Optional<AccountGroup> load(String name)
        throws Exception {
      final ReviewDb db = schema.open();
      try {
        AccountGroup.NameKey key = new AccountGroup.NameKey(name);
        AccountGroupName r = db.accountGroupNames().get(key);
        if (r != null) {
          return Optional.fromNullable(db.accountGroups().get(r.getId()));
        }
        return Optional.absent();
      } finally {
        db.close();
      }
    }
View Full Code Here

    }

    @Override
    public Optional<AccountGroup> load(String uuid)
        throws Exception {
      final ReviewDb db = schema.open();
      try {
        List<AccountGroup> r;

        r = db.accountGroups().byUUID(new AccountGroup.UUID(uuid)).toList();
        if (r.size() == 1) {
          return Optional.of(r.get(0));
        } else if (r.size() == 0) {
          return Optional.absent();
        } else {
          throw new OrmDuplicateKeyException("Duplicate group UUID " + uuid);
        }
      } finally {
        db.close();
      }
    }
View Full Code Here

        .submit(requestScopePropagator.wrap(new Runnable() {
      @Override
      public void run() {
        PatchSetInfo patchSetInfo;
        try {
          ReviewDb reviewDb = schemaFactory.open();
          try {
            patchSetInfo = patchSetInfoFactory.get(reviewDb, patchSetId);
          } finally {
            reviewDb.close();
          }
        } catch (PatchSetInfoNotAvailableException e) {
          log.error("Cannot read PatchSetInfo of " + patchSetId, e);
          return;
        } catch (Exception e) {
View Full Code Here

      this.byName = byUsername;
    }

    @Override
    public AccountState load(Account.Id key) throws Exception {
      final ReviewDb db = schema.open();
      try {
        final AccountState state = load(db, key);
        String user = state.getUserName();
        if (user != null) {
          byName.put(user, Optional.of(state.getAccount().getId()));
        }
        return state;
      } finally {
        db.close();
      }
    }
View Full Code Here

TOP

Related Classes of com.google.gerrit.reviewdb.server.ReviewDb

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.