Package org.exoplatform.services.jcr.dataflow.serialization

Examples of org.exoplatform.services.jcr.dataflow.serialization.ObjectWriter


   /**
    * {@inheritDoc}
    */
   public void backup(File storageDir) throws BackupException
   {
      ObjectWriter backupInfo = null;

      try
      {
         backupInfo =
            new ObjectWriterImpl(PrivilegedFileHelper.fileOutputStream(new File(storageDir,
               "JDBCWorkspaceDataContainer.info")));

         backupInfo.writeString(containerName);
         backupInfo.writeBoolean(multiDb);

         Map<String, String> scripts = new HashMap<String, String>();

         if (multiDb)
         {
            scripts.put("JCR_MITEM", "select * from JCR_MITEM where JCR_MITEM.name <> '" + Constants.ROOT_PARENT_NAME
               + "'");
            scripts.put("JCR_MVALUE", "select * from JCR_MVALUE");
            scripts.put("JCR_MREF", "select * from JCR_MREF");
         }
         else
         {
            scripts.put("JCR_SITEM", "select * from JCR_SITEM where CONTAINER_NAME='" + containerName + "'");
            scripts
               .put(
                  "JCR_SVALUE",
                  "select * from JCR_SVALUE where exists(select * from JCR_SITEM where JCR_SITEM.ID=JCR_SVALUE.PROPERTY_ID and JCR_SITEM.CONTAINER_NAME='"
                     + containerName + "')");
            scripts
               .put(
                  "JCR_SREF",
                  "select * from JCR_SREF where exists(select * from JCR_SITEM where JCR_SITEM.ID=JCR_SREF.PROPERTY_ID and JCR_SITEM.CONTAINER_NAME='"
                     + containerName + "')");
         }

         BackupTables.backup(storageDir, dbSourceName, scripts);
      }
      catch (IOException e)
      {
         throw new BackupException(e);
      }
      finally
      {
         if (backupInfo != null)
         {
            try
            {
               backupInfo.close();
            }
            catch (IOException e)
            {
               throw new BackupException(e);
            }
View Full Code Here


   /**
    * {@inheritDoc}
    */
   public void backup(final File storageDir) throws BackupException
   {
      ObjectWriter backupInfo = null;

      try
      {
         backupInfo =
            new ObjectWriterImpl(PrivilegedFileHelper.fileOutputStream(new File(storageDir,
               "JDBCWorkspaceDataContainer.info")));

         backupInfo.writeString(containerConfig.containerName);
         backupInfo.writeString(containerConfig.dbStructureType.toString());

         Map<String, String> scripts = new HashMap<String, String>();

         String itemTable = DBInitializerHelper.getItemTableName(containerConfig);
         String valueTable = DBInitializerHelper.getValueTableName(containerConfig);
         String refTable = DBInitializerHelper.getRefTableName(containerConfig);

         backupInfo.writeString(itemTable);
         backupInfo.writeString(valueTable);
         backupInfo.writeString(refTable);

         if (containerConfig.dbStructureType.isMultiDatabase())
         {
            scripts
               .put(itemTable, "select * from " + itemTable + " where NAME <> '" + Constants.ROOT_PARENT_NAME + "'");
            scripts.put(valueTable, "select * from " + valueTable);
            scripts.put(refTable, "select * from " + refTable);
         }
         else
         {
            scripts.put(itemTable, "select * from " + itemTable + " where CONTAINER_NAME='"
               + containerConfig.containerName + "'");
            scripts.put(valueTable, "select V.* from " + valueTable + " V, " + itemTable
               + " I where I.ID=V.PROPERTY_ID and I.CONTAINER_NAME='" + containerConfig.containerName + "'");
            scripts.put(refTable, "select R.* from " + refTable + " R, " + itemTable
               + " I where I.ID=R.PROPERTY_ID and I.CONTAINER_NAME='" + containerConfig.containerName + "'");
         }

         // using existing DataSource to get a JDBC Connection.
         Connection jdbcConn = connFactory.getJdbcConnection();

         DBBackup.backup(storageDir, jdbcConn, scripts);

         // backup value storage
         if (wsConfig.getContainer().getValueStorages() != null)
         {
            SecurityHelper.doPrivilegedExceptionAction(new PrivilegedExceptionAction<Void>()
            {
               public Void run() throws RepositoryConfigurationException, IOException
               {
                  for (ValueStorageEntry valueStorage : wsConfig.getContainer().getValueStorages())
                  {
                     File srcDir = new File(valueStorage.getParameterValue(FileValueStorage.PATH));

                     if (!srcDir.exists())
                     {
                        throw new IOException("Can't backup value storage. Directory " + srcDir.getName()
                           + " doesn't exists");
                     }
                     else
                     {
                        File zipFile = new File(storageDir, "values-" + valueStorage.getId() + ".zip");
                        DirectoryHelper.compressDirectory(srcDir, zipFile);
                     }
                  }
                  return null;
               }
            });
         }
      }
      catch (IOException e)
      {
         throw new BackupException(e);
      }
      catch (RepositoryException e)
      {
         throw new BackupException(e);
      }
      catch (PrivilegedActionException e)
      {
         throw new BackupException(e);
      }
      finally
      {
         if (backupInfo != null)
         {
            try
            {
               backupInfo.close();
            }
            catch (IOException e)
            {
               throw new BackupException(e);
            }
View Full Code Here

   /**
    * {@inheritDoc}
    */
   public void backup(final File storageDir) throws BackupException
   {
      ObjectWriter backupInfo = null;

      try
      {
         backupInfo =
            new ObjectWriterImpl(PrivilegedFileHelper.fileOutputStream(new File(storageDir,
               "JDBCWorkspaceDataContainer.info")));

         backupInfo.writeString(containerConfig.containerName);
         backupInfo.writeString(containerConfig.dbStructureType.toString());

         Map<String, String> scripts = new HashMap<String, String>();

         String itemTable = DBInitializerHelper.getItemTableName(containerConfig);
         String valueTable = DBInitializerHelper.getValueTableName(containerConfig);
         String refTable = DBInitializerHelper.getRefTableName(containerConfig);

         backupInfo.writeString(itemTable);
         backupInfo.writeString(valueTable);
         backupInfo.writeString(refTable);

         if (containerConfig.dbStructureType.isMultiDatabase())
         {
            scripts
               .put(itemTable, "select * from " + itemTable + " where NAME <> '" + Constants.ROOT_PARENT_NAME + "'");
            scripts.put(valueTable, "select * from " + valueTable);
            scripts.put(refTable, "select * from " + refTable);
         }
         else
         {
            scripts.put(itemTable, "select * from " + itemTable + " where CONTAINER_NAME='"
               + containerConfig.containerName + "'");
            scripts.put(valueTable, "select V.* from " + valueTable + " V, " + itemTable
               + " I where I.ID=V.PROPERTY_ID and I.CONTAINER_NAME='" + containerConfig.containerName + "'");
            scripts.put(refTable, "select R.* from " + refTable + " R, " + itemTable
               + " I where I.ID=R.PROPERTY_ID and I.CONTAINER_NAME='" + containerConfig.containerName + "'");
         }

         // using existing DataSource to get a JDBC Connection.
         Connection jdbcConn = connFactory.getJdbcConnection();

         DBBackup.backup(storageDir, jdbcConn, scripts);

         // backup value storage
         if (wsConfig.getContainer().getValueStorages() != null)
         {
            SecurityHelper.doPrivilegedExceptionAction(new PrivilegedExceptionAction<Void>()
            {
               public Void run() throws RepositoryConfigurationException, IOException
               {
                  for (ValueStorageEntry valueStorage : wsConfig.getContainer().getValueStorages())
                  {
                     File srcDir = new File(valueStorage.getParameterValue(FileValueStorage.PATH));

                     if (!srcDir.exists())
                     {
                        throw new IOException("Can't backup value storage. Directory " + srcDir.getName()
                           + " doesn't exists");
                     }
                     else
                     {
                        File zipFile = new File(storageDir, "values-" + valueStorage.getId() + ".zip");
                        DirectoryHelper.compressDirectory(srcDir, zipFile);
                     }
                  }
                  return null;
               }
            });
         }
      }
      catch (IOException e)
      {
         throw new BackupException(e);
      }
      catch (RepositoryException e)
      {
         throw new BackupException(e);
      }
      catch (PrivilegedActionException e)
      {
         throw new BackupException(e);
      }
      finally
      {
         if (backupInfo != null)
         {
            try
            {
               backupInfo.close();
            }
            catch (IOException e)
            {
               throw new BackupException(e);
            }
View Full Code Here

    * {@inheritDoc}
    */
   public void backup(final File storageDir) throws BackupException
   {
      LOG.info("Start to backup value storage of the workspace '"+containerConfig.containerName+"'");
      ObjectWriter backupInfo = null;

      try
      {
         backupInfo =
            new ObjectWriterImpl(PrivilegedFileHelper.fileOutputStream(new File(storageDir,
               "JDBCWorkspaceDataContainer.info")));

         backupInfo.writeString(containerConfig.containerName);
         backupInfo.writeString(containerConfig.dbStructureType.toString());

         Map<String, String> scripts = new HashMap<String, String>();

         String itemTable = DBInitializerHelper.getItemTableName(containerConfig);
         String valueTable = DBInitializerHelper.getValueTableName(containerConfig);
         String refTable = DBInitializerHelper.getRefTableName(containerConfig);

         backupInfo.writeString(itemTable);
         backupInfo.writeString(valueTable);
         backupInfo.writeString(refTable);

         if (containerConfig.dbStructureType.isMultiDatabase())
         {
            scripts
               .put(itemTable, "select * from " + itemTable + " where NAME <> '" + Constants.ROOT_PARENT_NAME + "'");
            scripts.put(valueTable, "select * from " + valueTable);
            scripts.put(refTable, "select * from " + refTable);
         }
         else
         {
            scripts.put(itemTable, "select * from " + itemTable + " where CONTAINER_NAME='"
               + containerConfig.containerName + "'");
            scripts.put(valueTable, "select V.* from " + valueTable + " V, " + itemTable
               + " I where I.ID=V.PROPERTY_ID and I.CONTAINER_NAME='" + containerConfig.containerName + "'");
            scripts.put(refTable, "select R.* from " + refTable + " R, " + itemTable
               + " I where I.ID=R.PROPERTY_ID and I.CONTAINER_NAME='" + containerConfig.containerName + "'");
         }

         // using existing DataSource to get a JDBC Connection.
         Connection jdbcConn = connFactory.getJdbcConnection();

         DBBackup.backup(storageDir, jdbcConn, scripts);

         // backup value storage
         if (wsConfig.getContainer().getValueStorages() != null)
         {
            SecurityHelper.doPrivilegedExceptionAction(new PrivilegedExceptionAction<Void>()
            {
               public Void run() throws RepositoryConfigurationException, IOException
               {
                  for (ValueStorageEntry valueStorage : wsConfig.getContainer().getValueStorages())
                  {
                     File srcDir = new File(valueStorage.getParameterValue(FileValueStorage.PATH));

                     if (!srcDir.exists())
                     {
                        throw new IOException("Can't backup value storage. Directory " + srcDir.getName()
                           + " doesn't exists");
                     }
                     else
                     {
                        File zipFile = new File(storageDir, "values-" + valueStorage.getId() + ".zip");
                        DirectoryHelper.compressDirectory(srcDir, zipFile);
                     }
                  }
                  return null;
               }
            });
         }
      }
      catch (IOException e)
      {
         throw new BackupException(e);
      }
      catch (RepositoryException e)
      {
         throw new BackupException(e);
      }
      catch (PrivilegedActionException e)
      {
         throw new BackupException(e);
      }
      finally
      {
         if (backupInfo != null)
         {
            try
            {
               backupInfo.close();
            }
            catch (IOException e)
            {
               throw new BackupException(e);
            }
View Full Code Here

TOP

Related Classes of org.exoplatform.services.jcr.dataflow.serialization.ObjectWriter

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.