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

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


   public DataRestore getDataRestorer(DataRestoreContext context) throws BackupException
   {

      List<DataRestore> restorers = new ArrayList<DataRestore>();

      ObjectReader backupInfo = null;
      try
      {
         File storageDir = (File)context.getObject(DataRestoreContext.STORAGE_DIR);
         Connection jdbcConn = null;

         if (context.getObject(DataRestoreContext.DB_CONNECTION) == null)
         {
            try
            {
               jdbcConn = connFactory.getJdbcConnection();
               jdbcConn.setAutoCommit(false);
            }
            catch (SQLException e)
            {
               throw new BackupException(e);
            }
            catch (RepositoryException e)
            {
               throw new BackupException(e);
            }

         }
         else
         {
            jdbcConn = (Connection)context.getObject(DataRestoreContext.DB_CONNECTION);
         }

         backupInfo =
            new ObjectReaderImpl(PrivilegedFileHelper.fileInputStream(new File(storageDir,
               "JDBCWorkspaceDataContainer.info")));

         String srcContainerName = backupInfo.readString();
         boolean srcMultiDb = backupInfo.readBoolean();

         Map<String, RestoreTableRule> tables = new LinkedHashMap<String, RestoreTableRule>();

         // ITEM table
         String dstTableName = "JCR_" + (multiDb ? "M" : "S") + "ITEM";
         String srcTableName = "JCR_" + (srcMultiDb ? "M" : "S") + "ITEM";

         RestoreTableRule restoreTableRule = new RestoreTableRule();
         restoreTableRule.setSrcContainerName(srcContainerName);
         restoreTableRule.setSrcMultiDb(srcMultiDb);
         restoreTableRule.setDstContainerName(containerName);
         restoreTableRule.setDstMultiDb(multiDb);
         restoreTableRule.setSrcTableName(srcTableName);

         if (multiDb)
         {
            if (!srcMultiDb)
            {
               // CONTAINER_NAME column index
               restoreTableRule.setDeleteColumnIndex(4);

               // ID and PARENT_ID column indexes
               Set<Integer> convertColumnIndex = new HashSet<Integer>();
               convertColumnIndex.add(0);
               convertColumnIndex.add(1);
               restoreTableRule.setConvertColumnIndex(convertColumnIndex);
            }
         }
         else
         {
            if (srcMultiDb)
            {
               // CONTAINER_NAME column index
               restoreTableRule.setNewColumnIndex(4);
               restoreTableRule.setNewColumnName("CONTAINER_NAME");
               restoreTableRule.setNewColumnType(Types.VARCHAR);

               // ID and PARENT_ID column indexes
               Set<Integer> convertColumnIndex = new HashSet<Integer>();
               convertColumnIndex.add(0);
               convertColumnIndex.add(1);
               restoreTableRule.setConvertColumnIndex(convertColumnIndex);
            }
            else
            {
               // ID and PARENT_ID and CONTAINER_NAME column indexes
               Set<Integer> convertColumnIndex = new HashSet<Integer>();
               convertColumnIndex.add(0);
               convertColumnIndex.add(1);
               convertColumnIndex.add(4);
               restoreTableRule.setConvertColumnIndex(convertColumnIndex);
            }
         }
         tables.put(dstTableName, restoreTableRule);

         // VALUE table
         dstTableName = "JCR_" + (multiDb ? "M" : "S") + "VALUE";
         srcTableName = "JCR_" + (srcMultiDb ? "M" : "S") + "VALUE";

         restoreTableRule = new RestoreTableRule();
         restoreTableRule.setSrcContainerName(srcContainerName);
         restoreTableRule.setSrcMultiDb(srcMultiDb);
         restoreTableRule.setDstContainerName(containerName);
         restoreTableRule.setDstMultiDb(multiDb);
         restoreTableRule.setSrcTableName(srcTableName);

         // auto increment ID column
         restoreTableRule.setSkipColumnIndex(0);

         if (!multiDb || !srcMultiDb)
         {
            // PROPERTY_ID column index
            Set<Integer> convertColumnIndex = new HashSet<Integer>();
            convertColumnIndex.add(3);
            restoreTableRule.setConvertColumnIndex(convertColumnIndex);
         }
         tables.put(dstTableName, restoreTableRule);

         // REF tables
         dstTableName = "JCR_" + (multiDb ? "M" : "S") + "REF";
         srcTableName = "JCR_" + (srcMultiDb ? "M" : "S") + "REF";

         restoreTableRule = new RestoreTableRule();
         restoreTableRule.setSrcContainerName(srcContainerName);
         restoreTableRule.setSrcMultiDb(srcMultiDb);
         restoreTableRule.setDstContainerName(containerName);
         restoreTableRule.setDstMultiDb(multiDb);
         restoreTableRule.setSrcTableName(srcTableName);

         if (!multiDb || !srcMultiDb)
         {
            // NODE_ID and PROPERTY_ID column indexes
            Set<Integer> convertColumnIndex = new HashSet<Integer>();
            convertColumnIndex.add(0);
            convertColumnIndex.add(1);
            restoreTableRule.setConvertColumnIndex(convertColumnIndex);
         }
         tables.put(dstTableName, restoreTableRule);

         DBCleaner dbCleaner = null;
         if (context.getObject(DataRestoreContext.DB_CLEANER) != null)
         {
            dbCleaner = (DBCleaner)context.getObject(DataRestoreContext.DB_CLEANER);
         }
         else
         {
            dbCleaner = DBCleanService.getWorkspaceDBCleaner(jdbcConn, wsConfig);
         }

         restorers.add(new DBRestore(storageDir, jdbcConn, tables, wsConfig, swapCleaner, dbCleaner));

         // prepare value storage restorer
         if (wsConfig.getContainer().getValueStorages() != null)
         {
            List<File> dataDirs = new ArrayList<File>();
            List<File> backupDirs = new ArrayList<File>();

            List<ValueStorageEntry> valueStorages = wsConfig.getContainer().getValueStorages();
            for (ValueStorageEntry valueStorage : valueStorages)
            {
               File dataDir = new File(valueStorage.getParameterValue(FileValueStorage.PATH));
               dataDirs.add(dataDir);

               File zipFile = new File(storageDir, "values-" + valueStorage.getId() + ".zip");
               if (PrivilegedFileHelper.exists(zipFile))
               {
                  backupDirs.add(zipFile);
               }
               else
               {
                  // try to check if we have deal with old backup format
                  zipFile = new File(storageDir, "values/" + valueStorage.getId());
                  if (PrivilegedFileHelper.exists(zipFile))
                  {
                     backupDirs.add(zipFile);
                  }
                  else
                  {
                     throw new RepositoryConfigurationException("There is no backup data for value storage with id "
                        + valueStorage.getId());
                  }
               }
            }

            restorers.add(new DirectoryRestore(dataDirs, backupDirs));
         }

         return new ComplexDataRestore(restorers);
      }
      catch (FileNotFoundException e)
      {
         throw new BackupException(e);
      }
      catch (IOException e)
      {
         throw new BackupException(e);
      }
      catch (NamingException e)
      {
         throw new BackupException(e);
      }
      catch (SQLException e)
      {
         throw new BackupException(e);
      }
      catch (RepositoryConfigurationException e)
      {
         throw new BackupException(e);
      }
      finally
      {
         if (backupInfo != null)
         {
            try
            {
               backupInfo.close();
            }
            catch (IOException e)
            {
               LOG.error("Can't close object reader", e);
            }
View Full Code Here


   public DataRestore getDataRestorer(File storageDir, Connection jdbcConn) throws BackupException
   {

      List<DataRestore> restorers = new ArrayList<DataRestore>();

      ObjectReader backupInfo = null;
      try
      {
         backupInfo =
            new ObjectReaderImpl(PrivilegedFileHelper.fileInputStream(new File(storageDir,
               "JDBCWorkspaceDataContainer.info")));

         String srcContainerName = backupInfo.readString();
         boolean srcMultiDb = backupInfo.readBoolean();

         Map<String, RestoreTableRule> tables = new LinkedHashMap<String, RestoreTableRule>();

         // ITEM table
         String dstTableName = "JCR_" + (multiDb ? "M" : "S") + "ITEM";
         String srcTableName = "JCR_" + (srcMultiDb ? "M" : "S") + "ITEM";

         RestoreTableRule restoreTableRule = new RestoreTableRule();
         restoreTableRule.setSrcContainerName(srcContainerName);
         restoreTableRule.setSrcMultiDb(srcMultiDb);
         restoreTableRule.setDstContainerName(containerName);
         restoreTableRule.setDstMultiDb(multiDb);
         restoreTableRule.setContentFile(new File(storageDir, srcTableName + DBBackup.CONTENT_FILE_SUFFIX));
         restoreTableRule.setContentLenFile(new File(storageDir, srcTableName + DBBackup.CONTENT_LEN_FILE_SUFFIX));

         if (multiDb)
         {
            if (!srcMultiDb)
            {
               // CONTAINER_NAME column index
               restoreTableRule.setDeleteColumnIndex(4);

               // ID and PARENT_ID column indexes
               Set<Integer> convertColumnIndex = new HashSet<Integer>();
               convertColumnIndex.add(0);
               convertColumnIndex.add(1);
               restoreTableRule.setConvertColumnIndex(convertColumnIndex);
            }
         }
         else
         {
            if (srcMultiDb)
            {
               // CONTAINER_NAME column index
               restoreTableRule.setNewColumnIndex(4);
               restoreTableRule.setNewColumnName("CONTAINER_NAME");
               restoreTableRule.setNewColumnType(Types.VARCHAR);

               // ID and PARENT_ID column indexes
               Set<Integer> convertColumnIndex = new HashSet<Integer>();
               convertColumnIndex.add(0);
               convertColumnIndex.add(1);
               restoreTableRule.setConvertColumnIndex(convertColumnIndex);
            }
            else
            {
               // ID and PARENT_ID and CONTAINER_NAME column indexes
               Set<Integer> convertColumnIndex = new HashSet<Integer>();
               convertColumnIndex.add(0);
               convertColumnIndex.add(1);
               convertColumnIndex.add(4);
               restoreTableRule.setConvertColumnIndex(convertColumnIndex);
            }
         }
         tables.put(dstTableName, restoreTableRule);

         // VALUE table
         dstTableName = "JCR_" + (multiDb ? "M" : "S") + "VALUE";
         srcTableName = "JCR_" + (srcMultiDb ? "M" : "S") + "VALUE";

         restoreTableRule = new RestoreTableRule();
         restoreTableRule.setSrcContainerName(srcContainerName);
         restoreTableRule.setSrcMultiDb(srcMultiDb);
         restoreTableRule.setDstContainerName(containerName);
         restoreTableRule.setDstMultiDb(multiDb);
         restoreTableRule.setContentFile(new File(storageDir, srcTableName + DBBackup.CONTENT_FILE_SUFFIX));
         restoreTableRule.setContentLenFile(new File(storageDir, srcTableName + DBBackup.CONTENT_LEN_FILE_SUFFIX));

         // auto increment ID column
         restoreTableRule.setSkipColumnIndex(0);

         if (!multiDb || !srcMultiDb)
         {
            // PROPERTY_ID column index
            Set<Integer> convertColumnIndex = new HashSet<Integer>();
            convertColumnIndex.add(3);
            restoreTableRule.setConvertColumnIndex(convertColumnIndex);
         }
         tables.put(dstTableName, restoreTableRule);

         // REF tables
         dstTableName = "JCR_" + (multiDb ? "M" : "S") + "REF";
         srcTableName = "JCR_" + (srcMultiDb ? "M" : "S") + "REF";

         restoreTableRule = new RestoreTableRule();
         restoreTableRule.setSrcContainerName(srcContainerName);
         restoreTableRule.setSrcMultiDb(srcMultiDb);
         restoreTableRule.setDstContainerName(containerName);
         restoreTableRule.setDstMultiDb(multiDb);
         restoreTableRule.setContentFile(new File(storageDir, srcTableName + DBBackup.CONTENT_FILE_SUFFIX));
         restoreTableRule.setContentLenFile(new File(storageDir, srcTableName + DBBackup.CONTENT_LEN_FILE_SUFFIX));

         if (!multiDb || !srcMultiDb)
         {
            // NODE_ID and PROPERTY_ID column indexes
            Set<Integer> convertColumnIndex = new HashSet<Integer>();
            convertColumnIndex.add(0);
            convertColumnIndex.add(1);
            restoreTableRule.setConvertColumnIndex(convertColumnIndex);
         }
         tables.put(dstTableName, restoreTableRule);

         restorers.add(new DBRestore(storageDir, jdbcConn, tables, wsConfig, swapCleaner));

         // prepare value storage restorer
         File backupValueStorageDir = new File(storageDir, "values");
         if (wsConfig.getContainer().getValueStorages() != null)
         {
            List<File> dataDirs = new ArrayList<File>();
            List<File> backupDirs = new ArrayList<File>();

            List<ValueStorageEntry> valueStorages = wsConfig.getContainer().getValueStorages();
            String[] valueStoragesFiles = PrivilegedFileHelper.list(backupValueStorageDir);

            if ((valueStoragesFiles == null && valueStorages.size() != 0)
               || (valueStoragesFiles != null && valueStoragesFiles.length != valueStorages.size()))
            {
               throw new RepositoryConfigurationException("Workspace configuration [" + wsConfig.getName()
                  + "] has a different amount of value storages than exist in backup");
            }

            for (ValueStorageEntry valueStorage : valueStorages)
            {
               File backupDir = new File(backupValueStorageDir, valueStorage.getId());
               if (!PrivilegedFileHelper.exists(backupDir))
               {
                  throw new RepositoryConfigurationException("Can't restore value storage. Directory "
                     + backupDir.getName() + " doesn't exists");
               }
               else
               {
                  File dataDir = new File(valueStorage.getParameterValue(FileValueStorage.PATH));

                  dataDirs.add(dataDir);
                  backupDirs.add(backupDir);
               }
            }

            restorers.add(new DirectoryRestore(dataDirs, backupDirs));
         }
         else
         {
            if (PrivilegedFileHelper.exists(backupValueStorageDir))
            {
               throw new RepositoryConfigurationException("Value storage didn't configure in workspace ["
                  + wsConfig.getName() + "] configuration but value storage backup files exist");
            }
         }

         return new ComplexDataRestore(restorers);
      }
      catch (FileNotFoundException e)
      {
         throw new BackupException(e);
      }
      catch (IOException e)
      {
         throw new BackupException(e);
      }
      catch (NamingException e)
      {
         throw new BackupException(e);
      }
      catch (SQLException e)
      {
         throw new BackupException(e);
      }
      catch (RepositoryConfigurationException e)
      {
         throw new BackupException(e);
      }
      finally
      {
         if (backupInfo != null)
         {
            try
            {
               backupInfo.close();
            }
            catch (IOException e)
            {
               LOG.error("Can't close object reader", e);
            }
View Full Code Here

   public DataRestore getDataRestorer(DataRestoreContext context) throws BackupException
   {

      List<DataRestore> restorers = new ArrayList<DataRestore>();

      ObjectReader backupInfo = null;
      try
      {
         File storageDir = (File)context.getObject(DataRestoreContext.STORAGE_DIR);
         Connection jdbcConn = null;

         if (context.getObject(DataRestoreContext.DB_CONNECTION) == null)
         {
            try
            {
               jdbcConn = connFactory.getJdbcConnection();
               jdbcConn.setAutoCommit(false);
            }
            catch (SQLException e)
            {
               throw new BackupException(e);
            }
            catch (RepositoryException e)
            {
               throw new BackupException(e);
            }

         }
         else
         {
            jdbcConn = (Connection)context.getObject(DataRestoreContext.DB_CONNECTION);
         }

         backupInfo =
            new ObjectReaderImpl(PrivilegedFileHelper.fileInputStream(new File(storageDir,
               "JDBCWorkspaceDataContainer.info")));

         String srcContainerName = backupInfo.readString();
         boolean srcMultiDb = backupInfo.readBoolean();

         Map<String, RestoreTableRule> tables = new LinkedHashMap<String, RestoreTableRule>();

         // ITEM table
         String dstTableName = "JCR_" + (multiDb ? "M" : "S") + "ITEM";
         String srcTableName = "JCR_" + (srcMultiDb ? "M" : "S") + "ITEM";

         RestoreTableRule restoreTableRule = new RestoreTableRule();
         restoreTableRule.setSrcContainerName(srcContainerName);
         restoreTableRule.setSrcMultiDb(srcMultiDb);
         restoreTableRule.setDstContainerName(containerName);
         restoreTableRule.setDstMultiDb(multiDb);
         restoreTableRule.setSrcTableName(srcTableName);

         if (multiDb)
         {
            if (!srcMultiDb)
            {
               // CONTAINER_NAME column index
               restoreTableRule.setDeleteColumnIndex(4);

               // ID and PARENT_ID column indexes
               Set<Integer> convertColumnIndex = new HashSet<Integer>();
               convertColumnIndex.add(0);
               convertColumnIndex.add(1);
               restoreTableRule.setConvertColumnIndex(convertColumnIndex);
            }
         }
         else
         {
            if (srcMultiDb)
            {
               // CONTAINER_NAME column index
               restoreTableRule.setNewColumnIndex(4);
               restoreTableRule.setNewColumnName("CONTAINER_NAME");
               restoreTableRule.setNewColumnType(Types.VARCHAR);

               // ID and PARENT_ID column indexes
               Set<Integer> convertColumnIndex = new HashSet<Integer>();
               convertColumnIndex.add(0);
               convertColumnIndex.add(1);
               restoreTableRule.setConvertColumnIndex(convertColumnIndex);
            }
            else
            {
               // ID and PARENT_ID and CONTAINER_NAME column indexes
               Set<Integer> convertColumnIndex = new HashSet<Integer>();
               convertColumnIndex.add(0);
               convertColumnIndex.add(1);
               convertColumnIndex.add(4);
               restoreTableRule.setConvertColumnIndex(convertColumnIndex);
            }
         }
         tables.put(dstTableName, restoreTableRule);

         // VALUE table
         dstTableName = "JCR_" + (multiDb ? "M" : "S") + "VALUE";
         srcTableName = "JCR_" + (srcMultiDb ? "M" : "S") + "VALUE";

         restoreTableRule = new RestoreTableRule();
         restoreTableRule.setSrcContainerName(srcContainerName);
         restoreTableRule.setSrcMultiDb(srcMultiDb);
         restoreTableRule.setDstContainerName(containerName);
         restoreTableRule.setDstMultiDb(multiDb);
         restoreTableRule.setSrcTableName(srcTableName);

         // auto increment ID column
         restoreTableRule.setSkipColumnIndex(0);

         if (!multiDb || !srcMultiDb)
         {
            // PROPERTY_ID column index
            Set<Integer> convertColumnIndex = new HashSet<Integer>();
            convertColumnIndex.add(3);
            restoreTableRule.setConvertColumnIndex(convertColumnIndex);
         }
         tables.put(dstTableName, restoreTableRule);

         // REF tables
         dstTableName = "JCR_" + (multiDb ? "M" : "S") + "REF";
         srcTableName = "JCR_" + (srcMultiDb ? "M" : "S") + "REF";

         restoreTableRule = new RestoreTableRule();
         restoreTableRule.setSrcContainerName(srcContainerName);
         restoreTableRule.setSrcMultiDb(srcMultiDb);
         restoreTableRule.setDstContainerName(containerName);
         restoreTableRule.setDstMultiDb(multiDb);
         restoreTableRule.setSrcTableName(srcTableName);

         if (!multiDb || !srcMultiDb)
         {
            // NODE_ID and PROPERTY_ID column indexes
            Set<Integer> convertColumnIndex = new HashSet<Integer>();
            convertColumnIndex.add(0);
            convertColumnIndex.add(1);
            restoreTableRule.setConvertColumnIndex(convertColumnIndex);
         }
         tables.put(dstTableName, restoreTableRule);

         DBCleaner dbCleaner = null;
         if (context.getObject(DataRestoreContext.DB_CLEANER) != null)
         {
            dbCleaner = (DBCleaner)context.getObject(DataRestoreContext.DB_CLEANER);
         }
         else
         {
            dbCleaner = DBCleanService.getWorkspaceDBCleaner(jdbcConn, wsConfig);
         }

         restorers.add(new DBRestore(storageDir, jdbcConn, tables, wsConfig, swapCleaner, dbCleaner));

         // prepare value storage restorer
         if (wsConfig.getContainer().getValueStorages() != null)
         {
            List<File> dataDirs = new ArrayList<File>();
            List<File> backupDirs = new ArrayList<File>();

            List<ValueStorageEntry> valueStorages = wsConfig.getContainer().getValueStorages();
            for (ValueStorageEntry valueStorage : valueStorages)
            {
               File dataDir = new File(valueStorage.getParameterValue(FileValueStorage.PATH));
               dataDirs.add(dataDir);

               File zipFile = new File(storageDir, "values-" + valueStorage.getId() + ".zip");
               if (PrivilegedFileHelper.exists(zipFile))
               {
                  backupDirs.add(zipFile);
               }
               else
               {
                  // try to check if we have deal with old backup format
                  zipFile = new File(storageDir, "values/" + valueStorage.getId());
                  if (PrivilegedFileHelper.exists(zipFile))
                  {
                     backupDirs.add(zipFile);
                  }
                  else
                  {
                     throw new RepositoryConfigurationException("There is no backup data for value storage with id "
                        + valueStorage.getId());
                  }
               }
            }

            restorers.add(new DirectoryRestore(dataDirs, backupDirs));
         }

         return new ComplexDataRestore(restorers);
      }
      catch (FileNotFoundException e)
      {
         throw new BackupException(e);
      }
      catch (IOException e)
      {
         throw new BackupException(e);
      }
      catch (NamingException e)
      {
         throw new BackupException(e);
      }
      catch (SQLException e)
      {
         throw new BackupException(e);
      }
      catch (RepositoryConfigurationException e)
      {
         throw new BackupException(e);
      }
      finally
      {
         if (backupInfo != null)
         {
            try
            {
               backupInfo.close();
            }
            catch (IOException e)
            {
               LOG.error("Can't close object reader", e);
            }
View Full Code Here

   public DataRestore getDataRestorer(DataRestoreContext context) throws BackupException
   {

      List<DataRestore> restorers = new ArrayList<DataRestore>();

      ObjectReader backupInfo = null;
      try
      {
         File storageDir = (File) context.getObject(DataRestoreContext.STORAGE_DIR);
         Connection jdbcConn = null;

         if (context.getObject(DataRestoreContext.DB_CONNECTION) == null)
         {
            try
            {
               jdbcConn = connFactory.getJdbcConnection();
               jdbcConn.setAutoCommit(false);
            }
            catch (SQLException e)
            {
               throw new BackupException(e);
            }
            catch (RepositoryException e)
            {
               throw new BackupException(e);
            }

         }
         else
         {
            jdbcConn = (Connection) context.getObject(DataRestoreContext.DB_CONNECTION);
         }

         backupInfo =
                  new ObjectReaderImpl(PrivilegedFileHelper.fileInputStream(new File(storageDir,
               "JDBCWorkspaceDataContainer.info")));

         String srcContainerName = backupInfo.readString();
         boolean srcMultiDb = backupInfo.readBoolean();

         Map<String, RestoreTableRule> tables = new LinkedHashMap<String, RestoreTableRule>();

         // ITEM table
         String dstTableName = "JCR_" + (multiDb ? "M" : "S") + "ITEM";
         String srcTableName = "JCR_" + (srcMultiDb ? "M" : "S") + "ITEM";

         RestoreTableRule restoreTableRule = new RestoreTableRule();
         restoreTableRule.setSrcContainerName(srcContainerName);
         restoreTableRule.setSrcMultiDb(srcMultiDb);
         restoreTableRule.setDstContainerName(containerName);
         restoreTableRule.setDstMultiDb(multiDb);
         restoreTableRule.setContentFile(new File(storageDir, srcTableName + DBBackup.CONTENT_FILE_SUFFIX));
         restoreTableRule.setContentLenFile(new File(storageDir, srcTableName + DBBackup.CONTENT_LEN_FILE_SUFFIX));

         if (multiDb)
         {
            if (!srcMultiDb)
            {
               // CONTAINER_NAME column index
               restoreTableRule.setDeleteColumnIndex(4);

               // ID and PARENT_ID column indexes
               Set<Integer> convertColumnIndex = new HashSet<Integer>();
               convertColumnIndex.add(0);
               convertColumnIndex.add(1);
               restoreTableRule.setConvertColumnIndex(convertColumnIndex);
            }
         }
         else
         {
            if (srcMultiDb)
            {
               // CONTAINER_NAME column index
               restoreTableRule.setNewColumnIndex(4);
               restoreTableRule.setNewColumnName("CONTAINER_NAME");
               restoreTableRule.setNewColumnType(Types.VARCHAR);

               // ID and PARENT_ID column indexes
               Set<Integer> convertColumnIndex = new HashSet<Integer>();
               convertColumnIndex.add(0);
               convertColumnIndex.add(1);
               restoreTableRule.setConvertColumnIndex(convertColumnIndex);
            }
            else
            {
               // ID and PARENT_ID and CONTAINER_NAME column indexes
               Set<Integer> convertColumnIndex = new HashSet<Integer>();
               convertColumnIndex.add(0);
               convertColumnIndex.add(1);
               convertColumnIndex.add(4);
               restoreTableRule.setConvertColumnIndex(convertColumnIndex);
            }
         }
         tables.put(dstTableName, restoreTableRule);

         // VALUE table
         dstTableName = "JCR_" + (multiDb ? "M" : "S") + "VALUE";
         srcTableName = "JCR_" + (srcMultiDb ? "M" : "S") + "VALUE";

         restoreTableRule = new RestoreTableRule();
         restoreTableRule.setSrcContainerName(srcContainerName);
         restoreTableRule.setSrcMultiDb(srcMultiDb);
         restoreTableRule.setDstContainerName(containerName);
         restoreTableRule.setDstMultiDb(multiDb);
         restoreTableRule.setContentFile(new File(storageDir, srcTableName + DBBackup.CONTENT_FILE_SUFFIX));
         restoreTableRule.setContentLenFile(new File(storageDir, srcTableName + DBBackup.CONTENT_LEN_FILE_SUFFIX));

         // auto increment ID column
         restoreTableRule.setSkipColumnIndex(0);

         if (!multiDb || !srcMultiDb)
         {
            // PROPERTY_ID column index
            Set<Integer> convertColumnIndex = new HashSet<Integer>();
            convertColumnIndex.add(3);
            restoreTableRule.setConvertColumnIndex(convertColumnIndex);
         }
         tables.put(dstTableName, restoreTableRule);

         // REF tables
         dstTableName = "JCR_" + (multiDb ? "M" : "S") + "REF";
         srcTableName = "JCR_" + (srcMultiDb ? "M" : "S") + "REF";

         restoreTableRule = new RestoreTableRule();
         restoreTableRule.setSrcContainerName(srcContainerName);
         restoreTableRule.setSrcMultiDb(srcMultiDb);
         restoreTableRule.setDstContainerName(containerName);
         restoreTableRule.setDstMultiDb(multiDb);
         restoreTableRule.setContentFile(new File(storageDir, srcTableName + DBBackup.CONTENT_FILE_SUFFIX));
         restoreTableRule.setContentLenFile(new File(storageDir, srcTableName + DBBackup.CONTENT_LEN_FILE_SUFFIX));

         if (!multiDb || !srcMultiDb)
         {
            // NODE_ID and PROPERTY_ID column indexes
            Set<Integer> convertColumnIndex = new HashSet<Integer>();
            convertColumnIndex.add(0);
            convertColumnIndex.add(1);
            restoreTableRule.setConvertColumnIndex(convertColumnIndex);
         }
         tables.put(dstTableName, restoreTableRule);

         if (dbDialect == DBConstants.DB_DIALECT_SYBASE)
         {
            restorers.add(new SybaseDBRestore(storageDir, jdbcConn, tables, wsConfig, swapCleaner));
         }
         else
         {
            restorers.add(new DBRestore(storageDir, jdbcConn, tables, wsConfig, swapCleaner));
         }

         // prepare value storage restorer
         File backupValueStorageDir = new File(storageDir, "values");
         if (wsConfig.getContainer().getValueStorages() != null)
         {
            List<File> dataDirs = new ArrayList<File>();
            List<File> backupDirs = new ArrayList<File>();

            List<ValueStorageEntry> valueStorages = wsConfig.getContainer().getValueStorages();
            String[] valueStoragesFiles = PrivilegedFileHelper.list(backupValueStorageDir);

            if ((valueStoragesFiles == null && valueStorages.size() != 0)
               || (valueStoragesFiles != null && valueStoragesFiles.length != valueStorages.size()))
            {
               throw new RepositoryConfigurationException("Workspace configuration [" + wsConfig.getName()
                  + "] has a different amount of value storages than exist in backup");
            }

            for (ValueStorageEntry valueStorage : valueStorages)
            {
               File backupDir = new File(backupValueStorageDir, valueStorage.getId());
               if (!PrivilegedFileHelper.exists(backupDir))
               {
                  throw new RepositoryConfigurationException("Can't restore value storage. Directory "
                     + backupDir.getName() + " doesn't exists");
               }
               else
               {
                  File dataDir = new File(valueStorage.getParameterValue(FileValueStorage.PATH));

                  dataDirs.add(dataDir);
                  backupDirs.add(backupDir);
               }
            }

            restorers.add(new DirectoryRestore(dataDirs, backupDirs));
         }
         else
         {
            if (PrivilegedFileHelper.exists(backupValueStorageDir))
            {
               throw new RepositoryConfigurationException("Value storage didn't configure in workspace ["
                  + wsConfig.getName() + "] configuration but value storage backup files exist");
            }
         }

         return new ComplexDataRestore(restorers);
      }
      catch (FileNotFoundException e)
      {
         throw new BackupException(e);
      }
      catch (IOException e)
      {
         throw new BackupException(e);
      }
      catch (NamingException e)
      {
         throw new BackupException(e);
      }
      catch (SQLException e)
      {
         throw new BackupException(e);
      }
      catch (RepositoryConfigurationException e)
      {
         throw new BackupException(e);
      }
      finally
      {
         if (backupInfo != null)
         {
            try
            {
               backupInfo.close();
            }
            catch (IOException e)
            {
               LOG.error("Can't close object reader", e);
            }
View Full Code Here

   public DataRestore getDataRestorer(File storageDir, Connection jdbcConn) throws BackupException
   {

      List<DataRestore> restorers = new ArrayList<DataRestore>();

      ObjectReader backupInfo = null;
      try
      {
         backupInfo =
            new ObjectReaderImpl(PrivilegedFileHelper.fileInputStream(new File(storageDir,
               "JDBCWorkspaceDataContainer.info")));

         String srcContainerName = backupInfo.readString();
         boolean srcMultiDb = backupInfo.readBoolean();

         Map<String, RestoreTableRule> tables = new LinkedHashMap<String, RestoreTableRule>();

         // ITEM table
         String dstTableName = "JCR_" + (multiDb ? "M" : "S") + "ITEM";
         String srcTableName = "JCR_" + (srcMultiDb ? "M" : "S") + "ITEM";

         RestoreTableRule restoreTableRule = new RestoreTableRule();
         restoreTableRule.setSrcContainerName(srcContainerName);
         restoreTableRule.setSrcMultiDb(srcMultiDb);
         restoreTableRule.setDstContainerName(containerName);
         restoreTableRule.setDstMultiDb(multiDb);
         restoreTableRule.setContentFile(new File(storageDir, srcTableName + DBBackup.CONTENT_FILE_SUFFIX));
         restoreTableRule.setContentLenFile(new File(storageDir, srcTableName + DBBackup.CONTENT_LEN_FILE_SUFFIX));

         if (multiDb)
         {
            if (!srcMultiDb)
            {
               // CONTAINER_NAME column index
               restoreTableRule.setDeleteColumnIndex(4);

               // ID and PARENT_ID column indexes
               Set<Integer> convertColumnIndex = new HashSet<Integer>();
               convertColumnIndex.add(0);
               convertColumnIndex.add(1);
               restoreTableRule.setConvertColumnIndex(convertColumnIndex);
            }
         }
         else
         {
            if (srcMultiDb)
            {
               // CONTAINER_NAME column index
               restoreTableRule.setNewColumnIndex(4);
               restoreTableRule.setNewColumnName("CONTAINER_NAME");
               restoreTableRule.setNewColumnType(Types.VARCHAR);

               // ID and PARENT_ID column indexes
               Set<Integer> convertColumnIndex = new HashSet<Integer>();
               convertColumnIndex.add(0);
               convertColumnIndex.add(1);
               restoreTableRule.setConvertColumnIndex(convertColumnIndex);
            }
            else
            {
               // ID and PARENT_ID and CONTAINER_NAME column indexes
               Set<Integer> convertColumnIndex = new HashSet<Integer>();
               convertColumnIndex.add(0);
               convertColumnIndex.add(1);
               convertColumnIndex.add(4);
               restoreTableRule.setConvertColumnIndex(convertColumnIndex);
            }
         }
         tables.put(dstTableName, restoreTableRule);

         // VALUE table
         dstTableName = "JCR_" + (multiDb ? "M" : "S") + "VALUE";
         srcTableName = "JCR_" + (srcMultiDb ? "M" : "S") + "VALUE";

         restoreTableRule = new RestoreTableRule();
         restoreTableRule.setSrcContainerName(srcContainerName);
         restoreTableRule.setSrcMultiDb(srcMultiDb);
         restoreTableRule.setDstContainerName(containerName);
         restoreTableRule.setDstMultiDb(multiDb);
         restoreTableRule.setContentFile(new File(storageDir, srcTableName + DBBackup.CONTENT_FILE_SUFFIX));
         restoreTableRule.setContentLenFile(new File(storageDir, srcTableName + DBBackup.CONTENT_LEN_FILE_SUFFIX));

         // auto increment ID column
         restoreTableRule.setSkipColumnIndex(0);

         if (!multiDb || !srcMultiDb)
         {
            // PROPERTY_ID column index
            Set<Integer> convertColumnIndex = new HashSet<Integer>();
            convertColumnIndex.add(3);
            restoreTableRule.setConvertColumnIndex(convertColumnIndex);
         }
         tables.put(dstTableName, restoreTableRule);

         // REF tables
         dstTableName = "JCR_" + (multiDb ? "M" : "S") + "REF";
         srcTableName = "JCR_" + (srcMultiDb ? "M" : "S") + "REF";

         restoreTableRule = new RestoreTableRule();
         restoreTableRule.setSrcContainerName(srcContainerName);
         restoreTableRule.setSrcMultiDb(srcMultiDb);
         restoreTableRule.setDstContainerName(containerName);
         restoreTableRule.setDstMultiDb(multiDb);
         restoreTableRule.setContentFile(new File(storageDir, srcTableName + DBBackup.CONTENT_FILE_SUFFIX));
         restoreTableRule.setContentLenFile(new File(storageDir, srcTableName + DBBackup.CONTENT_LEN_FILE_SUFFIX));

         if (!multiDb || !srcMultiDb)
         {
            // NODE_ID and PROPERTY_ID column indexes
            Set<Integer> convertColumnIndex = new HashSet<Integer>();
            convertColumnIndex.add(0);
            convertColumnIndex.add(1);
            restoreTableRule.setConvertColumnIndex(convertColumnIndex);
         }
         tables.put(dstTableName, restoreTableRule);

         restorers.add(new DBRestore(storageDir, jdbcConn, tables, wsConfig, swapCleaner));

         // prepare value storage restorer
         File backupValueStorageDir = new File(storageDir, "values");
         if (wsConfig.getContainer().getValueStorages() != null)
         {
            List<File> dataDirs = new ArrayList<File>();
            List<File> backupDirs = new ArrayList<File>();

            List<ValueStorageEntry> valueStorages = wsConfig.getContainer().getValueStorages();
            String[] valueStoragesFiles = PrivilegedFileHelper.list(backupValueStorageDir);

            if ((valueStoragesFiles == null && valueStorages.size() != 0)
               || (valueStoragesFiles != null && valueStoragesFiles.length != valueStorages.size()))
            {
               throw new RepositoryConfigurationException("Workspace configuration [" + wsConfig.getName()
                  + "] has a different amount of value storages than exist in backup");
            }

            for (ValueStorageEntry valueStorage : valueStorages)
            {
               File backupDir = new File(backupValueStorageDir, valueStorage.getId());
               if (!PrivilegedFileHelper.exists(backupDir))
               {
                  throw new RepositoryConfigurationException("Can't restore value storage. Directory "
                     + backupDir.getName() + " doesn't exists");
               }
               else
               {
                  File dataDir = new File(valueStorage.getParameterValue(FileValueStorage.PATH));

                  dataDirs.add(dataDir);
                  backupDirs.add(backupDir);
               }
            }

            restorers.add(new DirectoryRestore(dataDirs, backupDirs));
         }
         else
         {
            if (PrivilegedFileHelper.exists(backupValueStorageDir))
            {
               throw new RepositoryConfigurationException("Value storage didn't configure in workspace ["
                  + wsConfig.getName() + "] configuration but value storage backup files exist");
            }
         }

         return new ComplexDataRestore(restorers);
      }
      catch (FileNotFoundException e)
      {
         throw new BackupException(e);
      }
      catch (IOException e)
      {
         throw new BackupException(e);
      }
      catch (NamingException e)
      {
         throw new BackupException(e);
      }
      catch (SQLException e)
      {
         throw new BackupException(e);
      }
      catch (RepositoryConfigurationException e)
      {
         throw new BackupException(e);
      }
      finally
      {
         if (backupInfo != null)
         {
            try
            {
               backupInfo.close();
            }
            catch (IOException e)
            {
               LOG.error("Can't close object reader", e);
            }
View Full Code Here

   public DataRestore getDataRestorer(DataRestoreContext context) throws BackupException
   {

      List<DataRestore> restorers = new ArrayList<DataRestore>();

      ObjectReader backupInfo = null;
      try
      {
         File storageDir = (File) context.getObject(DataRestoreContext.STORAGE_DIR);
         Connection jdbcConn = null;

         if (context.getObject(DataRestoreContext.DB_CONNECTION) == null)
         {
            try
            {
               jdbcConn = connFactory.getJdbcConnection();
               jdbcConn.setAutoCommit(false);
            }
            catch (SQLException e)
            {
               throw new BackupException(e);
            }
            catch (RepositoryException e)
            {
               throw new BackupException(e);
            }

         }
         else
         {
            jdbcConn = (Connection) context.getObject(DataRestoreContext.DB_CONNECTION);
         }

         backupInfo =
                  new ObjectReaderImpl(PrivilegedFileHelper.fileInputStream(new File(storageDir,
               "JDBCWorkspaceDataContainer.info")));

         String srcContainerName = backupInfo.readString();
         boolean srcMultiDb = backupInfo.readBoolean();

         Map<String, RestoreTableRule> tables = new LinkedHashMap<String, RestoreTableRule>();

         // ITEM table
         String dstTableName = "JCR_" + (multiDb ? "M" : "S") + "ITEM";
         String srcTableName = "JCR_" + (srcMultiDb ? "M" : "S") + "ITEM";

         RestoreTableRule restoreTableRule = new RestoreTableRule();
         restoreTableRule.setSrcContainerName(srcContainerName);
         restoreTableRule.setSrcMultiDb(srcMultiDb);
         restoreTableRule.setDstContainerName(containerName);
         restoreTableRule.setDstMultiDb(multiDb);
         restoreTableRule.setSrcTableName(srcTableName);

         if (multiDb)
         {
            if (!srcMultiDb)
            {
               // CONTAINER_NAME column index
               restoreTableRule.setDeleteColumnIndex(4);

               // ID and PARENT_ID column indexes
               Set<Integer> convertColumnIndex = new HashSet<Integer>();
               convertColumnIndex.add(0);
               convertColumnIndex.add(1);
               restoreTableRule.setConvertColumnIndex(convertColumnIndex);
            }
         }
         else
         {
            if (srcMultiDb)
            {
               // CONTAINER_NAME column index
               restoreTableRule.setNewColumnIndex(4);
               restoreTableRule.setNewColumnName("CONTAINER_NAME");
               restoreTableRule.setNewColumnType(Types.VARCHAR);

               // ID and PARENT_ID column indexes
               Set<Integer> convertColumnIndex = new HashSet<Integer>();
               convertColumnIndex.add(0);
               convertColumnIndex.add(1);
               restoreTableRule.setConvertColumnIndex(convertColumnIndex);
            }
            else
            {
               // ID and PARENT_ID and CONTAINER_NAME column indexes
               Set<Integer> convertColumnIndex = new HashSet<Integer>();
               convertColumnIndex.add(0);
               convertColumnIndex.add(1);
               convertColumnIndex.add(4);
               restoreTableRule.setConvertColumnIndex(convertColumnIndex);
            }
         }
         tables.put(dstTableName, restoreTableRule);

         // VALUE table
         dstTableName = "JCR_" + (multiDb ? "M" : "S") + "VALUE";
         srcTableName = "JCR_" + (srcMultiDb ? "M" : "S") + "VALUE";

         restoreTableRule = new RestoreTableRule();
         restoreTableRule.setSrcContainerName(srcContainerName);
         restoreTableRule.setSrcMultiDb(srcMultiDb);
         restoreTableRule.setDstContainerName(containerName);
         restoreTableRule.setDstMultiDb(multiDb);
         restoreTableRule.setSrcTableName(srcTableName);

         // auto increment ID column
         restoreTableRule.setSkipColumnIndex(0);

         if (!multiDb || !srcMultiDb)
         {
            // PROPERTY_ID column index
            Set<Integer> convertColumnIndex = new HashSet<Integer>();
            convertColumnIndex.add(3);
            restoreTableRule.setConvertColumnIndex(convertColumnIndex);
         }
         tables.put(dstTableName, restoreTableRule);

         // REF tables
         dstTableName = "JCR_" + (multiDb ? "M" : "S") + "REF";
         srcTableName = "JCR_" + (srcMultiDb ? "M" : "S") + "REF";

         restoreTableRule = new RestoreTableRule();
         restoreTableRule.setSrcContainerName(srcContainerName);
         restoreTableRule.setSrcMultiDb(srcMultiDb);
         restoreTableRule.setDstContainerName(containerName);
         restoreTableRule.setDstMultiDb(multiDb);
         restoreTableRule.setSrcTableName(srcTableName);

         if (!multiDb || !srcMultiDb)
         {
            // NODE_ID and PROPERTY_ID column indexes
            Set<Integer> convertColumnIndex = new HashSet<Integer>();
            convertColumnIndex.add(0);
            convertColumnIndex.add(1);
            restoreTableRule.setConvertColumnIndex(convertColumnIndex);
         }
         tables.put(dstTableName, restoreTableRule);

         DBCleaner dbCleaner = null;
         if (context.getObject(DataRestoreContext.DB_CLEANER) != null)
         {
            dbCleaner = (DBCleaner)context.getObject(DataRestoreContext.DB_CLEANER);
         }
         else
         {
            dbCleaner = DBCleanService.getWorkspaceDBCleaner(jdbcConn, wsConfig);
         }

         restorers.add(new DBRestore(storageDir, jdbcConn, tables, wsConfig, swapCleaner, dbCleaner));

         // prepare value storage restorer
         if (wsConfig.getContainer().getValueStorages() != null)
         {
            List<File> dataDirs = new ArrayList<File>();
            List<File> backupDirs = new ArrayList<File>();

            List<ValueStorageEntry> valueStorages = wsConfig.getContainer().getValueStorages();
            for (ValueStorageEntry valueStorage : valueStorages)
            {
               File dataDir = new File(valueStorage.getParameterValue(FileValueStorage.PATH));
               dataDirs.add(dataDir);

               File zipFile = new File(storageDir, "values-" + valueStorage.getId() + ".zip");
               if (PrivilegedFileHelper.exists(zipFile))
               {
                  backupDirs.add(zipFile);
               }
               else
               {
                  // try to check if we have deal with old backup format
                  zipFile = new File(storageDir, "values/" + valueStorage.getId());
                  if (PrivilegedFileHelper.exists(zipFile))
                  {
                     backupDirs.add(zipFile);
                  }
                  else
                  {
                     throw new RepositoryConfigurationException("There is no backup data for value storage with id "
                        + valueStorage.getId());
                  }
               }
            }

            restorers.add(new DirectoryRestore(dataDirs, backupDirs));
         }

         return new ComplexDataRestore(restorers);
      }
      catch (FileNotFoundException e)
      {
         throw new BackupException(e);
      }
      catch (IOException e)
      {
         throw new BackupException(e);
      }
      catch (NamingException e)
      {
         throw new BackupException(e);
      }
      catch (SQLException e)
      {
         throw new BackupException(e);
      }
      catch (RepositoryConfigurationException e)
      {
         throw new BackupException(e);
      }
      finally
      {
         if (backupInfo != null)
         {
            try
            {
               backupInfo.close();
            }
            catch (IOException e)
            {
               LOG.error("Can't close object reader", e);
            }
View Full Code Here

      long start = System.currentTimeMillis();

      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();
View Full Code Here

      wr.close();

      vd = null;

      // read first time
      ObjectReader or = new ObjectReaderImpl(new FileInputStream(serf));

      FilePersistedValueData vd1 = null;

      PersistedValueDataReader vdr = new PersistedValueDataReader(fileCleaner, maxBufferSize, holder);
      try
      {
         vd1 = (FilePersistedValueData)vdr.read(or);
      }
      catch (UnknownClassIdException e)
      {
         fail(e.getMessage());
      }

      or.close();
      // Imitation save
      ((StreamPersistedValueData) vd1).setPersistedFile(((StreamPersistedValueData) vd1).getTempFile());

      // read second time
      or = new ObjectReaderImpl(new FileInputStream(serf));
      FilePersistedValueData vd2 = null;

      try
      {
         vd2 = (FilePersistedValueData)vdr.read(or);
      }
      catch (UnknownClassIdException e)
      {
         fail(e.getMessage());
      }
      or.close();
      // Imitation save
      ((StreamPersistedValueData) vd2).setPersistedFile(((StreamPersistedValueData) vd2).getTempFile());

      assertTrue(vd1.getFile().exists());
      assertTrue(vd2.getFile().exists());
View Full Code Here

   public DataRestore getDataRestorer(DataRestoreContext context) throws BackupException
   {

      List<DataRestore> restorers = new ArrayList<DataRestore>();

      ObjectReader backupInfo = null;
      try
      {
         File storageDir = (File) context.getObject(DataRestoreContext.STORAGE_DIR);
         Connection jdbcConn = null;

         if (context.getObject(DataRestoreContext.DB_CONNECTION) == null)
         {
            try
            {
               jdbcConn = connFactory.getJdbcConnection();
               jdbcConn.setAutoCommit(false);
            }
            catch (SQLException e)
            {
               throw new BackupException(e);
            }
            catch (RepositoryException e)
            {
               throw new BackupException(e);
            }

         }
         else
         {
            jdbcConn = (Connection) context.getObject(DataRestoreContext.DB_CONNECTION);
         }

         backupInfo =
                  new ObjectReaderImpl(PrivilegedFileHelper.fileInputStream(new File(storageDir,
               "JDBCWorkspaceDataContainer.info")));

         String srcContainerName = backupInfo.readString();
         boolean srcMultiDb = backupInfo.readBoolean();

         Map<String, RestoreTableRule> tables = new LinkedHashMap<String, RestoreTableRule>();

         // ITEM table
         String dstTableName = "JCR_" + (multiDb ? "M" : "S") + "ITEM";
         String srcTableName = "JCR_" + (srcMultiDb ? "M" : "S") + "ITEM";

         RestoreTableRule restoreTableRule = new RestoreTableRule();
         restoreTableRule.setSrcContainerName(srcContainerName);
         restoreTableRule.setSrcMultiDb(srcMultiDb);
         restoreTableRule.setDstContainerName(containerName);
         restoreTableRule.setDstMultiDb(multiDb);
         restoreTableRule.setSrcTableName(srcTableName);

         if (multiDb)
         {
            if (!srcMultiDb)
            {
               // CONTAINER_NAME column index
               restoreTableRule.setDeleteColumnIndex(4);

               // ID and PARENT_ID column indexes
               Set<Integer> convertColumnIndex = new HashSet<Integer>();
               convertColumnIndex.add(0);
               convertColumnIndex.add(1);
               restoreTableRule.setConvertColumnIndex(convertColumnIndex);
            }
         }
         else
         {
            if (srcMultiDb)
            {
               // CONTAINER_NAME column index
               restoreTableRule.setNewColumnIndex(4);
               restoreTableRule.setNewColumnName("CONTAINER_NAME");
               restoreTableRule.setNewColumnType(Types.VARCHAR);

               // ID and PARENT_ID column indexes
               Set<Integer> convertColumnIndex = new HashSet<Integer>();
               convertColumnIndex.add(0);
               convertColumnIndex.add(1);
               restoreTableRule.setConvertColumnIndex(convertColumnIndex);
            }
            else
            {
               // ID and PARENT_ID and CONTAINER_NAME column indexes
               Set<Integer> convertColumnIndex = new HashSet<Integer>();
               convertColumnIndex.add(0);
               convertColumnIndex.add(1);
               convertColumnIndex.add(4);
               restoreTableRule.setConvertColumnIndex(convertColumnIndex);
            }
         }
         tables.put(dstTableName, restoreTableRule);

         // VALUE table
         dstTableName = "JCR_" + (multiDb ? "M" : "S") + "VALUE";
         srcTableName = "JCR_" + (srcMultiDb ? "M" : "S") + "VALUE";

         restoreTableRule = new RestoreTableRule();
         restoreTableRule.setSrcContainerName(srcContainerName);
         restoreTableRule.setSrcMultiDb(srcMultiDb);
         restoreTableRule.setDstContainerName(containerName);
         restoreTableRule.setDstMultiDb(multiDb);
         restoreTableRule.setSrcTableName(srcTableName);

         // auto increment ID column
         restoreTableRule.setSkipColumnIndex(0);

         if (!multiDb || !srcMultiDb)
         {
            // PROPERTY_ID column index
            Set<Integer> convertColumnIndex = new HashSet<Integer>();
            convertColumnIndex.add(3);
            restoreTableRule.setConvertColumnIndex(convertColumnIndex);
         }
         tables.put(dstTableName, restoreTableRule);

         // REF tables
         dstTableName = "JCR_" + (multiDb ? "M" : "S") + "REF";
         srcTableName = "JCR_" + (srcMultiDb ? "M" : "S") + "REF";

         restoreTableRule = new RestoreTableRule();
         restoreTableRule.setSrcContainerName(srcContainerName);
         restoreTableRule.setSrcMultiDb(srcMultiDb);
         restoreTableRule.setDstContainerName(containerName);
         restoreTableRule.setDstMultiDb(multiDb);
         restoreTableRule.setSrcTableName(srcTableName);

         if (!multiDb || !srcMultiDb)
         {
            // NODE_ID and PROPERTY_ID column indexes
            Set<Integer> convertColumnIndex = new HashSet<Integer>();
            convertColumnIndex.add(0);
            convertColumnIndex.add(1);
            restoreTableRule.setConvertColumnIndex(convertColumnIndex);
         }
         tables.put(dstTableName, restoreTableRule);

         DBCleaner dbCleaner = null;
         if (context.getObject(DataRestoreContext.DB_CLEANER) != null)
         {
            dbCleaner = (DBCleaner)context.getObject(DataRestoreContext.DB_CLEANER);
         }
         else
         {
            dbCleaner = DBCleanService.getWorkspaceDBCleaner(jdbcConn, wsConfig);
         }

         if (dbDialect == DBConstants.DB_DIALECT_SYBASE)
         {
            restorers.add(new SybaseDBRestore(storageDir, jdbcConn, tables, wsConfig, swapCleaner, dbCleaner));
         }
         else
         {
            restorers.add(new DBRestore(storageDir, jdbcConn, tables, wsConfig, swapCleaner, dbCleaner));
         }

         // prepare value storage restorer
         File backupValueStorageDir = new File(storageDir, "values");
         if (wsConfig.getContainer().getValueStorages() != null)
         {
            List<File> dataDirs = new ArrayList<File>();
            List<File> backupDirs = new ArrayList<File>();

            List<ValueStorageEntry> valueStorages = wsConfig.getContainer().getValueStorages();
            for (ValueStorageEntry valueStorage : valueStorages)
            {
               File dataDir = new File(valueStorage.getParameterValue(FileValueStorage.PATH));
               dataDirs.add(dataDir);

               File zipFile = new File(storageDir, "values-" + valueStorage.getId() + ".zip");
               if (PrivilegedFileHelper.exists(zipFile))
               {
                  backupDirs.add(zipFile);
               }
               else
               {
                  // try to check if we have deal with old backup format
                  zipFile = new File(storageDir, "values/" + valueStorage.getId());
                  if (PrivilegedFileHelper.exists(zipFile))
                  {
                     backupDirs.add(zipFile);
                  }
                  else
                  {
                     throw new RepositoryConfigurationException("There is no backup data for value storage with id "
                        + valueStorage.getId());
                  }
               }
            }

            restorers.add(new DirectoryRestore(dataDirs, backupDirs));
         }

         return new ComplexDataRestore(restorers);
      }
      catch (FileNotFoundException e)
      {
         throw new BackupException(e);
      }
      catch (IOException e)
      {
         throw new BackupException(e);
      }
      catch (NamingException e)
      {
         throw new BackupException(e);
      }
      catch (SQLException e)
      {
         throw new BackupException(e);
      }
      catch (RepositoryConfigurationException e)
      {
         throw new BackupException(e);
      }
      finally
      {
         if (backupInfo != null)
         {
            try
            {
               backupInfo.close();
            }
            catch (IOException e)
            {
               LOG.error("Can't close object reader", e);
            }
View Full Code Here

   private final String srcRefTableName;

   public TableTransformationRuleGenerator(JDBCDataContainerConfig containerConfig, File storageDir) throws IOException

   {
      ObjectReader backupInfoReader = null;
      try
      {
         this.dstDbType = containerConfig.dbStructureType;
         this.dstContainerName = containerConfig.containerName;

         backupInfoReader =
            new ObjectReaderImpl(PrivilegedFileHelper.fileInputStream(new File(storageDir,
               "JDBCWorkspaceDataContainer.info")));;

         this.srcContainerName = backupInfoReader.readString();
         this.srcDbType = DatabaseStructureType.valueOf(backupInfoReader.readString());
         this.srcItemTableName = backupInfoReader.readString();
         this.srcValueTableName = backupInfoReader.readString();
         this.srcRefTableName = backupInfoReader.readString();
      }
      finally
      {
         if (backupInfoReader != null)
         {
            try
            {
               backupInfoReader.close();
            }
            catch (IOException e)
            {
               LOG.error("Can't close object reader", e);
            }
View Full Code Here

TOP

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

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.