Package com.google.gerrit.reviewdb.server

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


      this.schema = sf;
    }

    @Override
    public Optional<Account.Id> load(String username) throws Exception {
      final ReviewDb db = schema.open();
      try {
        final AccountExternalId.Key key = new AccountExternalId.Key( //
            AccountExternalId.SCHEME_USERNAME, //
            username);
        final AccountExternalId id = db.accountExternalIds().get(key);
        if (id != null) {
          return Optional.of(id.getAccountId());
        }
        return Optional.absent();
      } finally {
        db.close();
      }
    }
View Full Code Here


      schema = sf;
    }

    @Override
    public Set<AccountGroup.UUID> load(AccountGroup.UUID key) throws Exception {
      final ReviewDb db = schema.open();
      try {
        List<AccountGroup> group = db.accountGroups().byUUID(key).toList();
        if (group.size() != 1) {
          return Collections.emptySet();
        }

        Set<AccountGroup.Id> ids = Sets.newHashSet();
        for (AccountGroupInclude agi : db.accountGroupIncludes()
            .byInclude(group.get(0).getId())) {
          ids.add(agi.getGroupId());
        }

        Set<AccountGroup.UUID> groupArray = Sets.newHashSet();
        for (AccountGroup g : db.accountGroups().get(ids)) {
          groupArray.add(g.getGroupUUID());
        }
        return ImmutableSet.copyOf(groupArray);
      } finally {
        db.close();
      }
    }
View Full Code Here

      this.schema = schema;
    }

    @Override
    public Set<Account.Id> load(String email) throws Exception {
      final ReviewDb db = schema.open();
      try {
        Set<Account.Id> r = Sets.newHashSet();
        for (Account a : db.accounts().byPreferredEmail(email)) {
          r.add(a.getId());
        }
        for (AccountExternalId a : db.accountExternalIds()
            .byEmailAddress(email)) {
          r.add(a.getAccountId());
        }
        return ImmutableSet.copyOf(r);
      } finally {
        db.close();
      }
    }
View Full Code Here

    field(b, "Date", df.format(on) + " " + UTC.getID());
    field(b, "Full-Name", account.getFullName());
    field(b, "Preferred-Email", account.getPreferredEmail());

    try {
      final ReviewDb db = schema.open();
      try {
        for (final AccountExternalId e : db.accountExternalIds().byAccount(
            account.getId())) {
          final StringBuilder oistr = new StringBuilder();
          if (e.getEmailAddress() != null && e.getEmailAddress().length() > 0) {
            if (oistr.length() > 0) {
              oistr.append(' ');
            }
            oistr.append(e.getEmailAddress());
          }
          if (e.isScheme(AccountExternalId.SCHEME_MAILTO)) {
            if (oistr.length() > 0) {
              oistr.append(' ');
            }
            oistr.append('<');
            oistr.append(e.getExternalId());
            oistr.append('>');
          }
          field(b, "Identity", oistr.toString());
        }
      } finally {
        db.close();
      }
    } catch (OrmException e) {
      throw new ContactInformationStoreException(e);
    }
View Full Code Here

        devmode.getParentNode().removeChild(devmode);
      }
    }

    Element userlistElement = HtmlDomUtil.find(doc, "userlist");
    ReviewDb db = schema.open();
    try {
      ResultSet<Account> accounts = db.accounts().firstNById(5);
      for (Account a : accounts) {
        String displayName;
        if (a.getUserName() != null) {
          displayName = a.getUserName();
        } else if (a.getFullName() != null) {
          displayName = a.getFullName();
        } else if (a.getPreferredEmail() != null) {
          displayName = a.getPreferredEmail();
        } else {
          displayName = a.getId().toString();
        }

        Element linkElement = doc.createElement("a");
        linkElement.setAttribute("href", "?account_id=" + a.getId().toString());
        linkElement.setTextContent(displayName);
        userlistElement.appendChild(linkElement);
        userlistElement.appendChild(doc.createElement("br"));
      }
    } finally {
      db.close();
    }

    return HtmlDomUtil.toUTF8(doc);
  }
View Full Code Here

  }

  private AuthResult byUserName(final HttpServletResponse rsp,
      final String userName) {
    try {
      final ReviewDb db = schema.open();
      try {
        AccountExternalId.Key key =
            new AccountExternalId.Key(SCHEME_USERNAME, userName);
        return auth(db.accountExternalIds().get(key));
      } finally {
        db.close();
      }
    } catch (OrmException e) {
      getServletContext().log("cannot query database", e);
      return null;
    }
View Full Code Here

  }

  private AuthResult byPreferredEmail(final HttpServletResponse rsp,
      final String email) {
    try {
      final ReviewDb db = schema.open();
      try {
        List<Account> matches = db.accounts().byPreferredEmail(email).toList();
        return matches.size() == 1 ? auth(matches.get(0)) : null;
      } finally {
        db.close();
      }
    } catch (OrmException e) {
      getServletContext().log("cannot query database", e);
      return null;
    }
View Full Code Here

      id = Account.Id.parse(idStr);
    } catch (NumberFormatException nfe) {
      return null;
    }
    try {
      final ReviewDb db = schema.open();
      try {
        return auth(db.accounts().get(id));
      } finally {
        db.close();
      }
    } catch (OrmException e) {
      getServletContext().log("cannot query database", e);
      return null;
    }
View Full Code Here

    this.userFactory = userFactory;
    this.changeUserNameFactory = changeUserNameFactory;
    this.projectCache = projectCache;

    firstAccount = new AtomicBoolean();
    final ReviewDb db = schema.open();
    try {
      firstAccount.set(db.accounts().anyAccounts().toList().isEmpty());
    } finally {
      db.close();
    }
  }
View Full Code Here

  /**
   * @return user identified by this external identity string, or null.
   */
  public Account.Id lookup(final String externalId) throws AccountException {
    try {
      final ReviewDb db = schema.open();
      try {
        final AccountExternalId ext =
            db.accountExternalIds().get(new AccountExternalId.Key(externalId));
        return ext != null ? ext.getAccountId() : null;
      } finally {
        db.close();
      }
    } catch (OrmException e) {
      throw new AccountException("Cannot lookup account " + externalId, e);
    }
  }
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.