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

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


   public void testReadBoolean() throws Exception
   {

      File test = File.createTempFile("testEOF", "");
      ObjectWriter ow = new ObjectWriterImpl(new FileOutputStream(test));

      ow.writeBoolean(true);
      ow.close();

      ObjectReader or = new ObjectReaderImpl(new FileInputStream(test));

      boolean b = or.readBoolean();
      try
View Full Code Here


   public void testReadInt() throws Exception
   {

      File test = File.createTempFile("testEOF", "");
      ObjectWriter ow = new ObjectWriterImpl(new FileOutputStream(test));

      ow.writeInt(24);
      ow.close();

      ObjectReader or = new ObjectReaderImpl(new FileInputStream(test));

      int b = or.readInt();
      assertEquals(24, b);
View Full Code Here

   public void testReadLong() throws Exception
   {

      File test = File.createTempFile("testEOF", "");
      ObjectWriter ow = new ObjectWriterImpl(new FileOutputStream(test));

      ow.writeLong(24);
      ow.close();

      ObjectReader or = new ObjectReaderImpl(new FileInputStream(test));

      long b = or.readLong();
      assertEquals(24, b);
View Full Code Here

      {
         srcSerialization = File.createTempFile("srcSerialization", ".tmp");
         srcSerialization.deleteOnExit();

         OutputStream out = new FileOutputStream(srcSerialization);
         ObjectWriter ow = new ObjectWriterImpl(out);
         for (int i = 0; i < BLOCK_COUNT; i++)
         {
            ow.writeInt(1024);
            ow.writeInt(1024);
            ow.writeInt(1024);
            ow.writeLong(1024);
            ow.writeLong(1024);
            ow.writeLong(1024);
            ow.writeString(str);
            ow.writeString(str);
            ow.write(buf);
         }

         out.flush();
         out.close();
      }
View Full Code Here

      InputStream in = new FileInputStream(srcSerialization);
      OutputStream out = new FileOutputStream(dest);

      ObjectReader or = new ObjectReaderImpl(in);
      ObjectWriter ow = new ObjectWriterImpl(out);

      for (int i = 0; i < BLOCK_COUNT; i++)
      {
         ow.writeInt(or.readInt());
         ow.writeInt(or.readInt());
         ow.writeInt(or.readInt());
         ow.writeLong(or.readLong());
         ow.writeLong(or.readLong());
         ow.writeLong(or.readLong());
         ow.writeString(or.readString());
         ow.writeString(or.readString());
         or.readFully(buf);
         ow.write(buf);
      }

      in.close();
      out.flush();
      out.close();
View Full Code Here

   /**
    * {@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 V.* from JCR_SVALUE V, JCR_SITEM I where I.ID=V.PROPERTY_ID and I.CONTAINER_NAME='"
                  + containerName + "'");
            scripts.put("JCR_SREF",
               "select R.* from JCR_SREF R, JCR_SITEM I where I.ID=R.PROPERTY_ID and I.CONTAINER_NAME='"
                  + 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)
         {
            for (ValueStorageEntry valueStorage : wsConfig.getContainer().getValueStorages())
            {
               File srcDir = new File(valueStorage.getParameterValue(FileValueStorage.PATH));
               if (!PrivilegedFileHelper.exists(srcDir))
               {
                  throw new BackupException("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);
               }
            }
         }
      }
      catch (IOException e)
      {
         throw new BackupException(e);
      }
      catch (RepositoryConfigurationException e)
      {
         throw new BackupException(e);
      }
      catch (RepositoryException 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

   /**
    * {@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(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 V.* from JCR_SVALUE V, JCR_SITEM I where I.ID=V.PROPERTY_ID and I.CONTAINER_NAME='"
                  + containerName + "'");
            scripts.put("JCR_SREF",
               "select R.* from JCR_SREF R, JCR_SITEM I where I.ID=R.PROPERTY_ID and I.CONTAINER_NAME='"
                  + 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 IOException, RepositoryConfigurationException
               {
                  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(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 V.* from JCR_SVALUE V, JCR_SITEM I where I.ID=V.PROPERTY_ID and I.CONTAINER_NAME='"
                  + containerName + "'");
            scripts.put("JCR_SREF",
               "select R.* from JCR_SREF R, JCR_SITEM I where I.ID=R.PROPERTY_ID and I.CONTAINER_NAME='"
                  + 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)
         {
            for (ValueStorageEntry valueStorage : wsConfig.getContainer().getValueStorages())
            {
               File srcDir = new File(valueStorage.getParameterValue(FileValueStorage.PATH));
               if (!PrivilegedFileHelper.exists(srcDir))
               {
                  throw new BackupException("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);
               }
            }
         }
      }
      catch (IOException e)
      {
         throw new BackupException(e);
      }
      catch (RepositoryConfigurationException e)
      {
         throw new BackupException(e);
      }
      catch (RepositoryException 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.