Beispiel #1
0
  /**
   * Update the passed in NCube. Only SNAPSHOT cubes can be updated.
   *
   * @param ncube NCube to be updated.
   * @return boolean true on success, false otherwise
   */
  public static boolean updateCube(ApplicationID appId, NCube ncube, String username) {
    validateAppId(appId);
    validateCube(ncube);

    if (appId.isRelease()) {
      throw new IllegalArgumentException(
          ReleaseStatus.RELEASE
              + " cubes cannot be updated, cube: "
              + ncube.getName()
              + ", app: "
              + appId);
    }

    appId.validateBranchIsNotHead();

    final String cubeName = ncube.getName();
    getPersister().updateCube(appId, ncube, username);
    ncube.setApplicationID(appId);

    if (CLASSPATH_CUBE.equalsIgnoreCase(
        cubeName)) { // If the sys.classpath cube is changed, then the entire class loader must be
                     // dropped.  It will be lazily rebuilt.
      clearCache(appId);
    }

    addCube(appId, ncube);
    broadcast(appId);
    return true;
  }
Beispiel #2
0
  /** Restore a previously deleted n-cube. */
  public static void restoreCubes(ApplicationID appId, Object[] cubeNames, String username) {
    validateAppId(appId);
    appId.validateBranchIsNotHead();

    if (appId.isRelease()) {
      throw new IllegalArgumentException(
          ReleaseStatus.RELEASE + " cubes cannot be restored, app: " + appId);
    }

    if (ArrayUtilities.isEmpty(cubeNames)) {
      throw new IllegalArgumentException(
          "Error, empty array of cube names passed in to be restored.");
    }

    // Batch restore
    getPersister().restoreCubes(appId, cubeNames, username);

    // Load cache
    for (Object name : cubeNames) {
      if ((name instanceof String)) {
        String cubeName = (String) name;
        NCube.validateCubeName(cubeName);
        NCube ncube = getPersister().loadCube(appId, cubeName);
        addCube(appId, ncube);
      } else {
        throw new IllegalArgumentException("Non string name given for cube to restore: " + name);
      }
    }
  }
Beispiel #3
0
  public static void changeVersionValue(ApplicationID appId, String newVersion) {
    validateAppId(appId);

    if (appId.isRelease()) {
      throw new IllegalArgumentException(
          "Cannot change the version of a " + ReleaseStatus.RELEASE + " app, app: " + appId);
    }
    ApplicationID.validateVersion(newVersion);
    getPersister().changeVersionValue(appId, newVersion);
    clearCache(appId);
    clearCache(appId.asVersion(newVersion));
    broadcast(appId);
  }
Beispiel #4
0
  /** Duplicate the given n-cube specified by oldAppId and oldName to new ApplicationID and name, */
  public static void duplicate(
      ApplicationID oldAppId,
      ApplicationID newAppId,
      String oldName,
      String newName,
      String username) {
    validateAppId(oldAppId);
    validateAppId(newAppId);

    newAppId.validateBranchIsNotHead();

    if (newAppId.isRelease()) {
      throw new IllegalArgumentException(
          "Cubes cannot be duplicated into a "
              + ReleaseStatus.RELEASE
              + " version, cube: "
              + newName
              + ", app: "
              + newAppId);
    }

    NCube.validateCubeName(oldName);
    NCube.validateCubeName(newName);

    if (oldName.equalsIgnoreCase(newName) && oldAppId.equals(newAppId)) {
      throw new IllegalArgumentException(
          "Could not duplicate, old name cannot be the same as the new name when oldAppId matches newAppId, name: "
              + oldName
              + ", app: "
              + oldAppId);
    }

    getPersister().duplicateCube(oldAppId, newAppId, oldName, newName, username);

    if (CLASSPATH_CUBE.equalsIgnoreCase(
        newName)) { // If another cube is renamed into sys.classpath,
      // then the entire class loader must be dropped (and then lazily rebuilt).
      clearCache(newAppId);
    } else {
      Map<String, Object> appCache = getCacheForApp(newAppId);
      appCache.remove(newName.toLowerCase());
    }

    broadcast(newAppId);
  }
Beispiel #5
0
  public static boolean renameCube(
      ApplicationID appId, String oldName, String newName, String username) {
    validateAppId(appId);
    appId.validateBranchIsNotHead();

    if (appId.isRelease()) {
      throw new IllegalArgumentException(
          "Cannot rename a "
              + ReleaseStatus.RELEASE
              + " cube, cube: "
              + oldName
              + ", app: "
              + appId);
    }

    NCube.validateCubeName(oldName);
    NCube.validateCubeName(newName);

    if (oldName.equalsIgnoreCase(newName)) {
      throw new IllegalArgumentException(
          "Could not rename, old name cannot be the same as the new name, name: "
              + oldName
              + ", app: "
              + appId);
    }

    boolean result = getPersister().renameCube(appId, oldName, newName, username);

    if (CLASSPATH_CUBE.equalsIgnoreCase(oldName)
        || CLASSPATH_CUBE.equalsIgnoreCase(
            newName)) { // If the sys.classpath cube is renamed, or another cube is renamed into
                        // sys.classpath,
      // then the entire class loader must be dropped (and then lazily rebuilt).
      clearCache(appId);
    } else {
      Map<String, Object> appCache = getCacheForApp(appId);
      appCache.remove(oldName.toLowerCase());
      appCache.remove(newName.toLowerCase());
    }

    broadcast(appId);
    return result;
  }
Beispiel #6
0
  static boolean deleteCubes(
      ApplicationID appId, Object[] cubeNames, boolean allowDelete, String username) {
    validateAppId(appId);
    if (!allowDelete) {
      if (appId.isRelease()) {
        throw new IllegalArgumentException(
            ReleaseStatus.RELEASE + " cubes cannot be hard-deleted, app: " + appId);
      }
    }

    if (getPersister().deleteCubes(appId, cubeNames, allowDelete, username)) {
      Map<String, Object> appCache = getCacheForApp(appId);
      for (int i = 0; i < cubeNames.length; i++) {
        appCache.remove(((String) cubeNames[i]).toLowerCase());
      }
      broadcast(appId);
      return true;
    }
    return false;
  }