コード例 #1
0
  /** Test locks are released when session logs out */
  public void testImplicitUnlock() throws RepositoryException, NotExecutableException {
    Session other = getHelper().getReadWriteSession();
    try {
      Node testNode = (Node) other.getItem(testRootNode.getPath());
      Node lockedNode = testNode.addNode(nodeName1, testNodeType);
      other.save();

      assertLockable(lockedNode);

      Lock lock =
          getLockManager(other)
              .lock(
                  lockedNode.getPath(),
                  isDeep(),
                  isSessionScoped(),
                  getTimeoutHint(),
                  getLockOwner());
      other.logout();

      assertFalse(lock.isLive());
    } finally {
      if (other.isLive()) {
        other.logout();
      }
    }
  }
コード例 #2
0
  @Test
  public void testWrapper() throws Exception {
    Connection conn = getConnection();

    assertTrue(conn.isWrapperFor(JcrConnection.class));

    try {
      conn.isWrapperFor(null);
      fail();
    } catch (IllegalArgumentException ignore) {
    }

    assertFalse(conn.isWrapperFor(Session.class));

    JcrConnection jcrConn = conn.unwrap(JcrConnection.class);
    Session jcrSession = jcrConn.getSession();
    assertNotNull(jcrSession);
    assertTrue(jcrSession.isLive());

    try {
      conn.unwrap(null);
      fail();
    } catch (IllegalArgumentException ignore) {
    }

    try {
      conn.unwrap(Session.class);
      fail();
    } catch (SQLException ignore) {
    }

    conn.close();
  }
コード例 #3
0
ファイル: JCRHelper.java プロジェクト: noobandy/ProjectIdea
  public void saveProfilePic(String username, InputStream inputStream) {
    Session session = null;
    try {
      session = repository.login(credentials);
      Node rootNode = session.getRootNode();
      Node userHomeFolder = null;
      if (rootNode.hasNode(username)) {
        userHomeFolder = rootNode.getNode(username);
      } else {
        userHomeFolder = rootNode.addNode(username, NodeType.NT_FOLDER);
      }

      Node userProfilePicFile = null;
      if (userHomeFolder.hasNode(username)) {
        userProfilePicFile = userHomeFolder.getNode(username);
      } else {
        userProfilePicFile = userHomeFolder.addNode(username, NodeType.NT_FILE);
      }

      Node userProfilePicData = null;

      if (userProfilePicFile.hasNode(username + ".jpg")) {
        userProfilePicData = userProfilePicFile.getNode(username + ".jpg");
      } else {
        userProfilePicData = userProfilePicFile.addNode(username + ".jpg", NodeType.NT_RESOURCE);
      }

      Binary value = session.getValueFactory().createBinary(inputStream);

      userProfilePicData.setProperty(Property.JCR_DATA, value);

      session.save();

    } catch (LoginException e) {

      new ApplicationException("Failed to authenticate with content repository", e);
    } catch (RepositoryException e) {

      new ApplicationException("failed to add file", e);
    } finally {
      if (session != null && session.isLive()) {
        session.logout();
      }
    }
  }
コード例 #4
0
ファイル: ForumPageList.java プロジェクト: hanhvq/exo-ks
 private NodeIterator setQuery(boolean isQuery, String value) throws Exception {
   NodeIterator iter;
   Session session = sessionManager.getCurrentSession();
   if (session == null || !session.isLive()) {
     sessionManager.openSession();
     session = sessionManager.getCurrentSession();
   }
   if (isQuery) {
     QueryManager qm = session.getWorkspace().getQueryManager();
     Query query = qm.createQuery(value, Query.XPATH);
     QueryResult result = query.execute();
     iter = result.getNodes();
   } else {
     Node node = (Node) session.getItem(value);
     iter = node.getNodes();
   }
   return iter;
 }
コード例 #5
0
  /** Test locks are released when session logs out */
  public void testImplicitUnlock2() throws RepositoryException, NotExecutableException {
    Session other = getHelper().getReadWriteSession();
    try {
      Node testNode = (Node) other.getItem(testRootNode.getPath());
      Node lockedNode = testNode.addNode(nodeName1, testNodeType);
      other.save();

      assertLockable(lockedNode);

      LockManager lMgr = getLockManager(other);
      Lock lock =
          lMgr.lock(
              lockedNode.getPath(), isDeep(), isSessionScoped(), getTimeoutHint(), getLockOwner());

      // access the locked noded added by another session
      testRootNode.refresh(false);
      Node n = (Node) superuser.getItem(lockedNode.getPath());

      // remove lock implicit by logout lock-holding session
      other.logout();

      // check if superuser session is properly informed about the unlock
      assertFalse(n.isLocked());
      assertFalse(n.holdsLock());
      try {
        n.getLock();
        fail("Upon logout of the session a session-scoped lock must be gone.");
      } catch (LockException e) {
        // ok
      }
    } finally {
      if (other.isLive()) {
        other.logout();
      }
    }
  }
コード例 #6
0
  private void clearRepository() {
    // cleanup session cache
    if (!this.sessions.isEmpty()) {
      final Iterator<Entry<Session, UnitOfWork>> itr = this.sessions.entrySet().iterator();

      while (itr.hasNext()) {
        final Entry<Session, UnitOfWork> entry = itr.next();
        final Session session = entry.getKey();

        // rollback and close all leftover sessions
        if (session.isLive()) {
          final UnitOfWork uow = entry.getValue();
          LOGGER.debug(
              "LocalRepository.stopRepository: closing session for transaction {0}",
              uow.getName()); // $NON-NLS-1$

          // rollback any session that is in an incomplete state
          if (!uow.getState().isFinal()) {
            try {
              session.refresh(false);
            } catch (final RepositoryException e) {
              LOGGER.error(
                  "LocalRepository.stopRepository(): Exception rolling back transaction \"{0}\"", //$NON-NLS-1$
                  e, uow.getName());
            }
          }

          // does not hurt to call logout if already called
          session.logout();
        }

        itr.remove();
      }
    }

    RequestCallback callback =
        new RequestCallback() {

          /**
           * {@inheritDoc}
           *
           * @see
           *     org.komodo.repository.internal.ModeshapeEngineThread.RequestCallback#errorOccurred(java.lang.Throwable)
           */
          @Override
          public void errorOccurred(final Throwable error) {
            throw new RuntimeException(error);
          }

          /**
           * {@inheritDoc}
           *
           * @see
           *     org.komodo.repository.internal.ModeshapeEngineThread.RequestCallback#respond(java.lang.Object)
           */
          @Override
          public void respond(final Object results) {
            notifyObservers();
          }
        };

    KLog.getLogger().debug("LocalRepository.clearRepository() post clear request"); // $NON-NLS-1$
    this.engineThread.accept(new Request(RequestType.CLEAR, callback));
  }