Exemple #1
0
  private static void installJar(String urlString, String jarName, boolean deploy, byte[] image)
      throws SQLException {
    assertJarName(jarName);

    if (getJarId(jarName, null) >= 0)
      throw new SQLException("A jar named '" + jarName + "' already exists", "46002");

    PreparedStatement stmt =
        SQLUtils.getDefaultConnection()
            .prepareStatement(
                "INSERT INTO sqlj.jar_repository(jarName, jarOrigin, jarOwner) VALUES(?, ?, ?)");
    try {
      stmt.setString(1, jarName);
      stmt.setString(2, urlString);
      stmt.setString(3, AclId.getSessionUser().getName());
      if (stmt.executeUpdate() != 1)
        throw new SQLException("Jar repository insert did not insert 1 row");
    } finally {
      SQLUtils.close(stmt);
    }

    AclId[] ownerRet = new AclId[1];
    int jarId = getJarId(jarName, ownerRet);
    if (jarId < 0) throw new SQLException("Unable to obtain id of '" + jarName + "'");

    if (image == null) Backend.addClassImages(jarId, urlString);
    else {
      InputStream imageStream = new ByteArrayInputStream(image);
      addClassImages(jarId, imageStream, image.length);
    }
    Loader.clearSchemaLoaders();
    if (deploy) deployInstall(jarId, jarName);
  }
 private static String[] implementors() throws SQLException {
   String settingString = Backend.getConfigOption("pljava.implementors");
   ArrayList<String> al = new ArrayList<String>();
   Matcher m = settingsRx.matcher(settingString);
   while (m.find()) {
     al.add(m.group(1));
     if (-1 != m.start(2)) continue;
     if (m.hitEnd()) return al.toArray(new String[al.size()]);
   }
   throw new SQLException("Failed to parse current pljava.implementors");
 }
Exemple #3
0
  private static void replaceJar(String urlString, String jarName, boolean redeploy, byte[] image)
      throws SQLException {
    AclId[] ownerRet = new AclId[1];
    int jarId = getJarId(jarName, ownerRet);
    if (jarId < 0)
      throw new SQLException("No Jar named '" + jarName + "' is known to the system", "4600A");

    AclId user = AclId.getSessionUser();
    if (!(user.isSuperuser() || user.equals(ownerRet[0])))
      throw new SecurityException("Only super user or owner can replace a jar");

    if (redeploy) deployRemove(jarId, jarName);

    PreparedStatement stmt =
        SQLUtils.getDefaultConnection()
            .prepareStatement(
                "UPDATE sqlj.jar_repository "
                    + "SET jarOrigin = ?, jarOwner = ?, jarManifest = NULL "
                    + "WHERE jarId = ?");
    try {
      stmt.setString(1, urlString);
      stmt.setString(2, user.getName());
      stmt.setInt(3, jarId);
      if (stmt.executeUpdate() != 1)
        throw new SQLException("Jar repository update did not update 1 row");
    } finally {
      SQLUtils.close(stmt);
    }

    stmt =
        SQLUtils.getDefaultConnection()
            .prepareStatement("DELETE FROM sqlj.jar_entry WHERE jarId = ?");
    try {
      stmt.setInt(1, jarId);
      stmt.executeUpdate();
    } finally {
      SQLUtils.close(stmt);
    }
    if (image == null) Backend.addClassImages(jarId, urlString);
    else {
      InputStream imageStream = new ByteArrayInputStream(image);
      addClassImages(jarId, imageStream, image.length);
    }
    Loader.clearSchemaLoaders();
    if (redeploy) deployInstall(jarId, jarName);
  }