Package com.google.enterprise.connector.util.database

Examples of com.google.enterprise.connector.util.database.DatabaseConnectionPool


    LOGGER.entering(CLASS_NAME, METHOD);

    if (notesUsers == null || notesUsers.size() == 0) {
      return Collections.emptyList();
    }
    DatabaseConnectionPool connectionPool = null;
    Connection lookupConn = null;
    PreparedStatement exactMatchStmt = null;
    PreparedStatement commonNameStmt = null;
    boolean isReadOnly = false;
    try {
      connectionPool = connectorSession.getConnector().getJdbcDatabase()
          .getConnectionPool();
      lookupConn = connectionPool.getConnection();
      isReadOnly = lookupConn.isReadOnly();
      lookupConn.setReadOnly(true);

      LinkedHashSet<String> gsaNames =
          new LinkedHashSet<String>(notesUsers.size());
      List<Object> verifiedUsers = new ArrayList<Object>();

      Map<Object, User> users = getSimpleUsers(notesSession, lookupConn,
          notesUsers);
      for (Map.Entry<Object, User> userData : users.entrySet()) {
        gsaNames.add(userData.getValue().getGsaName());
        verifiedUsers.add(userData.getKey());
      }

      if (removeUsers) {
        notesUsers.removeAll(verifiedUsers);
      }

      if (LOGGER.isLoggable(Level.FINEST)) {
        LOGGER.logp(Level.FINEST, CLASS_NAME, METHOD,
            "Mapped Notes names: " + notesUsers + " to GSA names: "
            + gsaNames);
      }
      return gsaNames;
    } catch (Exception e) {
      LOGGER.logp(Level.SEVERE, CLASS_NAME, METHOD,
          "Failed to map users", e);
      return null;
    } finally {
      try {
        Util.close(exactMatchStmt);
        Util.close(commonNameStmt);
        lookupConn.setReadOnly(isReadOnly);
        connectionPool.releaseConnection(lookupConn);
      } catch (SQLException e) {
        LOGGER.logp(Level.WARNING, CLASS_NAME, METHOD,
            "Failure releasing connection", e);
      }
      LOGGER.exiting(CLASS_NAME, METHOD);
View Full Code Here


    LOGGER.entering(CLASS_NAME, METHOD);

    if (Strings.isNullOrEmpty(value)) {
      return null;
    }
    DatabaseConnectionPool connectionPool = null;
    Connection lookupConn = null;
    boolean isReadOnly = false;
    try {
      connectionPool = connectorSession.getConnector().getJdbcDatabase()
          .getConnectionPool();
      lookupConn = connectionPool.getConnection();
      isReadOnly = lookupConn.isReadOnly();
      lookupConn.setReadOnly(true);

      // Find the user.
      PreparedStatement pstmt = lookupConn.prepareStatement("select * from "
          + userTableName + " where " + field + " = ?",
          ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
      ResultSet rs = null;
      long userId = -1L;
      String notesName;
      String gsaName;
      try {
        pstmt.setString(1, value.toLowerCase());
        rs = pstmt.executeQuery();
        if (!rs.next()) {
          return null;
        }
        userId = rs.getLong("userid");
        notesName = rs.getString("notesname");
        gsaName = rs.getString("gsaname");
      } finally {
        Util.close(rs);
        Util.close(pstmt);
      }
      User user = new User(userId, notesName, gsaName);

      // User is authenticated and should be a member of "-default-" group.
      user.addGroup("-default-");

      // Find user groups and nested groups
      pstmt = lookupConn.prepareStatement(
          Util.buildString(
              "select groupname from ", groupTableName,
              " where groupid in ",
              "(select groupid from ",userGroupsTableName,
              " where userid = ?)"),
          ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
      try {
        pstmt.setLong(1, userId);
        rs = pstmt.executeQuery();
        while (rs.next()) {
          user.addGroup(rs.getString(1));
        }
      } finally {
        Util.close(rs);
        Util.close(pstmt);
      }

      // Find user's parent and great grand-parent groups
      // This query queries for user's groups.  From user's groups, it looks up
      // all parent ids.  From parent ids, it looks up for group names.
      pstmt = lookupConn.prepareStatement(
          Util.buildString(
              "select groupname from ", groupTableName,
              " where groupid in ",
              "(select parentgroupid from ", groupChildrenTableName,
              " where childgroupid in ",
              "(select groupid from ", userGroupsTableName,
              " where userid = ?)", ")"),
          ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
      try {
        pstmt.setLong(1, userId);
        rs = pstmt.executeQuery();
        while (rs.next()) {
          user.addGroup(rs.getString(1));
        }
      } finally {
        Util.close(rs);
        Util.close(pstmt);
      }

      // Find their roles.
      pstmt = lookupConn.prepareStatement("select replicaid, rolename from "
          + roleTableName + " where roleid in (select roleid from "
          + userRolesTableName + " where userid = ?)",
          ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
      try {
        pstmt.setLong(1, userId);
        rs = pstmt.executeQuery();
        while (rs.next()) {
          user.addRole(rs.getString(1), rs.getString(2));
        }
      } finally {
        Util.close(rs);
        Util.close(pstmt);
      }

      // Find any roles they acquire because of direct group membership and
      // via parent groups.
      pstmt = lookupConn.prepareStatement("select replicaid, rolename from "
          + roleTableName + " where roleid in (select roleid from "
          + groupRolesTableName + " where groupid in "
          + "(select groupid from " + userGroupsTableName
          + " where userid = ? union select parentgroupid from "
          + groupChildrenTableName
          + " where childgroupid in (select groupid from "
          + userGroupsTableName + " where userid = ?)))",
          ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
      try {
        pstmt.setLong(1, userId);
        pstmt.setLong(2, userId);
        rs = pstmt.executeQuery();
        while (rs.next()) {
          user.addRole(rs.getString(1), rs.getString(2));
        }
      } finally {
        Util.close(rs);
        Util.close(pstmt);
      }

      return user;
    } catch (Exception e) {
      LOGGER.logp(Level.SEVERE, CLASS_NAME, METHOD,
          "Failed to find user record for: " + field
          + " = " + value, e);
      return null;
    } finally {
      try {
        lookupConn.setReadOnly(isReadOnly);
        connectionPool.releaseConnection(lookupConn);
      } catch (SQLException e) {
        LOGGER.logp(Level.WARNING, CLASS_NAME, METHOD,
            "Failure releasing connection", e);
      }
      LOGGER.exiting(CLASS_NAME, METHOD);
View Full Code Here

    }
  }

  void dropTables() {
    final String METHOD = "dropTables";
    DatabaseConnectionPool connectionPool = null;
    Connection conn = null;
    Statement stmt = null;
    boolean isReadOnly = false;
    try {
      connectionPool = connectorSession.getConnector().getJdbcDatabase()
          .getConnectionPool();
      conn = connectionPool.getConnection();
      isReadOnly = conn.isReadOnly();
      conn.setReadOnly(false);

      String[] tables = { userGroupsTableName, userRolesTableName,
         groupRolesTableName, groupChildrenTableName,
         userTableName, groupTableName, roleTableName
      };
      stmt = conn.createStatement();
      for (String table : tables) {
        try {
          stmt.executeUpdate("drop table " + table);
        } catch (Exception e) {
          LOGGER.logp(Level.WARNING, CLASS_NAME, METHOD,
              "Failed to drop table: " + table, e);
        }
      }
    } catch (Exception e) {
      LOGGER.logp(Level.WARNING, CLASS_NAME, METHOD,
          "Failed to drop tables", e);
    } finally {
      try {
        Util.close(stmt);
        conn.setReadOnly(isReadOnly);
        connectionPool.releaseConnection(conn);
      } catch (SQLException e) {
        LOGGER.logp(Level.WARNING, CLASS_NAME, METHOD,
            "Failure releasing connection", e);
      }
      LOGGER.exiting(CLASS_NAME, METHOD);
View Full Code Here

  public AdDbUtil(DataSource dataSource, String databaseType) {
    queries =
        ResourceBundle.getBundle(getClass().getPackage().getName() + ".sql",
        new Locale(databaseType));
    connectionPool = new DatabaseConnectionPool(dataSource);

    this.dataSource = dataSource;
    try {
      // Test connection to datasource.
      connectionPool.releaseConnection(connectionPool.getConnection());
View Full Code Here

TOP

Related Classes of com.google.enterprise.connector.util.database.DatabaseConnectionPool

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.