コード例 #1
0
ファイル: VoltCompiler.java プロジェクト: repos-db/h-store
  void compileConnector(final Connector conn, final Database catdb) throws VoltCompilerException {
    // Test the error paths before touching the catalog
    if (conn == null) {
      return;
    }

    // Figure out if the connector is enabled or disabled
    // Export will be disabled if there is no destination.
    boolean adminstate = conn.isEnabled();

    if (!conn.isEnabled()) {
      LOG.info(
          "Export configuration is present and is "
              + "configured to be disabled. Export will be disabled.");
    }

    // Catalog Connector
    // Relying on schema's enforcement of at most 1 connector
    org.voltdb.catalog.Connector catconn = catdb.getConnectors().add("0");
    catconn.setEnabled(adminstate);
    catconn.setLoaderclass(conn.getClazz());

    // add authorized users and groups
    final ArrayList<String> userslist = new ArrayList<String>();
    final ArrayList<String> groupslist = new ArrayList<String>();

    // @users
    if (conn.getUsers() != null) {
      for (String user : conn.getUsers().split(",")) {
        userslist.add(user);
      }
    }

    // @groups
    if (conn.getGroups() != null) {
      for (String group : conn.getGroups().split(",")) {
        groupslist.add(group);
      }
    }

    for (String userName : userslist) {
      final User user = catdb.getUsers().get(userName);
      if (user == null) {
        throw new VoltCompilerException(
            "Export connector "
                + conn.getClazz()
                + " has a user "
                + userName
                + " that does not exist");
      }
      final UserRef userRef = catconn.getAuthusers().add(userName);
      userRef.setUser(user);
    }
    for (String groupName : groupslist) {
      final Group group = catdb.getGroups().get(groupName);
      if (group == null) {
        throw new VoltCompilerException(
            "Export connector "
                + conn.getClazz()
                + " has a group "
                + groupName
                + " that does not exist");
      }
      final GroupRef groupRef = catconn.getAuthgroups().add(groupName);
      groupRef.setGroup(group);
    }

    // Catalog Connector.ConnectorTableInfo
    Integer i = 0;
    if (conn.getTables() != null) {
      for (Tables.Table xmltable : conn.getTables().getTable()) {
        // verify that the table exists in the catalog
        String tablename = xmltable.getName();
        org.voltdb.catalog.Table tableref = catdb.getTables().get(tablename);
        if (tableref == null) {
          LOG.warn(
              "While configuring export, table "
                  + tablename
                  + " was not present in "
                  + "the catalog. Export will be disabled for this table.");
          continue;
        }

        org.voltdb.catalog.ConnectorTableInfo cattable = catconn.getTableinfo().add(i.toString());
        cattable.setAppendonly(xmltable.isExportonly());
        cattable.setTable(tableref);
        ++i;
      }
    }
  }