Author: tolusha
Date: 2010-12-15 05:50:35 -0500 (Wed, 15 Dec 2010)
New Revision: 3667
Added:
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/rdbms/RDBMSBackupInfoReader.java
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/rdbms/RDBMSBackupInfoWriter.java
Log:
JCR-1097: support restore singleDb->multiDb, mulitDb->SingleDB
Added:
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/rdbms/RDBMSBackupInfoReader.java
===================================================================
---
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/rdbms/RDBMSBackupInfoReader.java
(rev 0)
+++
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/rdbms/RDBMSBackupInfoReader.java 2010-12-15
10:50:35 UTC (rev 3667)
@@ -0,0 +1,180 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.services.jcr.ext.backup.impl.rdbms;
+
+import org.exoplatform.commons.utils.PrivilegedFileHelper;
+import org.exoplatform.services.jcr.dataflow.serialization.ObjectReader;
+import org.exoplatform.services.jcr.impl.dataflow.serialization.ObjectReaderImpl;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Contains information about performed backup.
+ *
+ * @author <a href="mailto:anatoliy.bazko@gmail.com">Anatoliy
Bazko</a>
+ * @version $Id: RDBMSBackupInfoReader.java 34360 2009-07-22 23:58:59Z tolusha $
+ */
+public class RDBMSBackupInfoReader
+{
+
+ /**
+ * File which contains necessary information about backup.
+ */
+ public static final String BACKUP_INFO = "backup.info";
+
+ /**
+ * Workspace name.
+ */
+ private final String workspaceName;
+
+ /**
+ * Repository name.
+ */
+ private final String repositoryName;
+
+ /**
+ * Is multi-db.
+ */
+ private final boolean isMultiDb;
+
+ /**
+ * Table name for items.
+ */
+ private final String itemTableName;
+
+ /**
+ * Table name for values.
+ */
+ private final String valueTableName;
+
+ /**
+ * Table name for referenceable data.
+ */
+ private final String refTableName;
+
+ /**
+ * Lock table names.
+ */
+ private final List<String> lockTableNames = new ArrayList<String>();
+
+ /**
+ * Constructor RDBMSBackupInfoReader.java.
+ *
+ * @param dir
+ * The directory where file with backup information was stored.
+ */
+ public RDBMSBackupInfoReader(String dir) throws IOException
+ {
+ ObjectReader backupInfoReader =
+ new ObjectReaderImpl(PrivilegedFileHelper.fileInputStream(new File(dir,
BACKUP_INFO)));
+
+ try
+ {
+ this.repositoryName = backupInfoReader.readString();
+ this.workspaceName = backupInfoReader.readString();
+ this.isMultiDb = backupInfoReader.readBoolean();
+ this.itemTableName = backupInfoReader.readString();
+ this.valueTableName = backupInfoReader.readString();
+ this.refTableName = backupInfoReader.readString();
+
+ int lockTablesCount = backupInfoReader.readInt();
+ for (int i = 0; i < lockTablesCount; i++)
+ {
+ lockTableNames.add(backupInfoReader.readString());
+ }
+ }
+ finally
+ {
+ backupInfoReader.close();
+ }
+ }
+
+ /**
+ * Returns the original repository name where backup was performed.
+ *
+ * @return repository name
+ */
+ public String getRepositoryName()
+ {
+ return repositoryName;
+ }
+
+ /**
+ * Returns the original workspace name where backup was performed.
+ *
+ * @return workspace name
+ */
+ public String getWorkspaceName()
+ {
+ return workspaceName;
+ }
+
+ /**
+ * Returns the original value of multi-db parameter of workspace from which backup was
performed.
+ *
+ * @return multi-db parameter
+ */
+ public boolean isMultiDb()
+ {
+ return isMultiDb;
+ }
+
+ /**
+ * Returns the original table name of items from which backup was performed.
+ *
+ * @return table name
+ */
+ public String getItemTableName()
+ {
+ return itemTableName;
+ }
+
+ /**
+ * Returns the original table name of values from which backup was performed.
+ *
+ * @return table name
+ */
+ public String getValueTableName()
+ {
+ return valueTableName;
+ }
+
+ /**
+ * Returns the original table name of referenceable data from which backup was
performed.
+ *
+ * @return table name
+ */
+ public String getRefTableName()
+ {
+ return refTableName;
+ }
+
+ /**
+ * Returns the original table names of lock data from which backup was performed.
+ *
+ * @return list of table names
+ */
+ public List<String> getLockTableNames()
+ {
+ return lockTableNames;
+ }
+}
Added:
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/rdbms/RDBMSBackupInfoWriter.java
===================================================================
---
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/rdbms/RDBMSBackupInfoWriter.java
(rev 0)
+++
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/rdbms/RDBMSBackupInfoWriter.java 2010-12-15
10:50:35 UTC (rev 3667)
@@ -0,0 +1,192 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.services.jcr.ext.backup.impl.rdbms;
+
+import org.exoplatform.commons.utils.PrivilegedFileHelper;
+import org.exoplatform.services.jcr.dataflow.serialization.ObjectWriter;
+import org.exoplatform.services.jcr.impl.dataflow.serialization.ObjectWriterImpl;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Contains information about performed backup.
+ *
+ * @author <a href="mailto:anatoliy.bazko@gmail.com">Anatoliy
Bazko</a>
+ * @version $Id: RDBMSBackupInfo.java 34360 2009-07-22 23:58:59Z tolusha $
+ */
+public class RDBMSBackupInfoWriter
+{
+
+ /**
+ * Workspace name.
+ */
+ private String workspaceName;
+
+ /**
+ * Repository name.
+ */
+ private String repositoryName;
+
+ /**
+ * Is multi-db.
+ */
+ private boolean isMultiDb;
+
+ /**
+ * Table name for items.
+ */
+ private String itemTableName;
+
+ /**
+ * Table name for values.
+ */
+ private String valueTableName;
+
+ /**
+ * Table name for referenceable data.
+ */
+ private String refTableName;
+
+ /**
+ * Lock table names.
+ */
+ private List<String> lockTableNames = new ArrayList<String>();
+
+ /**
+ * The directory where file with backup information will be stored.
+ */
+ private final String dir;
+
+ /**
+ * Constructor RDBMSBackupInfoWriter.
+ *
+ * @param dir
+ * The directory where file with backup information was stored.
+ */
+ public RDBMSBackupInfoWriter(String dir)
+ {
+ this.dir = dir;
+ }
+
+ /**
+ * Returns the original repository name where backup was performed.
+ *
+ * @return repository name
+ */
+ public void setRepositoryName(String repositoryName)
+ {
+ this.repositoryName = repositoryName;
+ }
+
+ /**
+ * Returns the original workspace name where backup was performed.
+ *
+ * @return workspace name
+ */
+ public void setWorkspaceName(String workspaceName)
+ {
+ this.workspaceName = workspaceName;
+ }
+
+ /**
+ * Returns the original value of multi-db parameter of workspace from which backup was
performed.
+ *
+ * @return multi-db parameter
+ */
+ public void setMultiDb(boolean isMultiDb)
+ {
+ this.isMultiDb = isMultiDb;
+ }
+
+ /**
+ * Returns the original table name of items from which backup was performed.
+ *
+ * @return table name
+ */
+ public void setItemTableName(String itemTableName)
+ {
+ this.itemTableName = itemTableName;
+ }
+
+ /**
+ * Returns the original table name of values from which backup was performed.
+ *
+ * @return table name
+ */
+ public void setValueTableName(String valueTableName)
+ {
+ this.valueTableName = valueTableName;
+ }
+
+ /**
+ * Returns the original table name of referenceable data from which backup was
performed.
+ *
+ * @return table name
+ */
+ public void setRefTableName(String refTableName)
+ {
+ this.refTableName = refTableName;
+ }
+
+ /**
+ * Returns the original table names of lock data from which backup was performed.
+ *
+ * @return list of table names
+ */
+ public void setLockTableNames(List<String> lockTableNames)
+ {
+ this.lockTableNames.clear();
+ this.lockTableNames.addAll(lockTableNames);
+ }
+
+ /**
+ * Write backup information into file.
+ *
+ * @throws IOException
+ * if any error occurred
+ */
+ public void write() throws IOException
+ {
+ ObjectWriter backupInfoWriter =
+ new ObjectWriterImpl(PrivilegedFileHelper.fileOutputStream(new File(dir,
RDBMSBackupInfoReader.BACKUP_INFO)));
+
+ try
+ {
+ backupInfoWriter.writeString(repositoryName);
+ backupInfoWriter.writeString(workspaceName);
+ backupInfoWriter.writeBoolean(isMultiDb);
+ backupInfoWriter.writeString(itemTableName);
+ backupInfoWriter.writeString(valueTableName);
+ backupInfoWriter.writeString(refTableName);
+
+ backupInfoWriter.writeInt(lockTableNames.size());
+ for (int i = 0; i < lockTableNames.size(); i++)
+ {
+ backupInfoWriter.writeString(lockTableNames.get(i));
+ }
+ }
+ finally
+ {
+ backupInfoWriter.close();
+ }
+ }
+}