Package org.exoplatform.services.jcr.impl.core

Examples of org.exoplatform.services.jcr.impl.core.SessionImpl


   private void incrementalRestore(String pathBackupFile, String repositoryName, String workspaceName)
      throws RepositoryException, RepositoryConfigurationException, BackupOperationException, FileNotFoundException,
      IOException, ClassNotFoundException
   {
      SessionImpl sesion = (SessionImpl)repoService.getRepository(repositoryName).getSystemSession(workspaceName);
      WorkspacePersistentDataManager dataManager =
         (WorkspacePersistentDataManager)sesion.getContainer().getComponentInstanceOfType(
            WorkspacePersistentDataManager.class);

      ObjectInputStream ois = null;
      File backupFile = null;
      try
      {
         backupFile = new File(pathBackupFile);
         ois = new ObjectInputStream(PrivilegedFileHelper.fileInputStream(backupFile));

         while (true)
         {
            TransactionChangesLog changesLog = readExternal(ois);

            ChangesLogIterator cli = changesLog.getLogIterator();
            while (cli.hasNextLog())
            {
               if (cli.nextLog().getEventType() == ExtendedEvent.LOCK)
                  cli.removeLog();
            }

            saveChangesLog(dataManager, changesLog);
         }
      }
      catch (EOFException ioe)
      {
         // ok - reading all data from backup file;
      }
      finally
      {
         if (sesion != null)
            sesion.logout();
      }
   }
View Full Code Here


   /**
    * {@inheritDoc}
    */
   public void onCloseSession(ExtendedSession session)
   {
      SessionImpl sessionImpl = (SessionImpl)session;

      String[] nodeIds = new String[lockedNodes.size()];
      lockedNodes.keySet().toArray(nodeIds);

      for (String nodeId : nodeIds)
      {
         LockData lock = lockedNodes.remove(nodeId);

         if (lock.isSessionScoped() && !pendingLocks.contains(nodeId))
         {
            try
            {
               NodeImpl node =
                  ((NodeImpl)sessionImpl.getTransientNodesManager()
                     .getItemByIdentifier(lock.getNodeIdentifier(), false));

               if (node != null)
               {
                  node.unlock();
View Full Code Here

   /**
    * {@inheritDoc}
    */
   public void onCloseSession(ExtendedSession session)
   {
      SessionImpl sessionImpl = (SessionImpl)session;

      int length = lockedNodes.size();
      if (length > 0)
      {
         String[] nodeIds = new String[length];
         lockedNodes.keySet().toArray(nodeIds);

         for (int i = 0; i < length; i++)
         {
            String nodeId = nodeIds[i];
            LockData lock = lockedNodes.remove(nodeId);

            if (lock.isSessionScoped() && !pendingLocks.contains(nodeId))
            {
               try
               {
                  NodeImpl node =
                     ((NodeImpl)sessionImpl.getTransientNodesManager()
                        .getItemByIdentifier(lock.getNodeIdentifier(), false));

                  if (node != null)
                  {
                     node.unlock();
View Full Code Here

         try
         {
            TransactionChangesLog allChanges = new TransactionChangesLog();
            for (Map.Entry<PlainChangesLog, SessionImpl> entry : changes.entrySet())
            {
               SessionImpl session = entry.getValue();
               // first check if the tx was not too long
               if (session.hasExpired())
               {
                  // at least one session has expired so we abort the tx
                  throw new RepositoryException("The tx was too long, at least one session has expired.");
               }
               // Add the change following the chronology order
View Full Code Here

            Map<PlainChangesLog, SessionImpl> changes = xidCtx.getMapChanges();
            if (changes != null && !changes.isEmpty())
            {
               for (Map.Entry<PlainChangesLog, SessionImpl> entry : changes.entrySet())
               {
                  SessionImpl session = entry.getValue();
                  TransactionableDataManager txManager = session.getTransientNodesManager().getTransactManager();
                  // Remove the change from the tx change log. Please note that a simple reset cannot
                  // be done since the session could be enrolled in several tx, so each change need to
                  // be scoped to a given xid
                  txManager.removeLog(entry.getKey());
               }
View Full Code Here

      // mix:versionable
      // we have to be sure that any versionable node somewhere in repository
      // doesn't refers to a VH of the node being deleted.
      for (String wsName : repository.getWorkspaceNames())
      {
         SessionImpl wsSession = repository.getSystemSession(wsName);
         try
         {
            for (PropertyData sref : wsSession.getTransientNodesManager().getReferencesData(vhID, false))
            {
               // Check if this VH isn't referenced from somewhere in workspace
               // or isn't contained in another one as a child history.
               // Ask ALL references incl. properties from version storage.
               if (sref.getQPath().isDescendantOf(Constants.JCR_VERSION_STORAGE_PATH))
               {
                  if (!sref.getQPath().isDescendantOf(vhnode.getQPath())
                     && (containingHistory != null ? !sref.getQPath().isDescendantOf(containingHistory) : true))
                     // has a reference to the VH in version storage,
                     // it's a REFERENCE property jcr:childVersionHistory of
                     // nt:versionedChild
                     // i.e. this VH is a child history in an another history.
                     // We can't remove this VH now.
                     return;
               }
               else if (!currentWorkspaceName.equals(wsName))
               {
                  // has a reference to the VH in traversed workspace,
                  // it's not a version storage, i.e. it's a property of versionable
                  // node somewhere in ws.
                  // We can't remove this VH now.
                  return;
               } // else -- if we has a references in workspace where the VH is being
               // deleted we can remove VH now.
            }
         }
         finally
         {
            wsSession.logout();
         }
      }

      // remove child versions from VH (if found)
      // ChildVersionRemoveVisitor cvremover = new
View Full Code Here

   }

   public synchronized void onCloseSession(ExtendedSession session)
   {
      // List<String> deadLocksList = new ArrayList<String>();
      SessionImpl sessionImpl = (SessionImpl)session;
      for (Iterator<Map.Entry<String, LockData>> entries = locks.entrySet().iterator(); entries.hasNext();)
      {
         Map.Entry<String, LockData> entry = entries.next();
         LockData lockData = entry.getValue();
         if (lockData.isLive())
         {
            if (lockData.isLockHolder(session.getId()))
            {
               if (lockData.isSessionScoped())
               {
                  // if no session currently holds lock except this
                  try
                  {
                     // TODO it's possible to have next error
                     // java.lang.NullPointerException
                     // at
                     // org.exoplatform.services.jcr.impl.core.lock.LockManagerImpl.onCloseSession(LockManagerImpl.java:312)
                     // at org.exoplatform.services.jcr.impl.core.SessionImpl.logout(SessionImpl.java:794)
                     // at
                     // org.exoplatform.services.jcr.impl.core.XASessionImpl.logout(XASessionImpl.java:254)
                     // at
                     // org.exoplatform.services.jcr.impl.core.SessionRegistry$SessionCleaner.callPeriodically(SessionRegistry.java:165)
                     // at
                     // org.exoplatform.services.jcr.impl.proccess.WorkerThread.run(WorkerThread.java:46)
                     ((NodeImpl)sessionImpl.getTransientNodesManager().getItemByIdentifier(
                        lockData.getNodeIdentifier(), false)).unlock();
                  }
                  catch (UnsupportedRepositoryOperationException e)
                  {
                     log.error(e.getLocalizedMessage());
View Full Code Here

      // mix:versionable
      // we have to be sure that any versionable node somewhere in repository
      // doesn't refers to a VH of the node being deleted.
      for (String wsName : repository.getWorkspaceNames())
      {
         SessionImpl wsSession = repository.getSystemSession(wsName);
         try
         {
            for (PropertyData sref : wsSession.getTransientNodesManager().getReferencesData(vhID, false))
            {
               // Check if this VH isn't referenced from somewhere in workspace
               // or isn't contained in another one as a child history.
               // Ask ALL references incl. properties from version storage.
               if (sref.getQPath().isDescendantOf(Constants.JCR_VERSION_STORAGE_PATH))
               {
                  if (!sref.getQPath().isDescendantOf(vhnode.getQPath())
                     && (containingHistory != null ? !sref.getQPath().isDescendantOf(containingHistory) : true))
                     // has a reference to the VH in version storage,
                     // it's a REFERENCE property jcr:childVersionHistory of
                     // nt:versionedChild
                     // i.e. this VH is a child history in an another history.
                     // We can't remove this VH now.
                     return;
               }
               else if (!currentWorkspaceName.equals(wsName))
               {
                  // has a reference to the VH in traversed workspace,
                  // it's not a version storage, i.e. it's a property of versionable
                  // node somewhere in ws.
                  // We can't remove this VH now.
                  return;
               } // else -- if we has a references in workspace where the VH is being
               // deleted we can remove VH now.
            }
         }
         finally
         {
            wsSession.logout();
         }
      }

      // remove child versions from VH (if found)
      // ChildVersionRemoveVisitor cvremover = new
View Full Code Here

         sessionWs1.logout();

         System.gc();
         Thread.sleep(1000);

         SessionImpl anotherWs1 = (SessionImpl)repository.login(credentials, "ws1");

         try
         {
            Node n1 = anotherWs1.getRootNode().getNode(testRootWs1.getName()).addNode("n1"); // /
            // observationTest
            // /n1
            Node n1n2 = n1.addNode("n2"); // /observationTest/n1/n2
            anotherWs1.save();

            assertEquals("A events count expected 1. ", 1, listener.getCounter());
         }
         catch (Exception e)
         {
View Full Code Here

         int sessionCount = 300; // can't be smaller removeCount, see below
         int removeCount = 100;
         int removeIndex = 0;
         for (int i = 0; i < sessionCount; i++)
         {
            SessionImpl anotherWs1 = (SessionImpl)repository.login(credentials, "ws1");

            try
            {

               Node n1 = anotherWs1.getRootNode().getNode(testRootWs1.getName()).addNode("n" + i, "nt:file"); // /
               // observationTest
               // /
               // n1
               Node n1n2 = n1.addNode("jcr:content", "nt:unstructured"); // /observationTest/nXXXX/jcr:
               // content
               n1n2.addMixin("mix:referenceable");
               anotherWs1.save();

               if (i == removeCount)
               {
                  anotherWs1.getWorkspace().getObservationManager().addEventListener(removeListener,
                     Event.PROPERTY_REMOVED, testRootWs1.getPath(), true, null, null, true); // no local
                  removeIndex = i + removeCount;
               }
               else if (i > removeCount && i <= removeIndex)
               {
                  // remove prop:
                  // jcr:content --> jcr:primaryType, jcr:mixinTypes, jcr:uuid
                  // nt:file --> jcr:primaryType, jcr:created
                  n1.remove();
                  anotherWs1.save();
               }
            }
            catch (Exception e)
            {
               e.printStackTrace();
               fail("There are no error should be, but found " + e.getMessage());
            }
            finally
            {
               anotherWs1.logout();
            }
         }

         assertEquals("A events count expected ", sessionCount, addListener.getCounter());
         assertEquals("A events count expected ", removeCount * 5, removeListener.getCounter());
View Full Code Here

TOP

Related Classes of org.exoplatform.services.jcr.impl.core.SessionImpl

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.