Package org.eclipse.orion.server.core.metastore

Examples of org.eclipse.orion.server.core.metastore.IMetaStore


  protected Thread deletePropertyThread(int number) {
    Runnable runnable = new Runnable() {
      public void run() {
        try {
          Logger logger = LoggerFactory.getLogger("org.eclipse.orion.server.config"); //$NON-NLS-1$
          IMetaStore metaStore = getMetaStore();
          String currentThreadName = Thread.currentThread().getName();
          List<String> propertyKeys = new ArrayList<String>();

          // read the user
          UserInfo userInfo = metaStore.readUser("anthony");
          if (userInfo == null) {
            logger.debug("Meta File Error, could not read user anthony to delete a property.");
            return;
          }

          // get the list of properties to delete

          for (String key : userInfo.getProperties().keySet()) {
            if (key.startsWith("property/" + currentThreadName)) {
              propertyKeys.add(key);
            }
          }

          // now delete the properties
          for (String key : propertyKeys) {
            // read the user
            userInfo = metaStore.readUser("anthony");
            if (userInfo == null) {
              logger.debug("Meta File Error, could not read user anthony to delete a property.");
              continue;
            }

            // set a new property
            userInfo.setProperty(key, null);
            metaStore.updateUser(userInfo);

            // read the user again
            userInfo = metaStore.readUser("anthony");
            if (userInfo == null) {
              logger.debug("Meta File Error, could not read user anthony to verify the property.");
            } else if (userInfo.getProperty(key) != null) {
              logger.debug("Meta File Error, JSONObject contains " + key + " that was just deleted.");
            }
View Full Code Here


    return thread;
  }

  protected IMetaStore getMetaStore() {
    // use the currently configured metastore if it is an SimpleMetaStore
    IMetaStore metaStore = null;
    try {
      metaStore = OrionConfiguration.getMetaStore();
    } catch (NullPointerException e) {
      // expected when the workbench is not running
    }
View Full Code Here

   * @throws CoreException
   */
  @Test
  public void testSimpleMetaStoreCreatePropertyConcurrency() throws CoreException {
    // create the MetaStore
    IMetaStore metaStore = getMetaStore();

    // create the user
    UserInfo userInfo = new UserInfo();
    userInfo.setUserName("anthony");
    userInfo.setFullName("Anthony Hunter");
    metaStore.createUser(userInfo);

    // add properties to the user in multiple threads
    Thread threads[] = new Thread[THREAD_COUNT];
    for (int i = 0; i < threads.length; i++) {
      threads[i] = createPropertyThread(i);
    }

    for (int i = 0; i < threads.length; i++) {
      try {
        threads[i].join();
      } catch (InterruptedException e) {
        // just continue
      }
    }

    // read the user and make sure the properties are there
    userInfo = metaStore.readUser("anthony");
    int count = 0;
    Map<String, String> properties = userInfo.getProperties();
    for (String key : properties.keySet()) {
      if (key.startsWith("property/")) {
        count++;
      }
    }

    // delete the user
    metaStore.deleteUser(userInfo.getUniqueId());

    assertEquals("Incomplete number of properties added for the user", THREAD_COUNT * PROPERTY_COUNT, count);
  }
View Full Code Here

   * @throws CoreException
   */
  @Test
  public void testSimpleMetaStoreDeletePropertyConcurrency() throws CoreException {
    // create the MetaStore
    IMetaStore metaStore = getMetaStore();

    // create the user
    UserInfo userInfo = new UserInfo();
    userInfo.setUserName("anthony");
    userInfo.setFullName("Anthony Hunter");
    metaStore.createUser(userInfo);

    // add properties to the user in multiple threads
    Thread threads[] = new Thread[THREAD_COUNT];
    for (int i = 0; i < threads.length; i++) {
      threads[i] = createPropertyThread(i);
    }

    for (int i = 0; i < threads.length; i++) {
      try {
        threads[i].join();
      } catch (InterruptedException e) {
        // just continue
      }
    }

    // read the user and make sure the properties are there
    userInfo = metaStore.readUser("anthony");
    int count = 0;
    Map<String, String> properties = userInfo.getProperties();
    for (String key : properties.keySet()) {
      if (key.startsWith("property/")) {
        count++;
      }
    }

    assertEquals("Incomplete number of properties added for the user", THREAD_COUNT * PROPERTY_COUNT, count);

    // delete properties in multiple threads
    threads = new Thread[THREAD_COUNT];
    for (int i = 0; i < threads.length; i++) {
      threads[i] = deletePropertyThread(i);
    }

    for (int i = 0; i < threads.length; i++) {
      try {
        threads[i].join();
      } catch (InterruptedException e) {
        // just continue
      }
    }

    // read the user and make sure there are no properties are there
    userInfo = metaStore.readUser("anthony");
    count = 0;
    properties = userInfo.getProperties();
    for (String key : properties.keySet()) {
      if (key.startsWith("property/")) {
        count++;
      }
    }

    // delete the user
    metaStore.deleteUser(userInfo.getUniqueId());

    assertEquals("Incomplete number of properties deleted for the user", 0, count);
  }
View Full Code Here

   */
  protected UserInfo createUser(String login, String password) {
    UserInfo userInfo = null;
    try {
      // see if the user exists already
      IMetaStore metaStore = OrionConfiguration.getMetaStore();
      userInfo = metaStore.readUserByProperty(UserConstants2.USER_NAME, login, false, false);
      if (userInfo != null) {
        return userInfo;
      }

      // create new user in the metadata storage
View Full Code Here

        cloneName = filePath.segmentCount() > 2 ? filePath.lastSegment() : project.getFullName();
    } else if (workspacePath != null) {
      IPath path = new Path(workspacePath);
      // TODO: move this to CloneJob
      // if so, modify init part to create a new project if necessary
      final IMetaStore metaStore = OrionConfiguration.getMetaStore();
      WorkspaceInfo workspace = metaStore.readWorkspace(path.segment(1));
      if (cloneName == null)
        cloneName = new URIish(url).getHumanishName();
      cloneName = getUniqueProjectName(workspace, cloneName);
      webProjectExists = false;
      project = new ProjectInfo();
      project.setFullName(cloneName);
      project.setWorkspaceId(workspace.getUniqueId());

      try {
        // creating project in the backing store will assign a project id
        metaStore.createProject(project);
      } catch (CoreException e) {
        return statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
            "Error persisting project state", e));
      }
      try {
        WorkspaceResourceHandler.computeProjectLocation(request, project, null, false);
        metaStore.updateProject(project);
      } catch (CoreException e) {
        // delete the project so we don't end up with a project in a bad location
        try {
          metaStore.deleteProject(workspace.getUniqueId(), project.getFullName());
        } catch (CoreException e1) {
          // swallow secondary error
          LogHelper.log(e1);
        }
        // we are unable to write in the platform location!
View Full Code Here

   * Returns a unique project name that does not exist in the given workspace, for the given clone name.
   */
  private String getUniqueProjectName(WorkspaceInfo workspace, String cloneName) {
    int i = 1;
    String uniqueName = cloneName;
    IMetaStore store = OrionConfiguration.getMetaStore();
    try {
      while (store.readProject(workspace.getUniqueId(), uniqueName) != null) {
        // add an incrementing counter suffix until we arrive at a unique name
        uniqueName = cloneName + '-' + ++i;
      }
    } catch (CoreException e) {
      // let it proceed with current name
View Full Code Here

TOP

Related Classes of org.eclipse.orion.server.core.metastore.IMetaStore

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.